/** * @param DOMNode $node * @param I2CE_Template $template * @param DOMNode $form_node * */ public function processDOMEditable_reportSelect($node, $template, $form_node) { $mf = I2CE_ModuleFactory::instance(); if (!$mf->isEnabled('CustomReports-Selector')) { return false; } $template->addHeaderLink("mootools-more.js"); $template->addHeaderLink("getElementsByClassName-1.0.1.js"); $template->addHeaderLink("I2CE_ClassValues.js"); $template->addHeaderLink("I2CE_Window.js"); $template->addHeaderLink("I2CE_ToggableWindow.js"); $template->addHeaderLink("I2CE_TreeSelect.js"); $template->addHeaderLink('Observer.js'); $template->addHeaderLink('Autocompleter.js'); $template->addHeaderLink('Autocompleter.css'); $template->addHeaderLink('I2CE_TreeSelectAutoCompleter.js'); $template->addHeaderLink("Tree.css"); $style = 'default'; if ($form_node->hasAttribute('show')) { $style = $this->ensureEditStyle($form_node->getAttribute('show')); } $styles = array($style); if ($style != 'default') { $styles[] = 'default'; } foreach ($styles as $style) { $edit_path = "meta/reportSelect/{$style}"; $report_path = "{$edit_path}/reportView"; if (!$this->optionsHasPath($edit_path) || !is_array($options = $this->getOptionsByPath($edit_path))) { continue; } if (!$this->optionsHasPath($report_path) || !is_scalar($reportView = $this->getOptionsByPath($report_path))) { continue; } $report = false; $relationship = false; $form = false; I2CE::getConfig()->setIfIsSet($report, "/modules/CustomReports/reportViews/{$reportView}/report"); if (!$report) { continue; } I2CE::getConfig()->setIfIsSet($relationship, "/modules/CustomReports/reports/{$report}/relationship"); if (!$relationship) { continue; } $form = false; $reportform_path = "meta/reportSelect/{$style}/reportform"; $reportform = 'primary_form'; if ($this->optionsHasPath($reportform_path)) { //we are not using the primary form in the relationship, instead we are using a named form. $reportform = $this->getOptionsByPath($reportform_path); if ($reportform == 'primary_form') { I2CE::getConfig()->setIfIsSet($form, "/modules/CustomReports/relationships/{$relationship}/form"); } else { try { $relObj = new I2CE_FormRelationship($relationship); } catch (Exception $e) { continue; } $form = $relObj->getForm($reportform); } } else { //we use the primary form I2CE::getConfig()->setIfIsSet($form, "/modules/CustomReports/relationships/{$relationship}/form"); } if (!$form) { continue; } if (!$this->canSelectAnyForm()) { $form_path = "meta/form"; if (!$this->optionsHasPath($form_path) || !is_array($forms = $this->getOptionsByPath($form_path))) { continue; } if (!in_array($form, $forms)) { continue; } } $printf_path = "meta/display/{$form}/{$style}/printf"; $printfargs_path = "meta/display/{$form}/{$style}/printf_args"; if (!$this->optionsHasPath($printf_path) || !is_string($printf = $this->getOptionsByPath($printf_path))) { continue; } if (!$this->optionsHasPath($printfargs_path) || !is_array($printfargs = $this->getOptionsByPath($printfargs_path))) { continue; } if (strlen($printf) == 0) { continue; } if (count($printfargs) == 0) { continue; } ksort($printfargs); $disp = $this->_getDisplayValue(null, $style); $node->setAttribute('id', $this->getHTMLName()); $options = array('reportview' => $reportView, 'printf' => $printf, 'printfargs' => $printfargs, 'display' => $disp, 'value' => $this->getDBValue(), 'reportform' => $reportform); $no_limits_path = "meta/display/{$form}/{$style}/no_limits"; if ($this->optionsHasPath($no_limits_path) && $this->getOptionsByPath($no_limits_path)) { $options['contentid'] = 'report_results'; } else { $options['contentid'] = 'report_results_with_limits'; } $options['multi_select'] = 1; if ($template->addReportSelector($node, $options)) { return true; } } return false; }
public function display($supress_output = false) { if (!array_key_exists('HTTP_HOST', $_SERVER)) { exit("No command line usage for this page"); } if (!$this->get_exists('delay_index')) { I2CE::raiseError("Invalid tree data request: 'request' is missing"); return false; } $delay_index = $this->get('delay_index'); if (!array_key_exists('tree_data', $_SESSION) || !is_array($_SESSION['tree_data']) || !array_key_exists($delay_index, $_SESSION['tree_data'])) { return false; } $data = $_SESSION['tree_data'][$delay_index]; unset($_SESSION['tree_data'][$delay_index]); if (!is_array($data)) { return false; } $template = new I2CE_Template(); $template->loadRootText("<span id='root'>"); $root = $template->getElementById('root'); $doc = $template->getDoc(); I2CE_Module_TreeSelect::createTreeData($template, $root, $data); $tdoc = new DOMDocument(); $tdoc->appendChild($tdoc->importNode($root, true)); echo $tdoc->saveHTML(); die; }
/** * Return the display value of this form field as a DOM Node. * @param DOMNode $node * @param I2CE_Template $template * @return DOMNode */ public function getDisplayNode($node, $template) { $text_node = $template->createElement('span', array('class' => 'assoc_container')); $value = $this->getValue(); foreach ($value as $k => $v) { list($form, $id) = array_pad(explode('|', $k, 2), 2, ''); $pair_node = $template->createElement('span', array('class' => 'assoc_pair_container')); $text_node->appendChild($pair_node); $attrs = array('class' => 'assoc_pair_value'); if ($this->has_auto_list && $form && $id) { $elem = 'a'; $attrs['href'] = 'auto_list/view?form_name=' . $form . '&id=' . $id; } else { $elem = 'span'; } $pair_node->appendChild($template->createElement($elem, $attrs, $this->getSingleDisplayValue($v))); } return $text_node; }
/** * Display the template as HTML/XML. Sets the header and displays any buffered warnings/echoed text. */ protected function _display($supress_output) { if (!$supress_output && array_key_exists('HTTP_HOST', $_SERVER)) { $headers = $this->template->getHeaders(); if (!is_array($headers)) { $headers = array($headers); } foreach ($headers as $header) { header($header); } } $classes = array(); if ($this->template instanceof I2CE_TemplateMeister) { $class = get_class($this->template); while ($class && $class != 'I2CE_Fuzzy') { $classes[] = $class; $class = get_parent_class($class); } $num = count($classes); } I2CE_ModuleFactory::callHooks('pre_page_prepare_display', $this); for ($i = $num - 1; $i >= 0; $i--) { I2CE_ModuleFactory::callHooks('pre_page_prepare_display_' . $classes[$i], $this); } if ($this->template instanceof I2CE_TemplateMeister) { $this->template->prepareDisplay(); } for ($i = $num - 1; $i >= 0; $i--) { I2CE_ModuleFactory::callHooks('post_page_prepare_display_' . $classes[$i], $this); } I2CE_ModuleFactory::callHooks('post_page_prepare_display', $this); if ($this->template instanceof I2CE_Template) { $this->template->checkRolesTasksAndPermissions(); } I2CE_ModuleFactory::callHooks('final_page_prepare_display', $this); if (!$supress_output) { $display = ''; if ($this->template instanceof I2CE_TemplateMeister) { $display = $this->template->getDisplay(); } $buffer = ''; if (ob_get_level() == I2CE::$ob_level + 1) { $buffer = ob_get_clean(); } echo $display; flush(); if ($buffer) { I2CE::raiseError("The page " . $_SERVER['PHP_SELF'] . " has errors"); $buffer = str_replace(array('<br/>', '<br />'), "\n", $buffer); $buffer = htmlentities($buffer, ENT_COMPAT, 'UTF-8', false); echo "<span class='buffered_errors'><pre>{$buffer}</pre></span>"; } } }
/** * Return the display value of this form field as a DOM Node. * @param DOMNode $node * @param I2CE_Template $template * @return DOMNode */ public function getDisplayNode($node, $template) { $text_node = $template->createElement('span', array('class' => 'assoc_container')); $value = $this->getValue(); foreach ($value as $k => $v) { $pair_node = $template->createElement('span', array('class' => 'assoc_pair_container')); $text_node->appendChild($pair_node); $pair_node->appendChild($template->createElement('span', array('class' => 'assoc_pair_key'), $k)); $pair_node->appendChild($template->createElement('span', array('class' => 'assoc_pair_value'), $this->getSingleDisplayValue($v))); } if ($href = $this->getHref()) { $link_node = $template->createElement("a", array("href" => $href)); $link_node->appendChild($text_node); return $link_node; } else { return $text_node; } }
* Wiki webservice helper function * *****************************************/ require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'CLI.php'; require_once dirname(__FILE__) . '/../lib/I2CE.php'; require_once dirname(__FILE__) . '/../lib/I2CE_FileSearch.php'; require_once dirname(__FILE__) . '/../lib/I2CE_TemplateMeister.php'; require_once dirname(__FILE__) . '/../lib/I2CE_MagicDataTemplate.php'; require_once dirname(__FILE__) . '/../modules/Pages/lib/I2CE_Template.php'; require_once dirname(__FILE__) . '/../modules/MagicDataExport/I2CE_MagicDataExport_Template.php'; if (count($arg_files) != 1) { usage("Please specify list html"); } $in_file = realpath($arg_files[0]); $out_file = dirname($in_file) . '/' . basename($in_file, '.html') . '.xml'; $template = new I2CE_Template(); $template->loadRootFile($in_file); $data = array(); foreach ($template->query('//li/a') as $a) { $li = $a->parentNode; $href = $a->getAttribute('href'); $comp = parse_url($href); if (!is_array($comp) || !array_key_exists('query', $comp) || !$comp['query'] || $li->tagName != 'li') { echo "Skipping(0): " . $a->textContent . " : href=" . $href . "\n"; continue; } $qry = array(); parse_str($comp['query'], $qry); if (!is_array($qry) || !array_key_exists('type', $qry)) { echo "Skipping(1): " . $a->textContent . " : href=" . $href . "\n"; continue;
/** * Adds a sequence of years to a {@link I2CE_Template} object. * * It takes two optional arguments to limit the years to use. The initial year to start with is 1990 and it will end * with the current year. * @param I2CE_Template $template * @param string $selectId The id of the element in the page to add the selections to. * @param integer $start The year to start with * @param integer $end The year to end with. * @see I2CE_Template::setData() */ public static function listYears($template, $selectId, $start = 1990, $end = 0) { if ($end == 0) { $now = getdate(); $end = $now['year']; } for ($i = $start; $i <= $end; $i++) { $template->setData(array('text' => $i, 'value' => $i), $selectId, 'OPTION', $selectId); } }
/** * Process the DOM for this form. * @param DOMNode $node * @param I2CE_Template $template * @param string $method * @param array $args */ public function processDOM(&$node, &$template, $method, $args) { if (!is_callable(array($this, $method))) { I2CE::raiseError("Method {$method} not callable in {$this->getName()}", E_USER_NOTICE); //do nothing return; } if ($node->hasAttribute("ifset")) { $ifset = $node->getAttribute("ifset"); if ($ifset[0] == "!") { $not = true; $ifset = substr($ifset, 1); } else { $not = false; } if (($ifset == "true" || $ifset == "dateblank") && $method == 'displayField') { //we check a field on the current form. the field name is the argument $if_field = $this->getField($args[0]); } else { $phpfunc = '[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*'; if (preg_match("/^({$phpfunc})\$/", $ifset)) { //we are looking at field of this form $if_field = $this->getField($ifset); } else { //we need to check the validity of a field of a different form $if_field = $template->getField($ifset, $node); } } $is_value = true; if ($node->hasAttribute("ifvalue")) { $ifvalue = $node->getAttribute("ifvalue"); if ($ifvalue[0] == "!") { $val_not = true; $ifvalue = substr($ifvalue, 1); } else { $val_not = false; } $is_value = $if_field instanceof I2CE_FormField && $if_field->getDBValue() == $ifvalue; if ($val_not) { $is_value = !$is_value; } } $is_valid = $if_field instanceof I2CE_FormField && $if_field->isValid(); if ($ifset == "dateblank") { $is_valid = $is_valid && $if_field instanceof I2CE_FormField && $if_field->getValue() instanceof I2CE_Date && $if_field->getValue()->isBlank(); } if (!($is_valid xor $not) || !$is_value) { $node->parentNode->removeChild($node); return; } $node->removeAttribute("ifset"); } elseif ($node->hasAttribute("ifvalue")) { $ifvalue = $node->getAttribute("ifvalue"); $if_field = $this->getField($args[0]); if ($ifvalue[0] == "!") { $val_not = true; $ifvalue = substr($ifvalue, 1); } else { $val_not = false; } $is_value = $if_field instanceof I2CE_FormField && $if_field->getDBValue() == $ifvalue; if ($val_not) { $is_value = !$is_value; } if (!$is_value) { $node->parentNode->removeChild($node); return; } else { if ($node->hasAttribute('display') && strlen($display = $node->getAttribute('display')) > 0) { if ($display[0] == 'f' || !$display) { $node->removeAttribute('type'); return; } } } } $this->{$method}($node, $template, $args); }
/** * Ensure that a node is really a node. If it is not, hopes that it is an ID * and then makes it the corresponding node * @param I2CE_Template $template * @param mixed &$node. Either a DOMNode or a node id. * @param bool $make_doc_on_failure defaults to true. If we can't find the node, make it the document element * If false, we leave $node alone. */ protected function _ensureNode($template, &$node, $make_doc_on_failure = true) { if (isset($node) && $node instanceof DOMNode) { //we are good so quit. return; } $new_node = null; if (is_string($node)) { $new_node = $template->getElementById($node); } if ($new_node == null) { if ($make_doc_on_failure) { $node = $template->getDoc()->documentElement; } } else { $node = $new_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); }
/** * Return the display value of this form field as a DOM Node. * @param DOMNode $node * @param I2CE_Template $template * @return DOMNode */ public function getDisplayNode($node, $template) { if ($this->container instanceof I2CE_Form) { $link_node = $template->createElement('a', array("href" => $this->getLink()), $this->getDisplayValue()); return $link_node; } else { return $template->createTextNode($this->getDisplayValue()); } }
/** * Creates a drop down list of options. * @param I2CE_Template $template * @param DOMNode $node -- the node we wish to add the drop down list under * @param boolean $show_hidden. Show the hidden members of the list, defaults to false. * @returns mixed DOMNode or an array of DOMNodes to add. */ protected function create_DOMEditable_list($node, $template, $form_node, $show_hidden = false) { $list = $this->getMapOptions('default', $show_hidden); $value = $this->getValue(); $ele_name = $this->getHTMLName(); $selectNode = $template->createElement('select', array('name' => $ele_name . '[currency]', 'class' => 'currency')); foreach ($list as $d) { $attrs = array('value' => $d['value']); if ($d['value'] == $value[0]) { $attrs['selected'] = 'selected'; } $selectNode->appendChild($template->createElement('option', $attrs, $d['display'])); } $node->appendChild($selectNode); if (!array_key_exists(1, $value)) { $value[1] = null; } $element = $template->createElement("input", array("name" => $ele_name . '[value]', "id" => $ele_name, "type" => "text", "value" => $value[1], "class" => "currency")); $this->setElement($element); $node->appendChild($element); }
/** * Return the display value of this form field as a DOM Node. * @param DOMNode $node * @param I2CE_Template $template * @return DOMNode */ public function getDisplayNode($node, $template) { $add_node = $template->createElement('span', array('class' => 'mult')); if ($href = $this->getHref()) { $link_node = $template->createElement("a", array("href" => $href)); $add_node->append_child($link_node); } else { $link_node = $add_node; } $value = $this->getValue(); $map_list = array(); foreach ($value as $map_value) { $map_list[] = I2CE_List::lookup($map_value[1], $map_value[0]); } $first = true; foreach ($map_list as $text) { if ($first) { $first = false; } else { $link_node->appendChild($template->createElement("span", array('class' => 'mult_sep'), ',')); } $link_node->appendChild($template->createElement("span", array('class' => 'mult_val'), $text)); } return $add_node; }
/** * @param DOMNode $node * @param I2CE_Template $template * @param DOMNode $form_node * */ public function processDOMEditable_reportSelect($node, $template, $form_node) { $mf = I2CE_ModuleFactory::instance(); if (!$mf->isEnabled('CustomReports-Selector')) { return false; } $style = 'default'; if ($form_node->hasAttribute('show')) { //$style = $this->ensureEditStyle($form_node->getAttribute('show')); $style = $form_node->getAttribute('show'); } $styles = array($style); if ($style != 'default') { $styles[] = 'default'; } foreach ($styles as $style) { $edit_path = "meta/reportSelect/{$style}"; $report_path = "{$edit_path}/reportView"; if (!$this->optionsHasPath($edit_path) || !is_array($options = $this->getOptionsByPath($edit_path))) { continue; } if (!$this->optionsHasPath($report_path) || !is_scalar($reportView = $this->getOptionsByPath($report_path))) { continue; } $report = false; $relationship = false; $form = false; I2CE::getConfig()->setIfIsSet($report, "/modules/CustomReports/reportViews/{$reportView}/report"); if (!$report) { continue; } I2CE::getConfig()->setIfIsSet($relationship, "/modules/CustomReports/reports/{$report}/relationship"); if (!$relationship) { continue; } $form = false; I2CE::getConfig()->setIfIsSet($form, "/modules/CustomReports/relationships/{$relationship}/form"); if (!$form) { continue; } if (!$this->canSelectAnyForm()) { $form_path = "meta/form"; if (!$this->optionsHasPath($form_path) || !is_array($forms = $this->getOptionsByPath($form_path))) { continue; } if (!in_array($form, $forms)) { continue; } } $printf_path = "meta/display/{$form}/{$style}/printf"; $printfargs_path = "meta/display/{$form}/{$style}/printf_args"; if (!$this->optionsHasPath($printf_path) || !is_string($printf = $this->getOptionsByPath($printf_path))) { continue; } if (!$this->optionsHasPath($printfargs_path) || !is_array($printfargs = $this->getOptionsByPath($printfargs_path))) { continue; } if (strlen($printf) == 0) { continue; } if (count($printfargs) == 0) { continue; } ksort($printfargs); $disp = $this->_getDisplayValue(null, $style); $node->setAttribute('id', $this->getHTMLName()); $options = array('reportview' => $reportView, 'printf' => $printf, 'printfargs' => $printfargs, 'display' => $disp, 'value' => $this->getDBValue()); if ($this->getOption('required')) { $options['allow_clear'] = false; } $no_limits_path = "meta/display/{$form}/{$style}/no_limits"; if ($this->optionsHasPath($no_limits_path) && $this->getOptionsByPath($no_limits_path)) { $options['contentid'] = 'report_results'; } else { $options['contentid'] = 'report_results_with_limits'; } if ($template->addReportSelector($node, $options)) { return true; } } return false; }
/** * Return the display value of this form field as a DOM Node. * @param DOMNode $node * @param I2CE_Template $template * @return DOMNode */ public function getDisplayNode($node, $template) { $add_node = $template->createElement('span', array('class' => 'mult')); if ($href = $this->getHref()) { $link_node = $template->createElement("a", array("href" => $href)); $add_node->append_child($link_node); } else { $link_node = $add_node; } $value = $this->getValue(); $map_text = array(); foreach ($value as $i => $map_value) { $map_text[$i] = I2CE_List::lookup($map_value[1], $map_value[0]); } $first = true; foreach ($map_text as $i => $text) { if ($first) { $first = false; } else { $link_node->appendChild($template->createElement("span", array('class' => 'mult_sep'), ',')); } if ($node->hasAttribute('auto_link') && $node->getAttribute('auto_link')) { $attrs = array('class' => 'mult_val', 'href' => 'auto_list/view?form_name=' . $value[$i][0] . '&id=' . $value[$i][0] . '|' . $value[$i][1]); $link_node->appendChild($template->createElement("a", $attrs, $text)); } else { $link_node->appendChild($template->createElement("span", array('class' => 'mult_val'), $text)); } } return $add_node; }
/** * 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); }
/** * Return the display value of this form field as a DOM Node. * @param DOMNode $node * @param I2CE_Template $template * @return DOMNode */ public function getDisplayNode($node, $template) { $text = $this->getDisplayValue(); $link = $this->getLink(); if (!$link || strlen($this->value) == 0) { //there is no linked URL to this field so we just display the text return $template->createTextNode($text); } $link_node = $template->createElement('a', array('href' => $link)); while ($node->hasChildNodes()) { $link_node->appendChild($node->firstChild); } if ($node->hasAttribute('show_text') && (strtolower($node->getAttribute('show_text')) == 'true' || strtolower($node->getAttribute('show_text')) == '!false')) { $link_node->appendChild($template->createTextNode($text)); } if (!$node->hasAttribute('show_image') || strtolower($node->getAttribute('show_image')) == 'true' || strtolower($node->getAttribute('show_image')) == '!false') { $width = null; $height = null; if ($node->hasAttribute('height')) { $height = $node->getAttribute('height'); $node->removeAttribute('height'); } if ($node->hasAttribute('width')) { $width = $node->getAttribute('width'); $node->removeAttribute('width'); } $attrs = array("src" => $link, 'alt' => $text, 'class' => 'field_image'); if (!empty($width)) { $attrs['width'] = $width; } if (!empty($height)) { $attrs['height'] = $height; } $link_node->appendChild($template->createElement('img', $attrs)); } return $link_node; }
/** * @param DOMNode $node * @param I2CE_Template $template * @param DOMNode $form_node */ public function processDOMNotEditable($node, $template, $form_node) { $ele_name = $this->getHTMLName(); $node->appendChild($template->createElement("input", array("name" => $ele_name, "type" => "hidden", "value" => $this->getDBValue()))); $node->appendChild($this->getDisplayNode($node, $template)); }
/** * Return the display value of this form field as a DOM Node. * @param DOMNode $node * @param I2CE_Template $template * @param string $style. Defaults to 'default' * @return DOMNode */ public function _getDisplayNode($node, $template, $style = 'default') { $text_node = $template->createTextNode($this->_getDisplayValue($style)); if ($href = $this->getHref()) { $link_node = $template->createElement("a", array("href" => $href)); $link_node->appendChild($text_node); return $link_node; } else { return $text_node; } }
/** * 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; }
/** * 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 see if the user is mapped to a personnel record and if so replace the node with the given link * @param DOMNode $node * @param I2CE_Template $template * @param string $link */ public function linkToPersonRecord($node, $template, $link) { if (!$node instanceof DOMNode || !$template instanceof I2CE_Template || !$node->parentNode instanceof DOMNode || ($id = iHRIS_UserMap::getPersonId()) == '|') { $template->removeNode($node); return; } $a = $template->createElement('a', array('href' => $link . $id)); $node->parentNode->replaceChild($a, $node); while ($node->firstChild instanceof DOMNode) { $a->appendChild($node->firstChild); } }