protected function manual_constructor()
 {
     $this->student_registration = STS_PageFormPerson::load_current_registration($this->person_id);
     $this->program = $this->student_registration["training_program"];
     $this->curr_semester = $this->student_registration["semester"];
     $this->reg_num = $this->student_registration["registration_number"];
 }
 /**
  * Create and load data for the objects used for this form.
  */
 protected function loadObjects()
 {
     $this->ff = I2CE_FormFactory::instance();
     //check to ensure that the current academic year is available
     iHRIS_AcademicYear::ensureAcademicYear();
     $selected_courses = $this->post("course");
     $person_id = $this->post("person_id");
     $curr_semester = $this->post("curr_semester");
     $student_registration = STS_PageFormPerson::load_current_registration($person_id);
     if (count($selected_courses) == 0) {
         $this->userMessage("No courses Selected!!!");
         $this->setRedirect("view?id=" . $this->person_id);
     }
     foreach ($selected_courses as $course) {
         $courseObj = $this->factory->createContainer($course);
         $courseObj->populate();
         $total_credits = $total_credits + $courseObj->getField("course_credits")->getDBValue();
     }
     $selected_courses = implode(",", $selected_courses);
     $where = array("operator" => "AND", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "parent", "style" => "equals", "data" => array("value" => $person_id)), 1 => array("operator" => "FIELD_LIMIT", "field" => "semester", "style" => "equals", "data" => array("value" => $curr_semester)), 2 => array("operator" => "FIELD_LIMIT", "field" => "registration", "style" => "equals", "data" => array("value" => $student_registration["id"]))));
     $enrolled_courses = I2CE_FormStorage::search("enroll_course", false, $where);
     if (count($enrolled_courses) > 0) {
         foreach ($enrolled_courses as $enrollment) {
             $course_enrollment_form = "enroll_course|" . $enrollment;
         }
     } else {
         $course_enrollment_form = "enroll_course";
     }
     if (!($enrollcourseObj = $this->ff->createContainer($course_enrollment_form)) instanceof I2CE_Form) {
         I2CE::raiseError("Invalid Object");
         return false;
     }
     $trainingCourseField = $enrollcourseObj->getField("training");
     $trainingCourseField->setFromPost($selected_courses);
     $date_enrolled = date("Y-m-d");
     $enrollcourseObj->getField("date_enrolled")->setFromDB($date_enrolled);
     $semesterField = $enrollcourseObj->getField("semester");
     $semesterField->setFromPost($curr_semester);
     $enrollcourseObj->getField("total_credits")->setValue($total_credits);
     $enrollcourseObj->getField("registration")->setFromDB($student_registration["id"]);
     $current_academic_year = iHRIS_AcademicYear::currentAcademicYear();
     $academic_year_id = iHRIS_AcademicYear::academicYearId($current_academic_year);
     $academic_year_id = "academic_year|" . $academic_year_id;
     if (!($academicYearField = $enrollcourseObj->getField("academic_year")) instanceof I2CE_FormField_MAP) {
         return;
     }
     $academicYearField->setFromDB($academic_year_id);
     $parentObj = $this->ff->createContainer($person_id);
     if ($parentObj instanceof I2CE_Form) {
         $parentObj->populate();
     }
     $this->setObject($enrollcourseObj, I2CE_PageForm::EDIT_PRIMARY);
     $this->setObject($parentObj, I2CE_PageForm::EDIT_PARENT);
     parent::save();
     $this->userMessage("Courses Enrolled Successfully");
     $this->setRedirect("view?id=" . $person_id);
     return true;
 }
 protected function getProgramAndSemester()
 {
     $this->student_registration = STS_PageFormPerson::load_current_registration($this->person_id);
     $this->date_registered = $this->student_registration["registration_date"];
     $this->program = $this->student_registration["training_program"];
     $this->curr_semester = $this->student_registration["semester"];
     $this->curr_level = $this->student_registration["academic_level"];
     $this->training_institution = $this->student_registration["training_institution"];
 }
 protected function appendExamTypesInput($tr, $reg_num, $person_id, $training_courses, $enroll_academic_year, $enroll_id)
 {
     foreach ($this->exam_types as $exam_type) {
         //check if results available
         $inputNodeHidden = 0;
         $results = $this->checkResults($exam_type, $person_id, $training_courses, $enroll_academic_year, $enroll_id);
         unset($mark);
         foreach ($results as $results_id => $mark) {
             //do nothing
         }
         $student_registration = STS_PageFormPerson::load_current_registration($person_id);
         //check if this course is in the current semester enrollment,if not,make it readonly
         $where = array("operator" => "AND", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "semester", "style" => "equals", "data" => array("value" => $student_registration["semester"])), 1 => array("operator" => "FIELD_LIMIT", "field" => "parent", "style" => "equals", "data" => array("value" => $person_id)), 2 => array("operator" => "FIELD_LIMIT", "field" => "training", "style" => "like", "data" => array("value" => "%" . $training_courses . "%")), 3 => array("operator" => "FIELD_LIMIT", "field" => "registration", "style" => "equals", "data" => array("value" => $student_registration["id"]))));
         $enrolls = I2CE_FormStorage::search("enroll_course", false, $where);
         if (count($enrolls) == 0) {
             $inputNode = $this->template->createElement("input", array("type" => "text", "name" => $exam_type . "/" . $reg_num, "value" => $mark, "readonly" => "true"));
             $inputNodeHidden = $this->template->createElement("input", array("type" => "hidden", "name" => $reg_num . "_results", "value" => $results_id));
             $this->template->appendNode($inputNodeHidden, $tr);
         } else {
             if ($mark == 0) {
                 $inputNode = $this->template->createElement("input", array("type" => "text", "name" => $exam_type . "/" . $reg_num, "size" => 4, "maxlength" => "5", "class" => "results"));
                 $errorNode = $this->template->createElement("span", array("class" => "error", "id" => $exam_type . "/" . $reg_num));
                 $this->template->appendNode($error, $inputNode);
             } else {
                 if ($mark > 0) {
                     $inputNode = $this->template->createElement("input", array("type" => "text", "name" => $exam_type . "/" . $reg_num, "value" => $mark, "readonly" => "true"));
                     $inputNodeHidden = $this->template->createElement("input", array("type" => "hidden", "name" => $reg_num . "_results", "value" => $results_id));
                     $this->template->appendNode($inputNodeHidden, $tr);
                 }
             }
         }
         $td = $this->template->createElement("td");
         $this->template->appendNode($errorNode, $td);
         $this->template->appendNode($inputNode, $td);
         $this->template->appendNode($td, $tr);
     }
 }
 /**
  * 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()
 {
     $this->student_registration = STS_PageFormPerson::load_current_registration($this->request("parent"));
     ###Deny drop semester for completed students###
     $progObj = $this->factory->createContainer($this->student_registration["training_program"]);
     $progObj->populate();
     if ($this->student_registration["admission_type"] == "admission_type|full-time") {
         $total_semesters = $progObj->getField("total_semesters_fulltime")->getDBValue();
     } else {
         if ($this->student_registration["admission_type"] == "admission_type|part-time") {
             $total_semesters = $progObj->getField("total_semesters_parttime")->getDBValue();
         }
     }
     $completed = IHS_PageFormEnrollcourse::completed_school($this->student_registration["semester"], $total_semesters, $this->request("parent"));
     if ($completed) {
         $this->userMessage("You Have Completed The Program");
         $this->setRedirect("view?id=" . $this->request("parent"));
         return;
     }
     ###End of denying drop semester for completed students###
     //check to ensure That A Student Must Resume Before Next Drop
     if ($this->get_exists("parent")) {
         $parent = $this->request("parent");
         $persObj = $this->factory->createContainer($parent);
         $persObj->populateChildren("drop_semester");
         foreach ($persObj->getChildren("drop_semester") as $dropSemObj) {
             if ($dropSemObj->getField("registration")->getDBValue() != $this->student_registration["id"]) {
                 continue;
             }
             $dropSemObj->populateChildren("resume_semester");
             $resSemObj = $dropSemObj->getChildren("resume_semester");
             if (count($resSemObj) == 0) {
                 $this->userMessage("This Student Is Currently Dropped In A Semester");
                 $this->setRedirect("view?id=" . $parent);
                 return;
             }
         }
         //avoid a student to drop a semester when GPA is already there
         $persObj->populateChildren("registration");
         $regObjs = $persObj->getChildren("registration");
         foreach ($regObjs as $regObj) {
             if ($regObj->getField("registration_status")->getDBValue() != "registration_status|ongoing") {
                 continue;
             }
             $semester = $regObj->getField("semester")->getDBValue();
         }
         $where = array("operator" => "AND", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "semester", "style" => "equals", "data" => array("value" => $semester)), 1 => array("operator" => "FIELD_LIMIT", "field" => "parent", "style" => "equals", "data" => array("value" => $parent)), 2 => array("operator" => "FIELD_LIMIT", "field" => "registration", "style" => "equals", "data" => array("value" => $this->student_registration["id"]))));
         $semGPA = I2CE_FormStorage::search("semester_GPA", false, $where);
         if (count($semGPA) > 0) {
             $this->userMessage("You Cant Drop This Semester");
             $this->setRedirect("view?id=" . $parent);
             return;
         }
     }
     if ($this->isPost()) {
         $primary = $this->factory->createContainer($this->getForm());
         if (!$primary instanceof I2CE_Form) {
             return false;
         }
         $primary->load($this->post);
     } elseif ($this->get_exists('id')) {
         if ($this->get_exists('id')) {
             $id = $this->get('id');
             if (strpos($id, '|') === false) {
                 I2CE::raiseError("Deprecated use of id variable");
                 $id = $this->getForm() . '|' . $id;
             }
         } else {
             $id = $this->getForm() . '|0';
         }
         $primary = $this->factory->createContainer($id);
         if (!$primary instanceof I2CE_Form || $primary->getName() != $this->getForm()) {
             I2CE::raiseError("Could not create valid " . $this->getForm() . "form from id:{$id}");
             return false;
         }
         $primary->populate();
     } elseif ($this->get_exists('parent')) {
         $primary = $this->factory->createContainer($this->getForm());
         if (!$primary instanceof I2CE_Form) {
             return;
         }
         $parent = $this->get('parent');
         if (strpos($parent, '|') === false) {
             I2CE::raiseError("Deprecated use of parent variable");
             $parent = 'person|' . $parent;
         }
         $primary->setParent($parent);
     }
     if ($this->isGet()) {
         $primary->load($this->get());
     }
     $person = parent::loadPerson($primary->getParent());
     if (!$person instanceof iHRIS_Person) {
         I2CE::raiseError("Could not create person form from " . $primary->getParent());
         return;
     }
     $this->applyLimits($primary);
     $this->setObject($primary, I2CE_PageForm::EDIT_PRIMARY, null, true);
     $this->setObject($person, I2CE_PageForm::EDIT_PARENT, null, true);
     return true;
 }
 /**
  * Save the objects to the database.
  * 
  * Save the default object being edited and return to the view page.
  * @global array
  */
 protected function save()
 {
     /**    
      * Check the number of semesters that have elapsed since this student dropped,if < 10 then a student may proceed,otherwise readmit to sem 			 1
      */
     $dropObj = $this->factory->createContainer("drop_semester");
     $dropObj->load($this->post);
     $resObj = $this->factory->createContainer("resume_semester");
     $resObj->load($this->post);
     $drp_sem_ac = $dropObj->getField("academic_year")->getDBValue();
     $drp_month = $dropObj->getField("drop_date")->getDBValue();
     $res_sem_ac = $resObj->getField("academic_year")->getDBValue();
     $drpacObj = $this->factory->createContainer($drp_sem_ac);
     $drpacObj->populate();
     $drp_sem_ac_name = $drpacObj->getField("name")->getDBValue();
     $resacObj = $this->factory->createContainer($res_sem_ac);
     $resacObj->populate();
     $res_sem_ac_name = $resacObj->getField("name")->getDBValue();
     $ac_year1 = explode("/", $drp_sem_ac_name);
     $ac_year1 = $ac_year1[0];
     $ac_year2 = explode("/", $res_sem_ac_name);
     $ac_year2 = $ac_year2[0];
     if ($drp_sem_ac_name != $res_sem_ac_name) {
         $res_month = $resObj->getField("resume_date")->getDBValue();
         $drp_month = explode("-", $drp_month);
         $drp_month = $drp_month[1];
         $res_month = explode("-", $res_month);
         $res_month = $res_month[1];
         $ac_year_diff = $ac_year2 - $ac_year1;
         if ($drp_month >= 7 and $drp_month <= 12) {
             $sem = $sem + 2;
         } else {
             if ($drp_month >= 1 and $drp_month <= 5) {
                 $sem = $sem + 1;
             }
         }
         if ($res_month >= 7 and $res_month <= 12) {
             $sem = $sem + 0;
         } else {
             if ($res_month >= 1 and $res_month <= 5) {
                 $sem = $sem + 1;
             }
         }
         $sem = $sem + ($ac_year_diff - 1) * 2;
     } else {
         $sem = 1;
     }
     //if a student resumes after 10 semesters have elapsed,take him/her to semester one
     if ($sem > 10) {
         $student_registration = STS_PageFormPerson::load_current_registration($this->person);
         //mark the ongoing registration as expired and create the new one
         $regObj = $this->factory->createContainer($student_registration["id"]);
         $regObj->populate();
         $regObj->getField("registration_status")->setFromDB("registration_status|expired");
         $regObj->getField("expire_date")->setFromDB($resObj->getField("resume_date")->getDBValue());
         $regObj->save($this->user);
         $regObj->cleanup();
         unset($regObj);
         //create the new registration
         $regObj = $this->factory->createContainer("registration");
         $regObj->populate();
         $regObj->getField("parent")->setFromDB($this->person);
         $regObj->getField("admission_type")->setFromDB($student_registration["admission_type"]);
         $regObj->getField("council_reg_num")->setFromDB($student_registration["council_reg_num"]);
         $regObj->getField("identification_number")->setFromDB($student_registration["identification_number"]);
         $regObj->getField("identification_type")->setFromDB($student_registration["identification_type"]);
         $regObj->getField("joined_semester")->setFromDB("semester|1");
         $regObj->getField("registration_number")->setFromDB($student_registration["registration_number"]);
         $regObj->getField("registration_status")->setFromDB("registration_status|ongoing");
         $regObj->getField("training_institution")->setFromDB($student_registration["training_institution"]);
         $regObj->getField("training_program")->setFromDB($student_registration["training_program"]);
         $reg_date = $resObj->getField("resume_date")->getDBValue();
         $reg_date = date("Y-m-d", strtotime($reg_date));
         $regObj->getField("registration_date")->setFromPost($reg_date);
         $regObj->getField("semester")->setFromDB("semester|1");
         $regObj->getField("academic_level")->setFromDB("academic_level|1");
         $regObj->getField("academic_year")->setFromDB($resObj->getField("academic_year")->getDBValue());
         $regObj->save($this->user);
         //add this student to the rejoin form for tracking info
         $ac_year_ended = $drp_sem_ac;
         $ac_year_rejoin = $res_sem_ac;
         $rejoin_reason = "rejoin_reason|dropped_semester";
         $rejoinObj = $this->factory->createContainer("rejoin");
         $rejoinObj->getField("academic_year_ended")->setFromDB($dropObj->getField("academic_year")->getDBValue());
         $rejoinObj->getField("academic_year_rejoin")->setFromDB($resObj->getField("academic_year")->getDBValue());
         $rejoinObj->getField("prev_registration")->setFromDB($student_registration["id"]);
         $rejoinObj->getField("new_registration")->setFromDB("registration|" . $regObj->getID());
         $rejoinObj->getField("rejoin_reason")->setFromDB($rejoin_reason);
         $rejoinObj->save($this->user);
     }
     $saved = parent::save();
     if ($saved !== false) {
         $message = "Student Resumed Successfully.";
     } else {
         $message = "This Student Has Not Been Resumed.";
     }
     $this->userMessage($message);
     $this->setRedirect("view?id=" . $this->person->getNameId());
     return $saved;
 }
 protected function getParentId($reg_num)
 {
     $where = array('operator' => 'FIELD_LIMIT', 'field' => "registration_number", 'style' => 'equals', 'data' => array('value' => $reg_num));
     $registrations = I2CE_FormStorage::ListFields('registration', array("parent"), false, $where);
     foreach ($registrations as $registration) {
         $this->person_id = $registration["parent"];
     }
     $this->student_registration = STS_PageFormPerson::load_current_registration($this->person_id);
     $this->date_registered = $this->student_registration["registration_date"];
     $this->training_program = $this->student_registration["training_program"];
     $this->training_institution = $this->student_registration["training_institution"];
     $this->curr_semester = $this->student_registration["semester"];
     $this->registered_academic_year = $this->student_registration["academic_year"];
     $instObj = $this->ff->createContainer($this->training_institution);
     $instObj->populate();
     $this->min_semester_GPA = $instObj->getField("minimum_semester_GPA")->getDBValue();
     $this->min_overall_GPA = $instObj->getField("minimum_overall_GPA")->getDBValue();
     $this->passing_score = $instObj->getField("passing_score")->getDBValue();
 }