]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/ListView/ListViewSmarty.php
Release 6.5.0
[Github/sugarcrm.git] / include / ListView / ListViewSmarty.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-2012 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 require_once('include/ListView/ListViewDisplay.php');
40
41
42 require_once('include/contextMenus/contextMenu.php');
43
44 class ListViewSmarty extends ListViewDisplay{
45
46         var $data;
47         var $ss; // the smarty object
48         var $displayColumns;
49         var $searchColumns; // set by view.list.php
50         var $tpl;
51         var $moduleString;
52         var $export = true;
53     var $delete = true;
54     var $select = true;
55     var $mailMerge = true;
56     var $email = true;
57     var $targetList = false;
58         var $multiSelect = true;
59         var $quickViewLinks = true;
60         var $lvd;
61         var $mergeduplicates = true;
62     var $contextMenus = true;
63     var $showMassupdateFields = true;
64     var $menu_location = 'top';
65     /**
66      * Constructor, Smarty object immediately available after
67      *
68      */
69         function ListViewSmarty() {
70                 parent::ListViewDisplay();
71                 $this->ss = new Sugar_Smarty();
72         }
73
74     /**
75      * Processes the request. Calls ListViewData process. Also assigns all lang strings, export links,
76      * This is called from ListViewDisplay
77      *
78      * @param file file Template file to use
79      * @param data array from ListViewData
80      * @param html_var string the corresponding html var in xtpl per row
81      *
82      */
83         function process($file, $data, $htmlVar) {
84                 if(!$this->should_process)return;
85                 global $odd_bg, $even_bg, $hilite_bg, $click_bg, $app_strings;
86                 parent::process($file, $data, $htmlVar);
87
88                 $this->tpl = $file;
89                 $this->data = $data;
90
91         $totalWidth = 0;
92         foreach($this->displayColumns as $name => $params) {
93             $totalWidth += $params['width'];
94         }
95         $adjustment = $totalWidth / 100;
96
97         $contextMenuObjectsTypes = array();
98         foreach($this->displayColumns as $name => $params) {
99             $this->displayColumns[$name]['width'] = floor($this->displayColumns[$name]['width'] / $adjustment);
100             // figure out which contextMenu objectsTypes are required
101             if(!empty($params['contextMenu']['objectType']))
102                 $contextMenuObjectsTypes[$params['contextMenu']['objectType']] = true;
103         }
104                 $this->ss->assign('displayColumns', $this->displayColumns);
105                 $this->ss->assign('APP',$app_strings);
106
107                 $this->ss->assign('bgHilite', $hilite_bg);
108                 $this->ss->assign('colCount', count($this->displayColumns) + 10);
109                 $this->ss->assign('htmlVar', strtoupper($htmlVar));
110                 $this->ss->assign('moduleString', $this->moduleString);
111         $this->ss->assign('editLinkString', $app_strings['LBL_EDIT_BUTTON']);
112         $this->ss->assign('viewLinkString', $app_strings['LBL_VIEW_BUTTON']);
113         $this->ss->assign('allLinkString',$app_strings['LBL_LINK_ALL']);
114         $this->ss->assign('noneLinkString',$app_strings['LBL_LINK_NONE']);
115         $this->ss->assign('recordsLinkString',$app_strings['LBL_LINK_RECORDS']);
116         $this->ss->assign('selectLinkString',$app_strings['LBL_LINK_SELECT']);
117
118         // Bug 24677 - Correct the page total amount on the last page of listviews
119         $pageTotal = $this->data['pageData']['offsets']['next']-$this->data['pageData']['offsets']['current'];
120         if ( $this->data['pageData']['offsets']['next'] < 0 ) {
121             $pageTotal = $this->data['pageData']['offsets']['total'] - $this->data['pageData']['offsets']['current'];
122         }
123
124                 if($this->select)$this->ss->assign('selectLinkTop', $this->buildSelectLink('select_link', $this->data['pageData']['offsets']['total'], $pageTotal));
125         if($this->select)$this->ss->assign('selectLinkBottom', $this->buildSelectLink('select_link', $this->data['pageData']['offsets']['total'], $pageTotal, "bottom"));
126
127         if($this->show_action_dropdown)
128                 {
129             $action_menu = $this->buildActionsLink();
130                         $this->ss->assign('actionsLinkTop', $action_menu);
131             if(count($action_menu['buttons']) > 0) {
132                 $this->ss->assign('actionDisabledLink', preg_replace("/id\s*\=(\"\w+\"|w+)/i", "", $action_menu['buttons'][0]));
133             }
134             $menu_location = 'bottom';
135             $this->ss->assign('actionsLinkBottom', $this->buildActionsLink('actions_link' ,$menu_location));
136                 }
137                 
138                 $this->ss->assign('quickViewLinks', $this->quickViewLinks);
139
140                 // handle save checks and stuff
141                 if($this->multiSelect)
142         {
143                         $this->ss->assign('selectedObjectsSpan', $this->buildSelectedObjectsSpan(true, (isset($_POST['mass'])) ? count($_POST['mass']): 0));
144                     $this->ss->assign('multiSelectData', $this->getMultiSelectData());
145                 } else {
146             $this->ss->assign('multiSelectData', '<textarea style="display: none" name="uid"></textarea>');
147         }
148                 // include button for Adding to Target List if in one of four applicable modules
149                 if ( isset ( $_REQUEST['module']) && in_array ( $_REQUEST['module'] , array ( 'Contacts','Prospects','Leads','Accounts' ))
150                 && ACLController::checkAccess('ProspectLists','edit',true)) {
151                         $this->ss->assign( 'targetLink', $this->buildTargetList() ) ;
152                 }
153                 $this->processArrows($data['pageData']['ordering']);
154                 $this->ss->assign('prerow', $this->multiSelect);
155                 $this->ss->assign('clearAll', $app_strings['LBL_CLEARALL']);
156                 $this->ss->assign('rowColor', array('oddListRow', 'evenListRow'));
157                 $this->ss->assign('bgColor', array($odd_bg, $even_bg));
158         $this->ss->assign('contextMenus', $this->contextMenus);
159         $this->ss->assign('is_admin_for_user', $GLOBALS['current_user']->isAdminForModule('Users'));
160         $this->ss->assign('is_admin', $GLOBALS['current_user']->isAdmin());
161
162
163         if($this->contextMenus && !empty($contextMenuObjectsTypes)) {
164             $script = '';
165             $cm = new contextMenu();
166             foreach($contextMenuObjectsTypes as $type => $value) {
167                 $cm->loadFromFile($type);
168                 $script .= $cm->getScript();
169                 $cm->menuItems = array(); // clear menuItems out
170             }
171             $this->ss->assign('contextMenuScript', $script);
172         }
173         }
174
175     /**
176      * Assigns the sort arrows in the tpl
177      *
178      * @param ordering array data that contains the ordering info
179      *
180      */
181         function processArrows($ordering)
182     {
183                 $pathParts = pathinfo(SugarThemeRegistry::current()->getImageURL('arrow.gif',false));
184
185         list($width,$height) = getimagesize($pathParts['dirname'].'/'.$pathParts['basename']);
186
187                 $this->ss->assign('arrowExt', $pathParts['extension']);
188                 $this->ss->assign('arrowWidth', $width);
189                 $this->ss->assign('arrowHeight', $height);
190                 $this->ss->assign('arrowAlt', translate('LBL_SORT'));
191         }
192
193
194
195     /**
196      * Displays the xtpl, either echo or returning the contents
197      *
198      * @param end bool display the ending of the listview data (ie MassUpdate)
199      *
200      */
201         function display($end = true) {
202
203                 if(!$this->should_process) return $GLOBALS['app_strings']['LBL_SEARCH_POPULATE_ONLY'];
204         global $app_strings, $sugar_version, $sugar_flavor, $server_unique_key, $currentModule, $app_list_strings;
205         $this->ss->assign('moduleListSingular', $app_list_strings["moduleListSingular"]);
206         $this->ss->assign('data', $this->data['data']);
207         $this->ss->assign('query', $this->data['query']);
208         $this->ss->assign('sugar_info', array("sugar_version" => $sugar_version, 
209                                                                                           "sugar_flavor" => $sugar_flavor));
210                 $this->data['pageData']['offsets']['lastOffsetOnPage'] = $this->data['pageData']['offsets']['current'] + count($this->data['data']);
211                 $this->ss->assign('pageData', $this->data['pageData']);
212
213         $navStrings = array('next' => $app_strings['LNK_LIST_NEXT'],
214                             'previous' => $app_strings['LNK_LIST_PREVIOUS'],
215                             'end' => $app_strings['LNK_LIST_END'],
216                             'start' => $app_strings['LNK_LIST_START'],
217                             'of' => $app_strings['LBL_LIST_OF']);
218         $this->ss->assign('navStrings', $navStrings);
219
220         $displayEmptyDataMessages = TRUE;
221         //TODO: Cleanup, better logic for which modules are exempt from the new messaging. 
222         $modulesExemptFromEmptyDataMessages = array('WorkFlow','ContractTypes', 'OAuthKeys', 'TimePeriods');
223         if( (isset($GLOBALS['moduleTabMap'][$currentModule]) && $GLOBALS['moduleTabMap'][$currentModule] == 'Administration')
224             || isset($GLOBALS['adminOnlyList'][$currentModule]) || in_array($currentModule, $modulesExemptFromEmptyDataMessages) )
225         {
226             $displayEmptyDataMessages = FALSE;
227         }
228         $this->ss->assign('displayEmptyDataMesssages', $displayEmptyDataMessages);
229
230                 $str = parent::display();
231                 $strend = $this->displayEnd();
232
233                 return $str . $this->ss->fetch($this->tpl) . (($end) ? $strend : '');
234         }
235     function displayEnd() {
236         $str = '';
237         if($this->show_mass_update_form) {
238             if($this->showMassupdateFields){
239                 $str .= $this->mass->getMassUpdateForm(true);
240             }
241             $str .= $this->mass->endMassUpdateForm();
242         }
243
244         return $str;
245     }
246 }
247
248 ?>