PageRenderTime 62ms CodeModel.GetById 7ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/propal/contact.php

https://bitbucket.org/speedealing/speedealing
PHP | 224 lines | 149 code | 34 blank | 41 comment | 38 complexity | b2cb26c612e28ca88a4ff9937d2476bb 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-2009 Destailleur Laurent <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/comm/propal/contact.php
  22. * \ingroup propal
  23. * \brief Onglet de gestion des contacts de propal
  24. */
  25. require '../../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/propal.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("facture");
  32. $langs->load("orders");
  33. $langs->load("sendings");
  34. $langs->load("companies");
  35. $id=GETPOST('id','int');
  36. $ref= GETPOST('ref','alpha');
  37. $lineid=GETPOST('lineid','int');
  38. $action=GETPOST('action','alpha');
  39. // Security check
  40. if ($user->societe_id) $socid=$user->societe_id;
  41. $result = restrictedArea($user, 'propal', $id);
  42. $object = new Propal($db);
  43. // Load object
  44. if ($id > 0 || ! empty($ref))
  45. {
  46. $ret=$object->fetch($id, $ref);
  47. if ($ret == 0)
  48. {
  49. $langs->load("errors");
  50. setEventMessage($langs->trans('ErrorRecordNotFound'), 'errors');
  51. $error++;
  52. }
  53. else if ($ret < 0)
  54. {
  55. setEventMessage($object->error, 'errors');
  56. $error++;
  57. }
  58. }
  59. if (! $error)
  60. {
  61. $object->fetch_thirdparty();
  62. }
  63. else
  64. {
  65. header('Location: '.DOL_URL_ROOT.'/comm/propal/list.php');
  66. exit;
  67. }
  68. /*
  69. * Ajout d'un nouveau contact
  70. */
  71. if ($action == 'addcontact' && $user->rights->propale->creer)
  72. {
  73. if ($object->id > 0)
  74. {
  75. $contactid = (GETPOST('userid','int') ? GETPOST('userid','int') : GETPOST('contactid','int'));
  76. $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
  77. }
  78. if ($result >= 0)
  79. {
  80. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  81. exit;
  82. }
  83. else
  84. {
  85. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
  86. {
  87. $langs->load("errors");
  88. setEventMessage($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), 'errors');
  89. }
  90. else
  91. {
  92. setEventMessage($object->error, 'errors');
  93. }
  94. }
  95. }
  96. // Bascule du statut d'un contact
  97. else if ($action == 'swapstatut' && $user->rights->propale->creer)
  98. {
  99. if ($object->id > 0)
  100. {
  101. $result=$object->swapContactStatus(GETPOST('ligne'));
  102. }
  103. }
  104. // Efface un contact
  105. else if ($action == 'deletecontact' && $user->rights->propale->creer)
  106. {
  107. $result = $object->delete_contact($lineid);
  108. if ($result >= 0)
  109. {
  110. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  111. exit;
  112. }
  113. else
  114. {
  115. dol_print_error($db);
  116. }
  117. }
  118. else if ($action == 'setaddress' && $user->rights->propale->creer)
  119. {
  120. $result=$object->setDeliveryAddress($_POST['fk_address']);
  121. if ($result < 0) dol_print_error($db,$object->error);
  122. }
  123. /*
  124. * View
  125. */
  126. llxHeader('',$langs->trans('Proposal'),'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos');
  127. $form = new Form($db);
  128. $formcompany= new FormCompany($db);
  129. $formother = new FormOther($db);
  130. if ($object->id > 0)
  131. {
  132. $head = propal_prepare_head($object);
  133. dol_fiche_head($head, 'contact', $langs->trans("Proposal"), 0, 'propal');
  134. /*
  135. * Propal synthese pour rappel
  136. */
  137. print '<table class="border" width="100%">';
  138. $linkback='<a href="'.DOL_URL_ROOT.'/comm/propal/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
  139. // Ref
  140. print '<tr><td width="25%">'.$langs->trans('Ref').'</td><td colspan="3">';
  141. print $form->showrefnav($object,'ref',$linkback,1,'ref','ref','');
  142. print '</td></tr>';
  143. // Ref client
  144. print '<tr><td>';
  145. print '<table class="nobordernopadding" width="100%"><tr><td nowrap>';
  146. print $langs->trans('RefCustomer').'</td><td align="left">';
  147. print '</td>';
  148. print '</tr></table>';
  149. print '</td><td colspan="3">';
  150. print $object->ref_client;
  151. print '</td>';
  152. print '</tr>';
  153. // Customer
  154. print "<tr><td>".$langs->trans("Company")."</td>";
  155. print '<td colspan="3">'.$object->client->getNomUrl(1).'</td></tr>';
  156. // Delivery address
  157. if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT))
  158. {
  159. print '<tr><td>';
  160. print '<table class="nobordernopadding" width="100%"><tr><td>';
  161. print $langs->trans('DeliveryAddress');
  162. print '</td>';
  163. if ($action != 'editdelivery_address' && ! empty($object->brouillon))
  164. 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>';
  165. print '</tr></table>';
  166. print '</td><td colspan="3">';
  167. if ($action == 'editdelivery_address')
  168. {
  169. $formother->form_address($_SERVER['PHP_SELF'].'?id='.$object->id,$object->fk_delivery_address,$object->socid,'fk_address','propal',$object->id);
  170. }
  171. else
  172. {
  173. $formother->form_address($_SERVER['PHP_SELF'].'?id='.$object->id,$object->fk_delivery_address,$object->socid,'none','propal',$object->id);
  174. }
  175. print '</td></tr>';
  176. }
  177. print "</table>";
  178. print '</div>';
  179. print '<br>';
  180. // Contacts lines (modules that overwrite templates must declare this into descriptor)
  181. $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
  182. foreach($dirtpls as $reldir)
  183. {
  184. $res=@include dol_buildpath($reldir.'/contacts.tpl.php');
  185. if ($res) break;
  186. }
  187. }
  188. llxFooter();
  189. $db->close();
  190. ?>