]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/Popups/PopupSmarty.php
Release 6.5.11
[Github/sugarcrm.git] / include / Popups / PopupSmarty.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38 require_once('include/ListView/ListViewSmarty.php');
39
40 require_once('include/TemplateHandler/TemplateHandler.php');
41 require_once('include/SearchForm/SearchForm2.php');
42 define("NUM_COLS", 2);
43 class PopupSmarty extends ListViewSmarty{
44
45         var $contextMenus = false;
46         var $export = false;
47         var $mailmerge = false;
48         var $mergeduplicates = false;
49         var $quickViewLinks = false;
50         var $multiSelect = false;
51         var $headerTpl;
52     var $footerTpl;
53     var $th;
54     var $tpl;
55     var $view;
56     var $field_defs;
57     var $formData;
58     var $_popupMeta;
59     var $_create = false;
60     var $searchdefs = array();
61     var $listviewdefs = array();
62     var $searchFields = array();
63     var $customFieldDefs;
64     var $filter_fields = array();
65     //rrs
66     var $searchForm;
67     var $module;
68     var $massUpdateData = '';
69
70         function PopupSmarty($seed, $module){
71                 parent::ListViewSmarty();
72                 $this->th = new TemplateHandler();
73                 $this->th->loadSmarty();
74                 $this->seed = $seed;
75                 $this->view = 'Popup';
76                 $this->module = $module;
77                 $this->searchForm = new SearchForm($this->seed, $this->module);
78                 $this->th->deleteTemplate($module, $this->view);
79         $this->headerTpl = 'include/Popups/tpls/header.tpl';
80         $this->footerTpl = 'include/Popups/tpls/footer.tpl';
81
82         }
83
84     /**
85      * Assign several arrow image attributes to TemplateHandler smarty. Such as width, height, etc.
86      * 
87      * @return void
88      */
89     function processArrowVars()
90     {
91         $pathParts = pathinfo(SugarThemeRegistry::current()->getImageURL('arrow.gif',false));
92
93         list($width,$height) = getimagesize($pathParts['dirname'].'/'.$pathParts['basename']);
94
95         $this->th->ss->assign('arrowExt', $pathParts['extension']);
96         $this->th->ss->assign('arrowWidth', $width);
97         $this->th->ss->assign('arrowHeight', $height);
98         $this->th->ss->assign('arrowAlt', translate('LBL_SORT'));
99     }
100
101         /**
102      * Processes the request. Calls ListViewData process. Also assigns all lang strings, export links,
103      * This is called from ListViewDisplay
104      *
105      * @param file file Template file to use
106      * @param data array from ListViewData
107      * @param html_var string the corresponding html var in xtpl per row
108      *
109      */
110         function process($file, $data, $htmlVar) {
111
112                 global $odd_bg, $even_bg, $hilite_bg, $click_bg, $app_strings;
113                 parent::process($file, $data, $htmlVar);
114
115                 $this->tpl = $file;
116                 $this->data = $data;
117
118         $totalWidth = 0;
119         foreach($this->displayColumns as $name => $params) {
120             $totalWidth += $params['width'];
121         }
122         $adjustment = $totalWidth / 100;
123
124         $contextMenuObjectsTypes = array();
125         foreach($this->displayColumns as $name => $params) {
126             $this->displayColumns[$name]['width'] = round($this->displayColumns[$name]['width'] / $adjustment, 2);
127             // figure out which contextMenu objectsTypes are required
128             if(!empty($params['contextMenu']['objectType']))
129                 $contextMenuObjectsTypes[$params['contextMenu']['objectType']] = true;
130         }
131                 $this->th->ss->assign('displayColumns', $this->displayColumns);
132
133
134                 $this->th->ss->assign('bgHilite', $hilite_bg);
135                 $this->th->ss->assign('colCount', count($this->displayColumns) + 1);
136                 $this->th->ss->assign('htmlVar', strtoupper($htmlVar));
137                 $this->th->ss->assign('moduleString', $this->moduleString);
138         $this->th->ss->assign('editLinkString', $GLOBALS['app_strings']['LBL_EDIT_BUTTON']);
139         $this->th->ss->assign('viewLinkString', $GLOBALS['app_strings']['LBL_VIEW_BUTTON']);
140
141         //rrs
142         $this->searchForm->parsedView = 'popup_query_form';
143         $this->searchForm->displayType = 'popupView';
144                 $this->th->ss->assign('searchForm', $this->searchForm->display(false));
145         //rrs
146
147                 if($this->export) $this->th->ss->assign('exportLink', $this->buildExportLink());
148                 $this->th->ss->assign('quickViewLinks', $this->quickViewLinks);
149                 if($this->mailMerge) $this->th->ss->assign('mergeLink', $this->buildMergeLink()); // still check for mailmerge access
150                 if($this->mergeduplicates) $this->th->ss->assign('mergedupLink', $this->buildMergeDuplicatesLink());
151
152
153                 if (!empty($_REQUEST['mode']) && strtoupper($_REQUEST['mode']) == 'MULTISELECT') {
154                         $this->multiSelect = true;
155                 }
156                 // handle save checks and stuff
157                 if($this->multiSelect) {
158                         $this->th->ss->assign('selectedObjectsSpan', $this->buildSelectedObjectsSpan());
159                         $this->th->ss->assign('multiSelectData', $this->getMultiSelectData());
160                         $this->th->ss->assign('MODE', "<input type='hidden' name='mode' value='MultiSelect'>");
161             $pageTotal = $this->data['pageData']['offsets']['next'] - $this->data['pageData']['offsets']['current'];
162             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
163                 $pageTotal = $this->data['pageData']['offsets']['total'] - $this->data['pageData']['offsets']['current'];
164             }
165                 $this->th->ss->assign('selectLink', $this->buildSelectLink('select_link', $this->data['pageData']['offsets']['total'], $pageTotal));
166                 }
167
168                 $this->processArrows($data['pageData']['ordering']);
169                 $this->th->ss->assign('prerow', $this->multiSelect);
170                 $this->th->ss->assign('rowColor', array('oddListRow', 'evenListRow'));
171                 $this->th->ss->assign('bgColor', array($odd_bg, $even_bg));
172         $this->th->ss->assign('contextMenus', $this->contextMenus);
173
174
175         if($this->contextMenus && !empty($contextMenuObjectsTypes)) {
176             $script = '';
177             $cm = new contextMenu();
178             foreach($contextMenuObjectsTypes as $type => $value) {
179                 $cm->loadFromFile($type);
180                 $script .= $cm->getScript();
181                 $cm->menuItems = array(); // clear menuItems out
182             }
183             $this->th->ss->assign('contextMenuScript', $script);
184         }
185
186         //rrs
187         $this->_build_field_defs();
188
189             // arrow image attributes
190             $this->processArrowVars();
191         }
192
193         /*
194          * Display the Smarty template.  Here we are using the TemplateHandler for caching per the module.
195          */
196         function display($end = true) {
197         global $app_strings;
198
199         if(!is_file(sugar_cached("jsLanguage/{$GLOBALS['current_language']}.js"))) {
200             require_once('include/language/jsLanguage.php');
201             jsLanguage::createAppStringsCache($GLOBALS['current_language']);
202         }
203         $jsLang = getVersionedScript("cache/jsLanguage/{$GLOBALS['current_language']}.js",  $GLOBALS['sugar_config']['js_lang_version']);
204
205         $this->th->ss->assign('data', $this->data['data']);
206                 $this->data['pageData']['offsets']['lastOffsetOnPage'] = $this->data['pageData']['offsets']['current'] + count($this->data['data']);
207                 $this->th->ss->assign('pageData', $this->data['pageData']);
208
209         $navStrings = array('next' => $GLOBALS['app_strings']['LNK_LIST_NEXT'],
210                             'previous' => $GLOBALS['app_strings']['LNK_LIST_PREVIOUS'],
211                             'end' => $GLOBALS['app_strings']['LNK_LIST_END'],
212                             'start' => $GLOBALS['app_strings']['LNK_LIST_START'],
213                             'of' => $GLOBALS['app_strings']['LBL_LIST_OF']);
214         $this->th->ss->assign('navStrings', $navStrings);
215
216
217                 $associated_row_data = array();
218                 
219                 //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
220                 $searchNameOverride = !empty($this->seed) && $this->seed instanceof Person && (isset($this->data['data'][0]['FIRST_NAME']) && isset($this->data['data'][0]['LAST_NAME'])) ? true : false;
221                 
222                 global $locale;
223                 foreach($this->data['data'] as $val)
224                 {
225                         $associated_row_data[$val['ID']] = $val;
226                         if($searchNameOverride)
227                         {
228                            $associated_row_data[$val['ID']]['NAME'] = $locale->getLocaleFormattedName($val['FIRST_NAME'], $val['LAST_NAME']);
229                         }
230                 }
231                 $is_show_fullname = showFullName() ? 1 : 0;
232                 $json = getJSONobj();
233                 $this->th->ss->assign('jsLang', $jsLang);
234                 $this->th->ss->assign('lang', substr($GLOBALS['current_language'], 0, 2));
235         $this->th->ss->assign('headerTpl', $this->headerTpl);
236         $this->th->ss->assign('footerTpl', $this->footerTpl);
237         $this->th->ss->assign('ASSOCIATED_JAVASCRIPT_DATA', 'var associated_javascript_data = '.$json->encode($associated_row_data). '; var is_show_fullname = '.$is_show_fullname.';');
238                 $this->th->ss->assign('module', $this->seed->module_dir);
239                 $request_data = empty($_REQUEST['request_data']) ? '' : $_REQUEST['request_data'];
240                 $this->th->ss->assign('request_data', $request_data);
241                 $this->th->ss->assign('fields', $this->fieldDefs);
242                 $this->th->ss->assign('formData', $this->formData);
243                 $this->th->ss->assign('APP', $GLOBALS['app_strings']);
244                 $this->th->ss->assign('MOD', $GLOBALS['mod_strings']);
245         if (isset($this->_popupMeta['create']['createButton'])) 
246                 {
247            $this->_popupMeta['create']['createButton'] = translate($this->_popupMeta['create']['createButton']);
248         }
249                 $this->th->ss->assign('popupMeta', $this->_popupMeta);
250         $this->th->ss->assign('current_query', base64_encode(serialize($_REQUEST)));
251                 $this->th->ss->assign('customFields', $this->customFieldDefs);
252                 $this->th->ss->assign('numCols', NUM_COLS);
253                 $this->th->ss->assign('massUpdateData', $this->massUpdateData);
254                 $this->th->ss->assign('sugarVersion', $GLOBALS['sugar_version']);
255         $this->th->ss->assign('should_process', $this->should_process);
256
257                 if($this->_create){
258                         $this->th->ss->assign('ADDFORM', $this->getQuickCreate());//$this->_getAddForm());
259                         $this->th->ss->assign('ADDFORMHEADER', $this->_getAddFormHeader());
260                         $this->th->ss->assign('object_name', $this->seed->object_name);
261                 }
262                 $this->th->ss->assign('LIST_HEADER', get_form_header($GLOBALS['mod_strings']['LBL_LIST_FORM_TITLE'], '', false));
263                 $this->th->ss->assign('SEARCH_FORM_HEADER', get_form_header($GLOBALS['mod_strings']['LBL_SEARCH_FORM_TITLE'], '', false));
264                 $str = $this->th->displayTemplate($this->seed->module_dir, $this->view, $this->tpl);
265                 return $str;
266         }
267
268         /*
269          * Setup up the smarty template. we added an extra step here to add the order by from the popupdefs.
270          */
271         function setup($file) {
272
273             if(isset($this->_popupMeta)){
274                         if(isset($this->_popupMeta['create']['formBase'])) {
275                                 require_once('modules/' . $this->seed->module_dir . '/' . $this->_popupMeta['create']['formBase']);
276                                 $this->_create = true;
277                         }
278                 }
279             if(!empty($this->_popupMeta['create'])){
280                         $formBase = new $this->_popupMeta['create']['formBaseClass']();
281                         if(isset($_REQUEST['doAction']) && $_REQUEST['doAction'] == 'save')
282                         {
283                                 //If it's a new record, set useRequired to false
284                                 $useRequired = empty($_REQUEST['id']) ? false : true;
285                                 $formBase->handleSave('', false, $useRequired);
286                         }
287                 }
288
289                 $params = array();
290                 if(!empty($this->_popupMeta['orderBy'])){
291                         $params['orderBy'] = $this->_popupMeta['orderBy'];
292                         $params['overrideOrder'] = true;
293                 }
294
295                 if(file_exists('custom/modules/'.$this->module.'/metadata/metafiles.php')){
296                         require('custom/modules/'.$this->module.'/metadata/metafiles.php');
297                 }elseif(file_exists('modules/'.$this->module.'/metadata/metafiles.php')){
298                         require('modules/'.$this->module.'/metadata/metafiles.php');
299                 }
300
301                 if(!empty($metafiles[$this->module]['searchfields'])) {
302                         require($metafiles[$this->module]['searchfields']);
303                 } elseif(file_exists('modules/'.$this->module.'/metadata/SearchFields.php')) {
304                         require('modules/'.$this->module.'/metadata/SearchFields.php');
305             }
306         $this->searchdefs[$this->module]['templateMeta']['maxColumns'] = 2;
307         $this->searchdefs[$this->module]['templateMeta']['widths']['label'] = 10;
308         $this->searchdefs[$this->module]['templateMeta']['widths']['field'] = 30;
309
310         $this->searchForm->view = 'PopupSearchForm';
311                 $this->searchForm->setup($this->searchdefs, $searchFields, 'SearchFormGenericAdvanced.tpl', 'advanced_search', $this->listviewdefs);
312
313                 $lv = new ListViewSmarty();
314                 $displayColumns = array();
315                 if(!empty($_REQUEST['displayColumns'])) {
316                     foreach(explode('|', $_REQUEST['displayColumns']) as $num => $col) {
317                         if(!empty($listViewDefs[$this->module][$col]))
318                             $displayColumns[$col] = $this->listviewdefs[$this->module][$col];
319                     }
320                 }
321                 else {
322                     foreach($this->listviewdefs[$this->module] as $col => $para) {
323                         if(!empty($para['default']) && $para['default'])
324                             $displayColumns[$col] = $para;
325                     }
326                 }
327                 $params['massupdate'] = true;
328                 if(!empty($_REQUEST['orderBy'])) {
329                     $params['orderBy'] = $_REQUEST['orderBy'];
330                     $params['overrideOrder'] = true;
331                     if(!empty($_REQUEST['sortOrder'])) $params['sortOrder'] = $_REQUEST['sortOrder'];
332                 }
333
334                 $lv->displayColumns = $displayColumns;
335         $this->searchForm->lv = $lv;
336         $this->searchForm->displaySavedSearch = false;
337
338
339         $this->searchForm->populateFromRequest('advanced_search');
340         $searchWhere = $this->_get_where_clause();
341         $this->searchColumns = $this->searchForm->searchColumns;
342         //parent::setup($this->seed, $file, $searchWhere, $params, 0, -1, $this->filter_fields);
343
344         $this->should_process = true;
345
346         if(isset($params['export'])) {
347           $this->export = $params['export'];
348         }
349         if(!empty($params['multiSelectPopup'])) {
350                   $this->multi_select_popup = $params['multiSelectPopup'];
351         }
352                 if(!empty($params['massupdate']) && $params['massupdate'] != false) {
353                         $this->show_mass_update_form = true;
354                         $this->mass = new MassUpdate();
355                         $this->mass->setSugarBean($this->seed);
356                         if(!empty($params['handleMassupdate']) || !isset($params['handleMassupdate'])) {
357                 $this->mass->handleMassUpdate();
358             }
359                 }
360
361         // create filter fields based off of display columns
362         if(empty($this->filter_fields) || $this->mergeDisplayColumns) {
363             foreach($this->displayColumns as $columnName => $def) {
364                $this->filter_fields[strtolower($columnName)] = true;
365                if(!empty($def['related_fields'])) {
366                     foreach($def['related_fields'] as $field) {
367                         //id column is added by query construction function. This addition creates duplicates
368                         //and causes issues in oracle. #10165
369                         if ($field != 'id') {
370                             $this->filter_fields[$field] = true;
371                         }
372                     }
373                 }
374                 if (!empty($this->seed->field_defs[strtolower($columnName)]['db_concat_fields'])) {
375                         foreach($this->seed->field_defs[strtolower($columnName)]['db_concat_fields'] as $index=>$field){
376                             if(!isset($this->filter_fields[strtolower($field)]) || !$this->filter_fields[strtolower($field)])
377                             {
378                                 $this->filter_fields[strtolower($field)] = true;
379                             }
380                         }
381                 }
382             }
383             foreach ($this->searchColumns as $columnName => $def )
384             {
385                 $this->filter_fields[strtolower($columnName)] = true;
386             }
387         }
388
389         /**
390          * Bug #46842 : The relate field field_to_name_array fails to copy over custom fields 
391          * By default bean's create_new_list_query function loads fields displayed on the page or used in the search
392          * add fields used to populate forms from _viewdefs :: field_to_name_array to retrive from db
393          */
394         if ( isset($_REQUEST['field_to_name']) && $_REQUEST['field_to_name'] )
395         {
396             $_REQUEST['field_to_name'] = is_array($_REQUEST['field_to_name']) ? $_REQUEST['field_to_name'] : array($_REQUEST['field_to_name']);
397             foreach ( $_REQUEST['field_to_name'] as $add_field )
398             {
399                 $add_field = strtolower($add_field);
400                 if ( $add_field != 'id' && !isset($this->filter_fields[$add_field]) && isset($this->seed->field_defs[$add_field]) )
401                 {
402                     $this->filter_fields[$add_field] = true;
403                 }
404             }
405             
406         }
407         else if (!empty($_REQUEST['request_data']))
408         {
409             $request_data = get_object_vars(json_decode(htmlspecialchars_decode($_REQUEST['request_data'])));
410
411             if (!empty($request_data['field_to_name_array']))
412             {
413                 $request_data['field_to_name'] = get_object_vars($request_data['field_to_name_array']);
414                 if (is_array($request_data['field_to_name']))
415                 {
416                     foreach ($request_data['field_to_name'] as $add_field)
417                     {
418                         $add_field = strtolower($add_field);
419                         if ($add_field != 'id' && !isset($this->filter_fields[$add_field]) && isset($this->seed->field_defs[$add_field]))
420                         {
421                             $this->filter_fields[$add_field] = true;
422                         }
423                     }
424                 }
425             }
426         }
427
428
429                 if (!empty($_REQUEST['query']) || (!empty($GLOBALS['sugar_config']['save_query']) && $GLOBALS['sugar_config']['save_query'] != 'populate_only')) {
430                         $data = $this->lvd->getListViewData($this->seed, $searchWhere, 0, -1, $this->filter_fields, $params, 'id');
431                 } else {
432                         $this->should_process = false;
433                         $data = array(
434                                 'data'=>array(),
435                             'pageData'=>array(
436                                 'bean'=>array('moduleDir'=>$this->seed->module_dir),
437                                         'ordering'=>'',
438                                         'offsets'=>array('total'=>0,'next'=>0,'current'=>0),
439                                 ),
440                         );
441                 }
442
443                 foreach($this->displayColumns as $columnName => $def)
444                 {
445                         $seedName =  strtolower($columnName);
446
447                         if(empty($this->displayColumns[$columnName]['type'])){
448                                 if(!empty($this->lvd->seed->field_defs[$seedName]['type'])){
449                                         $seedDef = $this->lvd->seed->field_defs[$seedName];
450                             $this->displayColumns[$columnName]['type'] = (!empty($seedDef['custom_type']))?$seedDef['custom_type']:$seedDef['type'];
451                         }else{
452                                 $this->displayColumns[$columnName]['type'] = '';
453                         }
454                         }//fi empty(...)
455
456                         if(!empty($this->lvd->seed->field_defs[$seedName]['options'])){
457                                         $this->displayColumns[$columnName]['options'] = $this->lvd->seed->field_defs[$seedName]['options'];
458                         }
459
460                 //C.L. Fix for 11177
461                 if($this->displayColumns[$columnName]['type'] == 'html') {
462                     $cField = $this->seed->custom_fields;
463                        if(isset($cField) && isset($cField->bean->$seedName)) {
464                                 $seedName2 = strtoupper($columnName);
465                                 $htmlDisplay = html_entity_decode($cField->bean->$seedName);
466                                 $count = 0;
467                                 while($count < count($data['data'])) {
468                                         $data['data'][$count][$seedName2] = &$htmlDisplay;
469                                     $count++;
470                                 }
471                         }
472                 }//fi == 'html'
473
474                         if (!empty($this->lvd->seed->field_defs[$seedName]['sort_on'])) {
475                         $this->displayColumns[$columnName]['orderBy'] = $this->lvd->seed->field_defs[$seedName]['sort_on'];
476                     }
477                 }
478
479                 $this->process($file, $data, $this->seed->object_name);
480         }
481
482         /*
483          * Return the where clause as per the REQUEST.
484          */
485         function _get_where_clause()
486         {
487                 $where = '';
488                 $where_clauses = $this->searchForm->generateSearchWhere(true, $this->seed->module_dir);
489
490                 // Bug 43452 - FG - Changed the way generated Where array is imploded into the string.
491                 //                  Now it's imploding in the same way view.list.php do.
492                 if (count($where_clauses) > 0 ) {
493                     $where = '( ' . implode(' and ', $where_clauses) . ' )';
494         }
495
496         // Need to include the default whereStatement
497                 if(!empty($this->_popupMeta['whereStatement'])){
498             if(!empty($where))$where .= ' AND ';
499             $where .= $this->_popupMeta['whereStatement'];
500                 }
501
502                 return $where;
503         }
504
505         /*
506          * Generate the data for the search form on the header of the Popup.
507          */
508                 function _build_field_defs(){
509                 $this->formData = array();
510                 $this->customFieldDefs = array();
511                 foreach($this->searchdefs[$this->module]['layout']['advanced_search'] as $data){
512                         if(is_array($data)){
513
514                                 $this->formData[] = array('field' => $data);
515                                 $value = '';
516                                 $this->customFieldDefs[$data['name']]= $data;
517                                 if(!empty($_REQUEST[$data['name']]))
518                         $value = $_REQUEST[$data['name']];
519                     $this->customFieldDefs[$data['name']]['value'] = $value;
520                         }else
521                                 $this->formData[] = array('field' => array('name'=>$data));
522                 }
523                 $this->fieldDefs = array();
524                 if($this->seed){
525                         $this->seed->fill_in_additional_detail_fields();
526
527                 foreach($this->seed->toArray() as $name => $value) {
528                     $this->fieldDefs[$name] = $this->seed->field_defs[$name];
529                     //if we have a relate type then reset to name so that we end up with a textbox
530                     //rather than a select button
531                     $this->fieldDefs[$name]['name'] = $this->fieldDefs[$name]['name'];
532                     if($this->fieldDefs[$name]['type'] == 'relate')
533                         $this->fieldDefs[$name]['type'] = 'name';
534                     if(isset($this->fieldDefs[$name]['options']) && isset($GLOBALS['app_list_strings'][$this->fieldDefs[$name]['options']])) {
535                         $this->fieldDefs[$name]['options'] = $GLOBALS['app_list_strings'][$this->fieldDefs[$name]['options']]; // fill in enums
536                     }
537                     if(!empty($_REQUEST[$name]))
538                         $value = $_REQUEST[$name];
539                     $this->fieldDefs[$name]['value'] = $value;
540                 }
541                 }
542         }
543
544         function _getAddForm(){
545                 $addform = '';
546         if(!$this->seed->ACLAccess('save')){
547             return;
548         }
549                 if(!empty($this->_popupMeta['create'])){
550                         $formBase = new $this->_popupMeta['create']['formBaseClass']();
551
552
553
554                                 // TODO: cleanup the construction of $addform
555                                 $prefix = empty($this->_popupMeta['create']['getFormBodyParams'][0]) ? '' : $this->_popupMeta['create']['getFormBodyParams'][0];
556                                 $mod = empty($this->_popupMeta['create']['getFormBodyParams'][1]) ? '' : $this->_popupMeta['create']['getFormBodyParams'][1];
557                                 $formBody = empty($this->_popupMeta['create']['getFormBodyParams'][2]) ? '' : $this->_popupMeta['create']['getFormBodyParams'][2];
558
559                                 $getFormMethod = (empty($this->_popupMeta['create']['getFormMethod']) ? 'getFormBody' : $this->_popupMeta['create']['getFormMethod']);
560                                 $formbody = $formBase->$getFormMethod($prefix, $mod, $formBody);
561
562                                 $addform = '<table><tr><td nowrap="nowrap" valign="top">'
563                                         . str_replace('<br>', '</td><td nowrap="nowrap" valign="top">&nbsp;', $formbody)
564                                         . '</td></tr></table>'
565                                         . '<input type="hidden" name="action" value="Popup" />';
566
567                         return $addform;
568                 }
569         }
570
571         function _getAddFormHeader(){
572                 $lbl_save_button_title = $GLOBALS['app_strings']['LBL_SAVE_BUTTON_TITLE'];
573                 $lbl_save_button_key = $GLOBALS['app_strings']['LBL_SAVE_BUTTON_KEY'];
574                 $lbl_save_button_label = $GLOBALS['app_strings']['LBL_SAVE_BUTTON_LABEL'];
575                 $module_dir = $this->seed->module_dir;
576 $formSave = <<<EOQ
577                         <input type="hidden" name="create" value="true">
578                         <input type="hidden" name="popup" value="true">
579                         <input type="hidden" name="to_pdf" value="true">
580                         <input type="hidden" name="return_module" value="$module_dir">
581                         <input type="hidden" name="return_action" value="Popup">
582 EOQ;
583                 // if metadata contains custom inputs for the quickcreate
584                 if(!empty($this->_popupMeta['customInput']) && is_array($this->_popupMeta['customInput'])) {
585                         foreach($this->_popupMeta['customInput'] as $key => $value)
586                                 $formSave .= '<input type="hidden" name="' . $key . '" value="'. $value .'">\n';
587                 }
588
589
590                 $addformheader = get_form_header(translate($this->_popupMeta['create']['createButton']), $formSave, false);
591                 return $addformheader;
592         }
593
594         function getQuickCreate(){
595                 require_once("include/EditView/PopupQuickCreate.php");
596                 $qc = new PopupQuickCreate($this->module);
597                 return $qc->process($this->module);
598         }
599 }
600 ?>