Example #1
0
 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();
 }
Example #2
0
 /**
  * A method which allows the user to change their password if they are
  * logging in for the forst time.
  * @return unknown_type
  */
 public function change_password()
 {
     Application::addStylesheet("css/login.css");
     Application::$template = "login.tpl";
     Application::setTitle("Change Password");
     $form = new Form();
     $form->setRenderer("default");
     $password = new PasswordField("Password", "password");
     $form->add($password);
     $passwordRetype = new PasswordField("Retype Password", "password2");
     $form->add($passwordRetype);
     $form->setValidatorCallback($this->getClassName() . "::change_password_callback");
     $form->setShowClear(false);
     $form = $form->render();
     return "<h2>Change Password</h2>" . "<p>It appears that this is the first time you are logging in. " . "Please change your password.</p> {$form}";
 }
Example #3
0
 /**
  * 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("/");
     }
     $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();
 }
Example #4
0
 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();
 }