/** * Create and load data for the objects used for this form. * * Create the list object and if this is a form submission load * the data from the form data. It determines the type based on the * {@link $type} member variable. */ protected function loadObjects() { $pers_pos = $this->factory->createContainer('person_position|0'); if (!$pers_pos instanceof I2CE_Form) { return; } if ($this->isPost()) { $pers_pos->load($this->post); if (!$pers_pos->end_date->isValid()) { $pers_pos->end_date = I2CE_Date::now(); } } else { $pers_pos->setID($this->get('id')); $pers_pos->populate(); } $person = $this->factory->createContainer($pers_pos->getParent()); if (!$person instanceof I2CE_Form) { return; } $person->populate(); $this->setObject($pers_pos); $this->setObject($person, I2CE_PageForm::EDIT_PARENT); $this->position = $this->factory->createContainer($this->getPrimary()->getField("position")->getDBValue()); $this->position->statusOnly(); if ($this->isPost()) { //$this->position->setStatus( $_POST[ $this->position->getField('status')->getHTMLName() ] ); $this->position->setFromPost($this->post); } }
/** * Handle the actions for the page. * @return boolean */ protected function action() { if (!$this->get_exists('id')) { $this->template->addFile("user_alerts_acknowledge_invalid.html"); return true; } else { $user_alert = I2CE_FormFactory::instance()->createContainer($this->get('id')); if (!$user_alert instanceof iHRIS_UserAlert) { $this->template->addFile("user_alerts_acknowledge_invalid.html"); return true; } $user_alert->populate(); $user = $this->getUser(); if (!$user_alert->getParentId()) { $this->template->addFile("user_alerts_acknowledge_invalid.html"); return true; } if ($user_alert->getParentId() != $user->username && !$this->hasPermission("task(user_alerts_edit_all)")) { $this->template->addFile("user_alerts_acknowledge_perms.html"); return true; } if ($user_alert->time_ack->equals(I2CE_Date::blank())) { $user_alert->time_ack = I2CE_Date::now(); $user_alert->save($user); } if (array_key_exists('HTTP_REFERER', $_SERVER)) { $this->setRedirect($_SERVER['HTTP_REFERER']); } else { $this->setRedirect("view_alerts"); } } return true; }
public function processDOMEditable($node, $template, $form_node) { $default = $this->getValue(); $ele_name = $this->getHTMLName(); if (!$default instanceof I2CE_Date) { $default = I2CE_Date::now(); } if ($this->use_date_picker) { $date = $default->dbFormat(); $attrs = array("class" => "datepicker_ymd", "name" => $ele_name, "type" => "text", "value" => $date); foreach (array('onclick', 'onchange') as $attr) { if ($node->hasAttribute($attr)) { $attrs[$attr] = $node->getAttribute($attr); $node->removeAttribute($attr); } } $element = $template->createElement("input", $attrs); $this->setElement($element); $node->appendChild($element); $args = array('format' => 'F j, Y', 'inputOutputFormat' => 'Y-m-d', 'allowEmpty' => true, 'startView' => 'decades'); $add_args = I2CE::getConfig()->getAsArray("/modules/DatePicker/options"); if (is_array($add_args)) { $args = array_merge($args, $add_args); } $template->addDatePicker('datepicker_ymd', $args); } else { I2CE_Date::addMonthDayElement($template, $ele_name, $default, $this->hasInvalid(), $node); I2CE_Date::addYearElement($template, $ele_name, $default, $this->hasInvalid(), $node, $this->getYearRange(), false, true); } }
public function processDOMEditable($node, $template, $form_node) { $ele_name = $this->getHTMLName(); $default = $this->getValue(); if (!$default instanceof I2CE_Date) { $default = I2CE_Date::now(); } I2CE_Date::addTimeElement($template, $ele_name, $default, $this->hasInvalid(), $node); }
public function action_person_instance($obj) { if (!$obj instanceof iHRIS_PageView) { return; } $person = $obj->getPerson(); $where = array('operator' => 'FIELD_LIMIT', 'field' => 'attending', 'style' => 'yes'); $person->populateChild('person_instance', null, $where); foreach ($person->children['person_instance'] as $key => $child) { $provider_instance = $child->getField('provider_instance')->getMappedFormObject(); if ($provider_instance->end_date instanceof I2CE_Date && $provider_instance->end_date->before(I2CE_Date::now())) { unset($person->children['person_instance'][$key]); } } return $obj->appendChildTemplate('person_instance'); }
public static function getAccidents($person, $only_active = true) { $accidents = array(); $factory = I2CE_FormFactory::instance(); if (is_string($person)) { $person = $factory->createContainer('person|' . $person_id); } if (!$person instanceof iHRIS_Person) { return $accidents; } if ($only_active) { $where = array('operator' => 'FIELD_LIMIT', 'field' => 'end_date', 'style' => 'greaterthan_equals', 'data' => I2CE_Date::now(I2CE_DATE::DATE)->getValues()); } else { $where = array(); } $accidentIds = $person->getChildIds('accident', 'start_date', $where); //get all accidents actions in order of increasing start date $now = I2CE_Date::now(); foreach ($accidentIds as $id) { $accident = $factory->createContainer('accident|' . $id); $accident->populate(); if (!$accident instanceof iHRIS_Accident || $accident->getId() == '0') { continue; } $accidents[] = $accident; } return $accidents; }
public function checkLimit_lessthan_equals_now($fieldObj, $vals) { if (!$fieldObj->getValue() instanceof I2CE_Date) { return null; } return !I2CE_Date::now()->before($fieldObj->getValue()); }
public static function getDisciplinaryActions($person, $only_active = true) { $discActions = array(); $factory = I2CE_FormFactory::instance(); if (is_scalar($person)) { $person = $factory->createContainer($person); } if (!$person instanceof iHRIS_Person) { return $discActions; } if ($only_active) { $where = array('operator' => 'OR', 'operand' => array(0 => array('operator' => 'FIELD_LIMIT', 'field' => 'end_date', 'style' => 'greaterthan_equals', 'data' => I2CE_Date::now(I2CE_DATE::DATE)->getValues()), 1 => array('operator' => 'FIELD_LIMIT', 'field' => 'end_date', 'style' => 'null'))); } else { $where = array(); } $discActionIds = $person->getChildIds('disciplinary_action', 'start_date', $where); //get all disciplinary actions in order of increasing start date foreach ($discActionIds as $id) { $discAction = $factory->createContainer('disciplinary_action|' . $id); $discAction->populate(); if (!$discAction instanceof iHRIS_DisciplinaryAction || $discAction->getId() == '0') { continue; } $discActions[] = $discAction; } return $discActions; }
/** * 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; }
/** * Template function to see if person_can_view_child_forms * @param DOMNode $node * @param I2CE_Template $template * @param string $link */ public function userAccessDepartment($node, $template) { // This should only work for the facility_manager role so ignore any others. if ($template->getUser()->getRole() != "department_manager") { return false; } if (!$template instanceof I2CE_Template) { return false; } if (!$node instanceof DOMNode) { $node = null; } if (!($person = $template->getForm('person', $node)) instanceof iHRIS_Person) { //No person associated with this node. so this user can have permission return true; } $access = self::getAccessDepartment($template->getUser()); // a list of locations a user is allowed to access if (count($access) == 0) { return false; } //look at the positions this person has had sorted by start date $person->populateLast(array("person_position" => "start_date")); if (!array_key_exists('person_position', $person->children) || !is_array($person->children['person_position']) || count($person->children['person_position']) == 0) { // If there is not person position then access is granted. return true; } foreach ($person->children['person_position'] as $pers_pos) { if ($pers_pos->end_date->isValid() && $pers_pos->end_date->before(I2CE_Date::now())) { // Not a current employee so access is granted. return true; } $position = $pers_pos->getField("position")->getMappedFormObject(); if (!$position instanceof iHRIS_Position) { continue; } if (in_array($position->getField('department')->getDBValue(), $access)) { return true; } } return false; }
/** * 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; }
/** * Save a form object into magicdata * @param I2CE_Form $form * @param I2CE_User $user * @param boolean $transact */ public function save($form, $user, $transact) { $form_id = $form->getId(); if (!$form_id) { $form_id = $this->getNextAvailableId($form->getName()); } if (!$form_id) { return false; } $form->setId($form_id); $form_config = $this->getFormConfig($form, true); if (!$form_config instanceof I2CE_MagicDataNode) { return false; } $form_config->last_modified = I2CE_Date::now(I2CE_Date::DATE_TIME)->dbFormat(); $form_config->who = $user->getId(); $parent = $form->getParent(); if ($parent != "") { /* Does this need to be here? the parent node may be new and doesn't exist... if ($form_config->is_parent('parent')) { return false; } */ $form_config->parent = $parent; } return parent::save($form, $user, $transact); }
/** * Return the year range for this field if it's a date. * @return array * @global array */ public function getYearRange() { $config = I2CE::getConfig()->modules->forms->defaults; if ($this->start_year == 0) { if (isset($config->default_start_year) && !$config->default_start_year instanceof I2CE_MagicDataNode) { $this->start_year = $config->default_start_year; } else { $this->start_year = 1955; } } if ($this->end_year == 0) { $now = I2CE_Date::now(); if (isset($config->default_end_year_increment) && !$config->default_end_year_increment instanceof I2CE_MagicDataNode) { $this->end_year = $now->year() + $config->default_end_year_increment; } else { $this->end_year = $now->year() + 10; } } return array($this->start_year, $this->end_year); }
/** * Return an array of all the record ids for a given form. * @param string $form * @param integer $mod_time. Defaults to -1. If non-negative, it is a unix timestamp and we retrieve records modified at or after the given time * @param string $parent Defaults to false. If true, The parent field we want to restrict values to * @return array */ public function getRecords($form, $mod_time = -1, $parent = false) { $storageOptions = $this->getStorageOptions($form); if (!$storageOptions instanceof I2CE_MagicDataNode) { I2CE::raiseError("Bad storage options"); return array(); } $getRecords = null; if (!$storageOptions->setIfIsSet($getRecords, 'records')) { I2CE::raiseError("Nothing to get records for {$form}"); return array(); } @eval('$records = ' . $getRecords . ';'); if (!is_array($records)) { I2CE::raiseError("invalid eval"); return array(); } if ($mod_time) { $mod_time = I2CE_Date::now(I2CE_Date::DATE_TIME, $mod_time); } if ($mod_time >= 0 || $parent) { //probably could be faster but I don't think it's used $ff = I2CE_FormFactory::instance(); foreach ($records as $i => $id) { if (!($obj = $ff->createForm($form . '|' . $id)) instanceof I2CE_Form || !$obj->populate() || $parent && $obj->getParent() != $parent || $mod_time && $mod_time->compare($obj->getField('last_modified')->getValue()) == -1) { unset($records[$i]); continue; } } } return $records; }
/** * Return a DateTime object to use for formatting this I2CE_Date object. * @return DateTime */ public function getDateTimeObj() { try { // DateTime objects need a month/day so handle separately for // DATE_Y if ($this->type == self::YEAR_ONLY) { $obj = new DateTime($this->year . "-01-01"); } elseif ($this->type == self::YEAR_MONTH) { $obj = new DateTime($this->year . "-" . $this->month . "-01"); } elseif ($this->type == self::MONTH_DAY) { $now = I2CE_Date::now(); $obj = new DateTime($now->year() . "-" . $this->month . "-" . $this->day); } else { $obj = new DateTime($this->dbFormat(true)); } } catch (Exception $e) { I2CE::raiseError("Invalid DateTime object: " . $e->getMessage()); return false; } return $obj; }
/** * 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() { if (!$this->permissionParser->hasTask('person_can_edit_child_form_person_scheduled_training_course')) { $this->userMessage("You do not have permission to add or edit a person's scheduleing of training course", 'notice', true); $this->setRedirect('noaccess'); return false; } $factory = I2CE_FormFactory::instance(); $personScheduledCourse = $factory->createContainer($this->id); if (!$personScheduledCourse instanceof I2CE_Form) { return false; } $this->setObject($personScheduledCourse); if ($personScheduledCourse->getId() != '0') { $personScheduledCourse->populate(); $this->person_id = $personScheduledCourse->getParent(); if ($personScheduledCourse->getField('request_date')->issetValue()) { $personScheduledCourse->request_date = I2CE_Date::now(); } } if ($this->person_id === false) { return false; } $parent = $factory->createContainer($this->person_id); if ($parent instanceof I2CE_Form) { $parent->populate(); $this->setObject($parent, I2CE_PageForm::EDIT_PARENT); } parent::loadObjects(); }
/** * 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() { //make sure we have valid objects $ff = I2CE_FormFactory::instance(); if ($this->isPost()) { if ($this->request_exists('id') && $this->request('id')) { if (!($primary = $this->factory->createContainer($this->request('id'))) instanceof iHRIS_Training_Course_Exam) { return false; } $primary->populate(); $primary->load($this->post); } else { if (!($primary = $this->factory->createContainer('training_course_exam')) instanceof iHRIS_Training_Course_Exam) { return false; } $primary->load($this->post); } if (($primary->getParent() == '0' || $primary->getParent() == '' || $primary->getParent() == '|') && $this->request('parent')) { $primary->setParent($this->request('parent')); } } elseif ($this->get_exists('id')) { if ($this->get_exists('id')) { $id = $this->get('id'); if (strpos($id, '|') === false) { I2CE::raiseError("Deprecated use of id variable"); $id = 'training_course_exam|' . $id; } } else { $id = 'training_course_exam|0'; } $primary = $this->factory->createContainer($id); if (!$primary instanceof iHRIS_Training_Course_Exam) { I2CE::raiseError("Could not create valid training_course_exam from id:{$id}"); return false; } $primary->populate(); } elseif ($this->get_exists('parent')) { $primary = $this->factory->createContainer('training_course_exam|0'); if (!$primary instanceof iHRIS_Training_Course_Exam) { return false; } $parent = $this->get('parent'); if (strpos($parent, '|') === false) { I2CE::raiseError("Deprecated use of parent variable"); $parent = 'person|' . $id; } $primary->setParent($parent); } if ($this->isGet()) { $primary->load($this->get()); } if (!($personScheduledCourse = $ff->createContainer($primary->getParent())) instanceof iHRIS_Person_Scheduled_Training_Course) { I2CE::raiseError("Cannot instantitatne person scheudled training course " . $primary->getParent()); return false; } $this->template->setDisplayData('parent', $personScheduledCourse->getNameId()); $personScheduledCourse->populate(); if (!($person = $ff->createContainer($personScheduledCourse->getParent())) instanceof iHRIS_Person) { I2CE::raiseError("bad person " . $personScheduledCourse->getParent()); return false; } $person->populate(); if ($personScheduledCourse->getId() == '0') { I2CE::raiseError("Bad ID"); return false; } if (!($scheduledTrainingCourse = $ff->createContainer($personScheduledCourse->scheduled_training_course)) instanceof iHRIS_Scheduled_Training_Course) { I2CE::raiseError("No linked scheduled training course"); return false; } $scheduledTrainingCourse->populate(); if (!($trainingCourse = $ff->createContainer($scheduledTrainingCourse->training_course)) instanceof iHRIS_Training_Course) { I2CE::raiseError("No linked training course"); return false; } $trainingCourse->populate(); $this->personScheduledTrainingCourse = $personScheduledCourse; $this->trainingCourse = $trainingCourse; $this->person = $person; $this->template->setDisplayData('passing_score', $trainingCourse->passing_score); if ($this->request_exists('action') && $this->request('action') == 'updatescore' && $this->request_exists('exam_type') && $this->request('exam_type')) { $primary->getField('training_course_exam_type')->setFromDB('training_course_exam_type|' . $this->request('exam_type')); $primary->getField('score')->setFromDB($this->request('score')); $primary->getField('evaluation_date')->setValue(I2CE_Date::now()); } $this->setObject($primary); }
/** * Perform any actions for the page. * @return boolean */ public function action() { if (count($this->request_remainder) > 0) { $cacheControl = array_shift($this->request_remainder); $usModule = I2CE_ModuleFactory::instance()->getClass("UserStatistics"); switch ($cacheControl) { case "updateCacheForce": if ($usModule->cacheUserStatistics(false, true)) { I2CE::raiseMessage("Updated user statistics."); } else { I2CE::raiseError("Failed to force cache user statistics."); } break; case "updateCache": if ($usModule->cacheUserStatistics()) { I2CE::raiseMessage("Updated user statistics."); } else { I2CE::raiseError("Failed to cache user statistics."); } } } if (!parent::action()) { return false; } if ((array_key_exists('admin_only', $this->args) ? $this->args['admin_only'] : true) && !$this->hasPermission('role(admin)')) { return false; } $this->template->setAttribute("class", "active", "menuConfigure", "a[@href='configure']"); $this->template->appendFileById("menu_configure.html", "ul", "menuConfigure"); $this->template->setAttribute("class", "active", "menuUserStatistics", "a[@href='UserStatistics']"); $displayObj = new iHRIS_CustomReport_Display_UserStatistics($this, "UserStatistics"); $contentNode = $this->template->getElementById('siteContent'); if (!$contentNode instanceof DOMNode) { I2CE::raiseError("Couldn't find siteContent node."); return false; } $this->template->addHeaderLink("customReports_display_Default.css"); $this->template->setDisplayData("limit_description", false); if ($displayObj->display($contentNode)) { //$cacheControl = $this->template->appendFileById( "user_statistics_cache_control.html", "div", "report_results", 0, null, true ); $limitNode = $this->template->getElementByName("report_view_limit_description", 0); $cacheNode = $this->template->createElement("div", array("id" => "user_statistics_cache_control")); $limitNode->parentNode->insertBefore($cacheNode, $limitNode->nextSibling); $cacheControl = $this->template->appendFileById("user_statistics_cache_control.html", "div", "user_statistics_cache_control"); $config = I2CE::getConfig()->modules->UserStatistics->cache; $config->volatile(true); $start = 0; $end = 0; $failed = 0; $config->setIfIsSet($start, "start"); $config->setIfIsSet($end, "end"); $config->setIfIsSet($failed, "failed"); $st_date = I2CE_Date::now(I2CE_DATE::DATE_TIME, $start); //I2CE::raiseMessage("last started on " . $st_date->displayDate() ); if ($start == 0) { $this->launchBackgroundPage("/UserStatistics/cache"); } else { if ($end != 0) { $end_date = I2CE_Date::now(I2CE_Date::DATE_TIME, $end); $this->setDisplayDataImmediate("last_cache_end", $end_date->displayDate(), $cacheControl); } else { $this->setDisplayDataImmediate("last_cache_end", "Never Cached", $cacheControl); } if ($end >= $start) { $this->template->addFile("user_statistics_cache_status_done.html", "p"); } elseif ($failed >= $start) { $this->template->addFile("user_statistics_cache_status_failed.html", "p"); } else { $this->template->addFile("user_statistics_cache_status_running.html", "p"); } } return true; } else { return false; } }
/** * Template function to see if person_can_view_child_forms * @param DOMNode $node * @param I2CE_Template $template * @param string $link */ public function userAccessFacilityDataEntrant($node, $template) { // This should only work for the facility_manager role so ignore any others. if ($template->getUser()->getRole() != "facility_data_entrant") { return false; } if (!$template instanceof I2CE_Template) { return false; } if (!$node instanceof DOMNode) { $node = null; } if (!($person = $template->getForm('person', $node)) instanceof iHRIS_Person) { //No person associated with this node. so this user can have permission return true; } $access = self::getAccessLocation($template->getUser()); // a list of locations a user is allowed to access if (count($access) == 0) { return false; } //look at the positions this person has had sorted by start date $person->populateLast(array("person_position" => "start_date")); if (!array_key_exists('person_position', $person->children) || !is_array($person->children['person_position']) || count($person->children['person_position']) == 0) { // If there is not person position then access is granted. return true; } $fieldWalks = array('facility' => 'location', 'county' => 'district', 'district' => 'region', 'region' => 'country', 'country' => false); $formObjs = $this->getTemplateForms($template, $node, array_keys($fieldWalks)); $fieldWalks['position'] = 'facility'; foreach ($person->children['person_position'] as $pers_pos) { if ($pers_pos->end_date->isValid() && $pers_pos->end_date->before(I2CE_Date::now())) { // Not a current employee so access is granted. return true; } $position = $pers_pos->getField("position")->getMappedFormObject(); if (!$position instanceof iHRIS_Position) { continue; } $t_formObjs = $formObjs; $t_formObjs['position'] = $position; if ($this->ValidateAccessAgainstWalkableForms($fieldWalks, $access, $t_formObjs)) { return true; } } return false; }
protected function archive() { if (count($this->request_remainder) != 1) { $this->userMessage("Cannot archive report"); $this->setRedirect("CustomReports/view/reportViews"); return false; } reset($this->request_remainder); $reportView = (string) current($this->request_remainder); $config = I2CE::getConfig()->modules->CustomReports; if (strlen($reportView) == 0 || !$config->is_parent("reportViews/{$reportView}")) { $this->userMessage("Cannot archive report"); $this->setRedirect("CustomReports/view/reportViews"); return false; } if (isset($config->reportViews->{$reportView}->limit_view_to) && $config->reportViews->{$reportView}->limit_view_to) { if (!$this->hasPermission(' task(custom_reports_admin) or ' . $config->reportViews->{$reportView}->limit_view_to)) { $this->userMessage("You do not have permission to view this report"); $this->setRedirect("CustomReports/view/reportViews"); return false; } } if (!isset($config->displays->Export) || !isset($config->displays->Export->class)) { I2CE::raiseError("No report display {$display}"); continue; } $displayClass = $config->displays->Export->class; try { $displayObj = new $displayClass($this, $reportView); } catch (Exception $e) { $this->userMessage("Could not archive report data"); $this->setRedirect("CustomReports/view/reportViews"); return false; } if (!$displayObj instanceof I2CE_CustomReport_Display_Export) { $this->userMessage("Could not archive the report data"); $this->setRedirect("CustomReports/view/reportViews"); return false; } $output = $displayObj->generateExport(); if (!$output) { $this->userMessage("Nothing archived"); $this->setRedirect("CustomReports/view/reportViews"); return false; } $filename = $displayObj->getFileName(); $ff = I2CE_FormFactory::instance(); $date = I2CE_Date::now(I2CE_DATE::DATE)->dbFormat(); $ids = I2CE_Module_ReportArchiver::getArchiveIds($reportView, $date); //only allow one per day if (count($ids) == 1) { $replaced = true; reset($ids); $archiveObj = $ff->createContainer('archived_report|' . current($ids)); } else { if (count($ids) > 2) { $this->userMessage("Unable to save report data -- to many exisitng reports for today"); $this->setRedirect("CustomReports/view/reportViews"); return false; } else { $replaced = false; $archiveObj = $ff->createContainer('archived_report'); } } if (!$archiveObj instanceof I2CE_ArchivedReport) { $this->userMessage("Unable to save report"); $this->setRedirect("CustomReports/view/reportViews"); return false; } $docField = $archiveObj->getField('report'); if (!$docField instanceof I2CE_FormField_BINARY_FILE) { $this->userMessage("Unable to save report data"); $this->setRedirect("CustomReports/view/reportViews"); return false; } $docField->setFromData($output, $filename); $dn = $reportView; $config->setIfIsSet($dn, "reportViews/{$reportView}/display_name"); $archiveObj->name = $dn; $archiveObj->report_view = $reportView; $archiveObj->save($this->user); if ($replaced) { $this->userMessage("Succesully replaced existing archived report"); } else { $this->userMessage("Succesully archived report"); } $this->redirect("CustomReports/view/reportViews"); }
protected function actionRolesSave() { if (count($this->request_remainder) == 0) { //adding new role if (!$this->post_exists('role_short_name')) { $this->userMessage("No role short name set", 'notice', false); return; } $role = $this->post('role_short_name'); if (array_key_exists($role, self::$fixed_roles)) { $this->userMessage("Invalid Role {$role} short name specified", 'notice', false); return; } if (!$role || !I2CE_MagicDataNode::checkKey($role) || I2CE::getConfig()->is_parent("/I2CE/formsData/forms/role/{$role}")) { $this->userMessage("Bad role short name {$role}", 'notice', false); return; } if (!$this->post_exists('role_name') || !$this->post('role_name')) { $this->userMessage("No role display name set", 'notice', false); return; } //we are good to go. I2CE::getConfig()->I2CE->formsData->forms->role->{$role}->fields->name = $this->post('role_name'); I2CE::getConfig()->I2CE->formsData->forms->role->{$role}->last_modified = I2CE_Date::now(I2CE_Date::DATE_TIME)->dbFormat(); } else { if (count($this->request_remainder) == 1) { $role = $this->request_remainder[0]; if (!$role || array_key_exists($role, self::$fixed_roles)) { $this->userMessage("Invalid Role {$role} specified", 'notice', false); return; } $roleBaseConfig = I2CE::getConfig()->traverse("/I2CE/formsData/forms/role/", false); if (!$roleBaseConfig instanceof I2CE_MagicDataNode) { $this->userMessage("System Error", 'notice', false); return; } $roleConfig = $roleBaseConfig->traverse("{$role}/fields", false); if (!$roleConfig instanceof I2CE_MagicDataNode) { $this->userMessage("Invalid Role {$role} specified", 'notice', false); return; } $post = $this->post(); if (!array_key_exists('role_name', $post) || !$post['role_name']) { $this->userMessage("No role display name set", 'notice', false); return; } if ($roleConfig->is_translatable("name")) { $locale = I2CE_Locales::getPreferredLocale(); $roleConfig->setTranslation($locale, $post['role_name'], "name"); if ($locale == I2CE_Locales::DEFAULT_LOCALE) { $roleConfig->name = $post['role_name']; } } else { $roleConfig->name = $post['role_name']; } $roleBaseConfig->{$role}->last_modified = I2CE_Date::now(I2CE_Date::DATE_TIME)->dbFormat(); if (array_key_exists('homepage', $post) && !is_array($post['homepage'])) { $roleConfig->homepage = $post['homepage']; } if (array_key_exists('role_roles', $post) && is_array($post['role_roles'])) { //make sure the roles are valid. $roles = $post['role_roles']; foreach ($roles as $i => $r) { if (!$roleBaseConfig->is_parent("{$r}") || array_key_exists($r, self::$fixed_roles)) { unset($roles[$i]); } } $roles[] = 'admin'; //make sure that admin inherits this role. $trickleConfig = $roleConfig->traverse("trickle_up", true, false); $trickleConfig->erase(); $roleConfig->traverse('trickle_up', true, false); //recreate what we just erased $roleConfig->trickle_up = implode(',', $roles); } if (array_key_exists('role_tasks', $post) && is_array($post['role_tasks'])) { $taskConfig = I2Ce::getConfig()->I2CE->tasks->role_trickle_down; if (isset($taskConfig, $role)) { $taskConfig->{$role}->erase(); $taskConfig->traverse($role, true, false); } $taskConfig->{$role} = $post['role_tasks']; } } } $this->setRedirect('tasks-roles/roles'); }
/** * 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); }
/** * Create and load data for the objects used for this form. */ protected function loadObjects() { $loaded = false; if ($this->isPost()) { $obj = $this->factory->createContainer("disciplinary_action"); $obj->load($this->post); $this->parent_id = $obj->getParent(); } $parent = $this->factory->createContainer($this->parent_id); $parent->populate(); $parent->populateChildren("disciplinary_action"); foreach ($parent->children as $form => $list) { if ($form != "disciplinary_action") { continue; } foreach ($list as $obj) { if ($obj->suspend) { $this->id = $obj->getId(); $this->setObject($obj); $this->setObject($parent, I2CE_PageForm::EDIT_PARENT); $loaded = true; break; } } } I2CE_PageForm::loadObjects(); if ($loaded && !$this->isPost()) { $this->getPrimary()->reinstate_date = I2CE_Date::now(); } if (!$loaded) { $this->setRedirect("view_training?id=" . $parent->getId()); } /* if ( $this->factory->exists( $this->getForm() ) ) $this->setObject( $this->factory->createContainer( $this->getForm().'|'. $this->id ) ); $parent = $this->factory->createContainer( "training".'|'. $this->parent_id ); $parent->populate(); $this->setObject( $parent, PageForm::EDIT_PARENT ); parent::loadObjects(); */ }
/** * Return a list of all instances for the given training. * @param string $training the training to get instances for * @param string $date_field the date field to use for limits and sorting * @param int $days the number of days before or after today to start the list * @param int $count the number of instances to return * @return array */ protected function getInstances($training, $date_field, $days = null, $count = null) { $where_data = array('operator' => 'FIELD_LIMIT', 'field' => 'providertraining', 'style' => 'equals', 'data' => array('value' => $training)); if ($days !== null) { $date = I2CE_Date::now(I2CE_Date::DATE, time() + $days * 86400); $where_data = array('operator' => 'AND', 'operand' => array(0 => $where_data, 1 => array('operator' => 'FIELD_LIMIT', 'field' => $date_field, 'style' => 'greaterthan_equals', 'data' => $date->getValues()))); } return I2CE_FormStorage::search('provider_instance', false, $where_data, array($date_field), $count); }
/** * Create and load data for the objects used for this form. * * Create the list object and if this is a form submission load * the data from the form data. It determines the type based on the * {@link $type} member variable. */ protected function loadObjects() { if (!$this->hasPermission('task(person_can_edit_child_form_person_position)')) { $this->userMessage("You can change a person's position"); return false; } $this->current_person_position = false; $this->new_person_position = false; $this->current_salary = false; $this->new_salary = false; $this->current_position = false; $this->new_position = false; if ($this->isPost()) { if (!$this->request_exists('parent') || !($this->person = $this->factory->createContainer($this->request('parent'))) instanceof iHRIS_Person || $this->person->getId() == 0) { I2CE::raiseError("Invalid person from " . $this->request('parent')); return false; } $this->person->populate(); if (($this->current_person_position = $this->person->getLastPosition()) instanceof iHRIS_PersonPosition && $this->current_person_position->getId() != 0) { $this->current_person_position->populate(); $curr_per_pos_id = $this->current_person_position->getID(); if (array_key_exists('forms', $this->post) && is_array($this->post['forms']) && array_key_exists('person_position', $this->post['forms']) && is_array($this->post['forms']['person_position']) && array_key_exists($curr_per_pos_id, $this->post['forms']['person_position']) && is_array($this->post['forms']['person_position'][$curr_per_pos_id])) { $this->current_person_position->setFromPost($this->post['forms']['person_position'][$curr_per_pos_id]); } if (($this->current_salary = $this->current_person_position->getLastSalary()) instanceof iHRIS_Salary) { $curr_sal_id = $this->current_salary->getID(); $this->current_salary->populate(); if (array_key_exists('forms', $this->post) && is_array($this->post['forms']) && array_key_exists('salary', $this->post['forms']) && is_array($this->post['forms']['salary']) && array_key_exists($curr_sal_id, $this->post['forms']['salary']) && is_array($this->post['forms']['salary'][$curr_sal_id])) { $this->current_salary->setFromPost($this->post['forms']['salary'][$curr_sal_id]); } } if (!($this->current_position = $this->factory->createContainer($this->current_person_position->getField('position')->getDBValue())) instanceof iHRIS_Position || $this->current_position->getID() == 0) { I2CE::raiseError("Invalid Current position"); return false; } else { $this->current_position->populate(); $curr_pos_id = $this->current_position->getID(); if (array_key_exists('forms', $this->post) && is_array($this->post['forms']) && array_key_exists('position', $this->post['forms']) && is_array($this->post['forms']['position']) && array_key_exists($curr_pos_id, $this->post['forms']['position']) && is_array($this->post['forms']['position'][$curr_pos_id])) { $this->current_position->setFromPost($this->post['forms']['position'][$curr_pos_id]); } } } $this->new_position = $this->factory->createContainer('position'); $this->new_position->setFromPost($this->post['forms']['position'][0][0]); $this->new_person_position = $this->factory->createContainer('person_position'); $this->new_person_position->setParent($this->person->getFormID()); $this->new_person_position->setFromPost($this->post['forms']['person_position'][0][1]); if ($this->hasPermission('task(person_can_edit_child_form_salary)')) { $this->new_salary = $this->factory->createContainer('salary'); $this->new_salary->setFromPost($this->post['forms']['salary'][0][0]); } } else { if ($this->get_exists('id')) { if (!($this->current_person_position = $this->factory->createContainer($this->get('id'))) instanceof iHRIS_PersonPosition || $this->current_person_position->getId() == 0) { I2CE::raiseError("Invalid person position identified by " . $this->get('id')); return false; } $this->current_person_position->populate(); if (!($this->person = $this->factory->createContainer($this->current_person_position->getParent())) instanceof iHRIS_Person || $this->person->getId() == 0) { I2CE::raiseError("invalid person associated to " . $this->get('id')); return false; } $this->person->populate(); } elseif ($this->get_exists('parent')) { if (!($this->person = $this->factory->createContainer($this->get('parent'))) instanceof iHRIS_Person || $this->person->getId() == 0) { I2CE::raiseError("Invalid person from " . $this->get('parent')); return false; } $this->person->populate(); $this->current_person_position = $this->person->getLastPosition(); //note: there may not be an current person position. } else { I2CE::raiseError("No forms specified"); return false; } if ($this->current_person_position instanceof iHRIS_PersonPosition) { $this->current_position = $this->current_person_position->getField('position')->getMappedFormObject(); } $this->current_salary = $this->current_person_position->getLastSalary(); $this->new_position = $this->factory->createContainer('position'); //create a new position $this->new_person_position = $this->factory->createContainer('person_position'); //create a new person position $this->new_person_position->setParent($this->person->getFormId()); if ($this->hasPermission('task(person_can_edit_child_form_salary)')) { $this->new_salary = $this->factory->createContainer('salary'); } } if ($this->current_person_position instanceof iHRIS_PersonPosition) { if (!$this->current_person_position->getField('end_date')->isValid()) { $this->current_person_position->end_date = I2CE_Date::now(); } if ($this->current_salary instanceof iHRIS_Salary) { $this->current_salary->end_date = $this->current_person_position->end_date; } if ($this->new_person_position instanceof iHRIS_PersonPosition) { $this->new_person_position->start_date = $this->current_person_position->end_date; } if ($this->new_salary instanceof iHRIS_Salary && !$this->new_salary->getField('start_date')->isValid()) { $this->new_salary->start_date = $this->new_person_position->start_date; } } return true; }
/** * Updates time stamp on given object * @param I2CE_Form $form * @param int $timestamp. Unix timestamp * @returns boolean. true on success */ public function updateTimeStamp($form, $timestamp) { if (!$this->prepareRecordStatement("updatetime")) { return false; } $datetime = I2CE_Date::now(I2CE_Date::DATE_TIME, $timestamp)->dbFormat(); $res = self::$prepared['record']['updatetime']->execute(array($datetime, $form->getId())); if (I2CE::pearError($res, "Error updateing record timestamp:")) { return false; } return true; }