/** * Process data * * @return void */ protected function _process() { // New project? $new = $this->model->exists() ? false : true; // Are we in setup? $setup = $new || $this->model->inSetup() ? true : false; // Incoming $private = Request::getInt('private', 1); // Save section switch ($this->section) { case 'describe': case 'info': // Incoming $name = trim(Request::getVar('name', '', 'post')); $title = trim(Request::getVar('title', '', 'post')); $name = preg_replace('/ /', '', $name); $name = strtolower($name); // Clean up title from any scripting $title = preg_replace('/\\s+/', ' ', $title); $title = $this->_txtClean($title); // Check incoming data if ($setup && $new && !$this->model->check($name, $this->model->get('id'))) { $this->setError(Lang::txt('COM_PROJECTS_ERROR_NAME_INVALID_OR_EMPTY')); return false; } elseif (!$title) { $this->setError(Lang::txt('COM_PROJECTS_ERROR_TITLE_SHORT_OR_EMPTY')); return false; } if ($this->model->exists()) { $this->model->set('modified', Date::toSql()); $this->model->set('modified_by', User::get('id')); } else { $this->model->set('alias', $name); $this->model->set('created', Date::toSql()); $this->model->set('created_by_user', User::get('id')); $this->model->set('owned_by_group', $this->_gid); $this->model->set('owned_by_user', User::get('id')); $this->model->set('private', $this->config->get('privacy', 1)); } $this->model->set('title', \Hubzero\Utility\String::truncate($title, 250)); $this->model->set('about', trim(Request::getVar('about', '', 'post', 'none', 2))); $this->model->set('type', Request::getInt('type', 1, 'post')); // save advanced permissions if (isset($_POST['private'])) { $this->model->set('private', $private); } if ($setup && !$this->model->exists()) { // Copy params from default project type $objT = $this->model->table('Type'); $this->model->set('params', $objT->getParams($this->model->get('type'))); } // Save changes if (!$this->model->store()) { $this->setError($this->model->getError()); return false; } // Save owners for new projects if ($new) { $this->_identifier = $this->model->get('alias'); // Group owners $objO = $this->model->table('Owner'); if ($this->_gid) { if (!$objO->saveOwners($this->model->get('id'), User::get('id'), 0, $this->_gid, 0, 1, 1, '', $split_group_roles = 0)) { $this->setError(Lang::txt('COM_PROJECTS_ERROR_SAVING_AUTHORS') . ': ' . $objO->getError()); return false; } // Make sure project creator is manager $objO->reassignRole($this->model->get('id'), $users = array(User::get('id')), 0, 1); } elseif (!$objO->saveOwners($this->model->get('id'), User::get('id'), User::get('id'), $this->_gid, 1, 1, 1)) { $this->setError(Lang::txt('COM_PROJECTS_ERROR_SAVING_AUTHORS') . ': ' . $objO->getError()); return false; } } break; case 'team': if ($new) { return false; } // Save team $content = Event::trigger('projects.onProject', array($this->model, 'save', array('team'))); if (isset($content[0]) && $this->next == $this->section) { if (isset($content[0]['msg']) && !empty($content[0]['msg'])) { $this->_setNotification($content[0]['msg']['message'], $content[0]['msg']['type']); } } break; case 'settings': if ($new) { return false; } // Save privacy if (isset($_POST['private'])) { $this->model->set('private', $private); // Save changes if (!$this->model->store()) { $this->setError($this->model->getError()); return false; } } // Save params $incoming = Request::getVar('params', array()); if (!empty($incoming)) { foreach ($incoming as $key => $value) { $this->model->saveParam($key, $value); // If grant information changed if ($key == 'grant_status') { // Meta data for comment $meta = '<meta>' . Date::of('now')->toLocal('M d, Y') . ' - ' . User::get('name') . '</meta>'; $cbase = $this->model->get('admin_notes'); $cbase .= '<nb:sponsored>' . Lang::txt('COM_PROJECTS_PROJECT_MANAGER_GRANT_INFO_UPDATE') . $meta . '</nb:sponsored>'; $this->model->set('admin_notes', $cbase); // Save admin notes if (!$this->model->store()) { $this->setError($this->model->getError()); return false; } $admingroup = $this->config->get('ginfo_group', ''); if (\Hubzero\User\Group::getInstance($admingroup)) { $admins = Helpers\Html::getGroupMembers($admingroup); // 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', Lang::txt('COM_PROJECTS_PROJECT_MANAGER_GRANT_INFO_UPDATE'), 'sponsored'); } } } } } break; } }
/** * On after change status * * @return string */ public function onAfterChangeState($pub, $originalStatus = 3) { $notify = 1; // Notify administrators/curators? // Log activity in curation history if (isset($pub->_curationModel)) { $pub->_curationModel->saveHistory($this->_uid, $originalStatus, $pub->version->get('state'), 0); } // Display status message switch ($pub->version->get('state')) { case 1: default: $this->_msg = Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_SUCCESS_PUBLISHED'); $action = $this->_task == 'republish' ? Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_ACTIVITY_REPUBLISHED') : Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_ACTIVITY_PUBLISHED'); break; case 4: $this->_msg = $this->_task == 'revert' ? Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_SUCCESS_REVERTED') : Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_SUCCESS_SAVED'); $action = $this->_task == 'revert' ? Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_ACTIVITY_REVERTED') : Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_ACTIVITY_SAVED'); $notify = 0; break; case 5: $this->_msg = $originalStatus == 7 ? Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_SUCCESS_PENDING_RESUBMITTED') : Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_SUCCESS_PENDING'); $action = $originalStatus == 7 ? Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_ACTIVITY_RESUBMITTED') : Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_ACTIVITY_SUBMITTED'); break; } $this->_msg .= ' <a href="' . Route::url($pub->link('version')) . '">' . Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_VIEWIT') . '</a>'; $pubtitle = \Hubzero\Utility\String::truncate($pub->version->get('title'), 100); $action .= ' ' . $pub->version->get('version_label') . ' '; $action .= Lang::txt('PLG_PROJECTS_PUBLICATIONS_OF_PUBLICATION') . ' "' . html_entity_decode($pubtitle) . '"'; $action = htmlentities($action, ENT_QUOTES, "UTF-8"); // Record activity if (!$this->model->isProvisioned() && !$this->getError()) { $aid = $this->model->recordActivity($action, $pub->id, $pubtitle, Route::url($pub->link('editversion')), 'publication', 1); } // Send out notifications $profile = \Hubzero\User\Profile::getInstance($this->_uid); $actor = $profile ? $profile->get('name') : Lang::txt('PLG_PROJECTS_PUBLICATIONS_PROJECT_MEMBER'); $sef = Route::url($pub->link('version')); $link = rtrim(Request::base(), DS) . DS . trim($sef, DS); $message = $actor . ' ' . html_entity_decode($action) . ' - ' . $link; // Notify admin group if ($notify) { $admingroup = $this->model->config()->get('admingroup', ''); $group = \Hubzero\User\Group::getInstance($admingroup); $admins = array(); if ($admingroup && $group) { $members = $group->get('members'); $managers = $group->get('managers'); $admins = array_merge($members, $managers); $admins = array_unique($admins); \Components\Projects\Helpers\Html::sendHUBMessage('com_projects', $this->model, $admins, Lang::txt('COM_PROJECTS_EMAIL_ADMIN_NEW_PUB_STATUS'), 'projects_new_project_admin', 'publication', $message); } // Notify curators by email $curatorMessage = $pub->version->get('state') == 5 ? $message . "\n" . "\n" . Lang::txt('PLG_PROJECTS_PUBLICATIONS_EMAIL_CURATORS_REVIEW') . ' ' . rtrim(Request::base(), DS) . DS . 'publications/curation' : $message; $curatorgroups = array($pub->masterType()->curatorgroup); if ($this->_pubconfig->get('curatorgroup', '')) { $curatorgroups[] = $this->_pubconfig->get('curatorgroup', ''); } $admins = array(); foreach ($curatorgroups as $curatorgroup) { if (trim($curatorgroup) && ($group = \Hubzero\User\Group::getInstance($curatorgroup))) { $members = $group->get('members'); $managers = $group->get('managers'); $admins = array_merge($members, $managers, $admins); $admins = array_unique($admins); } } \Components\Publications\Helpers\Html::notify($pub, $admins, Lang::txt('PLG_PROJECTS_PUBLICATIONS_EMAIL_CURATORS'), $curatorMessage); } // Notify project managers (in all cases) $objO = $this->model->table('Owner'); $managers = $objO->getIds($this->model->get('id'), 1, 1); if (!$this->model->isProvisioned() && !empty($managers)) { \Components\Projects\Helpers\Html::sendHUBMessage('com_projects', $this->model, $managers, Lang::txt('COM_PROJECTS_EMAIL_MANAGERS_NEW_PUB_STATUS'), 'projects_admin_notice', 'publication', $message); } // Produce archival package if ($pub->version->get('state') == 1 || $pub->version->get('state') == 5) { $pub->_curationModel->package(); } // Pass error or success message if ($this->getError()) { \Notify::message($this->getError(), 'error', 'projects'); } elseif (!empty($this->_msg)) { \Notify::message($this->_msg, 'success', 'projects'); } return; }
/** * Process data * * @return void */ protected function _process() { // New project? $new = $this->model->exists() ? false : true; // Are we in setup? $setup = $new || $this->model->inSetup() ? true : false; // Incoming $private = Request::getInt('private', 1); // Save section switch ($this->section) { case 'describe': case 'info': case 'info_custom': // Incoming $name = trim(Request::getVar('name', '', 'post')); $title = trim(Request::getVar('title', '', 'post')); $name = preg_replace('/ /', '', $name); $name = strtolower($name); // Clean up title from any scripting $title = preg_replace('/\\s+/', ' ', $title); $title = $this->_txtClean($title); // Check incoming data if ($setup && $new && !$this->model->check($name, $this->model->get('id'))) { $this->setError(Lang::txt('COM_PROJECTS_ERROR_NAME_INVALID_OR_EMPTY')); return false; } elseif (!$title) { $this->setError(Lang::txt('COM_PROJECTS_ERROR_TITLE_SHORT_OR_EMPTY')); return false; } if ($this->model->exists()) { $this->model->set('modified', Date::toSql()); $this->model->set('modified_by', User::get('id')); } else { $this->model->set('alias', $name); $this->model->set('created', Date::toSql()); $this->model->set('created_by_user', User::get('id')); $this->model->set('owned_by_group', $this->_gid); $this->model->set('owned_by_user', User::get('id')); $this->model->set('private', $this->config->get('privacy', 1)); } $this->model->set('title', \Hubzero\Utility\String::truncate($title, 250)); $this->model->set('about', trim(Request::getVar('about', '', 'post', 'none', 2))); $this->model->set('type', Request::getInt('type', 1, 'post')); // save advanced permissions if (isset($_POST['private'])) { $this->model->set('private', $private); } if ($setup && !$this->model->exists()) { // Copy params from default project type $objT = $this->model->table('Type'); $this->model->set('params', $objT->getParams($this->model->get('type'))); } // Save changes if (!$this->model->store()) { $this->setError($this->model->getError()); return false; } // Save custom description if ($this->section == 'info_custom') { $newInfo = Request::getVar('description', array()); $projectID = $this->model->get('id'); $project = ProjectORM::one($this->model->get('id')); $old = Description::collect($project->descriptions); $formFields = array_merge($old, $newInfo); $knownFields = Field::all()->rows()->toObject(); foreach ($knownFields as $kField) { $existingField = Description::all()->whereEquals('project_id', $this->model->get('id'))->whereEquals('description_key', $kField->name)->limit(1)->row(); if ($existingField->id != NULL) { $existingField->set('description_value', $formFields[$kField->name]); $existingField->set('ordering', $kField->ordering); $existingField->save(); } else { // Create a new field $newField = new Description(); $newField->set('description_key', $kField->name)->set('description_value', $formFields[$kField->name])->set('project_id', $this->model->get('id'))->set('ordering', $kField->ordering); if (!$newField->save()) { $this->setError($newField->getError()); } } } } // Save owners for new projects if ($new && $this->section != 'info_custom') { $this->_identifier = $this->model->get('alias'); // Group owners $objO = $this->model->table('Owner'); if ($this->_gid) { // Only add the creator // They'll choose if they want to sync the entire group or not in the next step if (!$objO->saveOwners($this->model->get('id'), User::get('id'), User::get('id'), $this->_gid, 0, 1, 1, '', $split_group_roles = 0)) { $this->setError(Lang::txt('COM_PROJECTS_ERROR_SAVING_AUTHORS') . ': ' . $objO->getError()); return false; } // Make sure project creator is manager $objO->reassignRole($this->model->get('id'), $users = array(User::get('id')), 0, 1); } elseif (!$objO->saveOwners($this->model->get('id'), User::get('id'), User::get('id'), $this->_gid, 1, 1, 1)) { $this->setError(Lang::txt('COM_PROJECTS_ERROR_SAVING_AUTHORS') . ': ' . $objO->getError()); return false; } } // Record activity $this->model->recordActivity(Lang::txt('COM_PROJECTS_PROJECT_INFO_UPDATED')); break; case 'team': if ($new) { return false; } if ($this->model->groupOwner()) { // Save group sync settings $this->model->set('sync_group', Request::getInt('sync_group', 0, 'post')); if (!$this->model->store()) { $this->setError($this->model->getError()); return false; } // Are we syncing group membership? if ($this->model->get('sync_group')) { $objO = $this->model->table('Owner'); $objO->saveOwners($this->model->get('id'), User::get('id'), 0, $this->_gid, 0, 1, 1, '', $split_group_roles = 0); } } // Save team $content = Event::trigger('projects.onProject', array($this->model, 'save', array('team'))); if (isset($content[0]) && $this->next == $this->section) { if (isset($content[0]['msg']) && !empty($content[0]['msg'])) { $this->_setNotification($content[0]['msg']['message'], $content[0]['msg']['type']); } } break; case 'settings': if ($new) { return false; } // Save privacy if (isset($_POST['private'])) { $this->model->set('private', $private); // Save changes if (!$this->model->store()) { $this->setError($this->model->getError()); return false; } } // Save params $incoming = Request::getVar('params', array()); if (!empty($incoming)) { foreach ($incoming as $key => $value) { $this->model->saveParam($key, $value); $this->model->params->set($key, $value); // If grant information changed if ($key == 'grant_status') { // Meta data for comment $meta = '<meta>' . Date::of('now')->toLocal('M d, Y') . ' - ' . User::get('name') . '</meta>'; $cbase = $this->model->get('admin_notes'); $cbase .= '<nb:sponsored>' . Lang::txt('COM_PROJECTS_PROJECT_MANAGER_GRANT_INFO_UPDATE') . $meta . '</nb:sponsored>'; $this->model->set('admin_notes', $cbase); // Save admin notes if (!$this->model->store()) { $this->setError($this->model->getError()); return false; } $admingroup = $this->config->get('ginfo_group', ''); if (\Hubzero\User\Group::getInstance($admingroup)) { $admins = Helpers\Html::getGroupMembers($admingroup); // 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', Lang::txt('COM_PROJECTS_PROJECT_MANAGER_GRANT_INFO_UPDATE'), 'sponsored'); } } } } // Record activity $this->model->recordActivity(Lang::txt('COM_PROJECTS_PROJECT_SETTINGS_UPDATED')); } break; } }
/** * 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(); } }