/** * Create a new I2CE_Date object with the current or given date and/or time. * @param integer $type The type of date object created. It defaults to date and time. * @param integer $time_stamp. Defaults to null in which case we use the current time stamp. If it is an array * then it should be the same array structture as returned by getdate() or the one returned by I2CE_Date::getValues() * @param mixed $strict . Defaults to false. If true, does not return now. If 'blank', returns the blank date. * @return mixed I2CE_Date or false if failure on strict mode */ public static function now($type = self::DATE_TIME, $time_stamp = null, $strict = false) { if (is_array($time_stamp)) { if (array_key_exists('value', $time_stamp)) { $time_stamp = I2CE_Date::fromDB($time_stamp['value'], $type)->getValues(); } $now = $time_stamp; } else { if ($time_stamp === null) { if ($strict === 'blank') { return self::blank($type); } else { if ($strict) { return false; } } $now = getdate(); } else { if (is_numeric($time_stamp)) { $now = getdate($time_stamp); } else { if ($strict === 'blank') { return self::blank($type); } else { if ($strict) { return false; } } } } } switch ($type) { case self::YEAR_ONLY: if (!array_key_exists('year', $now) || !$now['year']) { if ($strict === 'blank') { return self::blank($type); } else { if ($strict) { return false; } } } return self::getYear($now['year']); case self::YEAR_MONTH: if (array_key_exists('month', $now) && !array_key_exists('mon', $now)) { $now['mon'] = $now['month']; } if (!array_key_exists('year', $now) || !$now['year'] || !array_key_exists('mon', $now) || !$now['mon']) { if ($strict === 'blank') { return self::blank($type); } else { if ($strict) { return false; } else { $now = getdate(); } } } return self::getYearMonth($now['mon'], $now['year']); case self::MONTH_DAY: if (array_key_exists('day', $now) && !array_key_exists('mday', $now)) { $now['mday'] = $now['day']; } if (array_key_exists('month', $now) && !array_key_exists('mon', $now)) { $now['mon'] = $now['month']; } if (!array_key_exists('mday', $now) || !$now['mday'] || !array_key_exists('mon', $now) || !$now['mon']) { if ($strict === 'blank') { return self::blank($type); } else { if ($strict) { return false; } else { $now = getdate(); } } } return self::getDay($now['mday'], $now['mon']); case self::DATE: if (array_key_exists('day', $now) && !array_key_exists('mday', $now)) { $now['mday'] = $now['day']; } if (array_key_exists('month', $now) && !array_key_exists('mon', $now)) { $now['mon'] = $now['month']; } if (!array_key_exists('mday', $now) || !$now['mday'] || !array_key_exists('mon', $now) || !$now['mon'] || !array_key_exists('year', $now) || !$now['year']) { if ($strict === 'blank') { return self::blank($type); } else { if ($strict) { return false; } else { $now = getdate(); } } } return self::getDate($now['mday'], $now['mon'], $now['year']); case self::DATE_TIME: if (array_key_exists('hour', $now) && !array_key_exists('hours', $now)) { $now['hours'] = $now['hour']; } if (array_key_exists('minute', $now) && !array_key_exists('minutes', $now)) { $now['minutes'] = $now['minute']; } if (array_key_exists('second', $now) && !array_key_exists('seconds', $now)) { $now['seconds'] = $now['second']; } if (array_key_exists('day', $now) && !array_key_exists('mday', $now)) { $now['mday'] = $now['day']; } if (array_key_exists('month', $now) && !array_key_exists('mon', $now)) { $now['mon'] = $now['month']; } if (!array_key_exists('mday', $now) || !$now['mday'] || !array_key_exists('mon', $now) || !$now['mday'] || !array_key_exists('year', $now) || !$now['year'] || !array_key_exists('seconds', $now) || !array_key_exists('minutes', $now) || !array_key_exists('hours', $now)) { if ($strict === 'blank') { return self::blank($type); } else { if ($strict) { return false; } else { $now = getdate(); } } } return self::getDateTime($now['seconds'], $now['minutes'], $now['hours'], $now['mday'], $now['mon'], $now['year']); case self::TIME_ONLY: if (array_key_exists('hour', $now) && !array_key_exists('hours', $now)) { $now['hours'] = $now['hour']; } if (array_key_exists('minute', $now) && !array_key_exists('minutes', $now)) { $now['minutes'] = $now['minute']; } if (array_key_exists('second', $now) && !array_key_exists('seconds', $now)) { $now['seconds'] = $now['second']; } if (!array_key_exists('seconds', $now) || !array_key_exists('minutes', $now) || !array_key_exists('hours', $now)) { if ($strict === 'blank') { return self::blank($type); } else { if ($strict) { return false; } else { $now = getdate(); } } } return self::getTime($now['seconds'], $now['minutes'], $now['hours']); default: if (array_key_exists('day', $now) && !array_key_exists('mday', $now)) { $now['mday'] = $now['day']; } if (array_key_exists('month', $now) && !array_key_exists('mon', $now)) { $now['mon'] = $now['month']; } if (!array_key_exists('mday', $now) || !$now['mday'] || !array_key_exists('mon', $now) || !$now['mon'] || !array_key_exists('year', $now) || !$now['year']) { if ($strict === 'blank') { return self::blank($type); } else { if ($strict) { return false; } else { $now = getdate(); } } } I2CE::raiseError("An invalid date type was used for I2CE_Date::now. Defaulting to DATE."); return self::getDate($now['mday'], $now['mon'], $now['year']); } }
/** * Compares this form field agains the given form field. * @param mixed $db_value Either a DB Value or an I2CE_FormField * @returns -1,0,1 */ public function compare($db_value) { if (is_string($db_value)) { $db_value = I2CE_Date::fromDB($db_value); } else { if ($db_value instanceof I2CE_FormField_DB_Date) { $db_value = $db_value->getValue(); } } if (!$db_value instanceof I2CE_Date) { if ($this->isValid()) { return 1; } else { return 0; } } elseif (!$this->getValue() instanceof I2CE_Date) { I2CE::raiseError("Trying to compare a non-set date"); return -1; } return $this->getValue()->compare($db_value); }
/** * Return the list of scheduled course for the given course id. * @param integer $course_id. Defaults to zero meaning we get all courses * @param boolean $flat. defaults to false * @return array the keys are the id of the scheduled course, the values are the string "$start_date -- $end_date" */ public static function getScheduledCourses($course_id = 0, $flat = false) { if ($course_id > 0) { $flat = true; } $values = array(); foreach (array('start_date', 'end_date') as $field) { $data = I2CE_FormField::getFormFieldIdAndType('scheduled_training_course', $field); if (!is_array($data)) { I2CE::raiseError("Could not available courses b/c could not find field {$field} in form scheduled_training_course"); return array(); } $values[] = $data['id']; } $query = "SELECT le_start_date.record AS id, le_start_date.date_value AS start_date, le_end_date.date_value AS end_date, r.parent AS parent "; $query .= "FROM last_entry le_start_date "; $query .= "JOIN last_entry le_end_date ON le_start_date.record = le_end_date.record "; $query .= "JOIN record r ON le_start_date.record = r.id "; $query .= "WHERE le_start_date.form_field = ? "; $query .= "AND le_end_date.form_field = ? "; if ($course_id > 0) { $query .= "AND r.parent = ? "; $values[] = $course_id; } $query .= "ORDER BY le_start_date.date_value DESC, le_end_date.date_value ASC"; $db = MDB2::singleton(); $sth = $db->prepare($query, array('integer', 'integer'), MDB2_PREPARE_RESULT); if (I2CE::pearError($sth, "Could not setup statement to get available courses")) { return array(); } $results = $sth->execute($values); if (I2CE::pearError($results, "Could not get available courses")) { return array(); } $scheduled_courses = array(); while ($result =& $results->fetchRow()) { $start_date = I2CE_Date::fromDB($result->start_date); $end_date = I2CE_Date::fromDB($result->end_date); if ($flat) { $scheduled_courses[$result->id] = $start_date->displayDate() . " - " . $end_date->displayDate(); } else { $scheduled_courses[$result->parent][$result->id] = $start_date->displayDate() . " - " . $end_date->displayDate(); } } return $scheduled_courses; }
public function checkLimit_DB_DATE_in($fieldObj, $vals) { if (is_array($vals['value'])) { $vals = $vals['value']; } else { $vals = preg_split('/,/', $vals['value'], -1, PREG_SPLIT_NO_EMPTY); } $f_date = $fieldObj->getValue(); if (!$f_date instanceof I2CE_Date) { return null; } foreach ($vals as $val) { $date = I2CE_Date::fromDB($val); if (!$date instanceof I2CE_Date) { continue; } if ($f_date->equals($date)) { return true; } } return false; }
/** * Populate the history of entries for the form field if the storage module handles history. * @param I2CE_FormField $form_field * @return boolean */ public function FF_populateHistory($form_field) { $field = $form_field->getName(); $form = $form_field->getContainer(); if (!$form instanceof I2CE_Form) { return false; } if ($field == 'parent') { $fieldQry = $this->getRequiredFieldsQuery($form->getName(), array('last_modified', 'who'), $form->getId(), true); } else { $fieldQry = $this->getRequiredFieldsQuery($form->getName(), array($field, 'last_modified', 'who'), $form->getId()); } $result = $this->db->getRow($fieldQry); if (I2CE::pearError($result, "Error populating field {$field} of form " . $form->getName())) { return false; } $ref = $form->getName() . '+' . $field; $last_ref = $form->getName() . '+' . 'last_modified'; $who_ref = $form->getName() . '+' . 'who'; $date = null; $who = 99; if (isset($result->{$last_ref})) { $date = I2CE_Date::fromDB($result->{$last_ref}); } if (!$date instanceof I2CE_Date) { $date = I2CE_Date::blank(); } if (isset($result->{$who_ref})) { $who = $result->{$who_ref}; } if (isset($result->{$ref})) { $entry = new I2CE_Entry($date, $who, 0, $form_field->getFromDB($result->{$ref})); $form_field->addHistory($entry); } return true; }
/** * 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; }
/** * @param string $form. THe form name * @param array $fields of string. The fields we want returned * Can include the special field 'last_modified' to get the last modification time for any of the fields of that form which is returned in the format "Y-m-d H:i:s" * @param boolean $parent. Defaults to false. If it is scalar and non-boolean, it is consider to be the ID of the parent, * and then we get all forms with parent the given id. If true, we return the parent as one of the fields. * @param array $where_data. 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. * @param integer $mod_time. Defaults to -1. If non-negative, we only list the requested fields for an id if at least one of them has a modification * time greater than or equal to $mod_time. If the form storage has no way of tracking modifucation time, all entries are listed. * @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 function listDisplayFields($form, $fields, $parent = false, $where_data = array(), $ordering = array(), $limit = false, $mod_time = -1) { $vals = array(); $data_fields = $fields; if (($key = array_search('parent', $data_fields)) !== false) { unset($data_fields[$key]); if ($parent === false) { $parent = true; } } $order_fields = array(); $order_func = false; if (count($ordering) > 0) { $order_func = ''; foreach ($ordering as $order) { if (!is_string($order) || strlen($order) == 0) { continue; } if ($order[0] == '-') { $order = substr($order, 1); $order_fields[] = $order; $order_func .= "if ( array_key_exists('{$order}',\$a) && array_key_exists('{$order}',\$b)) { if (\$a['{$order}'] < \$b['{$order}']) return 1; if (\$a['{$order}'] > \$b['{$order}']) return -1;}"; } else { $order_fields[] = $order; $order_func .= "if ( array_key_exists('{$order}',\$a) && array_key_exists('{$order}',\$b)) { if (\$a['{$order}'] < \$b['{$order}']) return -1; if (\$a['{$order}'] > \$b['{$order}']) return 1;}"; } } $order_func .= 'return 0;'; $order_func = @create_function('$a,$b', $order_func); } $all_fields = array_unique(array_merge($data_fields, $this->getLimitedFields($where_data), $order_fields)); $new_fields = array_diff($all_fields, $data_fields); $factory = I2CE_FormFactory::instance(); $formObj = $factory->createContainer($form); if (!$formObj instanceof I2CE_Form && $this->config->is_parent("forms/{$form}")) { I2CE::raiseError("No data for form {$form} is stored in magic data"); return array(); } $func = $formObj->createCheckFunction($where_data); if ($func === false) { I2CE::raiseError("Bad limit data"); return array(); } if (is_array($mod_time) && array_key_exists('mod_time', $mod_time)) { $mod_time = $mod_time['mod_time']; } if (is_scalar($mod_time) && $mod_time >= 0) { $mod_time = I2CE_Date::now(I2CE_Date::DATE_TIME, $mod_time); } else { $mod_time = false; } if (!$this->config->is_parent("forms/{$form}")) { return array(); } $forms = $this->config->traverse("forms/{$form}"); if (count($order_fields) == 0) { foreach ($forms as $id => $form_config) { if (!$form_config instanceof I2CE_MagicDataNode) { continue; } if ($mod_time && $form_config->is_scalar('last_modified') && $mod_time->compare(I2CE_Date::fromDB($form_config->last_modified)) == -1) { continue; } $data = array(); foreach ($all_fields as $field) { if ($field == "id") { $data[$field] = $id; } else { if ($field == 'parent') { $data['parent'] = null; $form_config->setIfIsSet($data['parent'], 'parent'); } else { if ($field == 'last_modified') { $data['last_modified'] = date("Y-m-d H:i:s", 0); $form_config->setIfIsSet($data['last_modified'], 'last_modified'); } else { $data[$field] = null; $form_config->setIfIsSet($data[$field], "fields/{$field}"); } } } } if ($func && $func($data) !== true) { continue; } foreach ($new_fields as $field) { unset($data[$field]); } if ($parent === true) { $data['parent'] = 0; $form_config->setIfIsSet($data['parent'], 'parent'); } $vals[$id] = $data; } } else { foreach ($forms as $id => $form_config) { if (!$form_config instanceof I2CE_MagicDataNode) { continue; } if ($mod_time && $form_config->is_scalar('last_modified') && $mod_time->before(I2CE_Date::now(I2CE_Date::DATE_TIME, $form_config->last_modified))) { continue; } $data = array(); $displays = array(); foreach ($all_fields as $field) { if ($field == "id") { $data[$field] = $id; } else { if ($field == 'parent') { $data['parent'] = null; $form_config->setIfIsSet($data['parent'], 'parent'); } else { if ($field == 'last_modified') { $data['last_modified'] = date("Y-m-d H:i:s", 0); $form_config->setIfIsSet($data['last_modified'], 'last_modified'); } else { $fieldObj = $formObj->getField($field); $data[$field] = null; if ($fieldObj instanceof I2CE_FormField && $form_config->setIfIsSet($dbval, "fields/{$field}")) { $fieldObj->setFromDB($dbval); $data[$field] = $dbval; $displays[$field] = $fieldObj->getDisplayValue(); } else { $data[$field] = null; } } } } } if ($func && $func($data) !== true) { continue; } if ($parent === true) { $data['parent'] = 0; $form_config->setIfIsSet($data['parent'], 'parent'); } foreach ($displays as $field => $disp) { $data[$field] = $disp; } $vals[$id] = $data; } if ($order_func) { uasort($vals, $order_func); } if (count($new_fields) > 0) { foreach ($vals as &$data) { foreach ($new_fields as $field) { unset($data[$field]); } } } } I2CE_FormStorage::setLastListCount($form, count($vals)); if ($limit === true) { return array_slice($vals, 0, 1); } else { if (is_numeric($limit)) { return array_slice($vals, 0, $limit); } else { if (is_array($limit)) { list($offset, $limit) = $limit; return array_slice($vals, $offset, $limit); } else { return $vals; } } } }
/** * Handle any additional actions after all the child forms have * been loaded on the user view page. * @param iHRIS_PageViewUser $page */ public function post_page_view_user($page) { if (!$page instanceof iHRIS_PageViewUser) { I2CE::raiseError("post_page_view_user hook called on a page that isn't the View User page."); return; } $user = $page->getViewUser(); $template = $page->getTemplate(); $defaults = I2CE::getConfig()->modules->UserStatistics->defaults; $login_limit = 10; $defaults->setIfIsSet($login_limit, "login_limit"); $userAccess = I2CE::getUserAccess(); $username = $user->getId(); $userid = $userAccess->getUserId($username); $logins = self::getLoginHistory($userid, $login_limit); $template->addHeaderLink("view_user_statistics.css"); $stats_node = $template->appendFileById("view_user_statistics_login_history.html", "div", "user_details"); $template->setDisplayDataImmediate("history_limit", $login_limit, $stats_node); if ($logins) { while ($row = $logins->fetchRow()) { $node = null; if ($row->logout) { $node = $template->appendFileById("view_user_statistics_logged_out.html", "tr", "user_stats_login_history"); $logout = I2CE_Date::fromDB($row->logout); $template->setDisplayDataImmediate("user_stats_logout", $logout->displayDate(), $node); } else { $node = $template->appendFileById("view_user_statistics_logged_in.html", "tr", "user_stats_login_history"); $activity = I2CE_Date::fromDB($row->activity); $template->setDisplayDataImmediate("user_stats_activity", $activity->displayDate(), $node); } $login = I2CE_Date::fromDB($row->login); $template->setDisplayDataImmediate("user_stats_login", $login->displayDate(), $node); } } $days_limit = 5; $defaults->setIfIsSet($days_limit, "days_forms_limit"); if (!self::setupEntryHistory($userid, $username, $days_limit)) { I2CE::raiseError("Unable to set up entry history for {$userid} ({$days_limit} days)"); return; } if (self::$entries[$userid]['has_person']) { $person_node = $template->appendFileById("view_user_statistics_person_history.html", "div", "user_details"); $template->setDisplayDataImmediate("days_limit", $days_limit, $person_node); foreach (self::$entries[$userid]['dates'] as $date => $data) { if (count($data['person']) > 0) { $node = $template->appendFileById("view_user_statistics_person_row.html", "tr", "user_stats_person_history"); $dateObj = I2CE_Date::fromDB($date); $template->setDisplayDataImmediate("user_stats_person_date", $dateObj->displayDate(), $node); $template->setDisplayDataImmediate("user_stats_person_count", count($data['person']), $node); } } } if (self::$entries[$userid]['has_forms']) { $forms_node = $template->appendFileById("view_user_statistics_form_history.html", "div", "user_details"); $template->setDisplayDataImmediate("days_limit", $days_limit, $forms_node); $displays = array(); $formConfig = I2CE::getConfig()->modules->forms->forms; foreach (self::$entries[$userid]['dates'] as $date => $data) { $date_node = $template->appendFileById("view_user_statistics_form_date.html", "tr", "user_stats_form_history"); $dateObj = I2CE_Date::fromDB($date); $template->setDisplayDataImmediate("form_date", $dateObj->displayDate(), $date_node); $total = 0; ksort($data['forms']); foreach ($data['forms'] as $form => $count) { if (!array_key_exists($form, $displays)) { if (!empty($formConfig->{$form}->display)) { $displays[$form] = $formConfig->{$form}->display; } else { $displays[$form] = $form; } } $form_node = $template->appendFileById("view_user_statistics_form_row.html", "tr", "user_stats_form_history"); $template->setDisplayDataImmediate("form_form", $displays[$form], $form_node); $template->setDisplayDataImmediate("form_count", $count, $form_node); $total += $count; } $total_node = $template->appendFileById("view_user_statistics_form_total.html", "tr", "user_stats_form_history"); $template->setDisplayDataImmediate("form_date", $dateObj->displayDate(), $total_node); $template->setDisplayDataImmediate("total_count", $total, $total_node); } } }
/** * Populate the history of entries for the form field if the storage module handles history. * @param I2CE_FormField $form_field * @return boolean */ public function FF_populateHistory($form_field) { if ($form_field->getName() == 'parent') { $sth = $this->db->prepare("SELECT last_modified AS date,0 AS who,0 AS change_type, CONCAT(parent_form,'|',parent_id) as value FROM record WHERE id = ? ", array("integer"), MDB2_PREPARE_RESULT); if (I2CE::pearError($sth, "Error preparing to populate history:")) { return false; } $result = $sth->execute(array($form_field->getContainer()->getId())); } else { if (!($formObj = $form_field->getContainer()) instanceof I2CE_Form) { return false; } $this->setupForm($formObj); $sth = $this->db->prepare("SELECT date,who,change_type," . $form_field->getTypeString() . "_value as value FROM entry WHERE record = ? AND form_field = ? ORDER BY date", array("integer", "integer"), MDB2_PREPARE_RESULT); if (I2CE::pearError($sth, "Error preparing to populate history:")) { return false; } $result = $sth->execute(array($form_field->getContainer()->getId(), $form_field->getAttribute("DBEntry_form_field_id"))); if (I2CE::pearError($result, "Error executing populate history: ")) { return false; } } $has_been_set = false; while ($data = $result->fetchRow()) { if (!$has_been_set && !isset($data->value)) { continue; } $has_been_set = true; $entry = new I2CE_Entry(I2CE_Date::fromDB($data->date), $data->who, $data->change_type, $form_field->getFromDB($data->value)); $form_field->addHistory($entry); } $result->free(); $sth->free(); return true; }
/** * Perform the main actions of the page. * @return boolean */ protected function action() { if (!parent::action()) { I2CE::raiseError("Base action failed"); return false; } if (!$this->hasPermission("task(person_can_edit_child_form_person_scheduled_training_course)")) { $no_edit = "You do not have permission to edit students for this course instance."; I2CE::getConfig()->setIfIsSet($no_edit, "/modules/training-course/translatable-strings/no_edit_students"); $this->userMessage($no_edit); I2CE::raiseError("Cannot edit"); return false; } $piObj = false; $person_instance = false; if ($this->request_exists('scheduled_training_course')) { if (!$this->request_exists('person')) { I2CE::raiseError("No person"); return true; } $person_instance = $this->getPersonInstance($this->request('person'), $this->request('scheduled_training_course')); } else { if ($this->request_exists('person_scheduled_training_course')) { $person_instance = $this->request('person_scheduled_training_course'); } } if ($person_instance && !($piObj = I2CE_FormFactory::instance()->createContainer($person_instance)) instanceof iHRIS_Person_Scheduled_Training_Course) { I2CE::raiseError("No scheuled course associated to " . $this->request('person')); $this->template->addFile('action_students_error.html'); return false; } if ($person_instance) { $piObj->populate(); switch ($this->request('action')) { case 'student_module': if (($modField = $piObj->getField('training_course_mod')) instanceof I2CE_FormField_MAP_MULT && ($mod = $this->request('training_course_mod'))) { $e_mod = explode("|", $mod); if ($e_mod[0] == 'training_course_mod' && $e_mod[1] != '0' && $e_mod[1] != '') { $val = $modField->getValue(); $t_val = $val; foreach ($t_val as &$v) { $v = implode("|", $v); } unset($v); if (($pos = array_search($mod, $t_val)) === false) { $val[] = $e_mod; } else { unset($val[$pos]); } $modField->setValue($val); } } break; case 'certify': if (($certField = $piObj->getField('certification_date')) instanceof I2CE_FormField_DATE_YMD) { if ($this->request_exists('certification_date')) { $date = I2CE_Date::fromDB($this->request('certification_date')); } else { $date = I2CE_Date::now(); } $certField->setValue($date); } break; case 'evaluation': $piObj->getField('training_course_evaluation')->setValue(explode('|', $this->request('evaluation'), 2)); break; case 'remove': $piObj->attending = 0; $this->template->addFile("action_students_remove.html"); break; default: if ($piObj->attending == 0) { $piObj->attending = 1; $this->template->addFile("action_students_add.html"); } else { $piObj->attending = 0; $this->template->addFile("action_students_remove.html"); } break; } } else { if (!($piObj = I2CE_FormFactory::instance()->createContainer('person_scheduled_training_course')) instanceof iHRIS_Person_Scheduled_Training_Course) { I2CE::raiseError("Could not create person_scheduled_training_course"); return false; } $piObj->setParent($this->request('person')); $piObj->getField('scheduled_training_course')->setFromDB($this->request('scheduled_training_course')); $piObj->getField('attending')->setFromDB(1); $this->template->addFile("action_students_add.html"); } I2CE::raiseError("Performing " . $this->request('action') . " on student " . $piObj->getParent() . " from " . $piObj->getField('scheduled_training_course')->getDBValue()); return $piObj->save($this->user); }