public static function loadFromUsername($username)
 {
     $user = new UserProfile();
     $user->Load("username ='******'");
     return $user;
 }
 public function act_edit_user()
 {
     // var_dump($_POST);
     include_once APPROOT . 'inc/lib_form.inc';
     include_once APPROOT . 'inc/lib_form_util.inc';
     include_once APPROOT . 'inc/lib_validate.inc';
     include_once APPROOT . 'inc//security/lib_auth.inc';
     include_once APPROOT . 'mod/admin/lib_user.inc';
     $user_form = user_get_form();
     unset($user_form['username']);
     unset($user_form['role']);
     unset($user_form['status']);
     unset($user_form['password1']);
     unset($user_form['password2']);
     $this->user_form = $user_form;
     //$user_form['username']['type'] = 'hidden';
     //$user_form['username']['extra_opts']['value'] = $_SESSION['username'];
     if (isset($_POST['save'])) {
         $valide = true;
         $username = $_SESSION['username'];
         $firstName = $_POST['first_name'];
         $lastName = $_POST['last_name'];
         $organization = $_POST['organization'];
         $designation = $_POST['designation'];
         $email = $_POST['email'];
         $address = $_POST['address'];
         $locale = $_POST['locale'];
         if (isset($email) && $email != '' && !shn_valid_email($email)) {
             //email not valide
             $user_form['email']['extra_opts'] = array();
             $user_form['email']['extra_opts']['error'] = array();
             $user_form['email']['extra_opts']['error'][] = _t("INVALID_EMAIL");
             $valide = false;
         }
         $this->user_form = $user_form;
         if ($valide == true) {
             $user = new User();
             $user = UserHelper::loadFromUsername($username);
             //$user->loadUserProfile();
             //$user->role = $role;
             //$user->status =  $status;
             $cfg = array();
             if (!empty($user->config)) {
                 $cfg = @json_decode($user->config, true);
             }
             $cfg['locale'] = $locale;
             $user->config = json_encode($cfg);
             $user->Save();
             $userProfile = UserProfileHelper::loadFromUsername($username);
             $userProfile->username = $username;
             $userProfile->first_name = $firstName;
             $userProfile->last_name = $lastName;
             $userProfile->organization = $organization;
             $userProfile->designation = $designation;
             $userProfile->email = $email;
             $userProfile->address = $address;
             $userProfile->Save();
             set_redirect_header('home', 'edit_user');
         }
     }
     if (isset($_SESSION['username'])) {
         $user = new User();
         $userProfile = new UserProfile();
         $username = $_SESSION['username'];
         $user->Load("username='******'");
         $userProfile->Load("username='******'");
         //$user_form['username']['extra_opts']['value'] = $user->getUserName();
         //$user_form['password1'] = null;
         //$user_form['password2'] = null;
         $user_form['first_name']['extra_opts']['value'] = $userProfile->getFirstName();
         $user_form['last_name']['extra_opts']['value'] = $userProfile->getLastName();
         $user_form['organization']['extra_opts']['value'] = $userProfile->getOrganization();
         $user_form['designation']['extra_opts']['value'] = $userProfile->getDesignation();
         $user_form['email']['extra_opts']['value'] = $userProfile->getEmail();
         $user_form['address']['extra_opts']['value'] = $userProfile->getAddress();
         //$user_form['role']['extra_opts']['value'] = $user->getUserType();
         //$user_form['status']['extra_opts']['value'] = $user->status;
         if (!empty($user->config)) {
             $cfg = @json_decode($user->config, true);
             if ($cfg['locale']) {
                 $user_form['locale']['extra_opts']['value'] = $cfg['locale'];
             }
         }
         $this->user_form = $user_form;
     }
     $this->username = $username;
 }