diff --git a/htdocs/comm/propal/contact.php b/htdocs/comm/propal/contact.php index 85803fa4c17..d8c170c8431 100644 --- a/htdocs/comm/propal/contact.php +++ b/htdocs/comm/propal/contact.php @@ -20,7 +20,7 @@ * \file htdocs/comm/propal/contact.php * \ingroup propal * \brief Onglet de gestion des contacts de propal - * \version $Id: contact.php,v 1.44 2011/08/14 02:11:45 eldy Exp $ + * \version $Id: contact.php,v 1.45 2011/08/14 03:13:50 eldy Exp $ */ require("../../main.inc.php"); @@ -81,26 +81,15 @@ if ($_POST["action"] == 'addcontact' && $user->rights->propale->creer) } } -// bascule du statut d'un contact +// Bascule du statut d'un contact if ($action == 'swapstatut' && $user->rights->propale->creer) { $propal = new Propal($db); - if ($propal->fetch($id)) + if ($propal->fetch($id) > 0) { - $contact = $propal->detail_contact($ligne); - $id_type_contact = $contact->fk_c_type_contact; - $statut = ($contact->statut == 4) ? 5 : 4; - - $result = $propal->update_contact($ligne, $statut, $id_type_contact); - if ($result >= 0) - { - $db->commit(); - } else - { - dol_print_error($db, "result=$result"); - $db->rollback(); - } - } else + $result=$propal->swapContactStatus(GETPOST('ligne')); + } + else { dol_print_error($db); } @@ -384,5 +373,5 @@ if ($id > 0 || ! empty($ref)) $db->close(); -llxFooter('$Date: 2011/08/14 02:11:45 $'); +llxFooter('$Date: 2011/08/14 03:13:50 $'); ?> \ No newline at end of file diff --git a/htdocs/commande/contact.php b/htdocs/commande/contact.php index d72d65c8c59..d41ce54f09e 100644 --- a/htdocs/commande/contact.php +++ b/htdocs/commande/contact.php @@ -21,7 +21,7 @@ * \file htdocs/commande/contact.php * \ingroup commande * \brief Onglet de gestion des contacts de commande - * \version $Id: contact.php,v 1.44 2011/08/14 02:11:45 eldy Exp $ + * \version $Id: contact.php,v 1.45 2011/08/14 03:13:50 eldy Exp $ */ require("../main.inc.php"); @@ -80,22 +80,11 @@ if ($_POST["action"] == 'addcontact' && $user->rights->commande->creer) if ($_GET["action"] == 'swapstatut' && $user->rights->commande->creer) { $commande = new Commande($db); - if ($commande->fetch($_GET["id"])) + if ($commande->fetch(GETPOST("id"))) { - $contact = $commande->detail_contact($_GET["ligne"]); - $id_type_contact = $contact->fk_c_type_contact; - $statut = ($contact->statut == 4) ? 5 : 4; - - $result = $commande->update_contact($_GET["ligne"], $statut, $id_type_contact); - if ($result >= 0) - { - $db->commit(); - } else - { - dol_print_error($db, "result=$result"); - $db->rollback(); - } - } else + $result=$commande->swapContactStatus(GETPOST('ligne')); + } + else { dol_print_error($db); } @@ -376,5 +365,5 @@ if ($id > 0 || ! empty($ref)) $db->close(); -llxFooter('$Date: 2011/08/14 02:11:45 $'); +llxFooter('$Date: 2011/08/14 03:13:50 $'); ?> \ No newline at end of file diff --git a/htdocs/compta/facture/contact.php b/htdocs/compta/facture/contact.php index e7b8cec1801..2e20c010b36 100644 --- a/htdocs/compta/facture/contact.php +++ b/htdocs/compta/facture/contact.php @@ -20,7 +20,7 @@ * \file htdocs/compta/facture/contact.php * \ingroup facture * \brief Onglet de gestion des contacts des factures - * \version $Id: contact.php,v 1.49 2011/08/14 02:11:46 eldy Exp $ + * \version $Id: contact.php,v 1.50 2011/08/14 03:13:50 eldy Exp $ */ require("../../main.inc.php"); @@ -79,22 +79,11 @@ if ($_POST["action"] == 'addcontact' && $user->rights->facture->creer) if ($_GET["action"] == 'swapstatut' && $user->rights->facture->creer) { $facture = new Facture($db); - if ($facture->fetch($_GET["facid"])) + if ($facture->fetch(GETPOST("facid"))) { - $contact = $facture->detail_contact($_GET["ligne"]); - $id_type_contact = $contact->fk_c_type_contact; - $statut = ($contact->statut == 4) ? 5 : 4; - - $result = $facture->update_contact($_GET["ligne"], $statut, $id_type_contact); - if ($result >= 0) - { - $db->commit(); - } else - { - dol_print_error($db, "result=$result"); - $db->rollback(); - } - } else + $result=$facture->swapContactStatus(GETPOST('ligne')); + } + else { dol_print_error($db); } @@ -135,7 +124,7 @@ $userstatic=new User($db); /* Mode vue et edition */ /* */ /* *************************************************************************** */ -if (isset($mesg)) print $mesg; +dol_htmloutput_mesg($mesg); $id = $_GET['facid']; $ref= $_GET['ref']; @@ -371,5 +360,5 @@ if ($id > 0 || ! empty($ref)) $db->close(); -llxFooter('$Date: 2011/08/14 02:11:46 $'); +llxFooter('$Date: 2011/08/14 03:13:50 $'); ?> \ No newline at end of file diff --git a/htdocs/contrat/contact.php b/htdocs/contrat/contact.php index 3ba26a6a982..b8da0313870 100644 --- a/htdocs/contrat/contact.php +++ b/htdocs/contrat/contact.php @@ -20,7 +20,7 @@ \file htdocs/contrat/contact.php \ingroup contrat \brief Onglet de gestion des contacts des contrats - \version $Id: contact.php,v 1.47 2011/08/14 02:11:46 eldy Exp $ + \version $Id: contact.php,v 1.48 2011/08/14 03:13:50 eldy Exp $ */ require ("../main.inc.php"); @@ -78,25 +78,9 @@ if ($_POST["action"] == 'addcontact' && $user->rights->contrat->creer) if ($_GET["action"] == 'swapstatut' && $user->rights->contrat->creer) { $contrat = new Contrat($db); - if ($contrat->fetch($_GET["id"])) + if ($contrat->fetch(GETPOST("id"))) { - $db->begin(); - - $contact = $contrat->detail_contact($_GET["ligne"]); - $id_type_contact = $contact->fk_c_type_contact; - - $statut = ($contact->statut == 4) ? 5 : 4; - - $result = $contrat->update_contact($_GET["ligne"], $statut, $id_type_contact); - if ($result >= 0) - { - $db->commit(); - } - else - { - dol_print_error($db, "result=$result"); - $db->rollback(); - } + $result=$contrat->swapContactStatus(GETPOST('ligne')); } else { @@ -130,6 +114,7 @@ $formcompany= new FormCompany($db); $contactstatic=new Contact($db); $userstatic=new User($db); +dol_htmloutput_mesg($mesg); /* *************************************************************************** */ /* */ @@ -376,5 +361,5 @@ if ($id > 0) $db->close(); -llxFooter('$Date: 2011/08/14 02:11:46 $'); +llxFooter('$Date: 2011/08/14 03:13:50 $'); ?> diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index e29058ef019..f20b82996da 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -21,7 +21,7 @@ * \file htdocs/core/class/commonobject.class.php * \ingroup core * \brief File of parent class of all other business classes (invoices, contracts, proposals, orders, ...) - * \version $Id: commonobject.class.php,v 1.155 2011/08/11 15:14:51 hregis Exp $ + * \version $Id: commonobject.class.php,v 1.156 2011/08/14 03:13:50 eldy Exp $ */ @@ -171,24 +171,24 @@ class CommonObject * Update a link to contact line * @param rowid Id of line contact-element * @param statut New status of link - * @param type_contact_id Id of contact type + * @param type_contact_id Id of contact type (not modified if 0) * @return int <0 if KO, >= 0 if OK */ - function update_contact($rowid, $statut, $type_contact_id) + function update_contact($rowid, $statut, $type_contact_id=0) { // Insertion dans la base $sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set"; - $sql.= " statut = ".$statut.","; - $sql.= " fk_c_type_contact = '".$type_contact_id ."'"; + $sql.= " statut = ".$statut; + if ($type_contact_id) $sql.= ", fk_c_type_contact = '".$type_contact_id ."'"; $sql.= " where rowid = ".$rowid; - // Retour - if ( $this->db->query($sql) ) + $resql=$this->db->query($sql); + if ($resql) { return 0; } else { - dol_print_error($this->db); + $this->error=$this->db->lasterror(); return -1; } } @@ -199,7 +199,7 @@ class CommonObject * @param notrigger Disable all triggers * @return int >0 if OK, <0 if KO */ - function delete_contact($rowid,$notrigger=0) + function delete_contact($rowid, $notrigger=0) { global $user,$langs,$conf; @@ -329,35 +329,41 @@ class CommonObject } } - /** - * Return fetch cursor of a contact - * FIXME We should never return an open db cursor - * @param rowid L'identifiant du contact - * @return object L'objet construit par DoliDb.fetch_object - */ - function detail_contact($rowid) + + /** + * Update status of a contact linked to object + * + * @param $rowid Id of link between object and contact + * @return int <0 if KO, >=0 if OK + */ + function swapContactStatus($rowid) { $sql = "SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,"; - $sql.= " tc.code, tc.libelle,"; - $sql.= " s.fk_soc"; + $sql.= " tc.code, tc.libelle"; + //$sql.= ", s.fk_soc"; $sql.= " FROM (".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc)"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as s ON ec.fk_socpeople=s.rowid"; // Si contact de type external, alors il est li� � une societe + //$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as s ON ec.fk_socpeople=s.rowid"; // Si contact de type external, alors il est lie a une societe $sql.= " WHERE ec.rowid =".$rowid; $sql.= " AND ec.fk_c_type_contact=tc.rowid"; $sql.= " AND tc.element = '".$this->element."'"; + dol_syslog(get_class($object)."::swapContactStatus sql=".$sql); $resql=$this->db->query($sql); if ($resql) { $obj = $this->db->fetch_object($resql); - return $obj; + $newstatut = ($obj->statut == 4) ? 5 : 4; + $result = $this->update_contact($rowid, $newstatut); + $this->db->free($resql); + return $result; } else { $this->error=$this->db->error(); dol_print_error($this->db); - return null; + return -1; } + } /** diff --git a/htdocs/fichinter/contact.php b/htdocs/fichinter/contact.php index 864f59626eb..6297910471a 100644 --- a/htdocs/fichinter/contact.php +++ b/htdocs/fichinter/contact.php @@ -20,7 +20,7 @@ * \file htdocs/fichinter/contact.php * \ingroup fichinter * \brief Onglet de gestion des contacts de fiche d'intervention - * \version $Id: contact.php,v 1.31 2011/08/14 02:11:45 eldy Exp $ + * \version $Id: contact.php,v 1.32 2011/08/14 03:13:50 eldy Exp $ */ require("../main.inc.php"); @@ -79,22 +79,11 @@ if ($_POST["action"] == 'addcontact' && $user->rights->ficheinter->creer) if ($_GET["action"] == 'swapstatut' && $user->rights->ficheinter->creer) { $fichinter = new Fichinter($db); - if ($fichinter->fetch($_GET["id"])) + if ($fichinter->fetch(GETPOST("id"))) { - $contact = $fichinter->detail_contact($_GET["ligne"]); - $id_type_contact = $contact->fk_c_type_contact; - $statut = ($contact->statut == 4) ? 5 : 4; - - $result = $fichinter->update_contact($_GET["ligne"], $statut, $id_type_contact); - if ($result >= 0) - { - $db->commit(); - } else - { - dol_print_error($db, "result=$result"); - $db->rollback(); - } - } else + $result=$fichinter->swapContactStatus(GETPOST('ligne')); + } + else { dol_print_error($db); } @@ -135,7 +124,7 @@ $userstatic=new User($db); /* Mode vue et edition */ /* */ /* *************************************************************************** */ -if (isset($mesg)) print $mesg; +dol_htmloutput_mesg($mesg); $id = $_GET["id"]; if ($id > 0) @@ -360,5 +349,5 @@ if ($id > 0) $db->close(); -llxFooter('$Date: 2011/08/14 02:11:45 $'); +llxFooter('$Date: 2011/08/14 03:13:50 $'); ?> \ No newline at end of file diff --git a/htdocs/fourn/commande/contact.php b/htdocs/fourn/commande/contact.php index 5f8f2111ddc..06ee97449f7 100644 --- a/htdocs/fourn/commande/contact.php +++ b/htdocs/fourn/commande/contact.php @@ -21,7 +21,7 @@ * \file htdocs/fourn/commande/contact.php * \ingroup commande * \brief Onglet de gestion des contacts de commande - * \version $Id: contact.php,v 1.21 2011/08/14 02:11:46 eldy Exp $ + * \version $Id: contact.php,v 1.22 2011/08/14 03:13:50 eldy Exp $ */ require("../../main.inc.php"); @@ -80,22 +80,11 @@ if ($_POST["action"] == 'addcontact' && $user->rights->commande->creer) if ($_GET["action"] == 'swapstatut' && $user->rights->commande->creer) { $commande = new CommandeFournisseur($db); - if ($commande->fetch($_GET["id"])) + if ($commande->fetch(GETPOST("id"))) { - $contact = $commande->detail_contact($_GET["ligne"]); - $id_type_contact = $contact->fk_c_type_contact; - $statut = ($contact->statut == 4) ? 5 : 4; - - $result = $commande->update_contact($_GET["ligne"], $statut, $id_type_contact); - if ($result >= 0) - { - $db->commit(); - } else - { - dol_print_error($db, "result=$result"); - $db->rollback(); - } - } else + $result=$commande->swapContactStatus(GETPOST('ligne')); + } + else { dol_print_error($db); } @@ -137,7 +126,7 @@ $userstatic=new User($db); /* Mode vue et edition */ /* */ /* *************************************************************************** */ -if (isset($mesg)) print $mesg; +dol_htmloutput_mesg($mesg); $id = $_GET['id']; $ref= $_GET['ref']; @@ -368,5 +357,5 @@ if ($id > 0 || ! empty($ref)) $db->close(); -llxFooter('$Date: 2011/08/14 02:11:46 $'); +llxFooter('$Date: 2011/08/14 03:13:50 $'); ?> \ No newline at end of file diff --git a/htdocs/fourn/facture/contact.php b/htdocs/fourn/facture/contact.php index 0119f841343..947a14cbd7e 100644 --- a/htdocs/fourn/facture/contact.php +++ b/htdocs/fourn/facture/contact.php @@ -21,7 +21,7 @@ * \file htdocs/fourn/facture/contact.php * \ingroup facture, fournisseur * \brief Onglet de gestion des contacts des factures - * \version $Id: contact.php,v 1.28 2011/08/14 02:11:46 eldy Exp $ + * \version $Id: contact.php,v 1.29 2011/08/14 03:13:50 eldy Exp $ */ require("../../main.inc.php"); @@ -81,22 +81,11 @@ if ($_POST["action"] == 'addcontact' && $user->rights->fournisseur->facture->cre if ($_GET["action"] == 'swapstatut' && $user->rights->fournisseur->facture->creer) { $facture = new FactureFournisseur($db); - if ($facture->fetch($_GET["facid"])) + if ($facture->fetch(GETPOST("facid"))) { - $contact = $facture->detail_contact($_GET["ligne"]); - $id_type_contact = $contact->fk_c_type_contact; - $statut = ($contact->statut == 4) ? 5 : 4; - - $result = $facture->update_contact($_GET["ligne"], $statut, $id_type_contact); - if ($result >= 0) - { - $db->commit(); - } else - { - dol_print_error($db, "result=$result"); - $db->rollback(); - } - } else + $result=$facture->swapContactStatus(GETPOST('ligne')); + } + else { dol_print_error($db); } @@ -137,7 +126,8 @@ $userstatic=new User($db); /* Mode vue et edition */ /* */ /* *************************************************************************** */ -if (isset($mesg)) print $mesg; +dol_htmloutput_mesg($mesg); + $id = $_GET["facid"]; if ($id > 0) { @@ -360,5 +350,5 @@ if ($id > 0) $db->close(); -llxFooter('$Date: 2011/08/14 02:11:46 $'); +llxFooter('$Date: 2011/08/14 03:13:50 $'); ?> \ No newline at end of file diff --git a/htdocs/projet/contact.php b/htdocs/projet/contact.php index 4630c03a664..a4d6b92f844 100644 --- a/htdocs/projet/contact.php +++ b/htdocs/projet/contact.php @@ -19,7 +19,7 @@ * \file htdocs/projet/contact.php * \ingroup project * \brief Onglet de gestion des contacts du projet - * \version $Id: contact.php,v 1.29 2011/08/14 02:11:15 eldy Exp $ + * \version $Id: contact.php,v 1.30 2011/08/14 03:13:50 eldy Exp $ */ require("../main.inc.php"); @@ -84,19 +84,7 @@ if ($_GET["action"] == 'swapstatut' && $user->rights->projet->creer) $project = new Project($db); if ($project->fetch($projectid)) { - $contact = $project->detail_contact($_GET["ligne"]); - $id_type_contact = $contact->fk_c_type_contact; - $statut = ($contact->statut == 4) ? 5 : 4; - - $result = $project->update_contact($_GET["ligne"], $statut, $id_type_contact); - if ($result >= 0) - { - $db->commit(); - } else - { - dol_print_error($db, "result=$result"); - $db->rollback(); - } + $result=$project->swapContactStatus(GETPOST('ligne')); } else { @@ -141,7 +129,7 @@ $userstatic=new User($db); /* Mode vue et edition */ /* */ /* *************************************************************************** */ -if (isset($mesg)) print $mesg; +dol_htmloutput_mesg($mesg); $id = $_GET['id']; $ref= $_GET['ref']; @@ -390,5 +378,5 @@ if ($id > 0 || ! empty($ref)) $db->close(); -llxFooter('$Date: 2011/08/14 02:11:15 $'); +llxFooter('$Date: 2011/08/14 03:13:50 $'); ?> \ No newline at end of file diff --git a/htdocs/projet/tasks/contact.php b/htdocs/projet/tasks/contact.php index 49d31e96d9d..72d44b1ae7a 100644 --- a/htdocs/projet/tasks/contact.php +++ b/htdocs/projet/tasks/contact.php @@ -21,7 +21,7 @@ * \file htdocs/projet/tasks/contact.php * \ingroup project * \brief Actors of a task - * \version $Id: contact.php,v 1.23 2011/08/14 02:11:46 eldy Exp $ + * \version $Id: contact.php,v 1.24 2011/08/14 03:13:51 eldy Exp $ */ require ("../../main.inc.php"); @@ -85,19 +85,7 @@ if ($_GET["action"] == 'swapstatut' && $user->rights->projet->creer) $task = new Task($db); if ($task->fetch($taskid)) { - $contact = $task->detail_contact($_GET["ligne"]); - $id_type_contact = $contact->fk_c_type_contact; - $statut = ($contact->statut == 4) ? 5 : 4; - - $result = $task->update_contact($_GET["ligne"], $statut, $id_type_contact); - if ($result >= 0) - { - $db->commit(); - } else - { - dol_print_error($db, "result=$result"); - $db->rollback(); - } + $result=$task->swapContactStatus(GETPOST('ligne')); } else { @@ -142,7 +130,7 @@ $project = new Project($db); /* Mode vue et edition */ /* */ /* *************************************************************************** */ -if (isset($mesg)) print $mesg; +dol_htmloutput_mesg($mesg); $id = $_GET['id']; $ref= $_GET['ref']; @@ -391,5 +379,5 @@ if ($id > 0 || ! empty($ref)) $db->close(); -llxFooter('$Date: 2011/08/14 02:11:46 $ - $Revision: 1.23 $'); +llxFooter('$Date: 2011/08/14 03:13:51 $ - $Revision: 1.24 $'); ?>