<?php
//+-----------------------------------------------+//
//+ Copyright Floopo.com
//+ helper.webprofile.php
//+ Edit web profiles
//+-----------------------------------------------+//

defined('BASEPATH') or die('You can not directly access this file');//check its within this framework

$show_web_profile = 1;

//___ADD/EDIT PROFILE_______

if(isset($_POST['submit'])) {

    //Insert New profile
    $site_name = Sanatize(mysql_real_escape_string($_POST['site_name']));
    $site_url = $_POST['site_url'];
    $full_name = Sanatize(mysql_real_escape_string($_POST['full_name']));
    $location = Sanatize(mysql_real_escape_string($_POST['location']));

    //check the url format
    if($_POST['site_url'] != '' && !ValidateURL($_POST['site_url'])) {
        $display_notification = $lang['invalid_url'];
    }
    else {

        $dbase->UpdateRecord("UPDATE web_profiles SET
					          site_name = '$site_name', 
					          site_url = '$site_url', 
					          full_name = '$full_name', 
					          location = '$location'
					          WHERE
					          user_name = '$env_user_name'");

        //check for any errors
        $display_notification = (($dbase->obj_status)?$lang['request_completed']:$lang['generic_error']);


    }

        //ready to show posted form
        $skip_select = true;
        foreach($_POST as $key => $value) {
            $$key = $value;
        }
        
}

//___DELETE PROFILE_______
if(isset($_POST['delete'])) {

    //Delete current if any
    $dbase->UpdateRecord("UPDATE web_profiles SET
					      site_name = NULL, 
					      site_url = NULL, 
					      full_name = NULL, 
					      location = NULL
					      WHERE
					      user_name = '$env_user_name'");
					      
    $display_notification = (($dbase->obj_status)?$lang['request_completed']:$lang['generic_error']);
}

//___LOAD PROFILE_______
if(!$skip_select) {
    $result = $dbase->SelectRecord("SELECT * FROM web_profiles
	                                WHERE
									user_name = '$env_user_name'");
    //set the vars for the html display
    foreach($result as $key => $value) {
        $$key = $value;
    }
}
?>