/**
  * 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);
 }
 /**
  * Upgrades the modules
  * @param string $old_vers
  * @param string $new_vers
  * @returns boolean
  */
 public function upgrade($old_vers, $new_vers)
 {
     if (I2CE_Validate::checkVersion($old_vers, '<', '3.2.12')) {
         I2CE::raiseError("Changing contact child forms of training_institution to training_institution_contact");
         if (!iHRIS_Module_Contact::changeContactForm('training_institution', 'contact_type|facility', 'training_institution_contact', true)) {
             I2CE::raiseError("Could not upgrade training instituion contacts");
             return false;
         }
     }
     if (I2CE_Validate::checkVersion($old_vers, '=', '3.2.12')) {
         //the changeContactForm did not remvoe the contact form before
         if (!iHRIS_Module_Contact::removeContactForm('training_institution')) {
             return false;
         }
     }
     if (I2CE_Validate::checkVersion($old_vers, '<', '3.2.19')) {
         I2CE::raiseError("Changing contact child forms of training_funder to training_funder_contact");
         if (!iHRIS_Module_Contact::changeContactForm('training_funder', 'contact_type|facility', 'training_funder_contact', true)) {
             I2CE::raiseError("Could not upgrade training funder contacts");
             return false;
         }
     }
     if (I2CE_Validate::checkVersion($old_vers, '<', '3.2.20')) {
         $user = new I2CE_User(1, false, false, false);
         $class_config = I2CE::getConfig()->modules->forms->formClasses;
         $migrate_path = "/I2CE/formsData/migrate_data/3.2.3";
         if (!I2CE_FormStorage::migrateField("training_institution", array("location" => array("county" => "county", "district" => "district", "country" => "country")), $migrate_path, $user)) {
             return false;
         }
         if (!I2CE_FormStorage::migrateField("training_funder", array("location" => array("county" => "county", "district" => "district", "country" => "country")), $migrate_path, $user)) {
             return false;
         }
     }
     return true;
 }
 public function displayValues($content_node, $transient_options, $action)
 {
     $mainNode = $this->template->appendFileByNode('service_directory_selector.html', 'div', $content_node);
     if (!$mainNode instanceof DOMNode) {
         return false;
     }
     $directories = array('provider', 'service', 'facility', 'organization');
     foreach ($directories as $directory) {
         $where = array('operator' => 'FIELD_LIMIT', 'field' => 'is_' . $directory, 'style' => 'true');
         if (!($selectNode = $this->template->getElementByName($directory, 0, $mainNode)) instanceof DOMElement) {
             continue;
         }
         $avail_dirs = I2CE_FormStorage::listDisplayFields('csd_info_manager', array('name'), false, $where);
         $selected = $this->getField($directory);
         foreach ($avail_dirs as $id => $data) {
             if (!is_array($data) || !array_key_exists('name', $data)) {
                 continue;
             }
             $id = 'csd_info_manager|' . $id;
             if ($id != $selected) {
                 $selectNode->appendChild($this->template->createElement('option', array('value' => $id), $data['name']));
             } else {
                 $selectNode->appendChild($this->template->createElement('option', array('value' => $id, 'selected' => 'selected'), $data['name']));
             }
         }
     }
     $this->renameInputs($directories, $mainNode);
     return true;
 }
 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");
     }
 }
 /**
  * Upgrade this module if necessary
  * @param string $old_vers
  * @param string $new_vers
  * @return boolean
  */
 public function upgrade($old_vers, $new_vers)
 {
     /*
      * In 3.2.3 we moved some lists from entry to magicdata storage so we need to get the
      * old data from entry and save them to the new form storage.
      */
     if (I2CE_Validate::checkVersion($old_vers, '<', '3.2.3')) {
         $user = new I2CE_User(1, false, false, false);
         $class_config = I2CE::getConfig()->modules->forms->formClasses;
         $migrate_path = "/I2CE/formsData/migrate_data/3.2.3";
         if (!I2CE_FormStorage::migrateForm("facility_type", "entry", $user, $migrate_path, false, array("type"))) {
             return false;
         }
         if (I2CE_FormStorage::migrateForm("facility", "entry", $user, $migrate_path, false, array("type"), array("facility_type" => "facility_type", "location" => array("county" => "county", "district" => "district", "country" => "country")))) {
             unset($class_config->iHRIS_Facility->fields->country);
             unset($class_config->iHRIS_Facility->fields->district);
             unset($class_config->iHRIS_Facility->fields->county);
             unset($class_config->iHRIS_Facility->fields->type);
         } else {
             return false;
         }
     } elseif (I2CE_Validate::checkVersion($old_vers, '<', '3.2.4')) {
         $user = new I2CE_User(1, false, false, false);
         $class_config = I2CE::getConfig()->modules->forms->formClasses;
         $migrate_path = "/I2CE/formsData/migrate_data/3.2.3";
         if (!I2CE_FormStorage::migrateForm("facility", "entry", $user, $migrate_path, false, array("type"))) {
             return false;
         }
         unset($class_config->iHRIS_Facility->fields->type);
     }
     return parent::upgrade($old_vers, $new_vers);
 }
 public static function getAvailableCourses()
 {
     $status = I2CE_FormStorage::listFields('training_course_status', 'name');
     foreach ($status as $i => &$s) {
         if (!array_key_exists('name', $s)) {
             unset($status[$i]);
             continue;
         }
         $s = $s['name'];
     }
     $t_filters = array();
     I2CE::getConfig()->setIfIsSet($t_filters, '/modules/training-course/filters/availableCourses', true);
     //this should be moved to magic data form storage!
     $filters = array();
     foreach ($t_filters as $val) {
         if (($key = array_search($val, $status)) !== false) {
             $filters[] = $key;
         }
     }
     $where = array();
     if (count($filters) > 0) {
         $where = array('operator' => 'FIELD_LIMIT', 'field' => 'training_course_status', 'style' => 'in', 'data' => array('value' => $filters));
     }
     $courses = I2CE_FormStorage::listFields('training_course', 'name', false, $where);
     foreach ($courses as $i => &$c) {
         if (!array_key_exists('name', $c)) {
             unset($courses[$i]);
             continue;
         }
         $c = $c['name'];
     }
     return $courses;
 }
 protected function loadObjects()
 {
     parent::loadObjects();
     if (($this->isPost() || $this->hasData()) && ($searchObj = $this->getPrimary()) instanceof CSD_Search && I2CE_FormStorage::getStorageMechanism($searchObj->getName()) instanceof I2CE_FormStorage_CSDSearch) {
         //this will populate "result" field
         $searchObj->setID("1");
         //so it will populate
         if (($maxField = $searchObj->getField('max')) instanceof I2CE_FormField_INT) {
             if ($maxField->getValue() > 200) {
                 $maxField->setValue(200);
             }
         }
         if (($entityIDField = $searchObj->getField('entityID')) instanceof I2CE_FormField_STRING_LINE) {
             list($form, $id) = array_pad(explode('|', $entityIDField->getValue(), 2), 2, '');
             if ($id) {
                 $entityIDField->setValue($id);
             }
         }
         $searchObj->populate(true);
         if (($matches = $searchObj->getField('matches')) instanceof I2CE_FormField_ASSOC_MAP_RESULTS && count($matches->getValue()) > 200) {
             $this->userMessage("To Many Results To Display.  Please refine your search");
             I2CE::raiseError("Too many results");
             $this->bad_result = true;
             $matches->setValue(array());
             if (($resultField = $searchObj->getField('result')) instanceof I2CE_FormField) {
                 $resultField->setValue('');
             }
         }
     }
     return true;
 }
 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);
 }
 static function academicYearId($academic_year)
 {
     $where = array("operator" => "FIELD_LIMIT", "field" => "name", "style" => "equals", "data" => array("value" => $academic_year));
     $academic_year_array = I2CE_FormStorage::Search("academic_year", false, $where);
     foreach ($academic_year_array as $academic_year_id) {
         return $academic_year_id;
     }
 }
 /**
  * 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;
 }
 /**
  * Migrate the facility contact data from entry to the current storage (magicdata)
  */
 public function migrate()
 {
     $user = new I2CE_User(1, false, false, false);
     $migrate_path = "/I2CE/formsData/migrate_data/3.2.3";
     if (!I2CE_FormStorage::migrateForm("facility_contact", "entry", $user, $migrate_path)) {
         return false;
     }
     return true;
 }
Example #14
0
 /**
  * Get the display name associated to a role's shortname
  * @param string $name the shortname of the role
  * @returns string
  */
 static function getRoleNameFromShortName($name)
 {
     $disp = I2CE_FormStorage::lookupField('role', $name);
     if ($disp === false) {
         I2CE::raiseError("Invalid shortname  for getRoleNameFromShortName: {$name}.");
         return null;
     }
     return $disp;
 }
 /** 
  * Perform the migrate actions for this module
  * This is for going from pre 3.2 versions where benefit data has
  * been saved to the database.
  * @return boolean
  */
 protected function migrate()
 {
     $user = new I2CE_User(1, false, false, false);
     $class_config = I2CE::getConfig()->modules->forms->formClasses;
     $migrate_path = "/I2CE/formsData/migrate_data/3.2.3";
     if (!I2CE_FormStorage::migrateField("employment", array("start_wage" => "currency", "end_wage" => "currency"), $migrate_path, $user)) {
         return false;
     }
     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;
 }
 /**
  * Perform the migrate actions for this module.
  * @return boolean;
  */
 protected function migrate()
 {
     $user = new I2CE_User(1, false, false, false);
     $class_config = I2CE::getConfig()->modules->forms->formClasses;
     $migrate_path = "/I2CE/formsData/migrate_data/3.2.3";
     if (!I2CE_FormStorage::migrateForm("id_type", "entry", $user, $migrate_path, false, array("type"))) {
         return false;
     }
     if (!I2CE_FormStorage::migrateField("person_id", array("id_type" => "id_type"), $migrate_path, $user)) {
         return false;
     }
     return true;
 }
 /**
  *@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;
 }
Example #20
0
 /**
  * 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]);
         }
     }
 }
 /**
  * Perform the migrate actions for this module
  * This is for going from pre 3.2 versions where benefit data has
  * been saved to the database.
  * @return boolean
  */
 protected function migrate()
 {
     $user = new I2CE_User(1, false, false, false);
     $class_config = I2CE::getConfig()->modules->forms->formClasses;
     $migrate_path = "/I2CE/formsData/migrate_data/3.2.3";
     if (!I2CE_FormStorage::migrateForm("competency_evaluation", "entry", $user, $migrate_path, "name", array("type"), array(), true)) {
         return false;
     }
     if (!I2CE_FormStorage::migrateField("person_competency", array("competency_evaluation" => "competency_evaluation", "competency" => "competency"), $migrate_path, $user)) {
         return false;
     }
     unset($class_config->iHRIS_PersonCompetency->fields->competency_type);
     return true;
 }
 protected function loadPrimary()
 {
     if ($this->request_exists('student_id') && in_array('person', $this->formRelationship->getFormNames()) && ($student_id = $this->request('student_id')) && ($pos = strpos($student_id, '|')) !== false && ($id = substr($student_id, $pos + 1)) != '' && ($stc_id = I2CE_FormStorage::lookupField('person_scheduled_training_course', $id, array('scheduled_training_course'), '')) != '' && ($person_id = I2CE_FormStorage::lookupField('person_scheduled_training_course', $id, array('parent'), '')) != '') {
         $formFactory = I2CE_FormFactory::instance();
         if (!($this->primObj = $formFactory->createContainer($stc_id)) instanceof I2CE_Form || $this->formRelationship->getPrimaryForm() != $this->primObj->getName()) {
             I2CE::raiseError("invalid form id :" . print_r($this->request(), true) . "\ndoes not match " . $this->formRelationship->getPrimaryForm());
             return false;
         }
         $this->primObj->populate();
         $this->person_id = $person_id;
     } else {
         return parent::loadPrimary();
     }
 }
 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);
         }
     }
 }
 /**
  * Init form storage options
  * @param string $form 
  */
 protected function init_data($form)
 {
     if (in_array($form, $this->init_status)) {
         //already done
         return true;
     }
     if (!parent::init_data($form)) {
         return false;
     }
     $options = $this->getStorageOptions($form);
     if (!$options instanceof I2CE_MagicDataNode) {
         I2CE::raiseError("Invalid storage options for {$form}");
         return false;
     }
     $options = $this->getStorageOptions($form);
     if (!$options instanceof I2CE_MagicDataNode) {
         I2CE::raiseError("Invalid storage options for {$form}");
         return false;
     }
     $directory = false;
     if (!$options->setIfIsSet($directory, 'csd_directory') || !in_array($directory, array('provider', 'service', 'facility', 'organization'))) {
         I2CE::raiseError("No valid defined for {$form}");
         return false;
     }
     if (!is_array($remote_services = I2CE::getConfig()->getAsArray("/modules/forms/storage_options/CSD/remote_services")) || !array_key_exists($directory, $remote_services) || !is_scalar($selected = $remote_services[$directory])) {
         I2CE::raiseError("No remote service directory selected in global CSD  options");
         return false;
     }
     list($t_form, $id) = array_pad(explode('|', $selected, 2), 2, '');
     if ($t_form != 'csd_info_manager' || $id == '0' || !is_array($urls = I2CE_FormStorage::lookupField('csd_info_manager', $id, array('url'), false)) || !array_key_exists('url', $urls) || !$urls['url']) {
         I2CE::raiseError("Invalid connection details from selected service: {$selected}");
     }
     if (!array_key_exists('csd', $this->namespaces[$form])) {
         $this->namespaces[$form]['csd'] = "urn:ihe:iti:csd:2013";
     }
     $cache_time = 0;
     if (is_array($this->global_options) && array_key_exists('cache_time', $this->global_options) && is_scalar($this->global_options['cache_time'])) {
         $cache_time = (int) $this->global_options['cache_time'];
     }
     $options->setIfIsSet($cache_time, "cache_time");
     $cache_time = (int) $cache_time;
     if (!array_key_exists('populate', $this->services[$form])) {
         $this->services[$form]['populate'] = array();
     }
     $populate = array('url' => $urls['url'], 'curl_opts' => array('HEADER' => 0, 'POST' => 1, 'HTTPHEADER' => array('content-type' => 'content-type: text/xml')), 'cache_time' => $cache_time);
     I2CE_Util::merge_recursive($this->services[$form]['populate'], $populate);
     return true;
 }
 /**
  * Perform the migrate actions for this module.
  * @return boolean
  */
 protected function migrate()
 {
     $user = new I2CE_User(1, false, false, false);
     $class_config = I2CE::getConfig()->modules->forms->formClasses;
     $migrate_path = "/I2CE/formsData/migrate_data/4.1.8";
     if (!I2CE_FormStorage::migrateForm("training_classification", "entry", $user, $migrate_path)) {
         return false;
     }
     if (I2CE_ModuleFactory::instance()->isEnabled("CachedForms")) {
         $cachedForm = new I2CE_CachedForm("training_classification");
         $cachedForm->dropTable();
     }
     if (!I2CE_FormStorage::migrateField("training", array("training_classification" => "training_classification"), $migrate_path, $user)) {
         return false;
     }
     return true;
 }
 /**
  * Return the record id and the parent id for the person position record
  * for the given position.
  * @param $position of the form "postion|$id"
  * @return array
  */
 public static function getIds($position)
 {
     $where = array('operator' => 'AND', 'operand' => array(0 => array('operator' => 'FIELD_LIMIT', 'field' => 'position', 'style' => 'equals', 'data' => array('value' => $position)), 1 => array('operator' => 'FIELD_LIMIT', 'field' => 'end_date', 'style' => 'null', 'data' => array())));
     $pers_pos = I2CE_FormStorage::listFields('person_position', array(), true, $where, array('-start_date'), 1);
     if (!is_array($pers_pos) || count($pers_pos) !== 1) {
         return array();
     }
     reset($pers_pos);
     $id = key($pers_pos);
     $pers_pos = $pers_pos[$id];
     if (is_array($pers_pos) && array_key_exists('parent', $pers_pos)) {
         $parent = $pers_pos['parent'];
     } else {
         $parent = false;
     }
     return array('record' => $id, 'parent' => $parent);
 }
 /** 
  * Perform the migrate actions for this module
  * This is for going from pre 3.2 versions where benefit data has
  * been saved to the database.
  * @return boolean
  */
 protected function migrate()
 {
     $user = new I2CE_User(1, false, false, false);
     $class_config = I2CE::getConfig()->modules->forms->formClasses;
     $migrate_path = "/I2CE/formsData/migrate_data/3.2.3";
     $migrate_node = I2CE::getConfig()->traverse($migrate_path, true, false);
     $constant_prof = array(1 => 'language_proficiency|elementary', 2 => 'language_proficiency|limited', 3 => 'language_proficiency|professional', 4 => 'language_proficiency|full_professional', 5 => 'language_proficiency|fluent');
     foreach ($constant_prof as $old_id => $new_id) {
         $migrate_node->forms->language_proficiency->{$old_id} = $new_id;
     }
     if (!I2CE_FormStorage::migrateForm("language", "entry", $user, $migrate_path, false, array("type"))) {
         return false;
     }
     if (!I2CE_FormStorage::migrateField("person_language", array("language" => "language", "speaking" => "language_proficiency", "reading" => "language_proficiency", "writing" => "language_proficiency"), $migrate_path, $user)) {
         return false;
     }
     return true;
 }
 /**
  * Perform the migrate actions for this module.
  * @return boolean
  */
 protected function migrate()
 {
     $user = new I2CE_User(1, false, false, false);
     $class_config = I2CE::getConfig()->modules->forms->formClasses;
     $migrate_path = "/I2CE/formsData/migrate_data/3.2.3";
     if (!I2CE_FormStorage::migrateForm("edu_type", "entry", $user, $migrate_path, false, array("type"))) {
         return false;
     }
     if (!I2CE_FormStorage::migrateForm("degree", "entry", $user, $migrate_path, false, array("type"), array("edu_type" => "edu_type"))) {
         return false;
     }
     if (!I2CE_FormStorage::migrateField("education", array("degree" => "degree"), $migrate_path, $user)) {
         return false;
     }
     unset($class_config->iHRIS_Degree->fields->type);
     unset($class_config->iHRIS_Education->fields->edu_type);
     return true;
 }
 /**
  * Perform the migrate actions for this module.
  * @return boolean
  */
 protected function migrate()
 {
     $user = new I2CE_User(1, false, false, false);
     $class_config = I2CE::getConfig()->modules->forms->formClasses;
     $migrate_path = "/I2CE/formsData/migrate_data/3.2.3";
     $migrate_node = I2CE::getConfig()->traverse($migrate_path, true, false);
     $constant_gender = array(1 => 'gender|F', 2 => 'gender|M');
     foreach ($constant_gender as $old_id => $new_id) {
         $migrate_node->forms->gender->{$old_id} = $new_id;
     }
     if (!I2CE_FormStorage::migrateForm("marital_status", "entry", $user, $migrate_path, false, array("type"))) {
         return false;
     }
     if (!I2CE_FormStorage::migrateField("demographic", array("gender" => "gender", "marital_status" => "marital_status"), $migrate_path, $user)) {
         return false;
     }
     return true;
 }
 /**
  * Initialize the data for the page
  * @return boolean
  */
 protected function initPage()
 {
     $this->form_factory = I2CE_FormFactory::instance();
     $this->user_form = $this->form_factory->createContainer("user|" . $this->getUser()->username);
     $pend_where = array('operator' => 'FIELD_LIMIT', 'field' => 'time_ack', 'style' => 'null');
     //$this->pending = I2CE_FormStorage::listFields( "user_alert", array( "time_sent", "message", "alert_type" ),
     //$this->user_form->getNameId(), $pend_where, array( "time_sent" ) );
     $this->pending = $this->user_form->getChildIds("user_alert", array("time_sent"), $pend_where);
     $this->jumper_opts['page_size'] = $this->args['page_size'];
     if ($this->get_exists('page')) {
         $this->jumper_opts['page'] = $this->get('page');
     } else {
         $this->jumper_opts['page'] = 1;
     }
     $this->user_form->populateChild("user_alert", array("-time_sent"), array(), 'default', array(($this->jumper_opts['page'] - 1) * $this->jumper_opts['page_size'], $this->jumper_opts['page_size']));
     $this->total_alerts = I2CE_FormStorage::getLastListCount("user_alert");
     return true;
 }