Passed
Push — scrutinizer-code-quality ( 09f5a1...c4c5fb )
by Adam
56:05 queued 14:08
created

ListViewDisplay::buildActionsLink()   F

Complexity

Conditions 15
Paths 256

Size

Total Lines 43
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 26
CRAP Score 15.0818
Metric Value
cc 15
eloc 30
nc 256
nop 2
dl 0
loc 43
ccs 26
cts 28
cp 0.9286
crap 15.0818
rs 3.7313

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2 1
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-2013 SugarCRM Inc.
6
7
 * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd.
8
 * Copyright (C) 2011 - 2014 Salesagility Ltd.
9
 *
10
 * This program is free software; you can redistribute it and/or modify it under
11
 * the terms of the GNU Affero General Public License version 3 as published by the
12
 * Free Software Foundation with the addition of the following permission added
13
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
14
 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
15
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
16
 *
17
 * This program is distributed in the hope that it will be useful, but WITHOUT
18
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19
 * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
20
 * details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License along with
23
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
24
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25
 * 02110-1301 USA.
26
 *
27
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
28
 * SW2-130, Cupertino, CA 95014, USA. or at email address [email protected].
29
 *
30
 * The interactive user interfaces in modified source and object code versions
31
 * of this program must display Appropriate Legal Notices, as required under
32
 * Section 5 of the GNU Affero General Public License version 3.
33
 *
34
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
35
 * these Appropriate Legal Notices must retain the display of the "Powered by
36
 * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
37
 * reasonably feasible for  technical reasons, the Appropriate Legal Notices must
38
 * display the words  "Powered by SugarCRM" and "Supercharged by SuiteCRM".
39
 ********************************************************************************/
40
41
42
43
44 1
require_once('include/ListView/ListViewData.php');
45 1
require_once('include/MassUpdate.php');
46
47
class ListViewDisplay {
48
    static $listViewCounter = 0;
49
50
	var $show_mass_update_form = false;
51
	var $show_action_dropdown = true;
52
	var $rowCount;
53
	var $mass = null;
54
	var $seed;
55
	var $multi_select_popup;
56
	var $lvd;
57
	var $moduleString;
58
	var $export = true;
59
	var $multiSelect = true;
60
	var $mailMerge = true;
61
	var $should_process = true;
62
	var $show_plus = false;
63
	/*
64
	 * Used in view.popup.php. Sometimes there are fields on the search form that are not referenced in the listviewdefs. If this
65
	 * is the case, then the filterFields will be set and the related fields will not be referenced when calling create_new_list_query.
66
	 */
67
	var $mergeDisplayColumns = false;
68
    public $actionsMenuExtraItems = array();
69
70
	/**
71
	 * Constructor
72
	 */
73 5
	public function __construct() {
74 5
		$this->lvd = new ListViewData();
75 5
		$this->searchColumns = array () ;
76 5
	}
77
78
    /**
79
     * @deprecated deprecated since version 7.6, PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code, use __construct instead
80
     */
81
    public function ListViewDisplay(){
82
        $deprecatedMessage = 'PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code';
83
        if(isset($GLOBALS['log'])) {
84
            $GLOBALS['log']->deprecated($deprecatedMessage);
85
        }
86
        else {
87
            trigger_error($deprecatedMessage, E_USER_DEPRECATED);
88
        }
89
        self::__construct();
90
    }
91
92
93 3
	function shouldProcess($moduleDir){
94 3
		$searching = false;
95 3
		$sessionSearchQuery = "{$moduleDir}2_QUERY_QUERY";
96 3
		if (!empty($_SESSION[$sessionSearchQuery])) {
97
			$searching = true;
98
		}
99 3
		if(!empty($GLOBALS['sugar_config']['save_query']) && $GLOBALS['sugar_config']['save_query'] == 'populate_only'){
100
		    if(empty($GLOBALS['displayListView'])
101
		            && (!empty($_REQUEST['clear_query'])
102
		                || $_REQUEST['module'] == $moduleDir
103
		                    && ((empty($_REQUEST['query']) || $_REQUEST['query'] == 'MSI' )
104
		                        && (!$searching)))) {
105
				$_SESSION['last_search_mod'] = $_REQUEST['module'] ;
106
				$this->should_process = false;
107
				return false;
108
			}
109
		}
110 3
		$this->should_process = true;
111 3
		return true;
112
	}
113
114
	/**
115
	 * Setup the class
116
	 * @param seed SugarBean Seed SugarBean to use
117
	 * @param file File Template file to use
118
	 * @param string $where
119
	 * @param offset:0 int offset to start at
120
	 * @param int:-1 $limit
0 ignored issues
show
Documentation introduced by
The doc-type int:-1 could not be parsed: Unknown type name "int:-1" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
121
	 * @param string[]:array() $filter_fields
0 ignored issues
show
Documentation introduced by
The doc-type string[]:array() could not be parsed: Expected "|" or "end of type", but got ":array" at position 8. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
122
	 * @param array:array() $params
0 ignored issues
show
Documentation introduced by
The doc-type array:array() could not be parsed: Unknown type name "array:array" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
123
	 * 	Potential $params are
124
		$params['distinct'] = use distinct key word
125
		$params['include_custom_fields'] = (on by default)
126
		$params['massupdate'] = true by default;
127
        $params['handleMassupdate'] = true by default, have massupdate.php handle massupdates?
128
	 * @param string:'id' $id_field
0 ignored issues
show
Documentation introduced by
The doc-type string:'id' could not be parsed: Unknown type name "string:'id'" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
129
	 */
130 3
	function setup($seed, $file, $where, $params = array(), $offset = 0, $limit = -1,  $filter_fields = array(), $id_field = 'id') {
131 3
        $this->should_process = true;
132 3
        if(isset($seed->module_dir) && !$this->shouldProcess($seed->module_dir)){
133
        		return false;
134
        }
135 3
        if(isset($params['export'])) {
136
          $this->export = $params['export'];
137
        }
138 3
        if(!empty($params['multiSelectPopup'])) {
139
		  $this->multi_select_popup = $params['multiSelectPopup'];
140
        }
141 3
		if(!empty($params['massupdate']) && $params['massupdate'] != false) {
142 1
			$this->show_mass_update_form = true;
143 1
			$this->mass = $this->getMassUpdate();
144 1
			$this->mass->setSugarBean($seed);
145 1
			if(!empty($params['handleMassupdate']) || !isset($params['handleMassupdate'])) {
146 1
                $this->mass->handleMassUpdate();
147
            }
148
		}
149 3
		$this->seed = $seed;
150
151 3
        $filter_fields = $this->setupFilterFields($filter_fields);
152
153 3
        $data = $this->lvd->getListViewData($seed, $where, $offset, $limit, $filter_fields, $params, $id_field);
154
155 3
        $this->fillDisplayColumnsWithVardefs();
156
157 3
		$this->process($file, $data, $seed->object_name);
158 3
		return true;
159
	}
160
161 3
	function setupFilterFields($filter_fields = array())
162
	{
163
		// create filter fields based off of display columns
164 3
        if(empty($filter_fields) || $this->mergeDisplayColumns) {
165 3
            foreach($this->displayColumns as $columnName => $def) {
166
167 1
               $filter_fields[strtolower($columnName)] = true;
168
169 1
            if(isset($this->seed->field_defs[strtolower($columnName)]['type']) &&
170 1
               strtolower($this->seed->field_defs[strtolower($columnName)]['type']) == 'currency' &&
171 1
               isset($this->seed->field_defs['currency_id'])) {
172
                    $filter_fields['currency_id'] = true;
173
            }
174
175 1
               if(!empty($def['related_fields'])) {
176 1
                    foreach($def['related_fields'] as $field) {
177
                        //id column is added by query construction function. This addition creates duplicates
178
                        //and causes issues in oracle. #10165
179 1
                        if ($field != 'id') {
180 1
                            $filter_fields[$field] = true;
181
                        }
182
                    }
183
                }
184 1
                if (!empty($this->seed->field_defs[strtolower($columnName)]['db_concat_fields'])) {
185
                    foreach($this->seed->field_defs[strtolower($columnName)]['db_concat_fields'] as $index=>$field){
186
                        if(!isset($filter_fields[strtolower($field)]) || !$filter_fields[strtolower($field)])
187
                        {
188 1
                            $filter_fields[strtolower($field)] = true;
189
                        }
190
                    }
191
                }
192
            }
193 3
            foreach ($this->searchColumns as $columnName => $def )
194
            {
195
                $filter_fields[strtolower($columnName)] = true;
196
            }
197
        }
198
199
200 3
        return $filter_fields;
201
	}
202
203
204
	/**
205
	 * Any additional processing
206
	 * @param file File template file to use
207
	 * @param data array row data
208
	 * @param html_var string html string to be passed back and forth
209
	 */
210 4
	function process($file, $data, $htmlVar) {
211 4
		$this->rowCount = count($data['data']);
212 4
		$this->moduleString = $data['pageData']['bean']['moduleDir'] . '2_' . strtoupper($htmlVar) . '_offset';
213 4
	}
214
215
	/**
216
	 * Display the listview
217
	 * @return string ListView contents
218
	 */
219 3
	public function display()
220
	{
221 3
		if (!$this->should_process) {
222
		    return '';
223
		}
224
225 3
		$str = '';
226 3
		if ($this->show_mass_update_form) {
227 1
			$str = $this->mass->getDisplayMassUpdateForm(true, $this->multi_select_popup).$this->mass->getMassUpdateFormHeader($this->multi_select_popup);
228
		}
229
230 3
		return $str;
231
	}
232
	/**
233
	 * Display the select link
234
     * @return string select link html
235
	 * @param echo Bool set true if you want it echo'd, set false to have contents returned
236
	 */
237 4
	function buildSelectLink($id = 'select_link', $total=0, $pageTotal=0, $location="top") {
238 4
		global $app_strings;
239 4
		if ($pageTotal < 0)
240
			$pageTotal = $total;
241
242
243 4
        $total_label = "";
244 4
        if (!empty($GLOBALS['sugar_config']['disable_count_query']) && $GLOBALS['sugar_config']['disable_count_query'] === true && $total > $pageTotal) {
245
            $this->show_plus = true;
246
            $total_label =  $pageTotal.'+';
247
            $total = $pageTotal;
248
        } else {
249 4
            $total_label = $total;
250
        }
251
252 4
		$close_inline_img = SugarThemeRegistry::current()->getImage('close_inline', 'border=0', null, null, ".gif", $app_strings['LBL_CLOSEINLINE']);
253
		$menuItems = array(
254 4
            "<input title=\"".$app_strings['LBL_SELECT_ALL_TITLE']."\" type='checkbox' class='checkbox massall' name='massall' id='massall_".$location."' value='' onclick='sListView.check_all(document.MassUpdate, \"mass[]\", this.checked);' /><a id='$id'  href='javascript: void(0);'></a>",
255 4
            "<a  name='thispage' id='button_select_this_page_".$location."' 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>",
256 4
            "<a  name='selectall' id='button_select_all_".$location."' 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_label}&#x29;&#x200E;</a>",
257 4
            "<a name='deselect' id='button_deselect_".$location."' class='menuItem' onmouseover='hiliteItem(this,\"yes\");' onmouseout='unhiliteItem(this);' onclick='sListView.clear_all(document.MassUpdate, \"mass[]\", false);' href='#'>{$app_strings['LBL_LISTVIEW_NONE']}</a>",
258
        );
259
260
        $link = array(
261 4
            'class' => 'clickMenu selectmenu',
262 4
            'id' => 'selectLink',
263 4
            'buttons' => $menuItems,
264
            'flat' => false,
265
        );
266 4
        return $link;
267
	}
268
269
	/**
270
	 * Display the actions link
271
	 *
272
	 * @param  string $id link id attribute, defaults to 'actions_link'
273
	 * @return string HTML source
274
	 */
275 4
	protected function buildActionsLink($id = 'actions_link', $location = 'top')
276
	{
277 4
	    global $app_strings;
278 4
		$closeText = SugarThemeRegistry::current()->getImage('close_inline', 'border=0', null, null, ".gif", $app_strings['LBL_CLOSEINLINE']);
279 4
		$moreDetailImage = SugarThemeRegistry::current()->getImageURL('MoreDetail.png');
280 4
		$menuItems = array();
281
282
		// delete
283 4
		if ( ACLController::checkAccess($this->seed->module_dir,'delete',true) && $this->delete )
284 4
			$menuItems[] = $this->buildDeleteLink($location);
285
		// compose email
286 4
        if ( $this->email )
287 4
			$menuItems[] = $this->buildComposeEmailLink($this->data['pageData']['offsets']['total'], $location);
288
		// mass update
289 4
		$mass = $this->getMassUpdate();
290 4
		$mass->setSugarBean($this->seed);
291 4
		if ( ( ACLController::checkAccess($this->seed->module_dir,'edit',true) && ACLController::checkAccess($this->seed->module_dir,'massupdate',true) ) && $this->showMassupdateFields && $mass->doMassUpdateFieldsExistForFocus() )
292 4
            $menuItems[] = $this->buildMassUpdateLink($location);
293
		// merge
294 4
		if ( $this->mailMerge )
295 4
		    $menuItems[] = $this->buildMergeLink(null, $location);
296 4
		if ( $this->mergeduplicates )
297 3
		    $menuItems[] = $this->buildMergeDuplicatesLink($location);
298
		// add to target list
299 4
		if ( $this->targetList && ACLController::checkAccess('ProspectLists','edit',true) )
300
		    $menuItems[] = $this->buildTargetList($location);
301
		// export
302 4
		if ( ACLController::checkAccess($this->seed->module_dir,'export',true) && $this->export )
303 2
			$menuItems[] = $this->buildExportLink($location);
304
305 4
		foreach ( $this->actionsMenuExtraItems as $item )
306
		    $menuItems[] = $item;
307
308
        $link = array(
309 4
            'class' => 'clickMenu selectActions fancymenu',
310 4
            'id' => 'selectActions',
311 4
            'name' => 'selectActions',
312 4
            'buttons' => $menuItems,
313
            'flat' => false,
314
        );
315 4
        return $link;
316
317
}
318
	/**
319
	 * Builds the export link
320
	 *
321
	 * @return string HTML
322
	 */
323 2
	protected function buildExportLink($loc = 'top')
324
	{
325 2
		global $app_strings;
326 2
		return "<a href='javascript:void(0)' id=\"export_listview_". $loc ." \" 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>";
327
    }
328
329
	/**
330
	 * Builds the massupdate link
331
	 *
332
	 * @return string HTML
333
	 */
334 4
	protected function buildMassUpdateLink($loc = 'top')
335
	{
336 4
		global $app_strings;
337
338 4
        $onClick = "document.getElementById('massupdate_form').style.display = ''; var yLoc = YAHOO.util.Dom.getY('massupdate_form'); scroll(0,yLoc);";
339 4
		return "<a href='javascript:void(0)' id=\"massupdate_listview_". $loc ."\" onclick=\"$onClick\">{$app_strings['LBL_MASS_UPDATE']}</a>";
340
341
	}
342
343
	/**
344
	 * Builds the compose email link
345
	 *
346
	 * @return string HTML
347
	 */
348 4
	protected function buildComposeEmailLink($totalCount, $loc = 'top')
349
	{
350 4
		global $app_strings,$dictionary;
351
352 4
        if (!is_array($this->seed->field_defs)) {
353
            return '';
354
        }
355 4
        $foundEmailField = false;
356
        // Search for fields that look like an email address
357 4
        foreach ($this->seed->field_defs as $field) {
358 4
            if(isset($field['type'])&&$field['type']=='link'
359 4
               &&isset($field['relationship'])&&isset($dictionary[$this->seed->object_name]['relationships'][$field['relationship']])
360 4
               &&$dictionary[$this->seed->object_name]['relationships'][$field['relationship']]['rhs_module']=='EmailAddresses') {
361 3
                $foundEmailField = true;
362 4
                break;
363
            }
364
        }
365 4
        if (!$foundEmailField) {
366 1
            return '';
367
        }
368
369
370 3
		$userPref = $GLOBALS['current_user']->getPreference('email_link_type');
371 3
		$defaultPref = $GLOBALS['sugar_config']['email_default_client'];
372 3
		if($userPref != '')
373 3
			$client = $userPref;
374
		else
375
			$client = $defaultPref;
376
377 3
		if($client == 'sugar')
378
			$script = "<a href='javascript:void(0)' " .
379 3
                    "id=\"composeemail_listview_". $loc ."\"".
380 3
					'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'].'\')">' .
381 3
					$app_strings['LBL_EMAIL_COMPOSE'] . '</a>';
382
		else
383
			$script = "<a href='javascript:void(0)' " .
384
                    "id=\"composeemail_listview_". $loc ."\"".
385
					"onclick=\"return sListView.use_external_mail_client('{$app_strings['LBL_LISTVIEW_NO_SELECTED']}', '{$_REQUEST['module']}');\">" .
386
					$app_strings['LBL_EMAIL_COMPOSE'] . '</a>';
387
388 3
        return $script;
389
	} // fn
390
	/**
391
	 * Builds the delete link
392
	 *
393
	 * @return string HTML
394
	 */
395 4
	protected function buildDeleteLink($loc = 'top')
396
	{
397 4
		global $app_strings;
398 4
        return "<a href='javascript:void(0)' id=\"delete_listview_". $loc ."\" onclick=\"return sListView.send_mass_update('selected', '{$app_strings['LBL_LISTVIEW_NO_SELECTED']}', 1)\">{$app_strings['LBL_DELETE_BUTTON_LABEL']}</a>";
399
	}
400
	/**
401
	 * Display the selected object span object
402
	 *
403
     * @return string select object span
404
	 */
405 2
	function buildSelectedObjectsSpan($echo = true, $total=0) {
406 2
		global $app_strings;
407
408 2
        $displayStyle = $total > 0 ? "" : "display: none;";
409 2
		$selectedObjectSpan = "<span style='$displayStyle' id='selectedRecordsTop'>{$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>";
410
411 2
        return $selectedObjectSpan;
412
	}
413
    /**
414
	 * Builds the mail merge link
415
	 * The link can be disabled by setting module level duplicate_merge property to false
416
	 * in the moudle's vardef file.
417
	 *
418
	 * @return string HTML
419
	 */
420 3
	protected function buildMergeDuplicatesLink($loc = 'top')
421
	{
422 3
        global $app_strings, $dictionary;
423
424 3
        $return_string='';
425 3
        $return_string.= isset($_REQUEST['module']) ? "&return_module={$_REQUEST['module']}" : "";
426 3
        $return_string.= isset($_REQUEST['action']) ? "&return_action={$_REQUEST['action']}" : "";
427 3
        $return_string.= isset($_REQUEST['record']) ? "&return_id={$_REQUEST['record']}" : "";
428
        //need delete and edit access.
429 3
		if (!(ACLController::checkAccess($this->seed->module_dir, 'edit', true)) or !(ACLController::checkAccess($this->seed->module_dir, 'delete', true))) {
430
			return "";
431
		}
432
433 3
        if (isset($dictionary[$this->seed->object_name]['duplicate_merge']) && $dictionary[$this->seed->object_name]['duplicate_merge']==true ) {
434
            return "<a href='javascript:void(0)' ".
435
                            "id='mergeduplicates_listview_". $loc ."'".
436
                            "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;}'>".
437
                            $app_strings['LBL_MERGE_DUPLICATES'].'</a>';
438
        }
439
440 3
        return "";
441
     }
442
    /**
443
	 * Builds the mail merge link
444
	 *
445
	 * @return string HTML
446
	 */
447 4
	protected function buildMergeLink(array $modules_array = null, $loc = 'top')
448
	{
449 4
        if ( empty($modules_array) ) {
450 4
            require('modules/MailMerge/modules_array.php');
451
        }
452 4
        global $current_user, $app_strings;
453
454 4
        $admin = new Administration();
455 4
        $admin->retrieveSettings('system');
456 4
        $user_merge = $current_user->getPreference('mailmerge_on');
457 4
        $module_dir = (!empty($this->seed->module_dir) ? $this->seed->module_dir : '');
458 4
        $str = '';
459
460 4
        if ($user_merge == 'on' && isset($admin->settings['system_mailmerge_on']) && $admin->settings['system_mailmerge_on'] && !empty($modules_array[$module_dir])) {
461
            return "<a href='javascript:void(0)'  " .
462
                    "id='merge_listview_". $loc ."'"  .
463
					'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'].'\');}">' .
464
					$app_strings['LBL_MAILMERGE'].'</a>';
465
        }
466 4
        return $str;
467
	}
468
469
	/**
470
	 * Builds the add to target list link
471
	 *
472
     * @return string HTML
473
	 */
474
	protected function buildTargetList($loc = 'top')
475
	{
476
        global $app_strings;
477
		unset($_REQUEST[session_name()]);
478
		unset($_REQUEST['PHPSESSID']);
479
        $current_query_by_page = base64_encode(serialize($_REQUEST));
480
481
		$js = <<<EOF
482
            if(sugarListView.get_checks_count() < 1) {
483
                alert('{$app_strings['LBL_LISTVIEW_NO_SELECTED']}');
484
                return false;
485
            }
486
			if ( document.forms['targetlist_form'] ) {
487
				var form = document.forms['targetlist_form'];
488
				form.reset;
489
			} else
490
				var form = document.createElement ( 'form' ) ;
491
			form.setAttribute ( 'name' , 'targetlist_form' );
492
			form.setAttribute ( 'method' , 'post' ) ;
493
			form.setAttribute ( 'action' , 'index.php' );
494
			document.body.appendChild ( form ) ;
495
			if ( !form.module ) {
496
			    var input = document.createElement('input');
497
			    input.setAttribute ( 'name' , 'module' );
498
			    input.setAttribute ( 'value' , '{$this->seed->module_dir}' );
499
			    input.setAttribute ( 'type' , 'hidden' );
500
			    form.appendChild ( input ) ;
501
			    var input = document.createElement('input');
502
			    input.setAttribute ( 'name' , 'action' );
503
			    input.setAttribute ( 'value' , 'TargetListUpdate' );
504
			    input.setAttribute ( 'type' , 'hidden' );
505
			    form.appendChild ( input ) ;
506
			}
507
			if ( !form.uids ) {
508
			    var input = document.createElement('input');
509
			    input.setAttribute ( 'name' , 'uids' );
510
			    input.setAttribute ( 'type' , 'hidden' );
511
			    form.appendChild ( input ) ;
512
			}
513
			if ( !form.prospect_list ) {
514
			    var input = document.createElement('input');
515
			    input.setAttribute ( 'name' , 'prospect_list' );
516
			    input.setAttribute ( 'type' , 'hidden' );
517
			    form.appendChild ( input ) ;
518
			}
519
			if ( !form.return_module ) {
520
			    var input = document.createElement('input');
521
			    input.setAttribute ( 'name' , 'return_module' );
522
			    input.setAttribute ( 'type' , 'hidden' );
523
			    form.appendChild ( input ) ;
524
			}
525
			if ( !form.return_action ) {
526
			    var input = document.createElement('input');
527
			    input.setAttribute ( 'name' , 'return_action' );
528
			    input.setAttribute ( 'type' , 'hidden' );
529
			    form.appendChild ( input ) ;
530
			}
531
			if ( !form.select_entire_list ) {
532
			    var input = document.createElement('input');
533
			    input.setAttribute ( 'name' , 'select_entire_list' );
534
			    input.setAttribute ( 'value', document.MassUpdate.select_entire_list.value);
535
			    input.setAttribute ( 'type' , 'hidden' );
536
			    form.appendChild ( input ) ;
537
			}
538
			if ( !form.current_query_by_page ) {
539
			    var input = document.createElement('input');
540
			    input.setAttribute ( 'name' , 'current_query_by_page' );
541
			    input.setAttribute ( 'value', '{$current_query_by_page}' );
542
			    input.setAttribute ( 'type' , 'hidden' );
543
			    form.appendChild ( input ) ;
544
			}
545
			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'} } );
546
EOF;
547
        $js = str_replace(array("\r","\n"),'',$js);
548
        return "<a href='javascript:void(0)' id=\"targetlist_listview_". $loc ." \" onclick=\"$js\">{$app_strings['LBL_ADD_TO_PROSPECT_LIST_BUTTON_LABEL']}</a>";
549
	}
550
	/**
551
	 * Display the bottom of the ListView (ie MassUpdate
552
	 * @return string contents
553
	 */
554
	public function displayEnd()
555
	{
556
		$str = '';
557
		if($this->show_mass_update_form) {
558
			$str .= $this->mass->getMassUpdateForm(true);
559
			$str .= $this->mass->endMassUpdateForm();
560
		}
561
562
		return $str;
563
	}
564
565
    /**
566
     * Display the multi select data box etc.
567
     * @return string contents
568
     */
569 2
	public function getMultiSelectData()
570
	{
571 2
		$str = "<script>YAHOO.util.Event.addListener(window, \"load\", sListView.check_boxes);</script>\n";
572
573 2
		$massUpdateRun = isset($_REQUEST['massupdate']) && $_REQUEST['massupdate'] == 'true';
574 2
		$uids = empty($_REQUEST['uid']) || $massUpdateRun ? '' : $_REQUEST['uid'];
575 2
        $select_entire_list = ($massUpdateRun) ? 0 : (isset($_POST['select_entire_list']) ? $_POST['select_entire_list'] : (isset($_REQUEST['select_entire_list']) ? $_REQUEST['select_entire_list'] : 0));
576
577 2
		$str .= "<textarea style='display: none' name='uid'>{$uids}</textarea>\n" .
578 2
				"<input type='hidden' name='select_entire_list' value='{$select_entire_list}'>\n".
579 2
				"<input type='hidden' name='{$this->moduleString}' value='0'>\n".
580 2
		        "<input type='hidden' name='show_plus' value='{$this->show_plus}'>\n";
581 2
		return $str;
582
	}
583
584
     /**
585
     * @return MassUpdate instance
586
     */
587 4
    protected function getMassUpdate()
588
    {
589 4
        return new MassUpdate();
590
    }
591
592
    /**
593
     * Fill displayColumns with additional field values from vardefs of the current bean seed.
594
     * We need vardefs to be in displayColumns for a further processing (e.g. in SugarField)
595
     * Similar vardef field values do not override field values from displayColumns, only necessary and missing ones are added
596
     */
597 4
    protected function fillDisplayColumnsWithVardefs()
598
    {
599 4
        foreach ($this->displayColumns as $columnName => $def) {
600 2
            $seedName =  strtolower($columnName);
601 2
            if (!empty($this->lvd->seed->field_defs[$seedName])) {
602 2
                $seedDef = $this->lvd->seed->field_defs[$seedName];
603
            }
604
605 2
            if (empty($this->displayColumns[$columnName]['type'])) {
606 2
                if (!empty($seedDef['type'])) {
607 2
                    $this->displayColumns[$columnName]['type'] = (!empty($seedDef['custom_type']))?$seedDef['custom_type']:$seedDef['type'];
608
                } else {
609 1
                    $this->displayColumns[$columnName]['type'] = '';
610
                }
611
            }//fi empty(...)
612
613 2
            if (!empty($seedDef['options'])) {
614 2
                $this->displayColumns[$columnName]['options'] = $seedDef['options'];
615
            }
616
617
            //C.L. Fix for 11177
618 2
            if ($this->displayColumns[$columnName]['type'] == 'html') {
619
                $cField = $this->seed->custom_fields;
620
                if (isset($cField) && isset($cField->bean->$seedName)) {
621
                    $seedName2 = strtoupper($columnName);
622
                    $htmlDisplay = html_entity_decode($cField->bean->$seedName);
623
                    $count = 0;
624
                    while ($count < count($data['data'])) {
625
                        $data['data'][$count][$seedName2] = &$htmlDisplay;
626
                        $count++;
627
                    }
628
                }
629
            }//fi == 'html'
630
631
            //Bug 40511, make sure relate fields have the correct module defined
632 2
            if ($this->displayColumns[$columnName]['type'] == "relate" && !empty($seedDef['link']) && empty( $this->displayColumns[$columnName]['module'])) {
633 1
                $link = $seedDef['link'];
634 1
                if (!empty($this->lvd->seed->field_defs[$link]) && !empty($this->lvd->seed->field_defs[$seedDef['link']]['module'])) {
635 1
                    $this->displayColumns[$columnName]['module'] = $this->lvd->seed->field_defs[$seedDef['link']]['module'];
636
                }
637
            }
638
639 2
            if (!empty($seedDef['sort_on'])) {
640
                $this->displayColumns[$columnName]['orderBy'] = $seedDef['sort_on'];
641
            }
642
643 2
            if (isset($seedDef)) {
644
                // Merge the two arrays together, making sure the seedDef doesn't override anything explicitly set in the displayColumns array.
645 2
                $this->displayColumns[$columnName] = $this->displayColumns[$columnName] + $seedDef;
646
            }
647
648
            //C.L. Bug 38388 - ensure that ['id'] is set for related fields
649 2
            if (!isset($this->displayColumns[$columnName]['id']) && isset($this->displayColumns[$columnName]['id_name'])) {
650 2
                $this->displayColumns[$columnName]['id'] = strtoupper($this->displayColumns[$columnName]['id_name']);
651
            }
652
        }
653
    }
654
}