// | Authors: João Prado Maia <*****@*****.**> | // +----------------------------------------------------------------------+ require_once dirname(__FILE__) . '/../../init.php'; $tpl = new Template_Helper(); $tpl->setTemplate('manage/field_display.tpl.html'); Auth::checkAuthentication(APP_COOKIE); $tpl->assign('type', 'field_display'); $prj_id = @$_GET['prj_id']; $role_id = Auth::getCurrentRole(); if ($role_id < User::ROLE_MANAGER) { Misc::setMessage(ev_gettext('Sorry, you are not allowed to access this page.'), Misc::MSG_ERROR); $tpl->displayTemplate(); exit; } if (count(@$_POST['fields']) > 0) { $res = Project::updateFieldDisplaySettings($prj_id, $_POST['fields']); $tpl->assign('result', $res); Misc::mapMessages($res, array(1 => array(ev_gettext('Thank you, the information was updated successfully.'), Misc::MSG_INFO), -1 => array(ev_gettext('An error occurred while trying to update the information.'), Misc::MSG_ERROR))); } $fields = Project::getDisplayFields(); $excluded_roles = array('viewer'); if (!CRM::hasCustomerIntegration($prj_id)) { $excluded_roles[] = 'customer'; } $user_roles = User::getRoles($excluded_roles); $user_roles[9] = 'Never Display'; $tpl->assign('prj_id', $prj_id); $tpl->assign('fields', $fields); $tpl->assign('user_roles', $user_roles); $tpl->assign('display_settings', Project::getFieldDisplaySettings($prj_id)); $tpl->displayTemplate();
/** * Returns display settings for a specific project. * * @access public * @param integer $prj_id The project ID * @return array An associative array of minimum role required to access a field. */ function getFieldDisplaySettings($prj_id) { $stmt = "SELECT\n pfd_field,\n pfd_min_role\n FROM\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_field_display\n WHERE\n pfd_prj_id = " . Misc::escapeInteger($prj_id); $res = $GLOBALS["db_api"]->dbh->getAssoc($stmt); if (PEAR::isError($res)) { Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); return -1; } $fields = Project::getDisplayFields(); foreach ($fields as $field_name => $field_title) { if (!isset($res[$field_name])) { $res[$field_name] = 0; } } return $res; }