/** * @return Form */ public function create() { $form = new Form(); if ($this->translator) { $form->setTranslator($this->translator); } if ($this->renderer) { $form->setRenderer($this->renderer); } return $form; }
public function roles($params) { //Load necessary models $usersModel = Model::load("auth.users"); $usersRolesModel = Model::load("auth.users_roles"); $rolesModel = Model::load("auth.roles"); //required queries $user = $usersModel->getWithField("user_id", $params[0]); $usersRoles = $usersRolesModel->getWithField("user_id", $params[0]); $loggedInUsersRoles = $usersRolesModel->getWithField("user_id", $_SESSION['user_id']); $roles = $rolesModel->get(); $this->label = "Select Role(s) for " . $user[0]['first_name'] . " " . $user[0]['last_name']; //create a new form $form = new Form(); $form->setRenderer("table"); $fieldset = Element::create('ColumnContainer', 3); $form->add($fieldset); foreach ($roles as $role) { if ($role['role_id'] == 1) { //Boolean to determine if the outer foreach loop should "continue" particular loop or not $continueBool = false; //Loop through all the current user's foreach ($loggedInUsersRoles as $userRole) { if ($userRole['role_id'] == 1) { $continueBool = false; break; } else { $continueBool = true; } } if ($continueBool) { continue; } } $checkbox = Element::create("Checkbox", $role['role_name'], self::underscore($role['role_name']), "", $role['role_id']); foreach ($usersRoles as $userRole) { if ($userRole['role_id'] == $role['role_id']) { $checkbox->setValue($role['role_id']); } } $fieldset->add($checkbox); } $userIdHiddenField = Element::create("HiddenField", "user_id", $params[0]); $form->add($userIdHiddenField); $form->setValidatorCallback("{$this->getClassName()}::roles_callback"); $form->setShowClear(false); //render the form return $form->render(); }
/** * The default page which shows the login form. * @see lib/controllers/Controller#getContents() */ public function getContents() { Application::addStylesheet("css/login.css"); Application::$template = "login.tpl"; Application::setTitle("Login"); if ($_SESSION["logged_in"]) { Application::redirect(Application::getLink("/")); } $form = new Form(); $form->setRenderer("default"); $username = new TextField("Username", "username"); $form->add($username); $password = new PasswordField("Password", "password"); $form->add($password); $form->setSubmitValue("Login"); $form->setCallback("{$this->getClassName()}::callback", $this); return $form->render(); }
public function getContents() { // if(Configuration::get('attempt_counter') == null || Configuration::get('attempt_counter') === '0') // { // Configuration::set('attempt_counter',0); // } Application::addStylesheet("css/login.css"); Application::$template = "login.tpl"; Application::setTitle("Login"); if ($_SESSION["logged_in"]) { Application::redirect("/"); } $form = new Form(); $form->setRenderer("default"); $username = new TextField("Username", "username"); $form->add($username); $password = new PasswordField("Password", "password"); $password->setEncrypted(false); $form->add($password); $form->setSubmitValue("Login"); $form->setValidatorCallback("{$this->getClassName()}::callback"); $form->setShowClear(false); return $form->render(); }
public function constraints($params) { //Load necessary Models $roleModel = Model::load('auth.roles'); $constraintModel = Model::load('auth.constraints'); $role = $roleModel->getWithField('role_id', $params[0]); $constraints = $constraintModel->getWithField("role_id", "{$params['0']}"); //Label at the top of the inner template $this->label = "Login Constraints for the '" . $role[0]['role_name'] . "' role"; //create a new form $form = new Form(); $form->setRenderer("default"); //Fieldset to group days of week checkboxes $daysFieldset = Element::create('ColumnContainer', 7); //create checkbox fields and set their respective values $mon = Element::create("Checkbox", "Monday", "mon", "", "1"); $mon->setValue(($constraints[0]['days_of_week_value'] & 1) == 1 ? "1" : "0"); $daysFieldset->add($mon); $tue = Element::create("Checkbox", "Tuesday", "tue", "", "2"); $tue->setValue(($constraints[0]['days_of_week_value'] & 2) == 2 ? "2" : "0"); $daysFieldset->add($tue); $wed = Element::create("Checkbox", "Wednesday", "wed", "", "4"); $wed->setValue(($constraints[0]['days_of_week_value'] & 4) == 4 ? "4" : "0"); $daysFieldset->add($wed); $thu = Element::create("Checkbox", "Thursday", "thu", "", "8"); $thu->setValue(($constraints[0]['days_of_week_value'] & 8) == 8 ? "8" : "0"); $daysFieldset->add($thu); $fri = Element::create("Checkbox", "Friday", "fri", "", "16"); $fri->setValue(($constraints[0]['days_of_week_value'] & 16) == 16 ? "16" : "0"); $daysFieldset->add($fri); $sat = Element::create("Checkbox", "Saturday", "sat", "", "32"); $sat->setValue(($constraints[0]['days_of_week_value'] & 32) == 32 ? "32" : "0"); $daysFieldset->add($sat); $sun = Element::create("Checkbox", "Sunday", "sun", "", "64"); $sun->setValue(($constraints[0]['days_of_week_value'] & 64) == 64 ? "64" : "0"); $daysFieldset->add($sun); $form->add($daysFieldset); //FieldSet to group beginning time section $beginningTimeFieldset = Element::create('ColumnContainer', 2); //Starting times $timeRangeStartFieldSet = Element::create("FieldSet", "Beginning Time"); $hourStartSelection = Element::create("SelectionList", "Hour", "hour_start"); //add all options to the hour start selection field for ($i = 0; $i <= 23; $i++) { $hourStartSelection->addOption(sprintf("%02d", $i)); } //add hour start to begin time range field set $beginningTimeFieldset->add($hourStartSelection); $minuteStartSelection = Element::create("SelectionList", "Minutes", "minutes_start"); //add all options to the minute start selection field for ($i = 0; $i <= 59; $i++) { $minuteStartSelection->addOption(sprintf("%02d", $i)); } //add minute start to begin time range field set $beginningTimeFieldset->add($minuteStartSelection)->addAttribute('style', 'width:30%'); //Add the column container fieldset to the main fieldset $timeRangeStartFieldSet->add($beginningTimeFieldset); $endingTimeFieldset = Element::create('ColumnContainer', 2); //Ending times $timeRangeEndFieldSet = Element::create("FieldSet", "Ending Time"); $hourEndSelection = Element::create("SelectionList", "Hour", "hour_end"); //add all options to the hour end selection field for ($i = 0; $i <= 23; $i++) { $hourEndSelection->addOption(sprintf("%02d", $i)); } $endingTimeFieldset->add($hourEndSelection); $minuteEndSelection = Element::create("SelectionList", "Minutes", "minutes_end"); //add all options to the minute end selection field for ($i = 0; $i <= 59; $i++) { $minuteEndSelection->addOption(sprintf("%02d", $i)); } $endingTimeFieldset->add($minuteEndSelection)->addAttribute('style', 'width:30%'); //Add the column container fieldset to the main fieldset $timeRangeEndFieldSet->add($endingTimeFieldset); $modeSelection = new SelectionList("Mode", "mode"); $modeSelection->addOption("Allow", "allow"); $modeSelection->addOption("Deny", "deny"); $roleIdHiddenField = Element::create("HiddenField", "role_id", $params[0]); //populate fields with values from database if the data for that partular role already exists if ($constraints[0] != null) { $hourStartSelection->setValue(substr($constraints[0]['time_range_start'], 0, 2)); $hourEndSelection->setValue(substr($constraints[0]['time_range_end'], 0, 2)); $minuteStartSelection->setValue(substr($constraints[0]['time_range_start'], 3)); $minuteEndSelection->setValue(substr($constraints[0]['time_range_end'], 3)); $modeSelection->setValue($constraints[0]['mode']); } //Add components to the form $form->add($timeRangeStartFieldSet); $form->add($timeRangeEndFieldSet); $form->add($modeSelection); $form->add($roleIdHiddenField); $form->setValidatorCallback("{$this->getClassName()}::constraint_callback"); $form->setShowClear(false); //render the form return $form->render(); }
/** * Provides all the necessary forms needed to start an update. * @param $params * @return unknown_type */ public function import($params) { if ($params[0] == 'execute') { $this->doImport(); die; } $data = array(); $form = new Form(); $form->add(Element::create("FileUploadField", "File", "file", "Select the file you want to upload.")->setScript($this->urlPath . "/import/execute")->setJsExpression("wyf.showUploadedData(callback_data)"), Element::create("Checkbox", "Break on errors", "break_on_errors", "", "1")->setValue("1")); $form->setRenderer("default"); $form->addAttribute("style", "width:400px"); $form->setShowSubmit(false); $data["form"] = $form->render(); return array("template" => "file:" . getcwd() . "/lib/controllers/import.tpl", "data" => $data); }
/** * Provides all the necessary forms needed to start an update. * @param $params * @return string */ public function import() { $this->label = "Import " . $this->label; $entity = $this->model->getEntity(); $path = $this->urlPath; $form = new Form(); $form->setRenderer('default'); $form->add(Element::create("HTMLBox", "This import utility would assist you to import new {$entity} into your database. You are expected to upload a CSV file which contains the data you want to import." . " <p>Please click <a href='{$path}/export/csv?template=yes'>here</a> to download a template csv file.</p>"), Element::create("UploadField", "File", "file", "Select the file you want to upload.")); $form->addAttribute("style", "width:50%"); $form->setCallback($this->getClassName() . '::importCallback', $this); $form->setSubmitValue('Import Data'); return $this->arbitraryTemplate(Application::getWyfHome('utils/model_controller/templates/import.tpl'), array('form' => $form->render())); }