PageRenderTime 78ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/commande/contact.php

https://bitbucket.org/speedealing/speedealing
PHP | 227 lines | 142 code | 39 blank | 46 comment | 36 complexity | dbd3f1d573e5fbcf5558f3fb451c8bf5 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2005 Patrick Rouillon <patrick@rouillon.net>
  3. * Copyright (C) 2005-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2011-2012 Philippe Grand <philippe.grand@atoo-net.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/commande/contact.php
  22. * \ingroup commande
  23. * \brief Onglet de gestion des contacts de commande
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/order.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  31. $langs->load("orders");
  32. $langs->load("sendings");
  33. $langs->load("companies");
  34. $id=GETPOST('id','int');
  35. $ref=GETPOST('ref','alpha');
  36. $action=GETPOST('action','alpha');
  37. // Security check
  38. if ($user->societe_id) $socid=$user->societe_id;
  39. $result = restrictedArea($user, 'commande', $id,'');
  40. $object = new Commande($db);
  41. /*
  42. * Ajout d'un nouveau contact
  43. */
  44. if ($action == 'addcontact' && $user->rights->commande->creer)
  45. {
  46. $result = $object->fetch($id);
  47. if ($result > 0 && $id > 0)
  48. {
  49. $contactid = (GETPOST('userid','int') ? GETPOST('userid','int') : GETPOST('contactid','int'));
  50. $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
  51. }
  52. if ($result >= 0)
  53. {
  54. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  55. exit;
  56. }
  57. else
  58. {
  59. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
  60. {
  61. $langs->load("errors");
  62. $mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
  63. }
  64. else
  65. {
  66. $mesg = '<div class="error">'.$object->error.'</div>';
  67. }
  68. }
  69. }
  70. // bascule du statut d'un contact
  71. else if ($action == 'swapstatut' && $user->rights->commande->creer)
  72. {
  73. if ($object->fetch($id))
  74. {
  75. $result=$object->swapContactStatus(GETPOST('ligne'));
  76. }
  77. else
  78. {
  79. dol_print_error($db);
  80. }
  81. }
  82. // Efface un contact
  83. else if ($action == 'deletecontact' && $user->rights->commande->creer)
  84. {
  85. $object->fetch($id);
  86. $result = $object->delete_contact($_GET["lineid"]);
  87. if ($result >= 0)
  88. {
  89. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  90. exit;
  91. }
  92. else {
  93. dol_print_error($db);
  94. }
  95. }
  96. else if ($action == 'setaddress' && $user->rights->commande->creer)
  97. {
  98. $object->fetch($id);
  99. $result=$object->setDeliveryAddress($_POST['fk_address']);
  100. if ($result < 0) dol_print_error($db,$object->error);
  101. }
  102. /*
  103. * View
  104. */
  105. llxHeader('',$langs->trans('Order'),'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes');
  106. $form = new Form($db);
  107. $formcompany = new FormCompany($db);
  108. $formother = new FormOther($db);
  109. $contactstatic=new Contact($db);
  110. $userstatic=new User($db);
  111. /* *************************************************************************** */
  112. /* */
  113. /* Mode vue et edition */
  114. /* */
  115. /* *************************************************************************** */
  116. dol_htmloutput_mesg($mesg);
  117. if ($id > 0 || ! empty($ref))
  118. {
  119. $langs->trans("OrderCard");
  120. if ($object->fetch($id, $ref) > 0)
  121. {
  122. $soc = new Societe($db);
  123. $soc->fetch($object->socid);
  124. $head = commande_prepare_head($object);
  125. dol_fiche_head($head, 'contact', $langs->trans("CustomerOrder"), 0, 'order');
  126. /*
  127. * Facture synthese pour rappel
  128. */
  129. print '<table class="border" width="100%">';
  130. $linkback = '<a href="'.DOL_URL_ROOT.'/commande/liste.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
  131. // Ref
  132. print '<tr><td width="18%">'.$langs->trans("Ref").'</td><td colspan="3">';
  133. print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref');
  134. print "</td></tr>";
  135. // Ref commande client
  136. print '<tr><td>';
  137. print '<table class="nobordernopadding" width="100%"><tr><td nowrap>';
  138. print $langs->trans('RefCustomer').'</td><td align="left">';
  139. print '</td>';
  140. print '</tr></table>';
  141. print '</td><td colspan="3">';
  142. print $object->ref_client;
  143. print '</td>';
  144. print '</tr>';
  145. // Customer
  146. if (is_null($object->client)) $object->fetch_thirdparty();
  147. print "<tr><td>".$langs->trans("Company")."</td>";
  148. print '<td colspan="3">'.$object->client->getNomUrl(1).'</td></tr>';
  149. // Delivery address
  150. if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT))
  151. {
  152. print '<tr><td>';
  153. print '<table class="nobordernopadding" width="100%"><tr><td>';
  154. print $langs->trans('DeliveryAddress');
  155. print '</td>';
  156. if ($action != 'editdelivery_address' && $object->brouillon) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdelivery_address&amp;socid='.$object->socid.'&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetDeliveryAddress'),1).'</a></td>';
  157. print '</tr></table>';
  158. print '</td><td colspan="3">';
  159. if ($action == 'editdelivery_address')
  160. {
  161. $formother->form_address($_SERVER['PHP_SELF'].'?id='.$object->id,$object->fk_delivery_address,GETPOST('socid','int'),'fk_address','commande',$object->id);
  162. }
  163. else
  164. {
  165. $formother->form_address($_SERVER['PHP_SELF'].'?id='.$object->id,$object->fk_delivery_address,GETPOST('socid','int'),'none','commande',$object->id);
  166. }
  167. print '</td></tr>';
  168. }
  169. print "</table>";
  170. print '</div>';
  171. print '<br>';
  172. // Contacts lines (modules that overwrite templates must declare this into descriptor)
  173. $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
  174. foreach($dirtpls as $reldir)
  175. {
  176. $res=@include dol_buildpath($reldir.'/contacts.tpl.php');
  177. if ($res) break;
  178. }
  179. }
  180. else
  181. {
  182. // Contrat non trouve
  183. print "ErrorRecordNotFound";
  184. }
  185. }
  186. $db->close();
  187. llxFooter();
  188. ?>