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

/htdocs/projet/tasks/contact.php

https://github.com/asterix14/dolibarr
PHP | 382 lines | 251 code | 64 blank | 67 comment | 42 complexity | c5583f23b12734378368a426189aed6e MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2010 Regis Houssin <regis@dolibarr.fr>
  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 2 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/projet/tasks/contact.php
  21. * \ingroup project
  22. * \brief Actors of a task
  23. */
  24. require ("../../main.inc.php");
  25. require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php");
  26. require_once(DOL_DOCUMENT_ROOT."/projet/class/task.class.php");
  27. require_once(DOL_DOCUMENT_ROOT."/contact/class/contact.class.php");
  28. require_once(DOL_DOCUMENT_ROOT."/core/lib/project.lib.php");
  29. require_once(DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php');
  30. $langs->load("projects");
  31. $langs->load("companies");
  32. $taskid = isset($_GET["id"])?$_GET["id"]:'';
  33. // Security check
  34. $socid=0;
  35. if ($user->societe_id > 0) $socid = $user->societe_id;
  36. //$result = restrictedArea($user, 'projet', $taskid, 'projet_task');
  37. if (!$user->rights->projet->lire) accessforbidden();
  38. /*
  39. * Actions
  40. */
  41. // Add new contact
  42. if ($_POST["action"] == 'addcontact' && $user->rights->projet->creer)
  43. {
  44. $result = 0;
  45. $task = new Task($db);
  46. $result = $task->fetch($taskid);
  47. if ($result > 0 && $taskid > 0)
  48. {
  49. $result = $task->add_contact($_POST["contactid"], $_POST["type"], $_POST["source"]);
  50. }
  51. if ($result >= 0)
  52. {
  53. Header("Location: contact.php?id=".$task->id);
  54. exit;
  55. }
  56. else
  57. {
  58. if ($task->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
  59. {
  60. $langs->load("errors");
  61. $mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
  62. }
  63. else
  64. {
  65. $mesg = '<div class="error">'.$task->error.'</div>';
  66. }
  67. }
  68. }
  69. // bascule du statut d'un contact
  70. if ($_GET["action"] == 'swapstatut' && $user->rights->projet->creer)
  71. {
  72. $task = new Task($db);
  73. if ($task->fetch($taskid))
  74. {
  75. $result=$task->swapContactStatus(GETPOST('ligne'));
  76. }
  77. else
  78. {
  79. dol_print_error($db);
  80. }
  81. }
  82. // Efface un contact
  83. if ($_GET["action"] == 'deleteline' && $user->rights->projet->creer)
  84. {
  85. $task = new Task($db);
  86. $task->fetch($taskid);
  87. $result = $task->delete_contact($_GET["lineid"]);
  88. if ($result >= 0)
  89. {
  90. Header("Location: contact.php?id=".$task->id);
  91. exit;
  92. }
  93. else
  94. {
  95. dol_print_error($db);
  96. }
  97. }
  98. /*
  99. * View
  100. */
  101. llxHeader('', $langs->trans("Task"));
  102. $form = new Form($db);
  103. $formcompany = new FormCompany($db);
  104. $contactstatic = new Contact($db);
  105. $userstatic = new User($db);
  106. $project = new Project($db);
  107. /* *************************************************************************** */
  108. /* */
  109. /* Mode vue et edition */
  110. /* */
  111. /* *************************************************************************** */
  112. dol_htmloutput_mesg($mesg);
  113. $id = $_GET['id'];
  114. $ref= $_GET['ref'];
  115. if ($id > 0 || ! empty($ref))
  116. {
  117. $task = new Task($db);
  118. if ( $task->fetch($id,$ref) > 0)
  119. {
  120. $result=$project->fetch($task->fk_project);
  121. if (! empty($project->socid)) $project->societe->fetch($project->socid);
  122. // To verify role of users
  123. //$userAccess = $projectstatic->restrictedProjectArea($user); // We allow task affected to user even if a not allowed project
  124. //$arrayofuseridoftask=$task->getListContactId('internal');
  125. $head = task_prepare_head($task);
  126. dol_fiche_head($head, 'contact', $langs->trans("Task"), 0, 'projecttask');
  127. /*
  128. * Projet synthese pour rappel
  129. */
  130. print '<table class="border" width="100%">';
  131. //$linkback="<a href=\"".$_SERVER["PHP_SELF"]."?page=$page&socid=$socid&viewstatut=$viewstatut&sortfield=$sortfield&$sortorder\">".$langs->trans("BackToList")."</a>";
  132. // Ref
  133. print '<tr><td width="30%">'.$langs->trans('Ref').'</td><td colspan="3">';
  134. $projectsListId = $project->getProjectsAuthorizedForUser($user,$mine,1);
  135. $task->next_prev_filter=" fk_projet in (".$projectsListId.")";
  136. print $form->showrefnav($task,'id','',1,'rowid','ref','','');
  137. print '</td></tr>';
  138. // Label
  139. print '<tr><td>'.$langs->trans("Label").'</td><td>'.$task->label.'</td></tr>';
  140. // Project
  141. print '<tr><td>'.$langs->trans("Project").'</td><td>';
  142. print $project->getNomUrl(1);
  143. print '</td></tr>';
  144. // Customer
  145. print "<tr><td>".$langs->trans("Company")."</td>";
  146. print '<td colspan="3">';
  147. if ($project->societe->id > 0) print $project->societe->getNomUrl(1);
  148. else print '&nbsp;';
  149. print '</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)
  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("ProjectContact").'</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. $contactsofproject=$project->getListContactId('internal');
  186. $form->select_users($user->id,'contactid',0,'',0,'',$contactsofproject);
  187. print '</td>';
  188. print '<td>';
  189. $formcompany->selectTypeContact($task, '', 'type','internal','rowid');
  190. print '</td>';
  191. print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
  192. print '</tr>';
  193. print '</form>';
  194. // Line to add an external contact. Only if project linked to a third party.
  195. if ($project->socid)
  196. {
  197. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="POST">';
  198. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  199. print '<input type="hidden" name="action" value="addcontact">';
  200. print '<input type="hidden" name="source" value="external">';
  201. print '<input type="hidden" name="id" value="'.$id.'">';
  202. $var=!$var;
  203. print "<tr $bc[$var]>";
  204. print '<td nowrap="nowrap">';
  205. print img_object('','contact').' '.$langs->trans("ThirdPartyContacts");
  206. print '</td>';
  207. print '<td colspan="1">';
  208. $thirdpartyofproject=$project->getListContactId('thirdparty');
  209. $selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$project->societe->id;
  210. $selectedCompany = $formcompany->selectCompaniesForNewContact($task, 'id', $selectedCompany, 'newcompany',$thirdpartyofproject);
  211. print '</td>';
  212. print '<td colspan="1">';
  213. $contactofproject=$project->getListContactId('external');
  214. $nbofcontacts=$form->select_contacts($selectedCompany,'','contactid',0,'',$contactofproject);
  215. if ($nbofcontacts == 0) print $langs->trans("NoContactDefined");
  216. print '</td>';
  217. print '<td>';
  218. $formcompany->selectTypeContact($task, '', 'type','external','rowid');
  219. print '</td>';
  220. print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"';
  221. if (! $nbofcontacts) print ' disabled="disabled"';
  222. print '></td>';
  223. print '</tr>';
  224. print "</form>";
  225. }
  226. print '<tr><td colspan="6">&nbsp;</td></tr>';
  227. }
  228. // Liste des contacts lies
  229. print '<tr class="liste_titre">';
  230. print '<td>'.$langs->trans("Source").'</td>';
  231. print '<td>'.$langs->trans("Company").'</td>';
  232. print '<td>'.$langs->trans("ProjectContact").'</td>';
  233. print '<td>'.$langs->trans("ContactType").'</td>';
  234. print '<td align="center">'.$langs->trans("Status").'</td>';
  235. print '<td colspan="2">&nbsp;</td>';
  236. print "</tr>\n";
  237. $companystatic = new Societe($db);
  238. $var = true;
  239. foreach(array('internal','external') as $source)
  240. {
  241. $tab = $task->liste_contact(-1,$source);
  242. $num=count($tab);
  243. $i = 0;
  244. while ($i < $num)
  245. {
  246. $var = !$var;
  247. print '<tr '.$bc[$var].' valign="top">';
  248. // Source
  249. print '<td align="left">';
  250. if ($tab[$i]['source']=='internal') print $langs->trans("User");
  251. if ($tab[$i]['source']=='external') print $langs->trans("ThirdPartyContact");
  252. print '</td>';
  253. // Societe
  254. print '<td align="left">';
  255. if ($tab[$i]['socid'] > 0)
  256. {
  257. $companystatic->fetch($tab[$i]['socid']);
  258. print $companystatic->getNomUrl(1);
  259. }
  260. if ($tab[$i]['socid'] < 0)
  261. {
  262. print $conf->global->MAIN_INFO_SOCIETE_NOM;
  263. }
  264. if (! $tab[$i]['socid'])
  265. {
  266. print '&nbsp;';
  267. }
  268. print '</td>';
  269. // Contact
  270. print '<td>';
  271. if ($tab[$i]['source']=='internal')
  272. {
  273. $userstatic->id=$tab[$i]['id'];
  274. $userstatic->nom=$tab[$i]['nom'];
  275. $userstatic->prenom=$tab[$i]['firstname'];
  276. print $userstatic->getNomUrl(1);
  277. }
  278. if ($tab[$i]['source']=='external')
  279. {
  280. $contactstatic->id=$tab[$i]['id'];
  281. $contactstatic->name=$tab[$i]['nom'];
  282. $contactstatic->firstname=$tab[$i]['firstname'];
  283. print $contactstatic->getNomUrl(1);
  284. }
  285. print '</td>';
  286. // Type de contact
  287. print '<td>'.$tab[$i]['libelle'].'</td>';
  288. // Statut
  289. print '<td align="center">';
  290. // Activation desativation du contact
  291. if ($task->statut >= 0) print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$task->id.'&amp;action=swapstatut&amp;ligne='.$tab[$i]['rowid'].'">';
  292. print $contactstatic->LibStatut($tab[$i]['status'],3);
  293. if ($task->statut >= 0) print '</a>';
  294. print '</td>';
  295. // Icon update et delete
  296. print '<td align="center" nowrap>';
  297. if ($user->rights->projet->creer)
  298. {
  299. print '&nbsp;';
  300. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$task->id.'&amp;action=deleteline&amp;lineid='.$tab[$i]['rowid'].'">';
  301. print img_delete();
  302. print '</a>';
  303. }
  304. print '</td>';
  305. print "</tr>\n";
  306. $i ++;
  307. }
  308. }
  309. print "</table>";
  310. }
  311. else
  312. {
  313. print "ErrorRecordNotFound";
  314. }
  315. }
  316. $db->close();
  317. llxFooter();
  318. ?>