/**
  * Update the position for this to mark it as closed and then save the object.
  */
 public function save()
 {
     if (!$this->hasPermission('task(person_can_edit_child_form_person_position)')) {
         $this->userMessage("You cannot change a person's position");
         return false;
     }
     //we are only displaying one person_position form on the page, it is the new person_position form. W
     if ($this->current_person_position instanceof iHRIS_PersonPosition) {
         $this->current_person_position->save($this->user);
     }
     if ($this->current_position instanceof iHRIS_Position) {
         //now close out the current position
         $this->current_position->statusOnly();
         $this->current_position->save($this->user);
     }
     //we can now save the details on the new position
     $this->new_position->setFromDB('position_status|closed');
     $this->new_position->save($this->user);
     //now that the new position has been saved, we can link it to the new_person_position
     $this->new_person_position->getField('position')->setFromDB($this->new_position->getNameID());
     $this->new_person_position->save($this->user);
     if ($this->hasPermission('task(person_can_edit_child_form_salary)')) {
         if ($this->current_salary instanceof iHRIS_Salary) {
             $this->current_salary->save($this->user);
         }
         $this->new_salary->setParent($this->new_person_position);
         $this->new_salary->save($this->user);
     }
     $this->setRedirect("view?id=" . $this->person->getFormID());
 }
 /**
  * Update the position for this to mark it as closed and then save the object.
  */
 public function save()
 {
     if (!$this->hasPermission('task(person_can_edit_child_form_person_position)')) {
         $this->userMessage("You can't change a person's position");
         return false;
     }
     $new_person_position = $this->getPrimary();
     if ($this->post_exists('position_option') && $this->post('position_option') == 'create' && $this->new_position instanceof iHRIS_Position) {
         $this->new_position->setStatus("position_status|closed");
         $this->new_position->save($this->user);
         $new_person_position->getField("position")->setFromDB($this->new_position->getNameId());
         $position = $this->new_position;
     } else {
         $position = $this->factory->createContainer($new_person_position->getField("position")->getDBValue());
         $position->statusOnly();
         $position->closePosition($this->user, $this->getParent()->getId());
     }
     if ($this->getParent()->isActive() && $this->old_position instanceof iHRIS_Position) {
         $this->old_position->statusOnly();
         $this->old_position->save($this->user);
         $person = $this->getParent();
         if ($this->old_person_position instanceof iHRIS_PersonPosition) {
             $this->old_person_position->end_date = $new_person_position->start_date;
             $this->old_person_position->save($this->user);
             I2CE_ModuleFactory::callHooks("make_promotion_save", $this->old_person_position, $new_person_position);
         }
         //$this->getPrimary()->reason = null;
     }
     I2CE_ModuleFactory::callHooks("make_offer_save", $new_person_position);
     foreach ($this->objects[self::EDIT_CHILD] as $obj) {
         if ($obj->getId() == '0') {
             $obj->setParent($new_person_position);
         }
         I2CE_ModuleFactory::callHooks("make_offer_save_" . $obj->getName(), $new_person_position, $obj);
     }
     parent::save();
 }
 /**
  * Perform the main actions of the page.
  */
 protected function action()
 {
     $factory = I2CE_FormFactory::instance();
     if ($this->get_exists('set_status')) {
         $new_status = $this->get('set_status');
         $set_status = $factory->createContainer($this->get('id'));
         $set_status->statusOnly();
         $set_status->setStatus("position_status|" . $new_status);
         $set_status->save($this->user);
         $set_status->cleanup();
         unset($set_status);
     }
     parent::action();
     $this->template->addHeaderLink("view.js");
     $this->template->appendFileById("menu_view.html", "li", "navBarUL", true);
     $this->template->setAttribute("class", "active", "menuConfigure", "a[@href='configure']");
     $this->template->appendFileById("menu_configure.html", "ul", "menuConfigure");
     $this->template->setAttribute("class", "active", "menuLists", "a[@href='lists']");
     if (($jobField = $this->position->getField("job")) instanceof I2CE_FormField) {
         $jobField->setHref("view_job?id=");
     }
     if (($supField = $this->position->getField("supervisor")) instanceof I2CE_FormField) {
         $supField->setHref("view_position?id=");
     }
     if ($this->position->status[1] != "closed") {
         $this->template->appendFileById("view_position_" . $this->position->status[1] . "_link.html", "li", "edit_links");
     }
     $pers_pos_ids = iHRIS_PersonPosition::getIds($this->get('id'));
     //print_r( $pers_pos_ids );
     if (count($pers_pos_ids) > 0 && $pers_pos_ids['record'] != '0') {
         $this->template->appendFileById("view_position_person.html", "div", "position");
         $pers_pos = $factory->createContainer("person_position" . '|' . $pers_pos_ids['record']);
         $pers_pos->populate();
         $this->template->setForm($pers_pos);
         $person = $factory->createContainer($pers_pos_ids['parent']);
         $person->populate();
         $this->template->setForm($person);
     }
     $supervised = $this->position->getSupervised();
     //print_r( $supervised );
     if (count($supervised) > 0) {
         $this->template->appendFileById("view_position_supervised.html", "div", "position");
         foreach ($supervised as $record) {
             $this->template->appendFileById("view_position_row.html", "tr", "supervised");
             $this->template->setDisplayData("position", I2CE_List::lookup($record, "position"));
             $this->template->setDisplayData("add_pos_id", array("id" => $record));
         }
         $this->template->setAttribute("class", "even", "supervised", "tr[position() mod 2 = 0]");
     }
 }