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/EditView/EditView2.php (10 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
/*********************************************************************************
3
 * SugarCRM Community Edition is a customer relationship management program developed by
4
 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
5
6
 * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd.
7
 * Copyright (C) 2011 - 2014 Salesagility Ltd.
8
 *
9
 * This program is free software; you can redistribute it and/or modify it under
10
 * the terms of the GNU Affero General Public License version 3 as published by the
11
 * Free Software Foundation with the addition of the following permission added
12
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
13
 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
14
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
15
 *
16
 * This program is distributed in the hope that it will be useful, but WITHOUT
17
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18
 * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
19
 * details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License along with
22
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
23
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24
 * 02110-1301 USA.
25
 *
26
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
27
 * SW2-130, Cupertino, CA 95014, USA. or at email address [email protected].
28
 *
29
 * The interactive user interfaces in modified source and object code versions
30
 * of this program must display Appropriate Legal Notices, as required under
31
 * Section 5 of the GNU Affero General Public License version 3.
32
 *
33
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
34
 * these Appropriate Legal Notices must retain the display of the "Powered by
35
 * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
36
 * reasonably feasible for  technical reasons, the Appropriate Legal Notices must
37
 * display the words  "Powered by SugarCRM" and "Supercharged by SuiteCRM".
38
 ********************************************************************************/
39
40
41
42 1
require_once('include/TemplateHandler/TemplateHandler.php');
43 1
require_once('include/EditView/SugarVCR.php');
44
45
/**
46
 * New EditView
47
 * @api
48
 */
49
class EditView
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type EditView has been defined more than once; this definition is ignored, only the first definition in include/EditView/EditView.php (L45-115) is considered.

This check looks for classes that have been defined more than once.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
50
{
51
    public $th;
52
    public $tpl;
53
    public $notes;
54
    public $id;
55
    public $metadataFile;
56
    public $headerTpl;
57
    public $footerTpl;
58
    public $returnAction;
59
    public $returnModule;
60
    public $returnId;
61
    public $isDuplicate;
62
    public $focus;
63
    public $module;
64
    public $fieldDefs;
65
    public $sectionPanels;
66
    public $view = 'EditView';
67
    public $formatFields = true;
68
    public $showDetailData = true;
69
    public $showVCRControl = true;
70
    public $showSectionPanelsTitles = true;
71
    public $quickSearchCode;
72
    public $ss;
73
    public $offset = 0;
74
    public $populateBean = true;
75
    public $moduleTitleKey;
76
    public $viewObject = null;
77
    public $formName = '';
78
79
    /**
80
     * EditView constructor
81
     * This is the EditView constructor responsible for processing the new
82
     * Meta-Data framework
83
     *
84
     * @param $module String value of module this Edit view is for
85
     * @param $focus An empty sugarbean object of module
86
     * @param $id The record id to retrieve and populate data for
87
     * @param $metadataFile String value of file location to use in overriding default metadata file
88
     * @param tpl String value of file location to use in overriding default Smarty template
89
     * @param createFocus bool value to tell whether to create a new bean if we do not have one with an id, this is used from ConvertLead
90
     *
91
     */
92 5
    function setup($module, $focus = null, $metadataFile = null, $tpl = 'include/EditView/EditView.tpl', $createFocus = true)
93
    {
94 5
        $this->th = $this->getTemplateHandler();
0 ignored issues
show
The method getTemplateHandler() does not seem to exist on object<EditView>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
95 5
        $this->th->ss =& $this->ss;
96 5
        $this->tpl = $tpl;
97 5
        $this->module = $module;
98 5
        $this->focus = $focus;
99
100
        //this logic checks if the focus has an id and if it does not then it will create a new instance of the focus bean
101
        //but in convert lead we do not want to create a new instance and do not want to populate id.
102 5
        if ($createFocus)
103
        {
104 5
            $this->createFocus();
0 ignored issues
show
The method createFocus() does not seem to exist on object<EditView>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
105
        }
106
107 5
        if (empty($GLOBALS['sugar_config']['showDetailData']))
108
        {
109
            $this->showDetailData = false;
110
        }
111 5
        $this->metadataFile = $metadataFile;
112
113 5
        if (isset($GLOBALS['sugar_config']['disable_vcr']))
114
        {
115
           $this->showVCRControl = !$GLOBALS['sugar_config']['disable_vcr'];
116
        }
117
118 5
        if (!empty($this->metadataFile) && file_exists($this->metadataFile))
119
        {
120 5
            include($this->metadataFile);
121
        }
122
        else
123
        {
124
            //If file doesn't exist we create a best guess
125
            if (!file_exists("modules/$this->module/metadata/editviewdefs.php")
126
                && file_exists("modules/$this->module/EditView.html"))
127
            {
128
                require_once('include/SugarFields/Parsers/EditViewMetaParser.php');
129
130
                global $dictionary;
131
132
                $htmlFile = "modules/" . $this->module . "/EditView.html";
133
                $parser = new EditViewMetaParser();
134
                if (!file_exists('modules/'.$this->module.'/metadata'))
135
                {
136
                   sugar_mkdir('modules/'.$this->module.'/metadata');
137
                }
138
139
                $fp = sugar_fopen('modules/'.$this->module.'/metadata/editviewdefs.php', 'w');
140
                fwrite($fp, $parser->parse($htmlFile, $dictionary[$focus->object_name]['fields'], $this->module));
141
                fclose($fp);
142
            }
143
144
            //Flag an error... we couldn't create the best guess meta-data file
145
            if (!file_exists("modules/$this->module/metadata/editviewdefs.php"))
146
            {
147
                global $app_strings;
148
149
                $error = str_replace("[file]", "modules/$this->module/metadata/editviewdefs.php", $app_strings['ERR_CANNOT_CREATE_METADATA_FILE']);
150
                $GLOBALS['log']->fatal($error);
151
                echo $error;
152
                die();
153
            }
154
155
            require("modules/$this->module/metadata/editviewdefs.php");
156
        }
157
158 5
        $this->defs = $viewdefs[$this->module][$this->view];
159 5
        $this->isDuplicate = isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true' && $this->focus->aclAccess('edit');
160 5
    }
161
162 5
    function createFocus()
163
    {
164 5
        global $beanList, $beanFiles;
165
166 5
        if (empty($beanList[$this->module])) return;
167 5
        if(!$this->focus )
168
        {
169 1
           $bean = $beanList[$this->module];
170 1
           require_once($beanFiles[$bean]);
171 1
           $obj = new $bean();
172 1
           $this->focus = $obj;
173
        }
174
175
        //If there is no idea, assume we are creating a new instance
176
        //and call the fill_in_additional_detail_fields where initialization
177
        //code has been moved to
178 5
        if (empty($this->focus->id))
179
        {
180 5
            global $current_user;
181
182 5
            $this->focus->fill_in_additional_detail_fields();
183 5
            $this->focus->assigned_user_id = $current_user->id;
184
        }
185 5
    }
186
187
    function populateBean()
188
    {
189
        if (!empty($_REQUEST['record']) && $this->populateBean)
190
        {
191
           global $beanList;
192
193
           $bean = $beanList[$this->module];
194
           $obj = new $bean();
195
           $this->focus = $obj->retrieve($_REQUEST['record']);
196
        }
197
        else
198
        {
199
           $GLOBALS['log']->debug("Unable to populate bean, no record parameter found");
200
        }
201
    }
202
203
    /**
204
     * enableFormatting
205
     * This method is used to manually turn on/off the field formatting
206
     * @param $format boolean value to turn on/off field formatting
207
     */
208
    function enableFormatting($format = true)
209
    {
210
        $this->formatFields = $format;
211
    }
212
213
    /**
214
     * Enter description here ...
215
     */
216
    function requiredFirst()
217
    {
218
        $panels = array('required'=>array());
219
        $reqCol = -1;
220
        $reqRow = 0;
221
        foreach($this->defs['panels'] as $key=>$p)
222
        {
223
            foreach ($p as $row=>$rowDef)
224
            {
225
                foreach($rowDef as $col => $colDef)
226
                {
227
                    $field = (is_array($p[$row][$col])) ? $p[$row][$col]['name'] : $p[$row][$col];
228
                    if ((!empty($this->focus->field_defs[$field])
229
                        && !empty($this->focus->field_defs[$field]['required']))
230
                            || (!empty($p[$row][$col]['displayParams']['required'])))
231
                    {
232
                        $reqCol++;
233
                        if ($reqCol == $this->defs['templateMeta']['maxColumns'])
234
                        {
235
                            $reqCol = -1;
236
                            $reqRow++;
237
                        }
238
239
                        $panels['required'][$reqRow][$reqCol] = $p[$row][$col];
240
                    }
241
                    else
242
                    {
243
                        $panels[$key][$row][$col] = $p[$row][$col];
244
                    }
245
                }
246
            }
247
        }
248
249
        $this->defs['panels'] = $panels;
250
    }
251
252 4
    function render()
253
    {
254 4
        $totalWidth = 0;
255 4
        foreach ($this->defs['templateMeta']['widths'] as $col => $def) {
256 4
            foreach ($def as $k => $value) {
257 4
                $totalWidth += $value;
258
            }
259
        }
260
261
        // calculate widths
262 4
        foreach ($this->defs['templateMeta']['widths'] as $col => $def) {
263 4
            foreach ($def as $k => $value) {
264 4
                $this->defs['templateMeta']['widths'][$col][$k] = round($value / ($totalWidth / 100), 2);
265
            }
266
        }
267
268 4
        $this->sectionPanels = array();
269 4
        $this->sectionLabels = array();
270 4
        if (!empty($this->defs['panels']) && count($this->defs['panels']) > 0)
271
        {
272 4
           $keys = array_keys($this->defs['panels']);
273 4
           if (is_numeric($keys[0]))
274
           {
275
               $defaultPanel = $this->defs['panels'];
276
               unset($this->defs['panels']); //blow away current value
277
               $this->defs['panels'][''] = $defaultPanel;
278
           }
279
        }
280
281 4
        if ($this->view == 'EditView' && !empty($GLOBALS['sugar_config']['forms']['requireFirst'])){
282
            $this->requiredFirst();
0 ignored issues
show
The method requiredFirst() does not seem to exist on object<EditView>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
283
        }
284
285 4
        $maxColumns = isset($this->defs['templateMeta']['maxColumns']) ? $this->defs['templateMeta']['maxColumns'] : 2;
286 4
        $panelCount = 0;
287 4
        static $itemCount = 100; //Start the generated tab indexes at 100 so they don't step on custom ones.
288
289
        /* loop all the panels */
290 4
        foreach ($this->defs['panels'] as $key=>$p)
291
        {
292 4
            $panel = array();
293
294 4
            if (!is_array($this->defs['panels'][$key])) {
295
               $this->sectionPanels[strtoupper($key)] = $p;
296
            }
297
            else
298
            {
299 4
                foreach ($p as $row=>$rowDef)
300
                {
301 4
                    $columnsInRows = count($rowDef);
302 4
                    $columnsUsed = 0;
303 4
                    foreach ($rowDef as $col => $colDef)
304
                    {
305 4
                        $panel[$row][$col] = is_array($p[$row][$col])
306 4
                            ? array('field' => $p[$row][$col])
307 2
                            : array('field' => array('name'=>$p[$row][$col]));
308
309 4
                        $panel[$row][$col]['field']['tabindex'] =
310 4
                            (isset($p[$row][$col]['tabindex']) && is_numeric($p[$row][$col]['tabindex']))
311
                                ? $p[$row][$col]['tabindex']
312 4
                                : '0';
313
314 4
                        if ($columnsInRows < $maxColumns)
315
                        {
316 4
                            if ($col == $columnsInRows - 1)
317
                            {
318 4
                                $panel[$row][$col]['colspan'] = 2 * $maxColumns - ($columnsUsed + 1);
319
                            }
320
                            else
321
                            {
322
                                $panel[$row][$col]['colspan'] = floor(($maxColumns * 2 - $columnsInRows) / $columnsInRows);
323
                                $columnsUsed = $panel[$row][$col]['colspan'];
324
                            }
325
                        }
326
327
                        //Set address types to have colspan value of 2 if colspan is not already defined
328 4
                        if (is_array($colDef) && !empty($colDef['hideLabel']) && !isset($panel[$row][$col]['colspan']))
329
                        {
330
                            $panel[$row][$col]['colspan'] = 2;
331
                        }
332
333 4
                        $itemCount++;
334
335
                    }
336
                }
337
338 4
			    	$panel = $this->getPanelWithFillers($panel);
0 ignored issues
show
The method getPanelWithFillers() does not seem to exist on object<EditView>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
339
340 4
			    	$this->sectionPanels[strtoupper($key)] = $panel;
341
		        }
342
343
344 4
		$panelCount++;
345
		} //foreach
346 4
    }
347
348
    /**
349
     * Adds fillers to each row if required
350
     *
351
     * Panel alignment will be off if the panel doesn't have a row with the max column
352
     * It will not be aligned to the other panels so we fill out the columns in the last row
353
     *
354
     * @param array $panel
355
     * @return array
356
     */
357 4
    protected function getPanelWithFillers($panel)
358
    {
359 4
        $addFiller = true;
360 4
        foreach($panel as $row)
361
        {
362 4
            if (count($row) == $this->defs['templateMeta']['maxColumns']
363 4
                || 1 == count($panel))
364
            {
365 4
                $addFiller = false;
366 4
                break;
367
            }
368
        }
369
370 4
        if ($addFiller)
371
        {
372
            $rowCount = count($panel);
373
            $filler   = count($panel[$rowCount-1]);
374
            while ($filler < $this->defs['templateMeta']['maxColumns'])
375
            {
376
                $panel[$rowCount - 1][$filler++] = array('field' => array('name' => ''));
377
            }
378
        }
379
380 4
        return $panel;
381
    }
382
383 6
    function process($checkFormName = false, $formName = '')
384
    {
385 6
        global $mod_strings, $sugar_config, $app_strings, $app_list_strings;
386
387
        //the retrieve already did this work;
388
        //$this->focus->fill_in_relationship_fields();
389
        //Bug#53261: If quickeditview is loaded after editview.tpl is created,
390
        //           the th->checkTemplate will return true. So, the following
391
        //           code prevent avoid rendering popup editview container.
392 6
        if(!empty($this->formName)) {
393 3
            $formName = $this->formName;
394 3
            $checkFormName = true;
395
        }
396
397 6
        if (!$this->th->checkTemplate($this->module, $this->view, $checkFormName, $formName))
398
        {
399 4
            $this->render();
0 ignored issues
show
The method render() does not seem to exist on object<EditView>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
400
        }
401
402 6
        if (isset($_REQUEST['offset']))
403
        {
404
            $this->offset = $_REQUEST['offset'] - 1;
405
        }
406
407 6
        if ($this->showVCRControl)
408
        {
409 5
            $this->th->ss->assign('PAGINATION', SugarVCR::menu($this->module, $this->offset, $this->focus->is_AuditEnabled(), ($this->view == 'EditView')));
410
        }
411
412 6
        if (isset($_REQUEST['return_module'])) $this->returnModule = $_REQUEST['return_module'];
413 6
        if (isset($_REQUEST['return_action'])) $this->returnAction = $_REQUEST['return_action'];
414 6
        if (isset($_REQUEST['return_id'])) $this->returnId = $_REQUEST['return_id'];
415 6
        if (isset($_REQUEST['return_relationship'])) $this->returnRelationship = $_REQUEST['return_relationship'];
416 6
        if (isset($_REQUEST['return_name'])) $this->returnName = $this->getValueFromRequest($_REQUEST, 'return_name' ) ;
0 ignored issues
show
The method getValueFromRequest() does not seem to exist on object<EditView>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
417
418
        // handle Create $module then Cancel
419 6
        if (empty($this->returnId))
420
        {
421 6
            $this->returnAction = 'index';
422
        }
423
424 6
        $is_owner = $this->focus->isOwner($GLOBALS['current_user']->id);
425
426 6
        $this->fieldDefs = array();
427 6
        if ($this->focus)
428
        {
429 6
            global $current_user;
430
431 6
            if (!empty($this->focus->assigned_user_id))
432
            {
433
                $this->focus->assigned_user_name = get_assigned_user_name($this->focus->assigned_user_id);
434
            }
435
436 6
            if (!empty($this->focus->job) && $this->focus->job_function == '')
437
            {
438
                $this->focus->job_function = $this->focus->job;
439
            }
440
441 6
            foreach ($this->focus->toArray() as $name => $value)
442
            {
443 6
                $valueFormatted = false;
444
                //if ($this->focus->field_defs[$name]['type']=='link')continue;
445
446 6
                $this->fieldDefs[$name] = (!empty($this->fieldDefs[$name]) && !empty($this->fieldDefs[$name]['value']))
447
                    ? array_merge($this->focus->field_defs[$name], $this->fieldDefs[$name])
448 6
                    : $this->focus->field_defs[$name];
449
450 6
                foreach (array("formula", "default", "comments", "help") as $toEscape)
451
                {
452 6
                    if (!empty($this->fieldDefs[$name][$toEscape]))
453
                    {
454 6
                        $this->fieldDefs[$name][$toEscape] = htmlentities($this->fieldDefs[$name][$toEscape], ENT_QUOTES, 'UTF-8');
455
                    }
456
                }
457
458 6
                if (isset($this->fieldDefs[$name]['options']) && isset($app_list_strings[$this->fieldDefs[$name]['options']]))
459
                {
460 6
                    if(isset($GLOBALS['sugar_config']['enable_autocomplete']) && $GLOBALS['sugar_config']['enable_autocomplete'] == true)
461
                    {
462
						$this->fieldDefs[$name]['autocomplete'] = true;
463
	                	$this->fieldDefs[$name]['autocomplete_options'] = $this->fieldDefs[$name]['options']; // we need the name for autocomplete
464
					} else {
465 6
                        $this->fieldDefs[$name]['autocomplete'] = false;
466
                   	}
467
                   	// Bug 57472 - $this->fieldDefs[$name]['autocomplete_options' was set too late, it didn't retrieve the list's name, but the list itself (the developper comment show us that developper expected to retrieve list's name and not the options array)
468 6
                   	$this->fieldDefs[$name]['options'] = $app_list_strings[$this->fieldDefs[$name]['options']];
469
                }
470
471 6
                if(isset($this->fieldDefs[$name]['options']) && is_array($this->fieldDefs[$name]['options']) && isset($this->fieldDefs[$name]['default_empty']) && !isset($this->fieldDefs[$name]['options'][$this->fieldDefs[$name]['default_empty']])) {
472
                    $this->fieldDefs[$name]['options'] = array_merge(array($this->fieldDefs[$name]['default_empty']=>$this->fieldDefs[$name]['default_empty']), $this->fieldDefs[$name]['options']);
473
                }
474
                                
475 6
	       	 	if(isset($this->fieldDefs[$name]['function'])) {
476 6
	       	 		$function = $this->fieldDefs[$name]['function'];
477 6
	       			if(is_array($function) && isset($function['name'])){
478 6
	       				$function = $this->fieldDefs[$name]['function']['name'];
479
	       			}else{
480
	       				$function = $this->fieldDefs[$name]['function'];
481
	       			}
482
483 6
                    if(isset($this->fieldDefs[$name]['function']['include']) && file_exists($this->fieldDefs[$name]['function']['include']))
484
                    {
485 2
                  		require_once($this->fieldDefs[$name]['function']['include']);
486
                  	}
487
488 6
	       	 		if(!empty($this->fieldDefs[$name]['function']['returns']) && $this->fieldDefs[$name]['function']['returns'] == 'html'){
489 6
						if(!empty($this->fieldDefs[$name]['function']['include'])){
490 2
								require_once($this->fieldDefs[$name]['function']['include']);
491
						}
492 6
						$value = call_user_func($function, $this->focus, $name, $value, $this->view);
493 6
						$valueFormatted = true;
494
					}else{
495
						$this->fieldDefs[$name]['options'] = call_user_func($function, $this->focus, $name, $value, $this->view);
496
					}
497
	       	 	}
498
499 6
	       	 	if(isset($this->fieldDefs[$name]['type']) && $this->fieldDefs[$name]['type'] == 'function' && isset($this->fieldDefs[$name]['function_name'])){
500
	       	 		$value = $this->callFunction($this->fieldDefs[$name]);
0 ignored issues
show
The method callFunction() does not seem to exist on object<EditView>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
501
	       	 		$valueFormatted = true;
502
	       	 	}
503
504 6
	       	 	if(!$valueFormatted) {
505
                    // $this->focus->format_field($this->focus->field_defs[$name]);
506 6
                   $value = isset($this->focus->$name) ? $this->focus->$name : '';
507
                }
508
509 6
                if (empty($this->fieldDefs[$name]['value']))
510
                {
511 6
                    $this->fieldDefs[$name]['value'] = $value;
512
                }
513
514
515
                //This code is used for QuickCreates that go to Full Form view.  We want to overwrite the values from the bean
516
                //with values from the request if they are set and either the bean is brand new (such as a create from a subpanels) or the 'full form' button has been clicked
517 6
                if ((($this->populateBean && empty($this->focus->id)) || (isset($_REQUEST['full_form'])))
518 6
                    && (!isset($this->fieldDefs[$name]['function']['returns']) || $this->fieldDefs[$name]['function']['returns'] != 'html')
519 6
                    && isset($_REQUEST[$name]))
520
                {
521
                    $this->fieldDefs[$name]['value'] = $this->getValueFromRequest($_REQUEST, $name);
0 ignored issues
show
The method getValueFromRequest() does not seem to exist on object<EditView>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
522
                }
523
524
               /*
525
                * Populate any relate fields that are linked by a relationship to the calling module.
526
                * Clicking the create button on a subpanel for example will populate three values in the $_REQUEST:
527
                * 1. return_module => the name of the calling module
528
                * 2. return_id => the id of the record in the calling module that the user was viewing and that should be associated with this new record
529
                * 3. return_name => the display value of the return_id record - the value to show in any relate field in this EditView
530
                * Only do if this fieldDef does not already have a value; if it does it will have been explicitly set, and that should overrule this less specific mechanism
531
                */
532 6
                if (isset($this->returnModule) && isset($this->returnName)
533 6
                    && empty($this->focus->id) && empty($this->fieldDefs['name']['value']) )
534
                {
535
                   if (($this->focus->field_defs[$name]['type'] == 'relate')
536
                       && isset($this->focus->field_defs[$name][ 'module' ])
537
                       && $this->focus->field_defs[$name][ 'module' ] == $this->returnModule)
538
                   {
539
                       if (isset( $this->fieldDefs[$name]['id_name'])
540
                           && !empty($this->returnRelationship)
541
                           && isset($this->focus->field_defs[$this->fieldDefs[$name]['id_name']]['relationship'])
542
                           && ($this->returnRelationship == $this->focus->field_defs[$this->fieldDefs[$name]['id_name']]['relationship']))
543
                       {
544
                           $this->fieldDefs[$name]['value'] =  $this->returnName ;
545
                           // set the hidden id field for this relate field to the correct value i.e., return_id
546 6
                           $this->fieldDefs[$this->fieldDefs[$name]['id_name']]['value'] = $this->returnId ;
547
                       }
548
                   }
549
                }
550
            }
551
        }
552
553 6
        if (isset($this->focus->additional_meta_fields))
554
        {
555 6
            $this->fieldDefs = array_merge($this->fieldDefs, $this->focus->additional_meta_fields);
556
        }
557
558 6
        if ($this->isDuplicate)
559
        {
560
            foreach ($this->fieldDefs as $name=>$defs) {
561
                if (!empty($defs['auto_increment']))
562
                {
563
                    $this->fieldDefs[$name]['value'] = '';
564
                }
565
            }
566
        }
567 6
    }
568
569
    
570
    /**
571
     * display
572
     * This method makes the Smarty variable assignments and then displays the
573
     * generated view.
574
     * @param $showTitle boolean value indicating whether or not to show a title on the resulting page
575
     * @param $ajaxSave boolean value indicating whether or not the operation is an Ajax save request
576
     * @return HTML display for view as String
577
     */
578 6
    function display($showTitle = true, $ajaxSave = false)
579
    {
580 6
        global $mod_strings, $sugar_config, $app_strings, $app_list_strings, $theme, $current_user;
581
582 6
        if(isset($this->defs['templateMeta']['javascript']))
583
        {
584
            if(is_array($this->defs['templateMeta']['javascript']))
585
            {
586
                //$this->th->ss->assign('externalJSFile', 'modules/' . $this->module . '/metadata/editvewdefs.js');
587
                $this->th->ss->assign('externalJSFile', $this->defs['templateMeta']['javascript']);
588
            }
589
            else
590
            {
591
                $this->th->ss->assign('scriptBlocks', $this->defs['templateMeta']['javascript']);
592
            }
593
        }
594
595 6
        $this->th->ss->assign('id', $this->fieldDefs['id']['value']);
596 6
        $this->th->ss->assign('offset', $this->offset + 1);
597 6
        $this->th->ss->assign('APP', $app_strings);
598 6
        $this->th->ss->assign('MOD', $mod_strings);
599 6
        $this->th->ss->assign('fields', $this->fieldDefs);
600 6
        $this->th->ss->assign('sectionPanels', $this->sectionPanels);
601 6
        $this->th->ss->assign('config', $sugar_config);
602 6
        $this->th->ss->assign('returnModule', $this->returnModule);
603 6
        $this->th->ss->assign('returnAction', $this->returnAction);
604 6
        $this->th->ss->assign('returnId', $this->returnId);
605 6
        $this->th->ss->assign('isDuplicate', $this->isDuplicate);
606 6
        $this->th->ss->assign('def', $this->defs);
607 6
        $this->th->ss->assign('useTabs', isset($this->defs['templateMeta']['useTabs']) && isset($this->defs['templateMeta']['tabDefs']) ? $this->defs['templateMeta']['useTabs'] : false);
608 6
        $this->th->ss->assign('maxColumns', isset($this->defs['templateMeta']['maxColumns']) ? $this->defs['templateMeta']['maxColumns'] : 2);
609 6
        $this->th->ss->assign('module', $this->module);
610 6
        $this->th->ss->assign('headerTpl', isset($this->defs['templateMeta']['form']['headerTpl']) ? $this->defs['templateMeta']['form']['headerTpl'] : 'include/' . $this->view . '/header.tpl');
611 6
        $this->th->ss->assign('footerTpl', isset($this->defs['templateMeta']['form']['footerTpl']) ? $this->defs['templateMeta']['form']['footerTpl'] : 'include/' . $this->view . '/footer.tpl');
612 6
        $this->th->ss->assign('current_user', $current_user);
613 6
        $this->th->ss->assign('bean', $this->focus);
614 6
        $this->th->ss->assign('isAuditEnabled', $this->focus->is_AuditEnabled());
615 6
        $this->th->ss->assign('gridline',$current_user->getPreference('gridline') == 'on' ? '1' : '0');
616 6
        $this->th->ss->assign('tabDefs', isset($this->defs['templateMeta']['tabDefs']) ? $this->defs['templateMeta']['tabDefs'] : false);
617 6
        $this->th->ss->assign('VERSION_MARK', getVersionedPath(''));
618
619 6
        global $js_custom_version;
620 6
        global $sugar_version;
621
622 6
        $this->th->ss->assign('SUGAR_VERSION', $sugar_version);
623 6
        $this->th->ss->assign('JS_CUSTOM_VERSION', $js_custom_version);
624
625
        //this is used for multiple forms on one page
626 6
        if (!empty($this->formName)) {
627 3
            $form_id = $this->formName;
628 3
            $form_name = $this->formName;
629
        }
630
        else
631
        {
632 3
            $form_id = $this->view;
633 3
            $form_name = $this->view;
634
        }
635
636 6
        if ($ajaxSave && empty($this->formName))
637
        {
638
            $form_id = 'form_'.$this->view .'_'.$this->module;
639
            $form_name = $form_id;
640
            $this->view = $form_name;
641
            //$this->defs['templateMeta']['form']['buttons'] = array();
642
            //$this->defs['templateMeta']['form']['buttons']['ajax_save'] = array('id' => 'AjaxSave', 'customCode'=>'<input type="button" class="button" value="Save" onclick="this.form.action.value=\'AjaxFormSave\';return saveForm(\''.$form_name.'\', \'multiedit_form_{$module}\', \'Saving {$module}...\');"/>');
643
        }
644
645 6
        $form_name = $form_name == 'QuickCreate' ? "QuickCreate_{$this->module}" : $form_name;
646 6
        $form_id = $form_id == 'QuickCreate' ? "QuickCreate_{$this->module}" : $form_id;
647
648 6
        if (isset($this->defs['templateMeta']['preForm']))
649
        {
650
            $this->th->ss->assign('preForm', $this->defs['templateMeta']['preForm']);
651
        }
652
653 6
        if (isset($this->defs['templateMeta']['form']['closeFormBeforeCustomButtons']))
654
        {
655
            $this->th->ss->assign('closeFormBeforeCustomButtons', $this->defs['templateMeta']['form']['closeFormBeforeCustomButtons']);
656
        }
657
658 6
        if(isset($this->defs['templateMeta']['form']['enctype']))
659
        {
660
            $this->th->ss->assign('enctype', 'enctype="'.$this->defs['templateMeta']['form']['enctype'].'"');
661
        }
662
663
        //for SugarFieldImage, we must set form enctype to "multipart/form-data"
664 6
        foreach ($this->fieldDefs as $field)
665
        {
666 6
            if (isset($field['type']) && $field['type'] == 'image')
667
            {
668 3
                $this->th->ss->assign('enctype', 'enctype="multipart/form-data"');
669 6
                break;
670
            }
671
        }
672
673 6
        $this->th->ss->assign('showDetailData', $this->showDetailData);
674 6
        $this->th->ss->assign('showSectionPanelsTitles', $this->showSectionPanelsTitles);
675 6
        $this->th->ss->assign('form_id', $form_id);
676 6
        $this->th->ss->assign('form_name', $form_name);
677 6
        $this->th->ss->assign('set_focus_block', get_set_focus_js());
678
679 6
        $this->th->ss->assign('form', isset($this->defs['templateMeta']['form']) ? $this->defs['templateMeta']['form'] : null);
680 6
        $this->th->ss->assign('includes', isset($this->defs['templateMeta']['includes']) ? $this->defs['templateMeta']['includes'] : null);
681 6
        $this->th->ss->assign('view', $this->view);
682
683
684
        //Calculate time & date formatting (may need to calculate this depending on a setting)
685 6
        global $timedate;
686
687 6
        $this->th->ss->assign('CALENDAR_DATEFORMAT', $timedate->get_cal_date_format());
688 6
        $this->th->ss->assign('USER_DATEFORMAT', $timedate->get_user_date_format());
689 6
        $time_format = $timedate->get_user_time_format();
690 6
        $this->th->ss->assign('TIME_FORMAT', $time_format);
691
692 6
        $date_format = $timedate->get_cal_date_format();
693 6
        $time_separator = ':';
694 6
        if (preg_match('/\d+([^\d])\d+([^\d]*)/s', $time_format, $match))
695
        {
696 6
            $time_separator = $match[1];
697
        }
698
699
        // Create Smarty variables for the Calendar picker widget
700 6
        $t23 = strpos($time_format, '23') !== false ? '%H' : '%I';
701 6
        if (!isset($match[2]) || $match[2] == '')
702
        {
703 6
            $this->th->ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . '%M');
704
        }
705
        else
706
        {
707
            $pm = $match[2] == 'pm' ? '%P' : '%p';
708
            $this->th->ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . '%M' . $pm);
709
        }
710
711 6
        $this->th->ss->assign('CALENDAR_FDOW', $current_user->get_first_day_of_week());
712 6
        $this->th->ss->assign('TIME_SEPARATOR', $time_separator);
713
714 6
        $seps = get_number_seperators();
715 6
        $this->th->ss->assign('NUM_GRP_SEP', $seps[0]);
716 6
        $this->th->ss->assign('DEC_SEP', $seps[1]);
717
718 6
        if ($this->view == 'EditView')
719
        {
720 1
            $height = $current_user->getPreference('text_editor_height');
721 1
            $width  = $current_user->getPreference('text_editor_width');
722
723 1
            $height = isset($height) ? $height : '300px';
724 1
            $width  = isset($width) ? $width : '95%';
725
726 1
            $this->th->ss->assign('RICH_TEXT_EDITOR_HEIGHT', $height);
727 1
            $this->th->ss->assign('RICH_TEXT_EDITOR_WIDTH', $width);
728
        }
729
        else
730
        {
731 5
            $this->th->ss->assign('RICH_TEXT_EDITOR_HEIGHT', '100px');
732 5
            $this->th->ss->assign('RICH_TEXT_EDITOR_WIDTH', '95%');
733
        }
734
735 6
        $this->th->ss->assign('SHOW_VCR_CONTROL', $this->showVCRControl);
736
737 6
        $str = $this->showTitle($showTitle);
0 ignored issues
show
The method showTitle() does not seem to exist on object<EditView>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
738
739
        //Use the output filter to trim the whitespace
740 6
        $this->th->ss->load_filter('output', 'trimwhitespace');
741 6
        $str .= $this->th->displayTemplate($this->module, $form_name, $this->tpl, $ajaxSave, $this->defs);
742
743
        /* BEGIN - SECURITY GROUPS */ 
744
        //if popup select add panel if user is a member of multiple groups to metadataFile
745 6
        global $sugar_config;
746 6
        if(isset($sugar_config['securitysuite_popup_select']) && $sugar_config['securitysuite_popup_select'] == true
747 6
            && empty($this->focus->fetched_row['id']) && $this->focus->module_dir != "Users" && $this->focus->module_dir != "SugarFeed") {
748
749
            //there are cases such as uploading an attachment to an email template where the request module may
750
            //not be the same as the current bean module. If that happens we can just skip it
751
            //however...let quickcreate through
752
            if($this->view != 'QuickCreate' && (empty($_REQUEST['module']) || $_REQUEST['module'] != $this->focus->module_dir)) return $str;
753
754
            require_once('modules/SecurityGroups/SecurityGroup.php');
755
            $groupFocus = new SecurityGroup();
756
            $security_modules = $groupFocus->getSecurityModules();
757
            if(in_array($this->focus->module_dir,array_keys($security_modules))) {
758
                global $current_user;
759
760
                $group_count = $groupFocus->getMembershipCount($current_user->id);
761
                if($group_count > 1) {
762
                
763
                    $groups = $groupFocus->getUserSecurityGroups($current_user->id);
764
                    $group_options = '';
765
                    foreach($groups as $group) {
766
                        $group_options .= '<option value="'.$group['id'].'" label="'.$group['name'].'" selected="selected">'.$group['name'].'</option>';
767
                    }
768
                    //multilingual support
769
                    global $current_language;
770
                    $ss_mod_strings = return_module_language($current_language, 'SecurityGroups');  
771
                    
772
                    $lbl_securitygroups_select = $ss_mod_strings['LBL_GROUP_SELECT'];
773
                    $lbl_securitygroups = $ss_mod_strings['LBL_LIST_FORM_TITLE'];
774
                    
775
                    $group_panel = <<<EOQ
776
<div class="edit view edit508 " id="detailpanel_securitygroups">
777
    <h4>&nbsp;&nbsp;
778
    $lbl_securitygroups_select
779
    </h4>
780
    <table width="100%" cellspacing="1" cellpadding="0" border="0" class="edit view panelContainer" id="LBL_PANEL_SECURITYGROUPS">
781
    <tbody><tr>
782
    <td width="12.5%" valign="top" scope="col" id="account_type_label">
783
        $lbl_securitygroups:
784
    </td>
785
    <td width="37.5%" valign="top">
786
        <select title="" id="securitygroup_list" name="securitygroup_list[]" multiple="multiple" size="${group_count}">
787
        $group_options
788
        </select>
789
    </td>
790
    </tr>
791
    </tbody></table>
792
</div>
793
EOQ;
794
                    $group_panel = preg_replace("/[\r\n]+/", "", $group_panel);
795
796
                    $group_panel_append = <<<EOQ
797
<script>
798
    $('#${form_name}_tabs div:first').append($('${group_panel}'));
799
</script>
800
EOQ;
801
                    $str .= $group_panel_append;
802
                }
803
            }
804
        }
805
        /* END - SECURITY GROUPS */  
806
        
807 6
        return $str;
808
    }
809
810
    function insertJavascript($javascript)
811
    {
812
        $this->ss->assign('javascript', $javascript);
813
    }
814
815
    function callFunction($vardef)
816
    {
817
        $can_execute = true;
818
        $execute_function = array();
819
        $execute_params = array();
820
        if (!empty($vardef['function_class']))
821
        {
822
            $execute_function[] = $vardef['function_class'];
823
            $execute_function[] = $vardef['function_name'];
824
        }
825
        else
826
        {
827
            $execute_function = $vardef['function_name'];
828
        }
829
830
        foreach ($vardef['function_params'] as $param )
831
        {
832
            if (empty($vardef['function_params_source']) or $vardef['function_params_source']=='parent')
833
            {
834
                if (empty($this->focus->$param))
835
                {
836
                    $can_execute = false;
837
                }
838
                else
839
                {
840
                    $execute_params[] = $this->focus->$param;
841
                }
842
            }
843
            else if ($vardef['function_params_source']=='this')
844
            {
845
                if (empty($this->focus->$param))
846
                {
847
                    $can_execute = false;
848
                } else {
849
                    $execute_params[] = $this->focus->$param;
850
                }
851
            }
852
            else
853
            {
854
                $can_execute = false;
855
            }
856
        }
857
858
        $value = '';
859
        if ($can_execute)
860
        {
861
            if (!empty($vardef['function_require']))
862
            {
863
                require_once($vardef['function_require']);
864
            }
865
866
            $value = call_user_func_array($execute_function, $execute_params);
867
        }
868
869
        return $value;
870
    }
871
872
    /**
873
     * getValueFromRequest
874
     * This is a helper method to extract a value from the request
875
     * Array.  We do some special processing for fields that start
876
     * with 'date_' by checking to see if they also include time
877
     * and meridiem values
878
     *
879
     * @param request The request Array
880
     * @param name The field name to extract value for
881
     * @return String value for given name
882
     */
883
    function getValueFromRequest($request, $name)
884
    {
885
        //Special processing for date values (combine to one field)
886
        if (preg_match('/^date_(.*)$/s', $name, $matches))
887
        {
888
            $d = $request[$name];
889
890
            if (isset($request['time_' . $matches[1]]))
891
            {
892
                $d .= ' ' . $request['time_' . $matches[1]];
893
                if (isset($request[$matches[1] . '_meridiem']))
894
                {
895
                    $d .= $request[$matches[1] . '_meridiem'];
896
                }
897
            }
898
            else
899
            {
900
                if (isset($request['time_hour_' . $matches[1]])
901
                    && isset($request['time_minute_' . $matches[1]]))
902
                {
903
                    $d .= sprintf(' %s:%s', $request['time_hour_' . $matches[1]], $request['time_minute_' . $matches[1]]);
904
                }
905
906
                if (isset($request['meridiem']))
907
                {
908
                    $d .= $request['meridiem'];
909
                }
910
           }
911
912
           return $d;
913
        }
914
915
        if (empty($request[$name]) || !isset($this->fieldDefs[$name]))
916
        {
917
           return $request[$name];
918
        }
919
920
        //if it's a bean field - unformat it
921
        require_once('include/SugarFields/SugarFieldHandler.php');
922
923
        $sfh  = new SugarFieldHandler();
924
        $type = !empty($this->fieldDefs[$name]['custom_type'])
925
            ? $this->fieldDefs[$name]['custom_type']
926
            : $this->fieldDefs[$name]['type'];
927
        $sf   = $sfh->getSugarField($type);
928
929
        return $sf ? $sf->unformatField($request[$name], $this->fieldDefs[$name]) : $request[$name];
930
    }
931
932
933
	/**
934
	 * Allow Subviews to overwrite this method to show custom titles.
935
	 * Examples: Projects & Project Templates.
936
	 * params: $showTitle: boolean for backwards compatibility.
937
	 */
938
    public function showTitle($showTitle = false)
939
    {
940 6
        global $mod_strings, $app_strings;
941
942 6
        if (is_null($this->viewObject))
943
        {
944 6
            $this->viewObject = (!empty($GLOBALS['current_view']))
945
                ? $GLOBALS['current_view']
946 6
                : new SugarView();
947
        }
948
949 6
        if ($showTitle)
950
        {
951 2
            return $this->viewObject->getModuleTitle();
952
        }
953
954 4
        return '';
955
    }
956
957
    /**
958
     * Get template handler object
959
     * @return TemplateHandler
960
     */
961
    protected function getTemplateHandler()
962
    {
963 5
        return new TemplateHandler();
964
    }
965 1
}
966
967