]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/ListView/ListViewDisplay.php
Release 6.4.0beta1
[Github/sugarcrm.git] / include / ListView / ListViewDisplay.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38
39
40
41 require_once('include/ListView/ListViewData.php');
42 require_once('include/MassUpdate.php');
43
44 class ListViewDisplay {
45
46         var $show_mass_update_form = false;
47         var $show_action_dropdown = true;
48         var $rowCount;
49         var $mass = null;
50         var $seed;
51         var $multi_select_popup;
52         var $lvd;
53         var $moduleString;
54         var $export = true;
55         var $multiSelect = true;
56         var $mailMerge = true;
57         var $should_process = true;
58         var $show_plus = false;
59         /*
60          * Used in view.popup.php. Sometimes there are fields on the search form that are not referenced in the listviewdefs. If this
61          * is the case, then the filterFields will be set and the related fields will not be referenced when calling create_new_list_query.
62          */
63         var $mergeDisplayColumns = false;
64     public $actionsMenuExtraItems = array();
65
66         /**
67          * Constructor
68          * @return null
69          */
70         function ListViewDisplay() {
71                 $this->lvd = new ListViewData();
72                 $this->searchColumns = array () ;
73         }
74         function shouldProcess($moduleDir){
75                 if(!empty($GLOBALS['sugar_config']['save_query']) && $GLOBALS['sugar_config']['save_query'] == 'populate_only'){
76                     if(empty($GLOBALS['displayListView']) 
77                             && (!empty($_REQUEST['clear_query']) 
78                                 || $_REQUEST['module'] == $moduleDir 
79                                     && ((empty($_REQUEST['query']) || $_REQUEST['query'] == 'MSI' )
80                                         && (empty($_SESSION['last_search_mod']) || $_SESSION['last_search_mod'] != $moduleDir ) ))){
81                                 $_SESSION['last_search_mod'] = $_REQUEST['module'] ;
82                                 $this->should_process = false;
83                                 return false;
84                         }
85                 }
86                 $this->should_process = true;
87                 return true;
88         }
89
90         /**
91          * Setup the class
92          * @param seed SugarBean Seed SugarBean to use
93          * @param file File Template file to use
94          * @param string $where
95          * @param offset:0 int offset to start at
96          * @param int:-1 $limit
97          * @param string[]:array() $filter_fields
98          * @param array:array() $params
99          *      Potential $params are
100                 $params['distinct'] = use distinct key word
101                 $params['include_custom_fields'] = (on by default)
102                 $params['massupdate'] = true by default;
103         $params['handleMassupdate'] = true by default, have massupdate.php handle massupdates?
104          * @param string:'id' $id_field
105          */
106         function setup($seed, $file, $where, $params = array(), $offset = 0, $limit = -1,  $filter_fields = array(), $id_field = 'id') {
107         $this->should_process = true;
108         if(isset($seed->module_dir) && !$this->shouldProcess($seed->module_dir)){
109                         return false;
110         }
111         if(isset($params['export'])) {
112           $this->export = $params['export'];
113         }
114         if(!empty($params['multiSelectPopup'])) {
115                   $this->multi_select_popup = $params['multiSelectPopup'];
116         }
117                 if(!empty($params['massupdate']) && $params['massupdate'] != false) {
118                         $this->show_mass_update_form = true;
119                         $this->mass = new MassUpdate();
120                         $this->mass->setSugarBean($seed);
121                         if(!empty($params['handleMassupdate']) || !isset($params['handleMassupdate'])) {
122                 $this->mass->handleMassUpdate();
123             }
124                 }
125                 $this->seed = $seed;
126
127         $filter_fields = $this->setupFilterFields($filter_fields);
128
129         $data = $this->lvd->getListViewData($seed, $where, $offset, $limit, $filter_fields, $params, $id_field);
130
131                 foreach($this->displayColumns as $columnName => $def)
132                 {
133                         $seedName =  strtolower($columnName);
134             if(!empty($this->lvd->seed->field_defs[$seedName])){
135                 $seedDef = $this->lvd->seed->field_defs[$seedName];
136             }
137
138                         if(empty($this->displayColumns[$columnName]['type'])){
139                                 if(!empty($seedDef['type'])){
140                             $this->displayColumns[$columnName]['type'] = (!empty($seedDef['custom_type']))?$seedDef['custom_type']:$seedDef['type'];
141                         }else{
142                                 $this->displayColumns[$columnName]['type'] = '';
143                         }
144                         }//fi empty(...)
145
146                         if(!empty($seedDef['options'])){
147                                         $this->displayColumns[$columnName]['options'] = $seedDef['options'];
148                         }
149
150                 //C.L. Fix for 11177
151                 if($this->displayColumns[$columnName]['type'] == 'html') {
152                     $cField = $this->seed->custom_fields;
153                        if(isset($cField) && isset($cField->bean->$seedName)) {
154                                 $seedName2 = strtoupper($columnName);
155                                 $htmlDisplay = html_entity_decode($cField->bean->$seedName);
156                                 $count = 0;
157                                 while($count < count($data['data'])) {
158                                         $data['data'][$count][$seedName2] = &$htmlDisplay;
159                                     $count++;
160                                 }
161                         }
162                 }//fi == 'html'
163
164             //Bug 40511, make sure relate fields have the correct module defined
165             if ($this->displayColumns[$columnName]['type'] == "relate" && !empty($seedDef['link']) && empty( $this->displayColumns[$columnName]['module']))
166             {
167                 $link = $seedDef['link'];
168                 if (!empty($this->lvd->seed->field_defs[$link]) && !empty($this->lvd->seed->field_defs[$seedDef['link']]['module']))
169                 {
170                     $this->displayColumns[$columnName]['module'] = $this->lvd->seed->field_defs[$seedDef['link']]['module'];
171                 }
172             }
173
174                         if (!empty($seedDef['sort_on'])) {
175                         $this->displayColumns[$columnName]['orderBy'] = $seedDef['sort_on'];
176                     }
177
178             if(isset($seedDef)){
179                 // Merge the two arrays together, making sure the seedDef doesn't override anything explicitly set in the displayColumns array.
180                 $this->displayColumns[$columnName] = $this->displayColumns[$columnName] + $seedDef;
181             }
182
183                     //C.L. Bug 38388 - ensure that ['id'] is set for related fields
184             if(!isset($this->displayColumns[$columnName]['id']) && isset($this->displayColumns[$columnName]['id_name'])) {
185                $this->displayColumns[$columnName]['id'] = strtoupper($this->displayColumns[$columnName]['id_name']);
186             }
187                 }
188
189                 $this->process($file, $data, $seed->object_name);
190                 return true;
191         }
192
193         function setupFilterFields($filter_fields = array())
194         {
195                 // create filter fields based off of display columns
196         if(empty($filter_fields) || $this->mergeDisplayColumns) {
197             foreach($this->displayColumns as $columnName => $def) {
198
199                $filter_fields[strtolower($columnName)] = true;
200
201             if(isset($this->seed->field_defs[strtolower($columnName)]['type']) &&
202                strtolower($this->seed->field_defs[strtolower($columnName)]['type']) == 'currency' &&
203                isset($this->seed->field_defs['currency_id'])) {
204                     $filter_fields['currency_id'] = true;
205             }
206
207                if(!empty($def['related_fields'])) {
208                     foreach($def['related_fields'] as $field) {
209                         //id column is added by query construction function. This addition creates duplicates
210                         //and causes issues in oracle. #10165
211                         if ($field != 'id') {
212                             $filter_fields[$field] = true;
213                         }
214                     }
215                 }
216                 if (!empty($this->seed->field_defs[strtolower($columnName)]['db_concat_fields'])) {
217                     foreach($this->seed->field_defs[strtolower($columnName)]['db_concat_fields'] as $index=>$field){
218                         if(!isset($filter_fields[strtolower($field)]) || !$filter_fields[strtolower($field)])
219                         {
220                             $filter_fields[strtolower($field)] = true;
221                         }
222                     }
223                 }
224             }
225             foreach ($this->searchColumns as $columnName => $def )
226             {
227                 $filter_fields[strtolower($columnName)] = true;
228             }
229         }
230
231
232         return $filter_fields;
233         }
234
235
236         /**
237          * Any additional processing
238          * @param file File template file to use
239          * @param data array row data
240          * @param html_var string html string to be passed back and forth
241          */
242         function process($file, $data, $htmlVar) {
243                 $this->rowCount = count($data['data']);
244                 $this->moduleString = $data['pageData']['bean']['moduleDir'] . '2_' . strtoupper($htmlVar) . '_offset';
245         }
246
247         /**
248          * Display the listview
249          * @return string ListView contents
250          */
251         public function display() 
252         {
253                 if (!$this->should_process) {
254                     return '';
255                 }
256                 
257                 $str = '';
258                 if ($this->show_mass_update_form) {
259                         $str = $this->mass->getDisplayMassUpdateForm(true, $this->multi_select_popup).$this->mass->getMassUpdateFormHeader($this->multi_select_popup);
260                 }
261         
262                 return $str;
263         }
264         /**
265          * Display the select link
266      * @return string select link html
267          * @param echo Bool set true if you want it echo'd, set false to have contents returned
268          */
269         function buildSelectLink($id = 'select_link', $total=0, $pageTotal=0) {
270                 global $app_strings;
271                 if ($pageTotal < 0)
272                         $pageTotal = $total;
273                 $plus = '';
274                 if (!empty($GLOBALS['sugar_config']['disable_count_query']) && $total > $pageTotal) {
275                         $plus = '+';
276                         $this->show_plus = true;
277                 }
278
279
280                 $close_inline_img = SugarThemeRegistry::current()->getImage('close_inline', 'border=0', null, null, ".gif", $app_strings['LBL_CLOSEINLINE']);
281                 $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, $pageTotal)}else {sListView.check_all(document.MassUpdate, \"mass[]\", true)};\' href=\'#\'>{$app_strings['LBL_LISTVIEW_OPTION_CURRENT']}&nbsp;&#x28;{$pageTotal}&#x29;&#x200E;</a>"
282                         . "<a style=\'width: 150px\' name=\"selectall\" class=\'menuItem\' onmouseover=\'hiliteItem(this,\"yes\");\' onmouseout=\'unhiliteItem(this);\' onclick=\'sListView.check_entire_list(document.MassUpdate, \"mass[]\",true,{$total});\' href=\'#\'>{$app_strings['LBL_LISTVIEW_OPTION_ENTIRE']}&nbsp;&#x28;{$total}&#x29;&#x200E;</a>"
283                         . "<a style=\'width: 150px\' name=\"deselect\" class=\'menuItem\' onmouseover=\'hiliteItem(this,\"yes\");\' onmouseout=\'unhiliteItem(this);\' onclick=\'sListView.clear_all(document.MassUpdate, \"mass[]\", false);\' href=\'#\'>{$app_strings['LBL_LISTVIEW_NONE']}</a>";
284
285                 $script = <<<EOHTML
286 <script type="text/javascript">
287 function select_overlib() {
288         return overlib('{$script_href}', CENTER, STICKY, MOUSEOFF, 3000, CLOSETEXT, '{$close_inline_img}', WIDTH, 150, CLOSETITLE, "{$app_strings['LBL_ADDITIONAL_DETAILS_CLOSE_TITLE']}" , CLOSECLICK, FGCLASS, 'olOptionsFgClass', CGCLASS, 'olOptionsCgClass', BGCLASS, 'olBgClass', TEXTFONTCLASS, 'olFontClass', CAPTIONFONTCLASS, 'olOptionsCapFontClass', CLOSEFONTCLASS, 'olOptionsCloseFontClass',TIMEOUT,1000);
289 }
290 </script>
291 EOHTML;
292             $script .= "<a id='$id' onclick='return select_overlib();' href=\"#\">".SugarThemeRegistry::current()->getImage('MoreDetail', 'border=0', null, null, '.png', $app_strings['LBL_MOREDETAIL'])."</a>";
293
294                 return $script;
295         }
296
297
298
299
300         /**
301          * Display the actions link
302          *
303          * @param  string $id link id attribute, defaults to 'actions_link'
304          * @return string HTML source
305          */
306         protected function buildActionsLink(
307             $id = 'actions_link'
308             )
309         {
310             global $app_strings;
311                 $closeText = SugarThemeRegistry::current()->getImage('close_inline', 'border=0', null, null, ".gif", $app_strings['LBL_CLOSEINLINE']);
312                 $moreDetailImage = SugarThemeRegistry::current()->getImageURL('MoreDetail.png');
313                 $menuItems = '';
314
315                 // delete
316                 if ( ACLController::checkAccess($this->seed->module_dir,'delete',true) && $this->delete )
317                         $menuItems .= $this->buildDeleteLink();
318                 // compose email
319         if ( $this->email )
320                         $menuItems .= $this->buildComposeEmailLink($this->data['pageData']['offsets']['total']);
321                 // mass update
322                 $mass = new MassUpdate();
323                 $mass->setSugarBean($this->seed);
324                 if ( ( ACLController::checkAccess($this->seed->module_dir,'edit',true) && ACLController::checkAccess($this->seed->module_dir,'massupdate',true) ) && $this->showMassupdateFields && $mass->doMassUpdateFieldsExistForFocus() )
325             $menuItems .= $this->buildMassUpdateLink();
326                 // merge
327                 if ( $this->mailMerge )
328                     $menuItems .= $this->buildMergeLink();
329                 if ( $this->mergeduplicates )
330                     $menuItems .= $this->buildMergeDuplicatesLink();
331                 // add to target list
332                 if ( $this->targetList && ACLController::checkAccess('ProspectLists','edit',true) )
333                     $menuItems .= $this->buildTargetList();
334                 // export
335                 if ( ACLController::checkAccess($this->seed->module_dir,'export',true) && $this->export )
336                         $menuItems .= $this->buildExportLink();
337
338                 foreach ( $this->actionsMenuExtraItems as $item )
339                     $menuItems .= $item;
340
341                 $menuItems = str_replace('"','\"',$menuItems);
342                 $menuItems = str_replace(array("\r","\n"),'',$menuItems);
343
344                 if ( empty($menuItems) )
345                     return '';
346
347                 return <<<EOHTML
348 <script type="text/javascript">
349 <!--
350 function actions_overlib()
351 {
352     return overlib("{$menuItems}", CENTER, '', STICKY, MOUSEOFF, 3000, CLOSETEXT, '{$closeText}', WIDTH, 150,
353         CLOSETITLE, "{$app_strings['LBL_ADDITIONAL_DETAILS_CLOSE_TITLE']}", CLOSECLICK,
354         FGCLASS, 'olOptionsFgClass', CGCLASS, 'olOptionsCgClass', BGCLASS, 'olBgClass',
355         TEXTFONTCLASS, 'olFontClass', CAPTIONFONTCLASS, 'olOptionsCapFontClass',
356         CLOSEFONTCLASS, 'olOptionsCloseFontClass');
357 }
358 -->
359 </script>
360 <a id='$id' onclick='return actions_overlib();' href="#">
361     {$app_strings['LBL_LINK_ACTIONS']}&nbsp;<img src='{$moreDetailImage}' border='0' />
362 </a>
363 EOHTML;
364         }
365
366         /**
367          * Builds the export link
368          *
369          * @return string HTML
370          */
371         protected function buildExportLink()
372         {
373                 global $app_strings;
374                 return "<a href='javascript:void(0)' style='width: 150px' class='menuItem' onmouseover='hiliteItem(this,\"yes\");' onmouseout='unhiliteItem(this);' onclick=\"return sListView.send_form(true, '{$this->seed->module_dir}', 'index.php?entryPoint=export','{$app_strings['LBL_LISTVIEW_NO_SELECTED']}')\">{$app_strings['LBL_EXPORT']}</a>";
375         }
376
377         /**
378          * Builds the massupdate link
379          *
380          * @return string HTML
381          */
382         protected function buildMassUpdateLink()
383         {
384                 global $app_strings;
385
386                 return "<a href='javascript:void(0)' style='width: 150px' class='menuItem' onmouseover='hiliteItem(this,\"yes\");' onmouseout='unhiliteItem(this);' onclick=\"document.getElementById('massupdate_form').style.display = '';\">{$app_strings['LBL_MASS_UPDATE']}</a>";
387         }
388
389         /**
390          * Builds the compose email link
391          *
392          * @return string HTML
393          */
394         protected function buildComposeEmailLink(
395             $totalCount
396             )
397         {
398                 global $app_strings,$dictionary;
399
400         if (!is_array($this->seed->field_defs)) {
401             return '';
402         }
403         $foundEmailField = false;
404         // Search for fields that look like an email address
405         foreach ($this->seed->field_defs as $field) {
406             if(isset($field['type'])&&$field['type']=='link'
407                &&isset($field['relationship'])&&isset($dictionary[$this->seed->object_name]['relationships'][$field['relationship']])
408                &&$dictionary[$this->seed->object_name]['relationships'][$field['relationship']]['rhs_module']=='EmailAddresses') {
409                 $foundEmailField = true;
410                 break;
411             }
412         }
413         if (!$foundEmailField) {
414             return '';
415         }
416
417
418                 $userPref = $GLOBALS['current_user']->getPreference('email_link_type');
419                 $defaultPref = $GLOBALS['sugar_config']['email_default_client'];
420                 if($userPref != '')
421                         $client = $userPref;
422                 else
423                         $client = $defaultPref;
424
425                 if($client == 'sugar')
426                         $script = "<a href='javascript:void(0)' style='width: 150px' class='menuItem' onmouseover='hiliteItem(this,\"yes\");' onmouseout='unhiliteItem(this);' " .
427                                         'onclick="return sListView.send_form_for_emails(true, \''."Emails".'\', \'index.php?module=Emails&action=Compose&ListView=true\',\''.$app_strings['LBL_LISTVIEW_NO_SELECTED'].'\', \''.$this->seed->module_dir.'\', \''.$totalCount.'\', \''.$app_strings['LBL_LISTVIEW_LESS_THAN_TEN_SELECT'].'\')">' .
428                                         $app_strings['LBL_EMAIL_COMPOSE'] . '</a>';
429                 else
430                         $script = "<a href='javascript:void(0)' style='width: 150px' class='menuItem' onmouseover='hiliteItem(this,\"yes\");' onmouseout='unhiliteItem(this);' " .
431                                         "onclick=\"return sListView.use_external_mail_client('{$app_strings['LBL_LISTVIEW_NO_SELECTED']}', '{$_REQUEST['module']}');\">" .
432                                         $app_strings['LBL_EMAIL_COMPOSE'] . '</a>';
433
434                 return $script;
435         } // fn
436         /**
437          * Builds the delete link
438          *
439          * @return string HTML
440          */
441         protected function buildDeleteLink()
442         {
443                 global $app_strings;
444
445                 return "<a href='javascript:void(0)' style='width: 150px' class='menuItem' onmouseover='hiliteItem(this,\"yes\");' onmouseout='unhiliteItem(this);' onclick=\"return sListView.send_mass_update('selected', '{$app_strings['LBL_LISTVIEW_NO_SELECTED']}', 1)\">{$app_strings['LBL_DELETE_BUTTON_LABEL']}</a>";
446         }
447         /**
448          * Display the selected object span object
449          *
450      * @return string select object span
451          */
452         function buildSelectedObjectsSpan($echo = true, $total=0) {
453                 global $app_strings;
454
455                 $selectedObjectSpan = "<span style='display: inline-block;'>{$app_strings['LBL_LISTVIEW_SELECTED_OBJECTS']}<input  style='border: 0px; background: transparent; font-size: inherit; color: inherit' type='text' id='selectCountTop' readonly name='selectCount[]' value='{$total}' /></span>";
456
457         return $selectedObjectSpan;
458         }
459     /**
460          * Builds the mail merge link
461          * The link can be disabled by setting module level duplicate_merge property to false
462          * in the moudle's vardef file.
463          *
464          * @return string HTML
465          */
466         protected function buildMergeDuplicatesLink()
467         {
468         global $app_strings, $dictionary;
469
470         $return_string='';
471         $return_string.= isset($_REQUEST['module']) ? "&return_module={$_REQUEST['module']}" : "";
472         $return_string.= isset($_REQUEST['action']) ? "&return_action={$_REQUEST['action']}" : "";
473         $return_string.= isset($_REQUEST['record']) ? "&return_id={$_REQUEST['record']}" : "";
474         //need delete and edit access.
475                 if (!(ACLController::checkAccess($this->seed->module_dir, 'edit', true)) or !(ACLController::checkAccess($this->seed->module_dir, 'delete', true))) {
476                         return '';
477                 }
478
479         if (isset($dictionary[$this->seed->object_name]['duplicate_merge']) && $dictionary[$this->seed->object_name]['duplicate_merge']==true ) {
480             return "<a href='javascript:void(0)' style='width: 150px' class='menuItem' onmouseover='hiliteItem(this,\"yes\");' onmouseout='unhiliteItem(this);' ".
481                 "onclick='if (sugarListView.get_checks_count()> 1) {sListView.send_form(true, \"MergeRecords\", \"index.php\", \"{$app_strings['LBL_LISTVIEW_NO_SELECTED']}\", \"{$this->seed->module_dir}\",\"$return_string\");} else {alert(\"{$app_strings['LBL_LISTVIEW_TWO_REQUIRED']}\");return false;}'>".
482                 $app_strings['LBL_MERGE_DUPLICATES'].'</a>';
483         }
484
485         return '';
486      }
487     /**
488          * Builds the mail merge link
489          *
490          * @return string HTML
491          */
492         protected function buildMergeLink(array $modules_array = null)
493         {
494         if ( empty($modules_array) ) {
495             require('modules/MailMerge/modules_array.php');
496         }
497         global $current_user, $app_strings;
498
499         $admin = new Administration();
500         $admin->retrieveSettings('system');
501         $user_merge = $current_user->getPreference('mailmerge_on');
502         $module_dir = (!empty($this->seed->module_dir) ? $this->seed->module_dir : '');
503         $str = '';
504         
505         if ($user_merge == 'on' && isset($admin->settings['system_mailmerge_on']) && $admin->settings['system_mailmerge_on'] && !empty($modules_array[$module_dir])) {
506             $str = "<a href='javascript:void(0)' style='width: 150px' class='menuItem' onmouseover='hiliteItem(this,\"yes\");' onmouseout='unhiliteItem(this);' " .
507                                         'onclick="if (document.MassUpdate.select_entire_list.value==1){document.location.href=\'index.php?action=index&module=MailMerge&entire=true\'} else {return sListView.send_form(true, \'MailMerge\',\'index.php\',\''.$app_strings['LBL_LISTVIEW_NO_SELECTED'].'\');}">' .
508                                         $app_strings['LBL_MAILMERGE'].'</a>';
509         }
510         return $str;
511         }
512
513         /**
514          * Builds the add to target list link
515          *
516      * @return string HTML
517          */
518         protected function buildTargetList()
519         {
520         global $app_strings;
521                 unset($_REQUEST[session_name()]);
522                 unset($_REQUEST['PHPSESSID']);
523         $current_query_by_page = base64_encode(serialize($_REQUEST));
524
525                 $js = <<<EOF
526             if(sugarListView.get_checks_count() < 1) {
527                 alert('{$app_strings['LBL_LISTVIEW_NO_SELECTED']}');
528                 return false;
529             }
530                         if ( document.forms['targetlist_form'] ) {
531                                 var form = document.forms['targetlist_form'];
532                                 form.reset;
533                         } else
534                                 var form = document.createElement ( 'form' ) ;
535                         form.setAttribute ( 'name' , 'targetlist_form' );
536                         form.setAttribute ( 'method' , 'post' ) ;
537                         form.setAttribute ( 'action' , 'index.php' );
538                         document.body.appendChild ( form ) ;
539                         if ( !form.module ) {
540                             var input = document.createElement('input');
541                             input.setAttribute ( 'name' , 'module' );
542                             input.setAttribute ( 'value' , '{$this->seed->module_dir}' );
543                             input.setAttribute ( 'type' , 'hidden' );
544                             form.appendChild ( input ) ;
545                             var input = document.createElement('input');
546                             input.setAttribute ( 'name' , 'action' );
547                             input.setAttribute ( 'value' , 'TargetListUpdate' );
548                             input.setAttribute ( 'type' , 'hidden' );
549                             form.appendChild ( input ) ;
550                         }
551                         if ( !form.uids ) {
552                             var input = document.createElement('input');
553                             input.setAttribute ( 'name' , 'uids' );
554                             input.setAttribute ( 'type' , 'hidden' );
555                             form.appendChild ( input ) ;
556                         }
557                         if ( !form.prospect_list ) {
558                             var input = document.createElement('input');
559                             input.setAttribute ( 'name' , 'prospect_list' );
560                             input.setAttribute ( 'type' , 'hidden' );
561                             form.appendChild ( input ) ;
562                         }
563                         if ( !form.return_module ) {
564                             var input = document.createElement('input');
565                             input.setAttribute ( 'name' , 'return_module' );
566                             input.setAttribute ( 'type' , 'hidden' );
567                             form.appendChild ( input ) ;
568                         }
569                         if ( !form.return_action ) {
570                             var input = document.createElement('input');
571                             input.setAttribute ( 'name' , 'return_action' );
572                             input.setAttribute ( 'type' , 'hidden' );
573                             form.appendChild ( input ) ;
574                         }
575                         if ( !form.select_entire_list ) {
576                             var input = document.createElement('input');
577                             input.setAttribute ( 'name' , 'select_entire_list' );
578                             input.setAttribute ( 'value', document.MassUpdate.select_entire_list.value);
579                             input.setAttribute ( 'type' , 'hidden' );
580                             form.appendChild ( input ) ;
581                         }
582                         if ( !form.current_query_by_page ) {
583                             var input = document.createElement('input');
584                             input.setAttribute ( 'name' , 'current_query_by_page' );
585                             input.setAttribute ( 'value', '{$current_query_by_page}' );
586                             input.setAttribute ( 'type' , 'hidden' );
587                             form.appendChild ( input ) ;
588                         }
589                         open_popup('ProspectLists','600','400','',true,false,{ 'call_back_function':'set_return_and_save_targetlist','form_name':'targetlist_form','field_to_name_array':{'id':'prospect_list'} } );
590 EOF;
591         $js = str_replace(array("\r","\n"),'',$js);
592         return "<a href='javascript:void(0)' style='width: 150px' class='menuItem' onmouseover='hiliteItem(this,\"yes\");' onmouseout='unhiliteItem(this);' onclick=\"$js\">{$app_strings['LBL_ADD_TO_PROSPECT_LIST_BUTTON_LABEL']}</a>";
593         }
594         /**
595          * Display the bottom of the ListView (ie MassUpdate
596          * @return string contents
597          */
598         public function displayEnd() 
599         {
600                 $str = '';
601                 if($this->show_mass_update_form) {
602                         $str .= $this->mass->getMassUpdateForm(true);
603                         $str .= $this->mass->endMassUpdateForm();
604                 }
605
606                 return $str;
607         }
608
609     /**
610      * Display the multi select data box etc.
611      * @return string contents
612      */
613         public function getMultiSelectData() 
614         {
615                 $str = "<script>YAHOO.util.Event.addListener(window, \"load\", sListView.check_boxes);</script>\n";
616
617                 $massUpdateRun = isset($_REQUEST['massupdate']) && $_REQUEST['massupdate'] == 'true';
618                 $uids = empty($_REQUEST['uid']) || $massUpdateRun ? '' : $_REQUEST['uid'];
619                 $select_entire_list = isset($_REQUEST['select_entire_list']) && !$massUpdateRun ? $_REQUEST['select_entire_list'] : 0;
620
621                 $str .= "<textarea style='display: none' name='uid'>{$uids}</textarea>\n" .
622                                 "<input type='hidden' name='select_entire_list' value='{$select_entire_list}'>\n".
623                                 "<input type='hidden' name='{$this->moduleString}' value='0'>\n".
624                         "<input type='hidden' name='show_plus' value='{$this->show_plus}'>\n";
625                 return $str;
626         }
627
628 }
629 ?>