PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/projet/contact.php

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