2009-02-16 23:37:30 +01:00
< ? php
/* Copyright ( C ) 2005 Patrick Rouillon < patrick @ rouillon . net >
* Copyright ( C ) 2005 - 2009 Destailleur Laurent < eldy @ users . sourceforge . net >
2009-04-27 22:37:50 +02:00
* Copyright ( C ) 2005 - 2009 Regis Houssin < regis @ dolibarr . fr >
2009-02-16 23:37:30 +01:00
*
* 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
2011-08-01 01:45:11 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2009-02-16 23:37:30 +01:00
*/
/**
2010-07-21 14:47:18 +02:00
* \file htdocs / fourn / commande / contact . php
2009-08-06 16:44:24 +02:00
* \ingroup commande
* \brief Onglet de gestion des contacts de commande
*/
2009-02-16 23:37:30 +01:00
2010-03-27 16:06:19 +01:00
require ( " ../../main.inc.php " );
2010-04-28 14:53:28 +02:00
require_once ( DOL_DOCUMENT_ROOT . " /fourn/class/fournisseur.commande.class.php " );
2010-04-28 09:55:43 +02:00
require_once ( DOL_DOCUMENT_ROOT . " /contact/class/contact.class.php " );
2009-02-16 23:37:30 +01:00
require_once DOL_DOCUMENT_ROOT . " /lib/fourn.lib.php " ;
2010-05-03 10:22:35 +02:00
require_once ( DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php' );
2009-02-16 23:37:30 +01:00
$langs -> load ( " facture " );
$langs -> load ( " orders " );
$langs -> load ( " sendings " );
$langs -> load ( " companies " );
// Security check
2009-04-27 22:37:50 +02:00
$id = isset ( $_GET [ " id " ]) ? $_GET [ " id " ] : '' ;
2009-02-16 23:37:30 +01:00
if ( $user -> societe_id ) $socid = $user -> societe_id ;
2009-04-27 22:37:50 +02:00
$result = restrictedArea ( $user , 'commande_fournisseur' , $id , '' );
2009-02-16 23:37:30 +01:00
/*
* Ajout d ' un nouveau contact
*/
if ( $_POST [ " action " ] == 'addcontact' && $user -> rights -> commande -> creer )
{
$result = 0 ;
$commande = new CommandeFournisseur ( $db );
$result = $commande -> fetch ( $_GET [ " id " ]);
if ( $result > 0 && $_GET [ " id " ] > 0 )
{
$result = $commande -> add_contact ( $_POST [ " contactid " ], $_POST [ " type " ], $_POST [ " source " ]);
}
if ( $result >= 0 )
{
Header ( " Location: contact.php?id= " . $commande -> id );
exit ;
}
else
{
if ( $commande -> error == 'DB_ERROR_RECORD_ALREADY_EXISTS' )
{
$langs -> load ( " errors " );
$mesg = '<div class="error">' . $langs -> trans ( " ErrorThisContactIsAlreadyDefinedAsThisType " ) . '</div>' ;
}
else
{
$mesg = '<div class="error">' . $commande -> error . '</div>' ;
}
}
}
// bascule du statut d'un contact
if ( $_GET [ " action " ] == 'swapstatut' && $user -> rights -> commande -> creer )
{
$commande = new CommandeFournisseur ( $db );
2011-08-14 05:13:50 +02:00
if ( $commande -> fetch ( GETPOST ( " id " )))
2009-02-16 23:37:30 +01:00
{
2011-08-14 05:13:50 +02:00
$result = $commande -> swapContactStatus ( GETPOST ( 'ligne' ));
}
else
2009-02-16 23:37:30 +01:00
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2009-02-16 23:37:30 +01:00
}
}
// Efface un contact
if ( $_GET [ " action " ] == 'deleteline' && $user -> rights -> commande -> creer )
{
$commande = new CommandeFournisseur ( $db );
$commande -> fetch ( $_GET [ " id " ]);
$result = $commande -> delete_contact ( $_GET [ " lineid " ]);
if ( $result >= 0 )
{
Header ( " Location: contact.php?id= " . $commande -> id );
exit ;
}
else {
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2009-02-16 23:37:30 +01:00
}
}
/*
* View
*/
llxHeader ( '' , $langs -> trans ( " Order " ), " Commande " );
$html = new Form ( $db );
2009-02-18 13:26:55 +01:00
$formcompany = new FormCompany ( $db );
2009-02-16 23:37:30 +01:00
$contactstatic = new Contact ( $db );
2011-02-09 19:27:56 +01:00
$userstatic = new User ( $db );
2009-02-16 23:37:30 +01:00
/* *************************************************************************** */
/* */
/* Mode vue et edition */
/* */
/* *************************************************************************** */
2011-08-14 05:13:50 +02:00
dol_htmloutput_mesg ( $mesg );
2009-02-16 23:37:30 +01:00
$id = $_GET [ 'id' ];
$ref = $_GET [ 'ref' ];
if ( $id > 0 || ! empty ( $ref ))
{
$langs -> trans ( " OrderCard " );
$commande = new CommandeFournisseur ( $db );
if ( $commande -> fetch ( $_GET [ 'id' ], $_GET [ 'ref' ]) > 0 )
{
2011-09-11 20:35:38 +02:00
$soc = new Societe ( $db );
2009-02-16 23:37:30 +01:00
$soc -> fetch ( $commande -> socid );
$head = ordersupplier_prepare_head ( $commande );
2009-08-06 16:44:24 +02:00
dol_fiche_head ( $head , 'contact' , $langs -> trans ( " SupplierOrder " ), 0 , 'order' );
2009-02-16 23:37:30 +01:00
/*
* Facture synthese pour rappel
*/
print '<table class="border" width="100%">' ;
// Ref
print '<tr><td width="20%">' . $langs -> trans ( " Ref " ) . '</td>' ;
print '<td colspan="2">' ;
print $html -> showrefnav ( $commande , 'ref' , '' , 1 , 'ref' , 'ref' );
print '</td>' ;
print '</tr>' ;
// Fournisseur
print '<tr><td>' . $langs -> trans ( " Supplier " ) . " </td> " ;
print '<td colspan="2">' . $soc -> getNomUrl ( 1 , 'supplier' ) . '</td>' ;
print '</tr>' ;
print " </table> " ;
print '</div>' ;
2010-05-09 17:15:10 +02:00
// TODO All contact.php pages use this huge part of code. Use a function instead.
2009-02-16 23:37:30 +01:00
/*
* Lignes de contacts
*/
echo '<br><table class="noborder" width="100%">' ;
/*
* Ajouter une ligne de contact
2010-05-09 17:15:10 +02:00
* Non affiche en mode modification de ligne
2009-02-16 23:37:30 +01:00
*/
if ( $_GET [ " action " ] != 'editline' && $user -> rights -> fournisseur -> facture -> creer )
{
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " Source " ) . '</td>' ;
print '<td>' . $langs -> trans ( " Company " ) . '</td>' ;
print '<td>' . $langs -> trans ( " Contacts " ) . '</td>' ;
print '<td>' . $langs -> trans ( " ContactType " ) . '</td>' ;
print '<td colspan="3"> </td>' ;
print " </tr> \n " ;
$var = false ;
print '<form action="contact.php?id=' . $id . '" method="post">' ;
2009-05-17 10:01:54 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2009-02-16 23:37:30 +01:00
print '<input type="hidden" name="action" value="addcontact">' ;
print '<input type="hidden" name="source" value="internal">' ;
print '<input type="hidden" name="id" value="' . $id . '">' ;
// Ligne ajout pour contact interne
print " <tr $bc[$var] > " ;
print '<td nowrap="0">' ;
print img_object ( '' , 'user' ) . ' ' . $langs -> trans ( " Users " );
print '</td>' ;
print '<td colspan="1">' ;
print $conf -> global -> MAIN_INFO_SOCIETE_NOM ;
print '</td>' ;
print '<td colspan="1">' ;
//$userAlreadySelected = $commande->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 '</td>' ;
print '<td>' ;
2009-02-18 13:26:55 +01:00
$formcompany -> selectTypeContact ( $commande , '' , 'type' , 'internal' );
2009-02-16 23:37:30 +01:00
print '</td>' ;
print '<td align="right" colspan="3" ><input type="submit" class="button" value="' . $langs -> trans ( " Add " ) . '"></td>' ;
print '</tr>' ;
print '</form>' ;
print '<form action="contact.php?id=' . $id . '" method="post">' ;
2009-05-17 10:01:54 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2009-02-16 23:37:30 +01:00
print '<input type="hidden" name="action" value="addcontact">' ;
print '<input type="hidden" name="source" value="external">' ;
print '<input type="hidden" name="id" value="' . $id . '">' ;
// Ligne ajout pour contact externe
$var =! $var ;
print " <tr $bc[$var] > " ;
print '<td nowrap="nowrap">' ;
print img_object ( '' , 'contact' ) . ' ' . $langs -> trans ( " ThirdPartyContacts " );
print '</td>' ;
print '<td colspan="1">' ;
$selectedCompany = isset ( $_GET [ " newcompany " ]) ? $_GET [ " newcompany " ] : $commande -> client -> id ;
2009-02-18 13:26:55 +01:00
$selectedCompany = $formcompany -> selectCompaniesForNewContact ( $commande , 'id' , $selectedCompany , 'newcompany' );
2009-02-16 23:37:30 +01:00
print '</td>' ;
print '<td colspan="1">' ;
2011-04-26 15:49:41 +02:00
$nbofcontacts = $html -> select_contacts ( $selectedCompany , '' , 'contactid' );
2009-02-16 23:37:30 +01:00
if ( $nbofcontacts == 0 ) print $langs -> trans ( " NoContactDefined " );
print '</td>' ;
print '<td>' ;
2009-02-18 13:26:55 +01:00
$formcompany -> selectTypeContact ( $commande , '' , 'type' , 'external' );
2009-02-16 23:37:30 +01:00
print '</td>' ;
print '<td align="right" colspan="3" ><input type="submit" class="button" value="' . $langs -> trans ( " Add " ) . '"' ;
2011-08-31 17:12:09 +02:00
if ( ! $nbofcontacts ) print ' disabled="disabled"' ;
2009-02-16 23:37:30 +01:00
print '></td>' ;
print '</tr>' ;
print " </form> " ;
print '<tr><td colspan="6"> </td></tr>' ;
}
2009-02-18 13:26:55 +01:00
// List of linked contacts
2009-02-16 23:37:30 +01:00
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " Source " ) . '</td>' ;
print '<td>' . $langs -> trans ( " Company " ) . '</td>' ;
print '<td>' . $langs -> trans ( " Contacts " ) . '</td>' ;
print '<td>' . $langs -> trans ( " ContactType " ) . '</td>' ;
print '<td align="center">' . $langs -> trans ( " Status " ) . '</td>' ;
print '<td colspan="2"> </td>' ;
print " </tr> \n " ;
2010-05-09 16:55:49 +02:00
$companystatic = new Societe ( $db );
2009-02-16 23:37:30 +01:00
$var = true ;
foreach ( array ( 'internal' , 'external' ) as $source )
{
$tab = $commande -> liste_contact ( - 1 , $source );
2011-09-17 21:49:50 +02:00
$num = count ( $tab );
2009-02-16 23:37:30 +01:00
$i = 0 ;
while ( $i < $num )
{
$var = ! $var ;
print '<tr ' . $bc [ $var ] . ' valign="top">' ;
// Source
print '<td align="left">' ;
if ( $tab [ $i ][ 'source' ] == 'internal' ) print $langs -> trans ( " User " );
if ( $tab [ $i ][ 'source' ] == 'external' ) print $langs -> trans ( " ThirdPartyContact " );
print '</td>' ;
// Societe
print '<td align="left">' ;
if ( $tab [ $i ][ 'socid' ] > 0 )
{
2010-05-09 17:15:10 +02:00
$companystatic -> fetch ( $tab [ $i ][ 'socid' ]);
print $companystatic -> getNomUrl ( 1 );
2009-02-16 23:37:30 +01:00
}
if ( $tab [ $i ][ 'socid' ] < 0 )
{
print $conf -> global -> MAIN_INFO_SOCIETE_NOM ;
}
if ( ! $tab [ $i ][ 'socid' ])
{
print ' ' ;
}
print '</td>' ;
// Contact
print '<td>' ;
2011-02-09 19:27:56 +01:00
if ( $tab [ $i ][ 'source' ] == 'internal' )
{
$userstatic -> id = $tab [ $i ][ 'id' ];
$userstatic -> nom = $tab [ $i ][ 'nom' ];
$userstatic -> prenom = $tab [ $i ][ 'firstname' ];
print $userstatic -> getNomUrl ( 1 );
}
if ( $tab [ $i ][ 'source' ] == 'external' )
{
$contactstatic -> id = $tab [ $i ][ 'id' ];
$contactstatic -> name = $tab [ $i ][ 'nom' ];
$contactstatic -> firstname = $tab [ $i ][ 'firstname' ];
print $contactstatic -> getNomUrl ( 1 );
}
2009-02-16 23:37:30 +01:00
print '</td>' ;
// Type de contact
print '<td>' . $tab [ $i ][ 'libelle' ] . '</td>' ;
// Statut
print '<td align="center">' ;
// Activation desativation du contact
if ( $commande -> statut >= 0 ) print '<a href="contact.php?id=' . $commande -> id . '&action=swapstatut&ligne=' . $tab [ $i ][ 'rowid' ] . '">' ;
print $contactstatic -> LibStatut ( $tab [ $i ][ 'status' ], 3 );
if ( $commande -> statut >= 0 ) print '</a>' ;
print '</td>' ;
// Icon update et delete
2011-08-14 04:11:15 +02:00
print '<td align="center" nowrap="nowrap">' ;
2009-02-16 23:37:30 +01:00
if ( $commande -> statut < 5 && $user -> rights -> commande -> creer )
{
print ' ' ;
print '<a href="contact.php?id=' . $commande -> id . '&action=deleteline&lineid=' . $tab [ $i ][ 'rowid' ] . '">' ;
print img_delete ();
print '</a>' ;
}
print '</td>' ;
print " </tr> \n " ;
$i ++ ;
}
}
print " </table> " ;
}
else
{
// Contrat non trouv
print " ErrorRecordNotFound " ;
}
}
$db -> close ();
2011-08-27 16:24:16 +02:00
llxFooter ();
2009-02-16 23:37:30 +01:00
?>