diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index 036b99f9ae325..01d8fda91f51b 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -58,7 +58,7 @@ class Contact extends CommonObject var $country; // Label of country var $socid; // fk_soc - var $status; // 0=brouillon, 1=4=actif, 5=inactif + var $statut; // 0=brouillon, 1=4=actif, 5=inactif var $code; var $email; @@ -481,8 +481,9 @@ function fetch($id, $user=0) $langs->load("companies"); + $sql = "SELECT c.rowid, c.fk_soc, c.civilite as civilite_id, c.lastname, c.firstname,"; - $sql.= " c.address, c.zip, c.town,"; + $sql.= " c.address, c.statut, c.zip, c.town,"; $sql.= " c.fk_pays as country_id,"; $sql.= " c.fk_departement,"; $sql.= " c.birthday,"; @@ -531,6 +532,7 @@ function fetch($id, $user=0) $this->socid = $obj->fk_soc; $this->socname = $obj->socname; $this->poste = $obj->poste; + $this->statut = $obj->statut; $this->phone_pro = trim($obj->phone); $this->fax = trim($obj->fax); @@ -896,7 +898,12 @@ function getCivilityLabel() */ function getLibStatut($mode) { - return $this->LibStatut($this->status,$mode); + return $this->LibStatut($this->statut,$mode); + } + + function getLibStatutcontact($mode) + { + return $this->LibStatutcontact($this->statut,$mode); } /** @@ -906,7 +913,7 @@ function getLibStatut($mode) * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto * @return string Libelle */ - function LibStatut($statut, $mode) + function LibStatut($statut) { global $langs; @@ -952,9 +959,14 @@ function LibStatut($statut, $mode) elseif ($statut==4) return ''.$langs->trans('StatusContactValidatedShort').' '.img_picto($langs->trans('StatusContactValidatedShort'),'statut4'); elseif ($statut==5) return ''.$langs->trans('StatusContactValidatedShort').' '.img_picto($langs->trans('StatusContactValidatedShort'),'statut5'); } + } - + function LibStatutcontact($mode) + { + if ($statut==1) return img_picto($langs->trans('StatusContactDraft'),'statut0').' '.$langs->trans('Disabled'); + else return img_picto($langs->trans('StatusContactValidated'),'statut1').' '.$langs->trans('Enabled'); + } /** * Return translated label of Public or Private * @@ -1020,7 +1032,57 @@ function initAsSpecimen() $socid = rand(1, $num_socs); $this->socid = $socids[$socid]; + $this->statut=1; + } + + /** + * Change status of a user + * + * @param int $statut Status to set + * @return int <0 if KO, 0 if nothing is done, >0 if OK + */ + function setstatus($statut) + { + global $conf,$langs,$user; + + $error=0; + + // Check parameters + if ($this->statut == $statut) return 0; + else $this->statut = $statut; + + $this->db->begin(); + + // Desactive utilisateur + $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople"; + $sql.= " SET statut = ".$this->statut; + $sql.= " WHERE rowid = ".$this->id; + $result = $this->db->query($sql); + + dol_syslog(get_class($this)."::setstatus sql=".$sql); + if ($result) + { + // Appel des triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('USER_ENABLEDISABLE',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + } + + if ($error) + { + $this->db->rollback(); + return -$error; + } + else + { + $this->db->commit(); + return 1; + } } + + } ?> diff --git a/htdocs/contact/fiche.php b/htdocs/contact/fiche.php index 7cf032c68b92a..3443405ca820e 100644 --- a/htdocs/contact/fiche.php +++ b/htdocs/contact/fiche.php @@ -31,10 +31,12 @@ require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - +require_once DOL_DOCUMENT_ROOT. '/core/class/html.form.class.php'; +require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; $langs->load("companies"); $langs->load("users"); $langs->load("other"); @@ -128,7 +130,30 @@ $error=$object->error; $errors=$object->errors; } } + + /* + * Confirmation desactivation + */ + if ($action == 'disable') + { + $object->fetch($id); + $object->setstatus(1); + header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id); + exit; + } + + /* + * Confirmation activation + */ + if ($action == 'enable') + { + $object->fetch($id); + $object->setstatus(0); + header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id); + exit; + + } // Add contact if ($action == 'add' && $user->rights->societe->contact->creer) { @@ -705,6 +730,18 @@ print $form->selectarray('priv',$selectarray,$object->priv,0); print ''; + // Note + print ''.$langs->trans("Note").''; + print ''; + + // Statut + print ''.$langs->trans("Status").''; + print ''; + print $object->getLibStatutcontact(); + print ''; + // Other attributes $parameters=array('colspan' => ' colspan="3"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook @@ -904,6 +941,17 @@ print $object->LibPubPriv($object->priv); print ''; + // Note + print ''.$langs->trans("Note").''; + print nl2br($object->note); + print ''; + + // Statut + print ''.$langs->trans("Status").''; + print ''; + print $object->getLibStatutcontact(); + print ''; + print ''."\n"; // Other attributes $parameters=array('socid'=>$socid, 'colspan' => ' colspan="3"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook @@ -976,6 +1024,16 @@ { print ''.$langs->trans('Delete').''; } + // Activer + if ($object->statut == 1 && $user->rights->societe->contact->creer) + { + print ''.$langs->trans("Reactivate").''; + } + // Desactiver + if ($object->statut == 0 && $user->rights->societe->contact->creer) + { + print ''.$langs->trans("DisableUser").''; + } print "
"; } diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php index d7ebb28034a09..801eebf606ac1 100644 --- a/htdocs/contact/list.php +++ b/htdocs/contact/list.php @@ -49,6 +49,8 @@ $search_email=GETPOST("search_email"); $search_priv=GETPOST("search_priv"); $search_categ = GETPOST("search_categ",'int'); +$search_statut=GETPOST("search_statut"); + $type=GETPOST("type"); $view=GETPOST("view"); @@ -114,7 +116,7 @@ $formother=new FormOther($db); $sql = "SELECT s.rowid as socid, s.nom as name,"; -$sql.= " p.rowid as cidp, p.lastname as lastname, p.firstname, p.poste, p.email,"; +$sql.= " p.rowid as cidp, p.lastname as lastname, p.statut, p.firstname, p.poste, p.email,"; $sql.= " p.phone, p.phone_mobile, p.fax, p.fk_pays, p.priv, p.tms,"; $sql.= " cp.code as country_code"; $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as p"; @@ -288,6 +290,7 @@ print_liste_field_titre($langs->trans("EMail"),$_SERVER["PHP_SELF"],"p.email", $begin, $param, '', $sortfield,$sortorder); print_liste_field_titre($langs->trans("DateModificationShort"),$_SERVER["PHP_SELF"],"p.tms", $begin, $param, 'align="center"', $sortfield,$sortorder); print_liste_field_titre($langs->trans("ContactVisibility"),$_SERVER["PHP_SELF"],"p.priv", $begin, $param, 'align="center"', $sortfield,$sortorder); + print ' '; print "\n"; @@ -336,9 +339,12 @@ while ($i < min($num,$limit)) { $obj = $db->fetch_object($result); + - $var=!$var; - + + if ($obj->statut == 0) + { + $var=!$var; print ""; // Name @@ -395,6 +401,7 @@ print ''; print "\n"; + } $i++; }