~oh-dev/openhealth/phit-tools

« back to all changes in this revision

Viewing changes to ihris-suite/lib/i2ce/modules/CustomReports/lib/I2CE_CustomReport_Display_Default.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_Default -- the default HTML display of a report view
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
*/
67
59
    }
68
60
 
69
61
 
 
62
    /**
 
63
     * @var protected array $formfields The array of formfields to display for this report.
 
64
     * Keys are the formfields 
 
65
     */
 
66
    protected $formfields = null;
 
67
 
 
68
 
70
69
 
71
70
    protected function doHeaderRow($contentNode) {
72
 
        $page_root =  "CustomReports/view/{$this->view}/{$this->display}";
 
71
        $page_root =  "CustomReports/show/{$this->view}/{$this->display}";
73
72
        $postfix = '?';
74
73
        $qry_fields = $this->page->request();
75
74
        if (array_key_exists('sort_order',$this->defaultOptions)) {
80
79
        }        
81
80
        if (count($qry_fields) > 0) {
82
81
            $flat = array();
83
 
            $qry_fields = $this->page->flattenVariables($qry_fields,$flat);
 
82
            $qry_fields = I2CE_Util::flattenVariables($qry_fields,$flat);
84
83
            $fields = array();
85
84
            foreach ($flat as $key=>$val) {
86
85
                if (is_array($val)) {
87
86
                    foreach ($val as $v) {
88
 
                        array_push($fields, "{$key}[]=$v");
 
87
                        array_push($fields, urlencode($key) . "[]=" . $v);
89
88
                    }
90
89
                } else {
91
 
                    array_push($fields, "$key=$val");
 
90
                array_push($fields, urlencode($key) . '=' . $val);
92
91
                }
93
92
            }
94
93
            $page_root .= '?' . implode('&',$fields);
95
94
            $postfix = '&';
96
95
        }
97
96
        if ($this->page->hasAjax()) {
98
 
            $this->page->getTemplate()->addHeaderLink("mootools.js");
 
97
            $this->page->getTemplate()->addHeaderLink("mootools-core.js");
99
98
        }        
100
99
        $sort_order = array();
101
 
        $formfields = $this->getDisplayFieldsData();
 
100
        if ($this->formfields == null) {
 
101
            $this->formfields = $this->getDisplayFieldsData();
 
102
        }
102
103
        $sort_descriptions = array();
103
104
        $t_sortFields = array();
104
105
        foreach ($sortFields as $i=>$s) {
107
108
            }
108
109
            if ($s[0] == '-') {
109
110
                $s = substr($s,1);
110
 
                if ( !array_key_exists($s,$formfields)) {
 
111
                if ( !array_key_exists($s,$this->formfields)) {
111
112
                    continue;
112
113
                }
113
 
                $sort_descriptions[] = $formfields[$s]['header'] . ' (Decreasing)';                
 
114
                $sort_descriptions[] = $this->formfields[$s]['header'] . ' (Decreasing)';                
114
115
                $t_sortFields[$s] = true;
115
116
                $sort_order[$s] = '-';
116
117
            } else {
117
 
                if ( !array_key_exists($s,$formfields)) {
 
118
                if ( !array_key_exists($s,$this->formfields)) {
118
119
                    continue;
119
120
                }
120
 
                $sort_descriptions[] = $formfields[$s]['header'] . ' (Increasing)';                
 
121
                $sort_descriptions[] = $this->formfields[$s]['header'] . ' (Increasing)';                
121
122
                $t_sortFields[$s] = true;
122
123
                $sort_order[$s] = '';
123
124
            }
128
129
            $sort_description = implode(',',$sort_descriptions);
129
130
        } 
130
131
        $this->template->setDisplayDataImmediate('sort_description',$sort_description,$contentNode);
 
132
        
131
133
        $color_grad = 0;
132
134
        if (count($sortFields) > 0) {
133
135
            $color_grad = (int) floor((0xFF - 0xCC) /(count($sortFields)));
134
136
        }
135
 
        foreach ($formfields as $formfield=>$data) {
 
137
        foreach ($this->formfields as $formfield=>$data) {
136
138
            $head = $this->template->appendFileByName( "customReports_table_head_cell.html", "th", "report_header",0,$contentNode );
137
139
            if (!$head instanceof DOMNode) {
138
140
                I2CE::raiseError("Could not add head cell to table");
139
141
                return false;
140
142
            }
141
 
            if ( $formfield == $sortFields[count($sortFields) -1]) {
 
143
            if ( count($sortFields) > 0 && $formfield == $sortFields[count($sortFields) -1]) {
142
144
                $this->template->setNodeAttribute( "class", "selected", $head );
143
145
            }else {
144
146
                $position = array_search($formfield,$sortFields);
211
213
        }
212
214
        //take care of the jumper
213
215
        $total_pages = 1;
214
 
        $per_page = (int) $this->page->request("limit_per_page");
 
216
        $per_page = $this->defaultOptions['limit_per_page'];
215
217
        if ($per_page <1) {
216
218
            //check it is not bad, if so make it something reasonable -- in fact make it the default per page in I2CE_CustomReport_Display
217
219
            $per_page = 100;
235
237
        foreach (array('limit_page') as $key) {
236
238
            unset($qry_fields[$key]);
237
239
        }
238
 
        $url = "CustomReports/view/{$this->view}/{$this->display}";
 
240
        $url = "CustomReports/show/{$this->view}/{$this->display}";
 
241
        $qry_fields = I2CE_Page::flattenRequestVars($qry_fields);
239
242
        $this->page->makeJumper('report',$page,$total_pages,$url,$qry_fields,'limit_page');            
240
243
    }
241
244
 
242
 
 
243
245
    
244
246
    /**
245
247
     * Process a result row.
249
251
     * @param DOMNode $contentNode. Default to null. A node to append the result onto
250
252
     */
251
253
    protected function processResultRow($row,$row_num,$contentNode=null) {
252
 
        $formfields = $this->getDisplayFieldsData();
 
254
        if ($this->formfields == null) {
 
255
            $this->formfields = $this->getDisplayFieldsData();
 
256
        }
253
257
        $mapped_row = $this->mapResults($row);
254
258
        $rowNode = $this->template->appendFileByNode( "customReports_table_data_row.html", "tr",$contentNode);
255
259
        if (!$rowNode instanceof DOMNode) {
257
261
            return false;
258
262
        }
259
263
        $this->template->setDisplayDataImmediate( "row_count", $row_num+1 ,$rowNode);                       
260
 
        foreach ($formfields as $formfield =>$data) {
 
264
        foreach ($this->formfields as $formfield =>$data) {
261
265
            if ($data['link']) {
262
266
                $cellNode =$this->template->appendFileByNode( "customReports_table_link_cell.html", "td", $rowNode );
263
267
                $link_append = '';