/** * 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; } }
/** * Archive publications beyond grace period * * @param object $job \Components\Cron\Models\Job * @return boolean */ public function runMkAip(\Components\Cron\Models\Job $job) { $database = \App::get('db'); $config = Component::params('com_publications'); require_once PATH_CORE . DS . 'components' . DS . 'com_publications' . DS . 'helpers' . DS . 'utilities.php'; require_once PATH_CORE . DS . 'components' . DS . 'com_publications' . DS . 'tables' . DS . 'version.php'; require_once PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'helpers' . DS . 'html.php'; // Check that mkAIP script exists if (!\Components\Publications\Helpers\Utilities::archiveOn()) { return; } // Check for grace period $gracePeriod = $config->get('graceperiod', 0); if (!$gracePeriod) { // If no grace period, this cron is unnecessary (archived as approval) return; } $aipBasePath = trim($config->get('aip_path', NULL), DS); $aipBasePath = $aipBasePath && is_dir(DS . $aipBasePath) ? DS . $aipBasePath : NULL; // Check for base path if (!$aipBasePath) { $this->setError('Missing archival base directory'); return; } // Get all unarchived publication versions $query = "SELECT V.*, C.id as id, V.id as version_id "; $query .= " FROM #__publication_versions as V, #__publications as C "; $query .= " WHERE C.id=V.publication_id AND V.state=1 "; $query .= " AND V.doi IS NOT NULL "; $query .= " AND V.accepted IS NOT NULL AND V.accepted !='0000-00-00 00:00:00' "; $query .= " AND (V.archived IS NULL OR V.archived ='0000-00-00 00:00:00') "; $database->setQuery($query); if (!($rows = $database->loadObjectList())) { return true; } // Start email message $subject = Lang::txt('Update on recently archived publications'); $body = Lang::txt('The following publications passed the grace period and were archived:') . "\n"; $aipGroup = $config->get('aip_group'); $counter = 0; foreach ($rows as $row) { // Grace period unexpired? $monthFrom = Date::of($row->accepted . '+1 month')->toSql(); if (strtotime($monthFrom) > strtotime(Date::of('now'))) { continue; } // Load version $pv = new \Components\Publications\Tables\Version($database); if (!$pv->load($row->version_id)) { continue; } // Create aip path $doiParts = explode('/', $row->doi); $aipName = count($doiParts) > 1 ? $doiParts[0] . '__' . $doiParts[1] : ''; // Archival package exists? if ($aipBasePath && $aipName && is_dir($aipBasePath . DS . $aipName)) { // Save approved date and archive date $pv->archived = $pv->accepted; $pv->store(); // Do not overwrite existing archives !! continue; } // Run mkAIP and save archived date if (\Components\Publications\Helpers\Utilities::mkAip($row)) { $pv->archived = Date::toSql(); $pv->store(); $counter++; $body .= $row->title . ' v.' . $row->version_label . ' (id #' . $row->id . ')' . "\n"; } } // Email update to admins if ($counter > 0 && $aipGroup) { // Set email config $from = array('name' => Config::get('fromname') . ' ' . Lang::txt('Publications'), 'email' => Config::get('mailfrom'), 'multipart' => md5(date('U'))); $admins = \Components\Projects\Helpers\Html::getGroupMembers($aipGroup); // Build message if (!empty($admins)) { foreach ($admins as $admin) { // Get the user's account $user = User::getInstance($admin); if (!$user->get('id')) { continue; } $message = new \Hubzero\Mail\Message(); $message->setSubject($subject)->addFrom($from['email'], $from['name'])->addTo($user->get('email'), $user->get('name'))->addHeader('X-Component', 'com_publications')->addHeader('X-Component-Object', 'publications'); $message->addPart($body, 'text/plain'); $message->send(); } } } // All done return true; }
/** * 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(); } }