>From 1d6581de68774165779106c9756f5d7963a57e3a Mon Sep 17 00:00:00 2001
From: Christian Fast <ChristianFast@Solvate.at>
Date: Wed, 19 Oct 2011 11:13:42 +0200
Subject: [PATCH 2/2] - Call-by-reference of var "importid" in function
 "import_insert" of class "ImportCsv" - No printout of
 importid if column "import_key" don't exists in table
 (it's a workaround until this column exists in all
 importable tables) - Two new rules for
 array_import_convertvalue (fetchfromtable,
 fetchfromclass) - Additional imports schemes for
 product and customer - New option to delete all unused
 products in the purge page - Additional tables in
 elements in function "delete" of class Product

Change-Id: I83fd4d299c63831c7c5d3f56f36fcd9bf5cd0472
Signed-off-by: Christian Fast <ChristianFast@Solvate.at>
---
 dev/translation/langAutoParser.class.php           |    5 +-
 htdocs/admin/tools/purge.php                       |  124 +++++++++++++-------
 htdocs/compta/clients.php                          |    1 +
 htdocs/imports/import.php                          |   12 +-
 .../includes/modules/import/import_csv.modules.php |  112 +++++++++++++++---
 htdocs/includes/modules/modProduct.class.php       |   42 ++++++-
 htdocs/includes/modules/modSociete.class.php       |   35 ++++--
 htdocs/langs/de_AT/admin.lang                      |    7 +-
 htdocs/langs/de_AT/companies.lang                  |    2 +
 htdocs/langs/es_ES/externalsite.lang               |   13 ++
 htdocs/langs/fr_FR/admin.lang                      |    7 +-
 htdocs/langs/fr_FR/companies.lang                  |    1 +
 htdocs/product/class/product.class.php             |    3 +-
 13 files changed, 281 insertions(+), 83 deletions(-)
 mode change 100755 => 100644 htdocs/langs/de_AT/admin.lang
 mode change 100755 => 100644 htdocs/langs/de_AT/companies.lang
 create mode 100644 htdocs/langs/es_ES/externalsite.lang

diff --git a/dev/translation/langAutoParser.class.php b/dev/translation/langAutoParser.class.php
index 1a40b2f..142f9fd 100644
--- a/dev/translation/langAutoParser.class.php
+++ b/dev/translation/langAutoParser.class.php
@@ -236,13 +236,12 @@ class langAutoParser {
 
 		$src_texts_query .= "&q=".urlencode($src_text_to_translate);
 
-		$url =
-"http://ajax.googleapis.com/ajax/services/language/translate?v=1.0".$src_texts_query."&langpair=".urlencode($lang_pair);
+		$url = "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0".$src_texts_query."&langpair=".urlencode($lang_pair);
 
 		// sendRequest
 		// note how referer is set manually
 
-		//print "Url to translate: ".$url."\n";
+		print "Url to translate: ".$url."\n";
 
 		if (! function_exists("curl_init"))
 		{
diff --git a/htdocs/admin/tools/purge.php b/htdocs/admin/tools/purge.php
index 414bbbc..5556e61 100644
--- a/htdocs/admin/tools/purge.php
+++ b/htdocs/admin/tools/purge.php
@@ -24,6 +24,7 @@
 require("../../main.inc.php");
 include_once(DOL_DOCUMENT_ROOT."/lib/databases/".$conf->db->type.".lib.php");
 include_once(DOL_DOCUMENT_ROOT.'/lib/files.lib.php');
+require_once(DOL_DOCUMENT_ROOT.'/product/class/product.class.php');
 
 $langs->load("admin");
 
@@ -46,63 +47,92 @@ if ($conf->syslog->enabled)
  */
 if ($_REQUEST["action"]=='purge' && ! preg_match('/^confirm/i',$_REQUEST["choice"]) && ($_REQUEST["choice"] != 'allfiles' || $_REQUEST["confirm"] == 'yes') )
 {
-	$filesarray=array();
-
-	if ($_REQUEST["choice"]=='tempfiles')
+	$count=0;
+	if($_REQUEST["choice"]=='allprods')
 	{
-		// Delete temporary files
-		if ($dolibarr_main_data_root)
+		$product = new Product($db);
+	
+		$sql="SELECT rowid, ref FROM ".MAIN_DB_PREFIX."product";
+		$resql=$db->query($sql);
+	
+		if ($resql)
 		{
-			$filesarray=dol_dir_list($dolibarr_main_data_root,"directories",1,'\/temp$');
+			while ($obj=$db->fetch_object($resql))
+			{
+				$result = $product->delete($obj->rowid);
+				if(!$result)
+				{
+					$message.=$langs->trans("PurgeProductRefDeleted", $obj->ref);
+					$count++;
+				}
+			}
 		}
-	}
-
-	if ($_REQUEST["choice"]=='allfiles')
-	{
-		// Delete all files
-		if ($dolibarr_main_data_root)
+		else
 		{
-			$filesarray=dol_dir_list($dolibarr_main_data_root,"all",0);
+			dol_print_error($this->db);
+			$message=$langs->trans("Error")." : ".$this->db->error()." - ".$sql;
 		}
+	
+		if ($count) $message.=$langs->trans("PurgeNProductsDeleted",$count);
 	}
-
-	if ($_REQUEST["choice"]=='logfile')
+	else
 	{
-		$filesarray[]=array('fullname'=>$filelog,'type'=>'file');
-	}
-
-	$count=0;
-	if (sizeof($filesarray))
-	{
-
-		foreach($filesarray as $key => $value)
+		$filesarray=array();
+	
+		if ($_REQUEST["choice"]=='tempfiles')
 		{
-			//print "x ".$filesarray[$key]['fullname']."<br>\n";
-			if ($filesarray[$key]['type'] == 'dir')
+			// Delete temporary files
+			if ($dolibarr_main_data_root)
 			{
-				$count+=dol_delete_dir_recursive($filesarray[$key]['fullname']);
+				$filesarray=dol_dir_list($dolibarr_main_data_root,"directories",1,'\/temp$');
 			}
-			elseif ($filesarray[$key]['type'] == 'file')
+		}
+	
+		if ($_REQUEST["choice"]=='allfiles')
+		{
+			// Delete all files
+			if ($dolibarr_main_data_root)
 			{
-				// If (file that is not logfile) or (if logfile with option logfile)
-				if ($filesarray[$key]['fullname'] != $filelog || $_POST["choice"]=='logfile')
-				{
-					$count+=dol_delete_file($filesarray[$key]['fullname']);
-				}
+				$filesarray=dol_dir_list($dolibarr_main_data_root,"all",0);
 			}
 		}
-
-		// Update cachenbofdoc
-		if ($conf->ecm->enabled && $_REQUEST["choice"]=='allfiles')
+	
+		if ($_REQUEST["choice"]=='logfile')
 		{
-			require_once(DOL_DOCUMENT_ROOT."/ecm/class/ecmdirectory.class.php");
-			$ecmdirstatic = new ECMDirectory($db);
-			$result = $ecmdirstatic->refreshcachenboffile(1);
+			$filesarray[]=array('fullname'=>$filelog,'type'=>'file');
 		}
+	
+		if (sizeof($filesarray))
+		{
+	
+			foreach($filesarray as $key => $value)
+			{
+				//print "x ".$filesarray[$key]['fullname']."<br>\n";
+				if ($filesarray[$key]['type'] == 'dir')
+				{
+					$count+=dol_delete_dir_recursive($filesarray[$key]['fullname']);
+				}
+				elseif ($filesarray[$key]['type'] == 'file')
+				{
+					// If (file that is not logfile) or (if logfile with option logfile)
+					if ($filesarray[$key]['fullname'] != $filelog || $_POST["choice"]=='logfile')
+					{
+						$count+=dol_delete_file($filesarray[$key]['fullname']);
+					}
+				}
+			}
+	
+			// Update cachenbofdoc
+			if ($conf->ecm->enabled && $_REQUEST["choice"]=='allfiles')
+			{
+				require_once(DOL_DOCUMENT_ROOT."/ecm/class/ecmdirectory.class.php");
+				$ecmdirstatic = new ECMDirectory($db);
+				$result = $ecmdirstatic->refreshcachenboffile(1);
+			}
+		}
+		if ($count) $message=$langs->trans("PurgeNDirectoriesDeleted",$count);
 	}
-
-	if ($count) $message=$langs->trans("PurgeNDirectoriesDeleted",$count);
-	else $message=$langs->trans("PurgeNothingToDelete");
+	if(!$count) $message=$langs->trans("PurgeNothingToDelete");
 	$message='<div class="ok">'.$message.'</div>';
 }
 
@@ -145,6 +175,10 @@ print '<input type="radio" name="choice" value="confirm_allfiles"';
 print ($_REQUEST["choice"] && $_REQUEST["choice"]=='confirm_allfiles') ? ' checked="true"' : '';
 print '> '.$langs->trans("PurgeDeleteAllFilesInDocumentsDir",$dolibarr_main_data_root).'<br>';
 
+print '<input type="radio" name="choice" value="confirm_allprods"';
+print ($_REQUEST["choice"] && $_REQUEST["choice"]=='confirm_allprods') ? ' checked="true"' : '';
+print '> '.$langs->trans("PurgeDeleteAllProducts").'<br>';
+
 print '</td></tr></table>';
 
 if ($_REQUEST['choice'] != 'confirm_allfiles')
@@ -169,7 +203,13 @@ if (preg_match('/^confirm/i',$_REQUEST["choice"]))
 	$ret=$html->form_confirm($_SERVER["PHP_SELF"].'?choice=allfiles',$langs->trans('Purge'),$langs->trans('ConfirmPurge').' '.img_warning(),'purge',$formquestion,'no',2);
 	if ($ret == 'html') print '<br>';
 }
-
+if (preg_match('/^confirm_allprods/i',$_REQUEST["choice"]))
+{
+	print '<br>';
+	$formquestion=array();
+	$ret=$html->form_confirm($_SERVER["PHP_SELF"].'?choice=allprods',$langs->trans('Purge'),$langs->trans('ConfirmPurgeProd').' '.img_warning(),'purge',$formquestion,'no',2);
+	if ($ret == 'html') print '<br>';
+}
 
 llxFooter('$Date: 2011/08/03 00:45:43 $ - $Revision: 1.19 $');
 ?>
\ No newline at end of file
diff --git a/htdocs/compta/clients.php b/htdocs/compta/clients.php
index e6b200a..b65ce39 100644
--- a/htdocs/compta/clients.php
+++ b/htdocs/compta/clients.php
@@ -42,6 +42,7 @@ accessforbidden();
 
 
 $langs->load("companies");
+$langs->load("commercial");
 
 $sortfield = GETPOST("sortfield",'alpha');
 $sortorder = GETPOST("sortorder",'alpha');
diff --git a/htdocs/imports/import.php b/htdocs/imports/import.php
index 1116f27..3e37f74 100644
--- a/htdocs/imports/import.php
+++ b/htdocs/imports/import.php
@@ -1376,12 +1376,12 @@ if ($step == 5 && $datatoimport)
             print '<br>';
         }
 
-        // Show import id
-        $importid=dol_print_date(dol_now(),'%Y%m%d%H%M%S');
 
         print '<center>';
         print $langs->trans("NowClickToRunTheImport",$langs->transnoentitiesnoconv("RunImportFile")).'<br>';
-        print $langs->trans("DataLoadedWithId",$importid).'<br>';
+        if(!empty($importid)) {
+           print $langs->trans("DataLoadedWithId",$importid).'<br>';
+		}
         print '</center>';
 
         print '<br>';
@@ -1653,8 +1653,10 @@ if ($step == 6 && $datatoimport)
 	print '<center>';
 	print '<br>';
 	print $langs->trans("NbOfLinesImported",$nbok).'</b><br><br>';
-	print $langs->trans("FileWasImported",$importid).'<br>';
-	print $langs->trans("YouCanUseImportIdToFindRecord",$importid).'<br>';
+	if(!empty($importid)) {
+		print $langs->trans("FileWasImported",$importid).'<br>';
+		print $langs->trans("YouCanUseImportIdToFindRecord",$importid).'<br>';
+	}
 	print '</center>';
 
 	if ($mesg) print $mesg;
diff --git a/htdocs/includes/modules/import/import_csv.modules.php b/htdocs/includes/modules/import/import_csv.modules.php
index 4378cd0..9184a77 100644
--- a/htdocs/includes/modules/import/import_csv.modules.php
+++ b/htdocs/includes/modules/import/import_csv.modules.php
@@ -271,7 +271,7 @@ class ImportCsv extends ModeleImports
 	 * @param	maxfields						Max number of fiels to use
 	 * @return	int								<0 if KO, >0 if OK
 	 */
-	function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$maxfields,$importid)
+	function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$maxfields,&$importid)
 	{
 		global $langs,$conf,$user;
 
@@ -398,31 +398,105 @@ class ImportCsv extends ModeleImports
 				}
 				//print $listvalues;
 
+				// If some values need to be found somewhere else than in source file: Case we need a rowid found from a fetch on a reference.
+				// This is used when insert must be done when a parent row already exists
+				foreach($objimport->array_import_convertvalue[0] as $alias => $rulearray)
+				{
+					if (empty($rulearray['rule']))  continue;
+				
+					// Used to import rowid from other table by sql
+					// Sample:
+					// $this->import_convertvalue_array[$r]=array('fk_product'=>array('rule'=>'fetchfromtable','table'=>'product', 'reference'=>'ref'));
+					if ($rulearray['rule']=='fetchfromtable')
+					{
+						dol_syslog("We need to get rowid from ref=".$alias." from table ".$rulearray['table']);
+						$key = array_search($alias, explode(', ', $listfields));
+						if ( $key === false) {
+							dol_syslog("import_csv.modules: key '$alias' not found in '$listfields'!");
+							continue;
+						}
+						$tmp = explode(", ", $listvalues);
+				
+						$sql='SELECT rowid from '.MAIN_DB_PREFIX.$rulearray['table'];
+						$sql.=' WHERE '. $rulearray['reference'] .'='. $tmp[$key];
+						//dol_syslog("import_csv.modules: sql=".$sql);
+				
+						$resql = $this->db->query($sql);
+						if ($resql)
+						{
+							$obj = $this->db->fetch_object($resql);
+							$tmp[$key] = "'".$obj->rowid."'";
+							$listvalues = implode(", ", $tmp);
+						}
+						else
+						{
+							// Guess Reference was not found
+							// dol_print_error($this->db);
+							$this->errors[$error]['lib']=$langs->trans('ErrorFieldValueNotIn',$key+1,$tmp[$key],$rulearray['reference'],MAIN_DB_PREFIX.$rulearray['table']);
+							$this->errors[$error]['type']='FOREIGNKEY';
+							$error++;
+						}
+					}
+				
+					// Used to import rowid from other class by the fetch function
+					// Sample:
+					// $this->import_convertvalue_array[$r]=array('fk_product'=>array('rule'=>'fetchfromclass','class'=>'Product'));
+					if ($rulearray['rule']=='fetchfromclass')
+					{
+						dol_syslog("We need to get rowid from ref=".$alias." from class ".$rulearray['class']);
+						$key = array_search($alias, explode(', ', $listfields));
+						if ( $key == false) continue;
+				
+						require_once(DOL_DOCUMENT_ROOT."/".strtolower($rulearray['class'])."/class/".strtolower($rulearray['class']).".class.php");
+						$obj = new $rulearray['class']($this->db);
+				
+						$tmp = explode(', ', $listvalues);
+						$resql = $obj->fetch('', cleansep($tmp[$key], "'", ""));
+						if($resql)
+						{
+							$tmp[$key] = "'".$obj->id."'";
+							$listvalues = implode(", ", $tmp);
+						}
+						else
+						{
+							// Guess Reference was not found
+							// dol_print_error($this->db);
+							$this->errors[$error]['lib']=$langs->trans('ErrorFieldValueNotIn',$key+1,$tmp[$key],"ref",$rulearray['class']);
+							$this->errors[$error]['type']='FOREIGNKEY';
+							$errorforthistable++;
+							$error++;
+						}
+					}
+				}
+				
 				if (! $errorforthistable)
 				{
 					if ($listfields)
 					{
-						// If some values need to be found somewhere else than in source file: Case we need a rowid found from a fetch on a reference.
-						// This is used when insert must be done when a parent row already exists
-						// $objimport->array_import_convertvalue=array('s.fk_soc'=>array('rule'=>'fetchfromref',file='/societe.class.php','class'=>'Societe','method'=>'fetch'));
-						foreach($objimport->array_import_convertvalue as $alias => $rulearray)
+						// If no field 'importkey' exists in table 
+						// Its a workaround until all importable tables gets such a colummn
+						$resql = $this->db->query("show columns from ".$tablename." like 'import_key'");
+						if($resql)
 						{
-							if (empty($rulearray['rule']) || $rulearray['rule']!='fetchfromref') continue;
-							dol_syslog("We need to get rowid from ref=".$alias." using value found in column ".$array_match_database_to_file." in source file, so ".$arrayrecord[$array_match_database_to_file]['val']);
+							if ($this->db->num_rows($resql) > 0) 
+							{
+								$importkey = ", import_key";
+								$importval = ", '" . $importid . "'";		
+							}
+							else
+							{
+								$importid = ""; // No import column in table
+								$importkey = $importval = "";
+							}
 						}
 
-						// If some values need to be found somewhere else than in source file: Case we need lastinsert id from previous insert
-						// This is used when insert must be done in several tables
-						// $objimport->array_import_convertvalue=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
-						// TODO
-
 						// Build SQL request
-						$sql ='INSERT INTO '.$tablename.'('.$listfields.', import_key';
+						$sql ='INSERT INTO '.$tablename.'('.$listfields.$importkey;
 						if (! empty($objimport->array_import_tables_creator[0][$alias])) $sql.=', '.$objimport->array_import_tables_creator[0][$alias];
-						$sql.=') VALUES('.$listvalues.", '".$importid."'";
+						$sql.=') VALUES('.$listvalues.$importval;
 						if (! empty($objimport->array_import_tables_creator[0][$alias])) $sql.=', '.$user->id;
 						$sql.=')';
-						dol_syslog("import_csv.modules sql=".$sql);
+						//dol_syslog("import_csv.modules: sql=".$sql);
 
 						//print '> '.join(',',$arrayrecord);
 						//print 'sql='.$sql;
@@ -460,10 +534,14 @@ class ImportCsv extends ModeleImports
 
 /**
  *	Clean a string from separator
+ * @param 	value						String to clean
+ * @param	sep							Seperator char (Default ",")
+ * @param 	replace						Replacment char (Default "/")
+ * @return	string	
  */
-function cleansep($value)
+function cleansep($value, $sep=",", $replace="/")
 {
-	return str_replace(',','/',$value);
+	return str_replace($sep, $replace, $value);
 };
 
 ?>
diff --git a/htdocs/includes/modules/modProduct.class.php b/htdocs/includes/modules/modProduct.class.php
index 6f9b7a8..5a42dae 100644
--- a/htdocs/includes/modules/modProduct.class.php
+++ b/htdocs/includes/modules/modProduct.class.php
@@ -155,10 +155,46 @@ class modProduct extends DolibarrModules
 		$this->import_icon[$r]=$this->picto;
 		$this->import_tables_array[$r]=array('p'=>MAIN_DB_PREFIX.'product');
 		$this->import_tables_creator_array[$r]=array('p'=>'fk_user_author');	// Fields to store import user id
-		$this->import_fields_array[$r]=array('p.ref'=>"Ref*",'p.label'=>"Label*",'p.description'=>"Description",'p.note'=>"Note",'p.price'=>"SellingPriceHT",'p.price_ttc'=>"SellingPriceTTC",'p.tva_tx'=>'VAT','p.tosell'=>"OnSell*",'p.tobuy'=>"OnBuy*",'p.fk_product_type'=>"Type*",'p.finished'=>'Nature','p.duration'=>"Duration",'p.weight'=>"Weight",'p.volume'=>"Volume",'p.datec'=>'DateCreation*');
+		$this->import_fields_array[$r]=array('p.ref'=>"Ref*",'p.label'=>"Label*",'p.description'=>"Description",'p.note'=>"Note",'p.price'=>"SellPrice",'p.price_ttc'=>"SellPriceTTC", 'p.price_min'=>"SellPriceMin",'p.price_min_ttc'=>"SellPriceTTC",'p.tva_tx'=>'VAT','p.tosell'=>"OnSell*",'p.tobuy'=>"OnBuy*",'p.fk_product_type'=>"Type*",'p.finished'=>'Nature','p.duration'=>"Duration",'p.weight'=>"Weight", 'p.volume'=>"Volume",'p.fk_country'=>"Country",'p.datec'=>'DateCreation*');
 		$this->import_entities_array[$r]=array();	// We define here only fields that use another picto
-		$this->import_regex_array[$r]=array('p.ref'=>'[^ ]','p.tosell'=>'^[0|1]','p.tobuy'=>'^[0|1]','p.fk_product_type'=>'^[0|1]','p.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$');
-		$this->import_examplevalues_array[$r]=array('p.ref'=>"PR123456",'p.label'=>"My product",'p.description'=>"This is a description example for record",'p.note'=>"Some note",'p.price'=>"100",'p.price_ttc'=>"110",'p.tva_tx'=>'10','p.tosell'=>"0 or 1",'p.tobuy'=>"0 or 1",'p.fk_product_type'=>"0 for product/1 for service",'p.finished'=>'','p.duration'=>"1y",'p.datec'=>'2008-12-31');
+		$this->import_regex_array[$r]=array('p.ref'=>'[^ ]','p.tosell'=>'^[0|1]','p.tobuy'=>'^[0|1]','p.fk_product_type'=>'^[0|1]','p.datec'=>'^[0-2][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9]$');
+		$this->import_examplevalues_array[$r]=array('p.ref'=>"PR123456",'p.label'=>"My product",'p.description'=>"This is a description example",'p.note'=>"Some note",'p.price'=>"100",'p.price_ttc'=>"120",'p.price_min'=>"90",'p.price_min_ttc'=>"108",'p.tva_tx'=>'20','p.tosell'=>"0 or 1",'p.tobuy'=>"0 or 1",'p.fk_product_type'=>"0 for product/1 for service",'p.finished'=>'','p.duration'=>"1y",'p.weight'=>"100Kg",'p.volume'=>"100",'p.fk_country'=>"5",'p.datec'=>'2008-12-31 15:00:00');
+		$this->import_convertvalue_array[$r]=array();
+		
+		$r++;
+		$this->import_code[$r]=$this->rights_class.'_'.$r;
+		$this->import_label[$r]="CustomerPrices";
+		$this->import_icon[$r]=$this->picto;
+		$this->import_tables_array[$r]=array('pp'=>MAIN_DB_PREFIX.'product_price');	// List of tables to insert into (insert done in same order)
+		$this->import_tables_creator_array[$r]=array();
+		$this->import_fields_array[$r]=array('pp.date_price'=>'Date','pp.fk_product'=>'Product','pp.price_level'=>"Level",'pp.price'=>"Price", 'pp.price_ttc'=>"PriceTTC",'pp.price_min'=>"PriceMin",'pp.price_min_ttc'=>"PriceMinTTC",'pp.tva_tx'=>"VAT",'pp.recuperableonly'=>"Rec",'pp.tosell'=>"ToSell",'pp.fk_user_author'=>"Autor");
+		$this->import_entities_array[$r]=array();	// We define here only fields that use another picto
+		$this->import_examplevalues_array[$r]=array('pp.date_price'=>'2008-12-31 15:00:00','pp.fk_product'=>'OIL00001','pp.price_level'=>"1",'pp.price'=>"100",'pp.price_ttc'=>"120",'pp.price_min'=>"90",'pp.price_min_ttc'=>"108",'pp.tva_tx'=>"20",'pp.recuperableonly'=>"1",'pp.tosell'=>"1",'pp.fk_user_author'=>"1");
+		$this->import_convertvalue_array[$r]=array('fk_product'=>array('rule'=>'fetchfromclass','class'=>'Product'));
+		
+		$r++;
+		$this->import_code[$r]=$this->rights_class.'_'.$r;
+		$this->import_label[$r]="Suppliers";
+		$this->import_icon[$r]=$this->picto;
+		$this->import_tables_array[$r]=array('pf'=>MAIN_DB_PREFIX.'product_fournisseur');	// List of tables to insert into (insert done in same order)
+		$this->import_tables_creator_array[$r]=array();
+		$this->import_fields_array[$r]=array('pf.datec'=>'Date','pf.fk_product'=>'Product','pf.fk_soc'=>"Supplier",'pf.ref_fourn'=>"Suppliers Art.Nr.",'pf.entity'=>"Entity",'pf.fk_user_author'=>"Autor");
+		$this->import_entities_array[$r]=array();	// We define here only fields that use another picto
+		$this->import_examplevalues_array[$r]=array('pf.datec'=>'2008-12-31 15:00:00','pf.fk_product'=>'OIL00001','pf.fk_soc'=>"1",'pf.ref_fourn'=>"4711",'pf.entity'=>"1",'pf.fk_user_author'=>"1");
+		$this->import_convertvalue_array[$r]=array('fk_product'=>array('rule'=>'fetchfromclass','class'=>'Product'));
+		
+		$r++;
+		$this->import_code[$r]=$this->rights_class.'_'.$r;
+		$this->import_label[$r]="SuppliersPrices";
+		$this->import_icon[$r]=$this->picto;
+		$this->import_tables_array[$r]=array('pf'=>MAIN_DB_PREFIX.'product_fournisseur_price');	// List of tables to insert into (insert done in same order)
+		$this->import_tables_creator_array[$r]=array();
+		$this->import_fields_array[$r]=array('pf.datec'=>'Date','pf.fk_product_fournisseur'=>'Product','pf.price'=>"Price",'pf.quantity'=>"Quantity",'pf.unitprice'=>"UnitPrice",'pf.fk_user'=>"User");
+		$this->import_entities_array[$r]=array();	// We define here only fields that use another picto
+		$this->import_examplevalues_array[$r]=array('pf.datec'=>'2008-12-31 15:00:00','pf.fk_product_fournisseur'=>'17004','pf.price'=>"1.34",'pf.quantity'=>"1",'pf.unitprice'=>"1.34",'pf.fk_user'=>"1");
+		$this->import_convertvalue_array[$r]=array('fk_product_fournisseur'=>array('rule'=>'fetchfromtable', 'table'=>'product_fournisseur', 'reference'=>'ref_fourn'));
+		
+	
 	}
 
 
diff --git a/htdocs/includes/modules/modSociete.class.php b/htdocs/includes/modules/modSociete.class.php
index 5c75193..b1891e3 100644
--- a/htdocs/includes/modules/modSociete.class.php
+++ b/htdocs/includes/modules/modSociete.class.php
@@ -274,22 +274,38 @@ class modSociete extends DolibarrModules
 		// Imports
 		//--------
 		$r=0;
-
+	
 		// Import list of third parties and attributes
 		$r++;
 		$this->import_code[$r]=$this->rights_class.'_'.$r;
-		$this->import_label[$r]='ImportDataset_company_1';
+		$this->import_label[$r]="ImportDataset_company_1";	// Translation key
 		$this->import_icon[$r]='company';
-		$this->import_tables_array[$r]=array('s'=>MAIN_DB_PREFIX.'societe');	// List of tables to insert into (insert done in same order)
-		$this->import_fields_array[$r]=array('s.nom'=>"Name*",'s.status'=>"Status",'s.client'=>"Customer*",'s.fournisseur'=>"Supplier*",'s.datec'=>"DateCreation",'s.code_client'=>"CustomerCode",'s.code_fournisseur'=>"SupplierCode",'s.address'=>"Address",'s.cp'=>"Zip",'s.ville'=>"Town",'s.tel'=>"Phone",'s.fax'=>"Fax",'s.url'=>"Url",'s.email'=>"Email",'s.siret'=>"IdProf1",'s.siren'=>"IdProf2",'s.ape'=>"IdProf3",'s.idprof4'=>"IdProf4",'s.tva_intra'=>"VATIntraShort",'s.capital'=>"Capital",'s.note'=>"Note",'s.fk_typent'=>"ThirdPartyType",'s.fk_effectif'=>"Effectif","s.fk_forme_juridique"=>"JuridicalStatus",'s.fk_prospectlevel'=>'ProspectLevel','s.fk_stcomm'=>'ProspectStatus','s.default_lang'=>'DefaultLanguage','s.gencod'=>'BarCode');
+		$this->import_tables_array[$r]=array('s'=>MAIN_DB_PREFIX.'societe');
+		$this->import_tables_creator_array[$r]=array();	// Fields to store import user id
+		$this->import_fields_array[$r]=array('s.nom'=>"Name*",'s.prefix_comm'=>"Prefix",'s.client'=>"Customer*",'s.fournisseur'=>"Supplier*",'s.datec'=>"DateCreation",'s.code_client'=>"CustomerCode",'s.code_fournisseur'=>"SupplierCode",'s.address'=>"Address",'s.cp'=>"Zip",'s.ville'=>"Town",'s.tel'=>"Phone",'s.fax'=>"Fax",'s.url'=>"Url",'s.email'=>"Email",'s.siret'=>"IdProf1",'s.siren'=>"IdProf2",'s.ape'=>"IdProf3",'s.idprof4'=>"IdProf4",'s.tva_intra'=>"VATIntraShort",'s.capital'=>"Capital",'s.note'=>"Note",'s.fk_typent'=>"ThirdPartyType",'s.fk_effectif'=>"Effectif","s.fk_forme_juridique"=>"JuridicalStatus",'s.fk_prospectlevel'=>'ProspectLevel','s.fk_stcomm'=>'ProspectStatus','s.default_lang'=>'DefaultLanguage','s.gencod'=>'BarCode');
 		$this->import_entities_array[$r]=array();	// We define here only fields that use another picto
-		$this->import_examplevalues_array[$r]=array('s.nom'=>"MyBigCompany",'s.status'=>"0 (closed) or 1 (active)",'s.prefix_comm'=>"comp",'s.client'=>'0 (no customer no prospect)/1 (customer)/2 (prospect)/3 (customer and prospect)','s.fournisseur'=>'0 or 1','s.datec'=>dol_print_date(mktime(),'YYYY-MM-DD'),'s.code_client'=>"CU01-0001",'s.code_fournisseur'=>"SU01-0001",'s.address'=>"61 jump street",'s.cp'=>"123456",'s.ville'=>"Big town",'s.tel'=>"0101010101",'s.fax'=>"0101010102",'s.url'=>"http://mycompany.com",'s.email'=>"test@mycompany.com",'s.siret'=>"",'s.siren'=>"",'s.ape'=>"",'s.idprof4'=>"",'s.tva_intra'=>"FR0123456789",'s.capital'=>"10000",'s.note'=>"This is an example of note for record",'s.fk_typent'=>"2",'s.fk_effectif'=>"3","s.fk_forme_juridique"=>"1",'s.fk_prospectlevel'=>'PL_MEDIUM','s.fk_stcomm'=>'','s.default_lang'=>'en_US','s.gencod'=>'123456789');
-
-		// Import list of contact and attributes
-/*		$r++;
+		$this->import_regex_array[$r]=array('p.ref'=>'[^ ]','p.tosell'=>'^[0|1]','p.tobuy'=>'^[0|1]','p.fk_product_type'=>'^[0|1]','p.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$');
+		$this->import_examplevalues_array[$r]=array('s.nom'=>"MyBigCompany",'s.prefix_comm'=>"comp",'s.client'=>'0 (no customer no prospect)/1 (customer)/2 (prospect)/3 (customer and prospect)','s.fournisseur'=>'0 or 1','s.datec'=>dol_print_date(mktime(),'YYYY-MM-DD'),'s.code_client'=>"CU01-0001",'s.code_fournisseur'=>"SU01-0001",'s.address'=>"61 jump street",'s.cp'=>"123456",'s.ville'=>"Big town",'s.tel'=>"0101010101",'s.fax'=>"0101010102",'s.url'=>"http://mycompany.com",'s.email'=>"test@mycompany.com",'s.siret'=>"",'s.siren'=>"",'s.ape'=>"",'s.idprof4'=>"",'s.tva_intra'=>"FR0123456789",'s.capital'=>"10000",'s.note'=>"This is an example of note for record",'s.fk_typent'=>"2",'s.fk_effectif'=>"3","s.fk_forme_juridique"=>"1",'s.fk_prospectlevel'=>'PL_MEDIUM','s.fk_stcomm'=>'','s.default_lang'=>'en_US','s.gencod'=>'123456789');
+		$this->import_convertvalue_array[$r]=array();
+		
+		
+		// Import list of zip codes
+		$r++;
 		$this->import_code[$r]=$this->rights_class.'_'.$r;
 		$this->import_label[$r]='ImportDataset_company_2';
 		$this->import_icon[$r]='contact';
+		$this->import_tables_array[$r]=array('sz'=>MAIN_DB_PREFIX.'c_ziptown');	// List of tables to insert into (insert done in same order)
+		$this->import_tables_creator_array[$r]=array();
+		$this->import_fields_array[$r]=array('sz.fk_county'=>'Region','pf.zip'=>"Zip",'pf.town'=>"Town",'pf.active'=>"Activ");
+		$this->import_entities_array[$r]=array();	// We define here only fields that use another picto
+		$this->import_examplevalues_array[$r]=array('sz.fk_county'=>'St','pf.zip'=>"8225",'pf.town'=>"Pöllau",'pf.active'=>"1");
+		$this->import_convertvalue_array[$r]=array('fk_county'=>array('rule'=>'fetchfromtable','table'=>'c_departements', 'reference'=>'code_departement'));
+		
+		// Import list of contact and attributes
+		/*		$r++;
+		 $this->import_code[$r]=$this->rights_class.'_'.$r;
+		$this->import_label[$r]='ImportDataset_company_2';
+		$this->import_icon[$r]='contact';
 		//$this->import_permission[$r]=array(array("societe","export"));
 		$this->import_tables_array[$r]=array('s'=>MAIN_DB_PREFIX.'socpeople');	// List of tables to insert into (insert done in same order)
 		$this->import_fields_array[$r]=array('s.fk_soc'=>'ThirdPartyName*','s.civilite'=>'Civility','s.name'=>"Name*",'s.firstname'=>"Firstname",'s.address'=>"Address",'s.cp'=>"Zip",'s.ville'=>"Town",'s.fk_pays'=>"CountryCode",'s.birthday'=>"BirthdayDate",'s.poste'=>"Role",'s.phone'=>"Phone",'s.phone_perso'=>"PhonePerso",'s.phone_mobile'=>"PhoneMobile",'s.fax'=>"Fax",'s.email'=>"Email",'s.note'=>"Note");
@@ -299,7 +315,8 @@ class modSociete extends DolibarrModules
 		$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'fetchfromref','file'=>'/societe.class.php','class'=>'Societe','method'=>'fetch'));
 		// If value for some fields must be the previous inserted record (lastinsertid)
 		//$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
-*/
+		*/
+		
 	}
 
 
diff --git a/htdocs/langs/de_AT/admin.lang b/htdocs/langs/de_AT/admin.lang
old mode 100755
new mode 100644
index 56304be..7ba710c
--- a/htdocs/langs/de_AT/admin.lang
+++ b/htdocs/langs/de_AT/admin.lang
@@ -4,7 +4,6 @@
  * Generation date 2010-11-13 13:09:12
  */
 
-
 CHARSET=UTF-8
 Version=Version
 VersionProgram=Programmversion
@@ -108,9 +107,12 @@ PurgeAreaDesc=Hier kĂ¶nnen Sie alle vom System erzeugten und gespeicherten Datei
 PurgeDeleteTemporaryFiles=Alle temporĂ¤ren Dateien lĂ¶schen (kein Datenverlustrisiko)
 PurgeDeleteAllFilesInDocumentsDir=Alle Datein im Verzeichnis <b>%s</b> lĂ¶schen. Dies beinhaltet temporĂ¤re Dateien ebenso wie Datenbanksicherungen, Dokumente (Partner, Rechnungen, ...) und alle Inhalte des ECM-Moduls.
 PurgeRunNow=Jetzt lĂ¶schen
-PurgeNothingToDelete=Keine zu lĂ¶schenden Verzeichnisse oder Dateien
+PurgeNothingToDelete=Keine zu lĂ¶schenden Daten.
 PurgeNDirectoriesDeleted=<b>%s</b> Dateien oder Verzeichnisse gelĂ¶scht.
 PurgeAuditEvents=Alle Protokolle lĂ¶schen
+PurgeNProductsDeleted=<br><b>%s</b> Produkte gelĂ¶scht.
+PurgeDeleteAllProducts=Alle unverwendeten Produkte lĂ¶schen
+PurgeProductRefDeleted=Produkt <b>%s</b> gelĂ¶scht.<br>
 ConfirmPurgeAuditEvents=MĂ¶chten Sie wirklich alle Protokolle lĂ¶schen? Alle Sicherheitsprotokolle werden dadurch gelĂ¶scht, andere Dateien sind nicht betroffen.
 NewBackup=Neue Sicherung
 GenerateBackup=Sicherung erzeugen
@@ -964,6 +966,7 @@ AddCRIfTooLong=Kein automatischer Zeilenumbruch. Entsprechend mĂĽssen Sie, falls
 ModuleDisabled=Modul deaktiviert
 ModuleDisabledSoNoEvent=Modul deaktiviert und Eintrag deshalb nie erstellt
 ConfirmPurge=MĂ¶chten Sie die LĂ¶schung wirklich durchfĂĽhren? <br>Dies wird alle Ihre Dateien unwiderbringlich entfernen (ECM-Dateien, Dateien, ...)!
+ConfirmPurgeProd=MĂ¶chten Sie die LĂ¶schung wirklich durchfĂĽhren? <br>Dies wird alle noch nicht verwendete Produkte unwiederbringlich entfernen!
 Module51Name=Postwurfsendungen
 Module51Desc=Verwaltung von Postwurf-/Massensendungen
 Module5000Name=MandantenfĂ¤higkeit
diff --git a/htdocs/langs/de_AT/companies.lang b/htdocs/langs/de_AT/companies.lang
old mode 100755
new mode 100644
index b72bfc1..5e157ba
--- a/htdocs/langs/de_AT/companies.lang
+++ b/htdocs/langs/de_AT/companies.lang
@@ -252,6 +252,8 @@ DolibarrLogin=Login
 NoDolibarrAccess=Kein Zugang
 ExportDataset_company_1=Partner und Eigenschaften
 ExportDataset_company_2=Kontakte und Eigenschaften
+ImportDataset_company_1=Partner und Eigenschaften
+ImportDataset_company_2=Zip-Codes
 DeliveriesAddress=Lieferadressen
 DeliveryAddress=Lieferadresse
 DeliveryAddressLabel=Lieferadressen-Label
diff --git a/htdocs/langs/es_ES/externalsite.lang b/htdocs/langs/es_ES/externalsite.lang
new file mode 100644
index 0000000..92f58eb
--- /dev/null
+++ b/htdocs/langs/es_ES/externalsite.lang
@@ -0,0 +1,13 @@
+/*
+ * Language code: es_ES
+ * Automatic generated via autotranslator.php tool
+ * Generation date 2011-10-19 09:22:16
+ */
+
+
+// START - Lines generated via autotranslator.php tool (2011-10-19 09:22:16).
+// Reference language: fr_FR -> es_ES
+CHARSET=UTF-8
+ExternalSiteSetup=Configurar el enlace al sitio web externo
+ExternalSiteURL=URL del sitio externo
+// STOP - Lines generated via autotranslator.php tool (2011-10-19 09:22:33).
diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang
index eca6c20..61bddce 100644
--- a/htdocs/langs/fr_FR/admin.lang
+++ b/htdocs/langs/fr_FR/admin.lang
@@ -1,4 +1,5 @@
 # Dolibarr language file - fr_FR - admin 
+
 CHARSET= UTF-8
 Version= Version
 VersionProgram= Version programmes
@@ -132,8 +133,11 @@ PurgeDeleteLogFile= Effacer le fichier log <b>%s</b> dĂ©fini pour le module Sysl
 PurgeDeleteTemporaryFiles= Effacer tous les fichiers temporaires (pas de risque de perte de donnĂ©es)
 PurgeDeleteAllFilesInDocumentsDir= Effacer tous les fichiers du rĂ©pertoire <b>%s</b>. Les fichiers temporaires mais aussi les fichiers dumps de sauvegardes de bases, les fichiers joints aux Ă©lĂ©ments (tiers, factures, ...) ou fichiers stockĂ©s dans le module GED seront irrĂ©mĂ©diablement effacĂ©s.
 PurgeRunNow= Lancer la purge maintenant
-PurgeNothingToDelete= Aucun rĂ©pertoire ou fichier Ă  supprimer.
+PurgeNothingToDelete= Aucun donnĂ©es Ă  supprimer.
 PurgeNDirectoriesDeleted= <b>%s</b> fichiers ou rĂ©pertoires supprimĂ©s.
+PurgeNProductsDeleted=<br><b>%s</b> produits supprimĂ©s.
+PurgeDeleteAllProducts=Supprimer tous les produits non utilisĂ©s.
+PurgeProductRefDeleted=Produit <b>%s </ b> supprimĂ©.<br>
 PurgeAuditEvents= Purger les Ă©vĂ©nements sĂ©curitĂ©
 ConfirmPurgeAuditEvents= Etes vous sĂ»r de vouloir purger la liste des Ă©vĂ©nements d'audit de sĂ©curitĂ©. Toute la liste sera effacĂ©e, mais ceci est sans consĂ©quence sur vos autres donnĂ©es.
 NewBackup= Nouvelle sauvegarde
@@ -288,6 +292,7 @@ AddCRIfTooLong=Il n'y a pas de coupure de ligne automatique, aussi si votre text
 ModuleDisabled=Module dĂ©sactivĂ©
 ModuleDisabledSoNoEvent=Module dĂ©sactivĂ© donc Ă©vĂ©nement jamais crĂ©Ă©
 ConfirmPurge=ĂŠtes vous sĂ»r de vouloir rĂ©aliser cette purge ?<br>Ceci effacera dĂ©finitivement toutes vos donnĂ©es fichier (espace GED, piĂ¨ces jointes, etc...). 
+ConfirmPurgeProd=ĂŠtes vous sĂ»r de vouloir rĂ©aliser cette purge ?<br>Ceci effacera dĂ©finitivement toutes vos produits!
 MinLength=Longueur minimale
 LanguageFilesCachedIntoShmopSharedMemory=Fichiers .lang en mĂ©moire partagĂ©e
 ExamplesWithCurrentSetup=Exemples avec le paramĂ©trage actif courant
diff --git a/htdocs/langs/fr_FR/companies.lang b/htdocs/langs/fr_FR/companies.lang
index 528514e..03caa23 100644
--- a/htdocs/langs/fr_FR/companies.lang
+++ b/htdocs/langs/fr_FR/companies.lang
@@ -319,6 +319,7 @@ NoDolibarrAccess=Pas d'accĂ¨s utilisateur
 ExportDataset_company_1=Tiers (sociĂ©tĂ©s/institutions) et attributs
 ExportDataset_company_2=Contacts (de tiers) et attributs
 ImportDataset_company_1=Tiers (sociĂ©tĂ©s/institutions) et attributs
+ImportDataset_company_2=Code postal
 PriceLevel=Niveau de prix
 DeliveriesAddress=Adresse(s) de livraison
 DeliveryAddress=Adresse de livraison
diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php
index c44cbc6..a121fd7 100644
--- a/htdocs/product/class/product.class.php
+++ b/htdocs/product/class/product.class.php
@@ -560,7 +560,7 @@ class Product extends CommonObject
 			if ($prod_use == 0)
 			{
 				// TODO possibility to add external module constraint
-				$elements = array('product_price','product_lang','categorie_product');
+				$elements = array('product_price', 'product_fournisseur_price', 'product_fournisseur_price_log', 'product_fournisseur','product_price_min','product_lang','categorie_product');
 
 				foreach($elements as $table)
 				{
@@ -670,6 +670,7 @@ class Product extends CommonObject
 
 	/**
 	 *	Load array this->multilangs
+	 *	@return		int			<0 si KO
 	 */
 	function getMultiLangs()
 	{
-- 
1.7.7.msysgit.0

