2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Affero General Public License version 3 as published by the
8 * Free Software Foundation with the addition of the following permission added
9 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
18 * You should have received a copy of the GNU Affero General Public License along with
19 * this program; if not, see http://www.gnu.org/licenses or write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26 * The interactive user interfaces in modified source and object code versions
27 * of this program must display Appropriate Legal Notices, as required under
28 * Section 5 of the GNU Affero General Public License version 3.
30 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31 * these Appropriate Legal Notices must retain the display of the "Powered by
32 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33 * technical reasons, the Appropriate Legal Notices must display the words
34 * "Powered by SugarCRM".
35 ********************************************************************************/
39 require_once('include/TemplateHandler/TemplateHandler.php');
40 require_once('include/EditView/SugarVCR.php');
58 public $sectionPanels;
59 public $view = 'EditView';
60 public $formatFields = true;
61 public $showDetailData = true;
62 public $showVCRControl = true;
63 public $showSectionPanelsTitles = true;
64 public $quickSearchCode;
67 public $populateBean = true;
68 public $moduleTitleKey;
69 public $viewObject = null;
70 public $formName = '';
73 * EditView constructor
74 * This is the EditView constructor responsible for processing the new
77 * @param $module String value of module this Edit view is for
78 * @param $focus An empty sugarbean object of module
79 * @param $id The record id to retrieve and populate data for
80 * @param $metadataFile String value of file location to use in overriding default metadata file
81 * @param tpl String value of file location to use in overriding default Smarty template
82 * @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
85 function setup($module, $focus = null, $metadataFile = null, $tpl = 'include/EditView/EditView.tpl', $createFocus = true)
87 $this->th = new TemplateHandler();
88 $this->th->ss =& $this->ss;
90 $this->module = $module;
91 $this->focus = $focus;
93 //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
94 //but in convert lead we do not want to create a new instance and do not want to populate id.
100 if (empty($GLOBALS['sugar_config']['showDetailData']))
102 $this->showDetailData = false;
104 $this->metadataFile = $metadataFile;
106 if (isset($GLOBALS['sugar_config']['disable_vcr']))
108 $this->showVCRControl = !$GLOBALS['sugar_config']['disable_vcr'];
111 if (!empty($this->metadataFile) && file_exists($this->metadataFile))
113 include($this->metadataFile);
117 //If file doesn't exist we create a best guess
118 if (!file_exists("modules/$this->module/metadata/editviewdefs.php")
119 && file_exists("modules/$this->module/EditView.html"))
121 require_once('include/SugarFields/Parsers/EditViewMetaParser.php');
125 $htmlFile = "modules/" . $this->module . "/EditView.html";
126 $parser = new EditViewMetaParser();
127 if (!file_exists('modules/'.$this->module.'/metadata'))
129 sugar_mkdir('modules/'.$this->module.'/metadata');
132 $fp = sugar_fopen('modules/'.$this->module.'/metadata/editviewdefs.php', 'w');
133 fwrite($fp, $parser->parse($htmlFile, $dictionary[$focus->object_name]['fields'], $this->module));
137 //Flag an error... we couldn't create the best guess meta-data file
138 if (!file_exists("modules/$this->module/metadata/editviewdefs.php"))
142 $error = str_replace("[file]", "modules/$this->module/metadata/editviewdefs.php", $app_strings['ERR_CANNOT_CREATE_METADATA_FILE']);
143 $GLOBALS['log']->fatal($error);
148 require_once("modules/$this->module/metadata/editviewdefs.php");
151 $this->defs = $viewdefs[$this->module][$this->view];
152 $this->isDuplicate = isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true' && $this->focus->aclAccess('edit');
155 function createFocus()
157 global $beanList, $beanFiles;
159 if (empty($beanList[$this->module])) return;
162 $bean = $beanList[$this->module];
163 require_once($beanFiles[$bean]);
168 //If there is no idea, assume we are creating a new instance
169 //and call the fill_in_additional_detail_fields where initialization
170 //code has been moved to
171 if (empty($this->focus->id))
173 global $current_user;
175 $this->focus->fill_in_additional_detail_fields();
176 $this->focus->assigned_user_id = $current_user->id;
180 function populateBean()
182 if (!empty($_REQUEST['record']) && $this->populateBean)
186 $bean = $beanList[$this->module];
188 $this->focus = $obj->retrieve($_REQUEST['record']);
192 $GLOBALS['log']->debug("Unable to populate bean, no record parameter found");
198 * This method is used to manually turn on/off the field formatting
199 * @param $format boolean value to turn on/off field formatting
201 function enableFormatting($format = true)
203 $this->formatFields = $format;
207 * Enter description here ...
209 function requiredFirst()
211 $panels = array('required'=>array());
214 foreach($this->defs['panels'] as $key=>$p)
216 foreach ($p as $row=>$rowDef)
218 foreach($rowDef as $col => $colDef)
220 $field = (is_array($p[$row][$col])) ? $p[$row][$col]['name'] : $p[$row][$col];
221 if ((!empty($this->focus->field_defs[$field])
222 && !empty($this->focus->field_defs[$field]['required']))
223 || (!empty($p[$row][$col]['displayParams']['required'])))
226 if ($reqCol == $this->defs['templateMeta']['maxColumns'])
232 $panels['required'][$reqRow][$reqCol] = $p[$row][$col];
236 $panels[$key][$row][$col] = $p[$row][$col];
242 $this->defs['panels'] = $panels;
248 foreach ($this->defs['templateMeta']['widths'] as $col => $def) {
249 foreach ($def as $k => $value) {
250 $totalWidth += $value;
255 foreach ($this->defs['templateMeta']['widths'] as $col => $def) {
256 foreach ($def as $k => $value) {
257 $this->defs['templateMeta']['widths'][$col][$k] = round($value / ($totalWidth / 100), 2);
261 $this->sectionPanels = array();
262 $this->sectionLabels = array();
263 if (!empty($this->defs['panels']) && count($this->defs['panels']) > 0)
265 $keys = array_keys($this->defs['panels']);
266 if (is_numeric($keys[0]))
268 $defaultPanel = $this->defs['panels'];
269 unset($this->defs['panels']); //blow away current value
270 $this->defs['panels'][''] = $defaultPanel;
274 if ($this->view == 'EditView' && !empty($GLOBALS['sugar_config']['forms']['requireFirst'])){
275 $this->requiredFirst();
278 $maxColumns = isset($this->defs['templateMeta']['maxColumns']) ? $this->defs['templateMeta']['maxColumns'] : 2;
280 static $itemCount = 100; //Start the generated tab indexes at 100 so they don't step on custom ones.
282 /* loop all the panels */
283 foreach ($this->defs['panels'] as $key=>$p)
287 if (!is_array($this->defs['panels'][$key])) {
288 $this->sectionPanels[strtoupper($key)] = $p;
292 foreach ($p as $row=>$rowDef)
294 $columnsInRows = count($rowDef);
296 foreach ($rowDef as $col => $colDef)
298 $panel[$row][$col] = is_array($p[$row][$col])
299 ? array('field' => $p[$row][$col])
300 : array('field' => array('name'=>$p[$row][$col]));
302 $panel[$row][$col]['field']['tabindex'] =
303 (isset($p[$row][$col]['tabindex']) && is_numeric($p[$row][$col]['tabindex']))
304 ? $p[$row][$col]['tabindex']
307 if ($columnsInRows < $maxColumns)
309 if ($col == $columnsInRows - 1)
311 $panel[$row][$col]['colspan'] = 2 * $maxColumns - ($columnsUsed + 1);
315 $panel[$row][$col]['colspan'] = floor(($maxColumns * 2 - $columnsInRows) / $columnsInRows);
316 $columnsUsed = $panel[$row][$col]['colspan'];
320 //Set address types to have colspan value of 2 if colspan is not already defined
321 if (is_array($colDef) && !empty($colDef['hideLabel']) && !isset($panel[$row][$col]['colspan']))
323 $panel[$row][$col]['colspan'] = 2;
331 $panel = $this->getPanelWithFillers($panel);
333 $this->sectionPanels[strtoupper($key)] = $panel;
342 * Adds fillers to each row if required
344 * Panel alignment will be off if the panel doesn't have a row with the max column
345 * It will not be aligned to the other panels so we fill out the columns in the last row
347 * @param array $panel
350 protected function getPanelWithFillers($panel)
353 foreach($panel as $row)
355 if (count($row) == $this->defs['templateMeta']['maxColumns']
356 || 1 == count($panel))
365 $rowCount = count($panel);
366 $filler = count($panel[$rowCount-1]);
367 while ($filler < $this->defs['templateMeta']['maxColumns'])
369 $panel[$rowCount - 1][$filler++] = array('field' => array('name' => ''));
376 function process($checkFormName = false, $formName = '')
378 global $mod_strings, $sugar_config, $app_strings, $app_list_strings;
380 //the retrieve already did this work;
381 //$this->focus->fill_in_relationship_fields();
383 if (!$this->th->checkTemplate($this->module, $this->view, $checkFormName, $formName))
388 if (isset($_REQUEST['offset']))
390 $this->offset = $_REQUEST['offset'] - 1;
393 if ($this->showVCRControl)
395 $this->th->ss->assign('PAGINATION', SugarVCR::menu($this->module, $this->offset, $this->focus->is_AuditEnabled(), ($this->view == 'EditView')));
398 if (isset($_REQUEST['return_module'])) $this->returnModule = $_REQUEST['return_module'];
399 if (isset($_REQUEST['return_action'])) $this->returnAction = $_REQUEST['return_action'];
400 if (isset($_REQUEST['return_id'])) $this->returnId = $_REQUEST['return_id'];
401 if (isset($_REQUEST['return_relationship'])) $this->returnRelationship = $_REQUEST['return_relationship'];
402 if (isset($_REQUEST['return_name'])) $this->returnName = $this->getValueFromRequest($_REQUEST, 'return_name' ) ;
404 // handle Create $module then Cancel
405 if (empty($this->returnId))
407 $this->returnAction = 'index';
410 $is_owner = $this->focus->isOwner($GLOBALS['current_user']->id);
412 $this->fieldDefs = array();
415 global $current_user;
417 if (!empty($this->focus->assigned_user_id))
419 $this->focus->assigned_user_name = get_assigned_user_name($this->focus->assigned_user_id);
423 foreach ($this->focus->toArray() as $name => $value)
425 $valueFormatted = false;
426 //if ($this->focus->field_defs[$name]['type']=='link')continue;
428 $this->fieldDefs[$name] = (!empty($this->fieldDefs[$name]) && !empty($this->fieldDefs[$name]['value']))
429 ? array_merge($this->focus->field_defs[$name], $this->fieldDefs[$name])
430 : $this->focus->field_defs[$name];
432 foreach (array("formula", "default", "comments", "help") as $toEscape)
434 if (!empty($this->fieldDefs[$name][$toEscape]))
436 $this->fieldDefs[$name][$toEscape] = htmlentities($this->fieldDefs[$name][$toEscape], ENT_QUOTES, 'UTF-8');
440 if (isset($this->fieldDefs[$name]['options']) && isset($app_list_strings[$this->fieldDefs[$name]['options']]))
442 $this->fieldDefs[$name]['options'] = $app_list_strings[$this->fieldDefs[$name]['options']];
443 if(isset($GLOBALS['sugar_config']['enable_autocomplete']) && $GLOBALS['sugar_config']['enable_autocomplete'] == true){
444 $this->fieldDefs[$name]['autocomplete'] = true;
445 $this->fieldDefs[$name]['autocomplete_options'] = $this->fieldDefs[$name]['options']; // we need the name for autocomplete
447 $this->fieldDefs[$name]['autocomplete'] = false;
451 if(isset($this->fieldDefs[$name]['function'])) {
452 $function = $this->fieldDefs[$name]['function'];
453 if(is_array($function) && isset($function['name'])){
454 $function = $this->fieldDefs[$name]['function']['name'];
456 $function = $this->fieldDefs[$name]['function'];
458 if(!empty($this->fieldDefs[$name]['function']['returns']) && $this->fieldDefs[$name]['function']['returns'] == 'html'){
459 if(!empty($this->fieldDefs[$name]['function']['include'])){
460 require_once($this->fieldDefs[$name]['function']['include']);
462 $value = $function($this->focus, $name, $value, $this->view);
463 $valueFormatted = true;
465 $this->fieldDefs[$name]['options'] = $function($this->focus, $name, $value, $this->view);
469 if(isset($this->fieldDefs[$name]['type']) && $this->fieldDefs[$name]['type'] == 'function' && isset($this->fieldDefs[$name]['function_name'])){
470 $value = $this->callFunction($this->fieldDefs[$name]);
471 $valueFormatted = true;
474 if(!$valueFormatted) {
475 // $this->focus->format_field($this->focus->field_defs[$name]);
476 $value = isset($this->focus->$name) ? $this->focus->$name : '';
479 if (empty($this->fieldDefs[$name]['value']))
481 $this->fieldDefs[$name]['value'] = $value;
485 //This code is used for QuickCreates that go to Full Form view. We want to overwrite the values from the bean
486 //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
487 if ((($this->populateBean && empty($this->focus->id)) || (isset($_REQUEST['full_form'])))
488 && (!isset($this->fieldDefs[$name]['function']['returns']) || $this->fieldDefs[$name]['function']['returns'] != 'html')
489 && isset($_REQUEST[$name]))
491 $this->fieldDefs[$name]['value'] = $this->getValueFromRequest($_REQUEST, $name);
495 * Populate any relate fields that are linked by a relationship to the calling module.
496 * Clicking the create button on a subpanel for example will populate three values in the $_REQUEST:
497 * 1. return_module => the name of the calling module
498 * 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
499 * 3. return_name => the display value of the return_id record - the value to show in any relate field in this EditView
500 * 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
502 if (isset($this->returnModule) && isset($this->returnName)
503 && empty($this->focus->id) && empty($this->fieldDefs['name']['value']) )
505 if (($this->focus->field_defs[$name]['type'] == 'relate')
506 && isset($this->focus->field_defs[$name][ 'module' ])
507 && $this->focus->field_defs[$name][ 'module' ] == $this->returnModule)
509 if (isset( $this->fieldDefs[$name]['id_name'])
510 && !empty($this->returnRelationship)
511 && isset($this->focus->field_defs[$this->fieldDefs[$name]['id_name']]['relationship'])
512 && ($this->returnRelationship == $this->focus->field_defs[$this->fieldDefs[$name]['id_name']]['relationship']))
514 $this->fieldDefs[$name]['value'] = $this->returnName ;
515 // set the hidden id field for this relate field to the correct value i.e., return_id
516 $this->fieldDefs[$this->fieldDefs[$name]['id_name']]['value'] = $this->returnId ;
523 if (isset($this->focus->additional_meta_fields))
525 $this->fieldDefs = array_merge($this->fieldDefs, $this->focus->additional_meta_fields);
528 if ($this->isDuplicate)
530 foreach ($this->fieldDefs as $name=>$defs) {
531 if (!empty($defs['auto_increment']))
533 $this->fieldDefs[$name]['value'] = '';
540 * This method makes the Smarty variable assignments and theautocomplete_ajax'vars the
542 * @param $showTitle boolean value indicating whether or not to show a title on the resulting page
543 * @param $ajaxSave boolean value indicating whether or not the operation is an Ajax save request
544 * @return HTML display for view as String
546 function display($showTitle = true, $ajaxSave = false)
548 global $mod_strings, $sugar_config, $app_strings, $app_list_strings, $theme, $current_user;
550 if(isset($this->defs['templateMeta']['javascript']))
552 if(is_array($this->defs['templateMeta']['javascript']))
554 //$this->th->ss->assign('externalJSFile', 'modules/' . $this->module . '/metadata/editvewdefs.js');
555 $this->th->ss->assign('externalJSFile', $this->defs['templateMeta']['javascript']);
559 $this->th->ss->assign('scriptBlocks', $this->defs['templateMeta']['javascript']);
563 $this->th->ss->assign('id', $this->fieldDefs['id']['value']);
564 $this->th->ss->assign('offset', $this->offset + 1);
565 $this->th->ss->assign('APP', $app_strings);
566 $this->th->ss->assign('MOD', $mod_strings);
567 $this->th->ss->assign('fields', $this->fieldDefs);
568 $this->th->ss->assign('sectionPanels', $this->sectionPanels);
569 $this->th->ss->assign('config', $sugar_config);
570 $this->th->ss->assign('returnModule', $this->returnModule);
571 $this->th->ss->assign('returnAction', $this->returnAction);
572 $this->th->ss->assign('returnId', $this->returnId);
573 $this->th->ss->assign('isDuplicate', $this->isDuplicate);
574 $this->th->ss->assign('def', $this->defs);
575 $this->th->ss->assign('useTabs', isset($this->defs['templateMeta']['useTabs']) ? $this->defs['templateMeta']['useTabs'] : false);
576 $this->th->ss->assign('maxColumns', isset($this->defs['templateMeta']['maxColumns']) ? $this->defs['templateMeta']['maxColumns'] : 2);
577 $this->th->ss->assign('module', $this->module);
578 $this->th->ss->assign('headerTpl', isset($this->defs['templateMeta']['form']['headerTpl']) ? $this->defs['templateMeta']['form']['headerTpl'] : 'include/' . $this->view . '/header.tpl');
579 $this->th->ss->assign('footerTpl', isset($this->defs['templateMeta']['form']['footerTpl']) ? $this->defs['templateMeta']['form']['footerTpl'] : 'include/' . $this->view . '/footer.tpl');
580 $this->th->ss->assign('current_user', $current_user);
581 $this->th->ss->assign('bean', $this->focus);
582 $this->th->ss->assign('isAuditEnabled', $this->focus->is_AuditEnabled());
583 $this->th->ss->assign('gridline',$current_user->getPreference('gridline') == 'on' ? '1' : '0');
585 global $js_custom_version;
586 global $sugar_version;
588 $this->th->ss->assign('SUGAR_VERSION', $sugar_version);
589 $this->th->ss->assign('JS_CUSTOM_VERSION', $js_custom_version);
591 //this is used for multiple forms on one page
592 if (!empty($this->formName)) {
593 $form_id = $this->formName;
594 $form_name = $this->formName;
598 $form_id = $this->view;
599 $form_name = $this->view;
602 if ($ajaxSave && empty($this->formName))
604 $form_id = 'form_'.$this->view .'_'.$this->module;
605 $form_name = $form_id;
606 $this->view = $form_name;
607 //$this->defs['templateMeta']['form']['buttons'] = array();
608 //$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}...\');"/>');
611 $form_name = $form_name == 'QuickCreate' ? "QuickCreate_{$this->module}" : $form_name;
612 $form_id = $form_id == 'QuickCreate' ? "QuickCreate_{$this->module}" : $form_id;
614 if (isset($this->defs['templateMeta']['preForm']))
616 $this->th->ss->assign('preForm', $this->defs['templateMeta']['preForm']);
619 if (isset($this->defs['templateMeta']['form']['closeFormBeforeCustomButtons']))
621 $this->th->ss->assign('closeFormBeforeCustomButtons', $this->defs['templateMeta']['form']['closeFormBeforeCustomButtons']);
624 if(isset($this->defs['templateMeta']['form']['enctype']))
626 $this->th->ss->assign('enctype', 'enctype="'.$this->defs['templateMeta']['form']['enctype'].'"');
629 //for SugarFieldImage, we must set form enctype to "multipart/form-data"
630 foreach ($this->fieldDefs as $field)
632 if (isset($field['type']) && $field['type'] == 'image')
634 $this->th->ss->assign('enctype', 'enctype="multipart/form-data"');
639 $this->th->ss->assign('showDetailData', $this->showDetailData);
640 $this->th->ss->assign('showSectionPanelsTitles', $this->showSectionPanelsTitles);
641 $this->th->ss->assign('form_id', $form_id);
642 $this->th->ss->assign('form_name', $form_name);
643 $this->th->ss->assign('set_focus_block', get_set_focus_js());
645 $this->th->ss->assign('form', isset($this->defs['templateMeta']['form']) ? $this->defs['templateMeta']['form'] : null);
646 $this->th->ss->assign('includes', isset($this->defs['templateMeta']['includes']) ? $this->defs['templateMeta']['includes'] : null);
647 $this->th->ss->assign('view', $this->view);
650 //Calculate time & date formatting (may need to calculate this depending on a setting)
653 $this->th->ss->assign('CALENDAR_DATEFORMAT', $timedate->get_cal_date_format());
654 $this->th->ss->assign('USER_DATEFORMAT', $timedate->get_user_date_format());
655 $time_format = $timedate->get_user_time_format();
656 $this->th->ss->assign('TIME_FORMAT', $time_format);
658 $date_format = $timedate->get_cal_date_format();
659 $time_separator = ':';
660 if (preg_match('/\d+([^\d])\d+([^\d]*)/s', $time_format, $match))
662 $time_separator = $match[1];
665 // Create Smarty variables for the Calendar picker widget
666 $t23 = strpos($time_format, '23') !== false ? '%H' : '%I';
667 if (!isset($match[2]) || $match[2] == '')
669 $this->th->ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . '%M');
673 $pm = $match[2] == 'pm' ? '%P' : '%p';
674 $this->th->ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . '%M' . $pm);
677 $this->th->ss->assign('TIME_SEPARATOR', $time_separator);
679 $seps = get_number_seperators();
680 $this->th->ss->assign('NUM_GRP_SEP', $seps[0]);
681 $this->th->ss->assign('DEC_SEP', $seps[1]);
683 if ($this->view == 'EditView')
685 $height = $current_user->getPreference('text_editor_height');
686 $width = $current_user->getPreference('text_editor_width');
688 $height = isset($height) ? $height : '300px';
689 $width = isset($width) ? $width : '95%';
691 $this->th->ss->assign('RICH_TEXT_EDITOR_HEIGHT', $height);
692 $this->th->ss->assign('RICH_TEXT_EDITOR_WIDTH', $width);
696 $this->th->ss->assign('RICH_TEXT_EDITOR_HEIGHT', '100px');
697 $this->th->ss->assign('RICH_TEXT_EDITOR_WIDTH', '95%');
700 $this->th->ss->assign('SHOW_VCR_CONTROL', $this->showVCRControl);
702 $str = $this->showTitle($showTitle);
704 //Use the output filter to trim the whitespace
705 $this->th->ss->load_filter('output', 'trimwhitespace');
706 $str .= $this->th->displayTemplate($this->module, $form_name, $this->tpl, $ajaxSave, $this->defs);
711 function insertJavascript($javascript)
713 $this->ss->assign('javascript', $javascript);
716 function callFunction($vardef)
719 $execute_function = array();
720 $execute_params = array();
721 if (!empty($vardef['function_class']))
723 $execute_function[] = $vardef['function_class'];
724 $execute_function[] = $vardef['function_name'];
728 $execute_function = $vardef['function_name'];
731 foreach ($vardef['function_params'] as $param )
733 if (empty($vardef['function_params_source']) or $vardef['function_params_source']=='parent')
735 if (empty($this->focus->$param))
737 $can_execute = false;
741 $execute_params[] = $this->focus->$param;
744 else if ($vardef['function_params_source']=='this')
746 if (empty($this->focus->$param))
748 $can_execute = false;
750 $execute_params[] = $this->focus->$param;
755 $can_execute = false;
762 if (!empty($vardef['function_require']))
764 require_once($vardef['function_require']);
767 $value = call_user_func_array($execute_function, $execute_params);
774 * getValueFromRequest
775 * This is a helper method to extract a value from the request
776 * Array. We do some special processing for fields that start
777 * with 'date_' by checking to see if they also include time
778 * and meridiem values
780 * @param request The request Array
781 * @param name The field name to extract value for
782 * @return String value for given name
784 function getValueFromRequest($request, $name)
786 //Special processing for date values (combine to one field)
787 if (preg_match('/^date_(.*)$/s', $name, $matches))
789 $d = $request[$name];
791 if (isset($request['time_' . $matches[1]]))
793 $d .= ' ' . $request['time_' . $matches[1]];
794 if (isset($request[$matches[1] . '_meridiem']))
796 $d .= $request[$matches[1] . '_meridiem'];
801 if (isset($request['time_hour_' . $matches[1]])
802 && isset($request['time_minute_' . $matches[1]]))
804 $d .= sprintf(' %s:%s', $request['time_hour_' . $matches[1]], $request['time_minute_' . $matches[1]]);
807 if (isset($request['meridiem']))
809 $d .= $request['meridiem'];
816 if (empty($request[$name]) || !isset($this->fieldDefs[$name]))
818 return $request[$name];
821 //if it's a bean field - unformat it
822 require_once('include/SugarFields/SugarFieldHandler.php');
824 $sfh = new SugarFieldHandler();
825 $type = !empty($this->fieldDefs[$name]['custom_type'])
826 ? $this->fieldDefs[$name]['custom_type']
827 : $this->fieldDefs[$name]['type'];
828 $sf = $sfh->getSugarField($type);
830 return $sf ? $sf->unformatField($request[$name], $this->fieldDefs[$name]) : $request[$name];
835 * Allow Subviews to overwrite this method to show custom titles.
836 * Examples: Projects & Project Templates.
837 * params: $showTitle: boolean for backwards compatibility.
839 public function showTitle($showTitle = false)
841 global $mod_strings, $app_strings;
843 if (is_null($this->viewObject))
845 $this->viewObject = (!empty($GLOBALS['current_view']))
846 ? $GLOBALS['current_view']
852 return $this->viewObject->getModuleTitle();