]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/ListView/ListViewXTPL.php
Release 6.4.0
[Github/sugarcrm.git] / include / ListView / ListViewXTPL.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38  
39
40
41 require_once('include/ListView/ListViewDisplay.php');
42         
43 class ListViewXTPL extends ListViewDisplay{
44         var $row_block = 'main.row';
45         var $main_block = 'main';
46         var $pro_block = 'main.row.pro';
47         var $os_block  = 'main.row.os';
48         var $nav_block = 'main.list_nav_row';
49         var $pro_nav_block = 'main.pro_nav';
50         var $data;
51         var $xtpl;
52
53         function ListViewXTPL() {
54                 parent::ListViewDisplay();
55         }
56         
57     /**
58      * Processes the request. Calls ListViewData process. Also assigns all lang strings, export links,
59      * This is called from ListViewDisplay
60      *    
61      * @param file file Template file to use
62      * @param data array from ListViewData
63      * @param html_var string the corresponding html var in xtpl per row
64      *
65      */ 
66         function process($file, $data, $html_var) {
67                 global $odd_bg, $even_bg, $hilite_bg, $click_bg;
68                 
69                 parent::process($file, $data, $html_var);
70                 $this->data = $data;
71                 $html_var = strtoupper($html_var);
72                 $this->xtpl = new XTemplate($file);
73                 $this->xtpl->assign('MOD', $GLOBALS['mod_strings']);
74                 $this->xtpl->assign('APP', $GLOBALS['app_strings']);
75                 $this->xtpl->assign('BG_HILITE', $hilite_bg);
76                 $this->xtpl->assign('ORDER_BY', $data['pageData']['urls']['orderBy']);
77                 
78                 $this->processPagination();
79                 $this->xtpl->parse($this->nav_block);
80                 
81                 $this->processArrows($data['pageData']['ordering']);
82                 
83                 $oddRow = false;
84                 if($this->xtpl->exists($this->pro_nav_block)) $this->xtpl->parse($this->pro_nav_block);
85                 $this->xtpl->assign('CHECKALL', "<input type='checkbox' title='".$GLOBALS['app_strings']['LBL_SELECT_ALL_TITLE']."' class='checkbox' id='massall' name='massall' value='' onclick='sListView.check_all(document.MassUpdate, \"mass[]\", this.checked);' />");
86                 foreach($data['data'] as $id=>$row) {
87                         $this->xtpl->assign($html_var, $row);
88                         if(!empty($data['pageData']['tag'][$id])) {
89                                 $this->xtpl->assign('TAG', $data['pageData']['tag'][$id]);
90                         }
91                                                 
92                         $this->xtpl->assign('ROW_COLOR', ($oddRow) ? 'oddListRow' : 'evenListRow');
93                         $this->xtpl->assign('BG_COLOR', ($oddRow) ? $odd_bg : $even_bg);
94                         $oddRow = !$oddRow;
95                         
96                         if($this->xtpl->exists($this->pro_block)) $this->xtpl->parse($this->pro_block);
97 //                      if($this->xtpl->exists($this->os_block)) $this->xtpl->parse($this->os_block);
98
99
100                         $prerow =  "&nbsp;<input onclick='sListView.check_item(this, document.MassUpdate)' type='checkbox' class='checkbox' name='mass[]' value='". $id. "'>";
101                         $this->xtpl->assign('PREROW', $prerow);
102                 
103                         $this->xtpl->parse($this->row_block);
104                 }
105         }
106         
107     /**
108      * Assigns the sort arrows in the tpl
109      *    
110      * @param ordering array data that contains the ordering info
111      *
112      */
113         function processArrows($ordering) {
114         
115                 $pathParts = pathinfo(SugarThemeRegistry::current()->getImageURL('arrow.gif',false));
116                 
117         list($width,$height) = getimagesize($pathParts['dirname'].'/'.$pathParts['basename']);
118                 
119                 $this->xtpl->assign('arrow_start', "&nbsp;<!--not_in_theme!--><img border='0' src='".getJSPath($pathParts['dirname'].'/'.$pathParts['filename']));
120                 $this->xtpl->assign('arrow_end', "' width='$width' height='$height' align='absmiddle' alt=".translate('LBL_SORT').">");
121                 $arrow_order = (strcmp($ordering['sortOrder'], 'ASC'))?'_up': '_down';
122                 $this->xtpl->assign($ordering['orderBy'].'_arrow', $arrow_order);
123         }       
124         
125     /**
126      * Assigns the pagination links at the top and bottom of the listview
127      *    
128      */
129         function processPagination() {
130                 global $app_strings;
131 //_pp($this->data['pageData']);
132                 if(empty($this->data['pageData']['urls']['prevPage'])) {
133                         $startLink = SugarThemeRegistry::current()->getImage("start_off", "border='0' align='absmiddle'",null,null,'.gif',$app_strings['LNK_LIST_START'])."&nbsp;".$app_strings['LNK_LIST_START'];
134                         $prevLink = SugarThemeRegistry::current()->getImage("previous_off", "border='0' align='absmiddle'",null,null,'.gif',$app_strings['LNK_LIST_PREVIOUS'])."&nbsp;".$app_strings['LNK_LIST_PREVIOUS'];
135                 }
136                 else {
137 //                      if($this->multi_select_popup) {// nav links for multiselect popup, submit form to save checks. 
138 //                              $start_link = "<a href=\"#\" onclick=\"javascript:save_checks(0, '{$moduleString}')\" >".SugarThemeRegistry::current()->getImage("start","border='0' align='absmiddle'",null,null,'.gif',$app_strings['LNK_LIST_START'])."&nbsp;".$app_strings['LNK_LIST_START']."</a>";
139 //                              $previous_link = "<a href=\"#\" onclick=\"javascript:save_checks($previous_offset, '{$moduleString}')\" >".SugarThemeRegistry::current()->getImage("previous","border='0' align='absmiddle'",null,null,'.gif',$app_strings['LNK_LIST_PREVIOUS'])."&nbsp;".$app_strings['LNK_LIST_PREVIOUS']."</a>";
140 //                      }
141 //                      elseif($this->shouldProcess) {
142 //                              // TODO: make popups / listview check saving the same 
143 //                              $start_link = "<a href=\"$start_URL\" onclick=\"javascript:return sListView.save_checks(0, '{$moduleString}')\" >".SugarThemeRegistry::current()->getImage("start","border='0' align='absmiddle'",null,null,'.gif',$app_strings['LNK_LIST_START'])."&nbsp;".$app_strings['LNK_LIST_START']."</a>";
144 //                              $previous_link = "<a href=\"$previous_URL\" onclick=\"javascript:return sListView.save_checks($previous_offset, '{$moduleString}')\" >".SugarThemeRegistry::current()->getImage("previous","border='0' align='absmiddle'",null,null,'.gif',$app_strings['LNK_LIST_PREVIOUS'])."&nbsp;".$app_strings['LNK_LIST_PREVIOUS']."</a>";
145 //                      }
146 //                      else {
147                                 $startLink = "<a href=\"{$this->data['pageData']['urls']['startPage']}\" >".SugarThemeRegistry::current()->getImage("start","border='0' align='absmiddle'",null,null,'.gif',$app_strings['LNK_LIST_START'])."&nbsp;".$app_strings['LNK_LIST_START']."</a>";
148                                 $prevLink = "<a href=\"{$this->data['pageData']['urls']['prevPage']}\" >".SugarThemeRegistry::current()->getImage("previous","border='0' align='absmiddle'",null,null,'.gif',$app_strings['LNK_LIST_PREVIOUS'])."&nbsp;".$app_strings['LNK_LIST_PREVIOUS']."</a>";
149 //                      }
150                 }
151
152                 if(!$this->data['pageData']['offsets']['totalCounted']) {
153                         $endLink = $app_strings['LNK_LIST_END']."&nbsp;".SugarThemeRegistry::current()->getImage("end_off","border='0' align='absmiddle'",null,null,'.gif',$app_strings['LNK_LIST_END']);
154                 }
155                 else {
156 //                      if($this->multi_select_popup) { // nav links for multiselect popup, submit form to save checks.
157 //                              $end_link = "<a href=\"#\" onclick=\"javascript:save_checks($last_offset, '{$moduleString}')\" >".$app_strings['LNK_LIST_END']."&nbsp;".SugarThemeRegistry::current()->getImage("end","border='0' align='absmiddle'",null,null,'.gif',$app_strings['LNK_LIST_END'])."</a>";
158 //                              $next_link = "<a href=\"#\" onclick=\"javascript:save_checks($next_offset, '{$moduleString}')\" >".$app_strings['LNK_LIST_NEXT']."&nbsp;".SugarThemeRegistry::current()->getImage("next","border='0' align='absmiddle'",null,null,'.gif',$app_strings['LNK_LIST_NEXT'])."</a>";
159 //                      }
160 //                      elseif($this->shouldProcess) {
161 //                              $end_link = "<a href=\"$end_URL\" onclick=\"javascript:return sListView.save_checks($last_offset, '{$moduleString}')\" >".$app_strings['LNK_LIST_END']."&nbsp;".SugarThemeRegistry::current()->getImage("end","border='0' align='absmiddle'",null,null,'.gif',$app_strings['LNK_LIST_END'])."</a>";
162 //                              $next_link = "<a href=\"$next_URL\" onclick=\"javascript:return sListView.save_checks($next_offset, '{$moduleString}')\" >".$app_strings['LNK_LIST_NEXT']."&nbsp;".SugarThemeRegistry::current()->getImage("next","border='0' align='absmiddle'",null,null,'.gif',$app_strings['LNK_LIST_NEXT'])."</a>";
163 //                      }
164 //                      else {
165                                 $endLink = "<a href=\"{$this->data['pageData']['urls']['endPage']}\" >".$app_strings['LNK_LIST_END']."&nbsp;".SugarThemeRegistry::current()->getImage("end","border='0' align='absmiddle'",null,null,'.gif',$app_strings['LNK_LIST_END'])."</a>";
166                                 
167 //                      }
168                 }
169                 if(empty($this->data['pageData']['urls']['nextPage'])){
170                         $nextLink = $app_strings['LNK_LIST_NEXT']."&nbsp;".SugarThemeRegistry::current()->getImage("next_off","border='0' align='absmiddle'",null,null,'.gif',$app_strings['LNK_LIST_NEXT']);
171                 }else{
172                                 $nextLink = "<a href=\"{$this->data['pageData']['urls']['nextPage']}\" >".$app_strings['LNK_LIST_NEXT']."&nbsp;".SugarThemeRegistry::current()->getImage("next","border='0' align='absmiddle'",null,null,'.gif',$app_strings['LNK_LIST_NEXT'])."</a>";
173                 }
174                 
175                 if($this->export) $export_link = $this->buildExportLink();
176                 else $export_link = '';
177                 if($this->mailMerge)$merge_link = $this->buildMergeLink();
178                 else $merge_link = '';
179                 if($this->multiSelect) $selected_objects_span = $this->buildSelectedObjectsSpan();
180                 else $selected_objects_span = '';
181
182                 $htmlText = "<tr class='pagination' role='presentation'>\n"
183                                 . "<td COLSPAN=\"20\" align=\"right\">\n"
184                                 . "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr><td align=\"left\">$export_link$merge_link$selected_objects_span</td>\n"
185                                 . "<td nowrap align=\"right\">".$startLink."&nbsp;&nbsp;".$prevLink."&nbsp;&nbsp;<span class='pageNumbers'>(".($this->data['pageData']['offsets']['current'] + 1) ." - ".($this->data['pageData']['offsets']['current'] + $this->rowCount)
186                                 . " ".$app_strings['LBL_LIST_OF']." ".$this->data['pageData']['offsets']['total'];
187                 if(!$this->data['pageData']['offsets']['totalCounted']){
188                         $htmlText .= '+';       
189                 }
190                 $htmlText .=")</span>&nbsp;&nbsp;".$nextLink."&nbsp;&nbsp;";
191                 if($this->data['pageData']['offsets']['totalCounted']){
192                         $htmlText .= $endLink;
193                 }
194                 $htmlText .="</td></tr></table>\n</td>\n</tr>\n";
195
196                 $this->xtpl->assign("PAGINATION", $htmlText);
197         }
198         
199     /**
200      * Displays the xtpl, either echo or returning the contents
201      *    
202      * @param echo bool echo or return contents
203      *
204      */
205         function display($echo = true) {
206                 $str = parent::display();
207                 $strend = parent::displayEnd();
208                 $this->xtpl->parse($this->main_block);
209                 if($echo) {
210                         echo $str;
211                         $this->xtpl->out($this->main_block);
212                         echo $strend;
213                 }
214                 else {
215                         return $str . $this->xtpl->text() . $strend;
216                 }
217         }
218 }
219
220
221 ?>