protected function setupDisplay($swiss, $action, $contentNode) { if ($action !== 'edit') { return true; } if (count($this->stored_options) > 0) { $flat_options = array(); I2CE_Util::flattenVariables($this->stored_options, $flat_options, false, true, 'swissFactory:options'); foreach ($flat_options as $k => $v) { if (is_scalar($v)) { $v = array($v); } else { if (is_array($v)) { $k .= '[]'; } else { continue; } } foreach ($v as $vv) { if (!is_scalar($vv)) { continue; } $contentNode->appendChild($this->template->createElement('input', array('type' => 'hidden', 'name' => $k, 'value' => $vv))); } } } $updateLink = $this->getURLRoot('update') . $swiss->getPath() . $swiss->getURLQueryString(); $this->template->setDisplayDataImmediate('swiss_form', $updateLink, $contentNode); $update = $this->template->getElementById('swiss_update_button', $contentNode); if (!$update instanceof DOMElement) { return false; } $update->setAttribute('action', $updateLink); $this->page->addFormWorm('swiss_form'); return true; }
/** * Display the headers for this report. * @param DOMNode $contentNode */ protected function doCrossTabHeaders($contentNode) { $page_root = $this->getPageRoot(); $postfix = '?'; $qry_fields = $this->page->request(); if (array_key_exists('sort_order', $this->defaultOptions)) { if ($this->defaultOptions['sort_order'] == 'none') { $sortFields = array(); } else { $sortFields = explode(',', $this->defaultOptions['sort_order']); } unset($qry_fields['sort_order']); } else { $sortFields = array(); } if (count($qry_fields) > 0) { $flat = array(); $qry_fields = I2CE_Util::flattenVariables($qry_fields, $flat); $fields = array(); foreach ($flat as $key => $val) { if (is_array($val)) { foreach ($val as $v) { array_push($fields, urlencode($key) . "[]=" . $v); } } else { array_push($fields, urlencode($key) . '=' . $val); } } $page_root .= '?' . implode('&', $fields); $postfix = '&'; } if ($this->page->hasAjax()) { $this->page->getTemplate()->addHeaderLink("mootools-core.js"); } $sort_order = array(); if ($this->displayedFields == null) { $this->displayedFields = $this->getDisplayFieldsData(); } $sort_descriptions = array(); $t_sortFields = array(); $decreasing = 'Decreasing'; $increasing = 'Increasing'; I2CE::getConfig()->setIfIsSet($decreasing, "/modules/CustomReports/text/Decreasing"); I2CE::getConfig()->setIfIsSet($increasing, "/modules/CustomReports/text/Increasing"); foreach ($sortFields as $i => $s) { if (strlen($s) == 0) { continue; } if ($s[0] == '-') { $s = substr($s, 1); if (!array_key_exists($s, $this->displayedFields)) { continue; } if (!$this->displayedFields[$s]) { continue; } $sort_descriptions[] = $this->displayedFields[$s]['header'] . ' (Decreasing)'; $t_sortFields[$s] = true; $sort_order[$s] = '-'; } else { if (!array_key_exists($s, $this->displayedFields)) { continue; } if (!$this->displayedFields[$s]) { continue; } $sort_descriptions[] = $this->displayedFields[$s]['header'] . ' (Increasing)'; $t_sortFields[$s] = true; $sort_order[$s] = ''; } } $sortFields = array_keys($t_sortFields); $sort_description = ''; if (count($sort_descriptions) > 0) { $sort_description = implode(',', $sort_descriptions); } $this->template->setDisplayDataImmediate('sort_description', $sort_description, $contentNode); $color_grad = 0; if (count($sortFields) > 0) { $color_grad = (int) floor((0xff - 0xcc) / count($sortFields)); } foreach ($this->headers as $formfield => $headinfo) { if (!$headinfo) { continue; } $show_sort = false; if (is_array($headinfo)) { $header = $this->displayedFields[$formfield]['header']; $head_count = count($headinfo); $head = $this->template->appendFileByName("customReports_table_head_cell.html", "th", "report_header_one", 0, $contentNode); if (!$head instanceof DOMNode) { I2CE::raiseError("Could not add head cell to table"); return false; } $head->setAttribute("colspan", $head_count); $this->template->appendElementByNode($head, "span", array('id' => "report_column_header_{$formfield}"), $header); $idx = 0; foreach ($headinfo as $header => $enabled) { if (!$enabled) { continue; } if ($header == '') { $header = '??'; } $head = $this->template->appendFileByName("customReports_table_head_cell.html", "th", "report_header_two", 0, $contentNode); if (!$head instanceof DOMNode) { I2CE::raiseError("Could not add head cell to table"); return false; } $this->template->appendElementByNode($head, "span", array('id' => "report_column_header_{$formfield}_{$idx}"), $header); $idx++; } } else { $header = $this->displayedFields[$formfield]['header']; $head = $this->template->appendFileByName("customReports_table_head_cell.html", "th", "report_header_one", 0, $contentNode); if (!$head instanceof DOMNode) { I2CE::raiseError("Could not add head cell to table"); return false; } $head->setAttribute("rowspan", "2"); if (count($sortFields) > 0 && $formfield == $sortFields[count($sortFields) - 1]) { $this->template->setNodeAttribute("class", "selected", $head); } else { $position = array_search($formfield, $sortFields); if ($position !== false) { $this->template->setNodeAttribute("class", "secondary_selected", $head); $bgcolor = dechex((count($sortFields) - $position - 1) * $color_grad + 0xcc); $bgcolor = hexdec($bgcolor . $bgcolor . $bgcolor) - 0x219; $bgcolor = '#' . dechex($bgcolor); $this->template->setNodeAttribute("style", "background-color:{$bgcolor}", $head); } } $t_sortFields = $sortFields; $t_sort_order = $sort_order; $key = array_search($formfield, $t_sortFields); if ($key !== false) { //the field is already in the sort order unset($t_sortFields[$key]); if ($key == count($sortFields) - 1) { //the field was the first on the list //so switch it's sort order if ($t_sort_order[$formfield] == '') { //make increasing decreasing $t_sort_order[$formfield] = '-'; $t_sortFields[] = $formfield; //put the field at the end of the list } else { //remove decreasing from the list (don't need to do anything) unset($t_sort_order[$formfield]); } } else { //sort it by ascending $t_sort_order[$formfield] = ''; $t_sortFields[] = $formfield; //put the field at the end of the list } } else { $t_sort_order[$formfield] = ''; $t_sortFields[] = $formfield; //put the field at the end of the list } foreach ($t_sortFields as $i => $s) { $t_sortFields[$i] = $t_sort_order[$s] . $s; } if (count($t_sortFields) > 0) { $link = $page_root . $postfix . 'sort_order=' . urlencode(implode(',', $t_sortFields)); } else { $link = $page_root . $postfix . 'sort_order=none'; } $this->template->appendElementByNode($head, "a", array("href" => $link, 'id' => "report_column_header_{$formfield}"), $header); if ($this->page->hasAjax()) { $this->page->addAjaxUpdate($this->getReportPrefix() . 'report_results', "report_column_header_{$formfield}", 'click', $link, $this->getReportPrefix() . 'report_results'); } } } }
public function display($supress_output = false) { if (!array_key_exists('HTTP_HOST', $_SERVER)) { exit("No command line usage for this page"); } foreach (array('request', 'content') as $key) { if (!$this->get_exists($key)) { I2CE::raiseError("Invalid Stub request: {$key} is missing"); return false; } } $value = $this->get('content'); $req = array_pad(explode('?', $this->request('request')), 2, ''); list($req, $query_str) = $req; $get = array(); if ($query_str) { parse_str($query_str, $get); } $post = array(); if ($this->isPost()) { I2CE_Util::flattenVariables($this->post, $post, false); } if (count($this->request_remainder) > 0) { $attribute = $this->request_remainder[0]; } else { $attribute = 'id'; } if (strpos($value, ',')) { $values = explode(',', $value); $value = array(); foreach ($values as $val) { list($a, $v) = array_pad(explode('=', $val, 2), 2, ''); if (!$v) { $v = $a; $a = $attribute; } if (!array_key_exists($a, $value) || !is_array($value[$a])) { $value[$a] = array(); } $value[$a][] = $v; } } else { $value = array($attribute => array($value)); } $js = false; if ($this->get_exists('keep_javascripts')) { $js = $this->get('keep_javascripts'); } $wrangler = new I2CE_Wrangler(); $page = $wrangler->wrangle($req, false, $get, $post); if (!$page instanceof I2CE_Page) { $this->userMessage("Unable to find requested page", 'notice'); I2CE::raiseError("Unable to create page"); exit; } $page->setIsPost($this->isPost()); $page->display(true); foreach ($value as $a => &$vals) { if (!is_array($vals) || count($vals) == 0) { unset($vals[$a]); continue; } $vals = array_map('addslashes', $vals); $vals = "(@{$a}='" . implode("' or @{$a}='", $vals) . "')"; } if (count($value) == 0) { $this->userMessage("Nothing selected to return"); I2CE::raiseError("Nothing selected to return"); exit; } $qry = '//*[(' . implode(' or ', $value) . ")]"; $list = $page->getTemplate()->query($qry); $nodes = 0; if ($list instanceof DOMNodeList) { $nodes += $list->length; } $scriptNodeList = null; if ($js) { $js_ids = explode(',', $js); $qry = '/html/head//script[@id="' . implode('" or @id="', $js_ids) . '"]'; $scriptNodeList = $page->getTemplate()->query($qry); if ($scriptNodeList instanceof DOMNodeList) { $nodes += $scriptNodeList->length; } } if ($nodes == 0) { I2CE::raiseError("Requested page content not found: " . implode(' or ', $value) . " for request " . $this->module . '/' . $this->page . '/' . implode('/', $this->request_remainder)); exit; } $doc = new DOMDocument(); if ($scriptNodeList instanceof DOMNodeList) { for ($i = 0; $i < $scriptNodeList->length; $i++) { $scriptNode = $doc->importNode($scriptNodeList->item($i), true); $doc->appendChild($scriptNode); } } if ($list instanceof DOMNodeList) { for ($i = 0; $i < $list->length; $i++) { $doc->appendChild($doc->importNode($list->item($i), true)); } } echo $doc->saveHTML(); }