2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
4 /*********************************************************************************
5 * SugarCRM is a customer relationship management program developed by
6 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
39 /*********************************************************************************
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 ********************************************************************************/
47 * Returns the bean object of the given module
49 * @param string $module
52 function loadImportBean(
56 $focus = SugarModule::get($module)->loadBean();
58 if ( !$focus->importable )
60 if ( $module == 'Users' && !is_admin($GLOBALS['current_user'])
61 && !is_admin_for_module($GLOBALS['current_user'],'Users')
64 if ( $focus->bean_implements('ACL')){
65 if(!ACLController::checkAccess($focus->module_dir, 'import', true)){
66 ACLController::displayNoAccess();
79 * Displays the Smarty template for an error
81 * @param string $message error message to show
82 * @param string $module what module we were importing into
83 * @param string $action what page we should go back to
85 function showImportError(
91 $ss = new Sugar_Smarty();
93 $ss->assign("MESSAGE",$message);
94 $ss->assign("ACTION",$action);
95 $ss->assign("IMPORT_MODULE",$module);
96 $ss->assign("MOD", $GLOBALS['mod_strings']);
97 $ss->assign("SOURCE","");
98 if ( isset($_REQUEST['source']) )
99 $ss->assign("SOURCE", $_REQUEST['source']);
101 echo $ss->fetch('modules/Import/tpls/error.tpl');
105 * Replaces PHP error handler in Step4
108 * @param string $errstr
109 * @param string $errfile
110 * @param string $errline
112 function handleImportErrors(
119 if ( !defined('E_DEPRECATED') )
120 define('E_DEPRECATED','8192');
121 if ( !defined('E_USER_DEPRECATED') )
122 define('E_USER_DEPRECATED','16384');
124 // check to see if current reporting level should be included based upon error_reporting() setting, if not
126 if ( !(error_reporting() & $errno) )
131 $err_str = "ERROR: [$errno] $errstr on line $errline in file $errfile<br />\n";
132 $GLOBALS['log']->fatal('IMPORT ERROR:: '.$err_str);
138 $GLOBALS['log']->fatal("IMPORT WARNING:: [$errno] $errstr on line $errline in file $errfile<br />\n");
142 $GLOBALS['log']->fatal("IMPORT NOTICE:: [$errno] $errstr on line $errline in file $errfile<br />\n");
146 case E_USER_DEPRECATED:
147 // don't worry about these
148 //echo "STRICT ERROR: [$errno] $errstr on line $errline in file $errfile<br />\n";
151 $err_str = "Unknown error type: [$errno] $errstr on line $errline in file $errfile<br />\n";
153 $GLOBALS['log']->fatal('IMPORT ERROR:: '.$err_str);
162 * Returns an input control for this fieldname given
164 * @param string $module
165 * @param string $fieldname
166 * @param string $vardef
167 * @param string $value
168 * @return string html for input element for this control
177 global $current_language, $app_strings, $dictionary, $app_list_strings;
179 // use the mod_strings for this module
180 $mod_strings = return_module_language($current_language,$module);
182 // set the filename for this control
183 $file = create_cache_directory('modules/Import/') . $module . $fieldname . '.tpl';
186 || !empty($GLOBALS['sugar_config']['developerMode'])
187 || !empty($_SESSION['developerMode']) ) {
189 if ( !isset($vardef) ) {
190 $focus = loadBean($module);
191 $vardef = $focus->getFieldDefinition($fieldname);
194 // if this is the id relation field, then don't have a pop-up selector.
195 if( $vardef['type'] == 'relate' && $vardef['id_name'] == $vardef['name']) {
196 $vardef['type'] = 'varchar';
199 // create the dropdowns for the parent type fields
200 if ( $vardef['type'] == 'parent_type' ) {
201 $vardef['type'] = 'enum';
204 // remove the special text entry field function 'getEmailAddressWidget'
205 if ( isset($vardef['function'])
206 && ( $vardef['function'] == 'getEmailAddressWidget'
207 || $vardef['function']['name'] == 'getEmailAddressWidget' ) )
208 unset($vardef['function']);
210 // load SugarFieldHandler to render the field tpl file
214 require_once('include/SugarFields/SugarFieldHandler.php');
215 $sfh = new SugarFieldHandler();
218 $displayParams = array();
219 $displayParams['formName'] = 'importstep3';
221 $contents = $sfh->displaySmarty('fields', $vardef, 'ImportView', $displayParams);
223 // Remove all the copyright comments
224 $contents = preg_replace('/\{\*[^\}]*?\*\}/', '', $contents);
226 // hack to disable one of the js calls in this control
227 if ( isset($vardef['function'])
228 && ( $vardef['function'] == 'getCurrencyDropDown'
229 || $vardef['function']['name'] == 'getCurrencyDropDown' ) )
230 $contents .= "{literal}<script>function CurrencyConvertAll() { return; }</script>{/literal}";
232 // Save it to the cache file
233 if($fh = @sugar_fopen($file, 'w')) {
234 fputs($fh, $contents);
239 // Now render the template we received
240 $ss = new Sugar_Smarty();
242 // Create Smarty variables for the Calendar picker widget
244 $time_format = $timedate->get_user_time_format();
245 $date_format = $timedate->get_cal_date_format();
246 $ss->assign('USER_DATEFORMAT', $timedate->get_user_date_format());
247 $ss->assign('TIME_FORMAT', $time_format);
248 $time_separator = ":";
250 if(preg_match('/\d+([^\d])\d+([^\d]*)/s', $time_format, $match)) {
251 $time_separator = $match[1];
253 $t23 = strpos($time_format, '23') !== false ? '%H' : '%I';
254 if(!isset($match[2]) || $match[2] == '') {
255 $ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M");
258 $pm = $match[2] == "pm" ? "%P" : "%p";
259 $ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M" . $pm);
262 // populate the fieldlist from the vardefs
263 $fieldlist = array();
264 if ( !isset($focus) || !($focus instanceof SugarBean) )
265 $focus = loadBean($module);
266 // create the dropdowns for the parent type fields
267 if ( $vardef['type'] == 'parent_type' ) {
268 $focus->field_defs[$vardef['name']]['options'] = $focus->field_defs[$vardef['group']]['options'];
270 $vardefFields = $focus->getFieldDefinitions();
271 foreach ( $vardefFields as $name => $properties ) {
272 $fieldlist[$name] = $properties;
274 if(isset($fieldlist[$name]['options']) && is_string($fieldlist[$name]['options']) && isset($app_list_strings[$fieldlist[$name]['options']]))
275 $fieldlist[$name]['options'] = $app_list_strings[$fieldlist[$name]['options']];
276 // Bug 32626: fall back on checking the mod_strings if not in the app_list_strings
277 elseif(isset($fieldlist[$name]['options']) && is_string($fieldlist[$name]['options']) && isset($mod_strings[$fieldlist[$name]['options']]))
278 $fieldlist[$name]['options'] = $mod_strings[$fieldlist[$name]['options']];
279 // Bug 22730: make sure all enums have the ability to select blank as the default value.
280 if(!isset($fieldlist[$name]['options']['']))
281 $fieldlist[$name]['options'][''] = '';
283 // fill in function return values
284 if ( !in_array($fieldname,array('email1','email2')) ) {
285 if (!empty($fieldlist[$fieldname]['function']['returns']) && $fieldlist[$fieldname]['function']['returns'] == 'html'){
286 $function = $fieldlist[$fieldname]['function']['name'];
287 // include various functions required in the various vardefs
288 if ( isset($fieldlist[$fieldname]['function']['include']) && is_file($fieldlist[$fieldname]['function']['include']))
289 require_once($fieldlist[$fieldname]['function']['include']);
290 $value = $function($focus, $fieldname, $value, 'EditView');
291 // Bug 22730 - add a hack for the currency type dropdown, since it's built by a function.
292 if ( preg_match('/getCurrency.*DropDown/s',$function) )
293 $value = str_ireplace('</select>','<option value="">'.$app_strings['LBL_NONE'].'</option></select>',$value);
296 $fieldlist[$fieldname]['value'] = $value;
297 $ss->assign("fields",$fieldlist);
298 $ss->assign("form_name",'importstep3');
299 $ss->assign("bean",$focus);
301 // add in any additional strings
302 $ss->assign("MOD", $mod_strings);
303 $ss->assign("APP", $app_strings);
304 return $ss->fetch($file);