*
* 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.
*
* $Id$
* $Source$
*/
/**
\file htdocs/fichinter/contact.php
\ingroup fichinter
\brief Onglet de gestion des contacts de fiche d'intervention
\version $Revision$
*/
require ("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/fichinter/fichinter.class.php");
require_once(DOL_DOCUMENT_ROOT."/contact.class.php");
require_once(DOL_DOCUMENT_ROOT."/lib/fichinter.lib.php");
$langs->load("interventions");
$langs->load("sendings");
$langs->load("companies");
$fichinterid = isset($_GET["id"])?$_GET["id"]:'';
// Sécurité d'accès client et commerciaux
$socid = 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
{
$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
{
dolibarr_print_error($db, "result=$result");
$db->rollback();
}
} else
{
dolibarr_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
{
dolibarr_print_error($db, "result=$result");
$db->rollback();
}
} else
{
dolibarr_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 {
dolibarr_print_error($db);
}
}
llxHeader();
$html = new Form($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);
dolibarr_fiche_head($head, 'contact', $langs->trans("InterventionCard"));
/*
* Fiche intervention synthese pour rappel
*/
print '';
// Ref
print '| '.$langs->trans("Ref").' | ';
print $fichinter->ref;
print " |
";
// Customer
if ( is_null($fichinter->client) )
$fichinter->fetch_client();
print "| ".$langs->trans("Company")." | ";
print ''.$fichinter->client->getNomUrl(1).' |
';
print "
";
print '';
/*
* Lignes de contacts
*/
echo '
';
/*
* Ajouter une ligne de contact
* Non affiché en mode modification de ligne
*/
if ($_GET["action"] != 'editline' && $user->rights->ficheinter->creer)
{
print '';
print '| '.$langs->trans("Source").' | ';
print ''.$langs->trans("Company").' | ';
print ''.$langs->trans("Contacts").' | ';
print ''.$langs->trans("ContactType").' | ';
print ' | ';
print "
\n";
$var = false;
print '';
print '";
print '| |
';
}
// Liste des contacts liés
print '';
print '| '.$langs->trans("Source").' | ';
print ''.$langs->trans("Company").' | ';
print ''.$langs->trans("Contacts").' | ';
print ''.$langs->trans("ContactType").' | ';
print ''.$langs->trans("Status").' | ';
print ' | ';
print "
\n";
$societe = 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 '| ';
if ($tab[$i]['source']=='internal') print $langs->trans("Internal");
if ($tab[$i]['source']=='external') print $langs->trans("External");
print ' | ';
// Societe
print '';
if ($tab[$i]['socid'] > 0)
{
print '';
print img_object($langs->trans("ShowCompany"),"company").' '.$societe->get_nom($tab[$i]['socid']);
print '';
}
if ($tab[$i]['socid'] < 0)
{
print $conf->global->MAIN_INFO_SOCIETE_NOM;
}
if (! $tab[$i]['socid'])
{
print ' ';
}
print ' | ';
// Contact
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 ' | ';
// Type de contact
print ''.$tab[$i]['libelle'].' | ';
// Statut
print '';
// Activation desativation du contact
if ($fichinter->statut >= 0) print '';
print $contactstatic->LibStatut($tab[$i]['status'],3);
if ($fichinter->statut >= 0) print '';
print ' | ';
// Icon update et delete
print '';
if ($fichinter->statut < 5 && $user->rights->ficheinter->creer)
{
print ' ';
print '';
print img_delete();
print '';
}
print ' | ';
print "
\n";
$i ++;
}
}
print "
";
}
else
{
// Fiche intervention non trouvée
print "Fiche intervention inexistante ou accès refusé";
}
}
$db->close();
llxFooter('$Date$');
?>