2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
41 require_once('include/ListView/ListViewDisplay.php');
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';
53 function ListViewXTPL() {
54 parent::ListViewDisplay();
58 * Processes the request. Calls ListViewData process. Also assigns all lang strings, export links,
59 * This is called from ListViewDisplay
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
66 function process($file, $data, $html_var) {
67 global $odd_bg, $even_bg, $hilite_bg, $click_bg;
69 parent::process($file, $data, $html_var);
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']);
78 $this->processPagination();
79 $this->xtpl->parse($this->nav_block);
81 $this->processArrows($data['pageData']['ordering']);
84 if($this->xtpl->exists($this->pro_nav_block)) $this->xtpl->parse($this->pro_nav_block);
85 $this->xtpl->assign('CHECKALL', "<input type='checkbox' 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]);
92 $this->xtpl->assign('ROW_COLOR', ($oddRow) ? 'oddListRow' : 'evenListRow');
93 $this->xtpl->assign('BG_COLOR', ($oddRow) ? $odd_bg : $even_bg);
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);
100 $prerow = " <input onclick='sListView.check_item(this, document.MassUpdate)' type='checkbox' class='checkbox' name='mass[]' value='". $id. "'>";
101 $this->xtpl->assign('PREROW', $prerow);
103 $this->xtpl->parse($this->row_block);
108 * Assigns the sort arrows in the tpl
110 * @param ordering array data that contains the ordering info
113 function processArrows($ordering) {
115 $pathParts = pathinfo(SugarThemeRegistry::current()->getImageURL('arrow.gif',false));
117 list($width,$height) = getimagesize($pathParts['dirname'].'/'.$pathParts['basename']);
119 $this->xtpl->assign('arrow_start', " <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);
126 * Assigns the pagination links at the top and bottom of the listview
129 function processPagination() {
131 //_pp($this->data['pageData']);
132 if(empty($this->data['pageData']['urls']['prevPage'])) {
133 $startLink = SugarThemeRegistry::current()->getImage("start_off", "alt='".$app_strings['LNK_LIST_START']."' border='0' align='absmiddle'")." ".$app_strings['LNK_LIST_START'];
134 $prevLink = SugarThemeRegistry::current()->getImage("previous_off", "alt='".$app_strings['LNK_LIST_PREVIOUS']."' border='0' align='absmiddle'")." ".$app_strings['LNK_LIST_PREVIOUS'];
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","alt='".$app_strings['LNK_LIST_START']."' border='0' align='absmiddle'")." ".$app_strings['LNK_LIST_START']."</a>";
139 // $previous_link = "<a href=\"#\" onclick=\"javascript:save_checks($previous_offset, '{$moduleString}')\" >".SugarThemeRegistry::current()->getImage("previous","alt='".$app_strings['LNK_LIST_PREVIOUS']."' border='0' align='absmiddle'")." ".$app_strings['LNK_LIST_PREVIOUS']."</a>";
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","alt='".$app_strings['LNK_LIST_START']."' border='0' align='absmiddle'")." ".$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","alt='".$app_strings['LNK_LIST_PREVIOUS']."' border='0' align='absmiddle'")." ".$app_strings['LNK_LIST_PREVIOUS']."</a>";
147 $startLink = "<a href=\"{$this->data['pageData']['urls']['startPage']}\" >".SugarThemeRegistry::current()->getImage("start","alt='".$app_strings['LNK_LIST_START']."' border='0' align='absmiddle'")." ".$app_strings['LNK_LIST_START']."</a>";
148 $prevLink = "<a href=\"{$this->data['pageData']['urls']['prevPage']}\" >".SugarThemeRegistry::current()->getImage("previous","alt='".$app_strings['LNK_LIST_PREVIOUS']."' border='0' align='absmiddle'")." ".$app_strings['LNK_LIST_PREVIOUS']."</a>";
152 if(!$this->data['pageData']['offsets']['totalCounted']) {
153 $endLink = $app_strings['LNK_LIST_END']." ".SugarThemeRegistry::current()->getImage("end_off","alt='".$app_strings['LNK_LIST_END']."' border='0' align='absmiddle'");
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']." ".SugarThemeRegistry::current()->getImage("end","alt='".$app_strings['LNK_LIST_END']."' border='0' align='absmiddle'")."</a>";
158 // $next_link = "<a href=\"#\" onclick=\"javascript:save_checks($next_offset, '{$moduleString}')\" >".$app_strings['LNK_LIST_NEXT']." ".SugarThemeRegistry::current()->getImage("next","alt='".$app_strings['LNK_LIST_NEXT']."' border='0' align='absmiddle'")."</a>";
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']." ".SugarThemeRegistry::current()->getImage("end","alt='".$app_strings['LNK_LIST_END']."' border='0' align='absmiddle'")."</a>";
162 // $next_link = "<a href=\"$next_URL\" onclick=\"javascript:return sListView.save_checks($next_offset, '{$moduleString}')\" >".$app_strings['LNK_LIST_NEXT']." ".SugarThemeRegistry::current()->getImage("next","alt='".$app_strings['LNK_LIST_NEXT']."' border='0' align='absmiddle'")."</a>";
165 $endLink = "<a href=\"{$this->data['pageData']['urls']['endPage']}\" >".$app_strings['LNK_LIST_END']." ".SugarThemeRegistry::current()->getImage("end","alt='".$app_strings['LNK_LIST_END']."' border='0' align='absmiddle'")."</a>";
169 if(empty($this->data['pageData']['urls']['nextPage'])){
170 $nextLink = $app_strings['LNK_LIST_NEXT']." ".SugarThemeRegistry::current()->getImage("next_off","alt='".$app_strings['LNK_LIST_NEXT']."' border='0' align='absmiddle'");
172 $nextLink = "<a href=\"{$this->data['pageData']['urls']['nextPage']}\" >".$app_strings['LNK_LIST_NEXT']." ".SugarThemeRegistry::current()->getImage("next","alt='".$app_strings['LNK_LIST_NEXT']."' border='0' align='absmiddle'")."</a>";
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 = '';
182 $htmlText = "<tr class='pagination'>\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." ".$prevLink." <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']){
190 $htmlText .=")</span> ".$nextLink." ";
191 if($this->data['pageData']['offsets']['totalCounted']){
192 $htmlText .= $endLink;
194 $htmlText .="</td></tr></table>\n</td>\n</tr>\n";
196 $this->xtpl->assign("PAGINATION", $htmlText);
200 * Displays the xtpl, either echo or returning the contents
202 * @param echo bool echo or return contents
205 function display($echo = true) {
206 $str = parent::display();
207 $strend = parent::displayEnd();
208 $this->xtpl->parse($this->main_block);
211 $this->xtpl->out($this->main_block);
215 return $str . $this->xtpl->text() . $strend;