|
@@ -473,40 +473,35 @@ class Contact extends CommonObject
|
|
|
|
|
|
dol_syslog(get_class($this)."::create", LOG_DEBUG);
|
|
|
$resql = $this->db->query($sql);
|
|
|
- if ($resql)
|
|
|
- {
|
|
|
+ if ($resql) {
|
|
|
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."socpeople");
|
|
|
|
|
|
- if (!$error)
|
|
|
- {
|
|
|
+ if (!$error) {
|
|
|
$result = $this->update($this->id, $user, 1, 'add'); // This include updateRoles(), ...
|
|
|
- if ($result < 0)
|
|
|
- {
|
|
|
+ if ($result < 0) {
|
|
|
$error++;
|
|
|
$this->error = $this->db->lasterror();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (!$error)
|
|
|
- {
|
|
|
+ if (!$error) {
|
|
|
$result = $this->update_perso($this->id, $user, 1); // TODO Remove function update_perso, should be same than update
|
|
|
- if ($result < 0)
|
|
|
- {
|
|
|
+ if ($result < 0) {
|
|
|
$error++;
|
|
|
$this->error = $this->db->lasterror();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (!$error)
|
|
|
- {
|
|
|
+ if (!$error) {
|
|
|
// Call trigger
|
|
|
$result = $this->call_trigger('CONTACT_CREATE', $user);
|
|
|
- if ($result < 0) { $error++; }
|
|
|
+ if ($result < 0) {
|
|
|
+ $error++;
|
|
|
+ }
|
|
|
// End call triggers
|
|
|
}
|
|
|
|
|
|
- if (!$error)
|
|
|
- {
|
|
|
+ if (!$error) {
|
|
|
$this->db->commit();
|
|
|
return $this->id;
|
|
|
} else {
|
|
@@ -558,13 +553,20 @@ class Contact extends CommonObject
|
|
|
$this->town = (empty($this->town) ? '' : trim($this->town));
|
|
|
$this->setUpperOrLowerCase();
|
|
|
$this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id);
|
|
|
- if (empty($this->statut)) $this->statut = 0;
|
|
|
- if (empty($this->civility_code) && !is_numeric($this->civility_id)) $this->civility_code = $this->civility_id; // For backward compatibility
|
|
|
+ if (empty($this->statut)) {
|
|
|
+ $this->statut = 0;
|
|
|
+ }
|
|
|
+ if (empty($this->civility_code) && !is_numeric($this->civility_id)) {
|
|
|
+ $this->civility_code = $this->civility_id; // For backward compatibility
|
|
|
+ }
|
|
|
$this->db->begin();
|
|
|
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET ";
|
|
|
- if ($this->socid > 0) $sql .= " fk_soc='".$this->db->escape($this->socid)."',";
|
|
|
- elseif ($this->socid == -1) $sql .= " fk_soc=null,";
|
|
|
+ if ($this->socid > 0) {
|
|
|
+ $sql .= " fk_soc='".$this->db->escape($this->socid)."',";
|
|
|
+ } elseif ($this->socid == -1) {
|
|
|
+ $sql .= " fk_soc=null,";
|
|
|
+ }
|
|
|
$sql .= " civility='".$this->db->escape($this->civility_code)."'";
|
|
|
$sql .= ", lastname='".$this->db->escape($this->lastname)."'";
|
|
|
$sql .= ", firstname='".$this->db->escape($this->firstname)."'";
|
|
@@ -586,8 +588,7 @@ class Contact extends CommonObject
|
|
|
$sql .= ", phone_mobile = ".(isset($this->phone_mobile) ? "'".$this->db->escape($this->phone_mobile)."'" : "null");
|
|
|
$sql .= ", priv = '".$this->db->escape($this->priv)."'";
|
|
|
$sql .= ", fk_prospectcontactlevel = '".$this->db->escape($this->fk_prospectlevel)."'";
|
|
|
- if (isset($this->stcomm_id))
|
|
|
- {
|
|
|
+ if (isset($this->stcomm_id)) {
|
|
|
$sql .= ", fk_stcommcontact = ".($this->stcomm_id > 0 || $this->stcomm_id == -1 ? $this->stcomm_id : "0");
|
|
|
}
|
|
|
$sql .= ", statut = ".$this->db->escape($this->statut);
|
|
@@ -598,8 +599,7 @@ class Contact extends CommonObject
|
|
|
|
|
|
dol_syslog(get_class($this)."::update", LOG_DEBUG);
|
|
|
$result = $this->db->query($sql);
|
|
|
- if ($result)
|
|
|
- {
|
|
|
+ if ($result) {
|
|
|
unset($this->country_code);
|
|
|
unset($this->country);
|
|
|
unset($this->state_code);
|
|
@@ -608,25 +608,21 @@ class Contact extends CommonObject
|
|
|
$action = 'update';
|
|
|
|
|
|
// Actions on extra fields
|
|
|
- if (!$error)
|
|
|
- {
|
|
|
+ if (!$error) {
|
|
|
$result = $this->insertExtraFields();
|
|
|
- if ($result < 0)
|
|
|
- {
|
|
|
+ if ($result < 0) {
|
|
|
$error++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (!$error) {
|
|
|
$result = $this->updateRoles();
|
|
|
- if ($result < 0)
|
|
|
- {
|
|
|
+ if ($result < 0) {
|
|
|
$error++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (!$error && $this->user_id > 0)
|
|
|
- {
|
|
|
+ if (!$error && $this->user_id > 0) {
|
|
|
// If contact is linked to a user
|
|
|
$tmpobj = new User($this->db);
|
|
|
$tmpobj->fetch($this->user_id);
|
|
@@ -685,14 +681,18 @@ class Contact extends CommonObject
|
|
|
// }
|
|
|
if ($usermustbemodified) {
|
|
|
$result = $tmpobj->update($user, 0, 1, 1, 1);
|
|
|
- if ($result < 0) { $error++; }
|
|
|
+ if ($result < 0) {
|
|
|
+ $error++;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (!$error && !$notrigger) {
|
|
|
// Call trigger
|
|
|
$result = $this->call_trigger('CONTACT_MODIFY', $user);
|
|
|
- if ($result < 0) { $error++; }
|
|
|
+ if ($result < 0) {
|
|
|
+ $error++;
|
|
|
+ }
|
|
|
// End call triggers
|
|
|
}
|
|
|
|
|
@@ -759,34 +759,69 @@ class Contact extends CommonObject
|
|
|
$this->fullname = $this->getFullName($langs);
|
|
|
|
|
|
// Fields
|
|
|
- if ($this->fullname && !empty($conf->global->LDAP_CONTACT_FIELD_FULLNAME)) $info[$conf->global->LDAP_CONTACT_FIELD_FULLNAME] = $this->fullname;
|
|
|
- if ($this->lastname && !empty($conf->global->LDAP_CONTACT_FIELD_NAME)) $info[$conf->global->LDAP_CONTACT_FIELD_NAME] = $this->lastname;
|
|
|
- if ($this->firstname && !empty($conf->global->LDAP_CONTACT_FIELD_FIRSTNAME)) $info[$conf->global->LDAP_CONTACT_FIELD_FIRSTNAME] = $this->firstname;
|
|
|
+ if ($this->fullname && !empty($conf->global->LDAP_CONTACT_FIELD_FULLNAME)) {
|
|
|
+ $info[$conf->global->LDAP_CONTACT_FIELD_FULLNAME] = $this->fullname;
|
|
|
+ }
|
|
|
+ if ($this->lastname && !empty($conf->global->LDAP_CONTACT_FIELD_NAME)) {
|
|
|
+ $info[$conf->global->LDAP_CONTACT_FIELD_NAME] = $this->lastname;
|
|
|
+ }
|
|
|
+ if ($this->firstname && !empty($conf->global->LDAP_CONTACT_FIELD_FIRSTNAME)) {
|
|
|
+ $info[$conf->global->LDAP_CONTACT_FIELD_FIRSTNAME] = $this->firstname;
|
|
|
+ }
|
|
|
|
|
|
- if ($this->poste) $info["title"] = $this->poste;
|
|
|
+ if ($this->poste) {
|
|
|
+ $info["title"] = $this->poste;
|
|
|
+ }
|
|
|
if ($this->socid > 0) {
|
|
|
$soc = new Societe($this->db);
|
|
|
$soc->fetch($this->socid);
|
|
|
|
|
|
$info[$conf->global->LDAP_CONTACT_FIELD_COMPANY] = $soc->name;
|
|
|
- if ($soc->client == 1) $info["businessCategory"] = "Customers";
|
|
|
- if ($soc->client == 2) $info["businessCategory"] = "Prospects";
|
|
|
- if ($soc->fournisseur == 1) $info["businessCategory"] = "Suppliers";
|
|
|
- }
|
|
|
- if ($this->address && !empty($conf->global->LDAP_CONTACT_FIELD_ADDRESS)) $info[$conf->global->LDAP_CONTACT_FIELD_ADDRESS] = $this->address;
|
|
|
- if ($this->zip && !empty($conf->global->LDAP_CONTACT_FIELD_ZIP)) $info[$conf->global->LDAP_CONTACT_FIELD_ZIP] = $this->zip;
|
|
|
- if ($this->town && !empty($conf->global->LDAP_CONTACT_FIELD_TOWN)) $info[$conf->global->LDAP_CONTACT_FIELD_TOWN] = $this->town;
|
|
|
- if ($this->country_code && !empty($conf->global->LDAP_CONTACT_FIELD_COUNTRY)) $info[$conf->global->LDAP_CONTACT_FIELD_COUNTRY] = $this->country_code;
|
|
|
- if ($this->phone_pro && !empty($conf->global->LDAP_CONTACT_FIELD_PHONE)) $info[$conf->global->LDAP_CONTACT_FIELD_PHONE] = $this->phone_pro;
|
|
|
- if ($this->phone_perso && !empty($conf->global->LDAP_CONTACT_FIELD_HOMEPHONE)) $info[$conf->global->LDAP_CONTACT_FIELD_HOMEPHONE] = $this->phone_perso;
|
|
|
- if ($this->phone_mobile && !empty($conf->global->LDAP_CONTACT_FIELD_MOBILE)) $info[$conf->global->LDAP_CONTACT_FIELD_MOBILE] = $this->phone_mobile;
|
|
|
- if ($this->fax && !empty($conf->global->LDAP_CONTACT_FIELD_FAX)) $info[$conf->global->LDAP_CONTACT_FIELD_FAX] = $this->fax;
|
|
|
- if ($this->skype && !empty($conf->global->LDAP_CONTACT_FIELD_SKYPE)) $info[$conf->global->LDAP_CONTACT_FIELD_SKYPE] = $this->skype;
|
|
|
- if ($this->note_private && !empty($conf->global->LDAP_CONTACT_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_CONTACT_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note_private, 2);
|
|
|
- if ($this->email && !empty($conf->global->LDAP_CONTACT_FIELD_MAIL)) $info[$conf->global->LDAP_CONTACT_FIELD_MAIL] = $this->email;
|
|
|
-
|
|
|
- if ($conf->global->LDAP_SERVER_TYPE == 'egroupware')
|
|
|
- {
|
|
|
+ if ($soc->client == 1) {
|
|
|
+ $info["businessCategory"] = "Customers";
|
|
|
+ }
|
|
|
+ if ($soc->client == 2) {
|
|
|
+ $info["businessCategory"] = "Prospects";
|
|
|
+ }
|
|
|
+ if ($soc->fournisseur == 1) {
|
|
|
+ $info["businessCategory"] = "Suppliers";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($this->address && !empty($conf->global->LDAP_CONTACT_FIELD_ADDRESS)) {
|
|
|
+ $info[$conf->global->LDAP_CONTACT_FIELD_ADDRESS] = $this->address;
|
|
|
+ }
|
|
|
+ if ($this->zip && !empty($conf->global->LDAP_CONTACT_FIELD_ZIP)) {
|
|
|
+ $info[$conf->global->LDAP_CONTACT_FIELD_ZIP] = $this->zip;
|
|
|
+ }
|
|
|
+ if ($this->town && !empty($conf->global->LDAP_CONTACT_FIELD_TOWN)) {
|
|
|
+ $info[$conf->global->LDAP_CONTACT_FIELD_TOWN] = $this->town;
|
|
|
+ }
|
|
|
+ if ($this->country_code && !empty($conf->global->LDAP_CONTACT_FIELD_COUNTRY)) {
|
|
|
+ $info[$conf->global->LDAP_CONTACT_FIELD_COUNTRY] = $this->country_code;
|
|
|
+ }
|
|
|
+ if ($this->phone_pro && !empty($conf->global->LDAP_CONTACT_FIELD_PHONE)) {
|
|
|
+ $info[$conf->global->LDAP_CONTACT_FIELD_PHONE] = $this->phone_pro;
|
|
|
+ }
|
|
|
+ if ($this->phone_perso && !empty($conf->global->LDAP_CONTACT_FIELD_HOMEPHONE)) {
|
|
|
+ $info[$conf->global->LDAP_CONTACT_FIELD_HOMEPHONE] = $this->phone_perso;
|
|
|
+ }
|
|
|
+ if ($this->phone_mobile && !empty($conf->global->LDAP_CONTACT_FIELD_MOBILE)) {
|
|
|
+ $info[$conf->global->LDAP_CONTACT_FIELD_MOBILE] = $this->phone_mobile;
|
|
|
+ }
|
|
|
+ if ($this->fax && !empty($conf->global->LDAP_CONTACT_FIELD_FAX)) {
|
|
|
+ $info[$conf->global->LDAP_CONTACT_FIELD_FAX] = $this->fax;
|
|
|
+ }
|
|
|
+ if ($this->skype && !empty($conf->global->LDAP_CONTACT_FIELD_SKYPE)) {
|
|
|
+ $info[$conf->global->LDAP_CONTACT_FIELD_SKYPE] = $this->skype;
|
|
|
+ }
|
|
|
+ if ($this->note_private && !empty($conf->global->LDAP_CONTACT_FIELD_DESCRIPTION)) {
|
|
|
+ $info[$conf->global->LDAP_CONTACT_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note_private, 2);
|
|
|
+ }
|
|
|
+ if ($this->email && !empty($conf->global->LDAP_CONTACT_FIELD_MAIL)) {
|
|
|
+ $info[$conf->global->LDAP_CONTACT_FIELD_MAIL] = $this->email;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($conf->global->LDAP_SERVER_TYPE == 'egroupware') {
|
|
|
$info["objectclass"][4] = "phpgwContact"; // compatibilite egroupware
|
|
|
|
|
|
$info['uidnumber'] = $this->id;
|
|
@@ -805,8 +840,12 @@ class Contact extends CommonObject
|
|
|
|
|
|
$info["phpgwContactOwner"] = $this->egroupware_id;
|
|
|
|
|
|
- if ($this->email) $info["rfc822Mailbox"] = $this->email;
|
|
|
- if ($this->phone_mobile) $info["phpgwCellTelephoneNumber"] = $this->phone_mobile;
|
|
|
+ if ($this->email) {
|
|
|
+ $info["rfc822Mailbox"] = $this->email;
|
|
|
+ }
|
|
|
+ if ($this->phone_mobile) {
|
|
|
+ $info["phpgwCellTelephoneNumber"] = $this->phone_mobile;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return $info;
|
|
@@ -834,13 +873,14 @@ class Contact extends CommonObject
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET";
|
|
|
$sql .= " birthday=".($this->birthday ? "'".$this->db->idate($this->birthday)."'" : "null");
|
|
|
$sql .= ", photo = ".($this->photo ? "'".$this->db->escape($this->photo)."'" : "null");
|
|
|
- if ($user) $sql .= ", fk_user_modif=".$user->id;
|
|
|
+ if ($user) {
|
|
|
+ $sql .= ", fk_user_modif=".$user->id;
|
|
|
+ }
|
|
|
$sql .= " WHERE rowid=".$this->db->escape($id);
|
|
|
|
|
|
dol_syslog(get_class($this)."::update_perso this->birthday=".$this->birthday." -", LOG_DEBUG);
|
|
|
$resql = $this->db->query($sql);
|
|
|
- if (!$resql)
|
|
|
- {
|
|
|
+ if (!$resql) {
|
|
|
$error++;
|
|
|
$this->error = $this->db->lasterror();
|
|
|
}
|
|
@@ -875,7 +915,9 @@ class Contact extends CommonObject
|
|
|
if (!$error && !$notrigger) {
|
|
|
// Call trigger
|
|
|
$result = $this->call_trigger('CONTACT_MODIFY', $user);
|
|
|
- if ($result < 0) { $error++; }
|
|
|
+ if ($result < 0) {
|
|
|
+ $error++;
|
|
|
+ }
|
|
|
// End call triggers
|
|
|
}
|
|
|
|
|
@@ -906,8 +948,7 @@ class Contact extends CommonObject
|
|
|
|
|
|
dol_syslog(get_class($this)."::fetch id=".$id." ref_ext=".$ref_ext." email=".$email, LOG_DEBUG);
|
|
|
|
|
|
- if (empty($id) && empty($ref_ext) && empty($email))
|
|
|
- {
|
|
|
+ if (empty($id) && empty($ref_ext) && empty($email)) {
|
|
|
$this->error = 'BadParameter';
|
|
|
return -1;
|
|
|
}
|
|
@@ -936,8 +977,9 @@ class Contact extends CommonObject
|
|
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON c.rowid = u.fk_socpeople";
|
|
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid";
|
|
|
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcommcontact as st ON c.fk_stcommcontact = st.id';
|
|
|
- if ($id) $sql .= " WHERE c.rowid = ".((int) $id);
|
|
|
- else {
|
|
|
+ if ($id) {
|
|
|
+ $sql .= " WHERE c.rowid = ".((int) $id);
|
|
|
+ } else {
|
|
|
$sql .= " WHERE c.entity IN (".getEntity($this->element).")";
|
|
|
if ($ref_ext) {
|
|
|
$sql .= " AND c.ref_ext = '".$this->db->escape($ref_ext)."'";
|
|
@@ -948,17 +990,14 @@ class Contact extends CommonObject
|
|
|
}
|
|
|
|
|
|
$resql = $this->db->query($sql);
|
|
|
- if ($resql)
|
|
|
- {
|
|
|
+ if ($resql) {
|
|
|
$num = $this->db->num_rows($resql);
|
|
|
- if ($num > 1)
|
|
|
- {
|
|
|
+ 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
|
|
|
- {
|
|
|
+ } elseif ($num) { // $num = 1
|
|
|
$obj = $this->db->fetch_object($resql);
|
|
|
|
|
|
$this->id = $obj->rowid;
|
|
@@ -1030,10 +1069,8 @@ class Contact extends CommonObject
|
|
|
$sql .= " WHERE u.fk_socpeople = ".$this->id;
|
|
|
|
|
|
$resql = $this->db->query($sql);
|
|
|
- if ($resql)
|
|
|
- {
|
|
|
- if ($this->db->num_rows($resql))
|
|
|
- {
|
|
|
+ if ($resql) {
|
|
|
+ if ($this->db->num_rows($resql)) {
|
|
|
$uobj = $this->db->fetch_object($resql);
|
|
|
|
|
|
$this->user_id = $uobj->rowid;
|
|
@@ -1049,17 +1086,14 @@ class Contact extends CommonObject
|
|
|
$this->fetch_optionals();
|
|
|
|
|
|
// Load also alerts of this user
|
|
|
- if ($user)
|
|
|
- {
|
|
|
+ if ($user) {
|
|
|
$sql = "SELECT fk_user";
|
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."user_alert";
|
|
|
$sql .= " WHERE fk_user = ".$user->id." AND fk_contact = ".$this->db->escape($id);
|
|
|
|
|
|
$resql = $this->db->query($sql);
|
|
|
- if ($resql)
|
|
|
- {
|
|
|
- if ($this->db->num_rows($resql))
|
|
|
- {
|
|
|
+ if ($resql) {
|
|
|
+ if ($this->db->num_rows($resql)) {
|
|
|
$obj = $this->db->fetch_object($resql);
|
|
|
|
|
|
$this->birthday_alert = 1;
|
|
@@ -1102,11 +1136,9 @@ class Contact extends CommonObject
|
|
|
{
|
|
|
unset($this->gender);
|
|
|
|
|
|
- if (in_array($this->civility_id, array('MR')) || in_array($this->civility_code, array('MR')))
|
|
|
- {
|
|
|
+ if (in_array($this->civility_id, array('MR')) || in_array($this->civility_code, array('MR'))) {
|
|
|
$this->gender = 'man';
|
|
|
- } elseif (in_array($this->civility_id, array('MME', 'MLE')) || in_array($this->civility_code, array('MME', 'MLE')))
|
|
|
- {
|
|
|
+ } elseif (in_array($this->civility_id, array('MME', 'MLE')) || in_array($this->civility_code, array('MME', 'MLE'))) {
|
|
|
$this->gender = 'woman';
|
|
|
}
|
|
|
}
|
|
@@ -1135,16 +1167,18 @@ class Contact extends CommonObject
|
|
|
dol_syslog(get_class($this)."::load_ref_elements", LOG_DEBUG);
|
|
|
|
|
|
$resql = $this->db->query($sql);
|
|
|
- if ($resql)
|
|
|
- {
|
|
|
- while ($obj = $this->db->fetch_object($resql))
|
|
|
- {
|
|
|
- if ($obj->nb)
|
|
|
- {
|
|
|
- if ($obj->element == 'facture') $this->ref_facturation = $obj->nb;
|
|
|
- elseif ($obj->element == 'contrat') $this->ref_contrat = $obj->nb;
|
|
|
- elseif ($obj->element == 'commande') $this->ref_commande = $obj->nb;
|
|
|
- elseif ($obj->element == 'propal') $this->ref_propal = $obj->nb;
|
|
|
+ if ($resql) {
|
|
|
+ while ($obj = $this->db->fetch_object($resql)) {
|
|
|
+ if ($obj->nb) {
|
|
|
+ if ($obj->element == 'facture') {
|
|
|
+ $this->ref_facturation = $obj->nb;
|
|
|
+ } elseif ($obj->element == 'contrat') {
|
|
|
+ $this->ref_contrat = $obj->nb;
|
|
|
+ } elseif ($obj->element == 'commande') {
|
|
|
+ $this->ref_commande = $obj->nb;
|
|
|
+ } elseif ($obj->element == 'propal') {
|
|
|
+ $this->ref_propal = $obj->nb;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
$this->db->free($resql);
|
|
@@ -1169,8 +1203,7 @@ class Contact extends CommonObject
|
|
|
|
|
|
$this->db->begin();
|
|
|
|
|
|
- if (!$error)
|
|
|
- {
|
|
|
+ if (!$error) {
|
|
|
// Get all rowid of element_contact linked to a type that is link to llx_socpeople
|
|
|
$sql = "SELECT ec.rowid";
|
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."element_contact ec,";
|
|
@@ -1180,21 +1213,18 @@ class Contact extends CommonObject
|
|
|
$sql .= " AND tc.source='external'";
|
|
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
|
|
$resql = $this->db->query($sql);
|
|
|
- if ($resql)
|
|
|
- {
|
|
|
+ if ($resql) {
|
|
|
$num = $this->db->num_rows($resql);
|
|
|
|
|
|
$i = 0;
|
|
|
- while ($i < $num && !$error)
|
|
|
- {
|
|
|
+ while ($i < $num && !$error) {
|
|
|
$obj = $this->db->fetch_object($resql);
|
|
|
|
|
|
$sqldel = "DELETE FROM ".MAIN_DB_PREFIX."element_contact";
|
|
|
$sqldel .= " WHERE rowid = ".$obj->rowid;
|
|
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
|
|
$result = $this->db->query($sqldel);
|
|
|
- if (!$result)
|
|
|
- {
|
|
|
+ if (!$result) {
|
|
|
$error++;
|
|
|
$this->error = $this->db->error().' sql='.$sqldel;
|
|
|
}
|
|
@@ -1207,56 +1237,48 @@ class Contact extends CommonObject
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (!$error)
|
|
|
- {
|
|
|
+ if (!$error) {
|
|
|
// Remove Roles
|
|
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_contacts WHERE fk_socpeople = ".$this->id;
|
|
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
|
|
$resql = $this->db->query($sql);
|
|
|
- if (!$resql)
|
|
|
- {
|
|
|
+ if (!$resql) {
|
|
|
$error++;
|
|
|
$this->error .= $this->db->lasterror();
|
|
|
$errorflag = -1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (!$error)
|
|
|
- {
|
|
|
+ if (!$error) {
|
|
|
// Remove Roles
|
|
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_contacts WHERE fk_socpeople = ".$this->id;
|
|
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
|
|
$resql = $this->db->query($sql);
|
|
|
- if (!$resql)
|
|
|
- {
|
|
|
+ if (!$resql) {
|
|
|
$error++;
|
|
|
$this->error .= $this->db->lasterror();
|
|
|
$errorflag = -1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (!$error)
|
|
|
- {
|
|
|
+ if (!$error) {
|
|
|
// Remove category
|
|
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_contact WHERE fk_socpeople = ".$this->id;
|
|
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
|
|
$resql = $this->db->query($sql);
|
|
|
- if (!$resql)
|
|
|
- {
|
|
|
+ if (!$resql) {
|
|
|
$error++;
|
|
|
$this->error .= $this->db->lasterror();
|
|
|
$errorflag = -1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (!$error)
|
|
|
- {
|
|
|
+ if (!$error) {
|
|
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."socpeople";
|
|
|
$sql .= " WHERE rowid=".$this->id;
|
|
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
|
|
$result = $this->db->query($sql);
|
|
|
- if (!$result)
|
|
|
- {
|
|
|
+ if (!$result) {
|
|
|
$error++;
|
|
|
$this->error = $this->db->error().' sql='.$sql;
|
|
|
}
|
|
@@ -1266,19 +1288,21 @@ class Contact extends CommonObject
|
|
|
if (!$error) {
|
|
|
// For avoid conflicts if trigger used
|
|
|
$result = $this->deleteExtraFields();
|
|
|
- if ($result < 0) $error++;
|
|
|
+ if ($result < 0) {
|
|
|
+ $error++;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- if (!$error && !$notrigger)
|
|
|
- {
|
|
|
+ if (!$error && !$notrigger) {
|
|
|
// Call trigger
|
|
|
$result = $this->call_trigger('CONTACT_DELETE', $user);
|
|
|
- if ($result < 0) { $error++; }
|
|
|
+ if ($result < 0) {
|
|
|
+ $error++;
|
|
|
+ }
|
|
|
// End call triggers
|
|
|
}
|
|
|
|
|
|
- if (!$error)
|
|
|
- {
|
|
|
+ if (!$error) {
|
|
|
$this->db->commit();
|
|
|
return 1;
|
|
|
} else {
|
|
@@ -1303,10 +1327,8 @@ class Contact extends CommonObject
|
|
|
$sql .= " WHERE c.rowid = ".$this->db->escape($id);
|
|
|
|
|
|
$resql = $this->db->query($sql);
|
|
|
- if ($resql)
|
|
|
- {
|
|
|
- if ($this->db->num_rows($resql))
|
|
|
- {
|
|
|
+ if ($resql) {
|
|
|
+ if ($this->db->num_rows($resql)) {
|
|
|
$obj = $this->db->fetch_object($resql);
|
|
|
|
|
|
$this->id = $obj->rowid;
|
|
@@ -1346,8 +1368,7 @@ class Contact extends CommonObject
|
|
|
$sql .= " AND m.entity IN (".getEntity($this->element).") AND mc.statut NOT IN (-1,0)"; // -1 error, 0 not sent, 1 sent with success
|
|
|
|
|
|
$resql = $this->db->query($sql);
|
|
|
- if ($resql)
|
|
|
- {
|
|
|
+ if ($resql) {
|
|
|
$obj = $this->db->fetch_object($resql);
|
|
|
$nb = $obj->nb;
|
|
|
|
|
@@ -1377,8 +1398,7 @@ class Contact extends CommonObject
|
|
|
|
|
|
$result = ''; $label = '';
|
|
|
|
|
|
- if (!empty($this->photo) && class_exists('Form'))
|
|
|
- {
|
|
|
+ if (!empty($this->photo) && class_exists('Form')) {
|
|
|
$label .= '<div class="photointooltip">';
|
|
|
$label .= Form::showphoto('contact', $this, 0, 40, 0, '', 'mini', 0); // Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip.
|
|
|
$label .= '</div><div style="clear: both;"></div>';
|
|
@@ -1388,67 +1408,83 @@ class Contact extends CommonObject
|
|
|
$label .= ' '.$this->getLibStatut(4);
|
|
|
$label .= '<br><b>'.$langs->trans("Name").':</b> '.$this->getFullName($langs);
|
|
|
//if ($this->civility_id) $label.= '<br><b>' . $langs->trans("Civility") . ':</b> '.$this->civility_id; // TODO Translate cibilty_id code
|
|
|
- if (!empty($this->poste)) $label .= '<br><b>'.$langs->trans("Poste").':</b> '.$this->poste;
|
|
|
+ if (!empty($this->poste)) {
|
|
|
+ $label .= '<br><b>'.$langs->trans("Poste").':</b> '.$this->poste;
|
|
|
+ }
|
|
|
$label .= '<br><b>'.$langs->trans("EMail").':</b> '.$this->email;
|
|
|
$phonelist = array();
|
|
|
$country_code = empty($this->country_code) ? '': $this->country_code;
|
|
|
- if ($this->phone_pro) $phonelist[] = dol_print_phone($this->phone_pro, $country_code, $this->id, 0, '', ' ', 'phone');
|
|
|
- if ($this->phone_mobile) $phonelist[] = dol_print_phone($this->phone_mobile, $country_code, $this->id, 0, '', ' ', 'mobile');
|
|
|
- if ($this->phone_perso) $phonelist[] = dol_print_phone($this->phone_perso, $country_code, $this->id, 0, '', ' ', 'phone');
|
|
|
+ if ($this->phone_pro) {
|
|
|
+ $phonelist[] = dol_print_phone($this->phone_pro, $country_code, $this->id, 0, '', ' ', 'phone');
|
|
|
+ }
|
|
|
+ if ($this->phone_mobile) {
|
|
|
+ $phonelist[] = dol_print_phone($this->phone_mobile, $country_code, $this->id, 0, '', ' ', 'mobile');
|
|
|
+ }
|
|
|
+ if ($this->phone_perso) {
|
|
|
+ $phonelist[] = dol_print_phone($this->phone_perso, $country_code, $this->id, 0, '', ' ', 'phone');
|
|
|
+ }
|
|
|
$label .= '<br><b>'.$langs->trans("Phone").':</b> '.implode(' ', $phonelist);
|
|
|
$label .= '<br><b>'.$langs->trans("Address").':</b> '.dol_format_address($this, 1, ' ', $langs);
|
|
|
|
|
|
$url = DOL_URL_ROOT.'/contact/card.php?id='.$this->id;
|
|
|
|
|
|
- if ($option !== 'nolink')
|
|
|
- {
|
|
|
+ if ($option !== 'nolink') {
|
|
|
// Add param to save lastsearch_values or not
|
|
|
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
|
|
|
- if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
|
|
|
- if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
|
|
|
+ if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
|
|
|
+ $add_save_lastsearch_values = 1;
|
|
|
+ }
|
|
|
+ if ($add_save_lastsearch_values) {
|
|
|
+ $url .= '&save_lastsearch_values=1';
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
$url .= $moreparam;
|
|
|
|
|
|
$linkclose = "";
|
|
|
if (empty($notooltip)) {
|
|
|
- if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
|
|
|
- {
|
|
|
+ if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
|
|
|
$label = $langs->trans("ShowContact");
|
|
|
$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
|
|
|
}
|
|
|
- $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
|
|
|
- $linkclose .= ' class="classfortooltip"';
|
|
|
-
|
|
|
- /*
|
|
|
- $hookmanager->initHooks(array('contactdao'));
|
|
|
- $parameters=array('id'=>$this->id);
|
|
|
- $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
|
|
- if ($reshook > 0) $linkclose = $hookmanager->resPrint;
|
|
|
- */
|
|
|
+ $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
|
|
|
+ $linkclose .= ' class="classfortooltip"';
|
|
|
+
|
|
|
+ /*
|
|
|
+ $hookmanager->initHooks(array('contactdao'));
|
|
|
+ $parameters=array('id'=>$this->id);
|
|
|
+ $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
|
|
+ if ($reshook > 0) $linkclose = $hookmanager->resPrint;
|
|
|
+ */
|
|
|
}
|
|
|
|
|
|
$linkstart = '<a href="'.$url.'"';
|
|
|
$linkstart .= $linkclose.'>';
|
|
|
$linkend = '</a>';
|
|
|
|
|
|
- if ($option == 'xxx')
|
|
|
- {
|
|
|
+ if ($option == 'xxx') {
|
|
|
$linkstart = '<a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$this->id.$moreparam.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
|
|
|
$linkend = '</a>';
|
|
|
}
|
|
|
|
|
|
$result .= $linkstart;
|
|
|
- if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
|
|
|
- if ($withpicto != 2) $result .= ($maxlen ?dol_trunc($this->getFullName($langs), $maxlen) : $this->getFullName($langs));
|
|
|
+ if ($withpicto) {
|
|
|
+ $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
|
|
|
+ }
|
|
|
+ if ($withpicto != 2) {
|
|
|
+ $result .= ($maxlen ?dol_trunc($this->getFullName($langs), $maxlen) : $this->getFullName($langs));
|
|
|
+ }
|
|
|
$result .= $linkend;
|
|
|
|
|
|
global $action;
|
|
|
$hookmanager->initHooks(array('contactdao'));
|
|
|
$parameters = array('id'=>$this->id, 'getnomurl'=>$result);
|
|
|
$reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
|
|
- if ($reshook > 0) $result = $hookmanager->resPrint;
|
|
|
- else $result .= $hookmanager->resPrint;
|
|
|
+ if ($reshook > 0) {
|
|
|
+ $result = $hookmanager->resPrint;
|
|
|
+ } else {
|
|
|
+ $result .= $hookmanager->resPrint;
|
|
|
+ }
|
|
|
|
|
|
return $result;
|
|
|
}
|
|
@@ -1463,7 +1499,9 @@ class Contact extends CommonObject
|
|
|
global $langs;
|
|
|
|
|
|
$code = ($this->civility_code ? $this->civility_code : (!empty($this->civility_id) ? $this->civility : (!empty($this->civilite) ? $this->civilite : '')));
|
|
|
- if (empty($code)) return '';
|
|
|
+ if (empty($code)) {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
|
|
|
$langs->load("dict");
|
|
|
return $langs->getLabelFromKey($this->db, "Civility".$code, "c_civility", "code", "label", $code);
|
|
@@ -1507,7 +1545,9 @@ class Contact extends CommonObject
|
|
|
);
|
|
|
|
|
|
$statusType = 'status4';
|
|
|
- if ($status == 0 || $status == 5) $statusType = 'status5';
|
|
|
+ if ($status == 0 || $status == 5) {
|
|
|
+ $statusType = 'status5';
|
|
|
+ }
|
|
|
|
|
|
$label = $langs->trans($labelStatus[$status]);
|
|
|
$labelshort = $langs->trans($labelStatusShort[$status]);
|
|
@@ -1527,8 +1567,11 @@ class Contact extends CommonObject
|
|
|
{
|
|
|
// phpcs:enable
|
|
|
global $langs;
|
|
|
- if ($status == '1') return $langs->trans('ContactPrivate');
|
|
|
- else return $langs->trans('ContactPublic');
|
|
|
+ if ($status == '1') {
|
|
|
+ return $langs->trans('ContactPrivate');
|
|
|
+ } else {
|
|
|
+ return $langs->trans('ContactPublic');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -1547,7 +1590,9 @@ class Contact extends CommonObject
|
|
|
$resql = $this->db->query($sql);
|
|
|
if ($resql) {
|
|
|
$obj = $this->db->fetch_object($resql);
|
|
|
- if ($obj) $socid = $obj->rowid;
|
|
|
+ if ($obj) {
|
|
|
+ $socid = $obj->rowid;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Initialise parameters
|
|
@@ -1592,8 +1637,11 @@ class Contact extends CommonObject
|
|
|
$error = 0;
|
|
|
|
|
|
// Check parameters
|
|
|
- if ($this->statut == $status) return 0;
|
|
|
- else $this->statut = $status;
|
|
|
+ if ($this->statut == $status) {
|
|
|
+ return 0;
|
|
|
+ } else {
|
|
|
+ $this->statut = $status;
|
|
|
+ }
|
|
|
|
|
|
$this->db->begin();
|
|
|
|
|
@@ -1604,16 +1652,16 @@ class Contact extends CommonObject
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
dol_syslog(get_class($this)."::setstatus", LOG_DEBUG);
|
|
|
- if ($result)
|
|
|
- {
|
|
|
+ if ($result) {
|
|
|
// Call trigger
|
|
|
$result = $this->call_trigger('CONTACT_ENABLEDISABLE', $user);
|
|
|
- if ($result < 0) { $error++; }
|
|
|
+ if ($result < 0) {
|
|
|
+ $error++;
|
|
|
+ }
|
|
|
// End call triggers
|
|
|
}
|
|
|
|
|
|
- if ($error)
|
|
|
- {
|
|
|
+ if ($error) {
|
|
|
$this->db->rollback();
|
|
|
return -$error;
|
|
|
} else {
|
|
@@ -1725,12 +1773,10 @@ class Contact extends CommonObject
|
|
|
|
|
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
|
|
$resql = $this->db->query($sql);
|
|
|
- if ($resql)
|
|
|
- {
|
|
|
+ if ($resql) {
|
|
|
$num = $this->db->num_rows($resql);
|
|
|
$i = 0;
|
|
|
- while ($i < $num)
|
|
|
- {
|
|
|
+ while ($i < $num) {
|
|
|
$obj = $this->db->fetch_object($resql);
|
|
|
$tab[] = array('fk_socpeople'=>$obj->id, 'type_contact'=>$obj->fk_c_type_contact);
|
|
|
|
|
@@ -1758,7 +1804,9 @@ class Contact extends CommonObject
|
|
|
|
|
|
$error = 0;
|
|
|
|
|
|
- if (!isset($this->roles)) return; // Avoid to loose roles when property not set
|
|
|
+ if (!isset($this->roles)) {
|
|
|
+ return; // Avoid to loose roles when property not set
|
|
|
+ }
|
|
|
|
|
|
$this->db->begin();
|
|
|
|
|
@@ -1800,8 +1848,7 @@ class Contact extends CommonObject
|
|
|
$sql .= ")";
|
|
|
|
|
|
$result = $this->db->query($sql);
|
|
|
- if (!$result)
|
|
|
- {
|
|
|
+ if (!$result) {
|
|
|
$this->errors[] = $this->db->lasterror().' sql='.$sql;
|
|
|
$error++;
|
|
|
}
|
|
@@ -1830,12 +1877,13 @@ class Contact extends CommonObject
|
|
|
global $langs;
|
|
|
|
|
|
$sql = "SELECT id, code, libelle as label, picto FROM ".MAIN_DB_PREFIX."c_stcommcontact";
|
|
|
- if ($active >= 0) $sql .= " WHERE active = ".$active;
|
|
|
+ if ($active >= 0) {
|
|
|
+ $sql .= " WHERE active = ".$active;
|
|
|
+ }
|
|
|
$resql = $this->db->query($sql);
|
|
|
$num = $this->db->num_rows($resql);
|
|
|
$i = 0;
|
|
|
- while ($i < $num)
|
|
|
- {
|
|
|
+ while ($i < $num) {
|
|
|
$obj = $this->db->fetch_object($resql);
|
|
|
$this->cacheprospectstatus[$obj->id] = array('id' => $obj->id, 'code' => $obj->code, 'label' => ($langs->trans("ST_".strtoupper($obj->code)) == "ST_".strtoupper($obj->code)) ? $obj->label : $langs->trans("ST_".strtoupper($obj->code)), 'picto' => $obj->picto);
|
|
|
$i++;
|
|
@@ -1865,8 +1913,7 @@ class Contact extends CommonObject
|
|
|
|
|
|
$lib = $langs->trans("ProspectLevel".$fk_prospectlevel);
|
|
|
// If lib not found in language file, we get label from cache/databse
|
|
|
- if ($lib == $langs->trans("ProspectLevel".$fk_prospectlevel))
|
|
|
- {
|
|
|
+ if ($lib == $langs->trans("ProspectLevel".$fk_prospectlevel)) {
|
|
|
$lib = $langs->getLabelFromKey($this->db, $fk_prospectlevel, 'c_prospectlevel', 'code', 'label');
|
|
|
}
|
|
|
return $lib;
|
|
@@ -1915,36 +1962,48 @@ class Contact extends CommonObject
|
|
|
global $langs;
|
|
|
$langs->load('customers');
|
|
|
|
|
|
- if ($mode == 2)
|
|
|
- {
|
|
|
- if ($statut == '-1' || $statut == 'ST_NO') return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1");
|
|
|
- elseif ($statut == '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0");
|
|
|
- elseif ($statut == '1' || $statut == 'ST_TODO') return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1");
|
|
|
- elseif ($statut == '2' || $statut == 'ST_PEND') return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2");
|
|
|
- elseif ($statut == '3' || $statut == 'ST_DONE') return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3");
|
|
|
- else {
|
|
|
+ if ($mode == 2) {
|
|
|
+ if ($statut == '-1' || $statut == 'ST_NO') {
|
|
|
+ return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1");
|
|
|
+ } elseif ($statut == '0' || $statut == 'ST_NEVER') {
|
|
|
+ return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0");
|
|
|
+ } elseif ($statut == '1' || $statut == 'ST_TODO') {
|
|
|
+ return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1");
|
|
|
+ } elseif ($statut == '2' || $statut == 'ST_PEND') {
|
|
|
+ return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2");
|
|
|
+ } elseif ($statut == '3' || $statut == 'ST_DONE') {
|
|
|
+ return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3");
|
|
|
+ } else {
|
|
|
return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0, $picto).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label);
|
|
|
}
|
|
|
}
|
|
|
- if ($mode == 3)
|
|
|
- {
|
|
|
- if ($statut == '-1' || $statut == 'ST_NO') return img_action($langs->trans("StatusProspect-1"), -1, $picto);
|
|
|
- elseif ($statut == '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0, $picto);
|
|
|
- elseif ($statut == '1' || $statut == 'ST_TODO') return img_action($langs->trans("StatusProspect1"), 1, $picto);
|
|
|
- elseif ($statut == '2' || $statut == 'ST_PEND') return img_action($langs->trans("StatusProspect2"), 2, $picto);
|
|
|
- elseif ($statut == '3' || $statut == 'ST_DONE') return img_action($langs->trans("StatusProspect3"), 3, $picto);
|
|
|
- else {
|
|
|
+ if ($mode == 3) {
|
|
|
+ if ($statut == '-1' || $statut == 'ST_NO') {
|
|
|
+ return img_action($langs->trans("StatusProspect-1"), -1, $picto);
|
|
|
+ } elseif ($statut == '0' || $statut == 'ST_NEVER') {
|
|
|
+ return img_action($langs->trans("StatusProspect0"), 0, $picto);
|
|
|
+ } elseif ($statut == '1' || $statut == 'ST_TODO') {
|
|
|
+ return img_action($langs->trans("StatusProspect1"), 1, $picto);
|
|
|
+ } elseif ($statut == '2' || $statut == 'ST_PEND') {
|
|
|
+ return img_action($langs->trans("StatusProspect2"), 2, $picto);
|
|
|
+ } elseif ($statut == '3' || $statut == 'ST_DONE') {
|
|
|
+ return img_action($langs->trans("StatusProspect3"), 3, $picto);
|
|
|
+ } else {
|
|
|
return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0, $picto);
|
|
|
}
|
|
|
}
|
|
|
- if ($mode == 4)
|
|
|
- {
|
|
|
- if ($statut == '-1' || $statut == 'ST_NO') return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1");
|
|
|
- elseif ($statut == '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0");
|
|
|
- elseif ($statut == '1' || $statut == 'ST_TODO') return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1");
|
|
|
- elseif ($statut == '2' || $statut == 'ST_PEND') return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2");
|
|
|
- elseif ($statut == '3' || $statut == 'ST_DONE') return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3");
|
|
|
- else {
|
|
|
+ if ($mode == 4) {
|
|
|
+ if ($statut == '-1' || $statut == 'ST_NO') {
|
|
|
+ return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1");
|
|
|
+ } elseif ($statut == '0' || $statut == 'ST_NEVER') {
|
|
|
+ return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0");
|
|
|
+ } elseif ($statut == '1' || $statut == 'ST_TODO') {
|
|
|
+ return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1");
|
|
|
+ } elseif ($statut == '2' || $statut == 'ST_PEND') {
|
|
|
+ return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2");
|
|
|
+ } elseif ($statut == '3' || $statut == 'ST_DONE') {
|
|
|
+ return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3");
|
|
|
+ } else {
|
|
|
return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0, $picto).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label);
|
|
|
}
|
|
|
}
|
|
@@ -1964,24 +2023,19 @@ class Contact extends CommonObject
|
|
|
$error = 0;
|
|
|
|
|
|
// Update mass emailing flag into table mailing_unsubscribe
|
|
|
- if ($this->email)
|
|
|
- {
|
|
|
+ if ($this->email) {
|
|
|
$this->db->begin();
|
|
|
|
|
|
- if ($no_email)
|
|
|
- {
|
|
|
+ if ($no_email) {
|
|
|
$sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE entity IN (".getEntity('mailing', 0).") AND email = '".$this->db->escape($this->email)."'";
|
|
|
$resql = $this->db->query($sql);
|
|
|
- if ($resql)
|
|
|
- {
|
|
|
+ if ($resql) {
|
|
|
$obj = $this->db->fetch_object($resql);
|
|
|
$noemail = $obj->nb;
|
|
|
- if (empty($noemail))
|
|
|
- {
|
|
|
+ if (empty($noemail)) {
|
|
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_unsubscribe(email, entity, date_creat) VALUES ('".$this->db->escape($this->email)."', ".$this->db->escape(getEntity('mailing', 0)).", '".$this->db->idate(dol_now())."')";
|
|
|
$resql = $this->db->query($sql);
|
|
|
- if (!$resql)
|
|
|
- {
|
|
|
+ if (!$resql) {
|
|
|
$error++;
|
|
|
$this->error = $this->db->lasterror();
|
|
|
$this->errors[] = $this->error;
|
|
@@ -1995,8 +2049,7 @@ class Contact extends CommonObject
|
|
|
} else {
|
|
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = '".$this->db->escape($this->email)."' AND entity = ".$this->db->escape(getEntity('mailing', 0));
|
|
|
$resql = $this->db->query($sql);
|
|
|
- if (!$resql)
|
|
|
- {
|
|
|
+ if (!$resql) {
|
|
|
$error++;
|
|
|
$this->error = $this->db->lasterror();
|
|
|
$this->errors[] = $this->error;
|
|
@@ -2024,8 +2077,7 @@ class Contact extends CommonObject
|
|
|
*/
|
|
|
public function getNoEmail()
|
|
|
{
|
|
|
- if ($this->email)
|
|
|
- {
|
|
|
+ if ($this->email) {
|
|
|
$sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE entity IN (".getEntity('mailing').") AND email = '".$this->db->escape($this->email)."'";
|
|
|
$resql = $this->db->query($sql);
|
|
|
if ($resql) {
|