/**
  * 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);
     }
 }
 /**
  * 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);
     }
 }
 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 function validate_form_resume_semester($form)
 {
     $ff = I2CE_FormFactory::instance();
     $academic_year = implode("|", $form->academic_year);
     if ($academic_year == "|") {
         return;
     }
     $acadYrObj = $ff->createContainer($academic_year);
     $acadYrObj->populate();
     $academic_year = $acadYrObj->getField("name")->getDBValue();
     $academic_year = explode("/", $academic_year);
     $start_dateObj = I2CE_Date::getDate(01, 07, $academic_year[0]);
     $end_dateObj = I2CE_Date::getDate(30, 05, $academic_year[1]);
     $start_date = $start_dateObj->displayDate();
     $end_date = $end_dateObj->displayDate();
     if ($start_dateObj->compare($form->resume_date) == -1) {
         $form->setInvalidMessage("resume_date", "Resume Date Should Be After {$start_date}");
     }
     if ($end_dateObj->compare($form->resume_date) != -1) {
         $form->setInvalidMessage("resume_date", "Resume Date Should Be Before {$end_date}");
     }
 }
 /**
  * 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);
 }
 /**
  * Checks to see if the most recent position for this person is still active and doesn't have an end date
  * for his/her position.
  * @see getLastPosition()
  * @return boolean
  */
 public function isActive_PersonPosition($pers_pos)
 {
     if (!$pers_pos instanceof iHRIS_PersonPosition) {
         return false;
     }
     if (isset($pers_pos->end_date) && $pers_pos->end_date instanceof I2CE_Date) {
         if ($pers_pos->end_date->equals(I2CE_Date::blank())) {
             return true;
         } else {
             return false;
         }
     } else {
         return true;
     }
 }
 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');
 }
 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;
 }
 /**
  * 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;
 }
 /**
  * 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);
 }
 /**
  * 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);
 }
 /**
  * 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;
 }
Example #15
0
 /**
  * Add a selection drop down for the hour, minute and second to be selected.
  * @param string $name The name of the selection element
  * @param I2CE_Date $default The default I2CE_Date object to use to preset the value.
  * @param boolean $showError A flag if this field is currently invalid to mark it as such.
  * @param DOMNode $node The node to append the element to.
  * @param boolean $hidden Set to true if the form element should be hidden.
  */
 public static function addTimeElement($template, $name, $default, $showError, $node, $hidden = false)
 {
     if ($hidden) {
         $hour = $template->createElement("input", array("name" => $name . "[hour]", "type" => "hidden", "value" => $default->hour()));
         $minute = $template->createElement("input", array("name" => $name . "[minute]", "type" => "hidden", "value" => $default->minute()));
         $second = $template->createElement("input", array("name" => $name . "[second]", "type" => "hidden", "value" => $default->second()));
     } else {
         $hour = $template->createElement("select", array("name" => $name . "[hour]", "class" => "date_hour" . ($showError ? "_error" : "")));
         for ($i = 0; $i <= 23; $i++) {
             $opt = $template->createElement("option", array("value" => $i), $i);
             if ($i == $default->isHour($i)) {
                 $opt->setAttribute("selected", "selected");
             }
             $hour->appendChild($opt);
         }
         $minute = $template->createElement("select", array("name" => $name . "[minute]", "class" => "date_minute" . ($showError ? "_error" : "")));
         for ($i = 0; $i <= 59; $i++) {
             $opt = $template->createElement("option", array("value" => $i), $i);
             if ($i == $default->isMinute($i)) {
                 $opt->setAttribute("selected", "selected");
             }
             $minute->appendChild($opt);
         }
         $second = $template->createElement("select", array("name" => $name . "[second]", "class" => "date_second" . ($showError ? "_error" : "")));
         for ($i = 0; $i <= 59; $i++) {
             $opt = $template->createElement("option", array("value" => $i), $i);
             if ($i == $default->isSecond($i)) {
                 $opt->setAttribute("selected", "selected");
             }
             $second->appendChild($opt);
         }
     }
     $node->appendChild($hour);
     $node->appendChild($minute);
     $node->appendChild($second);
 }
 /**
  * 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);
 }
 /**
  * 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;
 }
 /**
  * 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();
     */
 }
 /**
  * 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);
         }
     }
 }
Example #20
0
 /**
  * Compares a date to this one and returns -1 if it is before, 0 if the same and 1 if after
  * this date.
  * @param I2CE_Date $date
  * @return integer
  */
 public function compare($date)
 {
     if (!$date instanceof I2CE_Date) {
         I2CE::raiseError("Invalid date comparison");
         return null;
     }
     switch ($this->type) {
         case self::YEAR_ONLY:
             return bccomp($date->year(), $this->year);
             break;
         case self::YEAR_MONTH:
             $year_cmp = bccomp($date->year(), $this->year);
             if ($year_cmp == 0) {
                 return bccomp($date->month(), $this->month);
             } else {
                 return $year_cmp;
             }
             break;
         case self::MONTH_DAY:
             $month_cmp = bccomp($date->month(), $this->month);
             if ($month_cmp == 0) {
                 return bccomp($date->day(), $this->day);
             } else {
                 return $month_cmp;
             }
             break;
         case self::DATE:
             $year_cmp = bccomp($date->year(), $this->year);
             if ($year_cmp == 0) {
                 $month_cmp = bccomp($date->month(), $this->month);
                 if ($month_cmp == 0) {
                     return bccomp($date->day(), $this->day);
                 } else {
                     return $month_cmp;
                 }
             } else {
                 return $year_cmp;
             }
             break;
         case self::DATE_TIME:
             $year_cmp = bccomp($date->year(), $this->year);
             if ($year_cmp == 0) {
                 $month_cmp = bccomp($date->month(), $this->month);
                 if ($month_cmp == 0) {
                     $day_cmp = bccomp($date->day(), $this->day);
                     if ($day_cmp == 0) {
                         $hour_cmp = bccomp($date->hour(), $this->hour);
                         if ($hour_cmp == 0) {
                             $min_cmp = bccomp($date->minute(), $this->minute);
                             if ($min_cmp == 0) {
                                 return bccomp($date->second, $this->second);
                             } else {
                                 return $min_cmp;
                             }
                         } else {
                             return $hour_cmp;
                         }
                     } else {
                         return $day_cmp;
                     }
                 } else {
                     return $month_cmp;
                 }
             } else {
                 return $year_cmp;
             }
             break;
         case self::TIME_ONLY:
             $hour_cmp = bccomp($date->hour(), $this->hour);
             if ($hour_cmp == 0) {
                 $min_cmp = bccomp($date->minute(), $this->minute);
                 if ($min_cmp == 0) {
                     return bccomp($date->second, $this->second);
                 } else {
                     return $min_cmp;
                 }
             } else {
                 return $hour_cmp;
             }
             break;
         default:
             I2CE::raiseError("An invalid date type was used for I2CE_Date::compare.", E_USER_WARNING);
             return 0;
             break;
     }
 }
Example #21
0
 /**
  * Checks to make sure a date is valid
  * @param I2CE_Date $data
  * @return boolean
  */
 public static function checkDate($data)
 {
     if ($data instanceof I2CE_Date) {
         return $data->isValid();
     }
     return false;
 }
 /**
  * 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;
 }
 /**
  * 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;
     }
 }
 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;
     }
     $fieldQry = $this->getRequiredFieldsQuery($form->getName(), array($field), $form->getId());
     $result = $this->db->getRow($fieldQry);
     if (I2CE::pearError($result, "Error populating field {$field} of form " . $form->getName())) {
         return false;
     }
     $ref = strtolower($form->getName() . '+' . $field);
     $entry = new I2CE_Entry(I2CE_Date::blank(), 1, 0, $form_field->getFromDB($result->{$ref}));
     $form_field->addHistory($entry);
     return true;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * 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;
     }
     $field_name = $form_field->getName();
     $fields = $this->lookupField($form->getName(), $form->getId(), array($field_name), false);
     if (!is_array($fields) || !array_key_exists($field_name, $fields)) {
         //no data to populate
         return true;
     }
     $last_modified = I2CE_Date::blank();
     $entry = new I2CE_Entry($last_modified, 1, 0, $form_field->getFromDB($fields[$field_name]));
     $form_field->addHistory($entry);
     return true;
 }
 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;
 }