Пример #1
0
 /**
  * Save a new record
  *
  * @return  void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Trim and addslashes all posted items
     $aro = Request::getVar('aro', array(), 'post');
     $aro = array_map('trim', $aro);
     // Initiate class and bind posted items to database fields
     $row = new Aro($this->database);
     if (!$row->bind($aro)) {
         App::abort(500, $row->getError());
     }
     if ($row->foreign_key) {
         switch ($row->model) {
             case 'user':
                 $user = User::getInstance($row->foreign_key);
                 if (!is_object($user)) {
                     App::abort(500, Lang::txt('COM_SUPPORT_ACL_ERROR_UNKNOWN_USER'));
                 }
                 $row->foreign_key = intval($user->get('id'));
                 $row->alias = $user->get('username');
                 break;
             case 'group':
                 $group = \Hubzero\User\Group::getInstance($row->foreign_key);
                 if (!is_object($group)) {
                     App::abort(500, Lang::txt('COM_SUPPORT_ACL_ERROR_UNKNOWN_GROUP'));
                 }
                 $row->foreign_key = intval($group->gidNumber);
                 $row->alias = $group->cn;
                 break;
         }
     }
     // Check content
     if (!$row->check()) {
         App::abort(500, $row->getError());
     }
     // Store new content
     if (!$row->store()) {
         App::abort(500, $row->getError());
     }
     if (!$row->id) {
         $row->id = $this->database->insertid();
     }
     // Trim and addslashes all posted items
     $map = Request::getVar('map', array(), 'post');
     foreach ($map as $k => $v) {
         // Initiate class and bind posted items to database fields
         $aroaco = new AroAco($this->database);
         if (!$aroaco->bind($v)) {
             App::abort(500, $aroaco->getError());
         }
         $aroaco->aro_id = !$aroaco->aro_id ? $row->id : $aroaco->aro_id;
         // Check content
         if (!$aroaco->check()) {
             App::abort(500, $aroaco->getError());
         }
         // Store new content
         if (!$aroaco->store()) {
             App::abort(500, $aroaco->getError());
         }
     }
     // Output messsage and redirect
     Notify::success(Lang::txt('COM_SUPPORT_ACL_SAVED'));
     $this->cancelTask();
 }