contact.php 10.0 KB

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