📄 view.step3.php
字号:
<?phpif(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');/********************************************************************************* * SugarCRM is a customer relationship management program developed by * SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc. * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation with the addition of the following permission added * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program; if not, see http://www.gnu.org/licenses or write to the Free * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301 USA. * * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road, * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com. * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by * SugarCRM" logo. If the display of the logo is not reasonably feasible for * technical reasons, the Appropriate Legal Notices must display the words * "Powered by SugarCRM". ********************************************************************************//********************************************************************************* * Description: view handler for step 3 of the import process * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. ********************************************************************************/require_once('include/MVC/View/SugarView.php');require_once('modules/Import/ImportFile.php');require_once('modules/Import/ImportFileSplitter.php');require_once('modules/Import/ImportCacheFiles.php');require_once('modules/Import/ImportMap.php');require_once('modules/Import/ImportDuplicateCheck.php');require_once('modules/Import/UsersLastImport.php');require_once('include/upload_file.php'); class ImportViewStep3 extends SugarView { /** * Constructor */ public function __construct() { parent::SugarView(); } /** * display the form */ public function display() { global $mod_strings, $app_strings, $current_user, $sugar_config, $app_list_strings, $locale; $this->ss->assign("MOD", $mod_strings); $this->ss->assign("APP", $app_strings); $this->ss->assign("IMPORT_MODULE", $_REQUEST['import_module']); $has_header = ( isset( $_REQUEST['has_header']) ? 1 : 0 ); $sugar_config['import_max_records_per_file'] = ( empty($sugar_config['import_max_records_per_file']) ? 1000 : $sugar_config['import_max_records_per_file'] ); // load the bean for the import module $focus = loadImportBean($_REQUEST['import_module']); if ( !$focus ) { showImportError($mod_strings['LBL_ERROR_IMPORTS_NOT_SET_UP'],$_REQUEST['import_module']); return; } // Clear out this user's last import $seedUsersLastImport = new UsersLastImport(); $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_'.$focus->object_name.'_'.$current_user->id); $uploadFileName = $uploadFile->get_upload_path('IMPORT_'.$focus->object_name.'_'.$current_user->id); } else { showImportError($mod_strings['LBL_IMPORT_MODULE_ERROR_NO_UPLOAD'],$_REQUEST['import_module'],'Step2'); return; } // split file into parts $splitter = new ImportFileSplitter( $uploadFileName, $sugar_config['import_max_records_per_file']); $splitter->splitSourceFile( $_REQUEST['custom_delimiter'], html_entity_decode($_REQUEST['custom_enclosure'],ENT_QUOTES), $has_header ); // Now parse the file and look for errors $importFile = new ImportFile( $uploadFileName, $_REQUEST['custom_delimiter'], html_entity_decode($_REQUEST['custom_enclosure'],ENT_QUOTES) ); if ( !$importFile->fileExists() ) { showImportError($mod_strings['LBL_CANNOT_OPEN'],$_REQUEST['import_module'],'Step2'); return; } // retrieve first 3 rows $rows = array(); for ( $i = 0; $i < 3; $i++ ) { $rows[$i] = $importFile->getNextRow(); } $ret_field_count = $importFile->getFieldCount(); if ($rows[0] == false) { showImportError($mod_strings['LBL_NO_LINES'],$_REQUEST['import_module'],'Step2'); return; } // save first row to send to step 4 $this->ss->assign("FIRSTROW", base64_encode(serialize($rows[0]))); // Now build template $this->ss->assign("TMP_FILE", $uploadFileName ); $this->ss->assign("FILECOUNT", $splitter->getFileCount() ); $this->ss->assign("RECORDCOUNT", $splitter->getRecordCount() ); $this->ss->assign("RECORDTHRESHOLD", $sugar_config['import_max_records_per_file']); $this->ss->assign("SOURCE", $_REQUEST['source'] ); $this->ss->assign("TYPE", $_REQUEST['type'] ); $this->ss->assign("DELETE_INLINE_PNG", get_image($GLOBALS['image_path'].'basic_search','align="absmiddle" alt="'.$app_strings['LNK_DELETE'].'" border="0"')); $this->ss->assign("PUBLISH_INLINE_PNG", get_image($GLOBALS['image_path'].'advanced_search','align="absmiddle" alt="'.$mod_strings['LBL_PUBLISH'].'" border="0"')); $this->ss->assign("MODULE_TITLE", get_module_title( $mod_strings['LBL_MODULE_NAME'], $mod_strings['LBL_MODULE_NAME']." ".$mod_strings['LBL_STEP_3_TITLE'], false ) ); $this->ss->assign("STEP4_TITLE", strip_tags(str_replace("\n","",get_module_title( $mod_strings['LBL_MODULE_NAME'], $mod_strings['LBL_MODULE_NAME']." ".$mod_strings['LBL_STEP_4_TITLE'], false ))) ); $this->ss->assign("HEADER", $app_strings['LBL_IMPORT']." ". $mod_strings['LBL_MODULE_NAME']); $this->ss->assign("CUSTOM_DELIMITER", ( !empty($_REQUEST['custom_delimiter']) ? $_REQUEST['custom_delimiter'] : "," )); $this->ss->assign("CUSTOM_ENCLOSURE", ( !empty($_REQUEST['custom_enclosure']) ? $_REQUEST['custom_enclosure'] : "" )); // attempt to lookup a preexisting field map // use the custom one if specfied to do so in step 1 $field_map = array(); $default_values = array(); if ( !empty( $_REQUEST['source_id'])) { $mapping_file = new ImportMap(); $mapping_file->retrieve( $_REQUEST['source_id'],false); $_REQUEST['source'] = $mapping_file->source; $has_header = $mapping_file->has_header; if (isset($mapping_file->delimiter)) $this->ss->assign("CUSTOM_DELIMITER", $mapping_file->delimiter); if (isset($mapping_file->enclosure)) $this->ss->assign("CUSTOM_ENCLOSURE", htmlentities($mapping_file->enclosure)); $field_map = $mapping_file->getMapping(); $default_values = $mapping_file->getDefaultValues(); $this->ss->assign("MAPNAME",$mapping_file->name); $this->ss->assign("CHECKMAP",'checked="checked" value="on"'); } else { // Try to see if we have a custom mapping we can use // based upon the where the records are coming from // and what module we are importing into $classname = 'ImportMap' . ucfirst($_REQUEST['source']); require("modules/Import/{$classname}.php"); $mapping_file = new $classname; if (isset($mapping_file->delimiter)) $this->ss->assign("CUSTOM_DELIMITER", $mapping_file->delimiter); if (isset($mapping_file->enclosure)) $this->ss->assign("CUSTOM_ENCLOSURE", htmlentities($mapping_file->enclosure)); $field_map = $mapping_file->getMapping($_REQUEST['import_module']); } // we export it as email_address, but import as email1 $field_map['email_address'] = 'email1'; // build each row; row count is determined by the the number of fields in the import file $columns = array(); for($field_count = 0; $field_count < $ret_field_count; $field_count++) { // See if we have any field map matches $defaultValue = ""; // See if we can match the import row to a field in the list of fields to import $firstrow_name = str_replace(":","",$rows[0][$field_count]); if ($has_header && isset( $field_map[$firstrow_name] ) ) { $defaultValue = $field_map[$firstrow_name]; } elseif (isset($field_map[$field_count])) { $defaultValue = $field_map[$field_count]; } elseif (empty( $_REQUEST['source_id'])) { $defaultValue = $rows[0][$field_count]; } // build string of options $fields = $focus->get_importable_fields(); $options = ""; $defaultField = ''; foreach ( $fields as $fieldname => $properties ) { // get field name if (!empty ($properties['vname'])) $displayname = str_replace(":","",translate($properties['vname'] ,$focus->module_dir)); else $displayname = str_replace(":","",translate($properties['name'] ,$focus->module_dir)); // see if this is required $req_mark = ""; $req_class = ""; if ( array_key_exists($fieldname, $focus->get_import_required_fields()) ) { $req_mark = ' ' . $app_strings['LBL_REQUIRED_SYMBOL']; $req_class = ' class="required" ';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -