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"); } }
/** * Perform the actions of this page. * @return boolean */ protected function action() { if (parent::action()) { $next_month = getdate(mktime(0, 0, 0, $this->month + 1, 1, $this->year)); $db_start = sprintf('%04d-%02d-%02d', $this->year, $this->month, 1); $db_end = sprintf('%04d-%02d-%02d', $next_month['year'], $next_month['mon'], $next_month['mday']); $find_instances = array('operator' => 'OR', 'operand' => array(0 => array('operator' => 'AND', 'operand' => array(0 => array('operator' => 'FIELD_LIMIT', 'style' => 'greaterthan_equals', 'field' => 'start_date', 'data' => array('value' => $db_start)), 1 => array('operator' => 'FIELD_LIMIT', 'style' => 'lessthan', 'field' => 'start_date', 'data' => array('value' => $db_end)))), 1 => array('operator' => 'AND', 'operand' => array(0 => array('operator' => 'FIELD_LIMIT', 'style' => 'greaterthan_equals', 'field' => 'end_date', 'data' => array('value' => $db_start)), 1 => array('operator' => 'FIELD_LIMIT', 'style' => 'lessthan', 'field' => 'end_date', 'data' => array('value' => $db_end)))))); $instances = I2CE_FormStorage::search("scheduled_training_course", false, $find_instances); $factory = I2CE_FormFactory::instance(); $month_end = new DateTime($db_end); $deviation = 35; $base = array(70, 116, 149); foreach ($instances as $instance) { $rgb = array(); foreach ($base as $idx => $num) { $rgb[$idx] = rand($num - $deviation, $num + $deviation); } $inst = $factory->createContainer("scheduled_training_course|{$instance}"); $inst->populate(); $this->addForm($inst, $inst->start_date->getDateTimeObj(), $inst->end_date->getDateTimeObj(), 'calendar_training_course_day.html', $rgb); } } else { return false; } return true; }
/** * Check for duplicates and save the user alert * @param I2CE_User $user * @param boolean $transact * @return boolean */ public function save($user, $transact = true) { if ($this->getId() === '0') { $find_duplicates = array('operator' => 'AND', 'operand' => array(array('operator' => 'FIELD_LIMIT', 'field' => 'message', 'style' => 'lowerequals', 'data' => array('value' => strtolower($this->message))), array('operator' => 'FIELD_LIMIT', 'field' => 'time_ack', 'style' => 'null'), array('operator' => 'FIELD_LIMIT', 'field' => 'alert_type', 'style' => 'equals', 'data' => array('value' => $this->alert_type)))); if ($this->link == '') { $find_duplicates['operand'][] = array('operator' => 'FIELD_LIMIT', 'field' => 'link', 'style' => 'null'); } else { $find_duplicates['operand'][] = array('operator' => 'FIELD_LIMIT', 'field' => 'link', 'style' => 'equals', 'data' => array('value' => $this->link)); } if ($this->link_text == '') { $find_duplicates['operand'][] = array('operator' => 'FIELD_LIMIT', 'field' => 'link_text', 'style' => 'null'); } else { $find_duplicates['operand'][] = array('operator' => 'FIELD_LIMIT', 'field' => 'link_text', 'style' => 'lowerequals', 'data' => array('value' => strtolower($this->link_text))); } $found = I2CE_FormStorage::search('user_alert', $this->getParent(), $find_duplicates, array("-time_sent"), 1); if ($found) { I2CE::raiseMessage("found duplicates so increasing repeats. {$found}"); $duplicate = I2CE_FormFactory::instance()->createContainer("user_alert|" . $found); $duplicate->populate(); $duplicate->repeated++; return $duplicate->save($user, $transact); } } return parent::save($user, $transact); }
protected function loadObjects() { if (!$this->hasPermission("task(can_schedule_students_course_enrollment)") or $this->getUser()->role == "admin") { $this->setRedirect("noaccess"); } $factory = I2CE_FormFactory::instance(); $username = $this->getUser()->username; $training_institution = IHS_PageFormLecturer::fetch_institution($username); $where = array("operator" => "FIELD_LIMIT", "field" => "training_institution", "style" => "equals", "data" => array("value" => $training_institution)); $fields = I2CE_FormStorage::search("schedule_course_enrollment", false, $where); foreach ($fields as $id) { //do nothing } if ($id) { $form = "schedule_course_enrollment|" . $id; } else { $form = "schedule_course_enrollment"; } $courseEnrObj = $factory->createContainer($form); $courseEnrObj->populate(); if ($this->isPost()) { $courseEnrObj->load($this->post); } $courseEnrObj->getField("training_institution")->setFromDB($training_institution); $this->setObject($courseEnrObj); }
public static function getArchiveIds($reportView, $date = null) { $where = array('operator' => 'FIELD_LIMIT', 'field' => 'report_view', 'style' => 'equals', 'data' => array('value' => $reportView)); if ($date) { $where = array('operator' => 'AND', 'operand' => array($where, array('operator' => 'FIELD_LIMIT', 'field' => 'date', 'style' => 'equals', 'data' => array('value' => $date)))); } return I2CE_FormStorage::search('archived_report', false, $where); }
public function generate($node) { if (!$node instanceof DOMNode || !$this->primaryObject instanceof I2CE_Form || I2CE_PermissionParser::taskExists($this->options['task']) && !$this->page->hasPermission("task(" . $this->options['task'] . ")", $node) || !($linkedNode = $this->template->appendFileByNode($this->options['template'], 'div', $node)) instanceof DOMNode || !($tbodyNode = $this->template->getElementByName('child_fields', 0, $node)) instanceof DOMNode) { return false; } $added = 0; if (count($this->options['action_links']) > 0 && ($ulNode = $this->template->getElementByName('child_links', 0, $linkedNode)) instanceof DOMNode) { $added = $this->addLinks('li', $this->options['action_links'], $ulNode); } if ($added == 0 && ($containerNode = $this->template->getElementByName('child_actions', 0, $linkedNode)) instanceof DOMNode) { $this->template->removeNode($containerNode); } $this->template->setDisplayDataImmediate('child_title', $this->options['title'], $linkedNode); $dispDatas = array(); $arg_walker = array(); if ($this->options['printf'] && is_array($this->options['printf_args'])) { foreach ($this->options['printf_args'] as $i => &$arg) { $t_arg = explode(":", $arg); if (count($t_arg) > 1) { $arg_walker[$i] = $t_arg; $arg = $t_arg[0]; } } unset($arg); $dispDatas = I2CE_FormStorage::listDisplayFields($this->options['form'], $this->options['printf_args'], $this->primaryObject->getNameId(), $this->options['where'], $this->options['orders'], $this->options['limit']); $ids = array_keys($dispDatas); } else { $ids = I2CE_FormStorage::search($this->options['form'], $this->primaryObject->getNameId(), $this->options['where'], $this->options['orders'], $this->options['limit']); } if (count($ids) == 0) { return false; } foreach ($ids as $id) { $text = $this->options['title']; //default text for child in case printf wasn't set. if (array_key_exists($id, $dispDatas) && is_array($dispDatas)) { $dispFields = $dispDatas[$id]; foreach ($this->options['printf_args'] as $i => $arg) { $dispData[$i] = $dispFields[$arg]; } foreach ($arg_walker as $i => $fields) { $val = $dispData[$i]; $count = 0; foreach ($fields as $field) { $count++; if ($count == 1) { continue; } list($wform, $wid) = array_pad(explode('|', $val, 2), 2, ''); $val = I2CE_FormStorage::lookupField($wform, $wid, array($field), ''); } $dispData[$i] = $val; } $text = @vsprintf($this->options['printf'], $dispData); } $this->generateAjaxLink($id, $text, $tbodyNode); } }
/** * 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; }
public function action_drop_semester($page) { if (!$page instanceof iHRIS_PageView) { return false; } $template = $page->getTemplate(); $appendNode = $template->getElementById('drop_semester'); if (!$appendNode instanceof DOMNode) { return true; } $person = $page->getPerson(); if (!$person instanceof iHRIS_Person) { return false; } $factory = I2CE_FormFactory::instance(); $where = array("operator" => "FIELD_LIMIT", "field" => "parent", "style" => "equals", "data" => array("value" => "person|" . $person->getId())); $dropped_semIds = I2CE_FormStorage::search("drop_semester", false, $where); $drpsem = array(); foreach ($dropped_semIds as $id) { $dropSemForm = $factory->createContainer('drop_semester' . '|' . $id); $dropSemForm->populate(); $drpsem[] = $dropSemForm; } if (count($drpsem) == 0) { return false; } foreach ($drpsem as $child) { $node = $template->appendFileByNode('view_drop_semester.html', 'div', $appendNode); if (!$node instanceof DOMNode) { I2CE::raiseError("Could not find template {$template} for child form {$form} of person"); return false; } $template->setForm($child, $node); $child->populateChildren('resume_semester'); $resumes = $child->getChildren('resume_semester'); if (count($resumes) > 0) { $template->setDisplayDataImmediate('has_exam_results', 1, $node); foreach ($resumes as $resume) { if (!($resumeNode = $template->appendFileById('view_resume_semester.html', 'tbody', 'resume_semester', false, $node)) instanceof DOMNode) { continue; } $template->setForm($resume, $resumeNode); } } else { $template->setDisplayDataImmediate('has_resume_semester', 0, $node); } $drop_semester = $factory->createContainer($child->drop_semester); if (!$drop_semester instanceof iHRIS_DropSemester || $drop_semester->getId() == '0') { I2CE::raiseError("Bad Drop Semester:" . $child->drop_semester); continue; } $drop_semester->populate(); $template->setForm($drop_semester, $node); } }
protected function getSampleIDs() { if (!($argsChild = $this->getChild('args', false)) instanceof I2CE_Swiss_PageArgs || !($rel_obj = $argsChild->getRelationship()) instanceof I2CE_FormRelationship || !($form = $rel_obj->getForm('primary_form')) || !is_array($ids = I2CE_FormStorage::search($form, false, array(), array(), 5))) { return array(); } foreach ($ids as &$id) { $id = $form . '|' . $id; } unset($id); return $ids; }
/** *@returns array where keys are ids, values are arrays with the following keys 'value', 'display' */ public function getMapOptions($type = 'default', $show_hidden = 0, $flat = true, $add_limits = array()) { $form = $this->getContainer()->getName(); $ff = I2CE_FormFactory::instance(); $data = array(); foreach (I2CE_FormStorage::search($form) as $id) { if (!($formObj = $ff->createContainer($form . '|' . $id)) instanceof I2CE_List) { continue; } $formObj->populate(); $data[] = array('display' => $formObj->name() . ' [[' . $id . ']]', 'value' => "{$form}|{$id}"); } return $data; }
/** * Populate the member variables of the object from the database. */ public function populate() { parent::populate(); if ($this->trained_outside) { $this->out_cadre = $this->cadre; } else { $this->in_cadre = $this->cadre; $where_data = array('operator' => 'AND', 'operand' => array(array('operator' => 'FIELD_LIMIT', 'field' => 'training_institution', 'style' => 'equals', 'data' => array('value' => $this->getField("training_institution")->getDBValue())), array('operator' => 'FIELD_LIMIT', 'field' => 'cadre', 'style' => 'equals', 'data' => array('value' => $this->getField("in_cadre")->getDBValue())))); $training_program = I2CE_FormStorage::search('training_program', false, $where_data); if (count($training_program) > 0) { $this->getField("training_program")->setFromDB("training_program|" . $training_program[0]); } } }
protected function showCourses() { if (!($listNode = $this->template->getElementByID("existing_course_list")) instanceof DOMNode) { return; } if ($this->getUser()->role == "registrar" || $this->getUser()->role == "lecturer" || $this->getUser()->role == "hod" || $this->getUser()->role == "principal" || $this->getUser()->role == "deputy_principal") { ######getting id of the currently logged in lecturer###### $username = $this->getUser()->username; $where = array("operator" => "FIELD_LIMIT", "field" => "identification_number", "style" => "equals", "data" => array("value" => $username)); $lecturer = I2CE_FormStorage::search("lecturer", false, $where); foreach ($lecturer as $id) { $lecturer_id = "lecturer|" . $id; } ######Getting the current academic year###### $academic_year = iHRIS_AcademicYear::currentAcademicYear(); $where = array("operator" => "FIELD_LIMIT", "field" => "name", "style" => "equals", "data" => array("value" => $academic_year)); $academic_year_id = I2CE_FormStorage::Search("academic_year", false, $where); $academic_year_id = "academic_year|" . $academic_year_id[0]; ######Getting a list of courses assigned to this lecturer###### $where_assign_course = array("operator" => "AND", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "lecturer", "style" => "equals", "data" => array("value" => $lecturer_id)), 1 => array("operator" => "FIELD_LIMIT", "field" => "academic_year", "style" => "equals", "data" => array("value" => $academic_year_id)))); $assigned_courses = I2CE_FormStorage::listFields("assign_course_trainer", array("training"), false, $where_assign_course); } else { $this->userMessage("Login as a training provider to add results"); $this->redirect("manage?action=provider"); return false; } ######Displaying courses assigned to this lecturer###### if (count($assigned_courses) == 0) { $this->userMessage("No courses assigned to you,contact the Registrar for further assistance"); $this->redirect("manage?action=provider"); return false; } foreach ($assigned_courses as $id => $course) { $course_id = explode("|", $course["training"]); $course_id = $course_id[1]; $where = array("operator" => "FIELD_LIMIT", "field" => "id", "style" => "equals", "data" => array("value" => $course_id)); $training_courses = I2CE_FormStorage::ListFields("training", array("name", "code"), false, $where); foreach ($training_courses as $id => $training_course) { $course_name = $training_course["name"]; $course_code = $training_course["code"]; $course = $course_code . "-" . $course_name; $id = "training|" . $id; $aNode = $this->template->createElement("a", array(href => "add_results?id=" . $id), $course); $liNode = $this->template->createElement("li"); $this->template->appendNode($aNode, $liNode); $this->template->appendNode($liNode, $listNode); } } }
protected function resaveTrainings() { $user = new I2CE_User(); $ff = I2CE_FormFactory::instance(); $ids = I2CE_FormStorage::search('person_scheduled_training_course'); foreach ($ids as $id) { I2CE::longExecution(); //to make sure we don't time out if (!($pstc = $ff->createContainer(array('person_scheduled_training_course', $id))) instanceof iHRIS_Person_Scheduled_Training_Course) { return false; //something is wrong } $pstc->populate(); //populate will recacluate the average field $pstc->save($user); //saves the new calculated average field to the databse $pstc->cleanup(); //free up memory } return true; }
/** * Perform the main actions of the page. */ protected function action() { parent::action(); $factory = I2CE_FormFactory::instance(); if ($this->type == "health_facility") { $where_data = array('operator' => 'FIELD_LIMIT', 'field' => 'health_facility', 'style' => 'equals', 'data' => array('value' => $this->list->getNameId())); $institutions = I2CE_FormStorage::search('facility_institution', false, $where_data); //$institutions = iHRIS_FacilityInstitution::search( "health_facility", $this->id ); foreach ($institutions as $id) { $obj = $factory->createContainer("facility_institution|" . $id); $obj->populate(); if ($obj->active == 1) { $node = $this->template->appendFileById("view_list_hf_ti.html", "span", "training_institution"); $obj->getField("training_institution")->setHref("view_list?type=training_institution&id="); $this->template->setForm($obj, $node); } } } elseif ($this->type == "training_institution") { $where_data = array('operator' => 'FIELD_LIMIT', 'field' => 'training_institution', 'style' => 'equals', 'data' => array('value' => $this->list->getNameId())); $facilities = I2CE_FormStorage::search('facility_institution', false, $where_data, array("health_facility")); //$facilities = iHRIS_FacilityInstitution::search( "training_institution", $this->id ); foreach ($facilities as $id) { $obj = $factory->createContainer("facility_institution|" . $id); $obj->populate(); if ($obj->active == 1) { $node = $this->template->appendFileById("view_list_ti_hf.html", "span", "health_facility"); $obj->getField("health_facility")->setHref("view_list?type=health_facility&id="); $this->template->setForm($obj, $node); } } $where_data = array('operator' => 'FIELD_LIMIT', 'field' => 'training_institution', 'style' => 'equals', 'data' => array('value' => $this->list->getNameId())); $programs = I2CE_FormStorage::search('training_program', false, $where_data); foreach ($programs as $id) { $obj = $factory->createContainer("training_program|" . $id); $obj->populate(); $node = $this->template->appendFileById("view_list_training_program.html", "div", "training_program"); $this->template->setForm($obj, $node); } } }
function getFormObjByWhere($form, $where) { global $form_factory; $formIds = I2CE_FormStorage::search($form, false, $where); if (count($formIds) > 1) { //I2CE::raiseError("Ambigous lookup for form $form:" . print_r($where,true)); return null; //the above should die but who knows. } else { if (count($formIds) == 1) { reset($formIds); $formObj = $form_factory->createForm($form . '|' . current($formIds)); if (!$formObj instanceof I2CE_Form) { return null; } $formObj->populate(); return $formObj; } else { return null; } } }
/** * update value of each instanceo of a given form field by a pho function call * @param I2CE_FormField $form_field * @param array $where Array of where data * @param callable $set_func */ public function globalFieldUpdateByFunction($form_field, $where, $set_func) { $formObj = $form_field->getContainer(); if (!$formObj instanceof I2CE_Form) { I2CE::raiseError("Field has no container"); return false; } $form = $formObj->getName(); $field = $form_field->getName(); $ff = I2CE_FormFactory::instance(); $ids = I2CE_FormStorage::search($form, true, $where); $user = new I2CE_User(); foreach ($ids as $id) { if (!($obj = $ff->createForm($form . '|' . $id)) instanceof I2CE_Form) { continue; } $obj->populate(); $data = array(); foreach ($obj as $fieldName => $fieldObj) { if (!$fieldObj instanceof I2CE_FormField) { continue; } $data[$fieldName] = $fieldObj->getDBValue(); } $data['parent'] = $obj->getParentID(); $fieldObj->setFromDB($set_func($data[$form_field->getName()])); $obj->save($user); $obj->cleanup(); } return true; }
/** * Lookup a degree with the given edu_type * @param string $degree * @param string $edu_type * @return string */ protected function lookupDegree($degree, $edu_type) { $degree = strtolower(trim($degree)); if (!array_key_exists("degree", $this->cache)) { $this->cache["degree"] = array(); } if (!array_key_exists($edu_type, $this->cache["degree"])) { $this->cache["degree"][$edu_type] = array(); } if (!array_key_exists($degree, $this->cache["degree"][$edu_type])) { $where = array('operator' => 'AND', 'operand' => array(array('operator' => 'FIELD_LIMIT', 'field' => 'edu_type', 'style' => 'equals', 'data' => array('value' => $edu_type)), array('operator' => 'FIELD_LIMIT', 'style' => 'lowerequals', 'field' => 'name', 'data' => array('value' => $degree)))); $id = I2CE_FormStorage::search("degree", false, $where, array(), true); if ($id) { $this->cache["degree"][$edu_type][$degree] = "degree|{$id}"; } else { $this->cache["degree"][$edu_type][$degree] = ""; } } return $this->cache["degree"][$edu_type][$degree]; }
public function getScheduledStudentIds() { if ($this->id == 0) { return array(); } $where = array('operator' => 'AND', 'operand' => array(0 => array('operator' => 'FIELD_LIMIT', 'field' => 'scheduled_training_course', 'style' => 'equals', 'data' => array('value' => $this->getNameId())), 1 => array('operator' => 'OR', 'operand' => array(0 => array('operator' => 'FIELD_LIMIT', 'field' => 'attending', 'style' => 'equals', 'data' => array('value' => 1)), 1 => array('operator' => 'FIELD_LIMIT', 'field' => 'attending', 'style' => 'null', 'data' => array()))))); return I2CE_FormStorage::search('person_scheduled_training_course', false, $where); }
protected function is_approved($results_academic_year, $course) { $academic_year = iHRIS_AcademicYear::currentAcademicYear(); $academic_year_id = iHRIS_AcademicYear::academicYearId($academic_year); $academic_year_id = "academic_year|" . $academic_year_id; if ($results_academic_year != $academic_year_id) { return true; } $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" => "like", "data" => array("value" => "%" . $course . "%")), 2 => array("operator" => "FIELD_LIMIT", "field" => "training_institution", "style" => "equals", "data" => array("value" => $this->student_registration["training_institution"])))); $is_approved = I2CE_FormStorage::search("results_approval", false, $where); if (count($is_approved) > 0) { return true; } return false; }
/** * @param string $form The form name. *@param mixed $where_data. Either I2CE_MagicDataNode or array. contains the where clause information about this form or a nested * @param array $ordering. An array of fields to order by. Defaults to the empty array. Prepend a - to order by in descending order. * @param mixed $limit. Defaults to false. It true, returns only one result. If an integer it is the numeber of records to limit to. * If it is as an array of two integers, it is the offset and then number of results to limit to. * @returns mixed an array of matching form ids. However, ff $limit_one is true or 1 or * array ($offset,1) then then we return either the id or false, if none found or there was an error. */ public static function search($form, $where_data = array(), $ordering = array(), $limit_one = false) { if (is_string($ordering)) { $ordering = array($ordering); } if (!is_array($ordering)) { $ordering = array(); } if (I2CE_ModuleFactory::instance()->isEnabled('forms-storage')) { return I2CE_FormStorage::search($form, $where_data, $ordering, $limit_one); } else { $limit = false; if (is_array($limit_one)) { if (count($limit_one) == 2) { end($limit_one); if (current($limit_one) == 1) { $limit = true; } } } else { $limit = $limit_one === true || is_numeric($limit_one) && $limit_one == 1; } if ($limit_one) { return false; } else { return array(); } } }
/** * Checks to make sure all the required fields are valid. * * Checks to make sure the username is unique in the system and that the password matches the confirmed password. * @global array */ public function validate() { parent::validate(); if ($this->id == '0') { if (I2CE_User::userExists($this->username, false)) { $this->setInvalidMessage('username', 'unique'); } } if (strlen($this->password) > 0 && $this->password != $this->confirm) { $this->setInvalidMessage('password', 'mismatch'); } if ($this->id == '0' && $this->password == "" && !$this->generate_password) { $this->setInvalidMessage('password', 'required'); } $saving_user = new I2CE_User('0', true, true, false); if ($saving_user->role != 'admin') { // Allow anyone to set the self service role $role_field = $this->getField('role'); $role_val = $role_field->getDBValue(); $role_val = str_replace('role|', '', $role_val); if ($saving_user->role != $role_val) { $default_ss = ''; I2CE::getConfig()->setIfIsSet($default_ss, "/modules/SelfService/default_user_role"); if ($role_val != $default_ss) { $where = array('operator' => 'AND', 'operand' => array(array('operator' => 'FIELD_LIMIT', 'field' => 'assignable', 'style' => 'yes'), array('operator' => 'FIELD_LIMIT', 'field' => 'trickle_up', 'style' => 'equals', 'data' => array('value' => $saving_user->role)), array('operator' => 'FIELD_LIMIT', 'field' => 'id', 'style' => 'equals', 'data' => array('value' => $role_val)))); $results = I2CE_FormStorage::search('role', false, $where); if (count($results) == 0) { $this->setInvalidMessage('role', 'notallowed'); } } } } }
/** * Get the person instance ID if it exists * @param string $person * @param string $instance * @return integer */ protected function getPersonInstance($person, $instance) { $where_data = array('operator' => 'FIELD_LIMIT', 'field' => 'provider_instance', 'style' => 'equals', 'data' => array('value' => $instance)); $participants = I2CE_FormStorage::search('person_instance', $person, $where_data, array(), 1); return $participants; }
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); } }
/** * Find and return the most recent position held by this person. * * @return I2CE_Form or null */ public function getLastPosition($person) { if (!$person instanceof iHRIS_Person) { return null; } $where = array('operator' => 'FIELD_LIMIT', 'field' => 'end_date', 'style' => 'null'); $per_pos_id = I2CE_FormStorage::search('person_position', $person->getNameId(), $where, '-start_date', 1); if (!$per_pos_id) { return null; } $pos = I2CE_FormFactory::instance()->createContainer('person_position' . '|' . $per_pos_id); if (!$pos instanceof iHRIS_PersonPosition) { return null; } $pos->populate(); return $pos; }
public function getLastSalary($formObj) { if (!$formObj instanceof iHRIS_PersonPosition) { return null; } $sal_id = I2CE_FormStorage::search('salary', $formObj->getNameId(), array(), '-start_date', 1); if (!$sal_id) { return null; } $sal = I2CE_FormFactory::instance()->createContainer('salary' . '|' . $sal_id); if (!$sal instanceof iHRIS_Salary) { return null; } $sal->populate(); return $sal; }
/** * Gets the list (in the format of {I2CE_FormStorage::listFields()} of allowed confirmations for the indicated person * @param iHRIS_Person $person * @param boolean $only_new. Defaults to false. it true, we only check for confirmations that this person does not already have * @returns array */ public function getAllowedConfirmations($person, $only_new = false) { if (!$person instanceof iHRIS_Person) { return array(); } $allowed = array(); $conf_type_fields = array('name', 'job', 'probation_period'); $confirmations = I2CE_FormStorage::listFields('confirmation_type', $conf_type_fields); if (count($confirmations) == 0) { return array(); } foreach ($confirmations as $id => $vals) { $job = false; if (array_key_exists('job', $vals) && $vals['job']) { $job = $vals['job']; } //there is no job associted to this confirmation, all positions are valid. $where = array('operator' => 'FIELD_LIMIT', 'field' => 'start_date', 'style' => 'not_null'); if ($job) { $pers_positions = I2CE_FormStorage::listFields('person_position', array('start_date', 'position'), $person->getNameId(), $where, 'start_date'); if (!is_array($pers_positions) || count($pers_positions) == 0) { continue; } $position = false; foreach ($pers_positions as $pp_id => $pp_data) { //we need to check if this posiiton has the correct job $pos_id = substr($pp_data['position'], 9); if (!$pos_id || !($pos_job = I2CE_FormStorage::lookupField('position', $pos_id, 'job'))) { continue; } if ($pos_job != $job) { continue; } $position = $pp_data; break; } if (!$position) { //no mathching posiiton continue; } } else { $positions = I2CE_FormStorage::listFields('person_position', array('start_date'), $person->getNameId(), $where, 'start_date', 1); if (!is_array($positions) || count($positions) == 0) { //person has no valid positions continue; } reset($positions); $position = current($positions); } if (array_key_exists('probation_period', $vals) && $vals['probation_period'] > 0) { if (!array_key_exists('start_date', $position) || !$position['start_date']) { //there was never a position for which can consider this person valid continue; } //now we need to check the probationary period $pos_start_date = I2CE_Date::fromDB($position['start_date']); if (!$pos_start_date->isValid()) { continue; } //probation period is measure in months. this is an approximation. we really need to use the php 5.3 date time class. $prob_valid_month = mktime(0, 0, 0, date("m") - (int) $vals['probation_period'], date("d"), date("Y")); if ($prob_valid_month === false) { I2CE::raiseError("Difficulty in calculating date offest"); continue; } $prob_valid = I2CE_Date::now(I2CE_Date::DATE, $prob_valid_month); if (!$prob_valid->isValid() || $prob_valid->before($pos_start_date)) { //comprare returns -1 if $prob_valid is before $pos_start_data continue; } //we have a position which is valid for this confirmation type } if ($only_new) { $confirm_where = array('operator' => 'FIELD_LIMIT', 'field' => 'confirmation_type', 'style' => 'equals', 'data' => array('value' => 'confirmation_type|' . $id)); if (count(I2CE_FormStorage::search('confirmation', $person->getNameId(), $confirm_where)) > 0) { continue; } } //we made it to here, then the confirmation type is allowed $allowed[$id] = $vals; } return $allowed; }
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######################## }
static function get_institution_programs() { $pageObj = new I2CE_Page(); $username = $pageObj->getUser()->username; $training_institution = IHS_PageFormLecturer::fetch_institution($username); $where = array("operator" => "FIELD_LIMIT", "field" => "training_institution", "style" => "like", "data" => array("value" => "%" . $training_institution . "%")); $prgrms = I2CE_FormStorage::search("training_program", false, $where); foreach ($prgrms as $prgrm) { $trng_prgrms["training_program|" . $prgrm] = "training_program|" . $prgrm; } return $trng_prgrms; }
protected function find_matching($form_obj) { $wheres = array(); foreach ($form_obj as $field_name => $field_obj) { if (!$field_obj instanceof I2CE_FormField || !$field_obj->hasOption('unique') || !$field_obj->getOption('unique')) { continue; } if (!$field_obj->hasOption('unique_field')) { if ($field_obj->isValid()) { $wheres[] = array('operator' => 'FIELD_LIMIT', 'style' => 'equals', 'field' => $field_obj->getName(), 'data' => array('value' => $field_obj->getDBValue())); } } else { $unique = $field_obj->getOption('unique_field'); $unique_fields = explode(',', $unique); foreach ($unique_fields as $unique_field) { //we need to say that this is unique only up to the other values if (strpos($unique_field, ':') !== false) { $main_where = array('operator' => 'FIELD_LIMIT', 'style' => 'equals', 'field' => $field_obj->getName(), 'data' => array('value' => $field_obj->getDBValue())); $field_path = explode(':', $unique_field); $restricted_field = false; if (preg_match('/^\\[(.*?)\\](.*)$/', $field_path[0])) { $restricted_field = $matches[1]; $field_path[0] = $matches[2]; } else { if (preg_match('/^(.*?)\\+(.*)$/', $field_path[0], $matches)) { $restricted_field = $matches[1]; } else { $restricted_field = $field_path[0]; } } $restricted_field_obj = $form_obj->getField($restricted_field); if (!$restricted_field_obj instanceof I2CE_FormField_MAP) { $this->raiseError("Invalid field passed as restricted field for " . $form_obj->getName() . ": {$unique_field}"); return; } if ($restricted_field_obj->hasHeader('default')) { $names[] = $restricted_field_obj->getHeader('default'); } else { $names[] = $restricted_field_obj->getName(); } //now let's split up field_path into the forms and the fields $top_formid = I2CE_List::walkupFieldPath($field_path, $restricted_field_obj->getDBValue()); if ($top_formid === false) { //the value is not set. or inappropriately set. error silently. //this is handled by hooked method defined in I2CE_Module_Form. return; } //now we get all forms under $top_formid defined by the field path $field_name = $field_obj->getName(); $field_val = $field_obj->getDBValue(); $form_id = $form_obj->getID(); $dtree_path = $field_path; array_unshift($dtree_path, $form_obj->getName()); list($top_form, $top_id) = explode('|', $top_formid, 2); $dtree_limits = array($top_form => array('operator' => 'FIELD_LIMIT', 'style' => 'equals', 'field' => 'id', 'data' => array('value' => $top_id)), $form_obj->getName() => $main_where); $options = I2CE_List::buildDataTree($dtree_path, array($form_obj->getName()), $dtree_limits); $options = I2CE_List::flattenDataTree($options); if (count($options) == 1) { // There is exactly one match. we should use it $matched_id = $options[0]['value']; return $this->factory->createContainer($matched_id); } } else { if (!($unique_field_obj = $form_obj->getField($unique_field)) instanceof I2CE_FormField) { $this->raiseError("Invalid field {$unqiue_field}"); return; } if ($unique_field_obj->isValid()) { $wheres[] = array('operator' => 'FIELD_LIMIT', 'style' => 'equals', 'field' => $unique_field_obj->getName(), 'data' => array('value' => $unique_field_obj->getDBValue())); } else { $wheres[] = array('operator' => 'OR', 'operand' => array(0 => array('operator' => 'FIELD_LIMIT', 'style' => 'equals', 'field' => $unique_field_obj->getName(), 'data' => array('value' => $unique_field_obj->getDBValue())), 1 => array('operator' => 'FIELD_LIMIT', 'style' => 'null', 'field' => $unique_field_obj->getName()))); } } } } } if (count($wheres) == 0) { //no matching conditions. don't try to do anything return false; } else { if (count($wheres) > 1) { $where = array('operator' => 'AND', 'operand' => $wheres); } else { $where = current($wheres); } } if (!($id = I2CE_FormStorage::search($form_obj->getName(), false, $where, array(), true))) { return false; } $form_obj = $this->factory->createContainer(array($form_obj->getName(), $id)); //$form_obj->populate(); return $form_obj; }
protected function doRemap($form, $field, $id) { $obj = $this->ff->createContainer($id); if (!$obj instanceof I2CE_List) { $this->pushError("ID {$id} does not refer to a list"); //needs to be localized return false; } $obj->populate(); $newform = '0'; $newid = '0'; $rField = $obj->getField('remap'); if (!$rField instanceof I2CE_FormField_REMAP || !($newform = $rField->getMappedForm()) || !($newid = $rField->getMappedID())) { $this->pushError("No remapping data has been set for {$id} [{$newform}|{$newid}]" . get_class($rField)); return false; } $where = array('operator' => 'FIELD_LIMIT', 'field' => $field, 'style' => 'equals', 'data' => array('value' => $id)); if (($count = count($remapIDs = I2CE_FormStorage::search($form, false, $where))) < 1) { $this->pushMessage("No fields found to remap"); return true; } $this->pushCount($count); $exec = array('max_execution_time' => 20 * 60, 'memory_limit' => 256 * 1048576); $user = new I2CE_User(); $success = true; foreach ($remapIDs as $i => $remapID) { I2CE::longExecution($exec); if (!($remapObj = $this->ff->createContainer($form . '|' . $remapID)) instanceof I2CE_Form) { $this->pushMessage("Could not create {$form}|{$remapID}", $i + 1); $success = false; continue; } $remapObj->populate(); if (!($fieldObj = $remapObj->getField($field)) instanceof I2CE_FormField_MAP) { $this->pushMessage("Field {$field} is not a map field", $i + 1); $success = false; $remapObj->cleanup(); continue; } $fieldObj->setFromDB($newform . '|' . $newid); $this->pushMessage("Remapping {$field} in {$form}|{$remapID} to be {$newform}|{$newid}", $i + 1); if (!$remapObj->save($user)) { $success = false; $this->pushMessage("Could not save {$field} in {$form}|{$remapID} to be {$newform}|{$newid}", $i + 1); } else { $this->pushMessage("Remapped {$field} in {$form}|{$remapID} to be {$newform}|{$newid}", $i + 1); } $remapObj->cleanup(); } return $success; }