]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Import/Forms.php
Release 6.4.0
[Github/sugarcrm.git] / modules / Import / Forms.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3
4 /*********************************************************************************
5  * SugarCRM Community Edition is a customer relationship management program developed by
6  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7  * 
8  * This program is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU Affero General Public License version 3 as published by the
10  * Free Software Foundation with the addition of the following permission added
11  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
12  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
13  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14  * 
15  * This program is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
18  * details.
19  * 
20  * You should have received a copy of the GNU Affero General Public License along with
21  * this program; if not, see http://www.gnu.org/licenses or write to the Free
22  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23  * 02110-1301 USA.
24  * 
25  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
26  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27  * 
28  * The interactive user interfaces in modified source and object code versions
29  * of this program must display Appropriate Legal Notices, as required under
30  * Section 5 of the GNU Affero General Public License version 3.
31  * 
32  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
33  * these Appropriate Legal Notices must retain the display of the "Powered by
34  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
35  * technical reasons, the Appropriate Legal Notices must display the words
36  * "Powered by SugarCRM".
37  ********************************************************************************/
38
39 /*********************************************************************************
40
41  * Description:  Contains a variety of utility functions for the Import module
42  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
43  * All Rights Reserved.
44  ********************************************************************************/
45
46 /**
47  * Returns an input control for this fieldname given
48  *
49  * @param  string $module
50  * @param  string $fieldname
51  * @param  string $vardef
52  * @param  string $value
53  * @return string html for input element for this control
54  */
55 function getControl(
56     $module,
57     $fieldname,
58     $vardef = null,
59     $value = ''
60     )
61 {
62     global $current_language, $app_strings, $dictionary, $app_list_strings, $current_user;
63     
64     // use the mod_strings for this module
65     $mod_strings = return_module_language($current_language,$module);
66     
67         // set the filename for this control
68     $file = create_cache_directory('modules/Import/') . $module . $fieldname . '.tpl';
69
70     if ( !is_file($file)
71             || !empty($GLOBALS['sugar_config']['developerMode'])
72             || !empty($_SESSION['developerMode']) ) {
73         
74         if ( !isset($vardef) ) {
75             $focus = loadBean($module);
76             $vardef = $focus->getFieldDefinition($fieldname);
77         }
78         
79         // if this is the id relation field, then don't have a pop-up selector.
80         if( $vardef['type'] == 'relate' && $vardef['id_name'] == $vardef['name']) { 
81             $vardef['type'] = 'varchar'; 
82         }
83         
84         // create the dropdowns for the parent type fields
85         if ( $vardef['type'] == 'parent_type' ) {
86             $vardef['type'] = 'enum';
87         }
88         
89         // remove the special text entry field function 'getEmailAddressWidget'
90         if ( isset($vardef['function']) 
91                 && ( $vardef['function'] == 'getEmailAddressWidget' 
92                     || $vardef['function']['name'] == 'getEmailAddressWidget' ) )
93             unset($vardef['function']);
94         
95         // load SugarFieldHandler to render the field tpl file
96         static $sfh;
97         
98         if(!isset($sfh)) {
99             require_once('include/SugarFields/SugarFieldHandler.php');
100             $sfh = new SugarFieldHandler();
101         }
102         
103         $displayParams = array();
104         $displayParams['formName'] = 'importstep3';  
105
106         $contents = $sfh->displaySmarty('fields', $vardef, 'ImportView', $displayParams);
107         
108         // Remove all the copyright comments
109         $contents = preg_replace('/\{\*[^\}]*?\*\}/', '', $contents);
110         
111         // hack to disable one of the js calls in this control
112         if ( isset($vardef['function']) 
113                 && ( $vardef['function'] == 'getCurrencyDropDown' 
114                     || $vardef['function']['name'] == 'getCurrencyDropDown' ) )
115         $contents .= "{literal}<script>function CurrencyConvertAll() { return; }</script>{/literal}";
116
117         // Save it to the cache file
118         if($fh = @sugar_fopen($file, 'w')) {
119             fputs($fh, $contents);
120             fclose($fh);
121         }
122     }
123     
124     // Now render the template we received
125     $ss = new Sugar_Smarty();
126     
127     // Create Smarty variables for the Calendar picker widget
128     global $timedate;
129     $time_format = $timedate->get_user_time_format();
130     $date_format = $timedate->get_cal_date_format();
131     $ss->assign('USER_DATEFORMAT', $timedate->get_user_date_format());
132         $ss->assign('TIME_FORMAT', $time_format);
133     $time_separator = ":";
134     $match = array();
135     if(preg_match('/\d+([^\d])\d+([^\d]*)/s', $time_format, $match)) {
136         $time_separator = $match[1];
137     }
138     $t23 = strpos($time_format, '23') !== false ? '%H' : '%I';
139     if(!isset($match[2]) || $match[2] == '') {
140         $ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M");
141     } 
142     else {
143         $pm = $match[2] == "pm" ? "%P" : "%p";
144         $ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M" . $pm);
145     }
146
147     $ss->assign('CALENDAR_FDOW', $current_user->get_first_day_of_week());
148  
149     // populate the fieldlist from the vardefs
150     $fieldlist = array();
151     if ( !isset($focus) || !($focus instanceof SugarBean) )
152         $focus = loadBean($module);
153     // create the dropdowns for the parent type fields
154     if ( $vardef['type'] == 'parent_type' ) {
155         $focus->field_defs[$vardef['name']]['options'] = $focus->field_defs[$vardef['group']]['options'];
156     }
157     $vardefFields = $focus->getFieldDefinitions();
158     foreach ( $vardefFields as $name => $properties ) {
159         $fieldlist[$name] = $properties;
160         // fill in enums
161         if(isset($fieldlist[$name]['options']) && is_string($fieldlist[$name]['options']) && isset($app_list_strings[$fieldlist[$name]['options']]))
162             $fieldlist[$name]['options'] = $app_list_strings[$fieldlist[$name]['options']];
163         // Bug 32626: fall back on checking the mod_strings if not in the app_list_strings
164         elseif(isset($fieldlist[$name]['options']) && is_string($fieldlist[$name]['options']) && isset($mod_strings[$fieldlist[$name]['options']]))
165             $fieldlist[$name]['options'] = $mod_strings[$fieldlist[$name]['options']];
166         // Bug 22730: make sure all enums have the ability to select blank as the default value.
167         if(!isset($fieldlist[$name]['options']['']))
168             $fieldlist[$name]['options'][''] = '';
169     }
170     // fill in function return values
171     if ( !in_array($fieldname,array('email1','email2')) )
172     {
173         if (!empty($fieldlist[$fieldname]['function']['returns']) && $fieldlist[$fieldname]['function']['returns'] == 'html')
174         {
175
176             $function = $fieldlist[$fieldname]['function']['name'];
177             // include various functions required in the various vardefs
178             if ( isset($fieldlist[$fieldname]['function']['include']) && is_file($fieldlist[$fieldname]['function']['include']))
179                 require_once($fieldlist[$fieldname]['function']['include']);
180             $value = $function($focus, $fieldname, $value, 'EditView');
181             // Bug 22730 - add a hack for the currency type dropdown, since it's built by a function.
182             if ( preg_match('/getCurrency.*DropDown/s',$function)  )
183                 $value = str_ireplace('</select>','<option value="">'.$app_strings['LBL_NONE'].'</option></select>',$value);
184         }
185         elseif($fieldname == 'assigned_user_name' && empty($value))
186         {
187             $fieldlist['assigned_user_id']['value'] = $GLOBALS['current_user']->id;
188             $value = get_assigned_user_name($GLOBALS['current_user']->id);
189         }
190         elseif($fieldname == 'team_name' && empty($value))
191         {
192             $value = json_encode(array());
193         }
194     }
195     $fieldlist[$fieldname]['value'] = $value;
196     $ss->assign("fields",$fieldlist);
197     $ss->assign("form_name",'importstep3');
198     $ss->assign("bean",$focus);
199     
200     // add in any additional strings
201     $ss->assign("MOD", $mod_strings);
202     $ss->assign("APP", $app_strings);
203     return $ss->fetch($file);
204 }