Example #1
0
 public function store()
 {
     //Load Tables
     $row = new UserTable();
     $data = $this->app->input->post->getArray();
     //$this->app->triggerEvent('onBeforeCRMUserSave', array(&$data));
     //date generation
     $date = date('Y-m-d H:i:s');
     if (!array_key_exists('id', $data)) {
         $data['created'] = $date;
         $data['time_zone'] = ConfigHelper::getConfigValue('timezone');
         $data['time_format'] = ConfigHelper::getConfigValue('time_format');
         $data['block'] = 0;
         $data['registerDate'] = $date;
         $data['activation'] = 0;
         $data['params'] = "";
     }
     if (array_key_exists('password', $data) && $data['password'] != "") {
         $data['password'] = UsersHelper::hashPassword($data['password']);
     } else {
         unset($data['password']);
     }
     //generate team data
     $model = new Teams();
     if (array_key_exists('id', $data) && $data['id'] > 0) {
         $teamId = $this->getTeamId($data['id']);
     }
     //assign user priviliges
     $data['modified'] = $date;
     $data['admin'] = array_key_exists('admin', $data) && $data['admin'] == '1' ? 1 : 0;
     $data['exports'] = array_key_exists('exports', $data) && $data['exports'] == 'on' ? 1 : 0;
     $data['can_delete'] = array_key_exists('can_delete', $data) && $data['can_delete'] == 'on' ? 1 : 0;
     //republish / register users
     if (array_key_exists('id', $data) && $data['id'] != "") {
         $query = $this->db->getQuery(true);
         $query->clear()->select("id")->from("#__users")->where("id=" . $data['id']);
         $this->db->setQuery($query);
         $id = $this->db->loadResult();
         if ($id) {
             $data['id'] = $id;
             $data['published'] = 1;
         }
     }
     if (array_key_exists('team_id', $data) && $data['team_id'] == "") {
         unset($data['team_id']);
     }
     // Bind the form fields to the table
     if (!$row->bind($data)) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
     // Make sure the record is valid
     if (!$row->check()) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
     // Store the web link table to the database
     if (!$row->store()) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
     if (array_key_exists('role_type', $data) && $data['role_type'] == "manager") {
         $teamModel = new Teams();
         $teamName = array_key_exists('team_name', $data) ? $data['team_name'] : "";
         $teamModel->createTeam($row->id, $teamName);
     }
     //if we are downgrading a users priviliges
     if (array_key_exists('manager_assignment', $data) && $data['manager_assignment'] != null && $data['manager_assignment'] != "") {
         $newTeamId = $this->getTeamId($data['manager_assignment']);
         $model->updateTeam($teamId, $newTeamId);
     }
     $row->id = array_key_exists('id', $data) && $data['id'] > 0 ? $data['id'] : $this->db->insertId();
     $this->updateUserMap($row);
     //$this->app->triggerEvent('onAfterCRMUserSave', array(&$data));
     return true;
 }
Example #2
0
 /**
  * Method to store a record
  *
  * @return boolean True on success
  */
 public function store($data = null)
 {
     if (!$data) {
         $data = $this->app->input->post->getArray();
     }
     //Load Table
     $row = new UserTable();
     if (isset($data['id']) && $data['id']) {
         $row->load($data['id']);
     }
     if (isset($data['fullscreen'])) {
         $data['fullscreen'] = !$row->fullscreen;
     }
     if (isset($data['password']) && $data['password']) {
         $data['password'] = UsersHelper::hashPassword($data['password']);
     }
     //date generation
     $date = DateHelper::formatDBDate(date('Y-m-d H:i:s'));
     $data['modified'] = $date;
     // Bind the form fields to the table
     if (!$row->bind($data)) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
     // Make sure the record is valid
     if (!$row->check()) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
     // Store the web link table to the database
     if (!$row->store()) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
     //update users email address
     if (array_key_exists('email', $data)) {
         $this->updateEmail($row->id, $data['email']);
     }
     if (isset($data['team_name']) && $data['team_name']) {
         $teamModel = new Teams();
         $teamModel->createTeam($row->id, $data['team_name']);
     }
     $this->app->refreshUser();
     return $row->id;
 }