PageRenderTime 48ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/projet/tasks/contact.php

https://bitbucket.org/speedealing/speedealing
PHP | 456 lines | 308 code | 76 blank | 72 comment | 56 complexity | 4f9488b8b88ea704ed2a4b05b92811d9 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  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-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/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. $id=GETPOST('id','int');
  33. $ref=GETPOST('ref','alpha');
  34. $action=GETPOST('action','alpha');
  35. $confirm=GETPOST('confirm','alpha');
  36. $withproject=GETPOST('withproject','int');
  37. $project_ref=GETPOST('project_ref','alpha');
  38. // Security check
  39. $socid=0;
  40. if ($user->societe_id > 0) $socid = $user->societe_id;
  41. //$result = restrictedArea($user, 'projet', $id, 'projet_task');
  42. if (! $user->rights->projet->lire) accessforbidden();
  43. $object = new Task($db);
  44. $projectstatic = new Project($db);
  45. /*
  46. * Actions
  47. */
  48. // Add new contact
  49. if ($action == 'addcontact' && $user->rights->projet->creer)
  50. {
  51. $result = $object->fetch($id);
  52. if ($result > 0 && $id > 0)
  53. {
  54. $result = $object->add_contact($_POST["contactid"], $_POST["type"], $_POST["source"]);
  55. }
  56. if ($result >= 0)
  57. {
  58. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id.($withproject?'&withproject=1':''));
  59. exit;
  60. }
  61. else
  62. {
  63. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
  64. {
  65. $langs->load("errors");
  66. $mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
  67. }
  68. else
  69. {
  70. $mesg = '<div class="error">'.$object->error.'</div>';
  71. }
  72. }
  73. }
  74. // bascule du statut d'un contact
  75. if ($action == 'swapstatut' && $user->rights->projet->creer)
  76. {
  77. if ($object->fetch($id))
  78. {
  79. $result=$object->swapContactStatus(GETPOST('ligne'));
  80. }
  81. else
  82. {
  83. dol_print_error($db);
  84. }
  85. }
  86. // Efface un contact
  87. if ($action == 'deleteline' && $user->rights->projet->creer)
  88. {
  89. $object->fetch($id);
  90. $result = $object->delete_contact($_GET["lineid"]);
  91. if ($result >= 0)
  92. {
  93. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id.($withproject?'&withproject=1':''));
  94. exit;
  95. }
  96. else
  97. {
  98. dol_print_error($db);
  99. }
  100. }
  101. // Retreive First Task ID of Project if withprojet is on to allow project prev next to work
  102. if (! empty($project_ref) && ! empty($withproject))
  103. {
  104. if ($projectstatic->fetch(0,$project_ref) > 0)
  105. {
  106. $tasksarray=$object->getTasksArray(0, 0, $projectstatic->id, $socid, 0);
  107. if (count($tasksarray) > 0)
  108. {
  109. $id=$tasksarray[0]->id;
  110. }
  111. else
  112. {
  113. header("Location: ".DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.($withproject?'&withproject=1':'').(empty($mode)?'':'&mode='.$mode));
  114. exit;
  115. }
  116. }
  117. }
  118. /*
  119. * View
  120. */
  121. llxHeader('', $langs->trans("Task"));
  122. $form = new Form($db);
  123. $formcompany = new FormCompany($db);
  124. $contactstatic = new Contact($db);
  125. $userstatic = new User($db);
  126. /* *************************************************************************** */
  127. /* */
  128. /* Mode vue et edition */
  129. /* */
  130. /* *************************************************************************** */
  131. if ($id > 0 || ! empty($ref))
  132. {
  133. if ($object->fetch($id) > 0)
  134. {
  135. $result=$projectstatic->fetch($object->fk_project);
  136. if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid);
  137. $userWrite = $projectstatic->restrictedProjectArea($user,'write');
  138. if ($withproject)
  139. {
  140. // Tabs for project
  141. $tab='tasks';
  142. $head=project_prepare_head($projectstatic);
  143. dol_fiche_head($head, $tab, $langs->trans("Project"),0,($projectstatic->public?'projectpub':'project'));
  144. $param=($mode=='mine'?'&mode=mine':'');
  145. print '<table class="border" width="100%">';
  146. // Ref
  147. print '<tr><td width="30%">';
  148. print $langs->trans("Ref");
  149. print '</td><td>';
  150. // Define a complementary filter for search of next/prev ref.
  151. if (! $user->rights->projet->all->lire)
  152. {
  153. $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,0);
  154. $projectstatic->next_prev_filter=" rowid in (".(count($projectsListId)?join(',',array_keys($projectsListId)):'0').")";
  155. }
  156. print $form->showrefnav($projectstatic,'project_ref','',1,'ref','ref','',$param.'&withproject=1');
  157. print '</td></tr>';
  158. print '<tr><td>'.$langs->trans("Label").'</td><td>'.$projectstatic->title.'</td></tr>';
  159. print '<tr><td>'.$langs->trans("Company").'</td><td>';
  160. if (! empty($projectstatic->societe->id)) print $projectstatic->societe->getNomUrl(1);
  161. else print '&nbsp;';
  162. print '</td>';
  163. print '</tr>';
  164. // Visibility
  165. print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
  166. if ($projectstatic->public) print $langs->trans('SharedProject');
  167. else print $langs->trans('PrivateProject');
  168. print '</td></tr>';
  169. // Statut
  170. print '<tr><td>'.$langs->trans("Status").'</td><td>'.$projectstatic->getLibStatut(4).'</td></tr>';
  171. print '</table>';
  172. dol_fiche_end();
  173. print '<br>';
  174. }
  175. // To verify role of users
  176. //$userAccess = $projectstatic->restrictedProjectArea($user); // We allow task affected to user even if a not allowed project
  177. //$arrayofuseridoftask=$object->getListContactId('internal');
  178. dol_htmloutput_mesg($mesg);
  179. $head = task_prepare_head($object);
  180. dol_fiche_head($head, 'task_contact', $langs->trans("Task"), 0, 'projecttask');
  181. /*
  182. * Projet synthese pour rappel
  183. */
  184. print '<table class="border" width="100%">';
  185. $param=(GETPOST('withproject')?'&withproject=1':'');
  186. $linkback=GETPOST('withproject')?'<a href="'.DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.'">'.$langs->trans("BackToList").'</a>':'';
  187. // Ref
  188. print '<tr><td width="30%">'.$langs->trans('Ref').'</td><td colspan="3">';
  189. if (! GETPOST('withproject') || empty($projectstatic->id))
  190. {
  191. $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,1);
  192. $object->next_prev_filter=" fk_projet in (".$projectsListId.")";
  193. }
  194. else $object->next_prev_filter=" fk_projet = ".$projectstatic->id;
  195. print $form->showrefnav($object,'id',$linkback,1,'rowid','ref','',$param);
  196. print '</td></tr>';
  197. // Label
  198. print '<tr><td>'.$langs->trans("Label").'</td><td>'.$object->label.'</td></tr>';
  199. // Project
  200. if (empty($withproject))
  201. {
  202. print '<tr><td>'.$langs->trans("Project").'</td><td>';
  203. print $projectstatic->getNomUrl(1);
  204. print '</td></tr>';
  205. // Customer
  206. print "<tr><td>".$langs->trans("Company")."</td>";
  207. print '<td colspan="3">';
  208. if ($projectstatic->societe->id > 0) print $projectstatic->societe->getNomUrl(1);
  209. else print '&nbsp;';
  210. print '</td></tr>';
  211. }
  212. print "</table>";
  213. dol_fiche_end();
  214. /*
  215. * Lignes de contacts
  216. */
  217. print '<br><table class="noborder" width="100%">';
  218. /*
  219. * Ajouter une ligne de contact
  220. * Non affiche en mode modification de ligne
  221. */
  222. if ($action != 'editline' && $user->rights->projet->creer)
  223. {
  224. print '<tr class="liste_titre">';
  225. print '<td>'.$langs->trans("Source").'</td>';
  226. print '<td>'.$langs->trans("Company").'</td>';
  227. print '<td>'.$langs->trans("ProjectContact").'</td>';
  228. print '<td>'.$langs->trans("ContactType").'</td>';
  229. print '<td colspan="3">&nbsp;</td>';
  230. print "</tr>\n";
  231. $var = false;
  232. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="POST">';
  233. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  234. print '<input type="hidden" name="action" value="addcontact">';
  235. print '<input type="hidden" name="source" value="internal">';
  236. print '<input type="hidden" name="id" value="'.$id.'">';
  237. print '<input type="hidden" name="withproject" value="'.$withproject.'">';
  238. // Ligne ajout pour contact interne
  239. print "<tr $bc[$var]>";
  240. print '<td nowrap="nowrap">';
  241. print img_object('','user').' '.$langs->trans("Users");
  242. print '</td>';
  243. print '<td colspan="1">';
  244. print $conf->global->MAIN_INFO_SOCIETE_NOM;
  245. print '</td>';
  246. print '<td colspan="1">';
  247. // On recupere les id des users deja selectionnes
  248. $contactsofproject=$projectstatic->getListContactId('internal');
  249. $form->select_users($user->id,'contactid',0,'',0,'',$contactsofproject);
  250. print '</td>';
  251. print '<td>';
  252. $formcompany->selectTypeContact($object, '', 'type','internal','rowid');
  253. print '</td>';
  254. print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
  255. print '</tr>';
  256. print '</form>';
  257. // Line to add an external contact. Only if project linked to a third party.
  258. if ($projectstatic->socid)
  259. {
  260. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
  261. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  262. print '<input type="hidden" name="action" value="addcontact">';
  263. print '<input type="hidden" name="source" value="external">';
  264. print '<input type="hidden" name="id" value="'.$object->id.'">';
  265. $var=!$var;
  266. print "<tr $bc[$var]>";
  267. print '<td nowrap="nowrap">';
  268. print img_object('','contact').' '.$langs->trans("ThirdPartyContacts");
  269. print '</td>';
  270. print '<td colspan="1">';
  271. $thirdpartyofproject=$projectstatic->getListContactId('thirdparty');
  272. $selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$projectstatic->societe->id;
  273. $selectedCompany = $formcompany->selectCompaniesForNewContact($object, 'id', $selectedCompany, 'newcompany',$thirdpartyofproject);
  274. print '</td>';
  275. print '<td colspan="1">';
  276. $contactofproject=$projectstatic->getListContactId('external');
  277. $nbofcontacts=$form->select_contacts($selectedCompany,'','contactid',0,'',$contactofproject);
  278. if ($nbofcontacts == 0) print $langs->trans("NoContactDefined");
  279. print '</td>';
  280. print '<td>';
  281. $formcompany->selectTypeContact($object, '', 'type','external','rowid');
  282. print '</td>';
  283. print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"';
  284. if (! $nbofcontacts) print ' disabled="disabled"';
  285. print '></td>';
  286. print '</tr>';
  287. print "</form>";
  288. }
  289. }
  290. // Liste des contacts lies
  291. print '<tr class="liste_titre">';
  292. print '<td>'.$langs->trans("Source").'</td>';
  293. print '<td>'.$langs->trans("Company").'</td>';
  294. print '<td>'.$langs->trans("ProjectContact").'</td>';
  295. print '<td>'.$langs->trans("ContactType").'</td>';
  296. print '<td align="center">'.$langs->trans("Status").'</td>';
  297. print '<td colspan="2">&nbsp;</td>';
  298. print "</tr>\n";
  299. $companystatic = new Societe($db);
  300. $var = true;
  301. foreach(array('internal','external') as $source)
  302. {
  303. $tab = $object->liste_contact(-1,$source);
  304. $num=count($tab);
  305. $i = 0;
  306. while ($i < $num)
  307. {
  308. $var = !$var;
  309. print '<tr '.$bc[$var].' valign="top">';
  310. // Source
  311. print '<td align="left">';
  312. if ($tab[$i]['source']=='internal') print $langs->trans("User");
  313. if ($tab[$i]['source']=='external') print $langs->trans("ThirdPartyContact");
  314. print '</td>';
  315. // Societe
  316. print '<td align="left">';
  317. if ($tab[$i]['socid'] > 0)
  318. {
  319. $companystatic->fetch($tab[$i]['socid']);
  320. print $companystatic->getNomUrl(1);
  321. }
  322. if ($tab[$i]['socid'] < 0)
  323. {
  324. print $conf->global->MAIN_INFO_SOCIETE_NOM;
  325. }
  326. if (! $tab[$i]['socid'])
  327. {
  328. print '&nbsp;';
  329. }
  330. print '</td>';
  331. // Contact
  332. print '<td>';
  333. if ($tab[$i]['source']=='internal')
  334. {
  335. $userstatic->id=$tab[$i]['id'];
  336. $userstatic->lastname=$tab[$i]['lastname'];
  337. $userstatic->firstname=$tab[$i]['firstname'];
  338. print $userstatic->getNomUrl(1);
  339. }
  340. if ($tab[$i]['source']=='external')
  341. {
  342. $contactstatic->id=$tab[$i]['id'];
  343. $contactstatic->lastname=$tab[$i]['lastname'];
  344. $contactstatic->firstname=$tab[$i]['firstname'];
  345. print $contactstatic->getNomUrl(1);
  346. }
  347. print '</td>';
  348. // Type de contact
  349. print '<td>'.$tab[$i]['libelle'].'</td>';
  350. // Statut
  351. print '<td align="center">';
  352. // Activation desativation du contact
  353. if ($object->statut >= 0) print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=swapstatut&ligne='.$tab[$i]['rowid'].($withproject?'&withproject=1':'').'">';
  354. print $contactstatic->LibStatut($tab[$i]['status'],3);
  355. if ($object->statut >= 0) print '</a>';
  356. print '</td>';
  357. // Icon update et delete
  358. print '<td align="center" nowrap>';
  359. if ($user->rights->projet->creer)
  360. {
  361. print '&nbsp;';
  362. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=deleteline&lineid='.$tab[$i]['rowid'].($withproject?'&withproject=1':'').'">';
  363. print img_delete();
  364. print '</a>';
  365. }
  366. print '</td>';
  367. print "</tr>\n";
  368. $i ++;
  369. }
  370. }
  371. print "</table>";
  372. }
  373. else
  374. {
  375. print "ErrorRecordNotFound";
  376. }
  377. }
  378. llxFooter();
  379. $db->close();
  380. ?>