';
}
print '';
diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php
index 16279187b97..013830ca864 100644
--- a/htdocs/contact/class/contact.class.php
+++ b/htdocs/contact/class/contact.class.php
@@ -802,20 +802,19 @@ class Contact extends CommonObject
/**
- * Load object contact
+ * Load object contact.
*
- * @param int $id id du contact
- * @param User $user Utilisateur (abonnes aux alertes) qui veut les alertes de ce contact
- * @param string $ref_ext External reference, not given by Dolibarr
- * @param string $email Email
- * @return int -1 if KO, 0 if OK but not found, 1 if OK
+ * @param int $id Id of contact
+ * @param User $user Load also alerts of this user (subscribing to alerts) that want alerts about this contact
+ * @param string $ref_ext External reference, not given by Dolibarr
+ * @param string $email Email
+ * @param int $loadalsoroles Load also roles
+ * @return int >0 if OK, <0 if KO or if two records found for same ref or idprof, 0 if not found.
*/
- public function fetch($id, $user = null, $ref_ext = '', $email = '')
+ public function fetch($id, $user = null, $ref_ext = '', $email = '', $loadalsoroles = 0)
{
global $langs;
- $langs->load("dict");
-
dol_syslog(get_class($this)."::fetch id=".$id." ref_ext=".$ref_ext." email=".$email, LOG_DEBUG);
if (empty($id) && empty($ref_ext) && empty($email))
@@ -824,7 +823,7 @@ class Contact extends CommonObject
return -1;
}
- $langs->load("companies");
+ $langs->loadLangs(array("dict", "companies"));
$sql = "SELECT c.rowid, c.entity, c.fk_soc, c.ref_ext, c.civility as civility_code, c.lastname, c.firstname,";
$sql .= " c.address, c.statut, c.zip, c.town,";
@@ -861,7 +860,15 @@ class Contact extends CommonObject
$resql = $this->db->query($sql);
if ($resql)
{
- if ($this->db->num_rows($resql))
+ $num = $this->db->num_rows($resql);
+ if ($num > 1)
+ {
+ $this->error = 'Fetch found several records. Rename one of contact to avoid duplicate.';
+ dol_syslog($this->error, LOG_ERR);
+
+ return 2;
+ }
+ elseif ($num) // $num = 1
{
$obj = $this->db->fetch_object($resql);
@@ -942,7 +949,11 @@ class Contact extends CommonObject
return -1;
}
- // Charge alertes du user
+ // Retreive all extrafield
+ // fetch optionals attributes and labels
+ $this->fetch_optionals();
+
+ // Load also alerts of this user
if ($user)
{
$sql = "SELECT fk_user";
@@ -967,13 +978,12 @@ class Contact extends CommonObject
}
}
- // Retreive all extrafield
- // fetch optionals attributes and labels
- $this->fetch_optionals();
-
- $resultRole = $this->fetchRoles();
- if ($resultRole < 0) {
- return $resultRole;
+ // Load also roles of this address
+ if ($loadalsoroles) {
+ $resultRole = $this->fetchRoles();
+ if ($resultRole < 0) {
+ return $resultRole;
+ }
}
return 1;
@@ -1587,7 +1597,7 @@ class Contact extends CommonObject
}
/**
- * Fetch Role for a contact
+ * Fetch Roles for a contact
*
* @return float|int
* @throws Exception
@@ -1599,7 +1609,7 @@ class Contact extends CommonObject
$num = 0;
$sql = "SELECT tc.rowid, tc.element, tc.source, tc.code, tc.libelle, sc.rowid as contactroleid";
- $sql .= " FROM ".MAIN_DB_PREFIX."societe_contacts as sc ";
+ $sql .= " FROM ".MAIN_DB_PREFIX."societe_contacts as sc";
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."c_type_contact as tc";
$sql .= " ON tc.rowid = sc.fk_c_type_contact";
$sql .= " AND sc.fk_socpeople = ".$this->id;
diff --git a/htdocs/core/modules/import/import_csv.modules.php b/htdocs/core/modules/import/import_csv.modules.php
index 93d68691a11..6c9dd9062a8 100644
--- a/htdocs/core/modules/import/import_csv.modules.php
+++ b/htdocs/core/modules/import/import_csv.modules.php
@@ -425,6 +425,7 @@ class ImportCsv extends ModeleImports
// New val can be an id or ref. If it start with id: it is forced to id, if it start with ref: it is forced to ref. It not, we try to guess.
$isidorref = 'id';
if (!is_numeric($newval) && $newval != '' && !preg_match('/^id:/i', $newval)) $isidorref = 'ref';
+
$newval = preg_replace('/^(id|ref):/i', '', $newval); // Remove id: or ref: that was used to force if field is id or ref
//print 'Val is now '.$newval.' and is type '.$isidorref." \n";
@@ -448,8 +449,7 @@ class ImportCsv extends ModeleImports
$classinstance = new $class($this->db);
// Try the fetch from code or ref
$param_array = array('', $newval);
- if ($class == 'AccountingAccount')
- {
+ if ($class == 'AccountingAccount') {
//var_dump($arrayrecord[0]['val']);
/*include_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancysystem.class.php';
$tmpchartofaccount = new AccountancySystem($this->db);
@@ -464,6 +464,7 @@ class ImportCsv extends ModeleImports
}*/
$param_array = array('', $newval, 0, $arrayrecord[0]['val']); // Param to fetch parent from account, in chart.
}
+
call_user_func_array(array($classinstance, $method), $param_array);
// If not found, try the fetch from label
if (! ($classinstance->id != '') && $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel')
diff --git a/htdocs/core/modules/modCategorie.class.php b/htdocs/core/modules/modCategorie.class.php
index b53a9630598..7f92dcef6d6 100644
--- a/htdocs/core/modules/modCategorie.class.php
+++ b/htdocs/core/modules/modCategorie.class.php
@@ -452,7 +452,7 @@ class modCategorie extends DolibarrModules
if (! empty($conf->societe->enabled))
{
- //Customers
+ // Customers
$r++;
$this->import_code[$r]=$this->rights_class.'_'.$r;
$this->import_label[$r]="CatCusLinks"; // Translation key
@@ -470,6 +470,25 @@ class modCategorie extends DolibarrModules
'cs.fk_soc'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty')
);
$this->import_examplevalues_array[$r]=array('cs.fk_categorie'=>"Imported category",'cs.fk_soc'=>"MyBigCompany");
+
+ // Contacts/Addresses
+ $r++;
+ $this->import_code[$r]=$this->rights_class.'_'.$r;
+ $this->import_label[$r]="CatContactsLinks"; // Translation key
+ $this->import_icon[$r]=$this->picto;
+ $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
+ $this->import_tables_array[$r]=array('cs'=>MAIN_DB_PREFIX.'categorie_contact');
+ $this->import_fields_array[$r]=array('cs.fk_categorie'=>"Category*",'cs.fk_socpeople'=>"Contact ID*");
+ $this->import_regex_array[$r]=array(
+ 'cs.fk_categorie'=>'rowid@'.MAIN_DB_PREFIX.'categorie:type=4'
+ //'cs.fk_socpeople'=>'rowid@'.MAIN_DB_PREFIX.'socpeople'
+ );
+
+ $this->import_convertvalue_array[$r]=array(
+ 'cs.fk_categorie'=>array('rule'=>'fetchidfromref','classfile'=>'/categories/class/categorie.class.php','class'=>'Categorie','method'=>'fetch','element'=>'category')
+ //'cs.fk_socpeople'=>array('rule'=>'fetchidfromref','classfile'=>'/contact/class/contact.class.php','class'=>'Contact','method'=>'fetch','element'=>'Contact')
+ );
+ $this->import_examplevalues_array[$r]=array('cs.fk_categorie'=>"Imported category",'cs.fk_socpeople'=>"123");
}
if (! empty($conf->fournisseur->enabled))
diff --git a/htdocs/langs/en_US/categories.lang b/htdocs/langs/en_US/categories.lang
index 7207bbacc38..1ec9b5bd409 100644
--- a/htdocs/langs/en_US/categories.lang
+++ b/htdocs/langs/en_US/categories.lang
@@ -78,6 +78,7 @@ CatMemberList=List of members tags/categories
CatContactList=List of contact tags/categories
CatSupLinks=Links between suppliers and tags/categories
CatCusLinks=Links between customers/prospects and tags/categories
+CatContactsLinks=Links between contacts/addresses and tags/categories
CatProdLinks=Links between products/services and tags/categories
CatProJectLinks=Links between projects and tags/categories
DeleteFromCat=Remove from tags/category