/**
  * Adds any controls for this display to the content node.
  * @param DOMNode $contentNode 
  * @returns boolean;
  */
 protected function displayReportControl($contentNode)
 {
     parent::displayReportControl($contentNode);
     if (function_exists('gzencode')) {
         $this->template->setDisplayDataImmediate('has_gz', 1);
     } else {
         $this->template->setDisplayDataImmediate('has_gz', 0);
     }
     if (function_exists('bzcompress')) {
         $this->template->setDisplayDataImmediate('has_bz2', 1);
     } else {
         $this->template->setDisplayDataImmediate('has_bz2', 0);
     }
     if (@class_exists('ZipArchive', false)) {
         $this->template->setDisplayDataImmediate('has_zip', 1);
     } else {
         $this->template->setDisplayDataImmediate('has_zip', 0);
     }
     $xslts = $this->getAvailableXSLT();
     if (count($xslts) == 0) {
         return true;
     }
     if (!($selNode = $this->template->getElementById('export_style', $contentNode)) instanceof DOMNode) {
         I2CE::raiseError("Bad");
     }
     foreach ($xslts as $xslt => $data) {
         $optionNode = $this->template->createElement('option', array('value' => 'xml:' . $xslt), "XML: " . $xslt);
         $this->template->appendNode($optionNode, $selNode);
     }
     return true;
 }
 /**
  * Adds any controls for this display to the content node.
  * @param DOMNode $contentNode
  * @returns boolean
  */
 protected function displayReportControl($contentNode)
 {
     if (!parent::displayReportControl($contentNode)) {
         return false;
     }
     $this->template->setDisplayData("has_odt_templates", false);
     if ($this->config->is_parent("printed_forms")) {
         $print_forms = $this->config->printed_forms->getAsArray();
         foreach ($print_forms as $print_form => $print_data) {
             $this->template->setDisplayDataImmediate("has_odt_templates", " ");
             $this->template->addOption("odt_template", $print_form, $print_data['displayName'], $contentNode);
         }
     }
 }
 /**
  * Adds any controls for this display to the content node.
  * @param DOMNode $contentNode 
  * @returns boolean;
  */
 protected function displayReportControl($contentNode)
 {
     parent::displayReportControl($contentNode);
     $js = '';
     $style = $this->defaultOptions['style'];
     $selectNode = $this->template->getElementByName('style', 0, $contentNode);
     if (!$selectNode instanceof DOMNode) {
         I2CE::raiseError("Could not find style node");
         return false;
     }
     $styles = $this->defaultOptions['styles'];
     foreach ($styles as $s => $data) {
         $chart_types = $data['chart_type_options'];
         //these have already been made sane.
         foreach ($chart_types as $k => $v) {
             $chart_types[$k] = "'{$v}'";
         }
         $js .= "\tcustom_report_chart_types['{$s}'] = new Array(" . implode(',', $chart_types) . ");\n";
         $attr = array('value' => $s);
         if ($style === $s) {
             $attr['selected'] = 'selected';
         }
         $header = $s;
         if (array_key_exists('display_name', $data) && $data['display_name']) {
             $header = $data['display_name'];
         }
         $selectNode->appendChild($this->template->createElement('option', $attr, $header));
     }
     $js .= "\n    if (window.addEvent) {\n       window.addEvent('domready',function(e) {\n           chart_styles = \$('chart_styles');\n\t   if (!chart_styles) {\n   \t      return;\n\t   }\n\t   custom_report_update_chart_types(chart_styles.options[chart_styles.selectedIndex].value);\n";
     if ($this->defaultOptions['displayFieldsType']) {
         $js .= "           \n           var types = \$('displayFieldTypes');\n           if (types) {\n                  var selected = -1;\n\t\t  \$each(types.options, function(option,i){\n                      if (option && option.value == '" . $this->defaultOptions['displayFieldsType'] . "') {\n                         selected = i;\n                      }\n                  });\n                  if (selected > -1)  {\n                        types.selectedIndex = selected;\n                  } \n                 custom_report_show_chart_type('" . $this->defaultOptions['displayFieldsType'] . "');\n            }\n";
     }
     $js .= "\n       });\n    }\n";
     $this->template->addHeaderLink('mootools-core.js');
     $this->template->addHeaderText($js, 'script', 'script_chart_type_options');
     $avail_fields = $this->getReportViewDisplayedFields(false, array(''));
     $numeric = $this->findNumericFields();
     $selects = $this->template->query('.//select[@class="reportformfield" or @class="reportformfield_numeric"]', $contentNode);
     for ($i = 0; $i < $selects->length; $i++) {
         $selectNode = $selects->item($i);
         $keys = explode(':', $selectNode->getAttribute('name'));
         //Example:  <select name="displayFieldsTypes:one_row_total:0:formfield" class='reportformfield'>
         $selected = $this->defaultOptions;
         while (count($keys) > 0) {
             $key = array_shift($keys);
             if (!is_array($selected) || !array_key_exists($key, $selected)) {
                 array_unshift($keys, $key);
                 break;
             }
             $selected = $selected[$key];
         }
         if (!is_scalar($selected) || count($keys) > 0 || is_string($selected) && strlen($selected) == 0) {
             $selected = false;
         }
         if ($selectNode->getAttribute('class') == 'reportformfield') {
             $rffs = $avail_fields;
         } else {
             $rffs = $numeric;
         }
         if ($selected && !array_key_exists($selected, $rffs)) {
             $selected = false;
         }
         foreach ($rffs as $reportformfield => $data) {
             $options = array('value' => $reportformfield);
             if ($selected === false || $selected == $reportformfield) {
                 //make the first one selected or the current one selected
                 $selected = $reportformfield;
                 $options['selected'] = 'selected';
             }
             $selectNode->appendChild($this->template->createElement('option', $options, $data['header']));
         }
     }
     $selects = $this->template->query('.//select[@class="reportformfield" or @class="reportformfield_numeric" or @class="reportformfield_aggregate"]', $contentNode);
     for ($i = 0; $i < $selects->length; $i++) {
         $selectNode = $selects->item($i);
         $selected = $this->defaultOptions;
         $keys = explode(':', $selectNode->getAttribute('name'));
         while (count($keys) > 0) {
             $key = array_shift($keys);
             if (!is_array($selected) || !array_key_exists($key, $selected)) {
                 array_unshift($keys, $key);
                 break;
             }
             $selected = $selected[$key];
         }
         if (!is_scalar($selected) || count($keys) > 0 || is_string($selected) && strlen($selected) == 0) {
             $selected = false;
         }
         if ($selected === false) {
             continue;
         }
         $options = $this->template->query(".//option[@value='{$selected}']", $selectNode);
         if ($options->length == 1) {
             $selected_options = $this->template->query(".//option[@selected]", $selectNode);
             //remove any existing selections
             for ($j = 0; $j < $selected_options->length; $j++) {
                 $selected_options->item($j)->removeAttribute('selected');
             }
             $options->item(0)->setAttribute('selected', 'selected');
         }
     }
     return true;
 }
 /**
  * Adds any controls for this display to the content node.
  * @param DOMNode $contentNode 
  * @returns boolean;
  */
 protected function displayReportControl($contentNode)
 {
     parent::displayReportControl($contentNode);
     $js = '';
     $avail_fields = $this->getReportViewDisplayedFields(false, array(''));
     $numeric = $this->findNumericFields();
     if ($this->defaultOptions['total']) {
         $total = 'Total';
         I2CE::getConfig()->setIfIsSet($total, "/modules/CustomReports/text/headers/count");
         $numeric['total'] = array('header' => $total);
     }
     $ol_config = I2CE::getConfig()->modules->OpenLayers;
     if ($ol_config->is_parent('default/layers')) {
         $layers = $ol_config->default->layers->getAsArray();
         foreach ($layers as $layer => $layer_data) {
             $layer_node = $this->template->appendFileById("customReports_display_control_OpenLayers_layer.html", "div", "openlayers_layers", false, $contentNode);
             $display = $layer;
             if (array_key_exists('_display', $layer_data)) {
                 $display = $layer_data['_display'];
             }
             $this->template->setDisplayDataImmediate("openlayers_layer_name", $display, $layer_node);
             $defaults = array();
             if (array_key_exists('layers', $this->defaultOptions) && is_array($this->defaultOptions['layers']) && array_key_exists($layer, $this->defaultOptions['layers']) && is_array($this->defaultOptions['layers'][$layer])) {
                 $defaults = $this->defaultOptions['layers'][$layer];
             }
             $renames = array("layers_enable" => "enable", "layers_style" => "style", "layers_exist" => "exist");
             $checkbox = array("enable" => true, "style" => true);
             foreach ($renames as $id => $new_id) {
                 $this->template->setAttribute("id", "layers:{$layer}:{$new_id}", $id, null, $layer_node);
                 $this->template->setAttribute("name", "layers:{$layer}:{$new_id}", "layers:{$layer}:{$new_id}", null, $layer_node);
                 if (array_key_exists($new_id, $defaults) && $defaults[$new_id] == 'on') {
                     if (array_key_exists($new_id, $checkbox) && $checkbox[$new_id]) {
                         $this->template->setAttribute("checked", "checked", "layers:{$layer}:{$new_id}", null, $layer_node);
                         $this->template->setAttribute("id", "layers:{$layer}:{$new_id}_for", "layers_{$new_id}_for", null, $layer_node);
                         $this->template->setAttribute("for", "layers:{$layer}:{$new_id}", "layers:{$layer}:{$new_id}_for", null, $layer_node);
                     } else {
                         $this->template->setAttribute("value", $defaults[$new_id], "layers:{$layer}:{$new_id}", null, $layer_node);
                     }
                 }
             }
         }
     }
     /*
     $selects = $this->template->query('.//select[@class="reportformfield" or @class="reportformfield_numeric"]',$contentNode);
     for ($i=0; $i < $selects->length; $i++) {
         $selectNode = $selects->item($i);
         $keys = explode(':',$selectNode->getAttribute('name'));
         //Example:  <select name="displayFieldsTypes:one_row_total:0:formfield" class='reportformfield'>
         $selected = $this->defaultOptions;
         while (count($keys) > 0) {
             $key = array_shift($keys);
             if (!is_array($selected) || !array_key_exists($key,$selected)) {
                 array_unshift($keys,$key);
                 break;
             }
             $selected = $selected[$key];
         }
         if (!is_scalar($selected) || count($keys) > 0 || (is_string($selected) && strlen($selected) == 0)) {
             $selected = false;
         }
         if ($selectNode->getAttribute('class') == 'reportformfield') {
             $rffs = $avail_fields;
         } else {
             $rffs = $numeric;
         }
         if ($selected && !array_key_exists($selected,$rffs)) {
             $selected = false;
         }
         foreach ($rffs as $reportformfield=>$data) {
             if ( !$data ) {
                 continue;
             }
             $options = array('value'=>$reportformfield);
             if (($selected == $reportformfield)) { //make the first one selected or the current one selected
                 $options['selected'] = 'selected';
             }
             $selectNode->appendChild($this->template->createElement('option',$options,$data['header']));
         }
     }
     
     $selects = $this->template->query('.//select[@class="reportformfield" or @class="reportformfield_numeric" or @class="reportformfield_aggregate"]',$contentNode);
     for ($i=0; $i < $selects->length; $i++) {
         $selectNode = $selects->item($i);
         $selected = $this->defaultOptions;
         $keys = explode(':',$selectNode->getAttribute('name'));
         while (count($keys) > 0) {
             $key = array_shift($keys);
             if (!is_array($selected) || !array_key_exists($key,$selected)) {
                 array_unshift($keys,$key);
                 break;
             }
             $selected = $selected[$key];
         }
         if (!is_scalar($selected) || count($keys) > 0 || (is_string($selected) && strlen($selected) == 0)) {
             $selected = false;
         }
         if ( $selected === false ) {
             continue;
         }
         $options = $this->template->query(".//option[@value='$selected']",$selectNode);
         if ($options->length == 1) {
             $selected_options = $this->template->query( ".//option[@selected]", $selectNode );
             //remove any existing selections
             for( $j = 0; $j < $selected_options->length; $j++ ) {
                 $selected_options->item($j)->removeAttribute('selected');
             }
             $options->item(0)->setAttribute('selected','selected');
         }           
     }
     */
     return true;
 }