[Vtigercrm-commits] [vtiger-commits] r6984 - in /vtigercrm/trunk/modules/Import: ImportSave.php ImportStep1.php ImportStep2.php ImportStep3.php ImportSteplast.php

vtigercrm-commits at vtiger.fosslabs.com vtigercrm-commits at vtiger.fosslabs.com
Fri Jun 9 08:20:13 EDT 2006


Author: saraj
Date: Fri Jun  9 06:20:06 2006
New Revision: 6984

Log:
* Modified the steps where as in previous the php files start with step2 and ends with step4 but now it has been starts with step1 and ends with step3 properly

Modified:
    vtigercrm/trunk/modules/Import/ImportSave.php
    vtigercrm/trunk/modules/Import/ImportStep1.php
    vtigercrm/trunk/modules/Import/ImportStep2.php
    vtigercrm/trunk/modules/Import/ImportStep3.php
    vtigercrm/trunk/modules/Import/ImportSteplast.php

Modified: vtigercrm/trunk/modules/Import/ImportSave.php
==============================================================================
--- vtigercrm/trunk/modules/Import/ImportSave.php (original)
+++ vtigercrm/trunk/modules/Import/ImportSave.php Fri Jun  9 06:20:06 2006
@@ -205,7 +205,7 @@
 else
 {
 	$module = 'Import';
-	$action = 'ImportStep4';
+	$action = 'ImportStep3';
 }
 ?>
 

Modified: vtigercrm/trunk/modules/Import/ImportStep1.php
==============================================================================
--- vtigercrm/trunk/modules/Import/ImportStep1.php (original)
+++ vtigercrm/trunk/modules/Import/ImportStep1.php Fri Jun  9 06:20:06 2006
@@ -1,211 +1,90 @@
 <?php
 /*********************************************************************************
- * The contents of this file are subject to the SugarCRM Public License Version 1.1.2
- * ("License"); You may not use this file except in compliance with the 
- * License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL
- * Software distributed under the License is distributed on an  "AS IS"  basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
- * the specific language governing rights and limitations under the License.
- * The Original Code is:  SugarCRM Open Source
- * The Initial Developer of the Original Code is SugarCRM, Inc.
- * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.;
+** The contents of this file are subject to the vtiger CRM Public License Version 1.0
+ * ("License"); You may not use this file except in compliance with the License
+ * The Original Code is:  vtiger CRM Open Source
+ * The Initial Developer of the Original Code is vtiger.
+ * Portions created by vtiger are Copyright (C) vtiger.
  * All Rights Reserved.
- *Contributor(s): ______________________________________.
+ *
  ********************************************************************************/
-/*********************************************************************************
- * $Header$
- * Description:  TODO: To be written.
- * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
- * All Rights Reserved.
- * Contributor(s): ______________________________________..
- ********************************************************************************/
-require_once('XTemplate/xtpl.php');
-require_once('data/Tracker.php');
+
+require_once('Smarty_setup.php');
+require_once('modules/Import/ImportLead.php');
+require_once('modules/Import/ImportAccount.php');
 require_once('modules/Import/ImportContact.php');
-require_once('modules/Import/ImportAccount.php');
 require_once('modules/Import/ImportOpportunity.php');
-require_once('modules/Import/ImportLead.php');
-require_once('modules/Import/Forms.php');
+require_once('modules/Import/ImportProduct.php');
 require_once('modules/Import/ImportMap.php');
-require_once('modules/Import/ImportProduct.php');
+require_once('include/utils/CommonUtils.php');
 
 global $mod_strings;
+global $app_strings;
 global $app_list_strings;
-global $app_strings;
 global $current_user;
 
+global $import_mod_strings;
 
 $focus = 0;
 
 global $theme;
-$error_msg = '';
 $theme_path="themes/".$theme."/";
 $image_path=$theme_path."images/";
 require_once($theme_path.'layout_utils.php');
 
 $log->info($mod_strings['LBL_MODULE_NAME'] . " Upload Step 1");
 
-global $import_dir;
+$smarty = new vtigerCRM_Smarty;
 
-$tmp_file_name = $import_dir. "IMPORT_".$current_user->id;
+$smarty->assign("MOD", $mod_strings);
+$smarty->assign("APP", $app_strings);
+$smarty->assign("IMP", $import_mod_strings);
 
-if (file_exists($tmp_file_name))
+$category = getParenttab();
+$smarty->assign("CATEGORY", $category);
+
+$import_object_array = Array(
+				"Leads"=>"ImportLead",
+				"Accounts"=>"ImportAccount",
+				"Contacts"=>"ImportContact",
+				"Potentials"=>"ImportOpportunity",
+				"Products"=>"ImportProduct"
+			    );
+
+if(isset($_REQUEST['module']) && $_REQUEST['module'] != '')
 {
-	unlink($tmp_file_name);
-}
-
-
-
-if (isset($_REQUEST['delete_map_id']))
-{
-	$import_map = new ImportMap();
-	$import_map->mark_deleted($_REQUEST['delete_map_id']);
-}
-
-if (isset($_REQUEST['publish']) )
-{
-	$import_map = new ImportMap();
-	$result = 0;
-
-	$import_map = $import_map->retrieve($_REQUEST['import_map_id'], false);
-
-	if ($_REQUEST['publish'] == 'yes')
-	{
-		$result = $import_map->mark_published($current_user->id,"yes");
-		if ($result == -1)
-		{
-			$error_msg = "Unable to publish. There is another published Import Map by the same name.";
-		}
-	}
-	else if ( $_REQUEST['publish'] == 'no')
-	{
-	 	// if you don't own this importmap, you do now!
-		// unless you have a map by the same name
-		$result = $import_map->mark_published($current_user->id,"no");
-		if ($result == -1)
-		{
-			$error_msg = "Unable to un-publish a map owned by another user. You own an Import Map by the same name.";
-		}
-	}
-}
-
-$xtpl=new XTemplate ('modules/Import/ImportStep1.html');
-$xtpl->assign("MOD", $mod_strings);
-$xtpl->assign("APP", $app_strings);
-
-if ($error_msg != '')
-{
-	$xtpl->assign("ERROR", $error_msg);
-	$xtpl->parse("main.error");
-}
-
-if ( $_REQUEST['module'] == 'Contacts')
-{
-	$focus = new ImportContact();
-}
-else if ( $_REQUEST['module'] == 'Accounts')
-{
-	$focus = new ImportAccount();
-} 
-else if ( $_REQUEST['module'] == 'Potentials')
-{
-	$focus = new ImportOpportunity();
-} 
-else if ( $_REQUEST['module'] == 'Leads')
-{
-	$focus = new ImportLead();
-}
-else if ( $_REQUEST['module'] == 'Products')
-{
-	$focus = new ImportProduct();
+	$object_name = $import_object_array[$_REQUEST['module']];
+	$focus = new $object_name();
 }
 else
 {
- echo "Imports aren't set up for this module type\n";
- exit;
+	echo "Sorry! Import Option is not provided for this module.";
+	exit;
 }
 
-if (isset($_REQUEST['return_module'])) $xtpl->assign("RETURN_MODULE", $_REQUEST['return_module']);
+if(isset($_REQUEST['return_module'])) $smarty->assign("RETURN_MODULE", $_REQUEST['return_module']);
+if(isset($_REQUEST['return_action'])) $smarty->assign("RETURN_ACTION", $_REQUEST['return_action']);
 
-if (isset($_REQUEST['return_action'])) $xtpl->assign("RETURN_ACTION", $_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']);
 
-$xtpl->assign("THEME", $theme);
+$smarty->assign("HEADER", $app_strings['LBL_IMPORT']." ". $mod_strings['LBL_MODULE_NAME']);
+$smarty->assign("HAS_HEADER_CHECKED"," CHECKED");
 
-$xtpl->assign("IMAGE_PATH", $image_path);$xtpl->assign("PRINT_URL", "phprint.php?jt=".session_id().$GLOBALS['request_string']);
+$smarty->assign("MODULE", $_REQUEST['module']);
+$smarty->assign("SOURCE", $_REQUEST['source']);
 
-$xtpl->assign("HEADER", $app_strings['LBL_IMPORT']." ". $mod_strings['LBL_MODULE_NAME']);
+//we have set this as default. upto 4.2.3 we have Outlook, Act, SF formats. but now CUSTOM is enough to import
+$lang_key = "CUSTOM";
+$smarty->assign("INSTRUCTIONS_TITLE",$mod_strings["LBL_IMPORT_{$lang_key}_TITLE"]);
 
-$xtpl->assign("MODULE", $_REQUEST['module']);
-
-$xtpl->assign("JAVASCRIPT", get_validate_upload_js());
-
-if ( $_REQUEST['module'] == 'Contacts')
+for($i = 1; isset($mod_strings["LBL_{$lang_key}_NUM_$i"]);$i++)
 {
-$xtpl->parse("main.show_salesforce");
-$xtpl->parse("main.show_outlook");
-$xtpl->parse("main.show_act");
-}
-else if ( $_REQUEST['module'] == 'Accounts')
-{
-$xtpl->parse("main.show_salesforce");
-$xtpl->parse("main.show_act");
-} 
-else if ( $_REQUEST['module'] == 'Potentials')
-{
-$xtpl->parse("main.show_salesforce");
-} 
-
-if ( is_admin($current_user)) 
-{
-//	$xtpl->parse("main.create_global_map");
+	$smarty->assign("STEP_NUM",$mod_strings["LBL_NUM_$i"]);
+	$smarty->assign("INSTRUCTION_STEP",$mod_strings["LBL_{$lang_key}_NUM_$i"]);
 }
 
-$query_arr = array('assigned_user_id'=>$current_user->id,'is_published'=>'no','module'=>$_REQUEST['module']);
-
-$import_map_seed = new ImportMap();
-
-$custom_imports_arr = $import_map_seed->retrieve_all_by_string_fields($query_arr);
-
-if ( count($custom_imports_arr) )
-{
-	foreach ( $custom_imports_arr as $import)
-	{
-		$xtpl->assign("IMPORT_NAME", $import->name);
-		$xtpl->assign("IMPORT_ID", $import->id);
-		if ( is_admin($current_user)) 
-		{
-			$xtpl->parse("main.saved.saved_elem.is_admin");
-		}
-		$xtpl->parse("main.saved.saved_elem");
-	}
-
-	$xtpl->parse("main.saved");
-}
-
-
-$query_arr = array('is_published'=>'yes','module'=>$_REQUEST['module']);
-
-$published_imports_arr = $import_map_seed->retrieve_all_by_string_fields($query_arr);
-
-if ( count($published_imports_arr) )
-{
-	foreach ( $published_imports_arr as $import)
-	{
-		$xtpl->assign("IMPORT_NAME", $import->name);
-		$xtpl->assign("IMPORT_ID", $import->id);
-		if ( is_admin($current_user))
-		{	
-			$xtpl->parse("main.published.published_elem.is_admin");
-		}
-		$xtpl->parse("main.published.published_elem");
-	}
-
-	$xtpl->parse("main.published");
-}
-
-
-$xtpl->parse("main");
-
-$xtpl->out("main");
+$smarty->display("ImportStep1.tpl");
 
 ?>

Modified: vtigercrm/trunk/modules/Import/ImportStep2.php
==============================================================================
--- vtigercrm/trunk/modules/Import/ImportStep2.php (original)
+++ vtigercrm/trunk/modules/Import/ImportStep2.php Fri Jun  9 06:20:06 2006
@@ -10,7 +10,7 @@
  * The Initial Developer of the Original Code is SugarCRM, Inc.
  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.;
  * All Rights Reserved.
- *Contributor(s): ______________________________________.
+ * Contributor(s): ______________________________________.
  ********************************************************************************/
 /*********************************************************************************
  * $Header$
@@ -21,150 +21,397 @@
  ********************************************************************************/
 
 require_once('Smarty_setup.php');
-require_once('data/Tracker.php');
+require_once('modules/Import/ImportLead.php');
+require_once('modules/Import/ImportAccount.php');
 require_once('modules/Import/ImportContact.php');
-require_once('modules/Import/ImportAccount.php');
 require_once('modules/Import/ImportOpportunity.php');
-require_once('modules/Import/ImportLead.php');
+require_once('modules/Import/ImportProduct.php');
 require_once('modules/Import/Forms.php');
+require_once('modules/Import/parse_utils.php');
 require_once('modules/Import/ImportMap.php');
-require_once('modules/Import/ImportProduct.php');
+require_once('include/database/PearDatabase.php');
+require_once('include/CustomFieldUtil.php');
 require_once('include/utils/CommonUtils.php');
 
+ at session_unregister('column_position_to_field');
+ at session_unregister('totalrows');
+ at session_unregister('recordcount');
+ at session_unregister('startval');
+ at session_unregister('return_field_count');
+$_SESSION['totalrows'] = '';
+$_SESSION['recordcount'] = 500;
+$_SESSION['startval'] = 0;
+
 global $mod_strings;
+global $mod_list_strings;
+global $app_strings;
 global $app_list_strings;
-global $app_strings;
 global $current_user;
-
-global $import_mod_strings;
-
-
+global $import_file_name;
+global $upload_maxsize;
+
+global $import_dir;
 $focus = 0;
+$delimiter = ',';
+$max_lines = 3;
+
+$has_header = 0;
+
+if ( isset($_REQUEST['has_header']))
+{
+	$has_header = 1;
+}
 
 global $theme;
 $theme_path="themes/".$theme."/";
 $image_path=$theme_path."images/";
 require_once($theme_path.'layout_utils.php');
 
-$log->info($mod_strings['LBL_MODULE_NAME'] . " Upload Step 1");
-
-$smarty = new vtigerCRM_Smarty;
+if (!is_uploaded_file($_FILES['userfile']['tmp_name']) )
+{
+	show_error_import($mod_strings['LBL_IMPORT_MODULE_ERROR_NO_UPLOAD']);
+	exit;
+}
+else if ($_FILES['userfile']['size'] > $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);
+
+
+// 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", $_REQUEST['source'] );
 
 $smarty->assign("MOD", $mod_strings);
 $smarty->assign("APP", $app_strings);
-$smarty->assign("IMP", $import_mod_strings);
-
-$category = getParenttab();
-$smarty->assign("CATEGORY", $category);
-
-if ( $_REQUEST['module'] == 'Contacts')
-{
-	$focus = new ImportContact();
-}
-else if ( $_REQUEST['module'] == 'Accounts')
-{
-	$focus = new ImportAccount();
-} 
-else if ( $_REQUEST['module'] == 'Potentials')
-{
-	$focus = new ImportOpportunity();
-}
-else if ( $_REQUEST['module'] == 'Leads')
-{
-	$focus = new ImportLead();
-}
-else if ( $_REQUEST['module'] == 'Products')
-{
-	$focus = new ImportProduct();
-}
-
-else
-{
- echo "Imports aren't set up for this module type\n";
- exit;
-}
-
-if (isset($_REQUEST['return_module'])) $smarty->assign("RETURN_MODULE", $_REQUEST['return_module']);
-
-if (isset($_REQUEST['return_action'])) $smarty->assign("RETURN_ACTION", $_REQUEST['return_action']);
+
+if(isset($_REQUEST['return_module'])) $smarty->assign("RETURN_MODULE", $_REQUEST['return_module']);
+if(isset($_REQUEST['return_action'])) $smarty->assign("RETURN_ACTION", $_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"
+			    );
+
+if(isset($_REQUEST['module']) && $_REQUEST['module'] != '')
+{
+	$object_name = $import_object_array[$_REQUEST['module']];
+	$focus = new $object_name();
+}
+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];
+}
+
+	
+$field_map = $outlook_contacts_field_map;
+
+$mapping_file = new ImportMap();
+$saved_map_lists = $mapping_file->getSavedMappingsList($_REQUEST['return_module']);
+$map_list_combo = '<select name="source" id="saved_source" disabled onchange="getImportSavedMap(this)">';
+$map_list_combo .= '<OPTION value="-1" selected>--Select--</OPTION>';
+if(is_array($saved_map_lists))
+{
+	foreach($saved_map_lists as $mapid => $mapname)
+	{
+		$map_list_combo .= '<OPTION value='.$mapid.'>'.$mapname.'</OPTION>';
+	}
+}
+$map_list_combo .= '</select>';
+$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";
+
+$translated_column_fields = $mod_list_strings[$list_string_key];
+
+// adding custom fields translations
+getCustomFieldTrans($_REQUEST['module'],&$translated_column_fields);
+
+$cnt=1;
+for($field_count = 0; $field_count < $ret_field_count; $field_count++)
+{
+
+	$smarty->assign("COLCOUNT", $field_count + 1);
+	$suggest = "";
+
+	/*
+	if ($has_header && isset( $field_map[$firstrow[$field_count]] ) )
+	{
+		$suggest = $field_map[$firstrow[$field_count]];	
+	}
+	else if (isset($field_map[$field_count]))
+	{
+		$suggest = $field_map[$field_count];	
+	}
+	*/
+
+	if($_REQUEST['module']=='Accounts')
+	{
+		$tablename='account';
+		$focus1=new Account();
+	}
+	if($_REQUEST['module']=='Contacts')
+	{
+		$tablename='contactdetails';
+		$focus1=new Contact();
+ 	}
+	if($_REQUEST['module']=='Leads')
+ 	{
+		$tablename='leaddetails';
+		$focus1=new Lead();
+	}
+	if($_REQUEST['module']=='Potentials')
+ 	{
+		$tablename='potential';
+		$focus1=new Potential();
+	}
+	if($_REQUEST['module']=='Products')
+ 	{
+ 		$tablename='products';
+ 		$focus1=new Product();
+ 	}
+
+	
+	$smarty->assign("FIRSTROW",$firstrow);
+	$smarty->assign("SECONDROW",$secondrow);
+	$smarty->assign("THIRDROW",$thirdrow);
+	$smarty_array[$field_count + 1] = getFieldSelect(	$focus->importable_fields,
+							$field_count,
+							$focus1->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]));
+//			$smarty->parse("main.table.row.cell");
+		} 
+		else
+		{
+//			$smarty->parse("main.table.row.cellempty");
+		}
+
+		$cnt++;
+	}
+}
+ at session_unregister('import_has_header');
+ at session_unregister('import_firstrow');
+ at session_unregister('import_field_map');
+ at session_unregister('import_module_object_column_fields');
+ at session_unregister('import_module_field_count');
+ at session_unregister('import_module_object_required_fields');
+ at session_unregister('import_module_translated_column_fields');
+$_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;
+
+
+//echo '<pre>Default array ==> '; print_r($smarty_array); echo '</pre>';
+
+$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("MODULE", $_REQUEST['module']);
 
-// see if the source starts with 'custom' 
-// if so, pull off the id, load that map, and get the name
-if ($_REQUEST['source'] == "outlook")
-{
-	$smarty->assign("SOURCE", $_REQUEST['source']);
-	$smarty->assign("SOURCE_NAME","Outlook ");
-	$smarty->assign("HAS_HEADER_CHECKED"," CHECKED");
-} 
-else if ($_REQUEST['source'] == "act")
-{
-	$smarty->assign("SOURCE", $_REQUEST['source']);
-	$smarty->assign("SOURCE_NAME","ACT! ");
-	$smarty->assign("HAS_HEADER_CHECKED"," CHECKED");
-}
-else if ( strncasecmp("custom:",$_REQUEST['source'],7) == 0)
-{
-	$id = substr($_REQUEST['source'],7);
-	$import_map_seed = new ImportMap();
-
-	$import_map_seed->retrieve($id, false);
-
-	$adb->println($import_map_seed->toString());
-
-	$smarty->assign("SOURCE_ID", $import_map_seed->id);
-	$smarty->assign("SOURCE_NAME", $import_map_seed->name);
-	$smarty->assign("SOURCE", "custom");
-
-	if ($import_map_seed->has_header)
-	{
-		$smarty->assign("HAS_HEADER_CHECKED"," CHECKED");
-	}
-}
-else
-{
-	$smarty->assign("HAS_HEADER_CHECKED"," CHECKED");
-	$smarty->assign("SOURCE", $_REQUEST['source']);
-}
-
-$smarty->assign("JAVASCRIPT", get_validate_upload_js());
-
-$lang_key = '';
-
-if ($_REQUEST['source'] == "outlook")
-{
-	$lang_key = "OUTLOOK";
-}
-else if ($_REQUEST['source'] == "act")
-{
-	$lang_key = "ACT";
-}
-else if ($_REQUEST['source'] == "salesforce")
-{
-	$lang_key = "SF";
-}
-else 
-{
-	$lang_key = "CUSTOM";
-}
-
-$smarty->assign("INSTRUCTIONS_TITLE",$mod_strings["LBL_IMPORT_{$lang_key}_TITLE"]);
-
-for ($i = 1; isset($mod_strings["LBL_{$lang_key}_NUM_$i"]);$i++)
-{
-$smarty->assign("STEP_NUM",$mod_strings["LBL_NUM_$i"]);
-$smarty->assign("INSTRUCTION_STEP",$mod_strings["LBL_{$lang_key}_NUM_$i"]);
-
-}
-
-$smarty->display("ImportStep1.tpl");
+$category = getParenttab();
+$smarty->assign('CATEGORY' , $category);
+
+$smarty->assign("JAVASCRIPT2", get_readonly_js() );
+
+$smarty->display('ImportStep2.tpl');
 
 ?>
+<script language="javascript" type="text/javascript">
+function validate_import_map()
+{
+	var tagName;
+	var count = 0;
+	var field_count = "<?php echo $field_count; ?>";
+	var required_fields = new Array();
+	var required_fields_name = new Array();
+	var seq_string = '';
+
+	<?php 
+		foreach($focus->required_fields as $name => $index)
+		{
+			?>
+			required_fields[count] = "<?php echo $name; ?>";
+			required_fields_name[count] = "<?php echo $translated_column_fields[$name]; ?>";
+			count = count + 1;
+			<?php 
+		} 
+	?>		
+	for(loop_count = 0; loop_count<field_count;loop_count++)
+	{
+		tagName = document.getElementById('colnum'+loop_count);
+		optionData = tagName.options[tagName.selectedIndex].value;
+
+		if(optionData != -1)
+		{
+			tmp = seq_string.indexOf(optionData);
+			if(tmp == -1)
+			{
+				seq_string = seq_string + optionData;
+			}
+			else
+			{
+				//if a field mapped more than once, alert the user and return
+				alert("'"+tagName.options[tagName.selectedIndex].text+"' is mapped more than once. Please check the mapping.");
+				return false;
+			}
+		}
+
+	}
+
+	//check whether the mandatory fields have been mapped.
+	for(inner_loop = 0; inner_loop<required_fields.length;inner_loop++)
+	{
+		if(seq_string.indexOf(required_fields[inner_loop]) == -1)
+		{
+			alert('Please map the mandatory field "'+required_fields_name[inner_loop]+'"');
+			return false;
+		}
+	}
+
+	//This is to check whether the save map name has been given or not when save map check box is checked
+	if(document.getElementById("save_map").checked == true)
+	{
+		if(trim(document.getElementById("save_map_as").value) == '')
+		{
+			alert("Please Enter Save Map Name");
+			return false;
+		}
+	}
+
+	return true;
+}
+</script>

Modified: vtigercrm/trunk/modules/Import/ImportStep3.php
==============================================================================
--- vtigercrm/trunk/modules/Import/ImportStep3.php (original)
+++ vtigercrm/trunk/modules/Import/ImportStep3.php Fri Jun  9 06:20:06 2006
@@ -21,487 +21,338 @@
  ********************************************************************************/
 
 require_once('Smarty_setup.php');
-require_once('data/Tracker.php');
+require_once('modules/Import/ImportLead.php');
+require_once('modules/Import/ImportAccount.php');
 require_once('modules/Import/ImportContact.php');
-require_once('modules/Import/ImportAccount.php');
 require_once('modules/Import/ImportOpportunity.php');
-require_once('modules/Import/ImportLead.php');
-require_once('modules/Import/Forms.php');
+require_once('modules/Import/ImportProduct.php');
+require_once('modules/Import/ImportMap.php');
+require_once('modules/Import/UsersLastImport.php');
 require_once('modules/Import/parse_utils.php');
-require_once('modules/Import/ImportMap.php');
+require_once('include/ListView/ListView.php');
 require_once('include/database/PearDatabase.php');
-require_once('include/CustomFieldUtil.php');
-require_once('modules/Import/ImportProduct.php');
-require_once('include/utils/CommonUtils.php');
-
- at session_unregister('column_position_to_field');
- at session_unregister('totalrows');
- at session_unregister('recordcount');
- at session_unregister('startval');
- at session_unregister('return_field_count');
-$_SESSION['totalrows'] = '';
-$_SESSION['recordcount'] = 500;
-$_SESSION['startval'] = 0;
+require_once('modules/Import/ImportSave.php');
+
+set_time_limit(0);
+ini_set("display_errors",'0');
+
+
+function p($str)
+{
+	global $adb;
+	$adb->println("IMP :".$str);
+}
+
+function implode_assoc($inner_delim, $outer_delim, $array) 
+{
+	$output = array();
+
+	foreach( $array as $key => $item )
+	{
+               $output[] = $key . $inner_delim . $item;
+	}
+
+       return implode($outer_delim, $output);
+}
 
 global $mod_strings;
-global $mod_list_strings;
 global $app_list_strings;
 global $app_strings;
 global $current_user;
 global $import_file_name;
+global $theme;
 global $upload_maxsize;
-
-global $theme;
-global $outlook_contacts_field_map;
-global $act_contacts_field_map;
-global $salesforce_contacts_field_map;
-global $outlook_accounts_field_map;
-global $act_accounts_field_map;
-global $salesforce_accounts_field_map;
-global $salesforce_opportunities_field_map;
-global $import_dir;
-$focus = 0;
-$delimiter = ',';
-$max_lines = 3;
-
-$has_header = 0;
-
-if ( isset($_REQUEST['has_header']))
-{
-	$has_header = 1;
-}
+global $site_URL;
 
 $theme_path="themes/".$theme."/";
 $image_path=$theme_path."images/";
 require_once($theme_path.'layout_utils.php');
 
-if (!is_uploaded_file($_FILES['userfile']['tmp_name']) )
-{
-	show_error_import($mod_strings['LBL_IMPORT_MODULE_ERROR_NO_UPLOAD']);
-	exit;
-}
-else if ($_FILES['userfile']['size'] > $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);
-
+$log->info("Upload Step 3");
+
+
+$delimiter = ',';
+// file handle
+$count = 0;
+$error = "";
+$col_pos_to_field = array();
+$header_to_field = array();
+$field_to_pos = array();
+$focus = 0;
+$current_bean_type = "";
+$id_exists_count = 0;
+$broken_ids = 0;
+
+$has_header = 0;
+
+if ( isset( $_REQUEST['has_header']) && $_REQUEST['has_header'] == 'on')
+{
+	$has_header = 1;
+}
+if($_REQUEST['modulename'] != '')
+	$_REQUEST['module'] = $_REQUEST['modulename'];
+
+
+$import_object_array = Array(
+				"Leads"=>"ImportLead",
+				"Accounts"=>"ImportAccount",
+				"Contacts"=>"ImportContact",
+				"Potentials"=>"ImportOpportunity",
+				"Products"=>"ImportProduct"
+			    );
+
+if(isset($_REQUEST['module']) && $_REQUEST['module'] != '')
+{
+	$current_bean_type = $import_object_array[$_REQUEST['module']];
+}
+else
+{
+	$current_bean_type = "ImportContact";
+}
+
+$focus = new $current_bean_type();
+
+//Constructing the custom field Array
+require_once('include/CustomFieldUtil.php');
+$custFldArray = getCustomFieldArray($_REQUEST['module']);
+p("IMP 3: custFldArray");
+p($custFldArray);
+
+//Initializing  an empty Array to store the custom field Column Name and Value
+$resCustFldArray = Array();
+
+p("Getting from request");
+// loop through all request variables
+foreach ($_REQUEST as $name=>$value)
+{
+	p("name=".$name." value=".$value);
+	// only look for var names that start with "colnum"
+	if ( strncasecmp( $name, "colnum", 6) != 0 )
+	{	
+		continue;
+	}
+	if ($value == "-1")
+	{
+		
+		continue;
+	}
+
+	// this value is a user defined field name
+	$user_field = $value;
+
+	// pull out the column position for this field name
+	$pos = substr($name,6);
+
+	// make sure we haven't seen this field defined yet
+	if ( isset( $field_to_pos[$user_field]) )
+	{
+		show_error_import($mod_strings['LBL_ERROR_MULTIPLE']);
+	        exit;
+
+	}
+
+	p("user_field=".$user_field." if=".$focus->importable_fields[$user_field]);
+	
+	// match up the "official" field to the user 
+	// defined one, and map to columm position: 
+	if ( isset( $focus->importable_fields[$user_field] ) || isset( $custFldArray[$user_field] ))
+	{
+		p("user_field SET=".$user_field);
+		// now mark that we've seen this field
+		$field_to_pos[$user_field] = $pos;
+		$col_pos_to_field[$pos] = $user_field;
+	}
+}
+
+p("field_to_pos");
+$adb->println($field_to_pos);
+p("col_pos_to_field");
+$adb->println($col_pos_to_field);
 
 // Now parse the file and look for errors
+$max_lines = -1;
+
 $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_value = parse_import_act($_REQUEST['tmp_file'],$delimiter,$max_lines,$has_header);
+}
+else
+{
+	$ret_value = parse_import($_REQUEST['tmp_file'],$delimiter,$max_lines,$has_header);
+}
+
+if (file_exists($_REQUEST['tmp_file']))
+{
+	unlink($_REQUEST['tmp_file']);
+}
+
+$datarows = $ret_value['rows'];
+
 $ret_field_count = $ret_value['field_count'];
 
-$smarty =  new vtigerCRM_Smarty;
-
-$smarty->assign("TMP_FILE", $tmp_file_name );
-
-$smarty->assign("SOURCE", $_REQUEST['source'] );
-
-$source_to_name = array( 
-			'outlook'=>$mod_strings['LBL_MICROSOFT_OUTLOOK'],
-			'act'=>$mod_strings['LBL_ACT'],
-			'salesforce'=>$mod_strings['LBL_SALESFORCE'],
-			'custom'=>$mod_strings['LBL_CUSTOM'],
-			'other'=>$mod_strings['LBL_CUSTOM'],
-		      );
-
-$smarty->assign("SOURCE_NAME", $source_to_name[$_REQUEST['source']] );
-$smarty->assign("MOD", $mod_strings);
-$smarty->assign("APP", $app_strings);
-
-if (isset($_REQUEST['return_module'])) $smarty->assign("RETURN_MODULE", $_REQUEST['return_module']);
-if (isset($_REQUEST['return_action'])) $smarty->assign("RETURN_ACTION", $_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);
-
-
-if (! isset( $_REQUEST['module'] ) || $_REQUEST['module'] == 'Contacts')
-{
-	$focus = new ImportContact();
-}
-else if ( $_REQUEST['module'] == 'Accounts')
-{
-	$focus = new ImportAccount();
-}
-else if ( $_REQUEST['module'] == 'Potentials')
-{
-	$focus = new ImportOpportunity();
-}
-else if ( $_REQUEST['module'] == 'Leads')
-{
-	$focus = new ImportLead();
-}
-else if ( $_REQUEST['module'] == 'Products')
-{
-	$focus = new ImportProduct();
-}
-
-
-
-$total_num_rows=sizeof($rows);	
-$firstrow = $rows[0];
-if($total_num_rows >1 )
-{
-	$secondrow = $rows[1];
-}		
-if($total_num_rows >2)
-{
-	$thirdrow = $rows[2];
-}
-
-	
-$field_map = $outlook_contacts_field_map;
-
-/*if ( isset( $_REQUEST['source_id']))
-{
-	$mapping_file = new ImportMap();
-
-	//$mapping_file->retrieve_entity_info( $_REQUEST['source_id'],$_REQUEST['return_module']);
-	$mapping_file->retrieve( $_REQUEST['source_id'],false);
-	$adb->println("richie : ".$mapping_file->toString());
-
-	$mapping_content = $mapping_file->content;
-
-	$mapping_arr = array();
-
-	if ( isset($mapping_content) && $mapping_content != "")
-	{
-		$pairs = split("&",$mapping_content);
-	
-		foreach ($pairs as $pair)
+$saved_ids = array();
+
+$firstrow = 0;
+
+if (! isset($datarows))
+{
+	$error = $mod_strings['LBL_FILE_ALREADY_BEEN_OR'];
+	$datarows = array();
+}
+
+if ($has_header == 1)
+{
+	$firstrow = array_shift($datarows);
+}
+
+//Mark the last imported records as deleted which are imported by the current user in users_last_import table
+if(!isset($_REQUEST['startval']))
+{
+	$seedUsersLastImport = new UsersLastImport();
+	$seedUsersLastImport->mark_deleted_by_user_id($current_user->id);
+}
+$skip_required_count = 0;
+
+p("processing started ret_field_count=".$ret_field_count);
+$adb->println($datarows);
+
+$error = '';
+$focus = new $current_bean_type();
+
+
+// SAVE MAPPING IF REQUESTED
+if(isset($_REQUEST['save_map']) && $_REQUEST['save_map'] == 'on' && isset($_REQUEST['save_map_as']) && $_REQUEST['save_map_as'] != '')
+{
+	p("save map");
+	$serialized_mapping = '';
+
+	if( $has_header)
+	{
+		foreach($col_pos_to_field as $pos=>$field_name)
 		{
-			list($name,$value) = split("=",$pair);
-			$mapping_arr["$name"] = $value;
-		}
-	}
-}
-*/
-	$mapping_file = new ImportMap();
-	$saved_map_lists = $mapping_file->getSavedMappingsList($_REQUEST['return_module']);
-	$map_list_combo = '<select name="source" id="saved_source" disabled onchange="getImportSavedMap(this)">';
-	$map_list_combo .= '<OPTION value="-1" selected>--Select--</OPTION>';
-	if(is_array($saved_map_lists))
-	{
-		foreach($saved_map_lists as $mapid => $mapname)
-		{
-			$map_list_combo .= '<OPTION value='.$mapid.'>'.$mapname.'</OPTION>';
-		}
-	}
-	$map_list_combo .= '</select>';
-	$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;
-	}
-} 
-else if ($_REQUEST['source'] == 'act')
-{
-	if ($_REQUEST['module'] == 'Contacts')
-	{
-		$field_map = $act_contacts_field_map;
-	} 
-	else if ($_REQUEST['module'] == 'Accounts')
-	{
-		$field_map = $act_accounts_field_map;
-	}
-}
-else if ($_REQUEST['source'] == 'salesforce')
-{
-	if ($_REQUEST['module'] == 'Contacts')
-	{
-		$field_map = $salesforce_contacts_field_map;
-	} 
-	else if ($_REQUEST['module'] == 'Accounts')
-	{
-		$field_map = $salesforce_accounts_field_map;
-	}
-	else if ($_REQUEST['module'] == 'Potentials')
-	{
-		$field_map = $salesforce_opportunities_field_map;
-	}
-}
-else if ($_REQUEST['source'] == 'outlook')
-{
-	$smarty->assign("IMPORT_FIRST_CHECKED", " CHECKED");
-	if ($_REQUEST['module'] == 'Contacts')
-	{
-		$field_map = $outlook_contacts_field_map;
-	} 
-	else if ($_REQUEST['module'] == 'Accounts')
-	{
-		$field_map = $outlook_accounts_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";
-
-$translated_column_fields = $mod_list_strings[$list_string_key];
-
-// adding custom fields translations
-getCustomFieldTrans($_REQUEST['module'],&$translated_column_fields);
-
-$cnt=1;
-for($field_count = 0; $field_count < $ret_field_count; $field_count++)
-{
-
-	$smarty->assign("COLCOUNT", $field_count + 1);
-	$suggest = "";
-
-	/*
-	if ($has_header && isset( $field_map[$firstrow[$field_count]] ) )
-	{
-		$suggest = $field_map[$firstrow[$field_count]];	
-	}
-	else if (isset($field_map[$field_count]))
-	{
-		$suggest = $field_map[$field_count];	
-	}
-	*/
-
-	if($_REQUEST['module']=='Accounts')
-	{
-		$tablename='account';
-		$focus1=new Account();
-	}
-	if($_REQUEST['module']=='Contacts')
-	{
-		$tablename='contactdetails';
-		$focus1=new Contact();
- 	}
-	if($_REQUEST['module']=='Leads')
- 	{
-		$tablename='leaddetails';
-		$focus1=new Lead();
-	}
-	if($_REQUEST['module']=='Potentials')
- 	{
-		$tablename='potential';
-		$focus1=new Potential();
-	}
-	if($_REQUEST['module']=='Products')
- 	{
- 		$tablename='products';
- 		$focus1=new Product();
- 	}
-
-	
-	$smarty->assign("FIRSTROW",$firstrow);
-	$smarty->assign("SECONDROW",$secondrow);
-	$smarty->assign("THIRDROW",$thirdrow);
-	$smarty_array[$field_count + 1] = getFieldSelect(	$focus->importable_fields,
-							$field_count,
-							$focus1->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]));
-//			$smarty->parse("main.table.row.cell");
-		} 
-		else
-		{
-//			$smarty->parse("main.table.row.cellempty");
-		}
-
-		$cnt++;
-	}
-}
- at session_unregister('import_has_header');
- at session_unregister('import_firstrow');
- at session_unregister('import_field_map');
- at session_unregister('import_module_object_column_fields');
- at session_unregister('import_module_field_count');
- at session_unregister('import_module_object_required_fields');
- at session_unregister('import_module_translated_column_fields');
-$_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;
-
-
-//echo '<pre>Default array ==> '; print_r($smarty_array); echo '</pre>';
-
-$smarty->assign("SELECTFIELD",$smarty_array);
-$smarty->assign("ROW", $row);
-//$xtpl->parse("main.table");
-
-$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]);
-	//$xtpl->parse("main.note");
-}
-
-
-if($has_header)
-{
-	$smarty->assign("HAS_HEADER", 'on');
-} 
-else
-{
-	$smarty->assign("HAS_HEADER", 'off');
-}
-
-
-$smarty->assign("MODULE", $_REQUEST['module']);
-
-$category = getParenttab();
-$smarty->assign('CATEGORY' , $category);
-
-$smarty->assign("JAVASCRIPT2", get_readonly_js() );
-
-$smarty->display('ImportStep2.tpl');
-
-?>
-<script language="javascript" type="text/javascript">
-function validate_import_map()
-{
-	var tagName;
-	var count = 0;
-	var field_count = "<?php echo $field_count; ?>";
-	var required_fields = new Array();
-	var required_fields_name = new Array();
-	var seq_string = '';
-
-	<?php 
-		foreach($focus->required_fields as $name => $index)
-		{
-			?>
-			required_fields[count] = "<?php echo $name; ?>";
-			required_fields_name[count] = "<?php echo $translated_column_fields[$name]; ?>";
-			count = count + 1;
-			<?php 
-		} 
-	?>		
-	for(loop_count = 0; loop_count<field_count;loop_count++)
-	{
-		tagName = document.getElementById('colnum'+loop_count);
-		optionData = tagName.options[tagName.selectedIndex].value;
-
-		if(optionData != -1)
-		{
-			tmp = seq_string.indexOf(optionData);
-			if(tmp == -1)
+			if ( isset($firstrow[$pos]) &&  isset( $field_name))
 			{
-				seq_string = seq_string + optionData;
-			}
-			else
-			{
-				//if a field mapped more than once, alert the user and return
-				alert("'"+tagName.options[tagName.selectedIndex].text+"' is mapped more than once. Please check the mapping.");
-				return false;
+				$header_to_field[ $firstrow[$pos] ] = $field_name;
 			}
 		}
 
-	}
-
-	//check whether the mandatory fields have been mapped.
-	for(inner_loop = 0; inner_loop<required_fields.length;inner_loop++)
-	{
-		if(seq_string.indexOf(required_fields[inner_loop]) == -1)
-		{
-			alert('Please map the mandatory field "'+required_fields_name[inner_loop]+'"');
-			return false;
-		}
-	}
-
-	//This is to check whether the save map name has been given or not when save map check box is checked
-	if(document.getElementById("save_map").checked == true)
-	{
-		if(trim(document.getElementById("save_map_as").value) == '')
-		{
-			alert("Please Enter Save Map Name");
-			return false;
-		}
-	}
-
-	return true;
-}
-</script>
+		$serialized_mapping = implode_assoc("=","&",$header_to_field);
+	}
+	else
+	{
+		$serialized_mapping = implode_assoc("=","&",$col_pos_to_field);
+	}
+
+	$mapping_file_name = $_REQUEST['save_map_as'];
+
+	$mapping_file = new ImportMap();
+
+	//$query_arr = array('assigned_user_id'=>$current_user->id,'name'=>$mapping_file_name);
+	//$mapping_file->retrieve_by_string_fields($query_arr, false);
+
+	$result = $mapping_file->save_map( $current_user->id,
+					$mapping_file_name,
+					$_REQUEST['module'],
+					$has_header,
+					$serialized_mapping );
+
+	$adb->println("Save map done");
+	$adb->println($result);
+}
+//save map - ends
+
+
+
+
+if(isset($_SESSION['totalrows']) && $_SESSION['totalrows'] != '')
+{
+	$xrows = $_SESSION['totalrows'];
+}
+else
+{
+	$xrows = $datarows;
+}
+if(isset($_SESSION['return_field_count']))
+{
+	$ret_field_count = $_SESSION['return_field_count'];
+}
+if(isset($_SESSION['column_position_to_field']))
+{
+	$col_pos_to_field = $_SESSION['column_position_to_field'];
+}
+if($xrows != '')
+{
+	$datarows = $xrows;
+}
+if($_REQUEST['skipped_record_count'] != '')
+	$skipped_record_count = $_REQUEST['skipped_record_count'];
+else
+	$_REQUEST['skipped_record_count'] = 0;
+
+if($_REQUEST['noofrows'] != '')
+	$totalnoofrows = $_REQUEST['noofrows'];
+else
+	$totalnoofrows = count($datarows);
+
+$loopcount = ($totalnoofrows/$RECORDCOUNT)+1;
+
+if($_REQUEST['startval'] != '')
+	$START = $_REQUEST['startval'];
+else
+	$START = $_SESSION['startval'];
+if($_REQUEST['recordcount'] != '')
+	$RECORDCOUNT = $_REQUEST['recordcount'];
+else
+	$RECORDCOUNT = $_SESSION['recordcount'];
+
+if(($START+$RECORDCOUNT) > $totalnoofrows)
+{
+	$RECORDCOUNT = $totalnoofrows - $START;
+}
+
+if($totalnoofrows > $RECORDCOUNT && $START < $totalnoofrows)
+{
+	$rows1 = Array();
+	for($j=$START;$j<$START+$RECORDCOUNT;$j++)
+	{
+		$rows1[] = $datarows[$j];
+	}
+
+	$res = InsertImportRecords($datarows,$rows1,$focus,$ret_field_count,$col_pos_to_field,$START,$RECORDCOUNT,$_REQUEST['module'],$totalnoofrows,$skipped_record_count);
+
+	if($START != 0)
+		echo '<b>'.$res.'</b>';
+
+	$count = $_REQUEST['count'];
+}
+else
+{
+	if($START == 0)
+	{
+		$res = InsertImportRecords($datarows,$datarows,$focus,$ret_field_count,$col_pos_to_field,$START,$totalnoofrows,$_REQUEST['module'],$totalnoofrows,$skipped_record_count);
+	}
+//	exit;
+}
+
+
+
+
+
+
+if ($error != "")
+{
+	show_error_import( $mod_strings['LBL_ERROR']." ". $error);
+	exit;
+}
+else 
+{
+	$message= urlencode($mod_strings['LBL_SUCCESS']."<BR>$count ". $mod_strings['LBL_MODULE_NAME']." ".$mod_strings['LBL_SUCCESSFULLY']."<br>".($broken_ids+$id_exists_count) ." ". $mod_strings['LBL_IDS_EXISTED_OR_LONGER']. "<br>$skip_required_count " .  $mod_strings['LBL_RECORDS_SKIPPED'] );
+
+	header("Location: index.php?module={$_REQUEST['module']}&action=Import&step=last&return_module={$_REQUEST['return_module']}&return_action={$_REQUEST['return_action']}&message=$message");
+exit;
+}
+
+
+?>

Modified: vtigercrm/trunk/modules/Import/ImportSteplast.php
==============================================================================
--- vtigercrm/trunk/modules/Import/ImportSteplast.php (original)
+++ vtigercrm/trunk/modules/Import/ImportSteplast.php Fri Jun  9 06:20:06 2006
@@ -57,7 +57,7 @@
 $image_path=$theme_path."images/";
 require_once($theme_path.'layout_utils.php');
 
-$log->info("Upload Step 2");
+$log->info("Import Step last");
 
 if ( isset($_REQUEST['message']))
 {
@@ -83,7 +83,7 @@
 				   <form enctype="multipart/form-data" name="Import" method="POST" action="index.php">
 					<input type="hidden" name="module" value="<?php echo $_REQUEST['modulename']; ?>">
 					<input type="hidden" name="action" value="Import">
-					<input type="hidden" name="step" value="2">
+					<input type="hidden" name="step" value="1">
 					<input type="hidden" name="return_id" value="<?php echo $_REQUEST['return_id']; ?>">
 					<input type="hidden" name="return_module" value="<?php echo $_REQUEST['return_module']; ?>">
 					<input type="hidden" name="return_action" value="<?php echo (($_REQUEST['return_action'] != '')?$_REQUEST['return_action']:'index'); ?>">
@@ -131,10 +131,10 @@
 $implict_account = false;
 
 $import_modules_array = Array(
+				"Leads"=>"Lead",
+				"Accounts"=>"Account",
 				"Contacts"=>"Contact",
 				"Potentials"=>"Potential",
-				"Leads"=>"Lead",
-				"Accounts"=>"Account",
 				"Products"=>"Product" 
 			     );
 
@@ -153,7 +153,7 @@
 	//Retreiving the no of rows
 	$noofrows = $adb->num_rows($list_result);
 
-	if($noofrows>1) 
+	if($noofrows>=1) 
 	{
 		if($module_name != 'Accounts')
 		{





More information about the vtigercrm-commits mailing list