Issues (4069)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

include/Popups/PopupSmarty.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 1
require_once('include/ListView/ListViewSmarty.php');
42
43 1
require_once('include/TemplateHandler/TemplateHandler.php');
44 1
require_once('include/SearchForm/SearchForm2.php');
45 1
define("NUM_COLS", 2);
46
class PopupSmarty extends ListViewSmarty{
47
48
	var $contextMenus = false;
49
	var $export = false;
50
	var $mailmerge = false;
51
	var $mergeduplicates = false;
52
	var $quickViewLinks = false;
53
	var $multiSelect = false;
54
	var $headerTpl;
55
    var $footerTpl;
56
    var $th;
57
    var $tpl;
58
    var $view;
59
    var $field_defs;
60
    var $formData;
61
    var $_popupMeta;
62
    var $_create = false;
63
    var $searchdefs = array();
64
    var $listviewdefs = array();
65
    var $searchFields = array();
66
    var $customFieldDefs;
67
    var $filter_fields = array();
68
    //rrs
69
    var $searchForm;
70
    var $module;
71
    var $massUpdateData = '';
72
73 1
	public function __construct($seed, $module){
74 1
		parent::__construct();
75 1
		$this->th = new TemplateHandler();
76 1
		$this->th->loadSmarty();
77 1
		$this->seed = $seed;
78 1
		$this->view = 'Popup';
79 1
		$this->module = $module;
80 1
		$this->searchForm = new SearchForm($this->seed, $this->module);
81 1
		$this->th->deleteTemplate($module, $this->view);
82 1
        $this->headerTpl = 'include/Popups/tpls/header.tpl';
83 1
        $this->footerTpl = 'include/Popups/tpls/footer.tpl';
84
85 1
	}
86
87
    /**
88
     * @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
89
     */
90
    public function PopupSmarty($seed, $module){
91
        $deprecatedMessage = 'PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code';
92
        if(isset($GLOBALS['log'])) {
93
            $GLOBALS['log']->deprecated($deprecatedMessage);
94
        }
95
        else {
96
            trigger_error($deprecatedMessage, E_USER_DEPRECATED);
97
        }
98
        self::__construct($seed, $module);
99
    }
100
101
102
    /**
103
     * Assign several arrow image attributes to TemplateHandler smarty. Such as width, height, etc.
104
     *
105
     * @return void
106
     */
107 1
    function processArrowVars()
108
    {
109 1
        $pathParts = pathinfo(SugarThemeRegistry::current()->getImageURL('arrow.gif',false));
110
111 1
        list($width,$height) = getimagesize($pathParts['dirname'].'/'.$pathParts['basename']);
112
113 1
        $this->th->ss->assign('arrowExt', $pathParts['extension']);
114 1
        $this->th->ss->assign('arrowWidth', $width);
115 1
        $this->th->ss->assign('arrowHeight', $height);
116 1
        $this->th->ss->assign('arrowAlt', translate('LBL_SORT'));
117 1
    }
118
119
	/**
120
     * Processes the request. Calls ListViewData process. Also assigns all lang strings, export links,
121
     * This is called from ListViewDisplay
122
     *
123
     * @param file file Template file to use
124
     * @param data array from ListViewData
125
     * @param html_var string the corresponding html var in xtpl per row
126
     *
127
     */
128 1
	function process($file, $data, $htmlVar) {
129
130 1
		global $odd_bg, $even_bg, $hilite_bg, $click_bg, $app_strings;
131 1
		parent::process($file, $data, $htmlVar);
132
133 1
		$this->tpl = $file;
134 1
		$this->data = $data;
135
136 1
        $totalWidth = 0;
137 1
        foreach($this->displayColumns as $name => $params) {
138 1
            $totalWidth += $params['width'];
139
        }
140 1
        $adjustment = $totalWidth / 100;
141
142 1
        $contextMenuObjectsTypes = array();
143 1
        foreach($this->displayColumns as $name => $params) {
144 1
            $this->displayColumns[$name]['width'] = round($this->displayColumns[$name]['width'] / $adjustment, 2);
145
            // figure out which contextMenu objectsTypes are required
146 1
            if(!empty($params['contextMenu']['objectType']))
147 1
                $contextMenuObjectsTypes[$params['contextMenu']['objectType']] = true;
148
        }
149 1
		$this->th->ss->assign('displayColumns', $this->displayColumns);
150
151
152 1
		$this->th->ss->assign('bgHilite', $hilite_bg);
153 1
		$this->th->ss->assign('colCount', count($this->displayColumns) + 1);
154 1
		$this->th->ss->assign('htmlVar', strtoupper($htmlVar));
155 1
		$this->th->ss->assign('moduleString', $this->moduleString);
156 1
        $this->th->ss->assign('editLinkString', $GLOBALS['app_strings']['LBL_EDIT_BUTTON']);
157 1
        $this->th->ss->assign('viewLinkString', $GLOBALS['app_strings']['LBL_VIEW_BUTTON']);
158
159
        //rrs
160 1
        $this->searchForm->parsedView = 'popup_query_form';
161 1
        $this->searchForm->displayType = 'popupView';
162 1
		$this->th->ss->assign('searchForm', $this->searchForm->display(false));
0 ignored issues
show
The method display() does not exist on SearchForm. Did you maybe mean displayTabs()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
163
        //rrs
164
165 1
		if($this->export) $this->th->ss->assign('exportLink', $this->buildExportLink());
166 1
		$this->th->ss->assign('quickViewLinks', $this->quickViewLinks);
167 1
		if($this->mailMerge) $this->th->ss->assign('mergeLink', $this->buildMergeLink()); // still check for mailmerge access
168 1
		if($this->mergeduplicates) $this->th->ss->assign('mergedupLink', $this->buildMergeDuplicatesLink());
169
170
171 1
		if (!empty($_REQUEST['mode']) && strtoupper($_REQUEST['mode']) == 'MULTISELECT') {
172
			$this->multiSelect = true;
173
		}
174
		// handle save checks and stuff
175 1
		if($this->multiSelect) {
176
			$this->th->ss->assign('selectedObjectsSpan', $this->buildSelectedObjectsSpan());
177
			$this->th->ss->assign('multiSelectData', $this->getMultiSelectData());
178
			$this->th->ss->assign('MODE', "<input type='hidden' name='mode' value='MultiSelect'>");
179
            $pageTotal = $this->data['pageData']['offsets']['next'] - $this->data['pageData']['offsets']['current'];
180
            if($this->data['pageData']['offsets']['next'] < 0){ // If we are on the last page, 'next' is -1, which means we have to have a custom calculation
181
                $pageTotal = $this->data['pageData']['offsets']['total'] - $this->data['pageData']['offsets']['current'];
182
            }
183
    		$this->th->ss->assign('selectLink', $this->buildSelectLink('select_link', $this->data['pageData']['offsets']['total'], $pageTotal));
184
		}
185
186 1
		$this->processArrows($data['pageData']['ordering']);
187 1
		$this->th->ss->assign('prerow', $this->multiSelect);
188 1
		$this->th->ss->assign('rowColor', array('oddListRow', 'evenListRow'));
189 1
		$this->th->ss->assign('bgColor', array($odd_bg, $even_bg));
190 1
        $this->th->ss->assign('contextMenus', $this->contextMenus);
191
192
193 1
        if($this->contextMenus && !empty($contextMenuObjectsTypes)) {
194
            $script = '';
195
            $cm = new contextMenu();
196
            foreach($contextMenuObjectsTypes as $type => $value) {
197
                $cm->loadFromFile($type);
198
                $script .= $cm->getScript();
199
                $cm->menuItems = array(); // clear menuItems out
200
            }
201
            $this->th->ss->assign('contextMenuScript', $script);
202
        }
203
204
        //rrs
205 1
        $this->_build_field_defs();
206
207
            // arrow image attributes
208 1
            $this->processArrowVars();
209 1
	}
210
211
	/*
212
	 * Display the Smarty template.  Here we are using the TemplateHandler for caching per the module.
213
	 */
214 1
	function display($end = true) {
215 1
        global $app_strings;
216
217 1
        if(!is_file(sugar_cached("jsLanguage/{$GLOBALS['current_language']}.js"))) {
218
            require_once('include/language/jsLanguage.php');
219
            jsLanguage::createAppStringsCache($GLOBALS['current_language']);
220
        }
221 1
        $jsLang = getVersionedScript("cache/jsLanguage/{$GLOBALS['current_language']}.js",  $GLOBALS['sugar_config']['js_lang_version']);
222
223 1
        $this->th->ss->assign('data', $this->data['data']);
224 1
		$this->data['pageData']['offsets']['lastOffsetOnPage'] = $this->data['pageData']['offsets']['current'] + count($this->data['data']);
225 1
		$this->th->ss->assign('pageData', $this->data['pageData']);
226
227 1
        $navStrings = array('next' => $GLOBALS['app_strings']['LNK_LIST_NEXT'],
228 1
                            'previous' => $GLOBALS['app_strings']['LNK_LIST_PREVIOUS'],
229 1
                            'end' => $GLOBALS['app_strings']['LNK_LIST_END'],
230 1
                            'start' => $GLOBALS['app_strings']['LNK_LIST_START'],
231 1
                            'of' => $GLOBALS['app_strings']['LBL_LIST_OF']);
232 1
        $this->th->ss->assign('navStrings', $navStrings);
233
234
235 1
		$associated_row_data = array();
236
237
		//C.L. - Bug 44324 - Override the NAME entry to not display salutation so that the data returned from the popup can be searched on correctly
238 1
		$searchNameOverride = !empty($this->seed) && $this->seed instanceof Person && (isset($this->data['data'][0]['FIRST_NAME']) && isset($this->data['data'][0]['LAST_NAME'])) ? true : false;
239
240 1
		global $locale;
241 1
		foreach($this->data['data'] as $val)
242
		{
243
			$associated_row_data[$val['ID']] = $val;
244
			if($searchNameOverride)
245
			{
246
			   $associated_row_data[$val['ID']]['NAME'] = $locale->getLocaleFormattedName($val['FIRST_NAME'], $val['LAST_NAME']);
247
			}
248
		}
249 1
		$is_show_fullname = showFullName() ? 1 : 0;
250 1
		$json = getJSONobj();
251 1
		$this->th->ss->assign('jsLang', $jsLang);
252 1
		$this->th->ss->assign('lang', substr($GLOBALS['current_language'], 0, 2));
253 1
        $this->th->ss->assign('headerTpl', $this->headerTpl);
254 1
        $this->th->ss->assign('footerTpl', $this->footerTpl);
255 1
        $this->th->ss->assign('ASSOCIATED_JAVASCRIPT_DATA', 'var associated_javascript_data = '.$json->encode($associated_row_data). '; var is_show_fullname = '.$is_show_fullname.';');
256 1
		$this->th->ss->assign('module', $this->seed->module_dir);
257 1
		$request_data = empty($_REQUEST['request_data']) ? '' : $_REQUEST['request_data'];
258
259 1
		$this->th->ss->assign('request_data', $request_data);
260 1
		$this->th->ss->assign('fields', $this->fieldDefs);
261 1
		$this->th->ss->assign('formData', $this->formData);
262 1
		$this->th->ss->assign('APP', $GLOBALS['app_strings']);
263 1
		$this->th->ss->assign('MOD', $GLOBALS['mod_strings']);
264 1
        if (isset($this->_popupMeta['create']['createButton']))
265
		{
266 1
           $this->_popupMeta['create']['createButton'] = translate($this->_popupMeta['create']['createButton']);
267
        }
268 1
		$this->th->ss->assign('popupMeta', $this->_popupMeta);
269 1
        $this->th->ss->assign('current_query', base64_encode(serialize($_REQUEST)));
270 1
		$this->th->ss->assign('customFields', $this->customFieldDefs);
271 1
		$this->th->ss->assign('numCols', NUM_COLS);
272 1
		$this->th->ss->assign('massUpdateData', $this->massUpdateData);
273 1
		$this->th->ss->assign('sugarVersion', $GLOBALS['sugar_version']);
274 1
        $this->th->ss->assign('should_process', $this->should_process);
275
276 1
		if($this->_create){
277 1
			$this->th->ss->assign('ADDFORM', $this->getQuickCreate());//$this->_getAddForm());
278 1
			$this->th->ss->assign('ADDFORMHEADER', $this->_getAddFormHeader());
279 1
			$this->th->ss->assign('object_name', $this->seed->object_name);
280
		}
281 1
		$this->th->ss->assign('LIST_HEADER', get_form_header($GLOBALS['mod_strings']['LBL_LIST_FORM_TITLE'], '', false));
282 1
		$this->th->ss->assign('SEARCH_FORM_HEADER', get_form_header($GLOBALS['mod_strings']['LBL_SEARCH_FORM_TITLE'], '', false));
283 1
		$str = $this->th->displayTemplate($this->seed->module_dir, $this->view, $this->tpl);
284 1
		return $str;
285
	}
286
287
	/*
288
	 * Setup up the smarty template. we added an extra step here to add the order by from the popupdefs.
289
	 */
290 1
	function setup($seed, $file = null, $where = null, $params = Array(), $offset = 0, $limit = -1, $filter_fields = Array(), $id_field = 'id') {
291 1
		$args = func_get_args();
292 1
		return call_user_func_array(array($this, '_setup'), $args);
293
	}
294 1
	function _setup($file) {
295
296 1
	    if(isset($this->_popupMeta)){
297 1
			if(isset($this->_popupMeta['create']['formBase'])) {
298 1
				require_once('modules/' . $this->seed->module_dir . '/' . $this->_popupMeta['create']['formBase']);
299 1
				$this->_create = true;
300
			}
301
		}
302 1
	    if(!empty($this->_popupMeta['create'])){
303 1
			$formBase = new $this->_popupMeta['create']['formBaseClass']();
304 1
			if(isset($_REQUEST['doAction']) && $_REQUEST['doAction'] == 'save')
305
			{
306
				//If it's a new record, set useRequired to false
307
				$useRequired = empty($_REQUEST['id']) ? false : true;
308
				$formBase->handleSave('', false, $useRequired);
309
			}
310
		}
311
312 1
		$params = array();
313 1
		if(!empty($this->_popupMeta['orderBy'])){
314 1
			$params['orderBy'] = $this->_popupMeta['orderBy'];
315
		}
316
317 1
		if(file_exists('custom/modules/'.$this->module.'/metadata/metafiles.php')){
318
			require('custom/modules/'.$this->module.'/metadata/metafiles.php');
319 1
		}elseif(file_exists('modules/'.$this->module.'/metadata/metafiles.php')){
320 1
			require('modules/'.$this->module.'/metadata/metafiles.php');
321
		}
322
323 1
		if(!empty($metafiles[$this->module]['searchfields'])) {
0 ignored issues
show
The variable $metafiles seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
324 1
			require($metafiles[$this->module]['searchfields']);
325
		} elseif(file_exists('modules/'.$this->module.'/metadata/SearchFields.php')) {
326
			require('modules/'.$this->module.'/metadata/SearchFields.php');
327
	    }
328 1
        $this->searchdefs[$this->module]['templateMeta']['maxColumns'] = 2;
329 1
        $this->searchdefs[$this->module]['templateMeta']['widths']['label'] = 10;
330 1
        $this->searchdefs[$this->module]['templateMeta']['widths']['field'] = 30;
331
332 1
        $this->searchForm->view = 'PopupSearchForm';
333 1
		$this->searchForm->setup($this->searchdefs, $searchFields, 'SearchFormGenericAdvanced.tpl', 'advanced_search', $this->listviewdefs);
0 ignored issues
show
The call to SearchForm::setup() has too many arguments starting with $this->searchdefs.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
334
335 1
		$lv = new ListViewSmarty();
336 1
		$displayColumns = array();
337 1
		if(!empty($_REQUEST['displayColumns'])) {
338
		    foreach(explode('|', $_REQUEST['displayColumns']) as $num => $col) {
339
		        if(!empty($listViewDefs[$this->module][$col]))
340
		            $displayColumns[$col] = $this->listviewdefs[$this->module][$col];
341
		    }
342
		}
343
		else {
344 1
		    foreach($this->listviewdefs[$this->module] as $col => $para) {
345 1
		        if(!empty($para['default']) && $para['default'])
346 1
		            $displayColumns[$col] = $para;
347
		    }
348
		}
349 1
		$params['massupdate'] = true;
350 1
		if(!empty($_REQUEST['orderBy'])) {
351
		    $params['orderBy'] = $_REQUEST['orderBy'];
352
		    $params['overrideOrder'] = true;
353
		    if(!empty($_REQUEST['sortOrder'])) $params['sortOrder'] = $_REQUEST['sortOrder'];
354
		}
355
356 1
		$lv->displayColumns = $displayColumns;
357 1
        $this->searchForm->lv = $lv;
358 1
        $this->searchForm->displaySavedSearch = false;
359
360
361 1
        $this->searchForm->populateFromRequest('advanced_search');
362 1
        $searchWhere = $this->_get_where_clause();
363 1
        $this->searchColumns = $this->searchForm->searchColumns;
364
        //parent::setup($this->seed, $file, $searchWhere, $params, 0, -1, $this->filter_fields);
365
366 1
        $this->should_process = true;
367
368 1
        if(isset($params['export'])) {
369
          $this->export = $params['export'];
370
        }
371 1
        if(!empty($params['multiSelectPopup'])) {
372
		  $this->multi_select_popup = $params['multiSelectPopup'];
373
        }
374 1
		if(!empty($params['massupdate']) && $params['massupdate'] != false) {
375 1
			$this->show_mass_update_form = true;
376 1
			$this->mass = new MassUpdate();
377 1
			$this->mass->setSugarBean($this->seed);
378 1
			if(!empty($params['handleMassupdate']) || !isset($params['handleMassupdate'])) {
379 1
                $this->mass->handleMassUpdate();
380
            }
381
		}
382
383
        // create filter fields based off of display columns
384 1
        if(empty($this->filter_fields) || $this->mergeDisplayColumns) {
385 1
            foreach($this->displayColumns as $columnName => $def) {
386 1
               $this->filter_fields[strtolower($columnName)] = true;
387 1
               if(!empty($def['related_fields'])) {
388
                    foreach($def['related_fields'] as $field) {
389
                        //id column is added by query construction function. This addition creates duplicates
390
                        //and causes issues in oracle. #10165
391
                        if ($field != 'id') {
392
                            $this->filter_fields[$field] = true;
393
                        }
394
                    }
395
                }
396 1
                if (!empty($this->seed->field_defs[strtolower($columnName)]['db_concat_fields'])) {
397
	                foreach($this->seed->field_defs[strtolower($columnName)]['db_concat_fields'] as $index=>$field){
398
	                    if(!isset($this->filter_fields[strtolower($field)]) || !$this->filter_fields[strtolower($field)])
399
	                    {
400 1
	                        $this->filter_fields[strtolower($field)] = true;
401
	                    }
402
	                }
403
                }
404
            }
405 1
            foreach ($this->searchColumns as $columnName => $def )
406
            {
407
                $this->filter_fields[strtolower($columnName)] = true;
408
            }
409
        }
410
411 1
        if (isset($_REQUEST['request_data'])) {
412
            $request_data = json_decode(html_entity_decode($_REQUEST['request_data']), true);
413
            $_POST['field_to_name'] = $_REQUEST['field_to_name'] = array_keys($request_data['field_to_name_array']);
414
        }
415
416
        /**
417
         * Bug #46842 : The relate field field_to_name_array fails to copy over custom fields
418
         * By default bean's create_new_list_query function loads fields displayed on the page or used in the search
419
         * add fields used to populate forms from _viewdefs :: field_to_name_array to retrive from db
420
         */
421 1
        if ( isset($_REQUEST['field_to_name']) && $_REQUEST['field_to_name'] )
422
        {
423
            $_REQUEST['field_to_name'] = is_array($_REQUEST['field_to_name']) ? $_REQUEST['field_to_name'] : array($_REQUEST['field_to_name']);
424
            foreach ( $_REQUEST['field_to_name'] as $add_field )
425
            {
426
                $add_field = strtolower($add_field);
427
                if ( $add_field != 'id' && !isset($this->filter_fields[$add_field]) && isset($this->seed->field_defs[$add_field]) )
428
                {
429
                    $this->filter_fields[$add_field] = true;
430
                }
431
            }
432
433
        }
434
435
436 1
		if (!empty($_REQUEST['query']) || (!empty($GLOBALS['sugar_config']['save_query']) && $GLOBALS['sugar_config']['save_query'] != 'populate_only')) {
437 1
			$data = $this->lvd->getListViewData($this->seed, $searchWhere, 0, -1, $this->filter_fields, $params, 'id');
438
		} else {
439
			$this->should_process = false;
440
			$data = array(
441
				'data'=>array(),
442
			    'pageData'=>array(
443
			    	'bean'=>array('moduleDir'=>$this->seed->module_dir),
444
					'ordering'=>'',
445
					'offsets'=>array('total'=>0,'next'=>0,'current'=>0),
446
				),
447
			);
448
		}
449
450 1
        $this->fillDisplayColumnsWithVardefs();
451
452 1
		$this->process($file, $data, $this->seed->object_name);
453 1
	}
454
455
	/*
456
	 * Return the where clause as per the REQUEST.
457
	 */
458 1
	function _get_where_clause()
459
	{
460 1
		$where = '';
461 1
		$where_clauses = $this->searchForm->generateSearchWhere(true, $this->seed->module_dir);
462
463
		// Bug 43452 - FG - Changed the way generated Where array is imploded into the string.
464
		//                  Now it's imploding in the same way view.list.php do.
465 1
		if (count($where_clauses) > 0 ) {
466
		    $where = '( ' . implode(' and ', $where_clauses) . ' )';
467
        }
468
469
        // Need to include the default whereStatement
470 1
		if(!empty($this->_popupMeta['whereStatement'])){
471
            if(!empty($where))$where .= ' AND ';
472
            $where .= $this->_popupMeta['whereStatement'];
473
		}
474
475 1
		return $where;
476
	}
477
478
	/*
479
	 * Generate the data for the search form on the header of the Popup.
480
	 */
481 1
		function _build_field_defs(){
482 1
		$this->formData = array();
483 1
		$this->customFieldDefs = array();
484 1
		foreach($this->searchdefs[$this->module]['layout']['advanced_search'] as $data){
485 1
			if(is_array($data)){
486
487 1
				$this->formData[] = array('field' => $data);
488 1
				$value = '';
489 1
				$this->customFieldDefs[$data['name']]= $data;
490 1
				if(!empty($_REQUEST[$data['name']]))
491
	            	$value = $_REQUEST[$data['name']];
492 1
	            $this->customFieldDefs[$data['name']]['value'] = $value;
493
			}else
494 1
				$this->formData[] = array('field' => array('name'=>$data));
495
		}
496 1
		$this->fieldDefs = array();
497 1
		if($this->seed){
498 1
			$this->seed->fill_in_additional_detail_fields();
499
500 1
	        foreach($this->seed->toArray() as $name => $value) {
501 1
	            $this->fieldDefs[$name] = $this->seed->field_defs[$name];
502
	            //if we have a relate type then reset to name so that we end up with a textbox
503
	            //rather than a select button
504 1
	            $this->fieldDefs[$name]['name'] = $this->fieldDefs[$name]['name'];
505 1
	            if($this->fieldDefs[$name]['type'] == 'relate')
506 1
	            	$this->fieldDefs[$name]['type'] = 'name';
507 1
	            if(isset($this->fieldDefs[$name]['options']) && isset($GLOBALS['app_list_strings'][$this->fieldDefs[$name]['options']])) {
508 1
	                $this->fieldDefs[$name]['options'] = $GLOBALS['app_list_strings'][$this->fieldDefs[$name]['options']]; // fill in enums
509
	            }
510 1
	            if(!empty($_REQUEST[$name]))
511
	            	$value = $_REQUEST[$name];
512 1
	            $this->fieldDefs[$name]['value'] = $value;
513
	        }
514
		}
515 1
	}
516
517
	function _getAddForm(){
518
		$addform = '';
519
        if(!$this->seed->ACLAccess('save')){
520
            return;
521
        }
522
		if(!empty($this->_popupMeta['create'])){
523
			$formBase = new $this->_popupMeta['create']['formBaseClass']();
524
525
526
527
				// TODO: cleanup the construction of $addform
528
				$prefix = empty($this->_popupMeta['create']['getFormBodyParams'][0]) ? '' : $this->_popupMeta['create']['getFormBodyParams'][0];
529
				$mod = empty($this->_popupMeta['create']['getFormBodyParams'][1]) ? '' : $this->_popupMeta['create']['getFormBodyParams'][1];
530
				$formBody = empty($this->_popupMeta['create']['getFormBodyParams'][2]) ? '' : $this->_popupMeta['create']['getFormBodyParams'][2];
531
532
				$getFormMethod = (empty($this->_popupMeta['create']['getFormMethod']) ? 'getFormBody' : $this->_popupMeta['create']['getFormMethod']);
533
				$formbody = $formBase->$getFormMethod($prefix, $mod, $formBody);
534
535
				$addform = '<table><tr><td nowrap="nowrap" valign="top">'
536
					. str_replace('<br>', '</td><td nowrap="nowrap" valign="top">&nbsp;', $formbody)
537
					. '</td></tr></table>'
538
					. '<input type="hidden" name="action" value="Popup" />';
539
540
			return $addform;
541
		}
542
	}
543
544 1
	function _getAddFormHeader(){
545 1
		$lbl_save_button_title = $GLOBALS['app_strings']['LBL_SAVE_BUTTON_TITLE'];
546 1
		$lbl_save_button_key = $GLOBALS['app_strings']['LBL_SAVE_BUTTON_KEY'];
547 1
		$lbl_save_button_label = $GLOBALS['app_strings']['LBL_SAVE_BUTTON_LABEL'];
548 1
		$module_dir = $this->seed->module_dir;
549
$formSave = <<<EOQ
550
			<input type="hidden" name="create" value="true">
551
			<input type="hidden" name="popup" value="true">
552
			<input type="hidden" name="to_pdf" value="true">
553 1
			<input type="hidden" name="return_module" value="$module_dir">
554 1
			<input type="hidden" name="return_action" value="Popup">
555
EOQ;
556
		// if metadata contains custom inputs for the quickcreate
557 1
		if(!empty($this->_popupMeta['customInput']) && is_array($this->_popupMeta['customInput'])) {
558
			foreach($this->_popupMeta['customInput'] as $key => $value)
559
				$formSave .= '<input type="hidden" name="' . $key . '" value="'. $value .'">\n';
560
		}
561
562
563 1
		$addformheader = get_form_header(translate($this->_popupMeta['create']['createButton']), $formSave, false);
564 1
		return $addformheader;
565
	}
566
567 1
	function getQuickCreate(){
568 1
		require_once("include/EditView/PopupQuickCreate.php");
569 1
		$qc = new PopupQuickCreate($this->module);
570 1
		return $qc->process($this->module);
571
	}
572
}
573
?>
574