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

/htdocs/comm/propal/contact.php

https://github.com/asterix14/dolibarr
PHP | 376 lines | 250 code | 66 blank | 60 comment | 39 complexity | 2851ad04134127bc129c95b4bb2e1490 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2005 Patrick Rouillon <patrick@rouillon.net>
  3. * Copyright (C) 2005-2009 Destailleur Laurent <eldy@users.sourceforge.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/comm/propal/contact.php
  20. * \ingroup propal
  21. * \brief Onglet de gestion des contacts de propal
  22. */
  23. require("../../main.inc.php");
  24. require_once(DOL_DOCUMENT_ROOT."/comm/propal/class/propal.class.php");
  25. require_once(DOL_DOCUMENT_ROOT."/contact/class/contact.class.php");
  26. require_once(DOL_DOCUMENT_ROOT."/core/lib/propal.lib.php");
  27. require_once(DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php');
  28. $langs->load("facture");
  29. $langs->load("orders");
  30. $langs->load("sendings");
  31. $langs->load("companies");
  32. $id=GETPOST('id');
  33. $ligne=GETPOST('ligne');
  34. $lineid=GETPOST('lineid');
  35. $action=GETPOST('action');
  36. $id = isset($id)?$id:'';
  37. // Security check
  38. if ($user->societe_id) $socid=$user->societe_id;
  39. $result = restrictedArea($user, 'propale', $id, 'propal');
  40. /*
  41. * Ajout d'un nouveau contact
  42. */
  43. if ($_POST["action"] == 'addcontact' && $user->rights->propale->creer)
  44. {
  45. $result = 0;
  46. $propal = new Propal($db);
  47. $result = $propal->fetch($id);
  48. if ($result > 0 && $id > 0)
  49. {
  50. $result = $propal->add_contact($_POST["contactid"], $_POST["type"], $_POST["source"]);
  51. }
  52. if ($result >= 0)
  53. {
  54. Header("Location: contact.php?id=".$propal->id);
  55. exit;
  56. }
  57. else
  58. {
  59. if ($propal->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">'.$propal->error.'</div>';
  67. }
  68. }
  69. }
  70. // Bascule du statut d'un contact
  71. if ($action == 'swapstatut' && $user->rights->propale->creer)
  72. {
  73. $propal = new Propal($db);
  74. if ($propal->fetch($id) > 0)
  75. {
  76. $result=$propal->swapContactStatus(GETPOST('ligne'));
  77. }
  78. else
  79. {
  80. dol_print_error($db);
  81. }
  82. }
  83. // Efface un contact
  84. if ($action == 'deleteline' && $user->rights->propale->creer)
  85. {
  86. $propal = new Propal($db);
  87. $propal->fetch($id);
  88. $result = $propal->delete_contact($lineid);
  89. if ($result >= 0)
  90. {
  91. Header("Location: contact.php?id=".$propal->id);
  92. exit;
  93. }
  94. else {
  95. dol_print_error($db);
  96. }
  97. }
  98. /*
  99. * View
  100. */
  101. llxHeader('', $langs->trans("Proposal"), "Propal");
  102. $form = new Form($db);
  103. $formcompany= new FormCompany($db);
  104. $contactstatic=new Contact($db);
  105. $userstatic=new User($db);
  106. /* *************************************************************************** */
  107. /* */
  108. /* Mode vue et edition */
  109. /* */
  110. /* *************************************************************************** */
  111. dol_htmloutput_mesg($mesg);
  112. $id = $id;
  113. $ref= GETPOST('ref');
  114. if ($id > 0 || ! empty($ref))
  115. {
  116. $propal = New Propal($db);
  117. if ( $propal->fetch($id,$ref) > 0)
  118. {
  119. $soc = new Societe($db);
  120. $soc->fetch($propal->socid);
  121. $head = propal_prepare_head($propal);
  122. dol_fiche_head($head, 'contact', $langs->trans("Proposal"), 0, 'propal');
  123. /*
  124. * Propal synthese pour rappel
  125. */
  126. print '<table class="border" width="100%">';
  127. $linkback="<a href=\"".DOL_URL_ROOT.'/comm/propal.php'."?page=$page&socid=$socid&viewstatut=$viewstatut&sortfield=$sortfield&$sortorder\">".$langs->trans("BackToList")."</a>";
  128. // Ref
  129. print '<tr><td width="25%">'.$langs->trans('Ref').'</td><td colspan="3">';
  130. print $form->showrefnav($propal,'ref',$linkback,1,'ref','ref','');
  131. print '</td></tr>';
  132. // Ref client
  133. print '<tr><td>';
  134. print '<table class="nobordernopadding" width="100%"><tr><td nowrap>';
  135. print $langs->trans('RefCustomer').'</td><td align="left">';
  136. print '</td>';
  137. print '</tr></table>';
  138. print '</td><td colspan="3">';
  139. print $propal->ref_client;
  140. print '</td>';
  141. print '</tr>';
  142. // Customer
  143. if ( is_null($propal->client) )
  144. $propal->fetch_thirdparty();
  145. print "<tr><td>".$langs->trans("Company")."</td>";
  146. print '<td colspan="3">'.$propal->client->getNomUrl(1).'</td></tr>';
  147. print "</table>";
  148. print '</div>';
  149. /*
  150. * Lignes de contacts
  151. */
  152. echo '<br><table class="noborder" width="100%">';
  153. /*
  154. * Ajouter une ligne de contact
  155. * Non affiche en mode modification de ligne
  156. */
  157. if ($action != 'editline' && $user->rights->propale->creer)
  158. {
  159. print '<tr class="liste_titre">';
  160. print '<td>'.$langs->trans("Source").'</td>';
  161. print '<td>'.$langs->trans("Company").'</td>';
  162. print '<td>'.$langs->trans("Contacts").'</td>';
  163. print '<td>'.$langs->trans("ContactType").'</td>';
  164. print '<td colspan="3">&nbsp;</td>';
  165. print "</tr>\n";
  166. $var = false;
  167. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="POST">';
  168. print '<input type="hidden" name="id" value="'.$id.'">';
  169. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  170. print '<input type="hidden" name="action" value="addcontact">';
  171. print '<input type="hidden" name="source" value="internal">';
  172. // Line to add an internal contact
  173. print "<tr ".$bc[$var].">";
  174. print '<td nowrap="nowrap">';
  175. print img_object('','user').' '.$langs->trans("Users");
  176. print '</td>';
  177. print '<td>';
  178. print $conf->global->MAIN_INFO_SOCIETE_NOM;
  179. print '</td>';
  180. print '<td>';
  181. // On recupere les id des users deja selectionnes
  182. //$userAlreadySelected = $propal->getListContactId('internal'); // On ne doit pas desactiver un contact deja selectionne car on doit pouvoir le selectionner une deuxieme fois pour un autre type
  183. $form->select_users($user->id,'contactid',0,$userAlreadySelected);
  184. print '</td>';
  185. print '<td>';
  186. $formcompany->selectTypeContact($propal, '', 'type','internal');
  187. print '</td>';
  188. print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
  189. print '</tr>';
  190. print '</form>';
  191. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="POST">';
  192. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  193. print '<input type="hidden" name="action" value="addcontact">';
  194. print '<input type="hidden" name="id" value="'.$id.'">';
  195. print '<input type="hidden" name="source" value="external">';
  196. // Line to add an external contact
  197. $var=!$var;
  198. print "<tr ".$bc[$var].">";
  199. print '<td nowrap="nowrap">';
  200. print img_object('','contact').' '.$langs->trans("ThirdPartyContacts");
  201. print '</td>';
  202. print '<td>';
  203. $selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$propal->client->id;
  204. $selectedCompany = $formcompany->selectCompaniesForNewContact($propal, 'id', $selectedCompany, 'newcompany');
  205. print '</td>';
  206. print '<td>';
  207. $nbofcontacts=$form->select_contacts($selectedCompany, '', 'contactid');
  208. if ($nbofcontacts == 0) print $langs->trans("NoContactDefined");
  209. print '</td>';
  210. print '<td>';
  211. $formcompany->selectTypeContact($propal, '', 'type','external');
  212. print '</td>';
  213. print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"';
  214. if (! $nbofcontacts) print ' disabled="disabled"';
  215. print '></td>';
  216. print '</tr>';
  217. print '</form>';
  218. print '<tr><td colspan="7">&nbsp;</td></tr>';
  219. }
  220. // Liste des contacts lies
  221. print '<tr class="liste_titre">';
  222. print '<td>'.$langs->trans("Source").'</td>';
  223. print '<td>'.$langs->trans("Company").'</td>';
  224. print '<td>'.$langs->trans("Contacts").'</td>';
  225. print '<td>'.$langs->trans("ContactType").'</td>';
  226. print '<td align="center">'.$langs->trans("Status").'</td>';
  227. print '<td colspan="2">&nbsp;</td>';
  228. print "</tr>\n";
  229. $companystatic = new Societe($db);
  230. $var = true;
  231. foreach(array('internal','external') as $source)
  232. {
  233. $tab = $propal->liste_contact(-1,$source);
  234. $num=count($tab);
  235. $i = 0;
  236. while ($i < $num)
  237. {
  238. $var = !$var;
  239. print '<tr '.$bc[$var].' valign="top">';
  240. // Source
  241. print '<td align="left">';
  242. if ($tab[$i]['source']=='internal') print $langs->trans("User");
  243. if ($tab[$i]['source']=='external') print $langs->trans("ThirdPartyContact");
  244. print '</td>';
  245. // Societe
  246. print '<td align="left">';
  247. if ($tab[$i]['socid'] > 0)
  248. {
  249. $companystatic->fetch($tab[$i]['socid']);
  250. print $companystatic->getNomUrl(1);
  251. }
  252. if ($tab[$i]['socid'] < 0)
  253. {
  254. print $conf->global->MAIN_INFO_SOCIETE_NOM;
  255. }
  256. if (! $tab[$i]['socid'])
  257. {
  258. print '&nbsp;';
  259. }
  260. print '</td>';
  261. // Contact
  262. print '<td>';
  263. if ($tab[$i]['source']=='internal')
  264. {
  265. $userstatic->id=$tab[$i]['id'];
  266. $userstatic->nom=$tab[$i]['nom'];
  267. $userstatic->prenom=$tab[$i]['firstname'];
  268. print $userstatic->getNomUrl(1);
  269. }
  270. if ($tab[$i]['source']=='external')
  271. {
  272. $contactstatic->id=$tab[$i]['id'];
  273. $contactstatic->name=$tab[$i]['nom'];
  274. $contactstatic->firstname=$tab[$i]['firstname'];
  275. print $contactstatic->getNomUrl(1);
  276. }
  277. print '</td>';
  278. // Type de contact
  279. print '<td>'.$tab[$i]['libelle'].'</td>';
  280. // Statut
  281. print '<td align="center">';
  282. // Activation desativation du contact
  283. if ($propal->statut >= 0) print '<a href="contact.php?id='.$propal->id.'&amp;action=swapstatut&amp;ligne='.$tab[$i]['rowid'].'">';
  284. print $contactstatic->LibStatut($tab[$i]['status'],3);
  285. if ($propal->statut >= 0) print '</a>';
  286. print '</td>';
  287. // Icon update et delete
  288. print '<td align="center" nowrap="nowrap" colspan="2">';
  289. if ($user->rights->propale->creer)
  290. {
  291. print '&nbsp;';
  292. print '<a href="contact.php?id='.$propal->id.'&amp;action=deleteline&amp;lineid='.$tab[$i]['rowid'].'">';
  293. print img_delete();
  294. print '</a>';
  295. }
  296. print '</td>';
  297. print "</tr>\n";
  298. $i ++;
  299. }
  300. }
  301. print "</table>";
  302. }
  303. else
  304. {
  305. print "ErrorRecordNotFound";
  306. }
  307. }
  308. $db->close();
  309. llxFooter();
  310. ?>