2006-05-06 17:15:48 +02:00
< ? php
2006-06-03 16:59:59 +02:00
/* Copyright ( C ) 2005 Patrick Rouillon < patrick @ rouillon . net >
2009-04-27 22:37:50 +02:00
* Copyright ( C ) 2005 - 2009 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2005 - 2009 Regis Houssin < regis @ dolibarr . fr >
2006-05-06 17:15:48 +02: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
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
*/
/**
2006-06-10 21:36:43 +02:00
\file htdocs / commande / contact . php
\ingroup commande
\brief Onglet de gestion des contacts de commande
2008-02-24 14:18:40 +01:00
\version $Id $
2006-05-06 17:15:48 +02:00
*/
require ( " ./pre.inc.php " );
require_once ( DOL_DOCUMENT_ROOT . " /commande/commande.class.php " );
require_once ( DOL_DOCUMENT_ROOT . " /contact.class.php " );
2006-05-06 21:06:40 +02:00
require_once ( DOL_DOCUMENT_ROOT . " /lib/order.lib.php " );
2009-02-18 13:26:55 +01:00
require_once ( DOL_DOCUMENT_ROOT . '/html.formcompany.class.php' );
2006-05-06 17:15:48 +02:00
$langs -> load ( " facture " );
$langs -> load ( " orders " );
$langs -> load ( " sendings " );
$langs -> load ( " companies " );
2009-04-27 22:37:50 +02:00
$comid = isset ( $_GET [ " id " ]) ? $_GET [ " id " ] : '' ;
2006-05-06 17:15:48 +02:00
2008-02-24 14:18:40 +01:00
// Security check
2008-02-25 21:03:21 +01:00
if ( $user -> societe_id ) $socid = $user -> societe_id ;
2009-04-27 22:37:50 +02:00
$result = restrictedArea ( $user , 'commande' , $comid , '' );
2008-02-24 14:18:40 +01:00
2006-05-06 17:15:48 +02:00
/*
* Ajout d ' un nouveau contact
*/
if ( $_POST [ " action " ] == 'addcontact' && $user -> rights -> commande -> creer )
{
2009-02-16 23:37:30 +01:00
2006-05-06 17:15:48 +02:00
$result = 0 ;
$commande = new Commande ( $db );
$result = $commande -> fetch ( $_GET [ " id " ]);
if ( $result > 0 && $_GET [ " id " ] > 0 )
{
$result = $commande -> add_contact ( $_POST [ " contactid " ], $_POST [ " type " ], $_POST [ " source " ]);
}
2009-02-16 23:37:30 +01:00
2006-05-06 17:15:48 +02:00
if ( $result >= 0 )
{
Header ( " Location: contact.php?id= " . $commande -> id );
exit ;
2007-10-31 13:55:01 +01:00
}
else
2006-05-06 17:15:48 +02:00
{
2007-10-31 13:55:01 +01:00
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>' ;
}
2006-05-06 17:15:48 +02:00
}
}
// modification d'un contact. On enregistre le type
if ( $_POST [ " action " ] == 'updateligne' && $user -> rights -> commande -> creer )
{
$commande = new Commande ( $db );
if ( $commande -> fetch ( $_GET [ " id " ]))
{
$contact = $commande -> detail_contact ( $_POST [ " elrowid " ]);
$type = $_POST [ " type " ];
$statut = $contact -> statut ;
$result = $commande -> update_contact ( $_POST [ " elrowid " ], $statut , $type );
if ( $result >= 0 )
{
$db -> commit ();
} else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db , " result= $result " );
2006-05-06 17:15:48 +02:00
$db -> rollback ();
}
} else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2006-05-06 17:15:48 +02:00
}
}
// bascule du statut d'un contact
if ( $_GET [ " action " ] == 'swapstatut' && $user -> rights -> commande -> creer )
{
$commande = new Commande ( $db );
if ( $commande -> fetch ( $_GET [ " 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
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db , " result= $result " );
2006-05-06 17:15:48 +02:00
$db -> rollback ();
}
} else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2006-05-06 17:15:48 +02:00
}
}
// Efface un contact
if ( $_GET [ " action " ] == 'deleteline' && $user -> rights -> commande -> creer )
{
$commande = new Commande ( $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 );
2006-05-06 17:15:48 +02:00
}
}
llxHeader ( '' , $langs -> trans ( " Order " ), " Commande " );
$html = new Form ( $db );
2009-02-18 13:26:55 +01:00
$formcompany = new FormCompany ( $db );
2007-05-04 23:19:15 +02:00
$contactstatic = new Contact ( $db );
2006-05-06 17:15:48 +02:00
/* *************************************************************************** */
/* */
/* Mode vue et edition */
/* */
/* *************************************************************************** */
2009-01-12 17:33:54 +01:00
if ( isset ( $mesg )) print $mesg ;
$id = $_GET [ 'id' ];
$ref = $_GET [ 'ref' ];
if ( $id > 0 || ! empty ( $ref ))
2006-05-06 17:15:48 +02:00
{
2006-05-06 21:06:40 +02:00
$langs -> trans ( " OrderCard " );
2009-01-12 17:33:54 +01:00
$commande = new Commande ( $db );
if ( $commande -> fetch ( $_GET [ 'id' ], $_GET [ 'ref' ]) > 0 )
2006-05-06 21:06:40 +02:00
{
2006-09-13 20:56:30 +02:00
$soc = new Societe ( $db , $commande -> socid );
$soc -> fetch ( $commande -> socid );
2006-05-06 21:06:40 +02:00
$head = commande_prepare_head ( $commande );
2009-02-20 23:53:15 +01:00
dol_fiche_head ( $head , 'contact' , $langs -> trans ( " CustomerOrder " ));
2006-05-06 17:15:48 +02:00
/*
2006-05-06 21:06:40 +02:00
* Facture synthese pour rappel
*/
2006-05-06 17:15:48 +02:00
print '<table class="border" width="100%">' ;
2006-05-06 21:06:40 +02:00
// Ref
2006-07-14 15:26:19 +02:00
print '<tr><td width="18%">' . $langs -> trans ( " Ref " ) . '</td><td colspan="3">' ;
2009-01-12 17:33:54 +01:00
print $html -> showrefnav ( $commande , 'ref' , '' , 1 , 'ref' , 'ref' );
2006-05-06 17:15:48 +02:00
print " </td></tr> " ;
2006-05-06 21:06:40 +02:00
// Ref commande client
print '<tr><td>' ;
print '<table class="nobordernopadding" width="100%"><tr><td nowrap>' ;
print $langs -> trans ( 'RefCustomer' ) . '</td><td align="left">' ;
print '</td>' ;
print '</tr></table>' ;
print '</td><td colspan="3">' ;
print $commande -> ref_client ;
print '</td>' ;
print '</tr>' ;
2009-02-16 23:37:30 +01:00
2006-05-06 17:15:48 +02:00
// Customer
2006-06-08 16:34:36 +02:00
if ( is_null ( $commande -> client ) )
$commande -> fetch_client ();
2009-02-16 23:37:30 +01:00
2006-05-06 21:06:40 +02:00
print " <tr><td> " . $langs -> trans ( " Company " ) . " </td> " ;
2006-06-08 16:34:36 +02:00
print '<td colspan="3">' . $commande -> client -> getNomUrl ( 1 ) . '</td></tr>' ;
2006-05-06 17:15:48 +02:00
print " </table> " ;
print '</div>' ;
/*
2006-05-06 21:06:40 +02:00
* Lignes de contacts
*/
2006-05-06 17:15:48 +02:00
echo '<br><table class="noborder" width="100%">' ;
/*
2006-05-06 21:06:40 +02:00
* Ajouter une ligne de contact
2009-02-18 13:26:55 +01:00
* Non affich<EFBFBD> en mode modification de ligne
2006-05-06 21:06:40 +02:00
*/
2006-05-06 17:15:48 +02:00
if ( $_GET [ " action " ] != 'editline' && $user -> rights -> 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' ] . '">' ;
2006-05-06 17:15:48 +02: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 . '">' ;
2006-05-06 21:06:40 +02:00
// Ligne ajout pour contact interne
2006-05-06 17:15:48 +02:00
print " <tr $bc[$var] > " ;
2006-05-06 21:06:40 +02:00
2009-02-16 23:37:30 +01:00
print '<td nowrap="nowrap">' ;
print img_object ( '' , 'user' ) . ' ' . $langs -> trans ( " Users " );
2006-05-06 21:06:40 +02:00
print '</td>' ;
2006-05-06 17:15:48 +02:00
print '<td colspan="1">' ;
print $conf -> global -> MAIN_INFO_SOCIETE_NOM ;
print '</td>' ;
print '<td colspan="1">' ;
2007-10-31 13:55:01 +01:00
//$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
2007-10-29 22:13:31 +01:00
$html -> select_users ( $user -> id , 'contactid' , 0 , $userAlreadySelected );
2006-05-06 17:15:48 +02:00
print '</td>' ;
print '<td>' ;
2009-02-18 13:26:55 +01:00
$formcompany -> selectTypeContact ( $commande , '' , 'type' , 'internal' );
2006-05-06 17:15:48 +02:00
print '</td>' ;
print '<td align="right" colspan="3" ><input type="submit" class="button" value="' . $langs -> trans ( " Add " ) . '"></td>' ;
print '</tr>' ;
2006-05-06 21:06:40 +02:00
print '</form>' ;
2006-05-06 17:15:48 +02:00
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' ] . '">' ;
2006-05-06 17:15:48 +02: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 . '">' ;
2006-05-06 21:06:40 +02:00
// Ligne ajout pour contact externe
2006-05-06 17:15:48 +02:00
$var =! $var ;
print " <tr $bc[$var] > " ;
2006-05-06 21:06:40 +02:00
2009-02-16 23:37:30 +01:00
print '<td nowrap="nowrap">' ;
print img_object ( '' , 'contact' ) . ' ' . $langs -> trans ( " ThirdPartyContacts " );
2006-05-06 21:06:40 +02:00
print '</td>' ;
2006-05-06 17:15:48 +02:00
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' );
2006-05-06 17:15:48 +02:00
print '</td>' ;
print '<td colspan="1">' ;
2009-02-16 23:37:30 +01:00
// $contactAlreadySelected = $commande->getListContactId('external'); // On ne doit pas desactiver un contact deja selectionner car on doit pouvoir le seclectionner une deuxieme fois pour un autre type
2007-11-04 19:34:16 +01:00
$nbofcontacts = $html -> select_contacts ( $selectedCompany , $selected = '' , $htmlname = 'contactid' , 0 , $contactAlreadySelected );
if ( $nbofcontacts == 0 ) print $langs -> trans ( " NoContactDefined " );
2006-05-06 17:15:48 +02:00
print '</td>' ;
print '<td>' ;
2009-02-18 13:26:55 +01:00
$formcompany -> selectTypeContact ( $commande , '' , 'type' , 'external' );
2006-05-06 17:15:48 +02:00
print '</td>' ;
2007-11-04 19:34:16 +01:00
print '<td align="right" colspan="3" ><input type="submit" class="button" value="' . $langs -> trans ( " Add " ) . '"' ;
if ( ! $nbofcontacts ) print ' disabled="true"' ;
print '></td>' ;
2006-05-06 17:15:48 +02:00
print '</tr>' ;
2006-05-06 21:06:40 +02:00
2006-05-06 17:15:48 +02:00
print " </form> " ;
2006-05-06 21:06:40 +02:00
print '<tr><td colspan="6"> </td></tr>' ;
2006-05-06 17:15:48 +02:00
}
2006-05-06 21:06:40 +02:00
2009-02-18 13:26:55 +01:00
// List of linked contacts
2006-05-06 17:15:48 +02: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 " ;
$societe = new Societe ( $db );
2006-05-06 21:06:40 +02:00
$var = true ;
2006-05-06 17:15:48 +02:00
foreach ( array ( 'internal' , 'external' ) as $source )
{
2006-05-06 21:06:40 +02:00
$tab = $commande -> liste_contact ( - 1 , $source );
$num = sizeof ( $tab );
2006-05-06 17:15:48 +02:00
$i = 0 ;
while ( $i < $num )
{
$var = ! $var ;
print '<tr ' . $bc [ $var ] . ' valign="top">' ;
2006-05-06 21:06:40 +02:00
// Source
2006-05-06 17:15:48 +02:00
print '<td align="left">' ;
2009-02-16 23:37:30 +01:00
if ( $tab [ $i ][ 'source' ] == 'internal' ) print $langs -> trans ( " User " );
if ( $tab [ $i ][ 'source' ] == 'external' ) print $langs -> trans ( " ThirdPartyContact " );
2006-05-06 21:06:40 +02:00
print '</td>' ;
2006-05-06 17:15:48 +02:00
// Societe
print '<td align="left">' ;
if ( $tab [ $i ][ 'socid' ] > 0 )
{
print '<a href="' . DOL_URL_ROOT . '/soc.php?socid=' . $tab [ $i ][ 'socid' ] . '">' ;
print img_object ( $langs -> trans ( " ShowCompany " ), " company " ) . ' ' . $societe -> get_nom ( $tab [ $i ][ 'socid' ]);
print '</a>' ;
2006-05-06 21:06:40 +02:00
}
2006-05-06 17:15:48 +02:00
if ( $tab [ $i ][ 'socid' ] < 0 )
{
2006-05-06 21:06:40 +02:00
print $conf -> global -> MAIN_INFO_SOCIETE_NOM ;
}
2006-05-06 17:15:48 +02:00
if ( ! $tab [ $i ][ 'socid' ])
2006-05-06 21:06:40 +02:00
{
print ' ' ;
}
2006-05-06 17:15:48 +02:00
print '</td>' ;
// Contact
print '<td>' ;
if ( $tab [ $i ][ 'source' ] == 'internal' )
{
print '<a href="' . DOL_URL_ROOT . '/user/fiche.php?id=' . $tab [ $i ][ 'id' ] . '">' ;
print img_object ( $langs -> trans ( " ShowUser " ), " user " ) . ' ' . $tab [ $i ][ 'nom' ] . '</a>' ;
2006-05-06 21:06:40 +02:00
}
2006-05-06 17:15:48 +02:00
if ( $tab [ $i ][ 'source' ] == 'external' )
{
print '<a href="' . DOL_URL_ROOT . '/contact/fiche.php?id=' . $tab [ $i ][ 'id' ] . '">' ;
print img_object ( $langs -> trans ( " ShowContact " ), " contact " ) . ' ' . $tab [ $i ][ 'nom' ] . '</a>' ;
2006-05-06 21:06:40 +02:00
}
2006-05-06 17:15:48 +02:00
print '</td>' ;
// Type de contact
print '<td>' . $tab [ $i ][ 'libelle' ] . '</td>' ;
// Statut
print '<td align="center">' ;
// Activation desativation du contact
2007-05-04 23:19:15 +02:00
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>' ;
2006-05-06 17:15:48 +02:00
print '</td>' ;
2006-05-06 21:15:59 +02:00
// Icon update et delete
2006-05-06 17:15:48 +02:00
print '<td align="center" nowrap>' ;
2006-05-06 21:15:59 +02:00
if ( $commande -> statut < 5 && $user -> rights -> commande -> creer )
2006-05-06 17:15:48 +02:00
{
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
{
2006-05-06 21:06:40 +02:00
// Contrat non trouv
2009-02-18 13:26:55 +01:00
print " ErrorRecordNotFound " ;
2006-05-06 17:15:48 +02:00
}
}
$db -> close ();
llxFooter ( '$Date$' );
?>