]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Import/views/view.confirm.php
Release 6.5.1
[Github/sugarcrm.git] / modules / Import / views / view.confirm.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-2012 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 /*********************************************************************************
39
40  * Description: view handler for step 1 of the import process
41  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42  * All Rights Reserved.
43  ********************************************************************************/
44 require_once('modules/Import/views/ImportView.php');
45 require_once('modules/Import/sources/ImportFile.php');
46 require_once('modules/Import/ImportFileSplitter.php');
47 require_once('modules/Import/CsvAutoDetect.php');
48
49 require_once('include/upload_file.php');
50
51 class ImportViewConfirm extends ImportView
52 {
53     const SAMPLE_ROW_SIZE = 3;
54         protected $pageTitleKey = 'LBL_CONFIRM_TITLE';
55     protected $errorScript = "";
56     
57         /**
58      * @see SugarView::display()
59      */
60         public function display()
61     {
62         global $mod_strings, $app_strings, $current_user;
63         global $sugar_config, $locale;
64         
65         $this->ss->assign("IMPORT_MODULE", $_REQUEST['import_module']);
66         $this->ss->assign("TYPE",( !empty($_REQUEST['type']) ? $_REQUEST['type'] : "import" ));
67         $this->ss->assign("SOURCE_ID", $_REQUEST['source_id']);
68
69         $this->instruction = 'LBL_SELECT_PROPERTY_INSTRUCTION';
70         $this->ss->assign('INSTRUCTION', $this->getInstruction());
71
72         $this->ss->assign("MODULE_TITLE", $this->getModuleTitle(false), ENT_NOQUOTES);
73         $this->ss->assign("CURRENT_STEP", $this->currentStep);
74         $sugar_config['import_max_records_per_file'] = ( empty($sugar_config['import_max_records_per_file']) ? 1000 : $sugar_config['import_max_records_per_file'] );
75         $importSource = isset($_REQUEST['source']) ? $_REQUEST['source'] : 'csv' ;
76
77         // Clear out this user's last import
78         $seedUsersLastImport = new UsersLastImport();
79         $seedUsersLastImport->mark_deleted_by_user_id($current_user->id);
80         ImportCacheFiles::clearCacheFiles();
81
82         // handle uploaded file
83         $uploadFile = new UploadFile('userfile');
84         if (isset($_FILES['userfile']) && $uploadFile->confirm_upload())
85         {
86             $uploadFile->final_move('IMPORT_'.$this->bean->object_name.'_'.$current_user->id);
87             $uploadFileName = $uploadFile->get_upload_path('IMPORT_'.$this->bean->object_name.'_'.$current_user->id);
88         }
89         elseif( !empty($_REQUEST['tmp_file']) )
90         {
91             $uploadFileName = "upload://".basename($_REQUEST['tmp_file']);
92         }
93         else
94         {
95             $this->_showImportError($mod_strings['LBL_IMPORT_MODULE_ERROR_NO_UPLOAD'],$_REQUEST['import_module'],'Step2', true, null, true);
96             return;
97         }
98
99         //check the file size, we dont want to process an empty file
100         if(isset($_FILES['userfile']['size']) && $_FILES['userfile']['size'] == 0){
101             //this file is empty, throw error message
102             $this->_showImportError($mod_strings['LBL_NO_LINES'],$_REQUEST['import_module'],'Step2', false, null, true);
103             return;
104         }
105
106         $mimeTypeOk = true;
107
108         //check to see if the file mime type is not a form of text or application octed streramand fire error if not
109         if(isset($_FILES['userfile']['type']) && strpos($_FILES['userfile']['type'],'octet-stream') === false && strpos($_FILES['userfile']['type'],'text') === false
110             && strpos($_FILES['userfile']['type'],'application/vnd.ms-excel') === false) {
111             //this file does not have a known text or application type of mime type, issue the warning
112             $error_msgs[] = $mod_strings['LBL_MIME_TYPE_ERROR_1'];
113             $error_msgs[] = $mod_strings['LBL_MIME_TYPE_ERROR_2'];
114             $this->_showImportError($error_msgs,$_REQUEST['import_module'],'Step2', true, $mod_strings['LBL_OK']);
115             $mimeTypeOk = false;
116         }
117
118         $this->ss->assign("FILE_NAME", $uploadFileName);
119
120         // Now parse the file and look for errors
121         $importFile = new ImportFile( $uploadFileName, $_REQUEST['custom_delimiter'], html_entity_decode($_REQUEST['custom_enclosure'],ENT_QUOTES), FALSE);
122
123         if( $this->shouldAutoDetectProperties($importSource) )
124         {
125             $GLOBALS['log']->debug("Auto detecing csv properties...");
126             $autoDetectOk = $importFile->autoDetectCSVProperties();
127             $importFileMap = array();
128             $this->ss->assign("SOURCE", 'csv');
129             if($autoDetectOk === FALSE)
130             {
131                 //show error only if previous mime type check has passed
132                 if($mimeTypeOk){
133                      $this->ss->assign("AUTO_DETECT_ERROR",  $mod_strings['LBL_AUTO_DETECT_ERROR']);
134                  }
135             }
136             else
137             {
138                 $dateFormat = $importFile->getDateFormat();
139                 $timeFormat = $importFile->getTimeFormat();
140                 if ($dateFormat) {
141                     $importFileMap['importlocale_dateformat'] = $dateFormat;
142                 }
143                 if ($timeFormat) {
144                     $importFileMap['importlocale_timeformat'] = $timeFormat;
145                 }
146             }
147         }
148         else
149         {
150             $impotMapSeed = $this->getImportMap($importSource);
151             $importFile->setImportFileMap($impotMapSeed);
152             $importFileMap = $impotMapSeed->getMapping($_REQUEST['import_module']);
153         }
154
155         $delimeter = $importFile->getFieldDelimeter();
156         $enclosure = $importFile->getFieldEnclosure();
157         $hasHeader = $importFile->hasHeaderRow();
158
159         $encodeOutput = TRUE;
160         //Handle users navigating back through the wizard.
161         if( !empty($_REQUEST['previous_action']) && $_REQUEST['previous_action'] == 'Confirm')
162         {
163             $encodeOutput = FALSE;
164             $importFileMap = $this->overloadImportFileMapFromRequest($importFileMap);
165             $delimeter = !empty($_REQUEST['custom_delimiter']) ? $_REQUEST['custom_delimiter'] : $delimeter;
166             $enclosure = isset($_REQUEST['custom_enclosure']) ? $_REQUEST['custom_enclosure'] : $enclosure;
167             $enclosure = html_entity_decode($enclosure, ENT_QUOTES);
168             $hasHeader = !empty($_REQUEST['has_header']) ? $_REQUEST['has_header'] : $hasHeader;
169             if ($hasHeader == 'on') {
170                 $hasHeader = true;
171             } else if ($hasHeader == 'off') {
172                 $hasHeader = false;
173             }
174         }
175
176         $this->ss->assign("IMPORT_ENCLOSURE_OPTIONS",  $this->getEnclosureOptions($enclosure));
177         $this->ss->assign("IMPORT_DELIMETER_OPTIONS",  $this->getDelimeterOptions($delimeter));
178         $this->ss->assign("CUSTOM_DELIMITER",  $delimeter);
179         $this->ss->assign("CUSTOM_ENCLOSURE",  htmlentities($enclosure, ENT_QUOTES));
180         $hasHeaderFlag = $hasHeader ? " CHECKED" : "";
181         $this->ss->assign("HAS_HEADER_CHECKED", $hasHeaderFlag);
182
183         if ( !$importFile->fileExists() ) {
184             $this->_showImportError($mod_strings['LBL_CANNOT_OPEN'],$_REQUEST['import_module'],'Step2', false, null, true);
185             return;
186         }
187
188          //Check if we will exceed the maximum number of records allowed per import.
189          $maxRecordsExceeded = FALSE;
190          $maxRecordsWarningMessg = "";
191          $lineCount = $importFile->getNumberOfLinesInfile();
192          $maxLineCount = isset($sugar_config['import_max_records_total_limit'] ) ? $sugar_config['import_max_records_total_limit'] : 5000;
193          if( !empty($maxLineCount) && ($lineCount > $maxLineCount) )
194          {
195              $maxRecordsExceeded = TRUE;
196              $maxRecordsWarningMessg = string_format($mod_strings['LBL_IMPORT_ERROR_MAX_REC_LIMIT_REACHED'], array($lineCount, $maxLineCount) );
197          }
198
199         //Retrieve a sample set of data
200         $rows = $this->getSampleSet($importFile);
201         $this->ss->assign('column_count', $this->getMaxColumnsInSampleSet($rows) );
202         $this->ss->assign('HAS_HEADER', $importFile->hasHeaderRow(FALSE) );
203         $this->ss->assign('getNumberJs', $locale->getNumberJs());
204         $this->setImportFileCharacterSet($importFile, $importFileMap);
205         $this->setDateTimeProperties($importFileMap);
206         $this->setCurrencyOptions($importFileMap);
207         $this->setNumberFormatOptions($importFileMap);
208         $this->setNameFormatProperties($importFileMap);
209
210         $importMappingJS = $this->getImportMappingJS();
211
212         $this->ss->assign("SAMPLE_ROWS",$rows);
213         $JS = $this->_getJS($maxRecordsExceeded, $maxRecordsWarningMessg, $importMappingJS, $importFileMap );
214         $this->ss->assign("JAVASCRIPT", $JS);
215         $content = $this->ss->fetch('modules/Import/tpls/confirm.tpl');
216         $this->ss->assign("CONTENT",$content);
217         $this->ss->display('modules/Import/tpls/wizardWrapper.tpl');
218         
219     }
220
221     private function getDelimeterOptions($selctedDelim)
222     {
223         $selctedDelim = $selctedDelim == "\t" ? '\t' : $selctedDelim;
224         return get_select_options_with_id($GLOBALS['app_list_strings']['import_delimeter_options'], $selctedDelim);
225     }
226
227     private function getEnclosureOptions($enclosure)
228     {
229         $results = array();
230         foreach ($GLOBALS['app_list_strings']['import_enclosure_options'] as $k => $v)
231         {
232             $results[htmlentities($k, ENT_QUOTES)] = $v;
233         }
234
235         return get_select_options_with_id($results, htmlentities($enclosure, ENT_QUOTES));
236     }
237
238     private function overloadImportFileMapFromRequest($importFileMap)
239     {
240         $overideKeys = array(
241             'importlocale_dateformat','importlocale_timeformat','importlocale_timezone','importlocale_charset',
242             'importlocale_currency','importlocale_default_currency_significant_digits','importlocale_num_grp_sep',
243             'importlocale_dec_sep','importlocale_default_locale_name_format','custom_delimiter', 'custom_enclosure'
244         );
245
246         foreach($overideKeys as $key)
247         {
248             if( !empty( $_REQUEST[$key]) )
249                 $importFileMap[$key] = $_REQUEST[$key];
250         }
251         return $importFileMap;
252     }
253
254     private function shouldAutoDetectProperties($importSource)
255     {
256         if(empty($importSource) || $importSource == 'csv' )
257             return TRUE;
258         else
259             return FALSE;
260     }
261
262     private function getImportMap($importSource)
263     {
264         if ( strncasecmp("custom:",$importSource,7) == 0)
265         {
266             $id = substr($importSource,7);
267             $import_map_seed = new ImportMap();
268             $import_map_seed->retrieve($id, false);
269
270             $this->ss->assign("SOURCE_ID", $import_map_seed->id);
271             $this->ss->assign("SOURCE_NAME", $import_map_seed->name);
272             $this->ss->assign("SOURCE", $import_map_seed->source);
273         }
274         else
275         {
276             $classname = 'ImportMap' . ucfirst($importSource);
277             if ( file_exists("modules/Import/maps/{$classname}.php") )
278                 require_once("modules/Import/maps/{$classname}.php");
279             elseif ( file_exists("custom/modules/Import/maps/{$classname}.php") )
280                 require_once("custom/modules/Import/maps/{$classname}.php");
281             else
282             {
283                 require_once("custom/modules/Import/maps/ImportMapOther.php");
284                 $classname = 'ImportMapOther';
285                 $importSource = 'other';
286             }
287             if ( class_exists($classname) )
288             {
289                 $import_map_seed = new $classname;
290                 $this->ss->assign("SOURCE", $importSource);
291             }
292         }
293
294         return $import_map_seed;
295     }
296
297     private function setNameFormatProperties($field_map = array())
298     {
299         global $locale, $current_user;
300
301         $localized_name_format = isset($field_map['importlocale_default_locale_name_format'])? $field_map['importlocale_default_locale_name_format'] : $locale->getLocaleFormatMacro($current_user);
302         $this->ss->assign('default_locale_name_format', $localized_name_format);
303         $this->ss->assign('getNameJs', $locale->getNameJs());
304
305     }
306
307     private function setNumberFormatOptions($field_map = array())
308     {
309         global $locale, $current_user, $sugar_config;
310
311         $num_grp_sep = isset($field_map['importlocale_num_grp_sep'])? $field_map['importlocale_num_grp_sep'] : $current_user->getPreference('num_grp_sep');
312         $dec_sep = isset($field_map['importlocale_dec_sep'])? $field_map['importlocale_dec_sep'] : $current_user->getPreference('dec_sep');
313
314         $this->ss->assign("NUM_GRP_SEP",( empty($num_grp_sep) ? $sugar_config['default_number_grouping_seperator'] : $num_grp_sep ));
315         $this->ss->assign("DEC_SEP",( empty($dec_sep)? $sugar_config['default_decimal_seperator'] : $dec_sep ));
316
317
318         $significantDigits = isset($field_map['importlocale_default_currency_significant_digits']) ? $field_map['importlocale_default_currency_significant_digits']
319                                 :  $locale->getPrecedentPreference('default_currency_significant_digits', $current_user);
320
321         $sigDigits = '';
322         for($i=0; $i<=6; $i++)
323         {
324             if($significantDigits == $i)
325             {
326                 $sigDigits .= '<option value="'.$i.'" selected="true">'.$i.'</option>';
327             } else
328             {
329                 $sigDigits .= '<option value="'.$i.'">'.$i.'</option>';
330             }
331         }
332
333         $this->ss->assign('sigDigits', $sigDigits);
334     }
335
336
337     private function setCurrencyOptions($field_map = array() )
338     {
339         global $locale, $current_user;
340         $cur_id = isset($field_map['importlocale_currency'])? $field_map['importlocale_currency'] : $locale->getPrecedentPreference('currency', $current_user);
341         // get currency preference
342         require_once('modules/Currencies/ListCurrency.php');
343         $currency = new ListCurrency();
344         if($cur_id)
345             $selectCurrency = $currency->getSelectOptions($cur_id);
346         else
347             $selectCurrency = $currency->getSelectOptions();
348
349         $this->ss->assign("CURRENCY", $selectCurrency);
350
351         $currenciesVars = "";
352         $i=0;
353         foreach($locale->currencies as $id => $arrVal)
354         {
355             $currenciesVars .= "currencies[{$i}] = '{$arrVal['symbol']}';\n";
356             $i++;
357         }
358         $currencySymbolsJs = <<<eoq
359 var currencies = new Object;
360 {$currenciesVars}
361 function setSymbolValue(id) {
362     document.getElementById('symbol').value = currencies[id];
363 }
364 eoq;
365         return $currencySymbolsJs;
366
367     }
368
369
370     private function setDateTimeProperties( $field_map = array() )
371     {
372         global $current_user, $sugar_config;
373
374         $timeFormat = $current_user->getUserDateTimePreferences();
375         $defaultTimeOption = isset($field_map['importlocale_timeformat'])? $field_map['importlocale_timeformat'] : $timeFormat['time'];
376         $defaultDateOption = isset($field_map['importlocale_dateformat'])? $field_map['importlocale_dateformat'] : $timeFormat['date'];
377
378         $timeOptions = get_select_options_with_id($sugar_config['time_formats'], $defaultTimeOption);
379         $dateOptions = get_select_options_with_id($sugar_config['date_formats'], $defaultDateOption);
380
381         // get list of valid timezones
382         $userTZ = isset($field_map['importlocale_timezone'])? $field_map['importlocale_timezone'] : $current_user->getPreference('timezone');
383         if(empty($userTZ))
384             $userTZ = TimeDate::userTimezone();
385
386         $this->ss->assign('TIMEZONE_CURRENT', $userTZ);
387         $this->ss->assign('TIMEOPTIONS', $timeOptions);
388         $this->ss->assign('DATEOPTIONS', $dateOptions);
389         $this->ss->assign('TIMEZONEOPTIONS', TimeDate::getTimezoneList());
390     }
391
392     private function setImportFileCharacterSet($importFile, $field_map = array())
393     {
394         global $locale;
395         $charset_for_import = isset($field_map['importlocale_charset']) ? $field_map['importlocale_charset'] : $importFile->autoDetectCharacterSet();
396         $charsetOptions = get_select_options_with_id( $locale->getCharsetSelect(), $charset_for_import);//wdong,  bug 25927, here we should use the charset testing results from above.
397         $this->ss->assign('CHARSETOPTIONS', $charsetOptions);
398     }
399
400     protected function getImportMappingJS()
401     {
402         $results = array();
403         $importMappings = array('ImportMapSalesforce', 'ImportMapOutlook');
404         foreach($importMappings as $importMap)
405         {
406             $tmpFile = "modules/Import/maps/$importMap.php";
407             if( file_exists($tmpFile) )
408             {
409                 require_once($tmpFile);
410                 $t = new $importMap();
411                 $results[$t->name] = array('delim' => $t->delimiter, 'enclos' => $t->enclosure, 'has_header' => $t->has_header);
412             }
413         }
414         return $results;
415     }
416
417     public function getMaxColumnsInSampleSet($sampleSet)
418     {
419         $maxColumns = 0;
420         foreach($sampleSet as $v)
421         {
422             if(count($v) > $maxColumns)
423                 $maxColumns = count($v);
424             else
425                 continue;
426         }
427
428         return $maxColumns;
429     }
430
431     public function getSampleSet($importFile)
432     {
433         $rows = array();
434         for($i=0; $i < self::SAMPLE_ROW_SIZE; $i++)
435         {
436             $rows[] = $importFile->getNextRow();
437         }
438
439         if( ! $importFile->hasHeaderRow(FALSE) )
440         {
441             array_unshift($rows, array_fill(0,1,'') );
442         }
443
444         // to be displayed in UTF-8 format
445         global $locale;
446         $encoding = $importFile->autoDetectCharacterSet();
447         if (!empty($encoding) && $encoding != 'UTF-8') {
448             foreach ($rows as &$row) {
449                 if (is_array($row)) {
450                     foreach ($row as &$val) {
451                         $val = $locale->translateCharset($val, $encoding);
452                     }
453                 }
454             }
455         }
456         
457         foreach ($rows as &$row) {
458             if (is_array($row)) {
459                 foreach ($row as &$val) {
460                     $val = strip_tags($val);
461                 }
462             }
463         }
464     
465         return $rows;
466     }
467
468     /**
469      * Returns JS used in this view
470      */
471     private function _getJS($maxRecordsExceeded, $maxRecordsWarningMessg, $importMappingJS, $importFileMap)
472     {
473         global $mod_strings, $locale;
474         $maxRecordsExceededJS = $maxRecordsExceeded?"true":"false";
475         $importMappingJS = json_encode($importMappingJS);
476         
477         $currencySymbolJs = $this->setCurrencyOptions($importFileMap);
478         $getNumberJs = $locale->getNumberJs();
479         $getNameJs = $locale->getNameJs();
480         
481         return <<<EOJAVASCRIPT
482
483
484 var import_mapping_js = $importMappingJS;
485 document.getElementById('goback').onclick = function()
486 {
487     document.getElementById('importconfirm').action.value = 'Step2';
488     return true;
489 }
490
491 document.getElementById('gonext').onclick = function()
492 {
493     document.getElementById('importconfirm').action.value = 'Step3';
494     return true;
495 }
496
497 document.getElementById('custom_enclosure').onchange = function()
498 {
499     document.getElementById('importconfirm').custom_enclosure_other.style.display = ( this.value == 'other' ? '' : 'none' );
500 }
501
502 document.getElementById('custom_delimiter').onchange = function()
503 {
504     document.getElementById('importconfirm').custom_delimiter_other.style.display = ( this.value == 'other' ? '' : 'none' );
505 }
506
507 document.getElementById('toggleImportOptions').onclick = function() {
508     if (document.getElementById('importOptions').style.display == 'none'){
509         document.getElementById('importOptions').style.display = '';
510         document.getElementById('toggleImportOptions').value='  {$mod_strings['LBL_HIDE_ADVANCED_OPTIONS']}  ';
511         document.getElementById('toggleImportOptions').title='{$mod_strings['LBL_HIDE_ADVANCED_OPTIONS']}';
512     }
513     else {
514         document.getElementById('importOptions').style.display = 'none';
515         document.getElementById('toggleImportOptions').value='  {$mod_strings['LBL_SHOW_ADVANCED_OPTIONS']}  ';
516         document.getElementById('toggleImportOptions').title='{$mod_strings['LBL_SHOW_ADVANCED_OPTIONS']}';
517     }
518 }
519
520 YAHOO.util.Event.onDOMReady(function(){
521     if($maxRecordsExceededJS)
522     {
523         var contImport = confirm('$maxRecordsWarningMessg');
524         if(!contImport)
525         {
526             var module = document.getElementById('importconfirm').import_module.value;
527             var source = document.getElementById('importconfirm').source.value;
528             var returnUrl = "index.php?module=Import&action=Step2&import_module=" + module + "&source=" + source;
529             document.location.href = returnUrl;
530         }
531     }
532
533     function refreshDataTable(e)
534     {
535         var callback = {
536           success: function(o) {
537             document.getElementById('confirm_table').innerHTML = o.responseText;
538           },
539           failure: function(o) {},
540         };
541
542         var importFile = document.getElementById('importconfirm').file_name.value;
543         var fieldDelimeter = document.getElementById('custom_delimiter').value;
544         if(fieldDelimeter == 'other')
545             fieldDelimeter  = document.getElementById('custom_delimiter_other').value;
546
547         var fieldQualifier = document.getElementById('custom_enclosure').value;
548         var hasHeader = document.getElementById('importconfirm').has_header.checked ? 'true' : '';
549
550         if(fieldQualifier == 'other' && this.id == 'custom_enclosure')
551         {
552             return;
553         }
554         else if( fieldQualifier == 'other' )
555         {
556             fieldQualifier = document.getElementById('custom_enclosure_other').value;
557         }
558
559         var url = 'index.php?action=RefreshMapping&module=Import&importFile=' + importFile
560                     + '&delim=' + fieldDelimeter + '&qualif=' + fieldQualifier + "&header=" + hasHeader;
561
562         YAHOO.util.Connect.asyncRequest('GET', url, callback);
563     }
564     var subscribers = ["custom_delimiter", "custom_enclosure", "custom_enclosure_other", "has_header", "importlocale_charset", "custom_delimiter_other"];
565     YAHOO.util.Event.addListener(subscribers, "change", refreshDataTable);
566
567     function setMappingProperties(el)
568     {
569        var sourceEl = document.getElementById('source');
570        if(sourceEl.value != '' && sourceEl.value != 'csv' && sourceEl.value != 'salesforce' && sourceEl.value != 'outlook')
571        {
572            if( !confirm(SUGAR.language.get('Import','LBL_CONFIRM_MAP_OVERRIDE')) )
573            {
574                 deSelectExternalSources();
575                 return;
576            }
577         }
578         var selectedMap = this.value;
579         if( typeof(import_mapping_js[selectedMap]) == 'undefined')
580             return;
581
582         sourceEl.value = selectedMap;
583         document.getElementById('custom_delimiter').value = import_mapping_js[selectedMap].delim;
584         document.getElementById('custom_enclosure').value = import_mapping_js[selectedMap].enclos;
585         document.getElementById('has_header').checked = import_mapping_js[selectedMap].has_header;
586
587         refreshDataTable();
588     }
589
590     function deSelectExternalSources()
591     {
592         var els = document.getElementsByName('external_source');
593         for(i=0;i<els.length;i++)
594         {
595             els[i].checked = false;
596         }
597     }
598     YAHOO.util.Event.addListener(['sf_map', 'outlook_map'], "click", setMappingProperties);
599 });
600 var deselectEl = document.getElementById('deselect');
601 if(deselectEl)
602 {
603     deselectEl.onclick = function() {
604         var els = document.getElementsByName('external_source');
605         for(i=0;i<els.length;i++)
606         {
607             els[i].checked = false;
608         }
609     }
610 }
611
612 {$currencySymbolJs}
613 {$getNumberJs}
614 {$getNameJs}
615 setSigDigits();
616 setSymbolValue(document.getElementById('currency_select').selectedIndex);
617
618 EOJAVASCRIPT;
619     }
620
621     /**
622      * Displays the Smarty template for an error
623      *
624      * @param string $message error message to show
625      * @param string $module what module we were importing into
626      * @param string $action what page we should go back to
627      */
628     protected function _showImportError($message,$module,$action = 'Step1',$showCancel = false, $cancelLabel = null, $display = false)
629     {
630         if(!is_array($message)){
631             $message = array($message);
632         }
633         $ss = new Sugar_Smarty();
634         $display_msg = '';
635         foreach($message as $m){
636             $display_msg .= '<p>'.htmlentities($m, ENT_QUOTES).'</p><br>';
637         }
638                 global $mod_strings;
639
640         $ss->assign("MESSAGE",$display_msg);
641         $ss->assign("ACTION",$action);
642         $ss->assign("IMPORT_MODULE",$module);
643         $ss->assign("MOD", $GLOBALS['mod_strings']);
644         $ss->assign("SOURCE","");
645         $ss->assign("SHOWCANCEL",$showCancel);
646         if ( isset($_REQUEST['source']) )
647             $ss->assign("SOURCE", $_REQUEST['source']);
648
649         if ($cancelLabel) {
650             $ss->assign('CANCELLABEL', $cancelLabel);
651         }
652
653         $content = $ss->fetch('modules/Import/tpls/error.tpl');
654
655         echo $ss->fetch('modules/Import/tpls/error.tpl');
656     }
657
658 }
659
660 ?>