/**
  * Template function to see if person_can_view_child_forms
  *  @param DOMNode $node
  * @param I2CE_Template $template
  * @param string $link
  */
 public function userAccessInstitution($node, $template)
 {
     // This should only work for the facility_manager role so ignore any others.
     if ($template->getUser()->getRole() == "admin") {
         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::getAccessInstitution($template->getUser());
     // a list of locations a user is allowed to access
     if (count($access) == 0) {
         return false;
     }
     $person->populateChildren("registration");
     foreach ($person->getChildren('registration') as $registration) {
         $training_institution = $registration->getField("training_institution")->getDBValue();
     }
     //if the instituion of the user differs the institution of the student then deny access
     if ($access["training_institution"][0] != $training_institution) {
         $this->userMessage("You dont have permission to access students from other institutions");
         //$this->setRedirect(  "home" );
         header("Location:home");
         return false;
     }
 }
 /**
  * Template function to link to the provider associated with this person.
  * @param DOMNode $node
  * @param I2CE_Template $template
  * @param string $link
  */
 public function linkToProvider($node, $template, $link)
 {
     if (!$node instanceof DOMNOde || !$template instanceof I2CE_Template || !$node->parentNode instanceof DOMNode || $template->getUser()->getRole() != "training_provider") {
         $template->removeNode($node);
         return;
     }
     $access = self::getAccessProvider($template->getUser());
     if (count($access) > 0) {
         $a = $template->createElement('a', array('href' => $link . $access[0]));
         $node->parentNode->replaceChild($a, $node);
         while ($node->firstChild instanceof DOMNode) {
             $a->appendChild($node->firstChild);
         }
         return;
     }
     $template->removeNode($node);
 }
 /**
  * Template function to see if  can_edit_database_list_position for the 
  *  @param DOMNode $node
  * @param I2CE_Template $template
  * @returns boolean
  */
 public function userAccessFacilityList($node, $template)
 {
     // This should only work for the facility_manager role so ignore any others.
     if ($template->getUser()->getRole() != "facility_manager") {
         return false;
     }
     $fieldWalks = array('position' => 'facility', 'facility' => 'location', 'county' => 'district', 'district' => 'region', 'region' => 'country', 'country' => false);
     return $this->userAccessWalkableForms($node, $template, $fieldWalks);
 }
 /**
  * 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;
 }