~oh-dev/openhealth/phit-tools

« back to all changes in this revision

Viewing changes to ihris-suite/lib/i2ce/modules/CustomReports/modules/PieChart/lib/I2CE_CustomReport_Display_PieChart.php

  • Committer: litlfred at ibiblio
  • Date: 2009-10-23 12:59:28 UTC
  • Revision ID: litlfred@ibiblio.org-20091023125928-u5lkafz0urm9t8eq
updated ihris-suite to 4.0.1-prerelease -- not debugged

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
2
/**
3
 
* © Copyright 2008 IntraHealth International, Inc.
4
 
5
 
* This File is part of I2CE 
6
 
7
 
* I2CE is free software; you can redistribute it and/or modify 
8
 
* it under the terms of the GNU General Public License as published by 
9
 
* the Free Software Foundation; either version 3 of the License, or
10
 
* (at your option) any later version.
11
 
12
 
* This program is distributed in the hope that it will be useful, 
13
 
* but WITHOUT ANY WARRANTY; without even the implied warranty of 
14
 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
15
 
* GNU General Public License for more details.
16
 
17
 
* You should have received a copy of the GNU General Public License 
18
 
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
3
 * @copyright © 2008, 2009 Intrahealth International, Inc.
 
4
 * This File is part of I2CE
 
5
 *
 
6
 * I2CE is free software; you can redistribute it and/or modify it
 
7
 * under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 3 of the License, or
 
9
 * (at your option) any later version.
 
10
 * 
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 * 
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
18
*/
20
19
/**
21
20
*  I2CE_CustomReport_Display_PDF
22
21
* @package I2CE
23
22
* @subpackage Core
24
23
* @author Carl Leitner <litlfred@ibiblio.org>
25
 
* @copyright Copyright &copy; 2008 IntraHealth International, Inc. 
26
 
* This file is part of I2CE. I2CE is free software; you can redistribute it and/or modify it under 
27
 
* the terms of the GNU General Public License as published by the Free Software Foundation; either 
28
 
* version 3 of the License, or (at your option) any later version. I2CE is distributed in the hope 
29
 
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
30
 
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have 
31
 
* received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
32
24
* @version 2.1
33
25
* @access public
34
26
*/
43
35
    protected $chart;
44
36
 
45
37
 
46
 
    /*
 
38
    /**
47
39
     * Display the report
48
40
     * @param DOMNode $contentNode The DOM node we wish to display into
49
41
     * @param boolean $processResults Defaults to true meaning we run through the results
 
42
     * @param mixed $controls.  If null (default), we display all the report controsl.  If string or an array of string, we only display the indicated controls
50
43
     * @returns boolean. true on sucess
51
44
     */
52
 
    public function display($contentNode,$processResults = true) {
 
45
    public function display($contentNode,$processResults = true, $controls = null) {
53
46
        if ($this->page->request_exists('flash_data')) {
54
 
            return parent::display(false,true); 
 
47
            return parent::display(false,true, $controls); 
55
48
        }  else {
56
 
            return parent::display($contentNode,false); 
 
49
            $parent_return = parent::display($contentNode,false,$controls); 
57
50
            //we want to do the reference to the flash content (this will call processResults below)
 
51
            // -- This doesn't seem to call processResults anymore so adding in the chart stuff here (?)
 
52
            
 
53
            $i2ce_config = I2CE::getConfig();
 
54
            $license = '';
 
55
            $i2ce_config->setIfIsSet($license, 'modules/maani-charts/license');
 
56
            $this->template->addHeaderLink('swfobject.js');
 
57
            $flashDataURL = 'file/charts.swf?library_path=file/charts_library';
 
58
            if ($license) {
 
59
                $flashDataURL .= '&license=' . $license;
 
60
            }
 
61
            $save_req = "flash_data&" . file_get_contents( "php://input" ) . "&" . $_SERVER['QUERY_STRING'];
 
62
            $req_key = md5($save_req);
 
63
            $_SESSION['req_query'][ $req_key ] = $save_req;
 
64
            $flashDataURL .='&php_source=' . 
 
65
                urlencode("CustomReports/show/{$this->view}/{$this->display}?req_query=" . $req_key );
 
66
            $js = "\tif(window.addEvent) { window.addEvent('domready', function() { swfobject.embedSWF('$flashDataURL', \n\t\t'report_results', '{$this->defaultOptions['flash_width']}', " .
 
67
                " '{$this->defaultOptions['flash_height']}', '9.0.0' ,'expressInstall.swf',  \n\t\t" .
 
68
                " {}, \n\t\t{quality: 'high', bgcolor:'{$this->defaultOptions['flash_bgcolor']}',wmode:'opaque'}\n\t); } ); } ";        
 
69
 
 
70
            $this->template->addHeaderLink('mootools-core.js');
 
71
            $this->template->addHeaderText($js,'script',true); //add this to a new script node.
 
72
 
 
73
            return $parent_return;
 
74
 
58
75
        }
59
76
    }
60
77
 
83
100
            SendChartData( $this->chart);
84
101
            exit();
85
102
        } else {
 
103
            // I don't think this ever gets called anymore?  Can it just be removed?
 
104
            I2CE::raiseError( "I don't think this should be called this way anymore.  It's being added to display() instead." );
86
105
            //just make a reference to the chart
87
106
            $i2ce_config = I2CE::getConfig();
88
107
            $license = '';
89
 
            if ($i2ce_config->__isset('modules/maani-charts/license')) {
90
 
                $license = $i2ce_config->__get('modules/maani-charts/license');
91
 
            }
92
 
            //$restuls_data will be false b/c we called parent::display($contentNode,false) in display() above
 
108
            $license = $i2ce_config->setIfIsSet($license, 'modules/maani-charts/license');
 
109
            //$results_data will be false b/c we called parent::display($contentNode,false) in display() above
93
110
            if (!$contentNode instanceof DOMNode) {
94
111
                return false;
95
112
            }
96
113
            $this->template->addHeaderLink('swfobject.js');
97
 
            $flashDataURL.= 'file/charts.swf?library_path=file/charts_library';
 
114
            $flashDataURL = 'file/charts.swf?library_path=file/charts_library';
98
115
            if ($license) {
99
116
                $flashDataURL .= '&license=' . $license;
100
117
            }
102
119
            $req_key = md5($save_req);
103
120
            $_SESSION['req_query'][ $req_key ] = $save_req;
104
121
            $flashDataURL .='&php_source=' . 
105
 
                urlencode("CustomReports/view/{$this->view}/{$this->display}?" . 'req_query=' . $req_key );        
 
122
                urlencode("CustomReports/show/{$this->view}/{$this->display}?req_query=" . $req_key );
106
123
            $js = "\tif(window.addEvent) { window.addEvent('domready', function() { swfobject.embedSWF('$flashDataURL', \n\t\t'report_results', '{$this->defaultOptions['flash_width']}', " .
107
124
                " '{$this->defaultOptions['flash_height']}', '9.0.0' ,'expressInstall.swf',  \n\t\t" .
108
125
                " {}, \n\t\t{quality: 'high', bgcolor:'{$this->defaultOptions['flash_bgcolor']}',wmode:'opaque'}\n\t); } ); } ";        
109
126
 
110
 
            $this->template->addHeaderLink('mootools.js');
 
127
            $this->template->addHeaderLink('mootools-core.js');
111
128
            $this->template->addHeaderText($js,'script',true); //add this to a new script node.
112
129
            return true;
113
130
        }
162
179
                array_multisort($this->chart['chart_data'][1],SORT_DESC,$this->chart['chart_data'][0]); //sort the chart data on the second row, the values.
163
180
            }
164
181
        }
 
182
        /* 
 
183
         * Moving this to the conditional below instead.
 
184
         * This corrects some issues with charts.  I'm not sure if it introduces new problems or not.
165
185
        if ($this->reverseOrder) {
166
186
            array_unshift($this->chart['chart_data'],array('',''));
167
187
        } else {
168
188
            array_unshift($this->chart['chart_data'][0],'');        
169
189
        }
 
190
        */
170
191
        $displayedFields = $this->getDisplayFieldsData();
171
192
        if ($type == 'one_row_total') {
172
 
            $header = $displayedFields[$this->displayedChartFields[0]]['header'];
 
193
            $header1 = $displayedFields[$this->displayedChartFields[0]]['header'];
 
194
            $header2 = $displayedFields[$this->displayedChartFields[1]]['header'];
173
195
        } else { 
174
 
            $header = $displayedFields[$this->displayedChartFields[1]]['header'];
 
196
            $header1 = $displayedFields[$this->displayedChartFields[1]]['header'];
 
197
            $header2 = $displayedFields[$this->displayedChartFields[0]]['header'];
175
198
        }
176
199
        if ($this->reverseOrder) {
177
 
            $this->chart['chart_data'][0][1] = $header;
 
200
            array_unshift($this->chart['chart_data'],array('',''));
 
201
            $this->chart['chart_data'][0][1] = $header1;
178
202
        } else {
179
 
            array_unshift($this->chart['chart_data'][1],$header);
 
203
            //array_unshift($this->chart['chart_data'][1],$header);
 
204
            // I'm not sure if this is right, but it fixes a couple instances so I'm trying it
 
205
            array_unshift($this->chart['chart_data'][0],$header1);
 
206
            array_unshift($this->chart['chart_data'][1],$header2);
180
207
        }
181
208
    }
182
209
 
534
561
       });
535
562
    }
536
563
";
537
 
        $this->template->addHeaderLink('mootools.js');
 
564
        $this->template->addHeaderLink('mootools-core.js');
538
565
        $this->template->addHeaderText($js,'script','script_chart_type_options');
539
 
 
540
 
        $avail_fields = $this->getReportViewDisplayedFields(false,array(''));
 
566
        
 
567
        $avail_fields = $this->getReportViewDisplayedFields( false, array( '' ) );
541
568
        $numeric = $this->findNumericFields();
542
569
        $selects = $this->template->query('.//select[@class="reportformfield" or @class="reportformfield_numeric"]',$contentNode);
543
570
        for ($i=0; $i < $selects->length; $i++) {
590
617
            if (!is_scalar($selected) || count($keys) > 0 || (is_string($selected) && strlen($selected) == 0)) {
591
618
                $selected = false;
592
619
            }
593
 
            if ($selected === false) {
 
620
            if ( $selected === false ) {
594
621
                continue;
595
622
            }
596
623
            $options = $this->template->query(".//option[@value='$selected']",$selectNode);
597
624
            if ($options->length == 1) {
598
 
                $selected_options = $this->template->query(".//option[@selected]",$selectNode);
 
625
                $selected_options = $this->template->query( ".//option[@selected]", $selectNode );
599
626
                //remove any existing selections
600
 
                for ($j=0; $k < $selected_options->length; $j++) {
601
 
                    $selected_options->removeAttribute('selected');
 
627
                for( $j = 0; $j < $selected_options->length; $j++ ) {
 
628
                    $selected_options->item($j)->removeAttribute('selected');
602
629
                }
603
630
                $options->item(0)->setAttribute('selected','selected');
604
631
            }           
614
641
    protected function setupFlashChart(&$defaultOptions) {
615
642
        $type =   $defaultOptions['displayFieldsType'];
616
643
        $displayFields  = $defaultOptions['displayFields'];
617
 
        $this->update($defaultOptions['displayFields'], $defaultOptions['displayFieldsTypes'][$type]);
 
644
        I2CE_Util::merge_recursive($defaultOptions['displayFields'], $defaultOptions['displayFieldsTypes'][$type]);
618
645
        $data = array();
619
646
        $data['title']['text']= $this->config->display_name;
620
647
        $data['elements']= array();
624
651
        if (array_key_exists('global_chart_options',$defaultOptions) && is_array($defaultOptions['global_chart_options'])) {
625
652
            $this->chart = $defaultOptions['global_chart_options'];
626
653
        }
627
 
        $this->update($this->chart,$defaultOptions['styles'][$style]['chart_options']);
 
654
        I2CE_Util::merge_recursive($this->chart,$defaultOptions['styles'][$style]['chart_options']);
628
655
        $this->displayedChartFields = array();
629
656
        foreach ($defaultOptions['displayFields'] as $index=>$data) {
630
657
            if (!is_numeric($index)) {