contact.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. <?php
  2. /* Copyright (C) 2010 Regis Houssin <regis.houssin@inodbox.com>
  3. * Copyright (C) 2012-2015 Laurent Destailleur <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 3 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 <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/projet/contact.php
  20. * \ingroup project
  21. * \brief List of all contacts of a project
  22. */
  23. // Load Dolibarr environment
  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. if (isModEnabled('categorie')) {
  31. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  32. }
  33. // Load translation files required by the page
  34. $langsLoad=array('projects', 'companies');
  35. if (isModEnabled('eventorganization')) {
  36. $langsLoad[]='eventorganization';
  37. }
  38. $langs->loadLangs($langsLoad);
  39. $id = GETPOST('id', 'int');
  40. $ref = GETPOST('ref', 'alpha');
  41. $lineid = GETPOST('lineid', 'int');
  42. $socid = GETPOST('socid', 'int');
  43. $action = GETPOST('action', 'aZ09');
  44. $mine = GETPOST('mode') == 'mine' ? 1 : 0;
  45. //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
  46. $object = new Project($db);
  47. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
  48. if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT) && method_exists($object, 'fetchComments') && empty($object->comments)) {
  49. $object->fetchComments();
  50. }
  51. // Security check
  52. $socid = 0;
  53. //if ($user->socid > 0) $socid = $user->socid; // For external user, no check is done on company because readability is managed by public status of project and assignement.
  54. $result = restrictedArea($user, 'projet', $id, 'projet&project');
  55. $hookmanager->initHooks(array('projectcontactcard', 'globalcard'));
  56. /*
  57. * Actions
  58. */
  59. $parameters = array('id'=>$id);
  60. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
  61. if ($reshook < 0) {
  62. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  63. }
  64. if (empty($reshook)) {
  65. // Test if we can add contact to the tasks at the same times, if not or not required, make a redirect
  66. $formconfirmtoaddtasks = '';
  67. if ($action == 'addcontact') {
  68. $form = new Form($db);
  69. $source=GETPOST("source", 'aZ09');
  70. $taskstatic = new Task($db);
  71. $task_array = $taskstatic->getTasksArray(0, 0, $object->id, 0, 0);
  72. $nbTasks = count($task_array);
  73. //If no task avaiblable, redirec to to add confirm
  74. $type_to = (GETPOST('typecontact') ? 'typecontact='.GETPOST('typecontact') : 'type='.GETPOST('type'));
  75. $personToAffect = (GETPOST('userid') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
  76. $affect_to = (GETPOST('userid') ? 'userid='.$personToAffect : 'contactid='.$personToAffect);
  77. $url_redirect='?id='.$object->id.'&'.$affect_to.'&'.$type_to.'&source='.$source;
  78. if ($personToAffect > 0 && (empty($conf->global->PROJECT_HIDE_TASKS) || $nbTasks > 0)) {
  79. $text = $langs->trans('AddPersonToTask');
  80. $textbody = $text.' (<a href="#" class="selectall">'.$langs->trans("SelectAll").'</a>)';
  81. $formquestion = array('text' => $textbody);
  82. $task_to_affect = array();
  83. foreach ($task_array as $task) {
  84. $task_already_affected=false;
  85. $personsLinked = $task->liste_contact(-1, $source);
  86. if (!is_array($personsLinked) && count($personsLinked) < 0) {
  87. setEventMessage($object->error, 'errors');
  88. } else {
  89. foreach ($personsLinked as $person) {
  90. if ($person['id']==$personToAffect) {
  91. $task_already_affected = true;
  92. break;
  93. }
  94. }
  95. if (!$task_already_affected) {
  96. $task_to_affect[$task->id] = $task->id;
  97. }
  98. }
  99. }
  100. if (empty($task_to_affect)) {
  101. $action = 'addcontact_confirm';
  102. } else {
  103. $formcompany = new FormCompany($db);
  104. foreach ($task_array as $task) {
  105. $key = $task->id;
  106. $val = $task->ref . ' '.dol_trunc($task->label);
  107. $formquestion[] = array(
  108. 'type' => 'other',
  109. 'name' => 'person_'.$key.',person_role_'.$key,
  110. 'label' => '<input type="checkbox" class="flat'.(in_array($key, $task_to_affect) ? ' taskcheckboxes"' : '" checked disabled').' id="person_'.$key.'" name="person_'.$key.'" value="1"> <label for="person_'.$key.'">'.$val.'<label>',
  111. 'value' => $formcompany->selectTypeContact($taskstatic, '', 'person_role_'.$key, $source, 'position', 0, 'minwidth100imp', 0, 1)
  112. );
  113. }
  114. $formquestion[] = array('type'=> 'other', 'name'=>'tasksavailable', 'label'=>'', 'value' => '<input type="hidden" id="tasksavailable" name="tasksavailable" value="'.implode(',', array_keys($task_to_affect)).'">');
  115. }
  116. $formconfirmtoaddtasks = $form->formconfirm($_SERVER['PHP_SELF'] . $url_redirect, $text, '', 'addcontact_confirm', $formquestion, '', 1, 300, 590);
  117. $formconfirmtoaddtasks .='
  118. <script>
  119. $(document).ready(function() {
  120. var saveprop = false;
  121. $(".selectall").click(function(){
  122. console.log("We click on select all with "+saveprop);
  123. if (!saveprop) {
  124. $(".taskcheckboxes").prop("checked", true);
  125. saveprop = true;
  126. } else {
  127. $(".taskcheckboxes").prop("checked", false);
  128. saveprop = false;
  129. }
  130. });
  131. });
  132. </script>';
  133. } else {
  134. $action = 'addcontact_confirm';
  135. }
  136. }
  137. // Add new contact
  138. if ($action == 'addcontact_confirm' && $user->rights->projet->creer) {
  139. $contactid = (GETPOST('userid') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
  140. $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
  141. if (! ($contactid > 0)) {
  142. $error++;
  143. $langs->load("errors");
  144. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Contact")), null, 'errors');
  145. }
  146. $result = 0;
  147. $result = $object->fetch($id);
  148. if (!$error && $result > 0 && $id > 0) {
  149. $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
  150. if ($result == 0) {
  151. $langs->load("errors");
  152. setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
  153. } elseif ($result < 0) {
  154. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  155. $langs->load("errors");
  156. setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
  157. } else {
  158. setEventMessages($object->error, $object->errors, 'errors');
  159. }
  160. }
  161. $affecttotask=GETPOST('tasksavailable', 'intcomma');
  162. if (!empty($affecttotask)) {
  163. require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
  164. $task_to_affect = explode(',', $affecttotask);
  165. if (!empty($task_to_affect)) {
  166. foreach ($task_to_affect as $task_id) {
  167. if (GETPOSTISSET('person_'.$task_id) && GETPOST('person_'.$task_id, 'san_alpha')) {
  168. $tasksToAffect = new Task($db);
  169. $result=$tasksToAffect->fetch($task_id);
  170. if ($result < 0) {
  171. setEventMessages($tasksToAffect->error, null, 'errors');
  172. } else {
  173. $result = $tasksToAffect->add_contact($contactid, GETPOST('person_role_'.$task_id), GETPOST("source", 'aZ09'));
  174. if ($result < 0) {
  175. if ($tasksToAffect->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  176. $langs->load("errors");
  177. setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
  178. } else {
  179. setEventMessages($tasksToAffect->error, $tasksToAffect->errors, 'errors');
  180. }
  181. }
  182. }
  183. }
  184. }
  185. }
  186. }
  187. }
  188. if ($result >= 0) {
  189. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  190. exit;
  191. }
  192. }
  193. // Change contact's status
  194. if ($action == 'swapstatut' && $user->rights->projet->creer) {
  195. if ($object->fetch($id)) {
  196. $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
  197. } else {
  198. dol_print_error($db);
  199. }
  200. }
  201. // Delete a contact
  202. if (($action == 'deleteline' || $action == 'deletecontact') && $user->rights->projet->creer) {
  203. $object->fetch($id);
  204. $result = $object->delete_contact(GETPOST("lineid", 'int'));
  205. if ($result >= 0) {
  206. header("Location: contact.php?id=".$object->id);
  207. exit;
  208. } else {
  209. dol_print_error($db);
  210. }
  211. }
  212. }
  213. /*
  214. * View
  215. */
  216. $form = new Form($db);
  217. $contactstatic = new Contact($db);
  218. $userstatic = new User($db);
  219. $title = $langs->trans('ProjectContact').' - '.$object->ref.' '.$object->name;
  220. if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/projectnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) {
  221. $title = $object->ref.' '.$object->name.' - '.$langs->trans('ProjectContact');
  222. }
  223. $help_url = 'EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos|DE:Modul_Projekte';
  224. llxHeader('', $title, $help_url);
  225. if ($id > 0 || !empty($ref)) {
  226. /*
  227. * View
  228. */
  229. if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT) && method_exists($object, 'fetchComments') && empty($object->comments)) {
  230. $object->fetchComments();
  231. }
  232. // To verify role of users
  233. //$userAccess = $object->restrictedProjectArea($user,'read');
  234. $userWrite = $object->restrictedProjectArea($user, 'write');
  235. //$userDelete = $object->restrictedProjectArea($user,'delete');
  236. //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
  237. $head = project_prepare_head($object);
  238. print dol_get_fiche_head($head, 'contact', $langs->trans("Project"), -1, ($object->public ? 'projectpub' : 'project'));
  239. $formconfirm = $formconfirmtoaddtasks;
  240. // Call Hook formConfirm
  241. $parameters = array('formConfirm' => $formconfirm);
  242. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  243. if (empty($reshook)) {
  244. $formconfirm .= $hookmanager->resPrint;
  245. } elseif ($reshook > 0) {
  246. $formconfirm = $hookmanager->resPrint;
  247. }
  248. // Print form confirm
  249. print $formconfirm;
  250. // Project card
  251. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  252. $morehtmlref = '<div class="refidno">';
  253. // Title
  254. $morehtmlref .= dol_escape_htmltag($object->title);
  255. $morehtmlref .= '<br>';
  256. // Thirdparty
  257. if (!empty($object->thirdparty->id) && $object->thirdparty->id > 0) {
  258. $morehtmlref .= $object->thirdparty->getNomUrl(1, 'project');
  259. }
  260. $morehtmlref .= '</div>';
  261. // Define a complementary filter for search of next/prev ref.
  262. if (empty($user->rights->projet->all->lire)) {
  263. $objectsListId = $object->getProjectsAuthorizedForUser($user, 0, 0);
  264. $object->next_prev_filter = " rowid IN (".$db->sanitize(count($objectsListId) ?join(',', array_keys($objectsListId)) : '0').")";
  265. }
  266. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  267. print '<div class="fichecenter">';
  268. print '<div class="fichehalfleft">';
  269. print '<div class="underbanner clearboth"></div>';
  270. print '<table class="border tableforfield centpercent">';
  271. // Usage
  272. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) || empty($conf->global->PROJECT_HIDE_TASKS) || isModEnabled('eventorganization')) {
  273. print '<tr><td class="tdtop">';
  274. print $langs->trans("Usage");
  275. print '</td>';
  276. print '<td>';
  277. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  278. print '<input type="checkbox" disabled name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_opportunity ? ' checked="checked"' : '')).'"> ';
  279. $htmltext = $langs->trans("ProjectFollowOpportunity");
  280. print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext);
  281. print '<br>';
  282. }
  283. if (empty($conf->global->PROJECT_HIDE_TASKS)) {
  284. print '<input type="checkbox" disabled name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_task ? ' checked="checked"' : '')).'"> ';
  285. $htmltext = $langs->trans("ProjectFollowTasks");
  286. print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext);
  287. print '<br>';
  288. }
  289. if (empty($conf->global->PROJECT_HIDE_TASKS) && !empty($conf->global->PROJECT_BILL_TIME_SPENT)) {
  290. print '<input type="checkbox" disabled name="usage_bill_time"'.(GETPOSTISSET('usage_bill_time') ? (GETPOST('usage_bill_time', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_bill_time ? ' checked="checked"' : '')).'"> ';
  291. $htmltext = $langs->trans("ProjectBillTimeDescription");
  292. print $form->textwithpicto($langs->trans("BillTime"), $htmltext);
  293. print '<br>';
  294. }
  295. if (isModEnabled('eventorganization')) {
  296. print '<input type="checkbox" disabled name="usage_organize_event"'.(GETPOSTISSET('usage_organize_event') ? (GETPOST('usage_organize_event', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_organize_event ? ' checked="checked"' : '')).'"> ';
  297. $htmltext = $langs->trans("EventOrganizationDescriptionLong");
  298. print $form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext);
  299. }
  300. print '</td></tr>';
  301. }
  302. // Visibility
  303. print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
  304. if ($object->public) {
  305. print img_picto($langs->trans('SharedProject'), 'world', 'class="paddingrightonly"');
  306. print $langs->trans('SharedProject');
  307. } else {
  308. print img_picto($langs->trans('PrivateProject'), 'private', 'class="paddingrightonly"');
  309. print $langs->trans('PrivateProject');
  310. }
  311. print '</td></tr>';
  312. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) && !empty($object->usage_opportunity)) {
  313. // Opportunity status
  314. print '<tr><td>'.$langs->trans("OpportunityStatus").'</td><td>';
  315. $code = dol_getIdFromCode($db, $object->opp_status, 'c_lead_status', 'rowid', 'code');
  316. if ($code) {
  317. print $langs->trans("OppStatus".$code);
  318. }
  319. // Opportunity percent
  320. print ' <span title="'.$langs->trans("OpportunityProbability").'"> / ';
  321. if (strcmp($object->opp_percent, '')) {
  322. print price($object->opp_percent, 0, $langs, 1, 0).' %';
  323. }
  324. print '</span></td></tr>';
  325. // Opportunity Amount
  326. print '<tr><td>'.$langs->trans("OpportunityAmount").'</td><td>';
  327. if (strcmp($object->opp_amount, '')) {
  328. print '<span class="amount">'.price($object->opp_amount, 0, $langs, 1, 0, -1, $conf->currency).'</span>';
  329. if (strcmp($object->opp_percent, '')) {
  330. print ' &nbsp; &nbsp; &nbsp; <span title="'.dol_escape_htmltag($langs->trans('OpportunityWeightedAmount')).'"><span class="opacitymedium">'.$langs->trans("Weighted").'</span>: <span class="amount">'.price($object->opp_amount * $object->opp_percent / 100, 0, $langs, 1, 0, -1, $conf->currency).'</span></span>';
  331. }
  332. }
  333. print '</td></tr>';
  334. }
  335. // Budget
  336. print '<tr><td>'.$langs->trans("Budget").'</td><td>';
  337. if (!is_null($object->budget_amount) && strcmp($object->budget_amount, '')) {
  338. print '<span class="amount">'.price($object->budget_amount, 0, $langs, 1, 0, 0, $conf->currency).'</span>';
  339. }
  340. print '</td></tr>';
  341. // Date start - end project
  342. print '<tr><td>'.$langs->trans("Dates").'</td><td>';
  343. $start = dol_print_date($object->date_start, 'day');
  344. print ($start ? $start : '?');
  345. $end = dol_print_date($object->date_end, 'day');
  346. print ' <span class="opacitymedium">-</span> ';
  347. print ($end ? $end : '?');
  348. if ($object->hasDelay()) {
  349. print img_warning("Late");
  350. }
  351. print '</td></tr>';
  352. // Other attributes
  353. $cols = 2;
  354. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  355. print "</table>";
  356. print '</div>';
  357. print '<div class="fichehalfright">';
  358. print '<div class="underbanner clearboth"></div>';
  359. print '<table class="border tableforfield centpercent">';
  360. // Description
  361. print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
  362. print dol_htmlentitiesbr($object->description);
  363. print '</td></tr>';
  364. // Categories
  365. if (isModEnabled('categorie')) {
  366. print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
  367. print $form->showCategories($object->id, Categorie::TYPE_PROJECT, 1);
  368. print "</td></tr>";
  369. }
  370. print '</table>';
  371. print '</div>';
  372. print '</div>';
  373. print '<div class="clearboth"></div>';
  374. print dol_get_fiche_end();
  375. print '<br>';
  376. // Contacts lines (modules that overwrite templates must declare this into descriptor)
  377. $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
  378. foreach ($dirtpls as $reldir) {
  379. $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
  380. if ($res) {
  381. break;
  382. }
  383. }
  384. }
  385. // End of page
  386. llxFooter();
  387. $db->close();