Beispiel #1
0
 /**
  * Sets the access of one or more entries
  *
  * @return  void
  */
 public function accessTask()
 {
     // Check for request forgeries
     Request::checkToken(['get', 'post']);
     if (!User::authorise('core.edit.state', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     // Incoming
     $private = $this->getTask() == 'accesspublic' ? 0 : 1;
     //Request::getInt('private', 0);
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     // Check for an ID
     if (count($ids) < 1) {
         Notify::warning(Lang::txt('COM_PROJECTS_SELECT_ENTRY_TO_CHANGE_PRIVACY'));
         return $this->cancelTask();
     }
     $i = 0;
     foreach ($ids as $id) {
         // Update record(s)
         $model = new Models\Project($id);
         $model->set('private', $private);
         if (!$model->exists()) {
             Notify::error(Lang::txt('COM_PROJECTS_NOTICE_ID_NOT_FOUND'));
             continue;
         }
         if (!$model->store()) {
             Notify::error($model->getError());
             continue;
         }
         $i++;
     }
     if ($i) {
         Notify::success(Lang::txt('COM_PROJECTS_ITEMS_PRIVACY_CHANGED', $i));
     }
     $this->cancelTask();
 }
Beispiel #2
0
 /**
  * Saves a project
  * Redirects to main listing
  *
  * @return     void
  */
 public function saveTask($redirect = false)
 {
     // Check for request forgeries
     Request::checkToken();
     // Config
     $setup_complete = $this->config->get('confirm_step', 0) ? 3 : 2;
     // Incoming
     $formdata = $_POST;
     $id = Request::getVar('id', 0);
     $action = Request::getVar('admin_action', '');
     $message = rtrim(\Hubzero\Utility\Sanitize::clean(Request::getVar('message', '')));
     // Load model
     $model = new Models\Project($id);
     if (!$model->exists()) {
         App::redirect('index.php?option=' . $this->_option, Lang::txt('COM_PROJECTS_NOTICE_ID_NOT_FOUND'), 'error');
         return;
     }
     $title = $formdata['title'] ? rtrim($formdata['title']) : $model->get('title');
     $type = isset($formdata['type']) ? $formdata['type'] : 1;
     $model->set('title', $title);
     $model->set('about', rtrim(\Hubzero\Utility\Sanitize::clean($formdata['about'])));
     $model->set('type', $type);
     $model->set('modified', Date::toSql());
     $model->set('modified_by', User::get('id'));
     $model->set('private', Request::getVar('private', 0));
     $this->_message = Lang::txt('COM_PROJECTS_SUCCESS_SAVED');
     // Was project suspended?
     $suspended = false;
     if ($model->isInactive()) {
         $suspended = $model->table('Activity')->checkActivity($id, Lang::txt('COM_PROJECTS_ACTIVITY_PROJECT_SUSPENDED'));
     }
     $subject = Lang::txt('COM_PROJECTS_PROJECT') . ' "' . $model->get('alias') . '" ';
     $sendmail = 0;
     // Get project managers
     $managers = $model->table('Owner')->getIds($id, 1, 1);
     // Admin actions
     if ($action) {
         switch ($action) {
             case 'delete':
                 $model->set('state', 2);
                 $what = Lang::txt('COM_PROJECTS_ACTIVITY_PROJECT_DELETED');
                 $subject .= Lang::txt('COM_PROJECTS_MSG_ADMIN_DELETED');
                 $this->_message = Lang::txt('COM_PROJECTS_SUCCESS_DELETED');
                 break;
             case 'suspend':
                 $model->set('state', 0);
                 $what = Lang::txt('COM_PROJECTS_ACTIVITY_PROJECT_SUSPENDED');
                 $subject .= Lang::txt('COM_PROJECTS_MSG_ADMIN_SUSPENDED');
                 $this->_message = Lang::txt('COM_PROJECTS_SUCCESS_SUSPENDED');
                 break;
             case 'reinstate':
                 $model->set('state', 1);
                 $what = $suspended ? Lang::txt('COM_PROJECTS_ACTIVITY_PROJECT_REINSTATED') : Lang::txt('COM_PROJECTS_ACTIVITY_PROJECT_ACTIVATED');
                 $subject .= $suspended ? Lang::txt('COM_PROJECTS_MSG_ADMIN_REINSTATED') : Lang::txt('COM_PROJECTS_MSG_ADMIN_ACTIVATED');
                 $this->_message = $suspended ? Lang::txt('COM_PROJECTS_SUCCESS_REINSTATED') : Lang::txt('COM_PROJECTS_SUCCESS_ACTIVATED');
                 break;
         }
         // Add activity
         $model->recordActivity($what, 0, '', '', 'project', 0, $admin = 1);
         $sendmail = 1;
     } elseif ($message) {
         $subject .= ' - ' . Lang::txt('COM_PROJECTS_MSG_ADMIN_NEW_MESSAGE');
         $sendmail = 1;
         $this->_message = Lang::txt('COM_PROJECTS_SUCCESS_MESSAGE_SENT');
     }
     // Save changes
     if (!$model->store()) {
         $this->setError($model->getError());
         return false;
     }
     // Incoming tags
     $tags = Request::getVar('tags', '', 'post');
     // Save the tags
     $cloud = new Models\Tags($model->get('id'));
     $cloud->setTags($tags, User::get('id'), 1);
     // Save params
     $incoming = Request::getVar('params', array());
     if (!empty($incoming)) {
         foreach ($incoming as $key => $value) {
             if ($key == 'quota' || $key == 'pubQuota') {
                 // convert GB to bytes
                 $value = Helpers\Html::convertSize(floatval($value), 'GB', 'b');
             }
             $model->saveParam($key, $value);
         }
     }
     // Add members if specified
     $this->model = $model;
     $this->_saveMember();
     // Change ownership
     $this->_changeOwnership();
     // Send message
     if ($this->config->get('messaging', 0) && $sendmail && count($managers) > 0) {
         // Email config
         $from = array();
         $from['name'] = Config::get('sitename') . ' ' . Lang::txt('COM_PROJECTS');
         $from['email'] = Config::get('mailfrom');
         // Html email
         $from['multipart'] = md5(date('U'));
         // Message body
         $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'admin_plain'));
         $eview->option = $this->_option;
         $eview->subject = $subject;
         $eview->action = $action;
         $eview->project = $model;
         $eview->message = $message;
         $body = array();
         $body['plaintext'] = $eview->loadTemplate(false);
         $body['plaintext'] = str_replace("\n", "\r\n", $body['plaintext']);
         // HTML email
         $eview->setLayout('admin_html');
         $body['multipart'] = $eview->loadTemplate();
         $body['multipart'] = str_replace("\n", "\r\n", $body['multipart']);
         // Send HUB message
         Event::trigger('xmessage.onSendMessage', array('projects_admin_notice', $subject, $body, $from, $managers, $this->_option));
     }
     \Notify::message($this->_message, 'success');
     // Redirect to edit view?
     if ($redirect) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&task=edit&id=' . $id, false));
     } else {
         App::redirect(Route::url('index.php?option=' . $this->_option, false));
     }
 }