Example #1
0
 /**
  * Erases all project information (to be used for test projects only)
  *
  * @return  void
  */
 public function eraseTask()
 {
     $id = Request::getVar('id', 0);
     $permanent = 1;
     // Initiate extended database class
     $obj = new Tables\Project($this->database);
     if (!$id or !$obj->loadProject($id)) {
         App::redirect(Route::url('index.php?option=' . $this->_option, false), Lang::txt('COM_PROJECTS_NOTICE_ID_NOT_FOUND'), 'error');
         return;
     }
     // Get project group
     $group_prefix = $this->config->get('group_prefix', 'pr-');
     $prGroup = $group_prefix . $obj->alias;
     // Store project info
     $alias = $obj->alias;
     $identifier = $alias;
     // Delete project
     $obj->delete();
     // Erase all owners
     $objO = new Tables\Owner($this->database);
     $objO->removeOwners($id, '', 0, $permanent, '', $all = 1);
     // Erase owner group
     $group = new \Hubzero\User\Group();
     $group->read($prGroup);
     if ($group) {
         $group->delete();
     }
     // Erase all comments
     $objC = new Tables\Comment($this->database);
     $objC->deleteProjectComments($id, $permanent);
     // Erase all activities
     $objA = new Tables\Activity($this->database);
     $objA->deleteActivities($id, $permanent);
     // Erase all todos
     $objTD = new Tables\Todo($this->database);
     $objTD->deleteTodos($id, '', $permanent);
     // Erase all blog entries
     $objB = new Tables\Blog($this->database);
     $objB->deletePosts($id, $permanent);
     // Erase all notes
     if (file_exists(PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'models' . DS . 'page.php')) {
         include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'models' . DS . 'page.php';
         // Get all notes
         $this->database->setQuery("SELECT DISTINCT p.id FROM `#__wiki_pages` AS p\n\t\t\t\tWHERE p.scope_id=" . $this->database->quote($id) . " AND p.scope=" . $this->database->quote('project'));
         $notes = $this->database->loadObjectList();
         if ($notes) {
             foreach ($notes as $note) {
                 $page = \Components\Wiki\Models\Page::oneOrFail($note->id);
                 // Finally, delete the page itself
                 $page->destroy();
             }
         }
     }
     // Erase all files, remove files repository
     if ($alias) {
         // Delete base dir for .git repos
         $dir = $alias;
         $prefix = $this->config->get('offroot', 0) ? '' : PATH_CORE;
         $repodir = DS . trim($this->config->get('webpath'), DS);
         $path = $prefix . $repodir . DS . $dir;
         if (is_dir($path)) {
             Filesystem::deleteDirectory($path);
         }
         // Delete images/preview directories
         $webdir = DS . trim($this->config->get('imagepath', '/site/projects'), DS);
         $webpath = PATH_APP . $webdir . DS . $dir;
         if (is_dir($webpath)) {
             Filesystem::deleteDirectory($webpath);
         }
     }
     // Redirect
     App::redirect(Route::url('index.php?option=' . $this->_option, false), Lang::txt('COM_PROJECTS_PROJECT') . ' #' . $id . ' (' . $alias . ') ' . Lang::txt('COM_PROJECTS_PROJECT_ERASED'));
 }
Example #2
0
 /**
  * Reviewers actions (sensitive data, sponsored research)
  *
  * @return     void
  */
 public function processTask()
 {
     // Incoming
     $reviewer = Request::getWord('reviewer', '');
     $action = Request::getVar('action', '');
     $comment = Request::getVar('comment', '');
     $approve = Request::getInt('approve', 0);
     $filterby = Request::getVar('filterby', 'pending');
     $notify = Request::getVar('notify', 0, 'post');
     // Cannot proceed without project id/alias
     if (!$this->model->exists() || $this->model->isDeleted()) {
         throw new Exception(Lang::txt('COM_PROJECTS_PROJECT_NOT_FOUND'), 404);
         return;
     }
     // Authorize
     if (!$this->model->reviewerAccess($reviewer)) {
         throw new Exception(Lang::txt('ALERTNOTAUTH'), 403);
         return;
     }
     // Set the pathway
     $this->_buildPathway();
     // Set the page title
     $this->_buildTitle();
     // Get project params
     $params = $this->model->params;
     if ($action == 'save' && !$this->getError()) {
         $cbase = $this->model->get('admin_notes');
         // Meta data for comment
         $meta = '<meta>' . Date::of('now')->toLocal('M d, Y') . ' - ' . User::get('name') . '</meta>';
         // Save approval
         if ($reviewer == 'sensitive') {
             $approve = $approve == 1 && $this->model->get('state') == 5 ? 1 : 0;
             // can only approve pending project
             $state = $approve ? 1 : $this->model->get('state');
             $this->model->set('state', $state);
         } elseif ($reviewer == 'sponsored') {
             $grant_agency = Request::getVar('grant_agency', '');
             $grant_title = Request::getVar('grant_title', '');
             $grant_PI = Request::getVar('grant_PI', '');
             $grant_budget = Request::getVar('grant_budget', '');
             $grant_approval = Request::getVar('grant_approval', '');
             $rejected = Request::getVar('rejected', 0);
             // New approval
             if (trim($params->get('grant_approval')) == '' && trim($grant_approval) != '' && $params->get('grant_status') != 1 && $rejected != 1) {
                 // Increase
                 $approve = 1;
                 // Bump up quota
                 $premiumQuota = Helpers\Html::convertSize(floatval($this->config->get('premiumQuota', '30')), 'GB', 'b');
                 $this->model->saveParam('quota', $premiumQuota);
                 // Bump up publication quota
                 $premiumPubQuota = Helpers\Html::convertSize(floatval($this->config->get('premiumPubQuota', '10')), 'GB', 'b');
                 $this->model->saveParam('pubQuota', $premiumPubQuota);
             }
             // Reject
             if ($rejected == 1 && $params->get('grant_status') != 2) {
                 $approve = 2;
             }
             $this->model->saveParam('grant_budget', $grant_budget);
             $this->model->saveParam('grant_agency', $grant_agency);
             $this->model->saveParam('grant_title', $grant_title);
             $this->model->saveParam('grant_PI', $grant_PI);
             $this->model->saveParam('grant_approval', $grant_approval);
             if ($approve) {
                 $this->model->saveParam('grant_status', $approve);
             }
         }
         // Save comment
         if (trim($comment) != '') {
             $comment = \Hubzero\Utility\String::truncate($comment, 500);
             $comment = \Hubzero\Utility\Sanitize::stripAll($comment);
             if (!$approve) {
                 $cbase .= '<nb:' . $reviewer . '>' . $comment . $meta . '</nb:' . $reviewer . '>';
             }
         }
         if ($approve) {
             if ($reviewer == 'sensitive') {
                 $cbase .= '<nb:' . $reviewer . '>' . Lang::txt('COM_PROJECTS_PROJECT_APPROVED_HIPAA');
                 $cbase .= trim($comment) != '' ? ' ' . $comment : '';
                 $cbase .= $meta . '</nb:' . $reviewer . '>';
             }
             if ($reviewer == 'sponsored') {
                 if ($approve == 1) {
                     $cbase .= '<nb:' . $reviewer . '>' . Lang::txt('COM_PROJECTS_PROJECT_APPROVED_SPS') . ' ' . ucfirst(Lang::txt('COM_PROJECTS_APPROVAL_CODE')) . ': ' . $grant_approval;
                     $cbase .= trim($comment) != '' ? '. ' . $comment : '';
                     $cbase .= $meta . '</nb:' . $reviewer . '>';
                 } elseif ($approve == 2) {
                     $cbase .= '<nb:' . $reviewer . '>' . Lang::txt('COM_PROJECTS_PROJECT_REJECTED_SPS');
                     $cbase .= trim($comment) != '' ? ' ' . $comment : '';
                     $cbase .= $meta . '</nb:' . $reviewer . '>';
                 }
             }
         }
         $this->model->set('admin_notes', $cbase);
         // Save changes
         if ($approve || $comment) {
             if (!$this->model->store()) {
                 $this->setError($this->model->getError());
             }
             $admingroup = $reviewer == 'sensitive' ? $this->config->get('sdata_group', '') : $this->config->get('ginfo_group', '');
             if (\Hubzero\User\Group::getInstance($admingroup)) {
                 $admins = Helpers\Html::getGroupMembers($admingroup);
                 $admincomment = $comment ? User::get('name') . ' ' . Lang::txt('COM_PROJECTS_SAID') . ': ' . $comment : '';
                 // Send out email to admins
                 if (!empty($admins)) {
                     Helpers\Html::sendHUBMessage($this->_option, $this->model, $admins, Lang::txt('COM_PROJECTS_EMAIL_ADMIN_REVIEWER_NOTIFICATION'), 'projects_new_project_admin', 'admin', $admincomment, $reviewer);
                 }
             }
         }
         // Pass success or error message
         if ($this->getError()) {
             $this->_setNotification($this->getError(), 'error');
         } else {
             if ($approve) {
                 if ($reviewer == 'sensitive') {
                     $this->_setNotification(Lang::txt('COM_PROJECTS_PROJECT_APPROVED_HIPAA_MSG'));
                     // Send out emails to team members
                     $this->_notifyTeam();
                 }
                 if ($reviewer == 'sponsored') {
                     $notification = $approve == 2 ? Lang::txt('COM_PROJECTS_PROJECT_REJECTED_SPS_MSG') : Lang::txt('COM_PROJECTS_PROJECT_APPROVED_SPS_MSG');
                     $this->_setNotification($notification);
                 }
             } elseif ($comment) {
                 $this->_setNotification(Lang::txt('COM_PROJECTS_REVIEWER_COMMENT_POSTED'));
             }
             // Add to project activity feed
             if ($notify) {
                 $activity = '';
                 if ($approve && $reviewer == 'sponsored') {
                     $activity = $approve == 2 ? Lang::txt('COM_PROJECTS_PROJECT_REJECTED_SPS_ACTIVITY') : Lang::txt('COM_PROJECTS_PROJECT_APPROVED_SPS_ACTIVITY');
                 } elseif ($comment) {
                     $activity = Lang::txt('COM_PROJECTS_PROJECT_REVIEWER_COMMENTED');
                 }
                 if ($activity) {
                     $aid = $this->model->recordActivity($activity, $this->model->get('id'), '', '', 'admin', 0, 1, 1);
                     // Append comment to activity
                     if ($comment && $aid) {
                         $objC = new Tables\Comment($this->database);
                         $cid = $objC->addComment($aid, 'activity', $comment, User::get('id'), $aid, 1);
                         if ($cid) {
                             $caid = $this->model->recordActivity(Lang::txt('COM_PROJECTS_COMMENTED') . ' ' . Lang::txt('COM_PROJECTS_ON') . ' ' . Lang::txt('COM_PROJECTS_AN_ACTIVITY'), $cid, '', '', 'quote', 0, 1, 1);
                             if ($caid) {
                                 $objC->storeCommentActivityId($cid, $caid);
                             }
                         }
                     }
                 }
             }
         }
         // Go back to project listing
         App::redirect(Route::url('index.php?option=' . $this->_option . '&task=browse&reviewer=' . $reviewer . '&filterby=' . $filterby));
         return;
     } else {
         // Instantiate a new view
         $this->view->setLayout('review');
         // Output HTML
         $this->view->reviewer = $reviewer;
         $this->view->ajax = Request::getInt('ajax', 0);
         $this->view->title = $this->title;
         $this->view->option = $this->_option;
         $this->view->model = $this->model;
         $this->view->params = $params;
         $this->view->config = $this->config;
         $this->view->database = $this->database;
         $this->view->action = $action;
         $this->view->filterby = $filterby;
         $this->view->uid = User::get('id');
         $this->view->msg = $this->_getNotifications('success');
         if ($this->getError()) {
             $this->view->setError($this->getError());
         }
         $this->view->display();
     }
 }