/** * 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); }
/** * AdminController::userAddEdit() * Add or Edit a user * @return void */ private function userAddEdit($p_sMode = 'create') { if (($iSchoolID = $this->oInput->get('schoolid', 0)) < 1) { throw new PPI_Exception('Invalid School ID: ' . $iSchoolID); } $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() && $oForm->isValidated()) { $aSubmitValues = $oForm->getSubmitValues(); // Setting the school ID when we insert the user if (!$bEdit) { $aSubmitValues['school_id'] = $iSchoolID; } // 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; } // Put the record (insert/update) $oUser->putRecord($aSubmitValues); $this->_setFlashMessage('User account successfully ' . ($bEdit ? 'updated' : 'created') . '.'); $this->_redirect('admin/user/list/schoolid/' . $iSchoolID); } else { 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(), 'leftMenu' => true); $this->loadSmarty('admin/user_addedit', $aViewVars); } }