public function validate_form_reschedule_course($form)
 {
     $semester = implode("|", $form->new_semester);
     $course = implode("|", $form->training);
     $academic_year = implode("|", $form->academic_year);
     $username = $this->getUser()->username;
     $training_institution = iHRIS_PageFormLecturer::fetch_institution($username);
     $where = array("operator" => "AND", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "academic_year", "style" => "equals", "data" => array("value" => $academic_year)), 1 => array("operator" => "FIELD_LIMIT", "field" => "training", "style" => "equals", "data" => array("value" => $course)), 2 => array("operator" => "FIELD_LIMIT", "field" => "training_institution", "style" => "equals", "data" => array("value" => $training_institution))));
     $is_rescheduled = I2CE_FormStorage::search("reschedule_course", false, $where);
     if (count($is_rescheduled) > 0) {
         $form->setInvalidMessage("training", "This Course Already Rescheduled For This Semester In This Academic Year");
     }
     $ff = I2CE_FormFactory::instance();
     if (!($courseObj = $ff->createContainer($course)) instanceof iHRIS_Training) {
         return;
     }
     $courseObj->populate();
     $crs_semester = $courseObj->getField("semester")->getDBValue();
     if ($crs_semester == $semester) {
         $form->setInvalidMessage("new_semester", "This Course Is Currently Offered In This Semester");
         return;
     }
     $sem = $form->new_semester[1];
     $crs_semester = explode("|", $crs_semester);
     $crs_semester = $crs_semester[1];
     if ($crs_semester > $sem or $sem - $crs_semester != 1) {
         $form->setInvalidMessage("new_semester", "A Course Must Be Rescheduled To A Next Semester");
     }
 }
 /**
  * Create and load data for the objects used for this form.
  * 
  * Create the list object and if this is a form submission load
  * the data from the form data.  It determines the type based on the
  * {@link $type} member variable.
  */
 protected function loadObjects()
 {
     if (!$this->hasPermission("task(can_edit_reschedule_course)") or $this->getUser()->role == "admin") {
         $this->setRedirect("noaccess");
     }
     if ($this->isPost()) {
         $primary = $this->factory->createContainer('reschedule_course');
         $course = $this->post["form"]["reschedule_course"][0][0]["fields"]["training"];
         $courseObj = $this->factory->createContainer($course);
         $courseObj->populate();
         $prev_sem = $courseObj->getField("semester")->getDBValue();
         $training_program = $courseObj->getField("training_program")->getDBValue();
         $this->post["form"]["reschedule_course"][0][0]["fields"]["old_semester"] = $prev_sem;
         $this->post["form"]["reschedule_course"][0][0]["fields"]["training_program"] = $training_program;
         $username = $this->getUser()->username;
         $inst_id = iHRIS_PageFormLecturer::fetch_institution($username);
         $this->post["form"]["reschedule_course"][0][0]["fields"]["training_institution"] = $inst_id;
         $primary->load($this->post);
     } else {
         $primary = $this->factory->createContainer('reschedule_course|0');
     }
     $username = $this->getUser()->username;
     $role = $this->getUser()->role;
     $this->applyLimits($primary, $inst_id, $role);
     $this->setObject($primary);
     return true;
 }
 protected function applyLimits($resAppObj)
 {
     $username = $this->getUser()->username;
     $user_info = iHRIS_PageFormLecturer::fetch_user_info($username);
     $inst_id = $user_info["training_institution"];
     $academic_year = iHRIS_AcademicYear::currentAcademicYear();
     $academic_year_id = iHRIS_AcademicYear::academicYearId($academic_year);
     $academic_year_id = "academic_year|" . $academic_year_id;
     ####################Limiting the display of training courses####################
     //get list of training that are having end of semester assessment
     $trng_prgrms = iHRIS_PageFormEnrollcourse::get_department_programs();
     $where = array("operator" => "AND", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "training_course_exam_type", "style" => "equals", "data" => array("training_course_exam_type|final")), 1 => array("operator" => "FIELD_LIMIT", "field" => "training_program", "style" => "in", "data" => array("value" => $trng_prgrms))));
     $trainings = I2CE_FormStorage::search("training", false, $where);
     foreach ($trainings as $training) {
         $training_courses[] = "training|" . $training;
     }
     //get list of courses assigned to lecturers
     $where = array("operator" => "AND", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "academic_year", "style" => "equals", "data" => array("value" => $academic_year_id)), 1 => array("operator" => "FIELD_LIMIT", "field" => "training_institution", "style" => "equals", "data" => array("value" => $inst_id))));
     $trainer_assigned_courses = I2CE_FormStorage::listFields("assign_course_trainer", array("training"), false, $where);
     $assigned_courses = array();
     if (is_array($trainer_assigned_courses)) {
         foreach ($trainer_assigned_courses as $crs) {
             $assigned_courses[] = $crs["training"];
         }
     }
     //get list of courses for which results have been uploaded
     $where = array("operator" => "AND", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "academic_year", "style" => "equals", "data" => array("value" => $academic_year_id)), 1 => array("operator" => "FIELD_LIMIT", "field" => "training", "style" => "in", "data" => array("value" => $training_courses))));
     $results = I2CE_FormStorage::listFields("students_results_grade", array("training"), false, $where);
     unset($training_courses);
     if (count($results) > 0) {
         foreach ($results as $id => $result) {
             //avoid displaying courses with results,but from other institutions
             if (!in_array($result["training"], $assigned_courses)) {
                 continue;
             }
             $course = explode("|", $result["training"]);
             $training_courses[] = $course[1];
         }
     }
     //end of getting list of courses for which results have been uploaded
     $where = array("operator" => "FIELD_LIMIT", "field" => "id", "style" => "in", "data" => array("value" => $training_courses));
     $course_field = $resAppObj->getField("training");
     $course_field->setOption(array("meta", "limits", "default", "training"), $where);
     #######################End of limiting the display of training courses###########################
     ####################Limiting the display of training institution######################
     $train_inst_id = explode("|", $inst_id);
     $train_inst_id = $train_inst_id[1];
     $where = array("operator" => "FIELD_LIMIT", "field" => "id", "style" => "equals", "data" => array("value" => $train_inst_id));
     $inst_field = $resAppObj->getField("training_institution");
     $inst_field->setOption(array("meta", "limits", "default", "training_institution"), $where);
     ####################End Limiting the display of training institution######################
     ###################Limiting the display of academic year###############################
     $ac_yr = explode("|", $academic_year_id);
     $ac_yr = $ac_yr[1];
     $where = array("operator" => "FIELD_LIMIT", "field" => "id", "style" => "equals", "data" => array("value" => $ac_yr));
     $acyr_field = $resAppObj->getField("academic_year");
     $acyr_field->setOption(array("meta", "limits", "default", "academic_year"), $where);
     ###################End of Limiting the display of acdemic year########################
 }
Ejemplo n.º 4
0
 /**
  * Create and load data for the objects used for this form.
  * 
  * Create the list object and if this is a form submission load
  * the data from the form data.
  */
 protected function loadObjects()
 {
     $role = $this->getUser()->role;
     if ($role != "registrar") {
         $this->userMessage("Only Registrar Can Add Students");
         $this->setRedirect("home");
     }
     //check to ensure that the current academic year is available
     iHRIS_AcademicYear::ensureAcademicYear();
     $username = $this->getUser()->username;
     $inst_id = iHRIS_PageFormLecturer::fetch_institution($username);
     $factory = I2CE_FormFactory::instance();
     if ($this->isPost()) {
         $person = $factory->createContainer("person");
         $person->load($this->post);
         $regObj = $factory->createContainer("registration");
         $regObj->load($this->post);
         $regObj->getField("training_institution")->setFromDB($inst_id);
         $regObj->getField("registration_status")->setFromDB("registration_status|ongoing");
         $program = $regObj->getField("training_program")->getDBValue();
         $st_reg_num = self::generateRegistrationNumber($program, $inst_id);
         $regObj->getField("registration_number")->setFromPost($st_reg_num);
     } else {
         if ($this->get_exists('id')) {
             $id = $this->get('id');
             if (strpos($id, '|') === false) {
                 I2CE::raiseError("Depcreated use of id variable");
                 $id = 'person|' . $id;
             }
         } else {
             $id = 'person|0';
         }
         $person = $factory->createContainer($id);
         if ($this->get_exists('id')) {
             $person->populateChildren("registration");
             foreach ($person->getChildren("registration") as $regObj) {
             }
         } else {
             $regObj = $this->factory->createContainer("registration|0");
         }
         if (!$person instanceof iHRIS_Person) {
             I2CE::raiseError("Could not create valid person form from id:{$id}");
             return;
         }
         $person->populate();
         $person->load($this->request());
     }
     $this->applyLimits($inst_id, $person, $regObj);
     $this->template->setForm($regObj);
     $this->template->setForm($person);
 }
 static function get_department_programs()
 {
     $ff = I2CE_FormFactory::instance();
     $pageObj = new I2CE_Page();
     $username = $pageObj->getUser()->username;
     $user_info = iHRIS_PageFormLecturer::fetch_user_info($username);
     $dep_id = $user_info["department"];
     $all_trng_prgrms = self::get_institution_programs();
     foreach ($all_trng_prgrms as $prgrms) {
         $progObj = $ff->createContainer($prgrms);
         $progObj->populate();
         if ($progObj->getField("department")->getDBValue() == $dep_id) {
             $trng_prgrms[] = $prgrms;
         }
     }
     return $trng_prgrms;
 }
 protected function action()
 {
     if (!$this->hasPermission("task(can_add_students_results)" or $this->getUser()->role == "admin")) {
         $this->setRedirect("noaccess");
         return;
     }
     $this->ff = I2CE_FormFactory::instance();
     //update academic year
     iHRIS_AcademicYear::ensureAcademicYear();
     //retrive the academic year
     $current_academic_year = iHRIS_AcademicYear::currentAcademicYear();
     $academic_year_id = iHRIS_AcademicYear::academicYearId($current_academic_year);
     $academic_year_id = "academic_year|" . $academic_year_id;
     $this->course_id = $this->request("id");
     $where_course_id = array("operator" => "AND", "operand" => array(0 => array('operator' => 'FIELD_LIMIT', 'field' => 'training', 'style' => 'like', 'data' => array('value' => "%" . $this->course_id . "%")), 1 => array('operator' => 'FIELD_LIMIT', 'field' => 'academic_year', 'style' => 'equals', 'data' => array('value' => $academic_year_id))));
     $parents = I2CE_FormStorage::listFields("enroll_course", array("parent", "training", "academic_year"), false, $where_course_id);
     if (!($listNode = $this->template->getElementByID("students_list")) instanceof DOMNode) {
         return;
     }
     if (!($hidden_data = $this->template->getElementByID("hidden_data")) instanceof DOMNode) {
         return;
     }
     if (count($parents) == 0) {
         $this->userMessage("No students enrolled for this course!!!");
         $this->setRedirect("add_results_select_course");
     }
     $input = $this->template->createElement("input", array("type" => "hidden", "name" => "course_id", "value" => $this->course_id));
     $this->template->appendNode($input, $listNode);
     $table = $this->template->createElement("table", array("class" => "multiFormTable", "width" => "100%", "border" => "0", "cellpadding" => "0", "cellspacing" => "0"));
     $tr = $this->template->createElement("tr");
     $th = $this->template->createElement("th", array("width" => "60%"), "Student Name");
     $this->template->appendNode($th, $tr);
     $th = $this->template->createElement("th", "", "Registration Number");
     $this->template->appendNode($th, $tr);
     $this->appendExamTypesHeaders($tr);
     $this->template->appendNode($tr, $table);
     //retrieving the max mark for each assessment
     foreach ($this->exam_types as $exam_type) {
         list($form, $id) = array_pad(explode("|", $exam_type, 2), 2, '');
         list($form, $course_id) = array_pad(explode("|", $this->course_id, 2), 2, '');
         $max_mark = I2CE_FormStorage::lookupField("training", $course_id, array($id), false);
         $max_mark = $max_mark[$id];
         $input = $this->template->createElement("input", array("type" => "hidden", "name" => $id, "id" => $id, "value" => $max_mark));
         $this->template->appendNode($input, $listNode);
     }
     //fecth lecturer institution to make sure can see students for his/her institution
     $username = $this->getUser()->username;
     $inst_id = iHRIS_PageFormLecturer::fetch_institution($username);
     foreach ($parents as $enroll_id => $parent) {
         $reg_details = STS_PageFormPerson::load_current_registration($person_id);
         ###drop students which are on different institution###
         if ($inst_id != $reg_details["training_institution"]) {
             continue;
         }
         $trainings = explode(",", $parent["training"]);
         $tr = $this->template->createElement("tr");
         $person_id = $parent["parent"];
         $reg_num = $this->getRegistrationNumber($person_id);
         $input = $this->template->createElement("input", array("type" => "hidden", "name" => "reg_num[" . $reg_num . "]", "value" => $reg_num));
         $this->template->appendNode($input, $tr);
         list($form, $id) = array_pad(explode("|", $person_id, 2), 2, '');
         $field_data = I2CE_FormStorage::lookupField("person", $id, array('firstname', 'surname'), false);
         if (is_array($field_data) && array_key_exists('surname', $field_data) && array_key_exists('firstname', $field_data)) {
             $fullname = $field_data['firstname'] . ' ' . $field_data['surname'];
             $aNode = $this->template->createElement("a", array("href" => "view?id=" . $person_id), $fullname);
             $td = $this->template->createElement("td");
             $this->template->appendNode($aNode, $td);
             $this->template->appendNode($td, $tr);
             $td = $this->template->createElement("td", array("id" => $reg_num, "align" => "center"));
             $this->template->addTextNode($reg_num, $reg_num, $td);
             $this->template->appendNode($td, $tr);
             $this->appendExamTypesInput($tr, $reg_num, $person_id, $this->course_id, $parent["academic_year"], $enroll_id);
         }
         $this->template->appendNode($tr, $table);
     }
     $tr = $this->template->createElement("tr");
     $td = $this->template->createElement("td", array("colspan" => "10", "align" => "right"));
     $input = $this->template->createElement("input", array("type" => "submit", "value" => "Save", "onclick" => "return verify()"));
     $this->template->appendNode($input, $td);
     $this->template->appendNode($td, $tr);
     $this->template->appendNode($tr, $table);
     $this->template->appendNode($table, $listNode);
 }
 protected function save()
 {
     $username = $this->getUser()->username;
     $training_institution = iHRIS_PageFormLecturer::fetch_institution($username);
     $assign_course_trainer = $this->factory->createContainer("assign_course_trainer");
     $assign_course_trainer->load($this->post);
     $assign_course_trainer->getField("training_institution")->setFromDB($training_institution);
     $lecturer = $assign_course_trainer->getField("lecturer")->getDBValue();
     $training_courses = $assign_course_trainer->getField("training")->getDBValue();
     $academic_year = $assign_course_trainer->getField("academic_year")->getDBValue();
     $training_courses = explode(",", $training_courses);
     $lecturers = explode(",", $lecturer);
     foreach ($lecturers as $lecturer) {
         foreach ($training_courses as $training_course) {
             //check if this course has been assigned for this lecturer
             $academic_year = iHRIS_AcademicYear::currentAcademicYear();
             $academic_year_id = iHRIS_AcademicYear::academicYearId($academic_year);
             $academic_year_id = "academic_year|" . $academic_year_id;
             $where_assigned = array("operator" => "AND", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "academic_year", "style" => "equals", "data" => array("value" => $academic_year_id)), 1 => array("operator" => "FIELD_LIMIT", "field" => "training", "style" => "equals", "data" => array("value" => $training_course)), 2 => array("operator" => "FIELD_LIMIT", "field" => "lecturer", "style" => "equals", "data" => array("value" => $lecturer)), 3 => array("operator" => "FIELD_LIMIT", "field" => "training_institution", "style" => "equals", "data" => array("value" => $training_institution))));
             $is_assigned = I2CE_FormStorage::search("assign_course_trainer", false, $where_assigned);
             if (count($is_assigned) > 0) {
                 continue;
             }
             $assign_course_trainer = $this->factory->createContainer("assign_course_trainer");
             $assign_course_trainer->getField("lecturer")->setFromDB($lecturer);
             $assign_course_trainer->getField("academic_year")->setFromDB($academic_year_id);
             $assign_course_trainer->getField("training")->setFromDB($training_course);
             $assign_course_trainer->getField("training_institution")->setFromDB($training_institution);
             /***alert HOD***/
             //get lecturer department
             $lectObj = $this->factory->createContainer($lecturer);
             $lectObj->populate();
             $lect_dep_id = $lectObj->getField("department")->getDBValue();
             //get course department
             $trainObj = $this->factory->createContainer($training_course);
             $trainObj->populate();
             $program = $trainObj->getField("training_program")->getDBValue();
             $progObj = $this->factory->createContainer($program);
             $progObj->populate();
             $course_dep_id = $progObj->getField("department")->getDBValue();
             $where = array("operator" => "AND", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "training_institution", "style" => "equals", "data" => array("value" => $training_institution)), 1 => array("operator" => "OR", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "department", "style" => "equals", "data" => array("value" => $lect_dep_id)), 1 => array("operator" => "FIELD_LIMIT", "field" => "department", "style" => "equals", "data" => array("value" => $course_dep_id)))), 2 => array("operator" => "FIELD_LIMIT", "field" => "role", "style" => "equals", "data" => array("value" => "role|hod"))));
             $hods = I2CE_FormStorage::listFields("lecturer", array("identification_number"), false, $where);
             $module_factory = I2CE_ModuleFactory::instance();
             $code = $trainObj->getField("code")->getDBValue();
             $course_name = $trainObj->getField("name")->getDBValue();
             $lect_fname = $lectObj->getField("first_name")->getDBValue();
             $lect_sname = $lectObj->getField("surname")->getDBValue();
             $lect_oname = $lectObj->getField("other_name")->getDBValue();
             $lect_name = $lect_fname . " " . $lect_oname . " " . $lect_sname;
             $lect_name = trim($lect_name);
             foreach ($hods as $hod) {
                 if ($module_factory->isEnabled("UserAlerts")) {
                     $alerts = $module_factory->getClass("UserAlerts");
                     $alerts->sendUserAlert($hod["identification_number"], 'notice', $code . "-" . $course_name . " Has Been Assigned To " . $lect_name, 'CustomReports/show/lecturer_assigned_courses', 'Vew Course Assignment Report');
                 } else {
                     I2CE::raiseError("Tried to send user alert, but the module isn't enabled.");
                 }
             }
             /***End of alerting HOD***/
             $assign_course_trainer->save($this->user);
         }
     }
     $this->userMessage("Course(s) Assigned To Trainer!!!");
     $this->setRedirect("assign_course_trainer");
 }