contact.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <?php
  2. /* Copyright (C) 2011-2016 Jean-François Ferry <hello@librethic.io>
  3. * Copyright (C) 2011 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2016 Christophe Battarel <christophe@altairis.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 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, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. /**
  21. * \file htdocs/ticket/contact.php
  22. * \ingroup ticket
  23. * \brief Contacts of tickets
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  29. require_once DOL_DOCUMENT_ROOT."/core/lib/company.lib.php";
  30. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  32. // Load translation files required by the page
  33. $langs->loadLangs(array('companies', 'ticket'));
  34. // Get parameters
  35. $socid = GETPOST("socid", 'int');
  36. $action = GETPOST("action", 'alpha');
  37. $track_id = GETPOST("track_id", 'alpha');
  38. $id = GETPOST("id", 'int');
  39. $ref = GETPOST('ref', 'alpha');
  40. $type = GETPOST('type', 'alpha');
  41. $source = GETPOST('source', 'alpha');
  42. $ligne = GETPOST('ligne', 'int');
  43. $lineid = GETPOST('lineid', 'int');
  44. // Store current page url
  45. $url_page_current = DOL_URL_ROOT.'/ticket/contact.php';
  46. $object = new Ticket($db);
  47. $permissiontoadd = $user->rights->ticket->write;
  48. // Security check
  49. $id = GETPOST("id", 'int');
  50. if ($user->socid > 0) $socid = $user->socid;
  51. $result = restrictedArea($user, 'ticket', $object->id, '');
  52. // restrict access for externals users
  53. if ($user->socid > 0 && ($object->fk_soc != $user->socid)) {
  54. accessforbidden();
  55. }
  56. // or for unauthorized internals users
  57. if (!$user->socid && (!empty($conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY) && $object->fk_user_assign != $user->id) && !$user->rights->ticket->manage) {
  58. accessforbidden();
  59. }
  60. /*
  61. * Actions
  62. */
  63. if ($action == 'addcontact' && $user->rights->ticket->write) {
  64. $result = $object->fetch($id, '', $track_id);
  65. if ($result > 0 && ($id > 0 || (!empty($track_id)))) {
  66. $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
  67. $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
  68. $error = 0;
  69. $codecontact = dol_getIdFromCode($db, $typeid, 'c_type_contact', 'rowid', 'code');
  70. if ($codecontact=='SUPPORTTEC') {
  71. $internal_contacts = $object->listeContact(-1, 'internal', 0, 'SUPPORTTEC');
  72. foreach ($internal_contacts as $key => $contact) {
  73. if ($contact['id'] !== $contactid) {
  74. //print "user à effacer : ".$useroriginassign;
  75. $result = $object->delete_contact($contact['rowid']);
  76. if ($result<0) {
  77. $error ++;
  78. setEventMessages($object->error, $object->errors, 'errors');
  79. }
  80. }
  81. }
  82. $ret = $object->assignUser($user, $contactid);
  83. if ($ret < 0) {
  84. $error ++;
  85. setEventMessages($object->error, $object->errors, 'errors');
  86. }
  87. }
  88. if (empty($error)) {
  89. $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
  90. }
  91. }
  92. if ($result >= 0) {
  93. Header("Location: ".$url_page_current."?id=".$object->id);
  94. exit;
  95. } else {
  96. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  97. $langs->load("errors");
  98. setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
  99. } else {
  100. setEventMessages($object->error, $object->errors, 'errors');
  101. }
  102. }
  103. }
  104. // bascule du statut d'un contact
  105. if ($action == 'swapstatut' && $user->rights->ticket->write) {
  106. if ($object->fetch($id, '', $track_id)) {
  107. $result = $object->swapContactStatus($ligne);
  108. } else {
  109. dol_print_error($db, $object->error);
  110. }
  111. }
  112. // Efface un contact
  113. if ($action == 'deletecontact' && $user->rights->ticket->write) {
  114. if ($object->fetch($id, '', $track_id)) {
  115. $internal_contacts = $object->listeContact(-1, 'internal', 0, 'SUPPORTTEC');
  116. foreach ($internal_contacts as $key => $contact) {
  117. if ($contact['rowid'] == $lineid && $object->fk_user_assign==$contact['id']) {
  118. $ret = $object->assignUser($user, null);
  119. if ($ret < 0) {
  120. $error ++;
  121. setEventMessages($object->error, $object->errors, 'errors');
  122. }
  123. }
  124. }
  125. $result = $object->delete_contact($lineid);
  126. if ($result >= 0) {
  127. Header("Location: ".$url_page_current."?id=".$object->id);
  128. exit;
  129. }
  130. }
  131. }
  132. /*
  133. * View
  134. */
  135. $help_url = 'FR:DocumentationModuleTicket';
  136. llxHeader('', $langs->trans("TicketContacts"), $help_url);
  137. $form = new Form($db);
  138. $formcompany = new FormCompany($db);
  139. $contactstatic = new Contact($db);
  140. $userstatic = new User($db);
  141. if ($id > 0 || !empty($track_id) || !empty($ref)) {
  142. if ($object->fetch($id, $ref, $track_id) > 0) {
  143. if ($socid > 0) {
  144. $object->fetch_thirdparty();
  145. $head = societe_prepare_head($object->thirdparty);
  146. print dol_get_fiche_head($head, 'ticket', $langs->trans("ThirdParty"), 0, 'company');
  147. dol_banner_tab($object->thirdparty, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
  148. print dol_get_fiche_end();
  149. }
  150. if (!$user->socid && !empty($conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY)) {
  151. $object->next_prev_filter = "te.fk_user_assign = '".$user->id."'";
  152. } elseif ($user->socid > 0) {
  153. $object->next_prev_filter = "te.fk_soc = '".$user->socid."'";
  154. }
  155. $head = ticket_prepare_head($object);
  156. print dol_get_fiche_head($head, 'contact', $langs->trans("Ticket"), -1, 'ticket');
  157. $morehtmlref = '<div class="refidno">';
  158. $morehtmlref .= $object->subject;
  159. // Author
  160. if ($object->fk_user_create > 0) {
  161. $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
  162. $fuser = new User($db);
  163. $fuser->fetch($object->fk_user_create);
  164. $morehtmlref .= $fuser->getNomUrl(-1);
  165. } elseif (!empty($object->email_msgid)) {
  166. $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
  167. $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
  168. $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">('.$form->textwithpicto($langs->trans("CreatedByEmailCollector"), $langs->trans("EmailMsgID").': '.$object->email_msgid).')</small>';
  169. } elseif (!empty($object->origin_email)) {
  170. $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
  171. $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
  172. $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">('.$langs->trans("CreatedByPublicPortal").')</small>';
  173. }
  174. // Thirdparty
  175. if (isModEnabled('societe')) {
  176. $morehtmlref .= '<br>'.$langs->trans('ThirdParty');
  177. /*if ($action != 'editcustomer' && $object->fk_statut < 8 && !$user->socid && $user->rights->ticket->write) {
  178. $morehtmlref.='<a class="editfielda" href="' . $url_page_current . '?action=editcustomer&token='.newToken().'&track_id=' . $object->track_id . '">' . img_edit($langs->transnoentitiesnoconv('Edit'), 1) . '</a>';
  179. }*/
  180. $morehtmlref .= ' : ';
  181. if ($action == 'editcustomer') {
  182. $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, $object->socid, 'editcustomer', '', 1, 0, 0, array(), 1);
  183. } else {
  184. $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, $object->socid, 'none', '', 1, 0, 0, array(), 1);
  185. }
  186. }
  187. // Project
  188. if (isModEnabled('project')) {
  189. $langs->load("projects");
  190. $morehtmlref .= '<br>'.$langs->trans('Project').' ';
  191. if ($user->rights->ticket->write) {
  192. if ($action != 'classify') {
  193. //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a>';
  194. $morehtmlref .= ' : ';
  195. }
  196. if ($action == 'classify') {
  197. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  198. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  199. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  200. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  201. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', 0, 0, 1, 0, 1, 0, 0, '', 1);
  202. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  203. $morehtmlref .= '</form>';
  204. } else {
  205. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  206. }
  207. } else {
  208. if (!empty($object->fk_project)) {
  209. $proj = new Project($db);
  210. $proj->fetch($object->fk_project);
  211. $morehtmlref .= $proj->getNomUrl(1);
  212. } else {
  213. $morehtmlref .= '';
  214. }
  215. }
  216. }
  217. $morehtmlref .= '</div>';
  218. $linkback = '<a href="'.dol_buildpath('/ticket/list.php', 1).'"><strong>'.$langs->trans("BackToList").'</strong></a> ';
  219. dol_banner_tab($object, 'ref', $linkback, ($user->socid ? 0 : 1), 'ref', 'ref', $morehtmlref, $param, 0, '', '', 1, '');
  220. print dol_get_fiche_end();
  221. //print '<br>';
  222. $permission = $user->rights->ticket->write;
  223. // Contacts lines (modules that overwrite templates must declare this into descriptor)
  224. $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
  225. foreach ($dirtpls as $reldir) {
  226. $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
  227. if ($res) {
  228. break;
  229. }
  230. }
  231. } else {
  232. print "ErrorRecordNotFound";
  233. }
  234. }
  235. // End of page
  236. llxFooter();
  237. $db->close();