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 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);
         }
     }
 }
 /**
  * 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 extra validation for the person form.
  * A new person record needs to verify there aren't any existing 
  * records with the same name.
  * @param I2CE_Form $form
  */
 public function validate_form_person($form)
 {
     $search = array();
     $surname_ignore = false;
     if (isset($form->surname_ignore)) {
         $surname_ignore = $form->surname_ignore;
     }
     if (I2CE_ModuleFactory::instance()->isEnabled('forms-storage') && $form->getId() == '0' && !$surname_ignore && I2CE_Validate::checkString($form->surname) && I2CE_Validate::checkString($form->firstname)) {
         $where = array('operator' => 'AND', 'operand' => array(0 => array('operator' => 'FIELD_LIMIT', 'field' => 'surname', 'style' => 'lowerequals', 'data' => array('value' => strtolower($form->surname))), 1 => array('operator' => 'FIELD_LIMIT', 'field' => 'firstname', 'style' => 'lowerequals', 'data' => array('value' => strtolower($form->firstname)))));
         $results = I2CE_FormStorage::listFields('person', array('surname', 'firstname'), false, $where, array('surname', 'firstname'));
         if (count($results) > 0) {
             foreach ($results as $id => &$data) {
                 $data = implode(', ', $data);
             }
             $form->setInvalidMessage('surname', 'unique', array("view?id=" => $results));
         }
     }
 }
 /**
  * Perform extra validation for the trainingprovider form.
  * A new trainingprovider record needs to verify there aren't any existing 
  * records with the same name.
  * @param I2CE_Form $form
  */
 public function validate_form_trainingprovider($form)
 {
     $search = array();
     $name_ignore = false;
     if (isset($form->name_ignore)) {
         $name_ignore = $form->name_ignore;
     }
     if (I2CE_ModuleFactory::instance()->isEnabled('forms-storage') && $form->getId() == 0 && !$name_ignore && I2CE_Validate::checkString($form->name)) {
         $where = array('operator' => 'AND', 'operand' => array(0 => array('operator' => 'FIELD_LIMIT', 'field' => 'name', 'style' => 'lowerequals', 'data' => array('value' => strtolower($form->name)))));
         $results = I2CE_FormStorage::listFields('trainingprovider', array('name'), false, $where, array('name'));
         if (count($results) > 0) {
             foreach ($results as $id => &$data) {
                 $data = implode(', ', $data);
             }
             $form->getField('name')->setInvalid("Duplicate records match this record's name:", array("viewprovider?id=" => $results));
         }
     }
     $value = $form->getField('email')->getValue();
     if (I2CE_Validate::checkString($value) && !I2CE_Validate::checkEmail($value)) {
         $form->getField('email')->setInvalid('invalid_email');
     }
 }
Example #6
0
 /**
  * Gets the id of her person associated to the fiven user
  * @param mixed $user I2CE_UserForm or I2CE_USER $user, or null for the logged in user
  * @returns string, the person id in the form of "person|XXX" or '|' or failure
  * 
  */
 public static function getPersonId($user = null)
 {
     if ($user === null) {
         $user = new I2CE_User();
     }
     if ($user instanceof I2CE_User) {
         $factory = I2CE_FormFactory::instance();
         $user = $factory->createContainer("user|" . $user->username());
     }
     if (!$user instanceof I2CE_User_Form) {
         return '|';
     }
     $where = array('operator' => 'FIELD_LIMIT', 'field' => 'username', 'style' => 'equals', 'data' => array('value' => $user->getNameId()));
     $maps = I2CE_FormStorage::listFields('user_map', array('parent'), true, $where);
     if (count($maps) != 1) {
         return '|';
     }
     $map = array_shift($maps);
     if (!array_key_exists('parent', $map) || !is_string($map['parent']) || !substr($map['parent'], 0, 7) == 'person|') {
         return '|';
     }
     return $map['parent'];
 }
Example #7
0
 /**
  * Internal method to search all the ids for forms that are below
  * the given matched form id.
  * @param string $match The form id to match at the top.
  * @param array $fields The getDisplayedFields() for the field object.
  * @param array $forms The getSelectableFroms() for the field object.
  * @param array $displayed A list of forms that should be included in the results.
  * @param int $show_hidden 0=non-hidden, 1=All, 2=hidden only.
  * @return array
  */
 protected static function _searchLowerMatches($match_form, $match_ids, $fields, $forms, $displayed, $show_hidden)
 {
     $formfield = array_shift($fields);
     if (!is_array($formfield)) {
         return array();
     }
     list($form, $link_field) = $formfield;
     $limit = array('operator' => 'FIELD_LIMIT', 'field' => $link_field, 'style' => 'in', 'data' => array('value' => $match_ids));
     $limit = I2CE_DataTree::showHiddenLimit($limit, $show_hidden);
     $order = I2CE_List::getSortFields($form);
     $field_datas = I2CE_FormStorage::listFields($form, 'id', false, $limit, $order);
     $matched = array();
     foreach (array_keys($field_datas) as $matched_id) {
         $matched[] = $form . "|" . $matched_id;
     }
     if ($displayed[$form]) {
         return array_merge($matched, self::_searchLowerMatches($form, $matched, $fields, $forms, $displayed, $show_hidden));
     } else {
         return self::_searchLowerMatches($form, $matched, $fields, $forms, $displayed, $show_hidden);
     }
 }
 protected function displayCourses($courses, $div, $text, $limit = false)
 {
     if (!($div = $this->template->getElementByID($div)) instanceof DOMNode) {
         return;
     }
     $table = $this->template->createElement("table", array("class" => "multiFormTable", "border" => "0", "cellpadding" => "0", "cellspacing" => "0"));
     $header = $this->template->createElement("H2", "", "{$text}");
     $this->template->appendNode($header, $div);
     $tr = $this->template->createElement("tr");
     $th = $this->template->createElement("th", array("width" => "40", "align" => "center"), "SN");
     $this->template->appendNode($th, $tr);
     $th = $this->template->createElement("th", array("width" => "10", "align" => "center"), "Select");
     $this->template->appendNode($th, $tr);
     $th = $this->template->createElement("th", array("width" => "100", "align" => "center"), "Course Code");
     $this->template->appendNode($th, $tr);
     $th = $this->template->createElement("th", "", "Course Name");
     $this->template->appendNode($th, $tr);
     $th = $this->template->createElement("th", "", "Course Type");
     $this->template->appendNode($th, $tr);
     $th = $this->template->createElement("th", "", "Course Credits");
     $this->template->appendNode($th, $tr);
     $th = $this->template->createElement("th", "", "Course Semester");
     $this->template->appendNode($th, $tr);
     $this->template->appendNode($tr, $table);
     $counter = 1;
     foreach ($courses as $id => $subject) {
         $tr = $this->template->createElement("tr");
         $td = $this->template->createElement("td", array("align" => "center"), $counter);
         $this->template->appendNode($td, $tr);
         $td = $this->template->createElement("td", array("align" => "center"));
         if ($this->isEnrolled($subject)) {
             $checkbox = $this->template->createElement("input", array("type" => "checkbox", "name" => "course[" . $subject . "]", "value" => $subject, "checked" => "checked"));
         } else {
             if ($limit == true) {
                 $checkbox = $this->template->createElement("input", array("type" => "checkbox", "name" => "course[" . $subject . "]", "value" => $subject, "disabled" => "true"));
             } else {
                 $checkbox = $this->template->createElement("input", array("type" => "checkbox", "name" => "course[" . $subject . "]", "value" => $subject));
             }
         }
         $this->template->appendNode($checkbox, $td);
         $this->template->appendNode($td, $tr);
         if ($limit == true) {
             $ids = explode("|", $subject);
             $id = $ids[1];
         }
         $where = array("operator" => "FIELD_LIMIT", "field" => "id", "style" => "equals", "data" => array("value" => $id));
         $course_descriptions = I2CE_FormStorage::listFields("training", array("name", "code", "course_type", "course_credits", "semester"), false, $where);
         $course_type_nameObj = $this->factory->createContainer($course_descriptions[$id]["course_type"]);
         $course_type_nameObj->populate();
         $course_type_name = $course_type_nameObj->getField("name")->getDBValue();
         $td = $this->template->createElement("td", array("align" => "center"), $course_descriptions[$id]["code"]);
         $this->template->appendNode($td, $tr);
         $td = $this->template->createElement("td", "", $course_descriptions[$id]["name"]);
         $this->template->appendNode($td, $tr);
         $td = $this->template->createElement("td", array("align" => "center"), $course_type_name);
         $this->template->appendNode($td, $tr);
         $td = $this->template->createElement("td", array("align" => "center", "width" => 100), $course_descriptions[$id]["course_credits"]);
         $this->template->appendNode($td, $tr);
         $td = $this->template->createElement("td", array("align" => "center", "width" => 120), self::getSemesterName($course_descriptions[$id]["semester"]));
         $this->template->appendNode($td, $tr);
         $this->template->appendNode($tr, $table);
         $counter++;
     }
     $this->template->appendNode($table, $div);
 }
 /**
  * Method used to populate the cache table in case the form storage mechanism is not DB like
  * @param boolean $check_mod.  Defaults to true.  If false, it skips the mod time check
  */
 protected function slowPopulate($check_mod = true)
 {
     $fields = array();
     $mdb2_types = array();
     $default_values = array();
     foreach ($this->formObj as $field => $fieldObj) {
         if (!$fieldObj->isInDB()) {
             continue;
         }
         $fields[] = $field;
         $mdb2_types[] = $fieldObj->getMDB2Type();
         $default_values[$field] = $fieldObj->getDBValue();
     }
     $default_values['last_modified'] = '1900-01-01 00:00:00';
     $default_values['created'] = '0000-00-00 00:00:00';
     $insert_fields = $fields;
     $insert_fields[] = 'last_modified';
     $insert_fields[] = 'created';
     $fields[] = 'last_modified';
     $fields[] = 'created';
     $insert_fields[] = "id";
     $insert_fields[] = 'parent';
     $update_fields = array();
     foreach ($insert_fields as &$field) {
         $field = '`' . $field . '`';
         $update_fields[] = "{$field}=values({$field})";
     }
     unset($field);
     $insertQry = 'INSERT INTO ' . $this->table_name . " (" . implode(',', $insert_fields) . " ) " . " VALUES (" . implode(',', array_fill(0, count($insert_fields), '?')) . ")" . " ON DUPLICATE KEY UPDATE " . implode(',', $update_fields);
     I2CE::raiseError("Slow populate:\n{$insertQry}");
     $db = MDB2::singleton();
     $prep = $db->prepare($insertQry, $mdb2_types, MDB2_PREPARE_MANIP);
     if (I2CE::pearError($prep, "Error setting up form in the database:")) {
         return false;
     }
     if ($check_mod) {
         $mod_time = $this->getLastCachedTime();
     } else {
         $mod_time = 0;
     }
     $list = I2CE_FormStorage::listFields($this->form, $fields, true, array(), array(), false, $mod_time);
     $count = 0;
     foreach ($list as $id => $data) {
         $count++;
         $t_data = array();
         foreach ($fields as $field) {
             if (array_key_exists($field, $data)) {
                 $t_data[] = $data[$field];
             } else {
                 $t_data[] = $default_values[$field];
             }
         }
         $t_data[] = $this->form . "|" . $id;
         if (array_key_exists('parent', $data)) {
             $t_data[] = $data['parent'];
         } else {
             $t_data[] = null;
         }
         $res = $prep->execute($t_data);
         if (I2CE::pearError($res, "Error insert into cache table:")) {
             return false;
         }
     }
     I2CE::raiseError("Populate {$count} entries for {$this->form}");
     return true;
 }
 /**
  * Setup the list of all participants for this instance.
  */
 protected function setupParticipants()
 {
     if (!is_array($this->participants)) {
         $this->participants = array();
         $where_data = array('operator' => 'FIELD_LIMIT', 'field' => 'provider_instance', 'style' => 'equals', 'data' => array('value' => $this->instance->getNameId()));
         $participants = I2CE_FormStorage::listFields('person_instance', array('attending', 'parent'), false, $where_data);
         foreach ($participants as $p_instance => $i_data) {
             $this->participants[$i_data['parent']] = $i_data['attending'];
         }
     } else {
         I2CE::raiseError("setupParticipants was called twice, so nothing was done the second time.");
     }
 }
    /**
     * Run the appropriate cron jobs based on the cron type.
     * @param string $type
     */
    public function cronjob($type)
    {
        // We need to run any normal hooks and not CLI hooks for this process if run from CLI
        $host_changed = false;
        if (!array_key_exists('HTTP_HOST', $_SERVER)) {
            $host_changed = true;
            $_SERVER['HTTP_HOST'] = '';
        }
        // Find all the Module Access modules that are available so the user can be set.
        $report_limits = I2CE_ModuleFactory::callHooks("get_report_module_limit_options");
        $limit_modules = array();
        foreach ($report_limits as $limit) {
            if (array_key_exists('module', $limit)) {
                $mod = I2CE_ModuleFactory::instance()->getClass($limit['module']);
                $limit_modules[] = array('module' => $mod, 'user' => $mod->getUser());
            }
        }
        $cron_type_where = array('operator' => "FIELD_LIMIT", 'style' => 'equals', 'field' => 'cron_type', 'data' => array('value' => $type));
        $reports = I2CE_FormStorage::listFields('cron_report', array('parent', 'report_view'), false, $cron_type_where);
        foreach ($reports as $report) {
            $view = $report['report_view'];
            $user = I2CE_FormFactory::instance()->createContainer($report['parent']);
            // Set the user on all access modules to limit results.
            foreach ($limit_modules as $module) {
                $module['module']->setUser($user->user);
            }
            $_SESSION['user_name'] = $user->username;
            $page = new I2CE_Page_ShowReport(array(), array($view));
            $template = $page->getTemplate();
            $display = $page->getDesiredDisplays($view);
            $use_display = 'Default';
            if ($display[0] != 'PieChart') {
                $use_display = $display[0];
            }
            $displayObj = $page->instantiateDisplay($use_display, $view);
            $config = I2CE::getConfig()->modules->CustomReports->reportViews->{$view};
            $template->loadRootText("<span id='siteContent' />");
            $contentNode = $template->getElementById('siteContent');
            $attachments = array();
            $report_name = $config->display_name;
            $report_desc = $config->description;
            $report_limit = '';
            $generated = strftime('%c');
            switch ($use_display) {
                case "CrossTab":
                    if ($displayObj->isExport()) {
                        $export = $displayObj->generateExport($contentNode, false);
                        $html = false;
                        $attachments[] = array('type' => "text/csv; charset=UTF-8", 'data' => $export, 'name' => $this->getFileName($report_name) . ".csv");
                        break;
                    }
                    // If not export then fall through to the Default
                // If not export then fall through to the Default
                case "Default":
                    $displayObj->unsetPaging();
                    $displayObj->display($contentNode);
                    $report_limit = $displayObj->getReportLimitsDescription();
                    $css = I2CE::getFileSearch()->search('CSS', 'customReports_display_Default.css');
                    $report_css = file_get_contents($css);
                    $report_table = $template->getElementById('report_table');
                    $report_content = $template->doc->saveHTML($report_table);
                    $html = <<<EOF
<?xml version="1.0" encoding="utf-8"?>'
<!DOCTYPE html>
<html>
<head>
    <title>Automated Report: {$report_name}</title>
    <style type="text/css">
{$report_css}
    </style>
</head>
<body>
    <h1>{$report_name}</h1>
    <h2>{$report_desc}</h2>
    <h3>{$report_limit}</h3>
    <p>Generated on: {$generated}</p>
    {$report_content}
</body>
</html>
EOF;
                    break;
                case "PDF":
                    $pdf = $displayObj->getPDF($contentNode);
                    $pdf_data = $pdf->Output($report_name, 'S');
                    $html = false;
                    $attachments[] = array('type' => 'application/pdf', 'data' => $pdf_data, 'name' => $this->getFileName($report_name) . ".pdf");
                    break;
                case "Export":
                    $export = $displayObj->generateExport();
                    $html = false;
                    $attachments[] = array('type' => $displayObj->getContentType(true), 'data' => $export, 'name' => $displayObj->getFileName());
                    break;
                default:
                    I2CE::raiseError("Unknown display type used for report display for user cron reports.");
                    break;
            }
            $email = $user->email;
            // This is duplicated from the Default setting so it can be in the main mail message as well.
            // It isn't called earlier to avoid duplicate processing with the Default display.
            if (!$html && $report_limit == '') {
                $report_limit = $displayObj->getReportLimitsDescription();
            }
            $mail_msg = wordwrap("This is the automated report for {$report_name}:  {$report_desc}.\nLimits are: {$report_limit}\nGenerated on: {$generated}.");
            if (I2CE_Mailer::mail($email, array('Subject' => 'Automated Report: ' . $report_name), $mail_msg, $html, $attachments)) {
                echo "Report mail {$report_name} (" . $report['report_view'] . ") sent to {$email}.\n";
            } else {
                echo "Report mail {$report_name} (" . $report['report_view'] . ") failed to {$email}.\n";
            }
            //$page->actionCommandLine( array(), array() );
        }
        if ($host_changed) {
            unset($_SERVER['HTTP_HOST']);
        }
        unset($_SESSION['user_name']);
        foreach ($limit_modules as $module) {
            $module['module']->setUser($module['user']);
        }
    }
 protected function action()
 {
     if (!$this->hasPermission("task(can_add_students_results)" or $this->getUser()->role == "admin")) {
         $this->setRedirect("noaccess");
         return;
     }
     $this->ff = I2CE_FormFactory::instance();
     //update academic year
     iHRIS_AcademicYear::ensureAcademicYear();
     //retrive the academic year
     $current_academic_year = iHRIS_AcademicYear::currentAcademicYear();
     $academic_year_id = iHRIS_AcademicYear::academicYearId($current_academic_year);
     $academic_year_id = "academic_year|" . $academic_year_id;
     $this->course_id = $this->request("id");
     $where_course_id = array("operator" => "AND", "operand" => array(0 => array('operator' => 'FIELD_LIMIT', 'field' => 'training', 'style' => 'like', 'data' => array('value' => "%" . $this->course_id . "%")), 1 => array('operator' => 'FIELD_LIMIT', 'field' => 'academic_year', 'style' => 'equals', 'data' => array('value' => $academic_year_id))));
     $parents = I2CE_FormStorage::listFields("enroll_course", array("parent", "training", "academic_year"), false, $where_course_id);
     if (!($listNode = $this->template->getElementByID("students_list")) instanceof DOMNode) {
         return;
     }
     if (!($hidden_data = $this->template->getElementByID("hidden_data")) instanceof DOMNode) {
         return;
     }
     if (count($parents) == 0) {
         $this->userMessage("No students enrolled for this course!!!");
         $this->setRedirect("add_results_select_course");
     }
     $input = $this->template->createElement("input", array("type" => "hidden", "name" => "course_id", "value" => $this->course_id));
     $this->template->appendNode($input, $listNode);
     $table = $this->template->createElement("table", array("class" => "multiFormTable", "width" => "100%", "border" => "0", "cellpadding" => "0", "cellspacing" => "0"));
     $tr = $this->template->createElement("tr");
     $th = $this->template->createElement("th", array("width" => "60%"), "Student Name");
     $this->template->appendNode($th, $tr);
     $th = $this->template->createElement("th", "", "Registration Number");
     $this->template->appendNode($th, $tr);
     $this->appendExamTypesHeaders($tr);
     $this->template->appendNode($tr, $table);
     //retrieving the max mark for each assessment
     foreach ($this->exam_types as $exam_type) {
         list($form, $id) = array_pad(explode("|", $exam_type, 2), 2, '');
         list($form, $course_id) = array_pad(explode("|", $this->course_id, 2), 2, '');
         $max_mark = I2CE_FormStorage::lookupField("training", $course_id, array($id), false);
         $max_mark = $max_mark[$id];
         $input = $this->template->createElement("input", array("type" => "hidden", "name" => $id, "id" => $id, "value" => $max_mark));
         $this->template->appendNode($input, $listNode);
     }
     //fecth lecturer institution to make sure can see students for his/her institution
     $username = $this->getUser()->username;
     $inst_id = iHRIS_PageFormLecturer::fetch_institution($username);
     foreach ($parents as $enroll_id => $parent) {
         $reg_details = STS_PageFormPerson::load_current_registration($person_id);
         ###drop students which are on different institution###
         if ($inst_id != $reg_details["training_institution"]) {
             continue;
         }
         $trainings = explode(",", $parent["training"]);
         $tr = $this->template->createElement("tr");
         $person_id = $parent["parent"];
         $reg_num = $this->getRegistrationNumber($person_id);
         $input = $this->template->createElement("input", array("type" => "hidden", "name" => "reg_num[" . $reg_num . "]", "value" => $reg_num));
         $this->template->appendNode($input, $tr);
         list($form, $id) = array_pad(explode("|", $person_id, 2), 2, '');
         $field_data = I2CE_FormStorage::lookupField("person", $id, array('firstname', 'surname'), false);
         if (is_array($field_data) && array_key_exists('surname', $field_data) && array_key_exists('firstname', $field_data)) {
             $fullname = $field_data['firstname'] . ' ' . $field_data['surname'];
             $aNode = $this->template->createElement("a", array("href" => "view?id=" . $person_id), $fullname);
             $td = $this->template->createElement("td");
             $this->template->appendNode($aNode, $td);
             $this->template->appendNode($td, $tr);
             $td = $this->template->createElement("td", array("id" => $reg_num, "align" => "center"));
             $this->template->addTextNode($reg_num, $reg_num, $td);
             $this->template->appendNode($td, $tr);
             $this->appendExamTypesInput($tr, $reg_num, $person_id, $this->course_id, $parent["academic_year"], $enroll_id);
         }
         $this->template->appendNode($tr, $table);
     }
     $tr = $this->template->createElement("tr");
     $td = $this->template->createElement("td", array("colspan" => "10", "align" => "right"));
     $input = $this->template->createElement("input", array("type" => "submit", "value" => "Save", "onclick" => "return verify()"));
     $this->template->appendNode($input, $td);
     $this->template->appendNode($td, $tr);
     $this->template->appendNode($tr, $table);
     $this->template->appendNode($table, $listNode);
 }
 /**
  * Gets any code lists that are already  mapped in the system
  * @param string $form
  * @returns boolean
  */
 protected function getMappedCodeLists($form, $field)
 {
     if (array_key_exists($form, $this->mapping_data) && array_key_exists($field, $this->mapping_data[$form])) {
         return $this->mapping_data[$form][$field];
     }
     if (!array_key_exists($form, $this->mapping_data)) {
         $this->mapping_data[$form] = array();
     }
     $options = $this->getStorageOptions($form);
     if (!$options instanceof I2CE_MagicDataNode) {
         I2CE::raiseError("Invalid SDMX_CrossSectional storage options for {$form}");
         //shouldn't happen at this point
         return false;
     }
     $mapData = false;
     //do something to populate the mapping data
     if ($field == 'parent') {
         $mapPath = "parent/map_data";
     } else {
         $mapPath = "fields/{$field}/map_data";
     }
     if ($options->is_scalar($mapPath . '/list') && $options->is_scalar($mapPath . '/codelist')) {
         $list = $option->{$mapPath}->list;
         $codelist = $option->{$mapPath}->codelist;
         if ($list && $codelist) {
             $mapData = array();
             //we have a list and a codelist set so we should attempt to get the mapping data at this point
             if (I2CE_FormFactory::instance()->exists($list)) {
                 $linkForm = 'list_linkto_list_' . I2CE_FormStorage::getStorage($options->{$mapPath}->list);
                 $options->setIfIsSet($linkForm, $mapPath . '/mapping_form');
                 $where = array('operator' => 'AND', 'operands' => array(0 => array('operator' => 'FIELD_LIMIT', 'field' => 'list', 'style' => 'like', 'data' => array('value' => $list . '|%')), 1 => array('operator' => 'FIELD_LIMIT', 'field' => 'like', 'style' => 'starts_with', 'data' => array('value' => $codelist . '|%'))));
                 $data = I2CE_FormStorage::listFields($linkForm, array('list', 'links_to'), false, $where);
             }
             $codelist_len = strlen($codelist) + 1;
             foreach ($data as $id => $vals) {
                 if (!is_array($vals) || !array_key_exists('list', $vals) || !array_key_exists('links_to', $vals) || strlen($vals['links_to'] <= $codelist_len)) {
                     continue;
                 }
                 //chop of the $codelist| from the links to value and store it.
                 $data[substr($vals['codelist'], $codelist_len)] = $vals['list'];
             }
         }
     }
     $this->mapping_data[$form][$field] = $mapData;
     return $this->mapping_data[$form][$field];
 }
 /**
  * Get the limits to be used for the current list based on any potentially "lower" limits to avoid
  * excess choices with nothing below.
  * @param array $form_limits
  * @param string $list
  * @param array $form_fields
  * @return array
  */
 protected function getCurrentListLimits($form_limits, $list, $form_fields)
 {
     if (count($form_limits) == 1 && array_key_exists($list, $form_limits)) {
         return $form_limits;
     }
     $ff = I2CE_FormFactory::instance();
     //foreach( $form_fields as $form_field ) {
     $max_idx = count($form_fields) - 1;
     for ($i = 0; $i < $max_idx; $i++) {
         $form_field = str_replace('[', '', str_replace(']', '', $form_fields[$i]));
         if (strpos($form_field, '+') !== false) {
             list($form, $field) = explode('+', $form_field, 2);
         } else {
             $form = $form_field;
             $next_ff = str_replace('[', '', str_replace(']', '', $form_fields[$i + 1]));
             if (strpos($next_ff, '+') !== false) {
                 list($field, $notused) = explode('+', $next_ff, 2);
             } else {
                 $field = $next_ff;
             }
         }
         if ($list == $form) {
             break;
         }
         if (array_key_exists($form, $form_limits)) {
             $matched = I2CE_FormStorage::listFields($form, array($field), false, $form_limits[$form]);
             $in = array();
             foreach ($matched as $match) {
                 if (array_key_exists($field, $match) && strpos($match[$field], '|') !== false) {
                     list($mf, $mid) = explode('|', $match[$field], 2);
                     $in[] = $mid;
                 }
             }
             if (count($in) > 0) {
                 self::addOrCombineFieldLimit($form_limits, $field, "id", $in, "in");
             }
         }
     }
     return $form_limits;
 }
 public static function add_uuids($form, $field = 'csd_uuid')
 {
     I2CE::raiseError("ADDING UUIDS to {$form} on {$field}");
     try {
         //we probably don't need this, but
         $cache = new I2CE_CachedForm($form);
         $cache->dropTable();
     } catch (Exception $e) {
         I2CE::raiseError("Could not clear cache");
         return false;
     }
     $ff = I2CE_FormFactory::instance();
     $user = new I2CE_User();
     $forms = I2CE_FormStorage::listFields($form, array($field));
     foreach ($forms as $id => $fields) {
         if (is_array($fields) && array_key_exists('csd_uuid', $fields) && $fields['csd_uuid']) {
             continue;
         }
         if (!($form_obj = $ff->createContainer(array($form, $id))) instanceof I2CE_Form) {
             I2CE::raiseError("Could not instantiate {$form}|{$id}");
             return false;
         }
         $form_obj->populate();
         self::set_uuid_on_form($form_obj);
         $form_obj->save($user);
         $form_obj->cleanup();
     }
     try {
         //we probably don't need this, but
         $cache = new I2CE_CachedForm($form);
         $cache->dropTable();
         $cache->generateCachedTable();
     } catch (Exception $e) {
         I2CE::raiseError("Could not clear cache");
         return false;
     }
     return true;
 }
 /**
  * Setup the list of all students for this instance.
  */
 protected function setupStudents()
 {
     if (!is_array($this->students)) {
         $this->students = array();
         $where_data = array('operator' => 'FIELD_LIMIT', 'field' => 'scheduled_training_course', 'style' => 'equals', 'data' => array('value' => $this->scheduled_training_course->getNameId()));
         $students = I2CE_FormStorage::listFields('person_scheduled_training_course', array('parent', 'attending'), false, $where_data);
         foreach ($students as $s_instance => $s_data) {
             $this->students[$s_data['parent']] = $s_data['attending'] == 1 || $s_data['attending'] === null;
         }
     } else {
         I2CE::raiseError("setupStudents was called twice, so nothing was done the second time.");
     }
 }
 /**
  * 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 getSemesterId($semester)
 {
     $where = array("operator" => "FIELD_LIMIT", "field" => "name", "style" => "equals", "data" => array("value" => $semester));
     $semester_id = I2CE_FormStorage::listFields("semester", array("id"), false, $where);
     foreach ($semester_id as $semester) {
         $semester = $semester["id"];
     }
     return $semester;
 }
 /**
  * Get the forms ids for joining on a given field of  a named child form's with the named parent form on a given field
  * @param string $childFormName the name of the child form in the relationship
  * @param string $parentForm
  * @param string $parentId
  * @param array $joinData The array containg the join data
  * @param array $where
  * @param array $limit
  * @param array $fields keys are relationship formnames, values are array of fields we want returned
  * @param array $ordering keys are relationship formnames, values are array of fields we want ordered by
  * @return mixed. An array of form ids
  */
 public function getFormDataJoiningByID_fields($childFormName, $parentForm, $parentId, $joinData, $where, $limit, $fields, $ordering)
 {
     if (!is_array($joinData)) {
         I2CE::raiseError("Join data  specified for parent_form/{$childFormName}");
         return array();
     }
     foreach (array('parent', 'child') as $field) {
         if (!array_key_exists($field, $joinData) || !is_string($joinData[$field]) || strlen($joinData[$field]) == 0) {
             I2CE::raiseError("Join {$field} field not specified for parent_form/{$childFormName}");
             return array();
         }
     }
     $form = $this->getForm($childFormName);
     $pfield = $joinData['parent'];
     $cfield = $joinData['child'];
     $pData = I2CE_FormStorage::lookupField($parentForm, $parentId, array($pField), '');
     list($pForm, $pId) = array_pad(explode("|", $pData, 2), 2, '');
     //this will give the linked form and id
     if (!array_key_exists($childFormName, $fields) || !is_array($fields[$childFormName])) {
         $fields[$childFormName] = array();
     }
     if (!array_key_exists($childFormName, $ordering)) {
         $ordering[$childFormName] = array();
     }
     $sub_where = array('operator' => 'FIELD_LIMIT', 'field' => $cfield, 'style' => 'equals', 'data' => array('value' => $pForm . '|' . $pId));
     if (count($where) > 0) {
         $where = array('operator' => 'AND', 'operand' => array($sub_where, $where));
     } else {
         $where = $sub_where;
     }
     if ($this->use_disp_fields) {
         return I2CE_FormStorage::listFields($form, $fields[$childFormName], false, $where, $ordering[$childFormName], $limit, -1, $this->use_cache);
     } else {
         return I2CE_FormStorage::listDisplayFields($form, $fields[$childFormName], false, $where, $ordering[$childFormName], $limit, -1, $this->use_cache);
     }
     //return " JOIN $refChildForm AS `$childFormName` ON `$childFormName`.`{$joinData['child']}` = `parent_form`.`{$joinData['parent']}` " ;
 }
 /**
  * Make ehceduled training courses a map value of training course
  * rather than a child.
  */
 protected function moveScheduledTrainingCourseToMap()
 {
     $fields = array('parent');
     $stcs = I2CE_FormStorage::listFields('scheduled_training_course', array('parent'));
     $user = new I2CE_User(1, false, false, false);
     $factory = I2CE_FormFactory::instance();
     foreach ($stcs as $stc_id => $data) {
         if (!array_key_exists('parent', $data)) {
             continue;
         }
         $parent = $data['parent'];
         if (empty($parent) || $parent == '|' || $parent == 'training_course|' || $parent == 'training_course' || !is_string($parent) || substr($parent, 0, 16) != 'training_course|') {
             continue;
         }
         $stcObj = $factory->createContainer('scheduled_training_course|' . $stc_id);
         if (!$stcObj instanceof I2CE_Form) {
             I2CE::raiseError("Cannot instanciatanve  'scheduled_training_course|" . $stc_id);
             return false;
         }
         $stcObj->populate();
         $fieldObj = $stcObj->getField('training_course');
         if (!$fieldObj instanceof I2CE_FormField) {
             I2CE::raiseError("Could not get training course");
             return false;
         }
         $fieldObj->setFromDB($parent);
         $stcObj->setParent('|');
         $stcObj->save($user);
     }
     if (!I2CE::getConfig()->is_parent("/modules/forms/forms/training_course/child_forms")) {
         return true;
     }
     $child_forms = I2CE::getConfig()->traverse("/modules/forms/forms/training_course/child_forms");
     foreach ($child_forms as $k => $val) {
         if ($val !== 'scheduled_training_course') {
             continue;
         }
         unset($child_forms->{$k});
     }
     return true;
 }
Example #21
0
 /**
  * @param string $form The form name
  * @param array $fields of string. The fields we want returned
  *@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 with key id's and value and array of values.  the array of values has as keys the fields with their corresponding value.
  */
 public static function listFields($form, $fields, $where_data = array(), $ordering = array(), $limit = false)
 {
     if (is_string($ordering)) {
         $ordering = array($ordering);
     }
     if (!is_array($ordering)) {
         $ordering = array();
     }
     if (I2CE_ModuleFactory::instance()->isEnabled('forms-storage')) {
         return I2CE_FormStorage::listFields($form, $fields, false, $where_data, $ordering, $limit);
     } else {
         return array();
     }
 }
 protected function save()
 {
     $username = $this->getUser()->username;
     $training_institution = iHRIS_PageFormLecturer::fetch_institution($username);
     $assign_course_trainer = $this->factory->createContainer("assign_course_trainer");
     $assign_course_trainer->load($this->post);
     $assign_course_trainer->getField("training_institution")->setFromDB($training_institution);
     $lecturer = $assign_course_trainer->getField("lecturer")->getDBValue();
     $training_courses = $assign_course_trainer->getField("training")->getDBValue();
     $academic_year = $assign_course_trainer->getField("academic_year")->getDBValue();
     $training_courses = explode(",", $training_courses);
     $lecturers = explode(",", $lecturer);
     foreach ($lecturers as $lecturer) {
         foreach ($training_courses as $training_course) {
             //check if this course has been assigned for this lecturer
             $academic_year = iHRIS_AcademicYear::currentAcademicYear();
             $academic_year_id = iHRIS_AcademicYear::academicYearId($academic_year);
             $academic_year_id = "academic_year|" . $academic_year_id;
             $where_assigned = array("operator" => "AND", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "academic_year", "style" => "equals", "data" => array("value" => $academic_year_id)), 1 => array("operator" => "FIELD_LIMIT", "field" => "training", "style" => "equals", "data" => array("value" => $training_course)), 2 => array("operator" => "FIELD_LIMIT", "field" => "lecturer", "style" => "equals", "data" => array("value" => $lecturer)), 3 => array("operator" => "FIELD_LIMIT", "field" => "training_institution", "style" => "equals", "data" => array("value" => $training_institution))));
             $is_assigned = I2CE_FormStorage::search("assign_course_trainer", false, $where_assigned);
             if (count($is_assigned) > 0) {
                 continue;
             }
             $assign_course_trainer = $this->factory->createContainer("assign_course_trainer");
             $assign_course_trainer->getField("lecturer")->setFromDB($lecturer);
             $assign_course_trainer->getField("academic_year")->setFromDB($academic_year_id);
             $assign_course_trainer->getField("training")->setFromDB($training_course);
             $assign_course_trainer->getField("training_institution")->setFromDB($training_institution);
             /***alert HOD***/
             //get lecturer department
             $lectObj = $this->factory->createContainer($lecturer);
             $lectObj->populate();
             $lect_dep_id = $lectObj->getField("department")->getDBValue();
             //get course department
             $trainObj = $this->factory->createContainer($training_course);
             $trainObj->populate();
             $program = $trainObj->getField("training_program")->getDBValue();
             $progObj = $this->factory->createContainer($program);
             $progObj->populate();
             $course_dep_id = $progObj->getField("department")->getDBValue();
             $where = array("operator" => "AND", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "training_institution", "style" => "equals", "data" => array("value" => $training_institution)), 1 => array("operator" => "OR", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "department", "style" => "equals", "data" => array("value" => $lect_dep_id)), 1 => array("operator" => "FIELD_LIMIT", "field" => "department", "style" => "equals", "data" => array("value" => $course_dep_id)))), 2 => array("operator" => "FIELD_LIMIT", "field" => "role", "style" => "equals", "data" => array("value" => "role|hod"))));
             $hods = I2CE_FormStorage::listFields("lecturer", array("identification_number"), false, $where);
             $module_factory = I2CE_ModuleFactory::instance();
             $code = $trainObj->getField("code")->getDBValue();
             $course_name = $trainObj->getField("name")->getDBValue();
             $lect_fname = $lectObj->getField("first_name")->getDBValue();
             $lect_sname = $lectObj->getField("surname")->getDBValue();
             $lect_oname = $lectObj->getField("other_name")->getDBValue();
             $lect_name = $lect_fname . " " . $lect_oname . " " . $lect_sname;
             $lect_name = trim($lect_name);
             foreach ($hods as $hod) {
                 if ($module_factory->isEnabled("UserAlerts")) {
                     $alerts = $module_factory->getClass("UserAlerts");
                     $alerts->sendUserAlert($hod["identification_number"], 'notice', $code . "-" . $course_name . " Has Been Assigned To " . $lect_name, 'CustomReports/show/lecturer_assigned_courses', 'Vew Course Assignment Report');
                 } else {
                     I2CE::raiseError("Tried to send user alert, but the module isn't enabled.");
                 }
             }
             /***End of alerting HOD***/
             $assign_course_trainer->save($this->user);
         }
     }
     $this->userMessage("Course(s) Assigned To Trainer!!!");
     $this->setRedirect("assign_course_trainer");
 }
Example #23
0
 /**
  * Create a data tree of the selectable forms.  Deisgned to be fed into tree select
  * @param array $fields an ordered array E.g array('village+county','county','district,'region+country','country').
  * it is an "bottom up" array of string where strings are of the form "$form" or "$form+$link_field".  In the case of
  * the former type, then $link_field is assumed to be the next form.  So for example, "county" has link field "district".
  * If a "$form(+$link_field)" is surrounded by brackets [ ] , it is not displayed.
  * @param array $forms An unorderd array of form names whose values we allow to be selected
  * @param array $limits An array with keys form names and value limit data
  * @param array $orders An array with keys form names and values array of field orders for that form.  
  *                      If the form name has no orders, we use default ordering for that form based on its displayed firelds
  * @param int $show_hidden 0=non-hidden, 1=All, 2=hidden only.  Defaults to 0
  * @param array $report A report name to use for the query instead of building it from form cache or directly.
  * @return array
  */
 public static function buildDataTree($fields, $forms, $limits, $orders = array(), $show_hidden = 0, $report = null, $style = 'default')
 {
     //$forms = array(village, county) -- order does not matter.
     //$fields -- order matters.
     //Example0:
     //$fields == array('village','county','[district+cssc_region],'cssc_region+cssc_country','country')
     //Example1:
     //$fields == array('village+county','county','district,'region+country','country')  -- you could just as easily have used 'region'
     //Example2:
     //$fields == array('village','county');
     //build the tree top down.  top  = country in Example 0,1 and top = county in Example 2
     if (!is_array($forms) || !is_array($fields) || count($fields) == 0) {
         return array();
     }
     $data = array();
     $displayed = array();
     $last_form = false;
     $fields = array_reverse($fields);
     foreach ($fields as &$field) {
         //start0: $form = country $link_field = false   $last_form = false
         //next0: $form = cssc_region $link_field = country $last_form = country
         //start1: $form = country $link_field = false   $last_form = false
         //next0: $form = region $link_field = country $last_form = country
         //start2: $form = county $link_field = false   $last_form = false
         //next2: $form = village $link_field = county  $last_form = county
         if (!is_string($field)) {
             return array();
         }
         $len = strlen($field);
         if ($len >= 2 && $field[0] == '[' && $field[$len - 1] == ']') {
             $field = substr($field, 1, $len - 2);
             $display = false;
         } else {
             $display = true;
         }
         if (($pos = strpos($field, '+')) !== false) {
             list($form, $link_field) = explode('+', $field, 2);
             if ($last_form == false) {
                 //throw away junk linked field data on the top level form
                 $link_field = false;
             }
         } else {
             $form = $field;
             $link_field = false;
         }
         if (!$form) {
             return array();
         }
         if (!$link_field) {
             $link_field = $last_form;
         }
         $field = array($form, $link_field);
         $displayed[$form] = $display;
         $last_form = $form;
     }
     unset($field);
     $styles = array();
     $ff = I2CE_FormFactory::instance();
     if ($last_form) {
         $avail_styles = array($last_form => $style);
         $curr_style = $style;
         foreach (array_reverse($fields) as $formfield) {
             list($form, $link_field) = $formfield;
             if (!$form || !($formObj = $ff->createContainer($form)) instanceof I2CE_Form) {
                 break;
             }
             if (array_key_exists($form, $avail_styles) && is_string($avail_styles[$form])) {
                 $curr_style = $avail_styles[$form];
             } else {
                 $curr_style = 'default';
             }
             $styles["{$form}+{$link_field}"] = $curr_style;
             if (!$link_field || !($fieldObj = $formObj->getField($link_field)) instanceof I2CE_FormField) {
                 break;
             }
             $avail_styles = I2CE_List::getDisplayFieldStyles($form, $style);
         }
     }
     if (is_array($report)) {
         $results = self::buildReportTree($fields, $forms, $displayed, $limits, $orders, $show_hidden, $report);
         if (count($results) > 0) {
             return $results;
         } else {
             I2CE::raiseError("buildReportTree returned no results so defaulting to regular display.  If there is data then something went wrong so it should be fixed.");
         }
     }
     $use_cache = true;
     if (I2CE_ModuleFactory::instance()->isEnabled("CachedForms")) {
         $fs = I2CE_FormStorage::getMechanismByStorage("cached");
         if ($fs instanceof I2CE_FormStorage_cached) {
             try {
                 return $fs->buildDataTree($fields, $forms, $displayed, $limits, $orders, $show_hidden, $style);
             } catch (Exception $e) {
                 $use_cache = false;
                 I2CE::raiseError("Could not cache {$form}");
             }
         }
     }
     $phonebook = array();
     //indexed by "$form|$id" with values (by reference) the arrays at which contains the 'children' sub-array  for $form|$id node
     $parent_links = array();
     //indexed by "$form|$id" with values "$pform|$pid" which is the form/id that "$form|$id" is linked against
     $display_string = array();
     foreach ($fields as $formfield) {
         list($form, $link_field) = $formfield;
         if (array_key_exists("{$form}+{$link_field}", $limits)) {
             $limit = $limits["{$form}+{$link_field}"];
         } elseif (array_key_exists($form, $limits)) {
             $limit = $limits[$form];
         } else {
             $limit = array();
         }
         if (!($formObj = $ff->createContainer($form)) instanceof I2CE_Form) {
             continue;
         }
         $style = 'default';
         if (array_key_exists("{$form}+{$link_field}", $styles)) {
             $style = $styles["{$form}+{$link_field}"];
         }
         //if we dont show the hidden list memmber we need to include the limit where i2ce_disabled is false
         $limit = self::showHiddenLimit($limit, $show_hidden);
         $disp_fields = I2CE_List::getDisplayFields($form, $style);
         $disp_str = I2CE_List::getDisplayString($form, $style);
         //start0:  $form = country, $fields = (name)
         //next0:  $form = cssc_region, $fields = (name, cssc_country)
         //next0:  $form =  district $fields = (name, cssc_region)
         //next0: $form = county $field = (name,distrcit)
         //end0: $form = villate $field = (name,county)
         //start1:  $form = country, $fields = (name)
         //next1:  $form = region, $fields = (name, country)
         //next1:  $form =  district $fields = (name, region)
         //etc.
         if (array_key_exists($form, $orders)) {
             $order = $orders[$form];
         } else {
             $order = I2CE_List::getSortFields($form, $style);
         }
         ksort($order);
         if ($link_field) {
             $field_datas = I2CE_FormStorage::listFields($form, $link_field, false, $limit, $order, false, -1, $use_cache);
         } else {
             $field_datas = I2CE_FormStorage::listFields($form, 'id', false, $limit, $order, false, -1, $use_cache);
         }
         $display_datas = I2CE_FormStorage::listFields($form, $disp_fields, false, $limit, $order, false, -1, $use_cache);
         $link_id = false;
         $last_link = false;
         $selectable = in_array($form, $forms);
         foreach ($field_datas as $id => $field_data) {
             $formid = $form . '|' . $id;
             if (!$link_field) {
                 //this should only be the case for the top form
                 $parent =& $data;
             } else {
                 //we are not at the top.
                 $link = $field_data[$link_field];
                 unset($field_data[$link_field]);
                 if ($last_link != $link) {
                     if (!array_key_exists($link, $phonebook)) {
                         //don't know where to put this as a child of the previous one so skip it
                         continue;
                     }
                     $last_link = $link;
                     if (!array_key_exists('children', $phonebook[$link])) {
                         $phonebook[$link]['children'] = array();
                     }
                     $parent =& $phonebook[$link]['children'];
                     //example: $diplayed == array(country=>true, region=>false,  district=>true, county=>true village => true)
                     //we have $form = district, $formid = district|30, $parent_link= region|40
                     end($displayed);
                     $disp_form = key($displayed);
                     while ($disp_form !== false && $disp_form !== $form) {
                         prev($displayed);
                         $disp_form = key($displayed);
                     }
                     //we end here either before the beginning of the array or where $disp_form == $form.
                     prev($displayed);
                     //we are now at the one before the $form.  if the current form was district, we are now at region
                     $parent_link = $link;
                 } else {
                     if (!array_key_exists($link, $phonebook) || !$phonebook[$link]) {
                         //don't know where to put this as a child of the previous one so skip it
                         continue;
                     }
                 }
                 $parent_links[$formid] = $link;
             }
             if (!array_key_exists($id, $display_datas)) {
                 continue;
             }
             $disp_array = array();
             foreach ($disp_fields as $field) {
                 if (array_key_exists($field, $display_datas[$id]) && ($fieldObj = $formObj->getField($field)) instanceof I2CE_FormField) {
                     $fieldObj->setFromDB($display_datas[$id][$field]);
                     $disp_array[] = $fieldObj->getDisplayValue(false, $style);
                 } else {
                     $disp_array[] = '';
                 }
             }
             $display = vsprintf($disp_str, $disp_array);
             $child_data = array('display' => $display, 'show' => $displayed[$form]);
             if ($selectable) {
                 $child_data['value'] = $formid;
             }
             $parent[] = $child_data;
             end($parent);
             $phonebook[$formid] =& $parent[key($parent)];
         }
     }
     self::removeNotShownNodes($data);
     return $data;
 }
Example #24
0
 /**
  * Perform the main actions of the page.
  * @global array Get the home page from the global configuration
  */
 protected function action()
 {
     if ($this->request_exists('message') && $this->request('message')) {
         $this->template->userMessage($this->request('message'), 'default', false);
     }
     $i2ce_config = I2CE::getConfig()->I2CE;
     parent::action();
     $this->template->setBodyId("loginPage");
     if ($this->isPost()) {
         if ($this->post('submit') == "Login as Guest") {
             $this->post['username'] = $i2ce_config->guest->account;
             $this->post['password'] = $i2ce_config->guest->password;
         }
         $message = $this->user->login($this->post('username'), $this->post('password'));
         if (is_string($message)) {
             $this->template->setDisplayDataImmediate('error_message', $message);
         } else {
             if ($message === true) {
                 //the user was logged in
                 if (I2CE_Locales::getPreferredLocale() != I2CE_Locales::getBrowserPreferredLocale()) {
                     $this->user->setPreferredLocale(I2CE_Locales::getPreferredLocale());
                 }
             }
         }
     }
     if ($this->user->logged_in()) {
         if (array_key_exists('referal', $_SESSION) && $_SESSION['referal']) {
             $site_url = $this->getAccessedBaseURL();
             $referal = $_SESSION['referal'];
             unset($_SESSION['referal']);
             if ($site_url . $this->page == $referal) {
                 //there is an off chance that we are redirect from the login page.  this can happen if we initialize the site by accessing the login page
                 $referal = $this->getHome();
             }
             if (preg_match('/login/', $referal) || preg_match('/logout/', $referal)) {
                 $referal = $this->getHome();
             }
         } else {
             $referal = $this->getHome();
         }
         if ($this->getUser()->role == "student") {
             $username = $this->getUser()->username;
             $where = array("operator" => "FIELD_LIMIT", "field" => "registration_number", "style" => "equals", "data" => array("value" => $username));
             $reg = I2CE_FormStorage::listFields("registration", array("parent"), false, $where);
             foreach ($reg as $registration) {
                 $person_id = $registration["parent"];
             }
             $referal = "view?id={$person_id}";
         }
         $this->setRedirect($referal);
         return true;
     }
     if ($default_password = I2CE_User::userHasPassword('administrator', 'administrator')) {
         $username = $this->template->query('//input[@name="username"]');
         if ($username->length == 1) {
             $username->item(0)->setAttribute('value', 'administrator');
         }
         $password = $this->template->query('//input[@name="password"]');
         if ($password->length == 1) {
             $password->item(0)->setAttribute('value', 'administrator');
         }
     } else {
         if (($autologinuser = I2CE_User::getAutoLoginUser()) !== false) {
             $username = $this->template->query('//input[@name="username"]');
             if ($username->length == 1) {
                 $username->item(0)->setAttribute('value', $autologinuser);
             }
         }
     }
     $this->template->addHeaderLink("welcomeText.css");
     if ($this->user->logged_in() && $this->user->username == 'administrator' && $default_password) {
         $this->userMessage("Your password is currently set to the default password, administrator.  Please change this by clicking on the \"Change Password\" link  below.", "notice");
         $this->userMessage("If you have not already done so, please create a new user with a non-administrative role for everyday use.", "notice");
     }
 }
 public function getEnrolledStudents()
 {
     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())))));
     $pstcs = I2CE_FormStorage::listFields('person_scheduled_training_course', array(), true, $where);
     $list = array();
     foreach ($pstcs as $pstc_id => $pstc) {
         if (strpos($pstc['parent'], '|') === false) {
             continue;
         }
         list($parent, $id) = explode('|', $pstc['parent'], 2);
         if ($parent != 'person') {
             continue;
         }
         $list[$pstc['parent']] = I2CE_FormStorage::lookupField('person', $id, array('surname', 'firstname'), false);
         $list[$pstc['parent']]['person_scheduled_training_course'] = 'person_scheduled_training_course|' . $pstc_id;
     }
     uasort($list, array($this, 'surnameSort'));
     return $list;
 }
 /**
  * Trigger an event and call any associated handlers for all users linked to the trigger.
  * @param string $trigger The trigger being called
  * @param string $msg_key A key to look up in /modules/UserTriggers/messages to get the message to display.
  * @param string $message The message to include with the $msg_key if it exists.
  * @param string $link The link to send to the handlers (or use the default if set to true)
  * @param string $link_add Any data to include to the end of the link
  * @param array $args Any custom args to override for each handler that may be used, otherwise the default from MD will
  *                    be used.
  * @return boolean
  */
 public function trigger($trigger, $msg_key = '', $message = '', $link = false, $link_add = '', $args = array())
 {
     if (!$this->config->__isset("triggers/{$trigger}")) {
         I2CE::raiseError("No trigger found for {$trigger}!");
         return false;
     }
     $trigger_opts = $this->config->triggers->{$trigger}->getAsArray();
     $handlers = $this->config->handlers->getAsArray();
     $call_handlers = array();
     if (array_key_exists('handler', $trigger_opts) && is_array($trigger_opts['handler'])) {
         foreach ($trigger_opts['handler'] as $handler => $bool) {
             if (array_key_exists($handler, $handlers) && $bool) {
                 $call_handlers[] = $handler;
                 if (!array_key_exists('args', $trigger_opts)) {
                     $trigger_opts['args'] = array();
                 }
                 if (!array_key_exists($handler, $trigger_opts['args'])) {
                     $trigger_opts['args'][$handler] = array();
                 }
                 if (array_key_exists($handler, $args)) {
                     foreach ($args[$handler] as $key => $val) {
                         // Override the default args with whatever is sent to the method call.
                         $trigger_opts['args'][$handler][$key] = $val;
                     }
                 }
             }
         }
     }
     if (count($call_handlers) == 0) {
         I2CE::raiseError("No handlers enabled for {$trigger} so nothing to do!");
         return false;
     }
     $msg_defaults = array('prefix' => '', 'suffix' => '', 'link_text' => '', 'link' => '');
     if (array_key_exists('message', $trigger_opts)) {
         foreach ($msg_defaults as $key => &$val) {
             if (array_key_exists($key, $trigger_opts['message'])) {
                 $val = $trigger_opts['message'][$key];
             }
         }
     }
     $msg_lookup = '';
     if ($msg_key) {
         $this->config->setIfIsSet($msg_lookup, "messages/{$msg_key}");
     }
     if ($link) {
         if (is_string($link) && strlen($link) > 2) {
             $msg_defaults['link'] = $link;
         }
     }
     if ($link_add) {
         $msg_defaults['link'] .= $link_add;
     }
     if (strlen($msg_defaults['link']) > 2 && strtolower(substr($msg_defaults['link'], 0, 4)) != 'http') {
         $site_url = I2CE::getAccessedBaseURL();
         if ($msg_defaults['link'][0] == '/') {
             $site_url = substr($site_url, 0, strpos($site_url, '/', 9));
         }
         $msg_defaults['link'] = $site_url . $msg_defaults['link'];
     }
     $full_message = $msg_defaults['prefix'] . " " . $msg_lookup . " " . $message . " " . $msg_defaults['suffix'];
     $trigger_where = array('operator' => 'FIELD_LIMIT', 'style' => 'equals', 'field' => 'trigger', 'data' => array('value' => $trigger));
     $triggers = I2CE_FormStorage::listFields('user_trigger', array('parent'), false, $trigger_where);
     $ret_val = true;
     foreach ($triggers as $data) {
         $user_form = I2CE_FormFactory::instance()->createContainer($data['parent']);
         foreach ($call_handlers as $handler) {
             foreach ($handlers[$handler] as $module => $method) {
                 $modObj = $this->module_factory->getClass($module);
                 if ($modObj instanceof I2CE_Module) {
                     if ($modObj->_hasMethod($method)) {
                         if (!$modObj->{$method}($user_form->username, $trigger, $full_message, $msg_defaults['link'], $msg_defaults['link_text'], $trigger_opts['args'][$handler])) {
                             I2CE::raiseError("Error trying to call {$method} on {$module}");
                             $ret_val &= false;
                         }
                     } else {
                         I2CE::raiseError("Can't find method {$method} on {$module}");
                         $ret_val &= false;
                     }
                 } else {
                     I2CE::raiseError("{$module} isn't an instance of I2CE_Module");
                     $ret_val &= false;
                 }
             }
         }
     }
     return $ret_val;
 }
 /**
  * From the given list of people get the positions and stripped people ids to be
  * passed to the mass delete method.
  * @param array $people
  * @return array
  */
 protected function getDeleteList($people)
 {
     // Get all positions for the given facilities
     $pos_where = array('operator' => "AND", 'operand' => array(0 => array('operator' => "FIELD_LIMIT", 'style' => "in", 'field' => "parent", 'data' => array('value' => $people)), 1 => array('operator' => "FIELD_LIMIT", 'style' => "null", 'field' => "end_date")));
     $positions = I2CE_FormStorage::listFields("person_position", array("position"), false, $pos_where);
     $results = array();
     foreach ($positions as $pers_pos => $data) {
         $results[] = str_replace('position|', '', $data['position']);
     }
     foreach ($people as $person) {
         $results[] = str_replace('person|', '', $person);
     }
     if (count($results) < 1) {
         return null;
     } else {
         return $results;
     }
 }
 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########################
 }
 /**
  * Create and load data for the objects used for this form.
  * 
  * Create the list object and if this is a form submission load
  * the data from the form data.
  */
 protected function loadObjects()
 {
     $this->evaluations = array();
     //make sure we have valid objects
     $ff = I2CE_FormFactory::instance();
     if ($this->id !== false) {
         $personScheduledCourse = $ff->createContainer($this->id);
         if (!$personScheduledCourse instanceof iHRIS_Person_Scheduled_Training_Course) {
             I2CE::raiseError("Cannot instantitatne person scheudled training course " . $this->id);
             return false;
         }
     } else {
         $personScheduledCourse = $ff->createContainer('person_scheduled_training_course');
         if (!$personScheduledCourse instanceof iHRIS_Person_Scheduled_Training_Course) {
             I2CE::raiseError("Cannot instantitatne person scheudled training course " . $this->id);
             return false;
         }
         $personScheduledCourse->load($this->post);
         $this->id = $personScheduledCourse->getNameId();
     }
     if ($personScheduledCourse->getId() == '0') {
         I2CE::raiseError("Bad ID");
         return false;
     }
     $personScheduledCourse->populate();
     $person_id = $personScheduledCourse->getParent();
     $person = $ff->createContainer($person_id);
     if (!$person instanceof iHRIS_Person) {
         I2CE::raiseError("No person:" . $person_id);
         return false;
     }
     $person->populate();
     $this->setObject($personScheduledCourse, I2CE_PageForm::EDIT_SECONDARY);
     $this->setObject($person, I2CE_PageForm::EDIT_PARENT);
     $comp_ids = iHRIS_Module_TrainingSimpleCompetency::getAssociatedCompetencies($personScheduledCourse);
     if (count($comp_ids) > 0) {
         $person_comps = array();
         foreach (I2CE_FormStorage::listFields('person_competency', 'competency', $person_id) as $pers_comp_id => $data) {
             if (!array_key_exists('competency', $data) || !$data['competency']) {
                 continue;
             }
             $person_comps[$data['competency']] = 'person_competency|' . $pers_comp_id;
         }
         $person_comp_objs = array();
         foreach ($comp_ids as $comp_id) {
             if (!array_key_exists($comp_id, $person_comps)) {
                 $pers_comp = $ff->createContainer('person_competency');
                 if (!$pers_comp instanceof iHRIS_PersonCompetency) {
                     I2CE::raiseError("Could not instantiatne person_competency");
                     return false;
                 }
                 $pers_comp->setParent($person_id);
                 $pers_comp->getField('competency')->setFromDB($comp_id);
             } else {
                 $pers_comp = $ff->createContainer($person_comps[$comp_id]);
                 if (!$pers_comp instanceof iHRIS_PersonCompetency) {
                     I2CE::raiseError("Could not instantiatne person_competency: " . $person_comps[$comp_id]);
                     return false;
                 }
                 $pers_comp->populate();
                 //don't need to populate here b/c taken care of by parent method
             }
             $node = $this->template->loadFile("training_course_evaluation_form.html", 'span');
             $pers_comp->load($this->post);
             $this->setObject($pers_comp, I2CE_PageForm::EDIT_SECONDARY, $node);
         }
     }
 }
 /**
  * Assigns compentices to a person based on the evaluation saved in a person scheduled training course
  * @param string $person_id the id of the person form e.g. 'person|12'
  * @param array $comp_ids of string.  The ids of competencies we want to esnure a pserson has.
  * @param string $comp_eval_id.  The competentcy evaluation we wish to assign to each person.
  * @param I2CE_DATE  $eval_date.  If null, then we use now as the date.
  * @param boolean $only_update.  If true (the default) we only update existing person competencies if the last evaluation date
  * is equal to or less than $eval_date.  
  * @returns boolean.  True on success
  */
 public static function assignAndEvaluateCompetencies($person_id, $comp_ids, $comp_eval_id, $eval_date = null, $only_update = true)
 {
     //lets get ids of the existing person_competncies
     $ff = I2CE_FormFactory::instance();
     $user = new I2CE_User();
     if (!$eval_date instanceof I2CE_Date) {
         $eval_date = I2CE_Date::now();
     }
     $person_comps = array();
     foreach (I2CE_FormStorage::listFields('person_competency', 'competency', $person_id) as $pers_comp_id => $data) {
         if (!array_key_exists('competency', $data) || !$data['competency']) {
             continue;
         }
         $person_comps[$data['competency']] = 'person_competency|' . $pers_comp_id;
     }
     foreach ($comp_ids as $comp_id) {
         if (!array_key_exists($comp_id, $person_comps)) {
             $pers_comp = $ff->createContainer('person_competency');
             if (!$pers_comp instanceof iHRIS_PersonCompetency) {
                 I2CE::raiseError("Could not instantiatne person_competency");
                 return false;
             }
             $pers_comp->setParent($person_id);
             $pers_comp->getField('competency')->setFromDB($comp_id);
         } else {
             $pers_comp = $ff->createContainer($person_comps[$comp_id]);
             if (!$pers_comp instanceof iHRIS_PersonCompetency) {
                 I2CE::raiseError("Could not instantiatne person_competency: " . $person_comps[$comp_id]);
                 return false;
             }
             $pers_comp->populate();
         }
         if ($only_update && $pers_comp->getField('evaluation_date')->isSetValue() && $eval_date->before($pers_comp->getField('evaluation_date')->getValue()) && !$eval_date->equals($pers_comp->getField('evaluation_date')->getValue())) {
             $pers_comp->cleanup();
             continue;
         }
         $pers_comp->getField('competency_evaluation')->setFromDB($comp_eval_id);
         $pers_comp->evaluation_date = $eval_date;
         $pers_comp->save($user);
         $person_comps[$comp_id] = $pers_comp->getNameId();
         //just in case we have the same comp_id twice in the $comp_ids array, we won't create two instances
         $pers_comp->cleanup();
     }
     return true;
 }