Пример #1
0
 function getAddEditFormStructure($p_sMode = 'create', array $p_aOptions = array())
 {
     $structure = array('fields' => array('title' => array('type' => 'text', 'label' => 'Title', 'size' => 60), 'category_id' => array('type' => 'dropdown', 'label' => 'Category', 'options' => array()), 'ticket_type' => array('type' => 'dropdown', 'label' => 'Type', 'options' => array()), 'severity' => array('type' => 'dropdown', 'label' => 'Severity', 'options' => array()), 'status' => array('type' => 'dropdown', 'label' => 'Status', 'options' => array()), 'version' => array('type' => 'dropdown', 'label' => 'Version', 'options' => array()), 'assigned_user_id' => array('type' => 'dropdown', 'label' => 'Assign', 'options' => array()), 'content' => array('type' => 'textarea', 'label' => 'Description', 'rows' => 10, 'cols' => 40), 'submit' => array('type' => 'submit', 'label' => '', 'value' => 'Create Ticket')), 'rules' => array('title' => array('type' => 'required', 'message' => 'Title cannot be blank'), 'content' => array('type' => 'required', 'message' => 'You must enter a description')));
     if (isset($p_aOptions['isAdmin']) && $p_aOptions['isAdmin'] === false) {
         unset($structure['fields']['assigned_user_id']);
         unset($structure['fields']['severity']);
         unset($structure['fields']['status']);
         unset($structure['fields']['version']);
     } else {
         $structure['fields']['severity']['options'] = array('minor' => 'minor', 'major' => 'major', 'critical' => 'critical');
         $structure['fields']['status']['options'] = array('open' => 'open', 'assigned' => 'assigned', 'closed' => 'closed');
         $oUser = new APP_Model_User();
         $oTicket = new APP_Model_Ticket();
         $structure['fields']['version']['options'] = $this->convertGetListToDropdown($oTicket->getVersionsForFormStructure(), 'version');
         $structure['fields']['assigned_user_id']['options'] = $this->convertGetListToDropdown($oUser->getList(), array('first_name', ' ', 'last_name'));
     }
     $oTicketCat = new APP_Model_Ticket_Category();
     $structure['fields']['ticket_type']['options'] = array('feature_request' => 'Feature request', 'bug' => 'Bug', 'enhancement' => 'Enhancement');
     $structure['fields']['category_id']['options'] = $this->convertGetListToDropdown($oTicketCat->getList(), 'title');
     return $structure;
 }
Пример #2
0
 /**
  * AdminController::userAddEdit()
  * Add or Edit a user
  * @return void
  */
 protected function userAddEdit($p_sMode = 'create')
 {
     $bEdit = $p_sMode == 'edit';
     $oUser = new APP_Model_User();
     $oForm = new PPI_Model_Form();
     $oForm->init('admin_user_addedit');
     //$oForm->setTinyMCE(true);
     $oForm->setFormStructure($oUser->getAdminAddEditFormStructure($p_sMode));
     if ($oForm->isSubmitted()) {
         $aSubmitValues = $oForm->getSubmitValues();
         // Edit mode to set the primary key so that it performs an update
         if ($bEdit && ($iUserID = $this->oInput->get($p_sMode)) > 0) {
             $aSubmitValues[$oUser->getPrimaryKey()] = $iUserID;
         }
         // Security check
         if ($bEdit && $this->getAuthData(false)->role_id < $aSubmitValues[$oUser->getPrimaryKey()]) {
             throw new PPI_Exception('Permission error: You cannot modify user privileges higher than your own.');
         }
         // Unique field check
         $sUsernameField = $this->getConfig()->system->usernameField;
         $aUniqueFields = array('email');
         if ($sUsernameField != 'email') {
             $aUniqueFields[] = $sUsernameField;
         }
         foreach ($aUniqueFields as $sUniqueField) {
             $aClause = array($sUniqueField . ' = ' . $oUser->quote($aSubmitValues[$sUsernameField]));
             // If we're editing a user, make sure we're not checking against that same user (eg: we don't change the value)
             if ($bEdit) {
                 $aClause[] = $oUser->getPrimaryKey() . ' != ' . $oUser->quote($iUserID);
             }
             $aRecord = $oUser->getList(implode(' AND ', $aClause))->fetch();
             if (!empty($aRecord)) {
                 $oForm->setElementError($sUniqueField, 'Another user has this field, it must be unique');
             }
         }
         // Main validation check
         if ($oForm->isValidated()) {
             // Put the record (insert/update)
             $oUser->putRecord($aSubmitValues);
             /*
             $aAuthData = $this->getAuthData();
             foreach($aSubmitValues as $submitField => $submitValue) {
             	$aAuthData[$submitField] = $submitValue;
             }
             $aAuthData['role_name'] = PPI_Helper_User::getRoleNameFromID($aAuthData['role_id']);
             $aAuthData['role_name_nice'] = PPI_Helper_User::getRoleNameNice($aAuthData['role_name']);
             $this->getSession()->setAuthData($aAuthData);
             */
             $this->setFlashMessage('User account successfully ' . ($bEdit ? 'updated' : 'created') . '.');
             $this->redirect('admin/user');
         }
     }
     if ($bEdit === true) {
         if (($iUserID = $this->oInput->get('edit', 0)) < 1) {
             throw new PPI_Exception('Invalid User ID: ' . $iUserID);
         }
         // Set the defaults here
         $oForm->setDefaults($oUser->find($iUserID));
     }
     $aViewVars = array('bEdit' => $bEdit, 'formBuilder' => $oForm->getRenderInformation());
     $this->adminLoad('admin/user_addedit', $aViewVars);
 }
Пример #3
0
 /**
  * AdminController::userList()
  * List all the users
  * @return void
  */
 private function userList()
 {
     $oUser = new APP_Model_User();
     if (($iSchoolID = $this->oInput->get('schoolid', 0)) < 1) {
         throw new PPI_Exception('Missing School ID');
     }
     $users = $oUser->getList('school_id = ' . $iSchoolID)->fetchAll();
     // If there was a filter applied but returned no results, we default the userlist back to normal
     foreach ($users as $key => $user) {
         $users[$key]['role_name'] = ucwords(str_replace('_', ' ', getRoleNameFromID($user['role_id'])));
     }
     $this->addStylesheet(array('demo_table_jui.css', 'jquery-ui-1.7.2.custom.css'));
     $this->addJavascript('jquery.dataTables.js');
     $this->load('admin/user_list', array('schoolID' => $iSchoolID, 'users' => $users, 'navItems' => array('Add Staff' => 'admin/user/create/schoolid/' . $iSchoolID), 'pageTitle' => 'Users', 'usernameField' => $this->getConfig()->system->usernameField));
 }