]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/ListView/ListView.php
Release 6.5.0RC2
[Github/sugarcrm.git] / include / ListView / ListView.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 require_once('include/EditView/SugarVCR.php');
39 /**
40  * ListView - list of many objects
41  * @api
42  */
43 class ListView
44 {
45     var $local_theme= null;
46     var $local_app_strings= null;
47     var $local_image_path = null;
48     var $local_current_module = null;
49     var $local_mod_strings = null;
50     var $records_per_page = 20;
51     var $xTemplate = null;
52     var $xTemplatePath = null;
53     var $seed_data = null;
54     var $query_where = null;
55     var $query_limit = -1;
56     var $query_orderby = null;
57     var $header_title = '';
58     var $header_text = '';
59     var $initialized = false;
60     var $show_export_button = true;
61     var $show_delete_button = true;
62     var $show_select_menu = true;
63     var $show_paging = true;
64     var $show_mass_update = true;
65     var $show_mass_update_form = true;
66     var $query_where_has_changed = false;
67     var $display_header_and_footer = true;
68     var $baseURL = '';
69     var $is_dynamic = false;
70     var $inline = false;
71     var $start_link_wrapper = '';
72     var $end_link_wrapper = '';
73     var $list_field_defs = array();
74
75     var $shouldProcess = false;
76     var $data_array;
77     var $related_field_name = '';
78     var $child_focus = '';
79     var $layout_manager = null;
80     var $process_for_popups = false;
81     var $multi_select_popup=false;
82     var $_additionalDetails = false;
83     var $additionalDetailsFunction = null;
84     var $sort_order = '';
85     var $force_mass_update=false;
86     var $keep_mass_update_form_open=false;
87     var $ignorePopulateOnly = false;
88
89 function setDataArray($value) {
90     $this->data_array = $value;
91 }
92
93 function processListViewMulti($seed, $xTemplateSection, $html_varName) {
94
95     $this->shouldProcess = true;
96
97     echo "<form name='MassUpdate' method='post' action='index.php'>";
98     $this->processListViewTwo($seed, $xTemplateSection, $html_varName);
99
100     echo "<a href='javascript:" . ((!$this->multi_select_popup) ? 'sListView.' : ''). "check_all(document.MassUpdate, \"mass[]\", true)'>".translate('LBL_CHECKALL')."</a> - <a href='javascript:sListView.check_all(document.MassUpdate, \"mass[]\", false);'>".translate('LBL_CLEARALL')."</a>";
101     echo '<br><br>';
102 }
103
104
105 function processListView($seed, $xTemplateSection, $html_varName)
106 {
107     global $sugar_config;
108
109     $populateOnly = $this->ignorePopulateOnly ? FALSE : (!empty($sugar_config['save_query']) && $sugar_config['save_query'] == 'populate_only');
110     if(isset($seed->module_dir) && $populateOnly) {
111         if(empty($GLOBALS['displayListView']) && strcmp(strtolower($_REQUEST['action']), 'popup') != 0 && (!empty($_REQUEST['clear_query']) || $_REQUEST['module'] == $seed->module_dir && ((empty($_REQUEST['query']) || $_REQUEST['query'] == 'MSI')&& (empty($_SESSION['last_search_mod']) || $_SESSION['last_search_mod'] != $seed->module_dir)))) {
112             $_SESSION['last_search_mod'] = $_REQUEST['module'] ;
113             return;
114         }
115     }
116     if(strcmp(strtolower($_REQUEST['action']), 'popup') != 0){
117         $_SESSION['last_search_mod'] = $_REQUEST['module'] ;
118     }
119     //following session variable will track the detail view navigation history.
120     //needs to the reset after each search.
121     $this->setLocalSessionVariable($html_varName,"DETAIL_NAV_HISTORY",false);
122
123     require_once('include/MassUpdate.php');
124     $mass = new MassUpdate();
125     $add_acl_javascript = false;
126     if(!isset($_REQUEST['action'])) {
127         $this->shouldProcess=false;
128     } else {
129     $this->shouldProcess = is_subclass_of($seed, "SugarBean")
130         && (($_REQUEST['action'] == 'index') || ('ListView' == substr($_REQUEST['action'],0,8)) /* cn: to include all ListViewXXX.php type views */)
131         && ($_REQUEST['module'] == $seed->module_dir);
132     }
133
134     //when processing a multi-select popup.
135     if($this->process_for_popups && $this->multi_select_popup)  $this->shouldProcess =true;
136     //mass update turned off?
137     if(!$this->show_mass_update) $this->shouldProcess = false;
138     if(is_subclass_of($seed, "SugarBean")) {
139         if($seed->bean_implements('ACL')) {
140             if(!ACLController::checkAccess($seed->module_dir,'list',true)) {
141                 if($_REQUEST['module'] != 'Home') {
142                     ACLController::displayNoAccess();
143                 }
144                 return;
145             }
146             if(!ACLController::checkAccess($seed->module_dir,'export',true)) {
147                 $sugar_config['disable_export']= true;
148             }
149
150         }
151     }
152
153     //force mass update form if requested.
154     if($this->force_mass_update) {
155         $this->shouldProcess = true;
156     }
157
158     if($this->shouldProcess) {
159         echo $mass->getDisplayMassUpdateForm(true, $this->multi_select_popup);
160         echo $mass->getMassUpdateFormHeader($this->multi_select_popup);
161         $mass->setSugarBean($seed);
162
163         //C.L. Fix for 10048, do not process handleMassUpdate for multi select popups
164         if(!$this->multi_select_popup) {
165             $mass->handleMassUpdate();
166         }
167     }
168
169     $this->processListViewTwo($seed,$xTemplateSection, $html_varName);
170
171     if($this->shouldProcess && empty($this->process_for_popups)) {
172         //echo "<a href='javascript:sListView.clear_all(document.MassUpdate, \"mass[]\");'>".translate('LBL_CLEARALL')."</a>";
173         // cn: preserves current functionality, exception is InboundEmail
174         if($this->show_mass_update_form) {
175             echo $mass->getMassUpdateForm();
176         }
177         if(!$this->keep_mass_update_form_open) {
178             echo $mass->endMassUpdateForm();
179         }
180     }
181 }
182
183
184 function process_dynamic_listview($source_module, $sugarbean,$subpanel_def)
185 {
186         $this->source_module = $source_module;
187         $this->subpanel_module = $subpanel_def->name;
188         if(!isset($this->xTemplate))
189             $this->createXTemplate();
190
191         $html_var = $this->subpanel_module . "_CELL";
192
193         $list_data = $this->processUnionBeans($sugarbean,$subpanel_def, $html_var);
194
195         $list = $list_data['list'];
196         $parent_data = $list_data['parent_data'];
197
198         if($subpanel_def->isCollection()) {
199             $thepanel=$subpanel_def->get_header_panel_def();
200         } else {
201             $thepanel=$subpanel_def;
202         }
203
204
205
206         $this->process_dynamic_listview_header($thepanel->get_module_name(), $thepanel, $html_var);
207         $this->process_dynamic_listview_rows($list,$parent_data, 'dyn_list_view', $html_var,$subpanel_def);
208
209         if($this->display_header_and_footer)
210         {
211             $this->getAdditionalHeader();
212             if(!empty($this->header_title))
213             {
214                 echo get_form_header($this->header_title, $this->header_text, false);
215             }
216         }
217
218         $this->xTemplate->out('dyn_list_view');
219
220         if(isset($_SESSION['validation']))
221         {
222             print base64_decode('PGEgaHJlZj0naHR0cDovL3d3dy5zdWdhcmNybS5jb20nPlBPV0VSRUQmbmJzcDtCWSZuYnNwO1NVR0FSQ1JNPC9hPg==');
223         }
224         if(isset($list_data['query'])) {
225             return ($list_data['query']);
226         }
227     }
228
229 /**
230  * @return void
231  * @param unknown $data
232  * @param unknown $xTemplateSection
233  * @param unknown $html_varName
234  * @desc INTERNAL FUNCTION handles the rows
235  */
236  function process_dynamic_listview_rows($data,$parent_data, $xtemplateSection, $html_varName, $subpanel_def)
237  {
238     global $subpanel_item_count;
239     global $odd_bg;
240     global $even_bg;
241     global $hilite_bg;
242     global $click_bg;
243
244     $this->xTemplate->assign("BG_HILITE", $hilite_bg);
245     $this->xTemplate->assign('CHECKALL', SugarThemeRegistry::current()->getImage('blank', '', 1, 1, ".gif", ''));
246     //$this->xTemplate->assign("BG_CLICK", $click_bg);
247     $subpanel_item_count = 0;
248     $oddRow = true;
249     $count = 0;
250     reset($data);
251
252     //GETTING OFFSET
253     $offset = $this->getOffset($html_varName);
254     //$totaltime = 0;
255     $processed_ids = array();
256
257     $fill_additional_fields = array();
258     //Either retrieve the is_fill_in_additional_fields property from the lone
259     //subpanel or visit each subpanel's subpanels to retrieve the is_fill_in_addition_fields
260     //property
261     $subpanel_list=array();
262     if($subpanel_def->isCollection()) {
263         $subpanel_list=$subpanel_def->sub_subpanels;
264     } else {
265         $subpanel_list[]= $subpanel_def;
266     }
267
268     foreach($subpanel_list as $this_subpanel)
269     {
270         if($this_subpanel->is_fill_in_additional_fields())
271         {
272             $fill_additional_fields[] = $this_subpanel->bean_name;
273             $fill_additional_fields[$this_subpanel->bean_name] = true;
274         }
275     }
276
277     if ( empty($data) ) {
278         $this->xTemplate->assign("ROW_COLOR", 'oddListRow');
279         $thepanel=$subpanel_def;
280         if($subpanel_def->isCollection())
281             $thepanel=$subpanel_def->get_header_panel_def();
282         $this->xTemplate->assign("COL_COUNT", count($thepanel->get_list_fields()));
283         $this->xTemplate->parse($xtemplateSection.".nodata");
284     }
285
286     while(list($aVal, $aItem) = each($data))
287     {
288         $subpanel_item_count++;
289         $aItem->check_date_relationships_load();
290         // TODO: expensive and needs to be removed and done better elsewhere
291
292         if(!empty($fill_additional_fields[$aItem->object_name])
293         || ($aItem->object_name == 'Case' && !empty($fill_additional_fields['aCase']))
294         )
295         {
296             $aItem->fill_in_additional_list_fields();
297             //$aItem->fill_in_additional_detail_fields();
298         }
299         //rrs bug: 25343
300         $aItem->call_custom_logic("process_record");
301
302         if(isset($parent_data[$aItem->id])) {
303
304             $aItem->parent_name = $parent_data[$aItem->id]['parent_name'];
305             if(!empty($parent_data[$aItem->id]['parent_name_owner'])) {
306             $aItem->parent_name_owner =  $parent_data[$aItem->id]['parent_name_owner'];
307             $aItem->parent_name_mod =  $parent_data[$aItem->id]['parent_name_mod'];
308         }}
309
310         $fields = $aItem->get_list_view_data();
311         if(isset($processed_ids[$aItem->id])) {
312             continue;
313
314         } else {
315             $processed_ids[$aItem->id] = 1;
316         }
317
318
319         //ADD OFFSET TO ARRAY
320         $fields['OFFSET'] = ($offset + $count + 1);
321
322         if($this->shouldProcess) {
323             if($aItem->ACLAccess('EditView')) {
324             $this->xTemplate->assign('PREROW', "<input type='checkbox' class='checkbox' name='mass[]' value='". $fields['ID']. "' />");
325             } else {
326                 $this->xTemplate->assign('PREROW', '');
327
328             }
329             if($aItem->ACLAccess('DetailView')) {
330                 $this->xTemplate->assign('TAG_NAME','a');
331             } else {
332                 $this->xTemplate->assign('TAG_NAME','span');
333             }
334             $this->xTemplate->assign('CHECKALL', "<input type='checkbox'  title='".$GLOBALS['app_strings']['LBL_SELECT_ALL_TITLE']."' class='checkbox' name='massall' id='massall' value='' onclick='sListView.check_all(document.MassUpdate, \"mass[]\", this.checked);' />");
335         }
336
337         if($oddRow)
338         {
339             $ROW_COLOR = 'oddListRow';
340             $BG_COLOR =  $odd_bg;
341         }
342         else
343         {
344             $ROW_COLOR = 'evenListRow';
345             $BG_COLOR =  $even_bg;
346         }
347         $oddRow = !$oddRow;
348                 $button_contents = array();
349         $this->xTemplate->assign("ROW_COLOR", $ROW_COLOR);
350         $this->xTemplate->assign("BG_COLOR", $BG_COLOR);
351         $layout_manager = $this->getLayoutManager();
352         $layout_manager->setAttribute('context','List');
353         $layout_manager->setAttribute('image_path',$this->local_image_path);
354         $layout_manager->setAttribute('module_name', $subpanel_def->_instance_properties['module']);
355         if(!empty($this->child_focus))
356             $layout_manager->setAttribute('related_module_name',$this->child_focus->module_dir);
357
358         //AG$subpanel_data = $this->list_field_defs;
359         //$bla = array_pop($subpanel_data);
360         //select which sub-panel to display here, the decision will be made based on the type of
361         //the sub-panel and panel in the bean being processed.
362         if($subpanel_def->isCollection()) {
363             $thepanel=$subpanel_def->sub_subpanels[$aItem->panel_name];
364         } else {
365             $thepanel=$subpanel_def;
366         }
367         //get data source name
368         $linked_field=$thepanel->get_data_source_name();
369         $linked_field_set=$thepanel->get_data_source_name(true);
370         static $count;
371         if(!isset($count))$count = 0;
372
373         foreach($thepanel->get_list_fields() as $field_name=>$list_field)
374         {
375             //add linked field attribute to the array.
376             $list_field['linked_field']=$linked_field;
377             $list_field['linked_field_set']=$linked_field_set;
378
379             $usage = empty($list_field['usage']) ? '' : $list_field['usage'];
380             if($usage != 'query_only')
381             {
382                 $list_field['name']=$field_name;
383
384                 $module_field = $field_name.'_mod';
385                 $owner_field = $field_name.'_owner';
386                 if(!empty($aItem->$module_field)) {
387
388                     $list_field['owner_id'] = $aItem->$owner_field;
389                     $list_field['owner_module'] = $aItem->$module_field;
390
391                 } else {
392                     $list_field['owner_id'] = false;
393                     $list_field['owner_module'] = false;
394                 }
395                 if(isset($list_field['alias'])) $list_field['name'] = $list_field['alias'];
396                 else $list_field['name']=$field_name;
397                 $list_field['fields'] = $fields;
398                 $list_field['module'] = $aItem->module_dir;
399                 $list_field['start_link_wrapper'] = $this->start_link_wrapper;
400                 $list_field['end_link_wrapper'] = $this->end_link_wrapper;
401                 $list_field['subpanel_id'] = $this->subpanel_id;
402                 $list_field['DetailView'] = $aItem->ACLAccess('DetailView');
403                 $list_field['ListView'] = $aItem->ACLAccess('ListView');
404                 $list_field['EditView'] = $aItem->ACLAccess('EditView');
405                 $list_field['Delete'] = $aItem->ACLAccess('Delete');
406                 if ( isset($aItem->field_defs[strtolower($list_field['name'])])) {
407                     require_once('include/SugarFields/SugarFieldHandler.php');
408                     // We need to see if a sugar field exists for this field type first,
409                     // if it doesn't, toss it at the old sugarWidgets. This is for
410                     // backwards compatibility and will be removed in a future release
411                     $vardef = $aItem->field_defs[strtolower($list_field['name'])];
412                     if ( isset($vardef['type']) ) {
413                         $fieldType = isset($vardef['custom_type'])?$vardef['custom_type']:$vardef['type'];
414                         $tmpField = SugarFieldHandler::getSugarField($fieldType,true);
415                     } else {
416                         $tmpField = NULL;
417                     }
418
419                     if ( $tmpField != NULL ) {
420                         $widget_contents = SugarFieldHandler::displaySmarty($list_field['fields'],$vardef,'ListView',$list_field);
421                     } else {
422                         // No SugarField for this particular type
423                         // Use the old, icky, SugarWidget for now
424                         $widget_contents = $layout_manager->widgetDisplay($list_field);
425                     }
426
427                     if ( isset($list_field['widget_class']) && $list_field['widget_class'] == 'SubPanelDetailViewLink' ) {
428                         // We need to call into the old SugarWidgets for the time being, so it can generate a proper link with all the various corner-cases handled
429                         // So we'll populate the field data with the pre-rendered display for the field
430                         $list_field['fields'][$field_name] = $widget_contents;
431                         if('full_name' == $field_name){//bug #32465
432                            $list_field['fields'][strtoupper($field_name)] = $widget_contents;
433                         }
434                         $widget_contents = $layout_manager->widgetDisplay($list_field);
435                     } else if(isset($list_field['widget_class']) && $list_field['widget_class'] == 'SubPanelEmailLink' ) {
436                         $widget_contents = $layout_manager->widgetDisplay($list_field);
437                     }
438
439                  $count++;
440                 $this->xTemplate->assign('CELL_COUNT', $count);
441                 $this->xTemplate->assign('CLASS', "");
442                 if ( empty($widget_contents) ) $widget_contents = '&nbsp;';
443                 $this->xTemplate->assign('CELL', $widget_contents);
444                 $this->xTemplate->parse($xtemplateSection.".row.cell");
445                 } else {
446                     // This handles the edit and remove buttons and icon widget
447                         if( isset($list_field['widget_class']) && $list_field['widget_class'] == "SubPanelIcon") {
448                                 $count++;
449                                 $widget_contents = $layout_manager->widgetDisplay($list_field);
450                                 $this->xTemplate->assign('CELL_COUNT', $count);
451                                 $this->xTemplate->assign('CLASS', "");
452                                 if ( empty($widget_contents) ) $widget_contents = '&nbsp;';
453                                 $this->xTemplate->assign('CELL', $widget_contents);
454                                 $this->xTemplate->parse($xtemplateSection.".row.cell");
455                         } elseif (preg_match("/button/i", $list_field['name'])) {
456                                 if($layout_manager->widgetDisplay($list_field) != "")
457                                 $button_contents[] = $layout_manager->widgetDisplay($list_field);
458                         } else {
459                                 $count++;
460                                 $this->xTemplate->assign('CLASS', "");
461                                 $widget_contents = $layout_manager->widgetDisplay($list_field);
462                                 $this->xTemplate->assign('CELL_COUNT', $count);
463                                 if ( empty($widget_contents) ) $widget_contents = '&nbsp;';
464                                 $this->xTemplate->assign('CELL', $widget_contents);
465                                 $this->xTemplate->parse($xtemplateSection.".row.cell");
466                         }
467                 }
468
469             }
470         }
471
472
473         // Make sure we have at least one button before rendering a column for
474         // the action buttons in a list view. Relevant bugs: #51647 and #51640.
475         if(isset($button_contents[0])) {
476             // this is for inline buttons on listviews
477             // bug#51275: smarty widget to help provide the action menu functionality as it is currently sprinkled throughout the app with html
478             require_once('include/Smarty/plugins/function.sugar_action_menu.php');
479             $tempid = create_guid();
480             $button_contents[0] = "<div style='display: inline' id='$tempid'>".$button_contents[0]."</div>";
481             $action_button = smarty_function_sugar_action_menu(array(
482                 'id' => $tempid,
483                 'buttons' => $button_contents,
484                 'class' => 'clickMenu subpanel records fancymenu button',
485                 'theme' => 'Sugar' //assign theme value to display dropdown menu on class theme
486             ), $this->xTemplate);
487             $this->xTemplate->assign('CLASS', "inlineButtons");
488             $this->xTemplate->assign('CELL_COUNT', ++$count);
489             //Bug#51275 for beta3 pre_script is not required any more
490             $this->xTemplate->assign('CELL', $action_button);
491             $this->xTemplate->parse($xtemplateSection.".row.cell");
492         }
493
494
495         $aItem->setupCustomFields($aItem->module_dir);
496         $aItem->custom_fields->populateAllXTPL($this->xTemplate, 'detail', $html_varName, $fields);
497
498         $count++;
499
500         $this->xTemplate->parse($xtemplateSection.".row");
501     }
502
503     $this->xTemplate->parse($xtemplateSection);
504 }
505
506 /**sets whether or not to display the xtemplate header and footer
507  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
508  * All Rights Reserved.
509  * Contributor(s): ______________________________________.
510 */
511 function setDisplayHeaderAndFooter($bool) {
512         $this->display_header_and_footer = $bool;
513 }
514
515 /**initializes ListView
516  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
517  * All Rights Reserved.
518  * Contributor(s): ______________________________________.
519 */
520  function ListView() {
521
522
523     if(!$this->initialized) {
524         global $sugar_config;
525         $this->records_per_page = $sugar_config['list_max_entries_per_page'] + 0;
526         $this->initialized = true;
527         global $app_strings, $currentModule;
528         $this->local_theme = SugarThemeRegistry::current()->__toString();
529         $this->local_app_strings =$app_strings;
530         $this->local_image_path = SugarThemeRegistry::current()->getImagePath();
531         $this->local_current_module = $currentModule;
532     }
533 }
534 /**sets how many records should be displayed per page in the list view
535  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
536  * All Rights Reserved.
537  * Contributor(s): ______________________________________.
538 */
539  function setRecordsPerPage($count) {
540     $this->records_per_page = $count;
541 }
542 /**sets the header title */
543  function setHeaderTitle($value) {
544     $this->header_title = $value;
545 }
546 /**sets the header text this is text that's appended to the header table and is usually used for the creation of buttons
547  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
548  * All Rights Reserved.
549  * Contributor(s): ______________________________________.
550 */
551  function setHeaderText($value) {
552     $this->header_text = $value;
553 }
554 /**sets the path for the XTemplate HTML file to be used this is only needed to be set if you are allowing ListView to create the XTemplate
555  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
556  * All Rights Reserved.
557  * Contributor(s): ______________________________________.
558 */
559  function setXTemplatePath($value) {
560     $this->xTemplatePath= $value;
561 }
562
563 /**this is a helper function for allowing ListView to create a new XTemplate it groups parameters that should be set into a single function
564  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
565  * All Rights Reserved.
566  * Contributor(s): ______________________________________.
567 */
568  function initNewXTemplate($XTemplatePath, $modString, $imagePath = null) {
569     $this->setXTemplatePath($XTemplatePath);
570     if(isset($modString))
571         $this->setModStrings($modString);
572     if(isset($imagePath))
573         $this->setImagePath($imagePath);
574 }
575
576
577 function getOrderBy($varName, $defaultOrderBy='', $force_sortorder='') {
578     $sortBy = $this->getSessionVariable($varName, "ORDER_BY") ;
579
580     $orderByDirection = $this->getSessionVariableName($varName, "order_by_direction");
581     $orderByColumn = $this->getSessionVariableName($varName, "ORDER_BY");
582     $lastEqualsSortBy = false;
583     $defaultOrder = false; //ascending
584
585     if(empty($sortBy)) {
586         $this->setUserVariable($varName, "ORDER_BY", $defaultOrderBy);
587         $sortBy = $defaultOrderBy;
588     } else {
589         $this->setUserVariable($varName, "ORDER_BY", $sortBy);
590     }
591     if($sortBy == 'amount') {
592         $sortBy = 'amount*1';
593     }
594     if($sortBy == 'amount_usdollar') {
595         $sortBy = 'amount_usdollar*1';
596     }
597
598     $desc = $this->getSessionVariable($varName, $sortBy."S");
599
600     if (empty($desc))
601         {
602             $desc = $defaultOrder;
603         }
604         $defaultOrder = $desc ? 'desc' : 'asc';
605         $orderByValue = $defaultOrder;
606         if (isset($_REQUEST[$orderByDirection]))
607         {
608             $possibleRequestOrderBy = $_REQUEST[$orderByDirection];
609             if ($possibleRequestOrderBy == 'asc' || $possibleRequestOrderBy == 'desc')
610             {
611                 $orderByValue = $possibleRequestOrderBy;
612             }
613         }
614
615         if (isset($_REQUEST[$orderByColumn]))
616         {
617             $last = $this->getSessionVariable($varName, "OBL");
618         }
619         if (!empty($last) && $last == $sortBy)
620         {
621             $lastEqualsSortBy = true;
622         } else
623         {
624             $orderByValue = $defaultOrder;
625             $this->setSessionVariable($varName, "OBL", $sortBy);
626         }
627         $desc = $orderByValue == 'desc';
628         $orderByDirectionValue = false;
629         $this->setSessionVariable($varName, $sortBy . "S", $desc);
630         if (!empty($sortBy))
631         {
632             if (empty($force_sortorder))
633             {
634                 if (substr_count(strtolower($sortBy), ' desc') == 0 && substr_count(strtolower($sortBy), ' asc') == 0)
635                 {
636                     if ($sortBy)
637                     {
638                         $orderByDirectionValue = $desc ? 'asc' : 'desc';
639                     }
640                     $this->query_orderby = $sortBy . ' ' . $orderByValue;
641                 }
642             } else
643             {
644                 $this->query_orderby = $sortBy . ' ' . $force_sortorder;
645             }
646             if (!isset($this->appendToBaseUrl))
647             {
648                 $this->appendToBaseUrl = array();
649             }
650             if ($orderByDirectionValue)
651             {
652                 $this->appendToBaseUrl[$orderByDirection] = $orderByDirectionValue;
653             }
654             $offsetVar = $this->getSessionVariableName($varName, "offset");
655             if (isset($_REQUEST[$offsetVar]))
656             {
657                 $this->appendToBaseUrl[$offsetVar] = $_REQUEST[$offsetVar];
658             }
659             //Just clear from url...
660             $this->appendToBaseUrl[$orderByColumn] = false;
661     }else {
662         $this->query_orderby = "";
663     }
664     $this->sortby = $sortBy;
665     return $this->query_orderby;
666
667 }
668
669
670 /**sets the parameters dealing with the db
671  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
672  * All Rights Reserved.
673  * Contributor(s): ______________________________________.
674 */
675  function setQuery($where, $limit, $orderBy, $varName, $allowOrderByOveride=true) {
676     $this->query_where = $where;
677     if($this->getSessionVariable("query", "where") != $where) {
678         $this->query_where_has_changed = true;
679         $this->setSessionVariable("query", "where", $where);
680     }
681
682     $this->query_limit = $limit;
683     if(!$allowOrderByOveride) {
684         $this->query_orderby = $orderBy;
685         return;
686     }
687     $this->getOrderBy($varName, $orderBy);
688
689     $this->setLocalSessionVariable($varName, "QUERY_WHERE", $where);
690
691     //SETTING ORDER_BY FOR USE IN DETAILVIEW
692     $this->setLocalSessionVariable($varName, "ORDER_BY_DETAIL", $this->query_orderby);
693 }
694
695 function displayArrow() {
696
697 }
698
699 /**sets the theme used only use if it is different from the global
700  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
701  * All Rights Reserved.
702  * Contributor(s): ______________________________________.
703 */
704  function setTheme($theme) {
705     $this->local_theme = $theme;
706     if(isset($this->xTemplate))$this->xTemplate->assign("THEME", $this->local_theme);
707 }
708
709 /**sets the AppStrings used only use if it is different from the global
710  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
711  * All Rights Reserved.
712  * Contributor(s): ______________________________________.
713 */
714  function setAppStrings($app_strings) {
715     unset($this->local_app_strings);
716     $this->local_app_strings = $app_strings;
717     if(isset($this->xTemplate))$this->xTemplate->assign("APP", $this->local_app_strings);
718 }
719
720 /**sets the ModStrings used
721  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
722  * All Rights Reserved.
723  * Contributor(s): ______________________________________.
724 */
725  function setModStrings($mod_strings) {
726     unset($this->local_module_strings);
727     $this->local_mod_strings = $mod_strings;
728     if(isset($this->xTemplate))$this->xTemplate->assign("MOD", $this->local_mod_strings);
729 }
730
731 /**sets the ImagePath used
732  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
733  * All Rights Reserved.
734  * Contributor(s): ______________________________________.
735 */
736  function setImagePath($image_path) {
737     $this->local_image_path = $image_path;
738     if(empty($this->local_image_path)) {
739         $this->local_image_path = SugarThemeRegistry::get($this->local_theme)->getImagePath();
740     }
741     if(isset($this->xTemplate))$this->xTemplate->assign("IMAGE_PATH", $this->local_image_path);
742 }
743
744 /**sets the currentModule only use if this is different from the global
745  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
746  * All Rights Reserved.
747  * Contributor(s): ______________________________________.
748 */
749  function setCurrentModule($currentModule) {
750     unset($this->local_current_module);
751     $this->local_current_module = $currentModule;
752     if(isset($this->xTemplate))$this->xTemplate->assign("MODULE_NAME", $this->local_current_module);
753 }
754
755 /**INTERNAL FUNCTION creates an XTemplate DO NOT CALL THIS THIS IS AN INTERNAL FUNCTION
756  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
757  * All Rights Reserved.
758  * Contributor(s): ______________________________________.
759 */
760  function createXTemplate() {
761     if(!isset($this->xTemplate)) {
762         if(isset($this->xTemplatePath)) {
763
764             $this->xTemplate = new XTemplate($this->xTemplatePath);
765             $this->xTemplate->assign("APP", $this->local_app_strings);
766             if(isset($this->local_mod_strings))$this->xTemplate->assign("MOD", $this->local_mod_strings);
767             $this->xTemplate->assign("THEME", $this->local_theme);
768             $this->xTemplate->assign("IMAGE_PATH", $this->local_image_path);
769             $this->xTemplate->assign("MODULE_NAME", $this->local_current_module);
770         } else {
771             $GLOBALS['log']->error("NO XTEMPLATEPATH DEFINED CANNOT CREATE XTEMPLATE");
772         }
773     }
774 }
775
776 /**sets the XTemplate telling ListView to use newXTemplate as its current XTemplate
777  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
778  * All Rights Reserved.
779  * Contributor(s): ______________________________________.
780 */
781  function setXTemplate($newXTemplate) {
782     $this->xTemplate = $newXTemplate;
783 }
784
785 /**returns the XTemplate
786  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
787  * All Rights Reserved.
788  * Contributor(s): ______________________________________.
789 */
790  function getXTemplate() {
791     return $this->xTemplate;
792 }
793
794 /**assigns a name value pair to the XTemplate
795  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
796  * All Rights Reserved.
797  * Contributor(s): ______________________________________.
798 */
799  function xTemplateAssign($name, $value) {
800
801         if(!isset($this->xTemplate)) {
802             $this->createXTemplate();
803         }
804         $this->xTemplate->assign($name, $value);
805
806 }
807
808 /**INTERNAL FUNCTION returns the offset first checking the query then checking the session if the where clause has changed from the last time it returns 0
809  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
810  * All Rights Reserved.
811  * Contributor(s): ______________________________________.
812 */
813  function getOffset($localVarName) {
814         if($this->query_where_has_changed || isset($GLOBALS['record_has_changed'])) {
815                 $this->setSessionVariable($localVarName,"offset", 0);
816         }
817         $offset = $this->getSessionVariable($localVarName,"offset");
818         if(isset($offset)) {
819                 return $offset;
820         }
821         return 0;
822 }
823
824 /**INTERNAL FUNCTION sets the offset in the session
825  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
826  * All Rights Reserved.
827  * Contributor(s): ______________________________________.
828 */
829  function setOffset($localVarName, $value) {
830         $this->setSessionVariable($localVarName, "offset", $value);
831 }
832
833 /**INTERNAL FUNCTION sets a session variable
834  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
835  * All Rights Reserved.
836  * Contributor(s): ______________________________________.
837 */
838  function setSessionVariable($localVarName,$varName, $value) {
839     $_SESSION[$this->local_current_module."_".$localVarName."_".$varName] = $value;
840 }
841
842 function setUserVariable($localVarName,$varName, $value) {
843         if($this->is_dynamic ||  $localVarName == 'CELL')return;
844         global $current_user;
845         $current_user->setPreference($this->local_current_module."_".$localVarName."_".$varName, $value);
846 }
847
848 /**INTERNAL FUNCTION returns a session variable first checking the query for it then checking the session
849  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
850  * All Rights Reserved.
851  * Contributor(s): ______________________________________.
852 */
853  function getSessionVariable($localVarName,$varName) {
854     //Set any variables pass in through request first
855     if(isset($_REQUEST[$this->getSessionVariableName($localVarName, $varName)])) {
856         $this->setSessionVariable($localVarName,$varName,$_REQUEST[$this->getSessionVariableName($localVarName, $varName)]);
857     }
858
859     if(isset($_SESSION[$this->getSessionVariableName($localVarName, $varName)])) {
860         return $_SESSION[$this->getSessionVariableName($localVarName, $varName)];
861     }
862     return "";
863 }
864
865 function getUserVariable($localVarName, $varName) {
866     global $current_user;
867     if($this->is_dynamic ||  $localVarName == 'CELL')return;
868     if(isset($_REQUEST[$this->getSessionVariableName($localVarName, $varName)])) {
869
870             $this->setUserVariable($localVarName,$varName,$_REQUEST[$this->getSessionVariableName($localVarName, $varName)]);
871     }
872     return $current_user->getPreference($this->getSessionVariableName($localVarName, $varName));
873 }
874
875
876     /**
877      * helper method to determine sort order by priority of source
878      * 1. explicit in request object
879      * 2. in session variable
880      * 3. subpaneldefs metadata
881      * 4. default 'asc'
882      * @param array $sortOrderList - contains options
883      * @return string 'asc' | 'desc'
884      */
885     function calculateSortOrder($sortOrderList)
886     {
887         $priority_map = array(
888           'request',
889           'session',
890           'subpaneldefs',
891           'default',
892         );
893
894         foreach($priority_map as $p) {
895             if (key_exists($p, $sortOrderList)) {
896                 $order = strtolower($sortOrderList[$p]);
897                 if (in_array($order, array('asc', 'desc'))) {
898                     return $order;
899                 }
900             }
901         }
902         return 'asc';
903     }
904
905
906     /**
907
908     * @return void
909     * @param unknown $localVarName
910     * @param unknown $varName
911     * @desc INTERNAL FUNCTION returns the session/query variable name
912     * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
913     * All Rights Reserved.
914     * Contributor(s): ______________________________________..
915     */
916     function getSessionVariableName($localVarName,$varName) {
917         return $this->local_current_module."_".$localVarName."_".$varName;
918     }
919
920     /**
921
922     * @return void
923     * @param unknown $seed
924     * @param unknown $xTemplateSection
925     * @param unknown $html_varName
926     * @desc INTERNAL FUNCTION Handles List Views using seeds that extend SugarBean
927         $XTemplateSection is the section in the XTemplate file that should be parsed usually main
928         $html_VarName is the variable name used in the XTemplateFile e.g. TASK
929         $seed is a seed that extends SugarBean
930         * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc..
931         * All Rights Reserved..
932         * Contributor(s): ______________________________________..
933     */
934     function processSugarBean($xtemplateSection, $html_varName, $seed) {
935         global $list_view_row_count;
936
937         $current_offset = $this->getOffset($html_varName);
938         $response = array();
939
940         //ADDING VCR CONTROL
941         SugarVCR::erase($seed->module_dir);
942         $params = array();
943         //$filter = array('id', 'full_name');
944         $filter=array();
945         $ret_array = $seed->create_new_list_query($this->query_orderby, $this->query_where, $filter, $params, 0, '', true, $seed, true);
946         if(!is_array($params)) $params = array();
947         if(!isset($params['custom_select'])) $params['custom_select'] = '';
948         if(!isset($params['custom_from'])) $params['custom_from'] = '';
949         if(!isset($params['custom_where'])) $params['custom_where'] = '';
950         if(!isset($params['custom_order_by'])) $params['custom_order_by'] = '';
951         $main_query = $ret_array['select'] . $params['custom_select'] . $ret_array['from'] . $params['custom_from'] . $ret_array['where'] . $params['custom_where'] . $ret_array['order_by'] . $params['custom_order_by'];
952         SugarVCR::store($seed->module_dir,  $main_query);
953         //ADDING VCR CONTROL
954
955         if(empty($this->related_field_name)) {
956             $response = $seed->get_list($this->query_orderby, $this->query_where, $current_offset, $this->query_limit);
957         } else {
958             $related_field_name = $this->related_field_name;
959             $response = $seed->get_related_list($this->child_focus,$related_field_name, $this->query_orderby,
960             $this->query_where, $current_offset, $this->query_limit);
961         }
962
963         $list = $response['list'];
964         $row_count = $response['row_count'];
965         $next_offset = $response['next_offset'];
966         $previous_offset = $response['previous_offset'];
967
968         if(!empty($response['current_offset'])) {
969             $current_offset = $response['current_offset'];
970         }
971
972         $list_view_row_count = $row_count;
973         $this->processListNavigation($xtemplateSection,$html_varName, $current_offset, $next_offset, $previous_offset, $row_count, null, null, empty($seed->column_fields) ? null : count($seed->column_fields));
974
975         return $list;
976     }
977
978
979
980     function processUnionBeans($sugarbean, $subpanel_def, $html_var = 'CELL') {
981
982                 $last_detailview_record = $this->getSessionVariable("detailview", "record");
983                 if(!empty($last_detailview_record) && $last_detailview_record != $sugarbean->id){
984                         $GLOBALS['record_has_changed'] = true;
985                 }
986                 $this->setSessionVariable("detailview", "record", $sugarbean->id);
987
988                 $current_offset = $this->getOffset($html_var);
989                 $module = isset($_REQUEST['module']) ? $_REQUEST['module'] : '';
990                 $response = array();
991
992         // choose sort order
993         $sort_order = array();
994         $sort_order['default'] = 'asc';
995
996         // explicit request parameter gets priority over all
997         $sort_order['request'] = isset($_REQUEST['sort_order']) ? $_REQUEST['sort_order'] : null;
998
999         // see if the session data has a sort order
1000         if (isset($_SESSION['last_sub' . $this->subpanel_module . '_order']))
1001         {
1002             $sort_order['session'] = $_SESSION['last_sub' . $this->subpanel_module . '_order'];
1003
1004             // We swap the order when the request contains an offset (indicating a column sort issued);
1005             // otherwise we do not sort.  If we don't make this check, then the subpanel listview will
1006             // swap ordering each time a new record is entered via quick create forms
1007             if (isset($_REQUEST[$module . '_' . $html_var . '_offset']))
1008             {
1009                 $sort_order['session'] = $sort_order['session'] == 'asc' ? 'desc' : 'asc';
1010             }
1011         }
1012         else
1013         {
1014             $sort_order['session'] = null;
1015         }
1016
1017         // does the metadata have a default sort order?
1018         $sort_order['subpaneldefs'] = isset($subpanel_def->_instance_properties['sort_order']) ?
1019             $subpanel_def->_instance_properties['sort_order'] : null;
1020
1021         $this->sort_order = $this->calculateSortOrder($sort_order);
1022
1023
1024         if (isset($subpanel_def->_instance_properties['sort_by'])) {
1025             $this->query_orderby = $subpanel_def->_instance_properties['sort_by'];
1026         } else {
1027             $this->query_orderby = 'id';
1028         }
1029
1030         $this->getOrderBy($html_var,$this->query_orderby, $this->sort_order);
1031
1032         $_SESSION['last_sub' .$this->subpanel_module. '_order'] = $this->sort_order;
1033         $_SESSION['last_sub' .$this->subpanel_module. '_url'] = $this->getBaseURL($html_var);
1034
1035                 // Bug 8139 - Correct Subpanel sorting on 'name', when subpanel sorting default is 'last_name, first_name'
1036                 if (($this->sortby == 'name' || $this->sortby == 'last_name') &&
1037                         str_replace(' ', '', trim($subpanel_def->_instance_properties['sort_by'])) == 'last_name,first_name') {
1038                         $this->sortby = 'last_name '.$this->sort_order.', first_name ';
1039                 }
1040
1041         if(!empty($this->response)){
1042             $response =& $this->response;
1043             echo 'cached';
1044         }else{
1045             $response = SugarBean::get_union_related_list($sugarbean,$this->sortby, $this->sort_order, $this->query_where, $current_offset, -1,-1,$this->query_limit,$subpanel_def);
1046             $this->response =& $response;
1047         }
1048         $list = $response['list'];
1049         $row_count = $response['row_count'];
1050         $next_offset = $response['next_offset'];
1051         $previous_offset = $response['previous_offset'];
1052         if(!empty($response['current_offset']))$current_offset = $response['current_offset'];
1053         global $list_view_row_count;
1054         $list_view_row_count = $row_count;
1055         $this->processListNavigation('dyn_list_view', $html_var, $current_offset, $next_offset, $previous_offset, $row_count, $sugarbean,$subpanel_def);
1056
1057         return array('list'=>$list, 'parent_data'=>$response['parent_data'], 'query'=>$response['query']);
1058     }
1059
1060     function getBaseURL($html_varName) {
1061         static $cache = array();
1062
1063         if(!empty($cache[$html_varName]))return $cache[$html_varName];
1064         $blockVariables = array('mass', 'uid', 'massupdate', 'delete', 'merge', 'selectCount','current_query_by_page');
1065         if(!empty($this->base_URL)) {
1066             return $this->base_URL;
1067         }
1068
1069             $baseurl = $_SERVER['PHP_SELF'];
1070             if(empty($baseurl)) {
1071                 $baseurl = 'index.php';
1072             }
1073
1074             /*fixes an issue with deletes when doing a search*/
1075             foreach(array_merge($_GET, $_POST) as $name=>$value) {
1076                 //echo ("$name = $value <br/>");
1077                 if(!empty($value) && $name != 'sort_order' //&& $name != ListView::getSessionVariableName($html_varName,"ORDER_BY")
1078                         && $name != ListView::getSessionVariableName($html_varName,"offset")
1079                         /*&& substr_count($name, "ORDER_BY")==0*/ && !in_array($name, $blockVariables))
1080                 {
1081                     if(is_array($value)) {
1082                         foreach($value as $valuename=>$valuevalue) {
1083                             if(substr_count($baseurl, '?') > 0)
1084                                 $baseurl        .= "&{$name}[]=".$valuevalue;
1085                             else
1086                                 $baseurl        .= "?{$name}[]=".$valuevalue;
1087                         }
1088                     } else {
1089                         $value = urlencode($value);
1090                         if(substr_count($baseurl, '?') > 0) {
1091                             $baseurl    .= "&$name=$value";
1092                         } else {
1093                             $baseurl    .= "?$name=$value";
1094                         }
1095                     }
1096                 }
1097             }
1098
1099
1100             if($_SERVER['REQUEST_METHOD'] == 'POST') {
1101                 // at this point it is possible that the above foreach already executed resulting in double ?'s in the url
1102                 if(substr_count($baseurl, '?') == 0) {
1103                     $baseurl .= '?';
1104                 }
1105                 if(isset($_REQUEST['action'])) $baseurl.= '&action='.$_REQUEST['action'];
1106                 if(isset($_REQUEST['record'])) $baseurl .= '&record='.$_REQUEST['record'];
1107                 if(isset($_REQUEST['module'])) $baseurl .= '&module='.$_REQUEST['module'];
1108             }
1109
1110             $baseurl .= "&".ListView::getSessionVariableName($html_varName,"offset")."=";
1111             $cache[$html_varName] = $baseurl;
1112             return $baseurl;
1113     }
1114     /**
1115     * @return void
1116     * @param unknown $data
1117     * @param unknown $xTemplateSection
1118     * @param unknown $html_varName
1119     * @desc INTERNAL FUNCTION process the List Navigation
1120     * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
1121     * All Rights Reserved.
1122     * Contributor(s): ______________________________________..
1123     */
1124     function processListNavigation($xtemplateSection, $html_varName, $current_offset, $next_offset, $previous_offset, $row_count, $sugarbean=null, $subpanel_def=null, $col_count = 20) {
1125
1126         global $export_module;
1127         global $sugar_config;
1128         global $current_user;
1129         global $currentModule;
1130         global $app_strings;
1131
1132         $start_record = $current_offset + 1;
1133
1134         if(!is_numeric($col_count))
1135             $col_count = 20;
1136
1137         if($row_count == 0)
1138             $start_record = 0;
1139
1140         $end_record = $start_record + $this->records_per_page;
1141         // back up the the last page.
1142         if($end_record > $row_count+1) {
1143             $end_record = $row_count+1;
1144         }
1145         // Determine the start location of the last page
1146         if($row_count == 0)
1147             $number_pages = 0;
1148         else
1149             $number_pages = floor(($row_count - 1) / $this->records_per_page);
1150
1151         $last_offset = $number_pages * $this->records_per_page;
1152
1153         if(empty($this->query_limit)  || $this->query_limit > $this->records_per_page) {
1154             $this->base_URL = $this->getBaseURL($html_varName);
1155             $dynamic_url = '';
1156
1157             if($this->is_dynamic) {
1158                 $dynamic_url .='&'. $this->getSessionVariableName($html_varName,'ORDER_BY') . '='. $this->getSessionVariable($html_varName,'ORDER_BY').'&sort_order='.$this->sort_order.'&to_pdf=true&action=SubPanelViewer&subpanel=' . $this->subpanel_module;
1159             }
1160
1161             $current_URL = htmlentities($this->base_URL.$current_offset.$dynamic_url);
1162             $start_URL = htmlentities($this->base_URL."0".$dynamic_url);
1163             $previous_URL  = htmlentities($this->base_URL.$previous_offset.$dynamic_url);
1164             $next_URL  = htmlentities($this->base_URL.$next_offset.$dynamic_url);
1165             $end_URL  = htmlentities($this->base_URL.'end'.$dynamic_url);
1166
1167             if(!empty($this->start_link_wrapper)) {
1168                 $current_URL = $this->start_link_wrapper.$current_URL.$this->end_link_wrapper;
1169                 $start_URL = $this->start_link_wrapper.$start_URL.$this->end_link_wrapper;
1170                 $previous_URL = $this->start_link_wrapper.$previous_URL.$this->end_link_wrapper;
1171                 $next_URL = $this->start_link_wrapper.$next_URL.$this->end_link_wrapper;
1172                 $end_URL = $this->start_link_wrapper.$end_URL.$this->end_link_wrapper;
1173             }
1174
1175             $moduleString = "{$currentModule}_{$html_varName}_offset";
1176             $moduleStringOrder = "{$currentModule}_{$html_varName}_ORDER_BY";
1177             if($this->shouldProcess && !$this->multi_select_popup) {
1178                 // check the checkboxes onload
1179                 echo "<script>YAHOO.util.Event.addListener(window, \"load\", sListView.check_boxes);</script>\n";
1180
1181                 $massUpdateRun = isset($_REQUEST['massupdate']) && $_REQUEST['massupdate'] == 'true';
1182                 $uids = empty($_REQUEST['uid']) || $massUpdateRun ? '' : $_REQUEST['uid'];
1183                 $select_entire_list = isset($_REQUEST['select_entire_list']) && !$massUpdateRun ? $_REQUEST['select_entire_list'] : 0;
1184
1185                 echo "<textarea style='display: none' name='uid'>{$uids}</textarea>\n" .
1186                     "<input type='hidden' name='select_entire_list' value='{$select_entire_list}'>\n".
1187                     "<input type='hidden' name='{$moduleString}' value='0'>\n".
1188                     "<input type='hidden' name='{$moduleStringOrder}' value='0'>\n";
1189
1190             }
1191
1192
1193             $GLOBALS['log']->debug("Offsets: (start, previous, next, last)(0, $previous_offset, $next_offset, $last_offset)");
1194
1195             if(0 == $current_offset) {
1196                 $start_link = "<button type='button' name='listViewStartButton' title='{$this->local_app_strings['LNK_LIST_START']}' class='button' disabled>".SugarThemeRegistry::current()->getImage("start_off","aborder='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_START'])."</button>";
1197                 $previous_link = "<button type='button' name='listViewPrevButton' title='{$this->local_app_strings['LNK_LIST_PREVIOUS']}' class='button' disabled>".SugarThemeRegistry::current()->getImage("previous_off","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_PREVIOUS'])."</button>";
1198             } else {
1199                 if($this->multi_select_popup) {// nav links for multiselect popup, submit form to save checks.
1200                     $start_link = "<button type='button' class='button' name='listViewStartButton' title='{$this->local_app_strings['LNK_LIST_START']}' onClick='javascript:save_checks(0, \"{$moduleString}\");'>".SugarThemeRegistry::current()->getImage("start","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_START'])."</button>";
1201                     $previous_link = "<button type='button' class='button' name='listViewPrevButton' title='{$this->local_app_strings['LNK_LIST_PREVIOUS']}' onClick='javascript:save_checks($previous_offset, \"{$moduleString}\");'>".SugarThemeRegistry::current()->getImage("previous","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_PREVIOUS'])."</button>";
1202                 } elseif($this->shouldProcess) {
1203                     $start_link = "<button type='button' class='button' name='listViewStartButton' title='{$this->local_app_strings['LNK_LIST_START']}' onClick='location.href=\"$start_URL\"; sListView.save_checks(0, \"{$moduleString}\");'>".SugarThemeRegistry::current()->getImage("start","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_START'])."</button>";
1204                     $previous_link = "<button type='button' class='button' name='listViewPrevButton' title='{$this->local_app_strings['LNK_LIST_PREVIOUS']}' onClick='location.href=\"$previous_URL\"; sListView.save_checks($previous_offset, \"{$moduleString}\");'>".SugarThemeRegistry::current()->getImage("previous","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_PREVIOUS'])."</button>";
1205                 } else {
1206                     $onClick = '';
1207                     if(0 != preg_match('/javascript.*/', $start_URL)){
1208                         $onClick = "\"$start_URL;\"";
1209                     }else{
1210                         $onClick ="'location.href=\"$start_URL\";'";
1211                     }
1212                     $start_link = "<button type='button' class='button' name='listViewStartButton' title='{$this->local_app_strings['LNK_LIST_START']}' onClick=".$onClick.">".SugarThemeRegistry::current()->getImage("start","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_START'])."</button>";
1213
1214                     $onClick = '';
1215                     if(0 != preg_match('/javascript.*/', $previous_URL)){
1216                         $onClick = "\"$previous_URL;\"";
1217                     }else{
1218                         $onClick = "'location.href=\"$previous_URL\";'";
1219                     }
1220                     $previous_link = "<button type='button' class='button' name='listViewPrevButton' title='{$this->local_app_strings['LNK_LIST_PREVIOUS']}' onClick=".$onClick.">".SugarThemeRegistry::current()->getImage("previous","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_PREVIOUS'])."</button>";
1221                 }
1222             }
1223
1224             if($last_offset <= $current_offset) {
1225                 $end_link = "<button type='button' name='listViewEndButton' title='{$this->local_app_strings['LNK_LIST_END']}' class='button' disabled>".SugarThemeRegistry::current()->getImage("end_off","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_END'])."</button>";
1226                 $next_link = "<button type='button' name='listViewNextButton' title='{$this->local_app_strings['LNK_LIST_NEXT']}' class='button' disabled>".SugarThemeRegistry::current()->getImage("next_off","aborder='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_NEXT'])."</button>";
1227             } else {
1228                 if($this->multi_select_popup) { // nav links for multiselect popup, submit form to save checks.
1229                     $end_link = "<button type='button' name='listViewEndButton' class='button' title='{$this->local_app_strings['LNK_LIST_END']}' onClick='javascript:save_checks($last_offset, \"{$moduleString}\");'>".SugarThemeRegistry::current()->getImage("end","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_END'])."</button>";
1230                     if(!empty($sugar_config['disable_count_query'])) {
1231                         $end_link = '';
1232                     }
1233                     $next_link = "<button type='button' name='listViewNextButton' title='{$this->local_app_strings['LNK_LIST_NEXT']}' class='button' onClick='javascript:save_checks($next_offset, \"{$moduleString}\");'>".SugarThemeRegistry::current()->getImage("next","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_NEXT'])."</button>";
1234                 } elseif($this->shouldProcess) {
1235                     $end_link = "<button type='button' name='listViewEndButton' class='button' title='{$this->local_app_strings['LNK_LIST_END']}' onClick='location.href=\"$end_URL\"; sListView.save_checks(\"end\", \"{$moduleString}\");'>".SugarThemeRegistry::current()->getImage("end","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_END'])."</button>";
1236                     $next_link = "<button type='button' name='listViewNextButton' class='button' title='{$this->local_app_strings['LNK_LIST_NEXT']}' onClick='location.href=\"$next_URL\"; sListView.save_checks($next_offset, \"{$moduleString}\");'>".SugarThemeRegistry::current()->getImage("next","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_NEXT'])."</button>";
1237                 } else {
1238                     $onClick = '';
1239                     if(0 != preg_match('/javascript.*/', $next_URL)){
1240                         $onClick = "\"$next_URL;\"";
1241                     }else{
1242                         $onClick ="'location.href=\"$next_URL\";'";
1243                     }
1244                     $next_link = "<button type='button' name='listViewNextButton' class='button' title='{$this->local_app_strings['LNK_LIST_NEXT']}' onClick=".$onClick.">".SugarThemeRegistry::current()->getImage("next","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_NEXT'])."</button>";
1245
1246                     $onClick = '';
1247                     if(0 != preg_match('/javascript.*/', $end_URL)){
1248                         $onClick = "\"$end_URL;\"";
1249                     }else{
1250                         $onClick = "'location.href=\"$end_URL\";'";
1251                     }
1252                     $end_link = "<button type='button' name='listViewEndButton' class='button' title='{$this->local_app_strings['LNK_LIST_END']}' onClick=".$onClick.">".SugarThemeRegistry::current()->getImage("end","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_END'])."</button>";
1253
1254                 }
1255             }
1256
1257             $GLOBALS['log']->info("Offset (next, current, prev)($next_offset, $current_offset, $previous_offset)");
1258             $GLOBALS['log']->info("Start/end records ($start_record, $end_record)");
1259
1260             $end_record = $end_record-1;
1261
1262 $script_href = "<a style=\'width: 150px\' name=\"thispage\" class=\'menuItem\' onmouseover=\'hiliteItem(this,\"yes\");\' onmouseout=\'unhiliteItem(this);\' onclick=\'if (document.MassUpdate.select_entire_list.value==1){document.MassUpdate.select_entire_list.value=0;sListView.check_all(document.MassUpdate, \"mass[]\", true, $this->records_per_page)}else {sListView.check_all(document.MassUpdate, \"mass[]\", true)};\' href=\'#\'>{$this->local_app_strings['LBL_LISTVIEW_OPTION_CURRENT']}&nbsp;&#x28;{$this->records_per_page}&#x29;&#x200E;</a>"
1263  . "<a style=\'width: 150px\' name=\"selectall\" class=\'menuItem\' onmouseover=\'hiliteItem(this,\"yes\");\' onmouseout=\'unhiliteItem(this);\' onclick=\'sListView.check_entire_list(document.MassUpdate, \"mass[]\",true,{$row_count});\' href=\'#\'>{$this->local_app_strings['LBL_LISTVIEW_OPTION_ENTIRE']}&nbsp;&#x28;{$row_count}&#x29;&#x200E;</a>"
1264  . "<a style=\'width: 150px\' name=\"deselect\" class=\'menuItem\' onmouseover=\'hiliteItem(this,\"yes\");\' onmouseout=\'unhiliteItem(this);\' onclick=\'sListView.clear_all(document.MassUpdate, \"mass[]\", false);\' href=\'#\'>{$this->local_app_strings['LBL_LISTVIEW_NONE']}</a>";
1265
1266 $close_inline_img = SugarThemeRegistry::current()->getImage('close_inline', 'border=0', null, null, ".gif", $app_strings['LBL_CLOSEINLINE']);
1267
1268             echo "<script>
1269                 function select_dialog() {
1270                         var \$dialog = \$('<div></div>')
1271                                         .html('<a style=\'width: 150px\' name=\"thispage\" class=\'menuItem\' onmouseover=\'hiliteItem(this,\"yes\");\' onmouseout=\'unhiliteItem(this);\' onclick=\'if (document.MassUpdate.select_entire_list.value==1){document.MassUpdate.select_entire_list.value=0;sListView.check_all(document.MassUpdate, \"mass[]\", true, $this->records_per_page)}else {sListView.check_all(document.MassUpdate, \"mass[]\", true)};\' href=\'javascript:void(0)\'>{$this->local_app_strings['LBL_LISTVIEW_OPTION_CURRENT']}&nbsp;&#x28;{$this->records_per_page}&#x29;&#x200E;</a>"
1272                 . "<a style=\'width: 150px\' name=\"selectall\" class=\'menuItem\' onmouseover=\'hiliteItem(this,\"yes\");\' onmouseout=\'unhiliteItem(this);\' onclick=\'sListView.check_entire_list(document.MassUpdate, \"mass[]\",true,{$row_count});\' href=\'javascript:void(0)\'>{$this->local_app_strings['LBL_LISTVIEW_OPTION_ENTIRE']}&nbsp;&#x28;{$row_count}&#x29;&#x200E;</a>"
1273                 . "<a style=\'width: 150px\' name=\"deselect\" class=\'menuItem\' onmouseover=\'hiliteItem(this,\"yes\");\' onmouseout=\'unhiliteItem(this);\' onclick=\'sListView.clear_all(document.MassUpdate, \"mass[]\", false);\' href=\'javascript:void(0)\'>{$this->local_app_strings['LBL_LISTVIEW_NONE']}</a>')
1274                                         .dialog({
1275                                                 autoOpen: false,
1276                                                 width: 150
1277                                         });
1278                                         \$dialog.dialog('open');
1279
1280                 }
1281                 </script>";
1282
1283             if($this->show_select_menu)
1284             {
1285                 $select_link = "<a id='select_link' onclick='return select_dialog();' href=\"javascript:void(0)\">".$this->local_app_strings['LBL_LINK_SELECT']."&nbsp;".SugarThemeRegistry::current()->getImage('MoreDetail', 'border=0', 11, 7, '.png', $app_strings['LBL_MOREDETAIL'])."</a>";
1286             } else {
1287                 $select_link = "&nbsp;";
1288             }
1289
1290             $export_link = '<input class="button" type="button" value="'.$this->local_app_strings['LBL_EXPORT'].'" ' .
1291                     'onclick="return sListView.send_form(true, \''.$_REQUEST['module'].'\', \'index.php?entryPoint=export\',\''.$this->local_app_strings['LBL_LISTVIEW_NO_SELECTED'].'\')">';
1292
1293             if($this->show_delete_button) {
1294                 $delete_link = '<input class="button" type="button" name="Delete" value="'.$this->local_app_strings['LBL_DELETE_BUTTON_LABEL'].'" onclick="return sListView.send_mass_update(\'selected\',\''.$this->local_app_strings['LBL_LISTVIEW_NO_SELECTED'].'\', 1)">';
1295             } else {
1296                 $delete_link = '&nbsp;';
1297             }
1298
1299             $admin = new Administration();
1300             $admin->retrieveSettings('system');
1301
1302             $user_merge = $current_user->getPreference('mailmerge_on');
1303             if($user_merge == 'on' && isset($admin->settings['system_mailmerge_on']) && $admin->settings['system_mailmerge_on']) {
1304                 echo "<script>
1305                 function mailmerge_dialog(el) {
1306                         var \$dialog = \$('<div></div>')
1307                                         .html('<a style=\'width: 150px\' class=\'menuItem\' onmouseover=\'hiliteItem(this,\"yes\");\' onmouseout=\'unhiliteItem(this);\' onclick=\'return sListView.send_form(true, \"MailMerge\", \"index.php\", \"{$this->local_app_strings['LBL_LISTVIEW_NO_SELECTED']}\")\' href=\'javascript:void(0)\'>{$this->local_app_strings['LBL_LISTVIEW_OPTION_SELECTED']}</a>"
1308                         . "<a style=\'width: 150px\' class=\'menuItem\' onmouseover=\'hiliteItem(this,\"yes\");\' onmouseout=\'unhiliteItem(this);\' href=\'index.php?action=index&module=MailMerge\'>{$this->local_app_strings['LBL_LISTVIEW_OPTION_CURRENT']}</a>"
1309                         . "<a style=\'width: 150px\' class=\'menuItem\' onmouseover=\'hiliteItem(this,\"yes\");\' onmouseout=\'unhiliteItem(this);\' href=\'index.php?action=index&module=MailMerge&entire=true\'>{$this->local_app_strings['LBL_LISTVIEW_OPTION_ENTIRE']}</a>')
1310                                         .dialog({
1311                                                 autoOpen: false,
1312                                                 title: '". $this->local_app_strings['LBL_MAILMERGE']."',
1313                                                 width: 150,
1314                                                 position: {
1315                                                     my: myPos,
1316                                                     at: atPos,
1317                                                     of: \$(el)
1318                                                 }
1319                                         });
1320
1321                 }
1322             </script>";
1323                 $merge_link = "&nbsp;|&nbsp;<a id='mailmerge_link' onclick='return mailmerge_dialog(this)'; href=\"javascript:void(0)\">".$this->local_app_strings['LBL_MAILMERGE']."</a>";
1324             } else {
1325                 $merge_link = "&nbsp;";
1326             }
1327
1328             $selected_objects_span = "&nbsp;|&nbsp;{$this->local_app_strings['LBL_LISTVIEW_SELECTED_OBJECTS']}<input  style='border: 0px; background: transparent; font-size: inherit; color: inherit' type='text' readonly name='selectCount[]' value='" . (!empty($select_entire_list) ? $row_count : 0) . "' />";
1329
1330             if($_REQUEST['module'] == 'Home' || $this->local_current_module == 'Import'
1331                 || $this->show_export_button == false
1332                 || (!empty($sugar_config['disable_export']))
1333                 || (!empty($sugar_config['admin_export_only'])
1334                 && !(
1335                         is_admin($current_user)
1336                         || (ACLController::moduleSupportsACL($_REQUEST['module'])
1337                             && ACLAction::getUserAccessLevel($current_user->id,$_REQUEST['module'], 'access') == ACL_ALLOW_ENABLED
1338                             && (ACLAction::getUserAccessLevel($current_user->id, $_REQUEST['module'], 'admin') == ACL_ALLOW_ADMIN ||
1339                                 ACLAction::getUserAccessLevel($current_user->id, $_REQUEST['module'], 'admin') == ACL_ALLOW_ADMIN_DEV)))))
1340             {
1341                 if ($_REQUEST['module'] != 'InboundEmail' && $_REQUEST['module'] != 'EmailMan' && $_REQUEST['module'] != 'iFrames') {
1342                     $selected_objects_span = '';
1343                 }
1344                 $export_link = "&nbsp;";
1345                 $merge_link = "&nbsp;";
1346             } elseif($_REQUEST['module'] != "Accounts" && $_REQUEST['module'] != "Cases" && $_REQUEST['module'] != "Contacts" && $_REQUEST['module'] != "Leads" && $_REQUEST['module'] != "Opportunities") {
1347                 $merge_link = "&nbsp;";
1348             }
1349
1350             if($this->show_paging == true) {
1351                 if(!empty($sugar_config['disable_count_query'])) {
1352                     if($row_count > $end_record) {
1353                         $row_count .= '+';
1354                     }
1355                 }
1356
1357                 $html_text = '';
1358                 $html_text .= "<tr class='pagination' role='presentation'>\n";
1359                 $html_text .= "<td COLSPAN=\"$col_count\" align=\"right\">\n";
1360                 //$html_text .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr><td align=\"left\"  >$export_link$merge_link$selected_objects_span</td>\n";
1361                 //$html_text .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr><td align=\"left\"  >";
1362                 if ($subpanel_def != null) {
1363                     include_once('include/SubPanel/SubPanelTiles.php');
1364                     $subpanelTiles = new SubPanelTiles($sugarbean);
1365                     $html_text .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr><td align=\"left\"  >";
1366
1367                     //attempt to get the query to recreate this subpanel
1368                     if(!empty($this->response)){
1369                         $response =& $this->response;
1370                     }else{
1371                         $response = SugarBean::get_union_related_list($sugarbean,$this->sortby, $this->sort_order, $this->query_where, $current_offset, -1,-1,$this->query_limit,$subpanel_def);
1372                         $this->response = $response;
1373                     }
1374                     //if query is present, then pass it in as parameter
1375                     if (isset($response['query']) && !empty($response['query'])){
1376                         $html_text .= $subpanelTiles->get_buttons($subpanel_def, $response['query']);
1377                     }else{
1378                         $html_text .= $subpanelTiles->get_buttons($subpanel_def);
1379                     }
1380                 }
1381                 else {
1382                     $html_text .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr><td align=\"left\"  nowrap>$select_link&nbsp;$export_link&nbsp;$delete_link&nbsp;$selected_objects_span";
1383                 }
1384                 $html_text .= "</td>\n<td nowrap align=\"right\">".$start_link."&nbsp;&nbsp;".$previous_link."&nbsp;&nbsp;<span class='pageNumbers'>(".$start_record." - ".$end_record." ".$this->local_app_strings['LBL_LIST_OF']." ".$row_count.")</span>&nbsp;&nbsp;".$next_link."&nbsp;&nbsp;".$end_link."</td></tr></table>\n";
1385                 $html_text .= "</td>\n";
1386                 $html_text .= "</tr>\n";
1387                 $this->xTemplate->assign("PAGINATION",$html_text);
1388             }
1389
1390             //C.L. - Fix for 23461
1391             if(empty($_REQUEST['action']) || $_REQUEST['action'] != 'Popup') {
1392                 $_SESSION['export_where'] = $this->query_where;
1393             }
1394             $this->xTemplate->parse($xtemplateSection.".list_nav_row");
1395         }
1396     } // end processListNavigation
1397
1398     function processOrderBy($html_varName) {
1399
1400         if(!isset($this->base_URL)) {
1401             $this->base_URL = $_SERVER['PHP_SELF'];
1402
1403             if(isset($_SERVER['QUERY_STRING'])) {
1404                 $this->base_URL = preg_replace("/\&".$this->getSessionVariableName($html_varName,"ORDER_BY")."=[0-9a-zA-Z\_\.]*/","",$this->base_URL .'?'.$_SERVER['QUERY_STRING']);
1405                 $this->base_URL = preg_replace("/\&".$this->getSessionVariableName($html_varName,"offset")."=[0-9]*/","",$this->base_URL);
1406             }
1407             if($_SERVER['REQUEST_METHOD'] == 'POST') {
1408                 $this->base_URL .= '?';
1409                 if(isset($_REQUEST['action'])) $this->base_URL .= '&action='.$_REQUEST['action'];
1410                 if(isset($_REQUEST['record'])) $this->base_URL .= '&record='.$_REQUEST['record'];
1411                 if(isset($_REQUEST['module'])) $this->base_URL .= '&module='.$_REQUEST['module'];
1412             }
1413             $this->base_URL .= "&".$this->getSessionVariableName($html_varName,"offset")."=";
1414         }
1415
1416         if($this->is_dynamic) {
1417             $this->base_URL.='&to_pdf=true&action=SubPanelViewer&subpanel=' . $this->source_module;
1418         }
1419
1420         //bug43465 start
1421         if (isset($this->appendToBaseUrl) && is_array($this->appendToBaseUrl))
1422         {
1423             foreach ($this->appendToBaseUrl as $key => $value)
1424             {
1425                 $fullRequestString = $key . '=' . $value;
1426
1427                 if ($this->base_URL == "/index.php")
1428                 {
1429                     $this->base_URL .= "?";
1430                 } else
1431                 {
1432                     if ($fullRequestString == substr($this->baseURL, '-' . strlen($fullRequestString)))
1433                     {
1434                         $this->base_URL = preg_replace("/&" . $key . "\=.*/", "", $this->base_URL);
1435                     } else
1436                     {
1437                         $this->base_URL = preg_replace("/&" . $key . "\=.*?&/", "&", $this->base_URL);
1438                     }
1439                     $this->base_URL .= "&";
1440                 }
1441                 if (!empty($value))
1442                 {
1443                     $this->base_URL .= "{$key}={$value}";
1444                 }
1445             }
1446         }
1447         //bug43465 end
1448
1449         $sort_URL_base = $this->base_URL. "&".$this->getSessionVariableName($html_varName,"ORDER_BY")."=";
1450
1451         if($sort_URL_base !== "")
1452         {
1453             $this->xTemplate->assign("ORDER_BY", $sort_URL_base);
1454             return $sort_URL_base;
1455         } else {
1456             return '';
1457         }
1458     }
1459
1460
1461     function getAdditionalHeader() {
1462
1463     }
1464
1465
1466     /**
1467     * @return void
1468     * @param unknown $data
1469     * @param unknown $xTemplateSection
1470     * @param unknown $html_varName
1471     * @desc INTERNAL FUNCTION handles the rows
1472     * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
1473     * All Rights Reserved.
1474     * Contributor(s): ______________________________________..
1475     */
1476     function processListRows($data, $xtemplateSection, $html_varName)
1477     {
1478         global $odd_bg;
1479         global $even_bg;
1480         global $hilite_bg;
1481         global $app_strings, $sugar_version, $sugar_config;
1482         global $currentModule;
1483
1484         $this->xTemplate->assign('BG_HILITE', $hilite_bg);
1485         $this->xTemplate->assign('CHECKALL', SugarThemeRegistry::current()->getImage('blank', '', 1, 1, ".gif", ''));
1486     //$this->xTemplate->assign("BG_CLICK", $click_bg);
1487         $oddRow = true;
1488         $count = 0;
1489         reset($data);
1490
1491         //GETTING OFFSET
1492         $offset = $this->getOffset($html_varName);
1493         $timeStamp = $this->unique_id();
1494         $_SESSION[$html_varName."_FROM_LIST_VIEW"] = $timeStamp;
1495
1496         $associated_row_data = array();
1497
1498         //mail merge list
1499         $mergeList = array();
1500         $module = '';
1501         //todo what is this?  It is using an array as a boolean
1502         while(list($aVal, $aItem) = each($data))
1503         {
1504             if(isset($this->data_array)) {
1505                 $fields = $this->data_array;
1506             } else {
1507                 $aItem->check_date_relationships_load();
1508                 $fields = $aItem->get_list_view_data();
1509             }
1510
1511             if(is_object($aItem)) { // cn: bug 5349
1512                 //add item id to merge list, if the button is clicked
1513                 $mergeList[] = $aItem->id;
1514                 if(empty($module)) {
1515                     $module = $aItem->module_dir;
1516                 }
1517             }
1518             //ADD OFFSET TO ARRAY
1519
1520                 $fields['OFFSET'] = ($offset + $count + 1);
1521
1522             $fields['STAMP'] = $timeStamp;
1523             if($this->shouldProcess) {
1524
1525             $prerow = '';
1526             if(!isset($this->data_array)) {
1527                 $prerow .= "<input onclick='sListView.check_item(this, document.MassUpdate)' type='checkbox' class='checkbox' name='mass[]' value='". $fields['ID']. "'>";
1528             }
1529             $this->xTemplate->assign('PREROW', $prerow);
1530
1531             $this->xTemplate->assign('CHECKALL', "<input type='checkbox' class='checkbox'  title='".$GLOBALS['app_strings']['LBL_SELECT_ALL_TITLE']."'  name='massall' id='massall' value='' onclick='sListView.check_all(document.MassUpdate, \"mass[]\", this.checked)'>");
1532             }
1533             if(!isset($this->data_array)) {
1534                 $tag = $aItem->listviewACLHelper();
1535                 $this->xTemplate->assign('TAG',$tag) ;
1536             }
1537
1538             if($oddRow)
1539             {
1540                 $ROW_COLOR = 'oddListRow';
1541                 $BG_COLOR =  $odd_bg;
1542             }
1543             else
1544             {
1545                 $ROW_COLOR = 'evenListRow';
1546                 $BG_COLOR =  $even_bg;
1547             }
1548             $oddRow = !$oddRow;
1549
1550             $this->xTemplate->assign('ROW_COLOR', $ROW_COLOR);
1551             $this->xTemplate->assign('BG_COLOR', $BG_COLOR);
1552
1553             if(isset($this->data_array))
1554             {
1555                 $this->xTemplate->assign('KEY', $aVal);
1556                 $this->xTemplate->assign('VALUE', $aItem);
1557                 $this->xTemplate->assign('INDEX', $count);
1558
1559             }
1560             else
1561             {
1562     //AED -- some modules do not have their additionalDetails.php established. Add a check to ensure require_once does not fail
1563     // Bug #2786
1564                 if($this->_additionalDetails && $aItem->ACLAccess('DetailView') && (file_exists('modules/' . $aItem->module_dir . '/metadata/additionalDetails.php') || file_exists('custom/modules/' . $aItem->module_dir . '/metadata/additionalDetails.php'))) {
1565
1566                     $additionalDetailsFile = 'modules/' . $aItem->module_dir . '/metadata/additionalDetails.php';
1567                     if(file_exists('custom/modules/' . $aItem->module_dir . '/metadata/additionalDetails.php')){
1568                         $additionalDetailsFile = 'custom/modules/' . $aItem->module_dir . '/metadata/additionalDetails.php';
1569                     }
1570
1571                     require_once($additionalDetailsFile);
1572                     $ad_function = (empty($this->additionalDetailsFunction) ? 'additionalDetails' : $this->additionalDetailsFunction) . $aItem->object_name;
1573                     $results = $ad_function($fields);
1574                     $results['string'] = str_replace(array("&#039", "'"), '\&#039', $results['string']); // no xss!
1575
1576                     if(trim($results['string']) == '') $results['string'] = $app_strings['LBL_NONE'];
1577                     $fields[$results['fieldToAddTo']] = $fields[$results['fieldToAddTo']].'</a>';
1578                 }
1579
1580                 if($aItem->ACLAccess('Delete')) {
1581                     $delete = '<a class="listViewTdToolsS1" onclick="return confirm(\''.$this->local_app_strings['NTC_DELETE_CONFIRMATION'].'\')" href="'.'index.php?action=Delete&module='.$aItem->module_dir.'&record='.$fields['ID'].'&return_module='.$aItem->module_dir.'&return_action=index&return_id=">'.$this->local_app_strings['LBL_DELETE_INLINE'].'</a>';
1582                     require_once('include/Smarty/plugins/function.sugar_action_menu.php');
1583                     $fields['DELETE_BUTTON'] = smarty_function_sugar_action_menu(array(
1584                         'id' => $aItem->module_dir.'_'.$fields['ID'].'_create_button',
1585                         'buttons' => array($delete),
1586                     ), $this);
1587
1588                 }
1589
1590                 $this->xTemplate->assign($html_varName, $fields);
1591                 $aItem->setupCustomFields($aItem->module_dir);
1592                 $aItem->custom_fields->populateAllXTPL($this->xTemplate, 'detail', $html_varName, $fields);
1593             }
1594             if(!isset($this->data_array) && $aItem->ACLAccess('DetailView')) {
1595                 $count++;
1596             }
1597             if(isset($this->data_array)) {
1598                 $count++;
1599             }
1600             if(!isset($this->data_array)) {
1601                 $aItem->list_view_parse_additional_sections($this->xTemplate, $xtemplateSection);
1602
1603                 if($this->xTemplate->exists($xtemplateSection.'.row.pro')) {
1604                     $this->xTemplate->parse($xtemplateSection.'.row.pro');
1605                 }
1606             }
1607             $this->xTemplate->parse($xtemplateSection . '.row');
1608
1609             if(isset($fields['ID'])) {
1610                 $associated_row_data[$fields['ID']] = $fields;
1611                 // Bug 38908: cleanup data for JS to avoid having &nbsp; shuffled around
1612                 foreach($fields as $key => $value) {
1613                     if($value == '&nbsp;') {
1614                         $associated_row_data[$fields['ID']][$key] = '';
1615                     }
1616                 }
1617             }
1618         }
1619
1620         $_SESSION['MAILMERGE_RECORDS'] = $mergeList;
1621         $_SESSION['MAILMERGE_MODULE_FROM_LISTVIEW'] = $module;
1622         if(empty($_REQUEST['action']) || $_REQUEST['action'] != 'Popup') {
1623             $_SESSION['MAILMERGE_MODULE'] = $module;
1624         }
1625
1626         if($this->process_for_popups)
1627         {
1628             $json = getJSONobj();
1629             $is_show_fullname = showFullName() ? 1 : 0;
1630             $associated_javascript_data = '<script type="text/javascript">' . "\n"
1631                 //. '<!-- // associated javascript data generated by ListView' . "\n"
1632                 . 'var associated_javascript_data = '
1633                 . $json->encode($associated_row_data) . ";\n"
1634                 //. '-->' . "\n"
1635                 . 'var is_show_fullname = '
1636                 . $is_show_fullname . ";\n"
1637                 . '</script>';
1638             $this->xTemplate->assign('ASSOCIATED_JAVASCRIPT_DATA', $associated_javascript_data);
1639         }
1640
1641         $this->xTemplate->parse($xtemplateSection);
1642     }
1643
1644
1645     function getLayoutManager()
1646     {
1647         require_once('include/generic/LayoutManager.php');
1648         if($this->layout_manager == null)
1649         {
1650             $this->layout_manager = new LayoutManager();
1651         }
1652         return $this->layout_manager;
1653     }
1654
1655
1656     function process_dynamic_listview_header($source_module, $subpanel_def, $html_var = 'CELL')
1657     {
1658
1659
1660         $layout_manager = $this->getLayoutManager();
1661         $layout_manager->setAttribute('order_by_link',$this->processOrderBy($html_var));
1662         $layout_manager->setAttribute('context','HeaderCell');
1663         $layout_manager->setAttribute('image_path',$this->local_image_path);
1664         $layout_manager->setAttribute('html_varName',$html_var);
1665         $layout_manager->setAttribute('module_name', $source_module);
1666         list($orderBy,$desc) = $this->getOrderByInfo($html_var);
1667
1668         if($orderBy == 'amount*1')
1669         {
1670             $orderBy=  'amount';
1671         }
1672                 $buttons = false;
1673         foreach($subpanel_def->get_list_fields() as $column_name=>$widget_args)
1674         {
1675             $usage = empty($widget_args['usage']) ? '' : $widget_args['usage'];
1676             if($usage != 'query_only')
1677             {
1678                 $imgArrow = '';
1679
1680                 if($orderBy == $column_name || (isset($widget_args['sort_by']) && str_replace('.','_',$widget_args['sort_by']) == $orderBy))
1681                 {
1682                     $imgArrow = "_down";
1683                     if($this->sort_order == 'asc') {
1684                         $imgArrow = "_up";
1685                     }
1686                 }
1687
1688                 if (!preg_match("/_button/i", $column_name)) {
1689                         $widget_args['name']=$column_name;
1690                         $widget_args['sort'] = $imgArrow;
1691                         $widget_args['start_link_wrapper'] = $this->start_link_wrapper;
1692                         $widget_args['end_link_wrapper'] = $this->end_link_wrapper;
1693                         $widget_args['subpanel_module'] = $this->subpanel_module;
1694
1695                         $widget_contents = $layout_manager->widgetDisplay($widget_args);
1696                         $cell_width = empty($widget_args['width']) ? '' : $widget_args['width'];
1697                         $this->xTemplate->assign('HEADER_CELL', $widget_contents);
1698                         static $count;
1699                     if(!isset($count))$count = 0; else $count++;
1700                         $this->xTemplate->assign('CELL_COUNT', $count);
1701                         $this->xTemplate->assign('CELL_WIDTH', $cell_width);
1702                         $this->xTemplate->parse('dyn_list_view.header_cell');
1703                 } else {
1704                         $buttons = true;
1705                 }
1706             }
1707         }
1708
1709         if($buttons) {
1710                                 $this->xTemplate->assign('HEADER_CELL', "&nbsp;");
1711                                 $this->xTemplate->assign('CELL_COUNT', $count);
1712                         $this->xTemplate->assign('CELL_WIDTH', $cell_width);
1713                         $this->xTemplate->parse('dyn_list_view.header_cell');
1714         }
1715
1716     }
1717
1718
1719     /**
1720     * @return void
1721     * @param unknown $seed
1722     * @param unknown $xTemplateSection
1723     * @param unknown $html_varName
1724     * @desc PUBLIC FUNCTION Handles List Views using seeds that extend SugarBean
1725         $XTemplateSection is the section in the XTemplate file that should be parsed usually main
1726         $html_VarName is the variable name used in the XTemplateFile e.g. TASK
1727         $seed is a seed there are two types of seeds one is a subclass of SugarBean, the other is a list usually created from a sugar bean using get_list
1728         if no XTemplate is set it will create  a new XTemplate
1729         * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc..
1730         * All Rights Reserved..
1731         * Contributor(s): ______________________________________..
1732     */
1733
1734     function processListViewTwo($seed, $xTemplateSection, $html_varName) {
1735         global $current_user;
1736         if(!isset($this->xTemplate)) {
1737             $this->createXTemplate();
1738         }
1739
1740         $isSugarBean = is_subclass_of($seed, "SugarBean");
1741         $list = null;
1742
1743         if($isSugarBean) {
1744             $list = $this->processSugarBean($xTemplateSection, $html_varName, $seed);
1745         } else {
1746             $list = $seed;
1747         }
1748
1749         if (is_object($seed) && isset($seed->object_name) && $seed->object_name == 'WorkFlow') {
1750             $tab=array();
1751             $access = get_workflow_admin_modules_for_user($current_user);
1752             for ($i = 0; $i < count($list); $i++) {
1753                 if(!empty($access[$list[$i]->base_module])){
1754                     $tab[]=$list[$i];
1755                 }
1756             }
1757             $list = $tab;
1758         }
1759
1760         if($this->is_dynamic) {
1761             $this->processHeaderDynamic($xTemplateSection,$html_varName);
1762             $this->processListRows($list,$xTemplateSection, $html_varName);
1763         } else {
1764             $this->processSortArrows($html_varName);
1765
1766             if($isSugarBean) {
1767                 $seed->parse_additional_headers($this->xTemplate, $xTemplateSection);
1768             }
1769             $this->xTemplateAssign('CHECKALL', SugarThemeRegistry::current()->getImage('blank', '', 1, 1, ".gif", ''));
1770
1771             // Process the  order by before processing the pro_nav.  The pro_nav requires the order by values to be set
1772             $this->processOrderBy($html_varName);
1773
1774
1775             $this->processListRows($list,$xTemplateSection, $html_varName);
1776         }
1777
1778         if($this->display_header_and_footer) {
1779             $this->getAdditionalHeader();
1780             if(!empty($this->header_title)) {
1781                 echo get_form_header($this->header_title, $this->header_text, false);
1782             }
1783         }
1784
1785         $this->xTemplate->out($xTemplateSection);
1786
1787         if(isset($_SESSION['validation'])) {
1788             print base64_decode('PGEgaHJlZj0naHR0cDovL3d3dy5zdWdhcmNybS5jb20nPlBPV0VSRUQmbmJzcDtCWSZuYnNwO1NVR0FSQ1JNPC9hPg==');
1789         }
1790     }
1791
1792     function getArrowStart() {
1793         $imgFileParts = pathinfo(SugarThemeRegistry::current()->getImageURL("arrow.gif"));
1794
1795         return "&nbsp;<!--not_in_theme!--><img border='0' src='".$imgFileParts['dirname']."/".$imgFileParts['filename']."";
1796     }
1797
1798     function getArrowUpDownStart($upDown) {
1799         $ext = ( SugarThemeRegistry::current()->pngSupport ? "png" : "gif" );
1800
1801         if (!isset($upDown) || empty($upDown)) {
1802             $upDown = "";
1803         }
1804         return "&nbsp;<img border='0' src='".SugarThemeRegistry::current()->getImageURL("arrow{$upDown}.{$ext}")."' ";
1805     }
1806
1807         function getArrowEnd() {
1808                 $imgFileParts = pathinfo(SugarThemeRegistry::current()->getImageURL("arrow.gif"));
1809
1810         list($width,$height) = ListView::getArrowImageSize();
1811
1812                 return '.'.$imgFileParts['extension']."' width='$width' height='$height' align='absmiddle' alt=".translate('LBL_SORT').">";
1813     }
1814
1815     function getArrowUpDownEnd($upDown) {
1816         if (!isset($upDown) || empty($upDown)) {
1817             $upDown = "";
1818         }
1819         $imgFileParts = pathinfo(SugarThemeRegistry::current()->getImageURL("arrow{$upDown}.gif"));
1820
1821         list($width,$height) = ListView::getArrowUpDownImageSize($upDown);
1822
1823         //get the right alt tag for the sort
1824         $sortStr = translate('LBL_ALT_SORT');
1825         if($upDown == '_down'){
1826             $sortStr = translate('LBL_ALT_SORT_DESC');
1827         }elseif($upDown == '_up'){
1828             $sortStr = translate('LBL_ALT_SORT_ASC');
1829         }
1830         return " width='$width' height='$height' align='absmiddle' alt='$sortStr'>";
1831     }
1832
1833         function getArrowImageSize() {
1834             // jbasicChartDashletsExpColust get the non-sort image's size.. the up and down have be the same.
1835                 $image = SugarThemeRegistry::current()->getImageURL("arrow.gif",false);
1836
1837         $cache_key = 'arrow_size.'.$image;
1838
1839         // Check the cache
1840         $result = sugar_cache_retrieve($cache_key);
1841         if(!empty($result))
1842         return $result;
1843
1844         // No cache hit.  Calculate the value and return.
1845         $result = getimagesize($image);
1846         sugar_cache_put($cache_key, $result);
1847         return $result;
1848     }
1849
1850     function getArrowUpDownImageSize($upDown) {
1851         // just get the non-sort image's size.. the up and down have be the same.
1852         $image = SugarThemeRegistry::current()->getImageURL("arrow{$upDown}.gif",false);
1853
1854         $cache_key = 'arrowupdown_size.'.$image;
1855
1856         // Check the cache
1857         $result = sugar_cache_retrieve($cache_key);
1858         if(!empty($result))
1859         return $result;
1860
1861         // No cache hit.  Calculate the value and return.
1862         $result = getimagesize($image);
1863         sugar_cache_put($cache_key, $result);
1864         return $result;
1865     }
1866
1867         function getOrderByInfo($html_varName)
1868         {
1869                 $orderBy = $this->getSessionVariable($html_varName, "OBL");
1870                 $desc = $this->getSessionVariable($html_varName, $orderBy.'S');
1871                 $orderBy = str_replace('.', '_', $orderBy);
1872                 return array($orderBy,$desc);
1873         }
1874
1875     function processSortArrows($html_varName)
1876     {
1877
1878         $this->xTemplateAssign("arrow_start", $this->getArrowStart());
1879
1880         list($orderBy,$desc) = $this->getOrderByInfo($html_varName);
1881
1882                 $imgArrow = "_up";
1883                 if($desc) {
1884                         $imgArrow = "_down";
1885                 }
1886                 /**
1887                  * @deprecated only used by legacy opportunites listview, nothing current. Leaving for BC
1888                  */
1889                 if($orderBy == 'amount*1')
1890                 {
1891                         $this->xTemplateAssign('amount_arrow', $imgArrow);
1892                 }
1893                 else if($orderBy == 'amount_usdollar*1')
1894                 {
1895                         $this->xTemplateAssign('amount_usdollar_arrow', $imgArrow);
1896                 }
1897                 else
1898                 {
1899                         $this->xTemplateAssign($orderBy.'_arrow', $imgArrow);
1900                 }
1901
1902         $this->xTemplateAssign('arrow_end', $this->getArrowEnd());
1903     }
1904
1905     // this is where translation happens for dynamic list views
1906     function loadListFieldDefs(&$subpanel_fields,&$child_focus)
1907     {
1908         $this->list_field_defs = $subpanel_fields;
1909
1910         for($i=0;$i < count($this->list_field_defs);$i++)
1911         {
1912             $list_field = $this->list_field_defs[$i];
1913             $field_def = null;
1914             $key = '';
1915             if(!empty($list_field['vname']))
1916             {
1917                 $key = $list_field['vname'];
1918             } else if(isset($list_field['name']) &&  isset($child_focus->field_defs[$list_field['name']]))
1919             {
1920                     $field_def = $child_focus->field_defs[$list_field['name']];
1921                     $key = $field_def['vname'];
1922             }
1923             if(!empty($key))
1924             {
1925                 $list_field['label'] = translate($key,$child_focus->module_dir);
1926                 $this->list_field_defs[$i]['label'] = preg_replace('/:$/','',$list_field['label']);
1927             }
1928             else
1929             {
1930                 $this->list_field_defs[$i]['label'] ='&nbsp;';
1931             }
1932         }
1933     }
1934
1935     function unique_id() {
1936         return sugar_microtime();
1937     }
1938
1939      /**INTERNAL FUNCTION sets a session variable keeping it local to the listview
1940      not the current_module
1941      * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
1942      * All Rights Reserved.
1943      * Contributor(s): ______________________________________.
1944      */
1945      function setLocalSessionVariable($localVarName,$varName, $value) {
1946         $_SESSION[$localVarName."_".$varName] = $value;
1947      }
1948
1949      /**INTERNAL FUNCTION returns a session variable that is local to the listview,
1950      not the current_module
1951      * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
1952      * All Rights Reserved.
1953      * Contributor(s): ______________________________________.
1954      */
1955  function getLocalSessionVariable($localVarName,$varName) {
1956     if(isset($_SESSION[$localVarName."_".$varName])) {
1957         return $_SESSION[$localVarName."_".$varName];
1958     }
1959     else{
1960         return "";
1961     }
1962  }
1963
1964  /* Set to true if you want Additional Details to appear in the listview
1965   */
1966  function setAdditionalDetails($value = true, $function = '') {
1967     if(!empty($function)) $this->additionalDetailsFunction = $function;
1968     $this->_additionalDetails = $value;
1969  }
1970
1971 }
1972 ?>