* Copyright (C) 2007-2009 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /** * \file htdocs/fichinter/contact.php * \ingroup fichinter * \brief Onglet de gestion des contacts de fiche d'intervention * \version $Id$ */ require("../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/fichinter/class/fichinter.class.php"); require_once(DOL_DOCUMENT_ROOT."/contact/class/contact.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/fichinter.lib.php"); require_once(DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'); $langs->load("interventions"); $langs->load("sendings"); $langs->load("companies"); $fichinterid = isset($_GET["id"])?$_GET["id"]:''; // Security check if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'ficheinter', $fichinterid, 'fichinter'); /* * Ajout d'un nouveau contact */ if ($_POST["action"] == 'addcontact' && $user->rights->ficheinter->creer) { $result = 0; $fichinter = new Fichinter($db); $result = $fichinter->fetch($_GET["id"]); if ($result > 0 && $_GET["id"] > 0) { $result = $fichinter->add_contact($_POST["contactid"], $_POST["type"], $_POST["source"]); } if ($result >= 0) { Header("Location: contact.php?id=".$fichinter->id); exit; } else { if ($fichinter->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $langs->load("errors"); $mesg = '
'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'
'; } else { $mesg = '
'.$fichinter->error.'
'; } } } // modification d'un contact. On enregistre le type if ($_POST["action"] == 'updateligne' && $user->rights->ficheinter->creer) { $fichinter = new Fichinter($db); if ($fichinter->fetch($_GET["id"])) { $contact = $fichinter->detail_contact($_POST["elrowid"]); $type = $_POST["type"]; $statut = $contact->statut; $result = $fichinter->update_contact($_POST["elrowid"], $statut, $type); if ($result >= 0) { $db->commit(); } else { dol_print_error($db, "result=$result"); $db->rollback(); } } else { dol_print_error($db); } } // bascule du statut d'un contact if ($_GET["action"] == 'swapstatut' && $user->rights->ficheinter->creer) { $fichinter = new Fichinter($db); if ($fichinter->fetch($_GET["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 { dol_print_error($db); } } // Efface un contact if ($_GET["action"] == 'deleteline' && $user->rights->ficheinter->creer) { $fichinter = new Fichinter($db); $fichinter->fetch($_GET["id"]); $result = $fichinter->delete_contact($_GET["lineid"]); if ($result >= 0) { Header("Location: contact.php?id=".$fichinter->id); exit; } else { dol_print_error($db); } } /* * View */ llxHeader(); $html = new Form($db); $formcompany = new FormCompany($db); $contactstatic=new Contact($db); /* *************************************************************************** */ /* */ /* Mode vue et edition */ /* */ /* *************************************************************************** */ if (isset($mesg)) print $mesg; $id = $_GET["id"]; if ($id > 0) { $fichinter = New Fichinter($db); if ($fichinter->fetch($_GET['id']) > 0) { $soc = new Societe($db, $fichinter->socid); $soc->fetch($fichinter->socid); $head = fichinter_prepare_head($fichinter); dol_fiche_head($head, 'contact', $langs->trans("InterventionCard"), 0, 'intervention'); /* * Fiche intervention synthese pour rappel */ print ''; // Ref print '"; // Customer if ( is_null($fichinter->client) ) $fichinter->fetch_thirdparty(); print ""; print ''; print "
'.$langs->trans("Ref").''; print $fichinter->ref; print "
".$langs->trans("Company")."'.$fichinter->client->getNomUrl(1).'
"; print ''; /* * Lignes de contacts */ echo '
'; /* * Ajouter une ligne de contact * Non affiche en mode modification de ligne */ if ($_GET["action"] != 'editline' && $user->rights->ficheinter->creer) { print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; $var = false; print ''; print ''; print ''; print ''; print ''; // Ligne ajout pour contact interne print ""; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; // Ligne ajout pour contact externe $var=!$var; print ""; print ''; print ''; print ''; print ''; print ''; print ''; print ""; print ''; } // Liste des contacts li�s print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; $companystatic = new Societe($db); $var = true; foreach(array('internal','external') as $source) { $tab = $fichinter->liste_contact(-1,$source); $num=sizeof($tab); $i = 0; while ($i < $num) { $var = !$var; print ''; // Source print ''; // Societe print ''; // Contact print ''; // Type de contact print ''; // Statut print ''; // Icon update et delete print ''; print "\n"; $i ++; } } print "
'.$langs->trans("Source").''.$langs->trans("Company").''.$langs->trans("Contacts").''.$langs->trans("ContactType").' 
'; print img_object('','user').' '.$langs->trans("Users"); print ''; print $conf->global->MAIN_INFO_SOCIETE_NOM; print ''; //$userAlreadySelected = $fichinter->getListContactId('internal'); // On ne doit pas desactiver un contact deja selectionner car on doit pouvoir le seclectionner une deuxieme fois pour un autre type $html->select_users($user->id,'contactid',0,$userAlreadySelected); print ''; $formcompany->selectTypeContact($fichinter, '', 'type','internal'); print '
'; print img_object('','contact').' '.$langs->trans("ThirdPartyContacts"); print ''; $selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$fichinter->client->id; $selectedCompany = $formcompany->selectCompaniesForNewContact($fichinter, 'id', $selectedCompany, $htmlname = 'newcompany'); print ''; //$contactAlreadySelected = $fichinter->getListContactId('external'); // On ne doit pas desactiver un contact deja selectionner car on doit pouvoir le seclectionner une deuxieme fois pour un autre type $nbofcontacts=$html->select_contacts($selectedCompany, '', 'contactid', 0, $contactAlreadySelected); if ($nbofcontacts == 0) print $langs->trans("NoContactDefined"); print ''; $formcompany->selectTypeContact($fichinter, '', 'type','external'); print '
 
'.$langs->trans("Source").''.$langs->trans("Company").''.$langs->trans("Contacts").''.$langs->trans("ContactType").''.$langs->trans("Status").' 
'; if ($tab[$i]['source']=='internal') print $langs->trans("User"); if ($tab[$i]['source']=='external') print $langs->trans("ThirdPartyContact"); print ''; if ($tab[$i]['socid'] > 0) { $companystatic->fetch($tab[$i]['socid']); print $companystatic->getNomUrl(1); } if ($tab[$i]['socid'] < 0) { print $conf->global->MAIN_INFO_SOCIETE_NOM; } if (! $tab[$i]['socid']) { print ' '; } print ''; if ($tab[$i]['source']=='internal') { print ''; print img_object($langs->trans("ShowUser"),"user").' '.$tab[$i]['nom'].''; } if ($tab[$i]['source']=='external') { print ''; print img_object($langs->trans("ShowContact"),"contact").' '.$tab[$i]['nom'].''; } print ''.$tab[$i]['libelle'].''; // Activation desativation du contact if ($fichinter->statut >= 0) print ''; print $contactstatic->LibStatut($tab[$i]['status'],3); if ($fichinter->statut >= 0) print ''; print ''; if ($fichinter->statut < 5 && $user->rights->ficheinter->creer) { print ' '; print ''; print img_delete(); print ''; } print '
"; } else { print "ErrorRecordNotFound"; } } $db->close(); llxFooter('$Date$'); ?>