* @copyright 2001-2007 VIKO team and contributors * @license http://www.gnu.org/licenses/gpl.html GPL 2.0 */ require_once 'Module.php'; require_once 'School.php'; require_once 'SchoolNameForm.php'; require_once 'HTML/QuickForm/Renderer/VIKO.php'; /** * Editing of school names * * */ class Module_SchoolEdit extends Module { /** * The school to be modified */ var $_school = null; /** * Constructs new SchoolEdit Module * * @param array $parameters parameters to the module */ function Module_SchoolEdit( $parameters ) { if ( isset($parameters[0]) && (int)$parameters[0] > 0 ) { $this->_school =& new School( (int)$parameters[0] ); } else { // fatal error: no school_id specified trigger_error("No school ID specified when editing school.", E_USER_ERROR); } } /** * Returns the module identifier string * * @access public * @static * @return string Identificator of module */ function getID() { return "school-edit"; } /** * Returns page in HTML * * @return string HTML fragment */ function toHTML() { // only admins are allowed to tinker with schools if ( !$_SESSION['user']->hasAccessToGroup("ADMIN") ) { return $this->accessDeniedPage( _("You are not authorized to add, edit or delete schools.") ); } // when editing, the school must exist if ( !$this->_school->loadFromDatabaseByID() ) { return $this->errorPage( _("The school you are trying to access does not exist.") ); } return $this->_editSchool(); } /** * Page for changing school name * * @access private * @return string HTML fragment */ function _editSchool() { $html_form = SchoolNameForm::createForm( $this->_school ); // translate the title $html = $this->title( _("Change school name") ); if ( $html_form->validate() ) { $this->_saveSchool( $html_form->exportValue('school-name') ); $html.= HTML::p( HTML::notice( _("School name successfully changed.") ) ); } else { // convert form to HTML $html .= HTML_QuickForm_Renderer_VIKO::render( $html_form ); } // backlink $html .= HTML::backLink( $this->URI("statistics"), _("Return to the list of all schools"), STANDALONE ); return $html; } /** * Saves the school * * @access private * @param string $school_name school name to use */ function _saveSchool( $school_name ) { $this->_school->setName( $school_name ); $this->_school->save(); } } ?>