contact.php 10.0 KB

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