/** * Saves a project * Redirects to main listing * * @param boolean $redirect * @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'); } $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::getInt('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)); } }
<input name="params[quota]" maxlength="100" type="text" value="<?php echo \Components\Projects\Helpers\Html::convertSize($quota, 'b', 'GB', 2); ?> " class="short" /> </div> <div class="input-wrap"> <label><?php echo Lang::txt('Publications Quota'); ?> : <?php echo ' (' . Lang::txt('COM_PROJECTS_FILES_GBYTES') . ')'; ?> </label> <input name="params[pubQuota]" maxlength="100" type="text" value="<?php echo \Components\Projects\Helpers\Html::convertSize($pubQuota, 'b', 'GB', 2); ?> " class="short" /> </div> <?php if ($this->diskusage) { ?> <div class="input-wrap"> <?php echo $this->diskusage; ?> </div> <?php } ?>
/** * Show disk usage * * @param object $model Project model * @param string $repoName * @param integer $by * @return string */ public function diskspace($model, $repoName = 'local', $by = '') { // Output HTML $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'files', 'name' => 'diskspace')); if (!isset($this->repo)) { $this->repo = new \Components\Projects\Models\Repo($model, $repoName); } $url = Route::url('index.php?option=' . $this->_option . '&alias=' . $model->get('alias') . '&active=files&action=diskspace'); // Report usage with all history? if ($this->params->get('disk_usage') == true || $by == 'admin') { $view->dirsize = $this->repo->call('getDiskUsage', $params = array('working' => true, 'history' => true)); $view->totalspace = $this->repo->call('getDiskUsage', $params = array('working' => false, 'history' => false)); } else { $view->totalspace = $this->repo->call('getDiskUsage', $params = array('working' => false, 'history' => true)); $view->dirsize = $view->totalspace; } // Get publication usage if (Plugin::isEnabled('projects', 'publications') && $by == 'admin') { require_once Component::path('com_publications') . DS . 'helpers' . DS . 'html.php'; $filters = array(); $filters['project'] = $model->get('id'); $filters['ignore_access'] = 1; $filters['dev'] = 1; $database = \App::get('db'); $objP = new \Components\Publications\Tables\Publication($database); $pubs = $objP->getRecords($filters); $view->pubDiskUsage = \Components\Publications\Helpers\Html::getDiskUsage($pubs); $view->pubQuota = $model->params->get('pubQuota') ? $model->params->get('pubQuota') : \Components\Projects\Helpers\Html::convertSize(floatval($model->config()->get('pubQuota', '1')), 'GB', 'b'); } $view->total = $this->repo->count(); $view->quota = $model->params->get('quota', \Components\Projects\Helpers\Html::convertSize(floatval($model->config()->get('defaultQuota', '1')), 'GB', 'b')); $view->by = $by; $view->model = $model; $view->option = $this->_option; $view->config = $model->config(); $view->title = isset($this->_area['title']) ? $this->_area['title'] : ''; $view->params = $this->params; return $view->loadTemplate(); }
<?php echo $this->subdir ? Lang::txt('PLG_PROJECTS_FILES_THIS_DIRECTORY_IS_EMPTY') : Lang::txt('PLG_PROJECTS_FILES_PROJECT_HAS_NO_FILES'); ?> </p> <?php } ?> <p class="extras"> <?php if ($this->repo->get('name') == 'local') { ?> <span class="leftfloat"> <?php // Used disk space and remaining quota $dirsize = $this->repo->call('getDiskUsage', $params = array('git' => $this->fileparams->get('disk_usage'))); $quota = $this->model->params->get('quota') ? $this->model->params->get('quota') : \Components\Projects\Helpers\Html::convertSize(floatval($this->model->config()->get('defaultQuota', '1')), 'GB', 'b'); // Disc space indicator $this->view('_mini', 'diskspace')->set('quota', $quota)->set('dirsize', $dirsize)->set('config', $this->model->config())->set('url', Route::url($this->model->link('files')))->display(); ?> </span> <?php } ?> <?php if ($this->model->access('content')) { ?> <span class="rightfloat"> <a href="<?php echo Route::url($this->model->link('files')) . '?action=trash'; ?> " class="showinbox"><?php
/** * Get disk space * * @param object $model * * @return string */ public function pubDiskSpace($model) { // Output HTML $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'publications', 'name' => 'diskspace')); // Include styling and js \Hubzero\Document\Assets::addPluginStylesheet('projects', 'files', 'diskspace'); \Hubzero\Document\Assets::addPluginScript('projects', 'files', 'diskspace'); $database = App::get('db'); // Build query $filters = array(); $filters['limit'] = Request::getInt('limit', 25); $filters['start'] = Request::getInt('limitstart', 0); $filters['sortby'] = Request::getVar('t_sortby', 'title'); $filters['sortdir'] = Request::getVar('t_sortdir', 'ASC'); $filters['project'] = $model->get('id'); $filters['ignore_access'] = 1; $filters['dev'] = 1; // get dev versions // Instantiate project publication $objP = new \Components\Publications\Tables\Publication($database); // Get all publications $view->rows = $objP->getRecords($filters); // Get used space $view->dirsize = \Components\Publications\Helpers\Html::getDiskUsage($view->rows); $view->params = $model->params; $view->quota = $view->params->get('pubQuota') ? $view->params->get('pubQuota') : \Components\Projects\Helpers\Html::convertSize(floatval($model->config()->get('pubQuota', '1')), 'GB', 'b'); // Get total count $view->total = $objP->getCount($filters); $view->project = $model; $view->option = $this->_option; $view->title = isset($this->_area['title']) ? $this->_area['title'] : ''; return $view->loadTemplate(); }
} else { if ($row->state == 0) { $status = '<span class="faded italic">' . Lang::txt('Inactive/Suspended') . '</span> '; } else { if ($row->state == 5) { $status = '<span class="inactive">' . Lang::txt('Pending approval') . '</span> '; } } } } } $cloud = new \Components\Projects\Models\Tags($row->id); $tags = $cloud->render('cloud'); $params = new \Hubzero\Config\Registry($row->params); $quota = $params->get('quota', $this->defaultQuota); $quota = \Components\Projects\Helpers\Html::convertSize($quota, 'b', 'GB', 2); ?> <tr class="<?php echo "row{$k}"; ?> "> <td><?php echo Html::grid('id', $i, $row->id, false, 'id'); ?> </td> <td class="priority-5"><?php echo $row->id; ?> </td> <td class="priority-5"><?php echo '<img src="' . rtrim($base, DS) . DS . 'projects' . DS . $row->alias . '/media' . '" width="30" height="30" alt="' . $this->escape($row->alias) . '" />';
/** * Get available disk space * * @return integer */ public function getAvailableDiskSpace() { $pParams = Plugin::params('projects', 'files'); $projectParams = $this->get('project')->params; $quota = $this->get('project')->config()->get('defaultQuota', '1'); // Get disk usage $diskUsage = $this->call('getDiskUsage', $params = array('working' => true, 'history' => $pParams->get('disk_usage'))); // Get quota if (!isset($this->_quota)) { $this->_quota = $projectParams->get('quota') ? $projectParams->get('quota') : Helpers\Html::convertSize(floatval($quota), 'GB', 'b'); } return $this->_quota - $diskUsage; }
/** * 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(); } }