$upload_maxsize) { show_error_import( $mod_strings['LBL_IMPORT_MODULE_ERROR_LARGE_FILE'] . " ". $upload_maxsize. " ". $mod_strings['LBL_IMPORT_MODULE_ERROR_LARGE_FILE_END']); exit; } if( !is_writable( $import_dir )) { show_error_import($mod_strings['LBL_IMPORT_MODULE_NO_DIRECTORY'].$import_dir.$mod_strings['LBL_IMPORT_MODULE_NO_DIRECTORY_END']); exit; } $tmp_file_name = $import_dir. "IMPORT_".$current_user->id; move_uploaded_file($_FILES['userfile']['tmp_name'], $tmp_file_name); // Convert ISO-8859 file (as saved by MS Excel) into UTF-8 to preserve umlauts and accents if ($_REQUEST["format"] != "UTF-8") { $fh = fopen($tmp_file_name,"r"); $content = fread($fh, filesize($tmp_file_name)); fclose($fh); if (function_exists("mb_convert_encoding")) { $content = mb_convert_encoding($content, 'UTF-8', $_REQUEST["format"]); } else { $content = iconv('UTF-8', $_REQUEST["format"], $content); } $fh = fopen($tmp_file_name,"w"); fwrite($fh, $content); fclose($fh); } // Now parse the file and look for errors $ret_value = 0; if ($_REQUEST['source'] == 'act') { $ret_value = parse_import_act($tmp_file_name,$delimiter,$max_lines,$has_header); } else { $ret_value = parse_import($tmp_file_name,$delimiter,$max_lines,$has_header); } if ($ret_value == -1) { show_error_import( $mod_strings['LBL_CANNOT_OPEN'] ); exit; } else if ($ret_value == -2) { show_error_import( $mod_strings['LBL_NOT_SAME_NUMBER'] ); exit; } else if ( $ret_value == -3 ) { show_error_import( $mod_strings['LBL_NO_LINES'] ); exit; } $rows = $ret_value['rows']; $ret_field_count = $ret_value['field_count']; $smarty = new vtigerCRM_Smarty; $smarty->assign("TMP_FILE", $tmp_file_name ); $smarty->assign("SOURCE", vtlib_purify($_REQUEST['source'])); $smarty->assign("MOD", $mod_strings); $smarty->assign("APP", $app_strings); if(isset($_REQUEST['return_module'])) $smarty->assign("RETURN_MODULE", vtlib_purify($_REQUEST['return_module'])); if(isset($_REQUEST['return_action'])) $smarty->assign("RETURN_ACTION", vtlib_purify($_REQUEST['return_action'])); $smarty->assign("THEME", $theme); $smarty->assign("IMAGE_PATH", $image_path); $smarty->assign("PRINT_URL", "phprint.php?jt=".session_id().$GLOBALS['request_string']); $smarty->assign("HEADER", $app_strings['LBL_IMPORT']." ". $mod_strings['LBL_MODULE_NAME']); $smarty->assign("HASHEADER", $has_header); $import_object_array = Array( "Leads"=>"ImportLead", "Accounts"=>"ImportAccount", "Contacts"=>"ImportContact", "Potentials"=>"ImportOpportunity", "Products"=>"ImportProduct", "HelpDesk"=>"ImportTicket", "Vendors"=>"ImportVendors" ); if(isset($_REQUEST['module']) && $_REQUEST['module'] != '') { $object_name = $import_object_array[$_REQUEST['module']]; // vtlib customization: Hook added to enable import for un-mapped modules $module = $_REQUEST['module']; if($object_name == null) { checkFileAccess("modules/$module/$module.php"); require_once("modules/$module/$module.php"); $object_name = $module; $callInitImport = true; } // END $focus = new $object_name(); // vtlib customization: Call the import initializer if($callInitImport) $focus->initImport($module); //initialized the required fields,used to check for mandatory fields while importing $focus->initRequiredFields($module); // END } else { $focus = new ImportContact(); } $total_num_rows=sizeof($rows); $firstrow = $rows[0]; if($total_num_rows >1 ) { $secondrow = $rows[1]; } if($total_num_rows >2) { $thirdrow = $rows[2]; } //If the cell value is very large then UI mapping will be collpased. So we will display partial text foreach($firstrow as $ind => $val) { if(strlen($val) > 30) $firstrow[$ind] = substr(to_html($val),0,30)." .........."; else $firstrow[$ind] = to_html($val); } if (isset($secondrow)) { //Asha: Fix for ticket #4432 foreach($secondrow as $ind => $val) { if(strlen($val) > 30) $secondrow[$ind] = substr(to_html($val),0,30)." .........."; else $secondrow[$ind] = to_html($val); } if (isset($thirdrow)) { //Asha: Fix for ticket #4432 foreach($thirdrow as $ind => $val) { if(strlen($val) > 30) $thirdrow[$ind] = substr(to_html($val),0,30)." .........."; else $thirdrow[$ind] = to_html($val); } } } $field_map = $outlook_contacts_field_map; $mapping_file = new ImportMap(); $saved_map_lists = $mapping_file->getSavedMappingsList($_REQUEST['return_module']); $map_list_combo = ''; //This link is Delete link for the selected mapping $map_list_combo .= "   "; $smarty->assign("SAVED_MAP_LISTS",$map_list_combo); if ( count($mapping_arr) > 0){ $field_map = &$mapping_arr; }else if ($_REQUEST['source'] == 'other'){ if ($_REQUEST['module'] == 'Contacts'){ $field_map = $outlook_contacts_field_map; }else if ($_REQUEST['module'] == 'Accounts'){ $field_map = $outlook_accounts_field_map; }else if ($_REQUEST['module'] == 'Potentials'){ $field_map = $salesforce_opportunities_field_map; } } $add_one = 1; $start_at = 0; if($has_header){ $add_one = 0; $start_at = 1; } for($row_count = $start_at; $row_count < count($rows); $row_count++){ $smarty->assign("ROWCOUNT", $row_count + $add_one); } $list_string_key = strtolower($_REQUEST['module']); $list_string_key .= "_import_fields"; //Now we are getting the import fields from DB instead of hard coded array $mod_list_strings $translated_column_fields = getImportFieldsList($_REQUEST['module']);//$mod_list_strings[$list_string_key]; $cnt=1; for($field_count = 0; $field_count < $ret_field_count; $field_count++){ $smarty->assign("COLCOUNT", $field_count + 1); $suggest = ""; if($_REQUEST['module']=='Accounts'){ $tablename='account'; $focus1=new Accounts(); } if($_REQUEST['module']=='Contacts'){ $tablename='contactdetails'; $focus1=new Contacts(); } if($_REQUEST['module']=='Leads'){ $tablename='leaddetails'; $focus1=new Leads(); } if($_REQUEST['module']=='Potentials'){ $tablename='potential'; $focus1=new Potentials(); } if($_REQUEST['module']=='Products'){ $tablename='products'; $focus1=new Products(); } if($_REQUEST['module']=='HelpDesk'){ $tablename='troubletickets'; $focus1=new HelpDesk(); } if($_REQUEST['module']=='Vendors'){ $tablename='Vendors'; $focus1=new Vendors(); } // vtlib customization: Hook to provide generic import for other modules if($_REQUEST['module']) { $focus1 = CRMEntity::getInstance($_REQUEST['module']); $tablename = $focus->table_name; } // END $smarty->assign("FIRSTROW",$firstrow); $smarty->assign("SECONDROW",$secondrow); $smarty->assign("THIRDROW",$thirdrow); $smarty_array[$field_count + 1] = getFieldSelect( $focus->importable_fields, $field_count, $focus->required_fields, $suggest, $translated_column_fields, $tablename ); $pos = 0; foreach($rows as $row ){ if( isset($row[$field_count]) && $row[$field_count] != ''){ $smarty->assign("CELL",htmlspecialchars($row[$field_count])); } $cnt++; } } @session_unregister('import_delimiter'); @session_unregister('import_has_header'); @session_unregister('import_firstrow'); @session_unregister('import_field_map'); @session_unregister('import_module_object_column_fields'); @session_unregister('import_module_field_count'); @session_unregister('import_module_object_required_fields'); @session_unregister('import_module_translated_column_fields'); $_SESSION['import_delimiter'] = $delimiter; $_SESSION['import_has_header'] = $has_header; $_SESSION['import_firstrow'] = $firstrow; $_SESSION['import_field_map'] = $field_map; $_SESSION['import_module_object_column_fields'] = $focus->importable_fields; $_SESSION['import_module_field_count'] = $field_count; $_SESSION['import_module_object_required_fields'] = $focus1->required_fields; $_SESSION['import_module_translated_column_fields'] = $translated_column_fields; $smarty->assign("SELECTFIELD",$smarty_array); $smarty->assign("ROW", $row); $module_key = "LBL_".strtoupper($_REQUEST['module'])."_NOTE_"; for ($i = 1;isset($mod_strings[$module_key.$i]);$i++){ $smarty->assign("NOTETEXT", $mod_strings[$module_key.$i]); } if($has_header){ $smarty->assign("HAS_HEADER", 'on'); }else{ $smarty->assign("HAS_HEADER", 'off'); } $smarty->assign("AVALABLE_FIELDS", getMergeFields($module,"available_fields")); $smarty->assign("FIELDS_TO_MERGE", getMergeFields($module,"fileds_to_merge")); if(isPermitted($module,'DuplicatesHandling','') == 'yes'){ $smarty->assign("DUPLICATESHANDLING", 'DuplicatesHandling'); } $smarty->assign("MODULE", vtlib_purify($_REQUEST['module'])); $smarty->assign("MODULELABEL", getTranslatedString($_REQUEST['module'],$_REQUEST['module'])); $parenttab = getParentTab(); $smarty->assign('CATEGORY' , $parenttab); $_SESSION['import_parenttab'] = $parenttab; $smarty->assign("JAVASCRIPT2", get_readonly_js() ); $smarty->display('ImportStep2.tpl'); ?>