Пример #1
0
 /**
  * run - display template and edit data
  *
  * @access public
  *
  */
 public function run()
 {
     $tpl = new template();
     $hasher = new PasswordHash(8, TRUE);
     //only Admins
     if ($_SESSION['userdata']['role'] == 'admin') {
         $values = array();
         if (isset($_POST['save'])) {
             $values = array('firstname' => $_POST['firstname'], 'lastname' => $_POST['lastname'], 'user' => $_POST['user'], 'phone' => $_POST['phone'], 'role' => $_POST['role'], 'password' => $hasher->HashPassword($_POST['password']), 'clientId' => $_POST['client']);
             //Validation
             if ($values['user'] !== '') {
                 $helper = new helper();
                 if ($helper->validateEmail($values['user']) == 1) {
                     if ($hasher->CheckPassword($_POST['password'], $values['password']) && $_POST['password'] != '') {
                         if ($this->usernameExist($values['user']) === false) {
                             $this->addUser($values);
                             $tpl->setNotification('USER_ADDED', 'success');
                         } else {
                             $tpl->setNotification('USERNAME_EXISTS', 'error');
                         }
                     } else {
                         $tpl->setNotification('PASSWORDS_DONT_MATCH', 'error');
                     }
                 } else {
                     $tpl->setNotification('NO_VALID_EMAIL', 'error');
                 }
             } else {
                 $tpl->setNotification('NO_USERNAME', 'error');
             }
             $tpl->assign('values', $values);
         }
         $clients = new clients();
         $tpl->assign('clients', $clients->getAll());
         $tpl->assign('roles', $this->getRoles());
         $tpl->display('users.newUser');
     } else {
         $tpl->display('general.error');
     }
 }
Пример #2
0
 /**
  * run - display template and edit data
  *
  * @access public
  *
  */
 public function run()
 {
     $tpl = new template();
     $hasher = new PasswordHash(8, TRUE);
     $userId = $_SESSION['userdata']['id'];
     $row = $this->getUser($userId);
     // $projects = $this->getUserProjectRelation($userId);
     $infoKey = '';
     //Build values array
     $values = array('firstname' => $row['firstname'], 'lastname' => $row['lastname'], 'user' => $row['username'], 'phone' => $row['phone'], 'role' => $row['role']);
     //Save form
     if (isset($_POST['save'])) {
         $values = array('firstname' => $_POST['firstname'], 'lastname' => $_POST['lastname'], 'user' => $_POST['user'], 'phone' => $_POST['phone'], 'password' => $hasher->HashPassword($_POST['newPassword']));
         $changedEmail = 0;
         if ($row['username'] != $values['user']) {
             $changedEmail = 1;
         }
         //Validation
         if ($values['user'] !== '') {
             $helper = new helper();
             if ($helper->validateEmail($values['user']) == 1) {
                 if ($_POST['newPassword'] == $_POST['confirmPassword']) {
                     if ($_POST['newPassword'] == '') {
                         $values['password'] = '';
                     } else {
                         $this->editOwn($values, $userId);
                     }
                     if ($changedEmail == 1) {
                         if ($this->usernameExist($values['user'], $userId) === false) {
                             $this->editOwn($values, $userId);
                             $tpl->setNotification('EDIT_SUCCESS', 'success');
                         } else {
                             $tpl->setNotification('USERNAME_EXISTS', 'error');
                         }
                     } else {
                         $this->editOwn($values, $userId);
                         $tpl->setNotification('EDIT_SUCCESS', 'success');
                     }
                 } else {
                     $tpl->setNotification('PASSWORDS_DONT_MATCH', 'ERROR');
                 }
             } else {
                 $tpl->setNotification('NO_VALID_EMAIL', 'error');
             }
         } else {
             $tpl->setNotification('NO_USERNAME', 'error');
         }
     }
     $file = new files();
     if (isset($_POST['savePic'])) {
         if (isset($_FILES)) {
             $this->setPicture($_FILES, $_SESSION['userdata']['id']);
         }
     }
     //Assign vars
     $users = new users();
     //		$tpl->assign('profilePic', $file->getFilesByModule('user',$_SESSION['userdata']['id']));
     $tpl->assign('profilePic', $users->getProfilePicture($_SESSION['userdata']['id']));
     $tpl->assign('info', $infoKey);
     $tpl->assign('values', $values);
     //$tpl->assign('roles', $this->roles);
     $tpl->assign('user', $row);
     $tpl->display('users.editOwn');
 }
Пример #3
0
 /**
  * run - display template and edit data
  *
  * @access public
  *
  */
 public function run()
 {
     $tpl = new template();
     //Only admins
     if ($_SESSION['userdata']['role'] == 'admin') {
         if (isset($_GET['id']) === true) {
             $project = new projects();
             $id = (int) $_GET['id'];
             $row = $this->getUser($id);
             $edit = false;
             $infoKey = '';
             //Build values array
             $values = array('firstname' => $row['firstname'], 'lastname' => $row['lastname'], 'user' => $row['username'], 'phone' => $row['phone'], 'status' => $row['status'], 'role' => $row['role'], 'hours' => $row['hours'], 'wage' => $row['wage'], 'clientId' => $row['clientId']);
             if (isset($_POST['save'])) {
                 $values = array('firstname' => $_POST['firstname'], 'lastname' => $_POST['lastname'], 'user' => $_POST['user'], 'phone' => $_POST['phone'], 'status' => $_POST['status'], 'role' => $_POST['role'], 'hours' => $_POST['hours'], 'wage' => $_POST['wage'], 'clientId' => $_POST['client']);
                 $changedEmail = 0;
                 if ($row['username'] != $values['user']) {
                     $changedEmail = 1;
                 }
                 if ($values['user'] !== '') {
                     $helper = new helper();
                     if ($helper->validateEmail($values['user']) === 1) {
                         if ($changedEmail == 1) {
                             if ($this->usernameExist($row['username'], $id) === false) {
                                 $edit = true;
                             } else {
                                 $tpl->setNotification('USERNAME_EXISTS', 'error');
                             }
                         } else {
                             $edit = true;
                         }
                     } else {
                         $tpl->setNotification('NO_VALID_EMAIL_' . $helper->validateEmail($values['user']), 'error');
                     }
                 } else {
                     $tpl->setNotification('NO_USERNAME', 'error');
                 }
             }
             //Was everything okay?
             if ($edit !== false) {
                 $this->editUser($values, $id);
                 if (isset($_POST['projects'])) {
                     if ($_POST['projects'][0] !== '0') {
                         $project->editUserProjectRelations($id, $_POST['projects']);
                     } else {
                         $project->deleteAllProjectRelations($id);
                     }
                 }
                 $tpl->setNotification('EDIT_SUCCESS', 'success');
             }
             // Get relations to projects
             $projects = $project->getUserProjectRelation($id);
             $projectrelation = array();
             foreach ($projects as $projectId) {
                 $projectrelation[] = $projectId['projectId'];
             }
             //Assign vars
             $clients = new clients();
             $tpl->assign('clients', $clients->getAll());
             $tpl->assign('allProjects', $project->getAll());
             $tpl->assign('values', $values);
             $tpl->assign('relations', $projectrelation);
             $tpl->assign('roles', $this->getRoles());
             $tpl->assign('status', $this->status);
             $tpl->display('users.editUser');
         } else {
             $tpl->display('general.error');
         }
     } else {
         $tpl->display('general.error');
     }
 }