protected function action() { if (!parent::action()) { return false; } $action = 'RetrieveValueSet'; if (count($this->request_remainder) > 0) { reset($this->request_remainder); $action = current($this->request_remainder); } $task = 'SVS_allow_' . $action; if (I2CE_PermissionParser::taskExists($task) && !$this->hasPermission('task(' . $task . ')')) { I2CE::raiseError("No permission"); return false; } if ($action == 'config') { return $this->action_config(); } else { if ($this->isGet()) { return $this->action_get($action); } else { return $this->action_post(); } } }
public function generate($node) { if (!$node instanceof DOMNode || !$this->primaryObject instanceof I2CE_Form || I2CE_PermissionParser::taskExists($this->options['task']) && !$this->page->hasPermission("task(" . $this->options['task'] . ")", $node) || !($linkedNode = $this->template->appendFileByNode($this->options['template'], 'div', $node)) instanceof DOMNode || !($tbodyNode = $this->template->getElementByName('child_fields', 0, $node)) instanceof DOMNode) { return false; } $added = 0; if (count($this->options['action_links']) > 0 && ($ulNode = $this->template->getElementByName('child_links', 0, $linkedNode)) instanceof DOMNode) { $added = $this->addLinks('li', $this->options['action_links'], $ulNode); } if ($added == 0 && ($containerNode = $this->template->getElementByName('child_actions', 0, $linkedNode)) instanceof DOMNode) { $this->template->removeNode($containerNode); } $this->template->setDisplayDataImmediate('child_title', $this->options['title'], $linkedNode); $dispDatas = array(); $arg_walker = array(); if ($this->options['printf'] && is_array($this->options['printf_args'])) { foreach ($this->options['printf_args'] as $i => &$arg) { $t_arg = explode(":", $arg); if (count($t_arg) > 1) { $arg_walker[$i] = $t_arg; $arg = $t_arg[0]; } } unset($arg); $dispDatas = I2CE_FormStorage::listDisplayFields($this->options['form'], $this->options['printf_args'], $this->primaryObject->getNameId(), $this->options['where'], $this->options['orders'], $this->options['limit']); $ids = array_keys($dispDatas); } else { $ids = I2CE_FormStorage::search($this->options['form'], $this->primaryObject->getNameId(), $this->options['where'], $this->options['orders'], $this->options['limit']); } if (count($ids) == 0) { return false; } foreach ($ids as $id) { $text = $this->options['title']; //default text for child in case printf wasn't set. if (array_key_exists($id, $dispDatas) && is_array($dispDatas)) { $dispFields = $dispDatas[$id]; foreach ($this->options['printf_args'] as $i => $arg) { $dispData[$i] = $dispFields[$arg]; } foreach ($arg_walker as $i => $fields) { $val = $dispData[$i]; $count = 0; foreach ($fields as $field) { $count++; if ($count == 1) { continue; } list($wform, $wid) = array_pad(explode('|', $val, 2), 2, ''); $val = I2CE_FormStorage::lookupField($wform, $wid, array($field), ''); } $dispData[$i] = $val; } $text = @vsprintf($this->options['printf'], $dispData); } $this->generateAjaxLink($id, $text, $tbodyNode); } }
public function generate($node) { if ($this->options['task'] && I2CE_PermissionParser::taskExists($this->options['task']) && !$this->page->hasPermission("task(" . $this->options['task'] . ")", $node) || !($linkedNode = $this->template->appendFileByNode($this->options['template'], 'div', $node)) instanceof DOMNode || !($pageDispNode = $this->template->getElementByName('pager_display', 0, $linkedNode)) instanceof DOMNode || !($pageResultsNode = $this->template->getElementByName('pager_results', 0, $linkedNode)) instanceof DOMNode || !($tbodyNode = $this->template->getElementByName('link_fields', 0, $node)) instanceof DOMNode) { return; } $arg_walker = array(); $printf_args = $this->options['printf_args']; foreach ($printf_args as $i => &$arg) { $t_arg = explode(":", $arg); if (count($t_arg) > 1) { $arg_walker[$i] = $t_arg; $arg = $t_arg[0]; } } unset($arg); $dispData = I2CE_FormStorage::listDisplayFields($this->options['form'], $printf_args, false, $this->options['where'], $this->options['orders'], $this->options['limit']); if (count($dispData) == 0) { return; } $pageDispNode->setAttribute('id', 'linked_' . $this->options['form'] . '_pager_display'); $pageResultsNode->setAttribute('id', 'linked_' . $this->options['form'] . '_results'); $dispData = $this->paginateList($dispData, array('form' => $this->options['form']), 'linked_' . $this->options['form']); $this->template->setDisplayDataImmediate('link_title', $this->options['title']); foreach ($dispData as $id => $r_dispData) { $dispData = array(); foreach ($printf_args as $i => $arg) { $dispData[$i] = $r_dispData[$arg]; } foreach ($arg_walker as $i => $fields) { $val = $dispData[$i]; $count = 0; foreach ($fields as $field) { $count++; if ($count == 1) { continue; } list($wform, $wid) = array_pad(explode('|', $val, 2), 2, ''); $val = I2CE_FormStorage::lookupField($wform, $wid, array($field), ''); } $dispData[$i] = $val; } $text = @vsprintf($this->options['printf'], $dispData); //form = person_position $linkid = $this->options['form'] . '|' . $id; foreach ($this->options['link_field'] as $lfield) { list($lform, $lid) = array_pad(explode('|', $linkid, 2), 2, ''); $linkid = I2CE_FormStorage::lookupField($lform, $lid, array($lfield), ''); } $attrs = array('href' => $this->options['link'] . $linkid); $tbodyNode->appendChild($trNode = $this->template->createElement('tr', array('colspan' => 2))); $trNode->appendChild($tdNode = $this->template->createElement('td', array('colspan' => 2))); $tdNode->appendChild($this->template->createElement('a', $attrs, $text)); } }
protected function generateAutoParentTemplate($data, $appendNode) { $form = $this->primaryObject->getName(); if (array_key_exists('task', $data) && $data['task']) { $task = $data['task']; if (I2CE_PermissionParser::taskExists($task) && !$this->hasPermission("task({$task})", $appendNode)) { return false; } } $node = $this->template->appendFileById("auto_view_parent_form.html", 'div', $appendNode); if (!$node instanceof DOMNode) { I2CE::raiseError("Could not load auto_view_parent_form.html"); return false; } $added = 0; if (($ulNode = $this->template->getElementByName('parent_form_edit_links', 0, $node)) instanceof DOMNode && array_key_exists('edit_links', $data) && is_array($data['edit_links'])) { $added = $this->addLinks('li', $data['edit_links'], $ulNode); } $this->template->setDisplayData('has_edit_links', $added, $node); if (($pNode = $this->template->getElementByName('parent_form_action_links', 0, $node)) instanceof DOMNode) { $added = 0; if (array_key_exists('action_links', $data) && is_array($data['action_links'])) { $added = $this->addLinks('span', $data['action_links'], $pNode); } if ($added == 0) { $this->template->removeNode($pNode); } } if (($tbodyNode = $this->template->getElementByName('parent_form_fields', 0, $node)) instanceof DOMNode) { $all_field_names = $this->primaryObject->getFieldNames(); $display_order = array(); if (array_key_exists('display_order', $data) && is_string($data['display_order'])) { $display_order = explode(",", $data['display_order']); } $field_names = array(); foreach ($display_order as $field_name) { if (($pos = array_search($field_name, $all_field_names)) === false) { continue; } unset($display_order[$pos]); $field_names[] = $field_name; } $field_names = array_unique(array_merge($field_names, $all_field_names)); $field_data = array(); if (array_key_exists('fields', $data) && is_array($data['fields'])) { $field_data = $data['fields']; } $default_enabled = 1; if (array_key_exists('default_disabled', $data)) { $default_enabled = !$data['default_disabled']; } $added = false; foreach ($field_names as $field_name) { if (!array_key_exists($field_name, $field_data) || !is_array($field_data[$field_name])) { $f_data = array(); } else { $f_data = $field_data[$field_name]; } if (array_key_exists('enabled', $f_data)) { if (!$f_data['enabled']) { continue; } } else { if (!$default_enabled) { continue; } } $attrs = array('type' => 'form', 'name' => $form . ':' . $field_name); if (array_key_exists('attributes', $f_data) && is_array($f_data['attributes'])) { $attrs = $f_data['attributes']; } if (!array_key_exists('showhead', $attrs)) { $attrs['showhead'] = 'default'; } if (!$attrs['showhead']) { unset($attrs['showhead']); } $tbodyNode->appendChild($this->template->createElement('span', $attrs)); $added = true; } $this->template->setDisplayData('has_field_data', $added, $node); } if (array_key_exists('display_name', $data) && $data['display_name']) { $display_name = $data['display_name']; } else { $display_name = $this->primaryObject->getDisplayName(); } $this->setDisplayDataImmediate('parent_form_display_name', $display_name, $node); if (array_key_exists('title', $data) && $data['title']) { $title = $data['title']; if (array_key_exists('title_args', $data) && is_array($data['title_args'])) { $args = array(); foreach ($data['title_args'] as $i => $fieldName) { $val = ''; if (($fieldObj = $this->primaryObject->getField($fieldName)) instanceof I2CE_FormField) { $val = $fieldObj->getDisplayValue(); } $args[$i] = $val; } ksort($args); if (count($args) > 0) { $title = @vsprintf($title, $args); } } } else { $title = $this->getTitle(); } if (array_key_exists('subtitle', $data) && !is_array($data['subtitle'])) { $subtitle = $data['subtitle']; if (array_key_exists('subtitle_args', $data) && is_array($data['subtitle_args'])) { $args = array(); foreach ($data['subtitle_args'] as $i => $fieldName) { $val = ''; if (($fieldObj = $this->primaryObject->getField($fieldName)) instanceof I2CE_FormField) { $val = $fieldObj->getDisplayValue(); } $args[$i] = $val; } ksort($args); if (count($args) > 0) { $subtitle = @vsprintf($subtitle, $args); } } } else { $subtitle = $this->primaryObject->getDisplayName(); } $this->setDisplayDataImmediate('parent_form_title', $title, $node); $this->setDisplayDataImmediate('parent_form_subtitle', $subtitle, $node); return $node; }
protected function addLinks($tag, $data, $containerNode) { $added = 0; foreach ($data as $name => $link_data) { if (array_key_exists('task', $link_data) && $link_data['task']) { $task = $link_data['task']; if (I2CE_PermissionParser::taskExists($task) && !$this->page->hasPermission("task({$task})", $containerNode)) { continue; } } if (!array_key_exists('href', $link_data) || !$link_data['href'] || !array_key_exists('text', $link_data) || !$link_data['text']) { continue; } if (array_key_exists('formfield', $link_data) && $link_data['formfield']) { $attrs = array('type' => 'form', 'name' => $link_data['formfield'], 'href' => $link_data['href']); if (array_key_exists('attributes', $link_data) && is_array($link_data['attributes'])) { foreach ($link_data['attributes'] as $attr => $val) { if (!is_scalar($val)) { continue; } $attrs[$attr] = $val; } } if (!array_key_exists('class', $attrs)) { $attrs['class'] = ''; } $attrs['class'] .= ' action_link_' . $name; $tagNode = $this->template->createElement($tag); $tagNode->appendChild($this->template->createElement('span', $attrs, $link_data['text'])); $containerNode->appendChild($tagNode); } else { $attrs = array('href' => $link_data['href'], 'class' => 'action_link_' . $name); $tagNode = $this->template->createElement($tag); $tagNode->appendChild($this->template->createElement('a', $attrs, $link_data['text'])); $containerNode->appendChild($tagNode); } $added++; } return $added; }
/** * Perform the main actions of the page. */ protected function action() { $task = $this->getViewChildTask(); if (I2CE_PermissionParser::taskExists($task) && !$this->hasPermission("task({$task})")) { $this->userMessage("You do not have permission to view this {$childForm}", true); return false; } $tag = array_key_exists('template_tag', $this->args) && is_scalar($this->args['template_tag']) ? $this->args['template_tag'] : 'div'; $append_id = array_key_exists('template_id', $this->args) && is_scalar($this->args['template_id']) ? $this->args['template_id'] : 'child_form'; $appendNode = $this->template->getElementById($append_id); if (!$appendNode instanceof DOMNode) { I2CE::raiseError("No {$append_id} to add child form " . $this->childForm); return false; } $limit_page = $this->request_exists('limit_page') ? $this->request('limit_page') : 1; if ($limit_page < 1) { $limit_page = 1; } $order_by = $this->getOrderBy(); $found = I2CE_FormStorage::search($this->childForm, $this->parent->getNameId(), array(), $order_by, array($limit_page - 1, 1)); if (!$found && $limit_page > 1) { $limit_page = 1; $found = I2CE_FormStorage::search($this->childForm, $this->parent->getNameId(), array(), $order_by, array($limit_page - 1, 1)); } if (!$found) { $this->redirect("view?id=" . $this->parent->getNameId()); return true; } $total_rows = I2CE_FormStorage::getLastListCount($this->childForm); if ($total_rows <= 1) { $this->template->setAttribute('style', 'display:none;', 'child_pager_div'); } else { $query = $this->request(); unset($query['limit_page']); $query = I2CE_Page::flattenRequestVars($query); $this->makeScalingJumper('child', $limit_page, $total_rows, $this->pageRoot(), $query, 'limit_page'); } $this->child = I2CE_FormFactory::instance()->createContainer($this->childForm . "|" . $found); $this->child->populate(); I2CE_ModuleFactory::callHooks('pre_add_child_form_' . $this->childForm, array('form' => $this->child, 'page' => $this, 'set_on_node' => null, 'append_node' => $appendNode)); $childNode = $this->template->appendFileByNode($this->getViewChildTemplate(), $tag, $appendNode); $this->template->setForm($this->child, $childNode); I2CE_ModuleFactory::callHooks('post_add_child_form_' . $this->childForm, array('form' => $this->child, 'page' => $this, 'node' => $childNode, 'set_on_node' => null, 'append_node' => $appendNode)); $this->template->setDisplayDataImmediate("child_form_header", "View " . $this->child->getDisplayName()); if (array_key_exists('show_edit', $this->args) ? !$this->args['show_edit'] : true) { $this->template->findAndRemoveNodes("//div[@class='editRecord']"); } // Do we want this? // $this->template->findAndRemoveNodes( "//span[@history='false']" ); return true; }
protected function generateAutoTemplate($data, $appendNode) { if (!$this->primaryObject instanceof I2CE_Form) { return false; } $form = $this->primaryObject->getName(); if (array_key_exists('task', $data) && $data['task']) { $task = $data['task']; if (I2CE_PermissionParser::taskExists($task) && !$this->hasPermission("task({$task})", $appendNode)) { return false; } } $node = $this->template->appendFileById("auto_edit_parent_form.html", 'div', $appendNode); if (!$node instanceof DOMNode) { I2CE::raiseError("Could not load auto_edit_parent_form.html"); return false; } $formNode = $this->template->getElementByTagName('form', 0, $node); if (!$node instanceof DOMNode) { I2CE::raiseError("Couldn't get form node"); return false; } $formNode->setAttribute('action', $this->page); if (($tbodyNode = $this->template->getElementByID('list_fields', $node)) instanceof DOMNode) { $all_field_names = $this->primaryObject->getFieldNames(); if ($this->primaryObject instanceof I2CE_List) { //shouldn't be here! $all_field_names = array_diff($all_field_names, array('remap', 'i2ce_hidden')); } $display_order = array(); if (array_key_exists('display_order', $data) && is_string($data['display_order'])) { $display_order = explode(",", $data['display_order']); } $field_names = array(); foreach ($display_order as $field_name) { if (($pos = array_search($field_name, $all_field_names)) === false) { continue; } unset($display_order[$pos]); $field_names[] = $field_name; } $field_names = array_unique(array_merge($field_names, $all_field_names)); $field_data = array(); if (array_key_exists('fields', $data) && is_array($data['fields'])) { $field_data = $data['fields']; } $count = 0; $default_enabled = 1; if (array_key_exists('default_disabled', $data)) { $default_enabled = !$data['default_disabled']; } foreach ($field_names as $field_name) { if (!array_key_exists($field_name, $field_data) || !is_array($field_data[$field_name])) { $f_data = array(); } else { $f_data = $field_data[$field_name]; } if (array_key_exists('enabled', $f_data)) { if (!$f_data['enabled']) { continue; } } else { if (!$default_enabled) { continue; } } if ($count % 2 == 0) { $trNode = $this->template->createElement('tr'); $tbodyNode->appendChild($trNode); } $count++; $attrs = array('type' => 'form', 'name' => $form . ':' . $field_name); if (array_key_exists('attributes', $f_data) && is_array($f_data['attributes'])) { $attrs = $f_data['attributes']; } if (!array_key_exists('showhead', $attrs)) { $attrs['showhead'] = 'default'; } if (!$attrs['showhead']) { unset($attrs['showhead']); } $tdNode = $this->template->createElement('td'); $tdNode->appendChild($this->template->createElement('span', $attrs)); $trNode->appendChild($tdNode); } } if (array_key_exists('display_name', $data) && $data['display_name']) { $display_name = $data['display_name']; } else { $display_name = $this->primaryObject->getDisplayName(); } $this->setDisplayDataImmediate('form_display_name', $display_name, $node); if (array_key_exists('title', $data) && $data['title']) { $title = $data['title']; if (array_key_exists('title_args', $data) && is_array($data['title_args'])) { $args = array(); foreach ($data['title_args'] as $i => $fieldName) { $val = ''; if (($fieldObj = $this->primaryObject->getField($fieldName)) instanceof I2CE_FormField) { $val = $fieldObj->getDisplayValue(); } $args[$i] = $val; } ksort($args); if (count($args) > 0) { $title = @vsprintf($title, $args); } } } else { $title = $this->getTitle(); } $this->setDisplayDataImmediate('form_title', $title, $node); if (array_key_exists('parent_display', $data) && is_array($data['parent_display']) && array_key_exists('printf', $data['parent_display']) && is_string($data['parent_display']['printf']) && $data['parent_display']['printf'] && array_key_exists('printf_args', $data['parent_display']) && is_array($data['parent_display']['printf_args'])) { ksort($data['parent_display']['printf_args']); foreach ($data['parent_display']['printf_args'] as $field) { $fieldObj = $this->parentObj->getField($field); if ($fieldObj instanceof I2CE_FormField) { $vals[] = $fieldObj->getDisplayValue(); } else { $vals[] = ''; } } $purpose = @vsprintf($this->printf, $vals); $this->setDisplayDataImmediate('purpose', $pupose, $node); } return $node; }
protected function getListConfig($type = null, $form = null) { $listConfig = null; if ($type === null) { if ($this->request_exists('type') && I2CE_MagicDataNode::checkKey($this->request('type'))) { $type = $this->request('type'); } } if (!$form && $type) { $listConfig = I2CE::getConfig()->getAsArray('/modules/Lists/auto_list/' . $type); $listConfig['type'] = $type; } if (!is_array($listConfig)) { $listConfig = array(); } if ($form === null && !array_key_exists('form', $listConfig) && $this->request_exists('form') && I2CE_MagicDataNode::checkKey($this->request('form'))) { $form = $this->request('form'); } if ($form) { $listConfig['form'] = $form; $listConfig['type'] = 0; $task = 'can_view_database_list_' . $form; if (I2CE_PermissionParser::taskExists($task)) { $listConfig['task'] = $task; } $edit_task = 'can_edit_database_list_' . $form; if (I2CE_PermissionParser::taskExists($edit_task)) { $listConfig['edit_task'] = $edit_task; } } if (!$listConfig['form']) { return false; } $form = $listConfig['form']; if (!array_key_exists('text', $listConfig) || !$listConfig['text']) { $listConfig['text'] = I2CE_FormFactory::instance()->getDisplayName($form); } if (!array_key_exists('title', $listConfig)) { $title = "Add/Update %s"; I2CE::getConfig()->setIfIsSet($title, '/modules/Lists/messages/edit_title'); $title = @vsprintf($title, $listConfig['text']); $listConfig['title'] = $title; } if ($this->request('remap') && $this->primaryObject instanceof I2CE_Form) { if (!array_key_exists('fields', $listConfig) || !is_array($listConfig['fields'])) { $listConfig['fields'] = array(); } foreach ($this->primaryObject->getFieldNames() as $field) { if ($field == 'remap') { $listConfig['fields']['remap'] = array('enabled' => 1); } else { if (!array_key_exists($field, $listConfig['fields']) || !is_array($listConfig['fields'][$field])) { $listConfig['fields'][$field] = array(); } $data =& $listConfig['fields'][$field]; if (!array_key_exists('attributes', $data) || !is_array($data['attributes'])) { $data['attributes'] = array(); } $data['attributes']['noedit'] = 'strict'; unset($data); } } $listConfig['fields']['remap'] = array('enabled' => 1); } else { $listConfig['fields']['remap'] = array('enabled' => 0); } if (!array_key_exists('display_order', $listConfig)) { if ($this->getPrimary() instanceof I2CE_Form) { $all_field_names = $this->getPrimary()->getFieldNames(); $display_first = array_diff($all_field_names, array('remap', 'i2ce_hidden')); $listConfig['display_order'] = implode(',', $display_first); } } return $listConfig; }
protected function getListLinkNode($listConfig) { $task = false; if (array_key_exists('task', $listConfig) && is_scalar($listConfig['task'])) { $task = $listConfig['task']; } if ($task && I2CE_PermissionParser::taskExists($task) && !$this->hasPermission("task({$task})")) { return false; } $form = false; if (array_key_exists('form', $listConfig) && is_scalar($listConfig['form'])) { $form = $listConfig['form']; } if (!$form || !in_array($form, $this->all_lists)) { return false; } $text = ''; if (array_key_exists('text', $listConfig) && is_scalar($listConfig['text'])) { $text = $listConfig['text']; } if (!$text) { $text = I2CE_FormStorage::instance()->getDisplayName($form); } if (!$listConfig['type']) { $attrs = array('href' => 'index.php/auto_list?form=' . $form); } else { $attrs = array('href' => 'index.php/auto_list?type=' . $listConfig['type']); } return $this->template->createElement('a', $attrs, $text); }
public function generate($top_node) { if (!$top_node instanceof DOMNode || !($node = $this->template->appendFileByNode($this->options['template'], 'div', $top_node)) || !$this->primaryObject instanceof I2CE_Form || $this->options['task'] && I2CE_PermissionParser::taskExists($this->options['task']) && !$this->page->hasPermission("task(" . $this->options['task'] . ")", $node)) { return false; } I2CE::raiseError("Generating for " . $this->primaryObject->getNameID()); if ($this->options['is_edit']) { if (!($formNode = $this->template->getElementByTagName('form', 0, $node)) instanceof DOMNode) { return false; } $formNode->setAttribute('action', $this->options['save_link']); } $this->template->setForm($this->primaryObject, $node); $this->template->setDisplayDataImmediate('form_display_name', $this->options['display_name'], $node); $this->template->setDisplayDataImmediate('form_title', $this->options['title'], $node); $this->template->setDisplayDataImmediate('form_subtitle', $this->options['subtitle'], $node); foreach ($this->getLinkTypes() as $type) { $added = 0; if (($ulNode = $this->template->getElementByName('form_' . $type . '_links', 0, $node)) instanceof DOMNode) { $added = $this->addLinks('li', $this->options[$type . '_links'], $ulNode); } if ($added == 0 && ($linkContainer = $this->template->getElementByName('form_' . $type, 0, $node)) instanceof DOMNode) { $this->template->removeNode($linkContainer); } } if (($fieldsNode = $this->template->getElementByName('form_fields', 0, $node)) instanceof DOMNode) { $field_tasks = array(); $all_field_names = $this->primaryObject->getFieldNames(); $field_names = array(); $display_order = $this->options['display_order']; foreach ($display_order as $field_name) { if (($pos = array_search($field_name, $all_field_names)) === false) { continue; } unset($display_order[$pos]); $field_names[] = $field_name; } $listed_fields = array_keys($this->options['field_data']); $field_names = array_unique(array_merge($field_names, $all_field_names, $listed_fields)); $count = 0; foreach ($field_names as $field_name) { if (!$this->options['field_data'][$field_name]['enabled']) { continue; } if ($this->options['is_edit']) { if ($count % 2 == 0) { $trNode = $this->template->createElement('tr'); $fieldsNode->appendChild($trNode); } $this->fieldEdit($field_name, $this->options['field_data'][$field_name], $trNode); } else { $this->fieldView($field_name, $this->options['field_data'][$field_name], $fieldsNode, $count % 2); } $count++; } } return true; }
public function action() { $this->template->addHeaderLink('I2CE_AjaxTabPanel.js'); $this->template->addHeaderLink('tabs.css'); if (!array_key_exists('tabs', $this->args) || !is_array($this->args['tabs'])) { I2CE::raiseError("No Tabs Defined"); return false; } $tabs = $this->args['tabs']; if (!($tabsNode = $this->template->getElementByID('tabs_link'))) { I2CE::raiseError("Don't know where to put tab links"); return false; } if (!($tabContentsNode = $this->template->getElementByID('tabs_content'))) { I2CE::raiseError("Don't know where to put tab content"); return false; } $selected = false; if (array_key_exists('selected_tab', $this->args) && is_scalar($this->args['selected_tab']) && $this->args['selected_tab']) { $selected = $this->args['tab']; } if ($this->request_exists('selected_tab') && is_scalar($this->request('selected_tab')) && $this->request('selected_tab')) { $selected = $this->request('tab'); } $order = array(); if (array_key_exists('tab_order', $this->args) && is_scalar($this->args['tab_order'])) { $order = explode(",", $this->args['tab_order']); } $order = array_unique(array_merge($order, array_keys($tabs))); foreach ($order as $i => $tab) { if (!array_key_exists($tab, $tabs) || !is_array($data = $tabs[$tab]) || !array_key_exists('href', $data) || !is_scalar($data['href']) || array_key_exists('task', $data) && is_scalar($data['task']) && ($task = $data['task']) && I2CE_PermissionParser::taskExists($task) && !$this->hasPermission("task({$task})")) { I2CE::raiseError("Skipping tab {$tab} as not valid"); unset($order[$i]); } } if (count($order) == 0) { I2CE::raiseError("No valid tabs"); return false; } if (!in_array($selected, $order)) { reset($order); $selected = current($order); } $sources = array(); $ff = I2CE_FormFactory::instance(); foreach ($order as $tab) { $data = $tabs[$tab]; if (!array_key_exists('content', $data) || !is_scalar($data['content']) || !$data['content']) { $data['content'] = 'siteContent'; } $title = $tab; if (array_key_exists('title', $data) && is_scalar($data['title']) && $data['title']) { $title = $data['title']; } $attrs = array('class' => 'tab_link', 'id' => 'tab_link_' . $tab); $tabsNode->appendChild($liNode = $this->template->createElement('li', $attrs, $title)); $href = $data['href']; $reqs = array(); if (array_key_exists('request_vars', $data) && is_array($data['request_vars'])) { $reqs = array(); foreach ($data['request_vars'] as $tgt_var => $src_var) { if (!$this->request_exists($src_var)) { continue; } $reqs[$tgt_var] = $this->request[$src_var]; } } if (count($reqs) > 0) { $reqs = http_build_query(self::flattenRequestVars($reqs)); if (strpos($href, '?') !== false) { $href .= '&' . $reqs; } else { $href .= '?' . $reqs; } } $attrs = array('class' => 'tab_content', 'id' => 'tab_content_' . $tab, 'href' => $href); if (array_key_exists('formfield', $data) && is_scalar($data['formfield']) && $data['formfield']) { $attrs['type'] = 'form'; $attrs['name'] = $data['formfield']; } $tabContentsNode->appendChild($contentNode = $this->template->createElement('span', $attrs)); $sources[$tab] = '#' . $data['content']; $formObj = false; $formID = false; if (array_key_exists('form', $data) && is_scalar($form = $data['form'])) { $where = array(); $order = null; if (array_key_exists('where', $data) && is_array($data['where'])) { $where = $data['where']; } if (array_key_exists('order', $data) && is_scalar($data['order'])) { $order = $data['order']; } if ($formID = I2CE_FormStorage::search($form, $this->primaryObject->getNameID(), $where, $order, 1)) { $formObj = $ff->createContainer($form . '|' . $formID); } } if ($formObj instanceof I2CE_Form) { $formObj->populate(); $this->template->setForm($formObj, $liNode); $this->template->setForm($formObj, $contentNode); } } $options = json_encode(array('responseFilters' => $sources)); $js = 'document.addEvent("domready", function() { var tab = new I2CE_AjaxTabPanel("tab_panel",' . $options . '); if (tab) {; tab.showTab("' . addslashes($selected) . '")}; });'; $this->template->addHeaderText($js, 'script', 'create_tabs'); }