コード例 #1
0
ファイル: view.confirm.php プロジェクト: jglaine/sugar761-ent
 /**
  * @see SugarView::display()
  */
 public function display()
 {
     global $mod_strings, $app_strings, $current_user;
     global $sugar_config, $locale;
     $this->ss->assign("IMPORT_MODULE", $_REQUEST['import_module']);
     $this->ss->assign("TYPE", !empty($_REQUEST['type']) ? $_REQUEST['type'] : "import");
     $this->ss->assign("SOURCE_ID", $_REQUEST['source_id']);
     $this->instruction = 'LBL_SELECT_PROPERTY_INSTRUCTION';
     $this->ss->assign('INSTRUCTION', $this->getInstruction());
     $this->ss->assign("MODULE_TITLE", $this->getModuleTitle(false), ENT_NOQUOTES);
     $this->ss->assign("CURRENT_STEP", $this->currentStep);
     $sugar_config['import_max_records_per_file'] = empty($sugar_config['import_max_records_per_file']) ? 1000 : $sugar_config['import_max_records_per_file'];
     $importSource = isset($_REQUEST['source']) ? $_REQUEST['source'] : 'csv';
     // Clear out this user's last import
     $seedUsersLastImport = BeanFactory::getBean('Import_2');
     $seedUsersLastImport->mark_deleted_by_user_id($current_user->id);
     ImportCacheFiles::clearCacheFiles();
     // handle uploaded file
     $uploadFile = new UploadFile('userfile');
     if (isset($_FILES['userfile']) && $uploadFile->confirm_upload()) {
         $uploadFile->final_move('IMPORT_' . $this->bean->object_name . '_' . $current_user->id);
         $uploadFileName = $uploadFile->get_upload_path('IMPORT_' . $this->bean->object_name . '_' . $current_user->id);
     } elseif (!empty($_REQUEST['tmp_file'])) {
         $uploadFileName = "upload://" . basename($_REQUEST['tmp_file']);
     } else {
         $this->_showImportError($mod_strings['LBL_IMPORT_MODULE_ERROR_NO_UPLOAD'], $_REQUEST['import_module'], 'Step2', true, null, true);
         return;
     }
     //check the file size, we dont want to process an empty file
     if (isset($_FILES['userfile']['size']) && $_FILES['userfile']['size'] == 0) {
         //this file is empty, throw error message
         $this->_showImportError($mod_strings['LBL_NO_LINES'], $_REQUEST['import_module'], 'Step2', false, null, true);
         return;
     }
     $mimeTypeOk = true;
     //check to see if the file mime type is not a form of text or application octed streramand fire error if not
     if (isset($_FILES['userfile']['type']) && strpos($_FILES['userfile']['type'], 'octet-stream') === false && strpos($_FILES['userfile']['type'], 'text') === false && strpos($_FILES['userfile']['type'], 'application/vnd.ms-excel') === false) {
         //this file does not have a known text or application type of mime type, issue the warning
         $error_msgs[] = $mod_strings['LBL_MIME_TYPE_ERROR_1'];
         $error_msgs[] = $mod_strings['LBL_MIME_TYPE_ERROR_2'];
         $this->_showImportError($error_msgs, $_REQUEST['import_module'], 'Step2', true, $mod_strings['LBL_OK']);
         $mimeTypeOk = false;
     }
     $this->ss->assign("FILE_NAME", $uploadFileName);
     // Now parse the file and look for errors
     $importFile = new ImportFile($uploadFileName, $_REQUEST['custom_delimiter'], html_entity_decode($_REQUEST['custom_enclosure'], ENT_QUOTES), FALSE);
     if ($this->shouldAutoDetectProperties($importSource)) {
         $GLOBALS['log']->debug("Auto detecing csv properties...");
         $autoDetectOk = $importFile->autoDetectCSVProperties();
         $importFileMap = array();
         $this->ss->assign("SOURCE", 'csv');
         if ($autoDetectOk === FALSE) {
             //show error only if previous mime type check has passed
             if ($mimeTypeOk) {
                 $this->ss->assign("AUTO_DETECT_ERROR", $mod_strings['LBL_AUTO_DETECT_ERROR']);
             }
         } else {
             $dateFormat = $importFile->getDateFormat();
             $timeFormat = $importFile->getTimeFormat();
             if ($dateFormat) {
                 $importFileMap['importlocale_dateformat'] = $dateFormat;
             }
             if ($timeFormat) {
                 $importFileMap['importlocale_timeformat'] = $timeFormat;
             }
         }
     } else {
         $impotMapSeed = $this->getImportMap($importSource);
         $importFile->setImportFileMap($impotMapSeed);
         $importFileMap = $impotMapSeed->getMapping($_REQUEST['import_module']);
     }
     $delimeter = $importFile->getFieldDelimeter();
     $enclosure = $importFile->getFieldEnclosure();
     $hasHeader = $importFile->hasHeaderRow();
     $encodeOutput = TRUE;
     //Handle users navigating back through the wizard.
     if (!empty($_REQUEST['previous_action']) && $_REQUEST['previous_action'] == 'Confirm') {
         $encodeOutput = FALSE;
         $importFileMap = $this->overloadImportFileMapFromRequest($importFileMap);
         $delimeter = !empty($_REQUEST['custom_delimiter']) ? $_REQUEST['custom_delimiter'] : $delimeter;
         $enclosure = isset($_REQUEST['custom_enclosure']) ? $_REQUEST['custom_enclosure'] : $enclosure;
         $enclosure = html_entity_decode($enclosure, ENT_QUOTES);
         $hasHeader = !empty($_REQUEST['has_header']) ? $_REQUEST['has_header'] : $hasHeader;
         if ($hasHeader == 'on') {
             $hasHeader = true;
         } else {
             if ($hasHeader == 'off') {
                 $hasHeader = false;
             }
         }
     }
     $this->ss->assign("IMPORT_ENCLOSURE_OPTIONS", $this->getEnclosureOptions($enclosure));
     $this->ss->assign("IMPORT_DELIMETER_OPTIONS", $this->getDelimeterOptions($delimeter));
     $this->ss->assign("CUSTOM_DELIMITER", $delimeter);
     $this->ss->assign("CUSTOM_ENCLOSURE", htmlentities($enclosure, ENT_QUOTES, 'utf-8'));
     $hasHeaderFlag = $hasHeader ? " CHECKED" : "";
     $this->ss->assign("HAS_HEADER_CHECKED", $hasHeaderFlag);
     if (!$importFile->fileExists()) {
         $this->_showImportError($mod_strings['LBL_CANNOT_OPEN'], $_REQUEST['import_module'], 'Step2', false, null, true);
         return;
     }
     //Check if we will exceed the maximum number of records allowed per import.
     $maxRecordsExceeded = FALSE;
     $maxRecordsWarningMessg = "";
     $lineCount = $importFile->getNumberOfLinesInfile();
     $maxLineCount = isset($sugar_config['import_max_records_total_limit']) ? $sugar_config['import_max_records_total_limit'] : 5000;
     if (!empty($maxLineCount) && $lineCount > $maxLineCount) {
         $maxRecordsExceeded = TRUE;
         $maxRecordsWarningMessg = string_format($mod_strings['LBL_IMPORT_ERROR_MAX_REC_LIMIT_REACHED'], array($lineCount, $maxLineCount));
     }
     //Retrieve a sample set of data
     $rows = $this->getSampleSet($importFile);
     $this->ss->assign('column_count', $this->getMaxColumnsInSampleSet($rows));
     $this->ss->assign('HAS_HEADER', $importFile->hasHeaderRow(FALSE));
     $this->ss->assign('getNumberJs', $locale->getNumberJs());
     $this->setImportFileCharacterSet($importFile, $importFileMap);
     $this->setDateTimeProperties($importFileMap);
     $this->setCurrencyOptions($importFileMap);
     $this->setNumberFormatOptions($importFileMap);
     $this->setNameFormatProperties($importFileMap);
     $importMappingJS = $this->getImportMappingJS();
     $this->ss->assign("SAMPLE_ROWS", $rows);
     $JS = $this->_getJS($maxRecordsExceeded, $maxRecordsWarningMessg, $importMappingJS, $importFileMap);
     $this->ss->assign("JAVASCRIPT", $JS);
     $content = $this->ss->fetch('modules/Import/tpls/confirm.tpl');
     $this->ss->assign("CONTENT", $content);
     $this->ss->display('modules/Import/tpls/wizardWrapper.tpl');
 }
コード例 #2
0
 /**
  * @dataProvider providerTimeFormatData
  */
 public function testTimeFormat($file, $format)
 {
     // create the test file
     $sample_file = $GLOBALS['sugar_config']['upload_dir'] . '/' . $file;
     copy('tests/modules/Import/' . $file, $sample_file);
     $this->unlink[] = $sample_file;
     $importFile = new ImportFile($sample_file, ",", '"', false, false);
     $this->assertTrue($importFile->fileExists());
     $ret = $importFile->autoDetectCSVProperties();
     $this->assertTrue($ret, 'Failed to auto detect properties.');
     $c = $importFile->getTimeFormat();
     $this->assertEquals($format, $c, 'incorrect time format.');
 }