PageRenderTime 53ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/expedition/contact.php

https://bitbucket.org/speedealing/speedealing
PHP | 426 lines | 296 code | 70 blank | 60 comment | 70 complexity | 81571d0d6d6ca0b5abc6ccc89f060bd9 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. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/expedition/contact.php
  21. * \ingroup expedition
  22. * \brief Onglet de gestion des contacts de expedition
  23. */
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/sendings.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  30. $langs->load("orders");
  31. $langs->load("sendings");
  32. $langs->load("companies");
  33. $id=GETPOST('id','int');
  34. $ref=GETPOST('ref','alpha');
  35. $action=GETPOST('action','alpha');
  36. // Security check
  37. if ($user->societe_id) $socid=$user->societe_id;
  38. $result = restrictedArea($user, 'expedition', $id,'');
  39. $object = new Expedition($db);
  40. if ($id > 0 || ! empty($ref))
  41. {
  42. $object->fetch($id, $ref);
  43. if (!empty($object->origin))
  44. {
  45. $typeobject = $object->origin;
  46. $origin = $object->origin;
  47. $object->fetch_origin();
  48. }
  49. // Linked documents
  50. if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))
  51. {
  52. $objectsrc=new Commande($db);
  53. $objectsrc->fetch($object->$typeobject->id);
  54. }
  55. if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
  56. {
  57. $objectsrc=new Propal($db);
  58. $objectsrc->fetch($object->$typeobject->id);
  59. }
  60. }
  61. /*
  62. * Actions
  63. */
  64. if ($action == 'addcontact' && $user->rights->expedition->creer)
  65. {
  66. if ($result > 0 && $id > 0)
  67. {
  68. $result = $objectsrc->add_contact($_POST["contactid"], $_POST["type"], $_POST["source"]);
  69. }
  70. if ($result >= 0)
  71. {
  72. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  73. exit;
  74. }
  75. else
  76. {
  77. if ($objectsrc->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
  78. {
  79. $langs->load("errors");
  80. $mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
  81. }
  82. else
  83. {
  84. $mesg = '<div class="error">'.$objectsrc->error.'</div>';
  85. }
  86. }
  87. }
  88. // bascule du statut d'un contact
  89. else if ($action == 'swapstatut' && $user->rights->expedition->creer)
  90. {
  91. $result=$objectsrc->swapContactStatus(GETPOST('ligne'));
  92. }
  93. // Efface un contact
  94. else if ($action == 'deleteline' && $user->rights->expedition->creer)
  95. {
  96. $result = $objectsrc->delete_contact($_GET["lineid"]);
  97. if ($result >= 0)
  98. {
  99. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  100. exit;
  101. }
  102. else {
  103. dol_print_error($db);
  104. }
  105. }
  106. else if ($action == 'setaddress' && $user->rights->expedition->creer)
  107. {
  108. $object->fetch($id);
  109. $result=$object->setDeliveryAddress($_POST['fk_address']);
  110. if ($result < 0) dol_print_error($db,$object->error);
  111. }
  112. /*
  113. * View
  114. */
  115. llxHeader('',$langs->trans('Order'),'EN:Customers_Orders|FR:expeditions_Clients|ES:Pedidos de clientes');
  116. $form = new Form($db);
  117. $formcompany = new FormCompany($db);
  118. $formother = new FormOther($db);
  119. $contactstatic=new Contact($db);
  120. $userstatic=new User($db);
  121. /* *************************************************************************** */
  122. /* */
  123. /* Mode vue et edition */
  124. /* */
  125. /* *************************************************************************** */
  126. dol_htmloutput_mesg($mesg);
  127. if ($id > 0 || ! empty($ref))
  128. {
  129. $langs->trans("OrderCard");
  130. $soc = new Societe($db);
  131. $soc->fetch($object->socid);
  132. $head = shipping_prepare_head($object);
  133. dol_fiche_head($head, 'contact', $langs->trans("Sending"), 0, 'sending');
  134. if (is_null($object->client)) $object->fetch_thirdparty();
  135. /*
  136. * Facture synthese pour rappel
  137. */
  138. print '<table class="border" width="100%">';
  139. $linkback = '<a href="'.DOL_URL_ROOT.'/expedition/liste.php">'.$langs->trans("BackToList").'</a>';
  140. // Ref
  141. print '<tr><td width="18%">'.$langs->trans("Ref").'</td><td colspan="3">';
  142. print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref');
  143. print "</td></tr>";
  144. // Customer
  145. print '<tr><td width="20%">'.$langs->trans("Customer").'</td>';
  146. print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';
  147. print "</tr>";
  148. // Linked documents
  149. if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))
  150. {
  151. print '<tr><td>';
  152. $objectsrc=new Commande($db);
  153. $objectsrc->fetch($object->$typeobject->id);
  154. print $langs->trans("RefOrder").'</td>';
  155. print '<td colspan="3">';
  156. print $objectsrc->getNomUrl(1,'commande');
  157. print "</td>\n";
  158. print '</tr>';
  159. }
  160. if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
  161. {
  162. print '<tr><td>';
  163. $objectsrc=new Propal($db);
  164. $objectsrc->fetch($object->$typeobject->id);
  165. print $langs->trans("RefProposal").'</td>';
  166. print '<td colspan="3">';
  167. print $objectsrc->getNomUrl(1,'expedition');
  168. print "</td>\n";
  169. print '</tr>';
  170. }
  171. // Ref expedition client
  172. print '<tr><td>';
  173. print '<table class="nobordernopadding" width="100%"><tr><td nowrap>';
  174. print $langs->trans('RefCustomer').'</td><td align="left">';
  175. print '</td>';
  176. print '</tr></table>';
  177. print '</td><td colspan="3">';
  178. print $objectsrc->ref_client;
  179. print '</td>';
  180. print '</tr>';
  181. // Delivery address
  182. if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT))
  183. {
  184. print '<tr><td>';
  185. print '<table class="nobordernopadding" width="100%"><tr><td>';
  186. print $langs->trans('DeliveryAddress');
  187. print '</td>';
  188. 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>';
  189. print '</tr></table>';
  190. print '</td><td colspan="3">';
  191. if ($action == 'editdelivery_address')
  192. {
  193. $formother->form_address($_SERVER['PHP_SELF'].'?id='.$object->id,$object->fk_delivery_address,$object->socid,'fk_address','shipping',$object->id);
  194. }
  195. else
  196. {
  197. $formother->form_address($_SERVER['PHP_SELF'].'?id='.$object->id,$object->fk_delivery_address,$object->socid,'none','shipping',$object->id);
  198. }
  199. print '</td></tr>';
  200. }
  201. print "</table>";
  202. print '</div>';
  203. // Lignes de contacts
  204. echo '<br><table class="noborder" width="100%">';
  205. /*
  206. * Ajouter une ligne de contact. Non affiche en mode modification de ligne
  207. */
  208. if ($action != 'editline' && $user->rights->expedition->creer)
  209. {
  210. print '<tr class="liste_titre">';
  211. print '<td>'.$langs->trans("Source").'</td>';
  212. print '<td>'.$langs->trans("Company").'</td>';
  213. print '<td>'.$langs->trans("Contacts").'</td>';
  214. print '<td>'.$langs->trans("ContactType").'</td>';
  215. print '<td>&nbsp;</td>';
  216. print '<td colspan="2">&nbsp;</td>';
  217. print "</tr>\n";
  218. $var = false;
  219. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="post">';
  220. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  221. print '<input type="hidden" name="action" value="addcontact">';
  222. print '<input type="hidden" name="source" value="internal">';
  223. print '<input type="hidden" name="id" value="'.$id.'">';
  224. // Ligne ajout pour contact interne
  225. print '<tr '.$bc[$var].'>';
  226. print '<td nowrap="nowrap">';
  227. print img_object('','user').' '.$langs->trans("Users");
  228. print '</td>';
  229. print '<td colspan="1">';
  230. print $conf->global->MAIN_INFO_SOCIETE_NOM;
  231. print '</td>';
  232. print '<td colspan="1">';
  233. //$userAlreadySelected = $object->getListContactId('internal'); // On ne doit pas desactiver un contact deja selectionne car on doit pouvoir le selectionner une deuxieme fois pour un autre type
  234. $form->select_users($user->id,'contactid',0,$userAlreadySelected);
  235. print '</td>';
  236. print '<td>';
  237. $formcompany->selectTypeContact($objectsrc, '', 'type','internal');
  238. print '</td>';
  239. print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
  240. print '</tr>';
  241. print '</form>';
  242. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="post">';
  243. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  244. print '<input type="hidden" name="action" value="addcontact">';
  245. print '<input type="hidden" name="source" value="external">';
  246. print '<input type="hidden" name="id" value="'.$id.'">';
  247. // Ligne ajout pour contact externe
  248. $var=!$var;
  249. print '<tr '.$bc[$var].'>';
  250. print '<td nowrap="nowrap">';
  251. print img_object('','contact').' '.$langs->trans("ThirdPartyContacts");
  252. print '</td>';
  253. print '<td colspan="1">';
  254. $selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$object->client->id;
  255. $selectedCompany = $formcompany->selectCompaniesForNewContact($objectsrc, 'id', $selectedCompany, 'newcompany', '', $object->id);
  256. print '</td>';
  257. print '<td colspan="1">';
  258. $nbofcontacts=$form->select_contacts($selectedCompany, '', 'contactid');
  259. if ($nbofcontacts == 0) print $langs->trans("NoContactDefined");
  260. print '</td>';
  261. print '<td>';
  262. $formcompany->selectTypeContact($objectsrc, '', 'type','external');
  263. print '</td>';
  264. print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"';
  265. if (! $nbofcontacts) print ' disabled="disabled"';
  266. print '></td>';
  267. print '</tr>';
  268. print "</form>";
  269. print '<tr><td colspan="7">&nbsp;</td></tr>';
  270. }
  271. // List of linked contacts
  272. print '<tr class="liste_titre">';
  273. print '<td>'.$langs->trans("Source").'</td>';
  274. print '<td>'.$langs->trans("Company").'</td>';
  275. print '<td>'.$langs->trans("Contacts").'</td>';
  276. print '<td>'.$langs->trans("ContactType").'</td>';
  277. print '<td align="center">'.$langs->trans("Status").'</td>';
  278. print '<td colspan="2">&nbsp;</td>';
  279. print "</tr>\n";
  280. $companystatic=new Societe($db);
  281. $var = true;
  282. foreach(array('internal','external') as $source)
  283. {
  284. $tab = $objectsrc->liste_contact(-1,$source);
  285. $num=count($tab);
  286. $i = 0;
  287. while ($i < $num)
  288. {
  289. $var = !$var;
  290. print '<tr '.$bc[$var].' valign="top">';
  291. // Source
  292. print '<td align="left">';
  293. if ($tab[$i]['source']=='internal') print $langs->trans("User");
  294. if ($tab[$i]['source']=='external') print $langs->trans("ThirdPartyContact");
  295. print '</td>';
  296. // Societe
  297. print '<td align="left">';
  298. if ($tab[$i]['socid'] > 0)
  299. {
  300. $companystatic->fetch($tab[$i]['socid']);
  301. print $companystatic->getNomUrl(1);
  302. }
  303. if ($tab[$i]['socid'] < 0)
  304. {
  305. print $conf->global->MAIN_INFO_SOCIETE_NOM;
  306. }
  307. if (! $tab[$i]['socid'])
  308. {
  309. print '&nbsp;';
  310. }
  311. print '</td>';
  312. // Contact
  313. print '<td>';
  314. if ($tab[$i]['source']=='internal')
  315. {
  316. $userstatic->id=$tab[$i]['id'];
  317. $userstatic->lastname=$tab[$i]['lastname'];
  318. $userstatic->firstname=$tab[$i]['firstname'];
  319. print $userstatic->getNomUrl(1);
  320. }
  321. if ($tab[$i]['source']=='external')
  322. {
  323. $contactstatic->id=$tab[$i]['id'];
  324. $contactstatic->lastname=$tab[$i]['lastname'];
  325. $contactstatic->firstname=$tab[$i]['firstname'];
  326. print $contactstatic->getNomUrl(1);
  327. }
  328. print '</td>';
  329. // Type de contact
  330. print '<td>'.$tab[$i]['libelle'].'</td>';
  331. // Statut
  332. print '<td align="center">';
  333. // Activation desativation du contact
  334. if ($object->statut >= 0) print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=swapstatut&amp;ligne='.$tab[$i]['rowid'].'">';
  335. print $contactstatic->LibStatut($tab[$i]['status'],3);
  336. if ($object->statut >= 0) print '</a>';
  337. print '</td>';
  338. // Icon update et delete
  339. print '<td align="center" nowrap="nowrap" colspan="2">';
  340. if ($object->statut < 5 && $user->rights->expedition->creer)
  341. {
  342. print '&nbsp;';
  343. print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=deleteline&amp;lineid='.$tab[$i]['rowid'].'">';
  344. print img_delete();
  345. print '</a>';
  346. }
  347. print '</td>';
  348. print "</tr>\n";
  349. $i ++;
  350. }
  351. }
  352. print "</table>";
  353. }
  354. llxFooter();
  355. $db->close();
  356. ?>