ticket.lib.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  1. <?php
  2. /* Copyright (C) 2013-2018 Jean-François FERRY <hello@librethic.io>
  3. * Copyright (C) 2016 Christophe Battarel <christophe@altairis.fr>
  4. * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.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, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file core/lib/ticket.lib.php
  21. * \ingroup ticket
  22. * \brief This file is a library for Ticket module
  23. */
  24. /**
  25. * Build tabs for admin page
  26. *
  27. * @return array
  28. */
  29. function ticketAdminPrepareHead()
  30. {
  31. global $langs, $conf;
  32. $langs->load("ticket");
  33. $h = 0;
  34. $head = array();
  35. $head[$h][0] = DOL_URL_ROOT.'/admin/ticket.php';
  36. $head[$h][1] = $langs->trans("TicketSettings");
  37. $head[$h][2] = 'settings';
  38. $h++;
  39. $head[$h][0] = DOL_URL_ROOT.'/admin/ticket_extrafields.php';
  40. $head[$h][1] = $langs->trans("ExtraFieldsTicket");
  41. $head[$h][2] = 'attributes';
  42. $h++;
  43. $head[$h][0] = DOL_URL_ROOT.'/admin/ticket_public.php';
  44. $head[$h][1] = $langs->trans("PublicInterface");
  45. $head[$h][2] = 'public';
  46. $h++;
  47. // Show more tabs from modules
  48. // Entries must be declared in modules descriptor with line
  49. //$this->tabs = array(
  50. // 'entity:+tabname:Title:@ticket:/ticket/mypage.php?id=__ID__'
  51. //); // to add new tab
  52. //$this->tabs = array(
  53. // 'entity:-tabname:Title:@ticket:/ticket/mypage.php?id=__ID__'
  54. //); // to remove a tab
  55. complete_head_from_modules($conf, $langs, null, $head, $h, 'ticketadmin');
  56. complete_head_from_modules($conf, $langs, null, $head, $h, 'ticketadmin', 'remove');
  57. return $head;
  58. }
  59. /**
  60. * Build tabs for a Ticket object
  61. *
  62. * @param Ticket $object Object Ticket
  63. * @return array Array of tabs
  64. */
  65. function ticket_prepare_head($object)
  66. {
  67. global $db, $langs, $conf, $user;
  68. $h = 0;
  69. $head = array();
  70. $head[$h][0] = DOL_URL_ROOT.'/ticket/card.php?action=view&track_id='.$object->track_id;
  71. $head[$h][1] = $langs->trans("Ticket");
  72. $head[$h][2] = 'tabTicket';
  73. $h++;
  74. if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && empty($user->socid))
  75. {
  76. $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
  77. $head[$h][0] = DOL_URL_ROOT.'/ticket/contact.php?track_id='.$object->track_id;
  78. $head[$h][1] = $langs->trans('ContactsAddresses');
  79. if ($nbContact > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
  80. $head[$h][2] = 'contact';
  81. $h++;
  82. }
  83. complete_head_from_modules($conf, $langs, $object, $head, $h, 'ticket');
  84. // Attached files
  85. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  86. $upload_dir = $conf->ticket->dir_output."/".$object->ref;
  87. $nbFiles = count(dol_dir_list($upload_dir, 'files'));
  88. $head[$h][0] = dol_buildpath('/ticket/document.php', 1).'?id='.$object->id;
  89. $head[$h][1] = $langs->trans("Documents");
  90. if ($nbFiles > 0) {
  91. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbFiles.'</span>';
  92. }
  93. $head[$h][2] = 'tabTicketDocument';
  94. $h++;
  95. // History
  96. $ticketViewType = "messaging";
  97. if (empty($_SESSION['ticket-view-type'])) {
  98. $_SESSION['ticket-view-type'] = $ticketViewType;
  99. } else {
  100. $ticketViewType = $_SESSION['ticket-view-type'];
  101. }
  102. if ($ticketViewType == "messaging") {
  103. $head[$h][0] = DOL_URL_ROOT.'/ticket/messaging.php?track_id='.$object->track_id;
  104. } else {
  105. // $ticketViewType == "list"
  106. $head[$h][0] = DOL_URL_ROOT.'/ticket/agenda.php?track_id='.$object->track_id;
  107. }
  108. $head[$h][1] = $langs->trans('Events');
  109. if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read)))
  110. {
  111. $head[$h][1] .= '/';
  112. $head[$h][1] .= $langs->trans("Agenda");
  113. }
  114. $head[$h][2] = 'tabTicketLogs';
  115. $h++;
  116. complete_head_from_modules($conf, $langs, $object, $head, $h, 'ticket', 'remove');
  117. return $head;
  118. }
  119. /**
  120. * Return string with full Url. The file qualified is the one defined by relative path in $object->last_main_doc
  121. *
  122. * @param Object $object Object
  123. * @return string Url string
  124. */
  125. function showDirectPublicLink($object)
  126. {
  127. global $conf, $langs;
  128. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  129. $email = CMailFile::getValidAddress($object->origin_email, 2);
  130. $url = '';
  131. if ($email)
  132. {
  133. $url = dol_buildpath('/public/ticket/view.php', 3).'?track_id='.$object->track_id.'&email='.$email;
  134. }
  135. $out = '';
  136. if (empty($conf->global->TICKET_ENABLE_PUBLIC_INTERFACE))
  137. {
  138. $out .= '<span class="opacitymedium">'.$langs->trans("PublicInterfaceNotEnabled").'</span>';
  139. } else {
  140. $out .= img_picto('', 'object_globe.png').' '.$langs->trans("TicketPublicAccess").':<br>';
  141. if ($url)
  142. {
  143. $out .= '<input type="text" id="directpubliclink" class="quatrevingtpercent" value="'.$url.'">';
  144. $out .= ajax_autoselect("directpubliclink", 0);
  145. } else {
  146. $out .= '<span class="opacitymedium">'.$langs->trans("TicketNotCreatedFromPublicInterface").'</span>';
  147. }
  148. }
  149. return $out;
  150. }
  151. /**
  152. * Generate a random id
  153. *
  154. * @param int $car Length of string to generate key
  155. * @return string
  156. */
  157. function generate_random_id($car = 16)
  158. {
  159. $string = "";
  160. $chaine = "abcdefghijklmnopqrstuvwxyz123456789";
  161. srand((double) microtime() * 1000000);
  162. for ($i = 0; $i < $car; $i++) {
  163. $string .= $chaine[rand() % strlen($chaine)];
  164. }
  165. return $string;
  166. }
  167. /**
  168. * Show header for public pages
  169. *
  170. * @param string $title Title
  171. * @param string $head Head array
  172. * @param int $disablejs More content into html header
  173. * @param int $disablehead More content into html header
  174. * @param array $arrayofjs Array of complementary js files
  175. * @param array $arrayofcss Array of complementary css files
  176. * @return void
  177. */
  178. function llxHeaderTicket($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '')
  179. {
  180. global $user, $conf, $langs, $mysoc;
  181. top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); // Show html headers
  182. print '<body id="mainbody" class="publicnewticketform">';
  183. print '<div class="center">';
  184. // Define urllogo
  185. if (!empty($conf->global->TICKET_SHOW_COMPANY_LOGO) || !empty($conf->global->TICKET_PUBLIC_INTERFACE_TOPIC)) {
  186. // Print logo
  187. if (!empty($conf->global->TICKET_SHOW_COMPANY_LOGO))
  188. {
  189. $urllogo = DOL_URL_ROOT.'/theme/common/login_logo.png';
  190. if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small)) {
  191. $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$mysoc->logo_small);
  192. } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$mysoc->logo)) {
  193. $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$mysoc->logo);
  194. } elseif (is_readable(DOL_DOCUMENT_ROOT.'/theme/dolibarr_logo.svg')) {
  195. $urllogo = DOL_URL_ROOT.'/theme/dolibarr_logo.svg';
  196. }
  197. }
  198. }
  199. // Output html code for logo
  200. if ($urllogo || !empty($conf->global->TICKET_PUBLIC_INTERFACE_TOPIC))
  201. {
  202. print '<div class="backgreypublicpayment">';
  203. print '<div class="logopublicpayment">';
  204. if ($urllogo) {
  205. print '<a href="'.($conf->global->TICKET_URL_PUBLIC_INTERFACE ? $conf->global->TICKET_URL_PUBLIC_INTERFACE : dol_buildpath('/public/ticket/index.php', 1)).'">';
  206. print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
  207. print '>';
  208. print '</a>';
  209. }
  210. if (!empty($conf->global->TICKET_PUBLIC_INTERFACE_TOPIC)) {
  211. print '<div class="clearboth"></div><strong>'.($conf->global->TICKET_PUBLIC_INTERFACE_TOPIC ? $conf->global->TICKET_PUBLIC_INTERFACE_TOPIC : $langs->trans("TicketSystem")).'</strong>';
  212. }
  213. print '</div>';
  214. if (empty($conf->global->MAIN_HIDE_POWERED_BY)) {
  215. print '<div class="poweredbypublicpayment opacitymedium right"><a href="https://www.dolibarr.org" target="dolibarr">'.$langs->trans("PoweredBy").'<br><img src="'.DOL_URL_ROOT.'/theme/dolibarr_logo.svg" width="80px"></a></div>';
  216. }
  217. print '</div>';
  218. }
  219. print '</div>';
  220. print '<div class="ticketlargemargin">';
  221. }
  222. /**
  223. * Show html area with actions for ticket messaging.
  224. * Note: Global parameter $param must be defined.
  225. *
  226. * @param Conf $conf Object conf
  227. * @param Translate $langs Object langs
  228. * @param DoliDB $db Object db
  229. * @param mixed $filterobj Filter on object Adherent|Societe|Project|Product|CommandeFournisseur|Dolresource|Ticket|... to list events linked to an object
  230. * @param Contact $objcon Filter on object contact to filter events on a contact
  231. * @param int $noprint Return string but does not output it
  232. * @param string $actioncode Filter on actioncode
  233. * @param string $donetodo Filter on event 'done' or 'todo' or ''=nofilter (all).
  234. * @param array $filters Filter on other fields
  235. * @param string $sortfield Sort field
  236. * @param string $sortorder Sort order
  237. * @return string|void Return html part or void if noprint is 1
  238. */
  239. function show_ticket_messaging($conf, $langs, $db, $filterobj, $objcon = '', $noprint = 0, $actioncode = '', $donetodo = 'done', $filters = array(), $sortfield = 'a.datep,a.id', $sortorder = 'DESC')
  240. {
  241. global $user, $conf;
  242. global $form;
  243. global $param, $massactionbutton;
  244. dol_include_once('/comm/action/class/actioncomm.class.php');
  245. // Check parameters
  246. if (!is_object($filterobj) && !is_object($objcon)) dol_print_error('', 'BadParameter');
  247. $out = '';
  248. $histo = array();
  249. $numaction = 0;
  250. $now = dol_now('tzuser');
  251. // Open DSI -- Fix order by -- Begin
  252. $sortfield_list = explode(',', $sortfield);
  253. $sortfield_label_list = array('a.id' => 'id', 'a.datep' => 'dp', 'a.percent' => 'percent');
  254. $sortfield_new_list = array();
  255. foreach ($sortfield_list as $sortfield_value) {
  256. $sortfield_new_list[] = $sortfield_label_list[trim($sortfield_value)];
  257. }
  258. $sortfield_new = implode(',', $sortfield_new_list);
  259. if (!empty($conf->agenda->enabled))
  260. {
  261. // Recherche histo sur actioncomm
  262. if (is_object($objcon) && $objcon->id > 0) {
  263. $sql = "SELECT DISTINCT a.id, a.label as label,";
  264. } else {
  265. $sql = "SELECT a.id, a.label as label,";
  266. }
  267. $sql .= " a.datep as dp,";
  268. $sql .= " a.note as message,";
  269. $sql .= " a.datep2 as dp2,";
  270. $sql .= " a.percent as percent, 'action' as type,";
  271. $sql .= " a.fk_element, a.elementtype,";
  272. $sql .= " a.fk_contact,";
  273. $sql .= " c.code as acode, c.libelle as alabel, c.picto as apicto,";
  274. $sql .= " u.rowid as user_id, u.login as user_login, u.photo as user_photo, u.firstname as user_firstname, u.lastname as user_lastname";
  275. if (is_object($filterobj) && get_class($filterobj) == 'Societe') $sql .= ", sp.lastname, sp.firstname";
  276. elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') $sql .= ", m.lastname, m.firstname";
  277. elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') $sql .= ", o.ref";
  278. elseif (is_object($filterobj) && get_class($filterobj) == 'Product') $sql .= ", o.ref";
  279. elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') $sql .= ", o.ref";
  280. elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') $sql .= ", o.ref";
  281. elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') $sql .= ", o.ref";
  282. $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
  283. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = a.fk_user_action";
  284. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_actioncomm as c ON a.fk_action = c.id";
  285. $force_filter_contact = false;
  286. if (is_object($objcon) && $objcon->id > 0) {
  287. $force_filter_contact = true;
  288. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."actioncomm_resources as r ON a.id = r.fk_actioncomm";
  289. $sql .= " AND r.element_type = '".$db->escape($objcon->table_element)."' AND r.fk_element = ".$objcon->id;
  290. }
  291. if (is_object($filterobj) && get_class($filterobj) == 'Societe') $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON a.fk_contact = sp.rowid";
  292. elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
  293. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."element_resources as er";
  294. $sql .= " ON er.resource_type = 'dolresource'";
  295. $sql .= " AND er.element_id = a.id";
  296. $sql .= " AND er.resource_id = ".$filterobj->id;
  297. } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') $sql .= ", ".MAIN_DB_PREFIX."adherent as m";
  298. elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as o";
  299. elseif (is_object($filterobj) && get_class($filterobj) == 'Product') $sql .= ", ".MAIN_DB_PREFIX."product as o";
  300. elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') $sql .= ", ".MAIN_DB_PREFIX."ticket as o";
  301. elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') $sql .= ", ".MAIN_DB_PREFIX."bom_bom as o";
  302. elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') $sql .= ", ".MAIN_DB_PREFIX."contrat as o";
  303. $sql .= " WHERE a.entity IN (".getEntity('agenda').")";
  304. if ($force_filter_contact === false) {
  305. if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur')) && $filterobj->id) $sql .= " AND a.fk_soc = ".$filterobj->id;
  306. elseif (is_object($filterobj) && get_class($filterobj) == 'Project' && $filterobj->id) $sql .= " AND a.fk_project = ".$filterobj->id;
  307. elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent')
  308. {
  309. $sql .= " AND a.fk_element = m.rowid AND a.elementtype = 'member'";
  310. if ($filterobj->id) $sql .= " AND a.fk_element = ".$filterobj->id;
  311. } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur')
  312. {
  313. $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'order_supplier'";
  314. if ($filterobj->id) $sql .= " AND a.fk_element = ".$filterobj->id;
  315. } elseif (is_object($filterobj) && get_class($filterobj) == 'Product')
  316. {
  317. $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'product'";
  318. if ($filterobj->id) $sql .= " AND a.fk_element = ".$filterobj->id;
  319. } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket')
  320. {
  321. $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'ticket'";
  322. if ($filterobj->id) $sql .= " AND a.fk_element = ".$filterobj->id;
  323. } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM')
  324. {
  325. $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'bom'";
  326. if ($filterobj->id) $sql .= " AND a.fk_element = ".$filterobj->id;
  327. } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat')
  328. {
  329. $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'contract'";
  330. if ($filterobj->id) $sql .= " AND a.fk_element = ".$filterobj->id;
  331. }
  332. }
  333. // Condition on actioncode
  334. if (!empty($actioncode))
  335. {
  336. if (empty($conf->global->AGENDA_USE_EVENT_TYPE))
  337. {
  338. if ($actioncode == 'AC_NON_AUTO') $sql .= " AND c.type != 'systemauto'";
  339. elseif ($actioncode == 'AC_ALL_AUTO') $sql .= " AND c.type = 'systemauto'";
  340. else {
  341. if ($actioncode == 'AC_OTH') $sql .= " AND c.type != 'systemauto'";
  342. elseif ($actioncode == 'AC_OTH_AUTO') $sql .= " AND c.type = 'systemauto'";
  343. }
  344. } else {
  345. if ($actioncode == 'AC_NON_AUTO') $sql .= " AND c.type != 'systemauto'";
  346. elseif ($actioncode == 'AC_ALL_AUTO') $sql .= " AND c.type = 'systemauto'";
  347. else $sql .= " AND c.code = '".$db->escape($actioncode)."'";
  348. }
  349. }
  350. if ($donetodo == 'todo') $sql .= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
  351. elseif ($donetodo == 'done') $sql .= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
  352. if (is_array($filters) && $filters['search_agenda_label']) $sql .= natural_search('a.label', $filters['search_agenda_label']);
  353. }
  354. // Add also event from emailings. TODO This should be replaced by an automatic event ? May be it's too much for very large emailing.
  355. if (!empty($conf->mailing->enabled) && !empty($objcon->email)
  356. && (empty($actioncode) || $actioncode == 'AC_OTH_AUTO' || $actioncode == 'AC_EMAILING'))
  357. {
  358. $langs->load("mails");
  359. $sql2 = "SELECT m.rowid as id, m.titre as label, mc.date_envoi as dp, mc.date_envoi as dp2, '100' as percent, 'mailing' as type";
  360. $sql2 .= ", null as fk_element, '' as elementtype, null as contact_id";
  361. $sql2 .= ", 'AC_EMAILING' as acode, '' as alabel, '' as apicto";
  362. $sql2 .= ", u.rowid as user_id, u.login as user_login, u.photo as user_photo, u.firstname as user_firstname, u.lastname as user_lastname"; // User that valid action
  363. if (is_object($filterobj) && get_class($filterobj) == 'Societe') $sql2 .= ", '' as lastname, '' as firstname";
  364. elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') $sql2 .= ", '' as lastname, '' as firstname";
  365. elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') $sql2 .= ", '' as ref";
  366. elseif (is_object($filterobj) && get_class($filterobj) == 'Product') $sql2 .= ", '' as ref";
  367. elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') $sql2 .= ", '' as ref";
  368. $sql2 .= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."user as u";
  369. $sql2 .= " WHERE mc.email = '".$db->escape($objcon->email)."'"; // Search is done on email.
  370. $sql2 .= " AND mc.statut = 1";
  371. $sql2 .= " AND u.rowid = m.fk_user_valid";
  372. $sql2 .= " AND mc.fk_mailing=m.rowid";
  373. }
  374. if (!empty($sql) && !empty($sql2)) {
  375. $sql = $sql." UNION ".$sql2;
  376. } elseif (empty($sql) && !empty($sql2)) {
  377. $sql = $sql2;
  378. }
  379. //TODO Add limit in nb of results
  380. $sql .= $db->order($sortfield_new, $sortorder);
  381. dol_syslog("company.lib::show_actions_done", LOG_DEBUG);
  382. $resql = $db->query($sql);
  383. if ($resql)
  384. {
  385. $i = 0;
  386. $num = $db->num_rows($resql);
  387. while ($i < $num)
  388. {
  389. $obj = $db->fetch_object($resql);
  390. if ($obj->type == 'action') {
  391. $contactaction = new ActionComm($db);
  392. $contactaction->id = $obj->id;
  393. $result = $contactaction->fetchResources();
  394. if ($result < 0) {
  395. dol_print_error($db);
  396. setEventMessage("company.lib::show_actions_done Error fetch ressource", 'errors');
  397. }
  398. //if ($donetodo == 'todo') $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
  399. //elseif ($donetodo == 'done') $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
  400. $tododone = '';
  401. if (($obj->percent >= 0 and $obj->percent < 100) || ($obj->percent == -1 && $obj->datep > $now)) $tododone = 'todo';
  402. $histo[$numaction] = array(
  403. 'type'=>$obj->type,
  404. 'tododone'=>$tododone,
  405. 'id'=>$obj->id,
  406. 'datestart'=>$db->jdate($obj->dp),
  407. 'dateend'=>$db->jdate($obj->dp2),
  408. 'note'=>$obj->label,
  409. 'message'=>$obj->message,
  410. 'percent'=>$obj->percent,
  411. 'userid'=>$obj->user_id,
  412. 'login'=>$obj->user_login,
  413. 'userfirstname'=>$obj->user_firstname,
  414. 'userlastname'=>$obj->user_lastname,
  415. 'userphoto'=>$obj->user_photo,
  416. 'contact_id'=>$obj->fk_contact,
  417. 'socpeopleassigned' => $contactaction->socpeopleassigned,
  418. 'lastname'=>$obj->lastname,
  419. 'firstname'=>$obj->firstname,
  420. 'fk_element'=>$obj->fk_element,
  421. 'elementtype'=>$obj->elementtype,
  422. // Type of event
  423. 'acode'=>$obj->acode,
  424. 'alabel'=>$obj->alabel,
  425. 'libelle'=>$obj->alabel, // deprecated
  426. 'apicto'=>$obj->apicto
  427. );
  428. } else {
  429. $histo[$numaction] = array(
  430. 'type'=>$obj->type,
  431. 'tododone'=>'done',
  432. 'id'=>$obj->id,
  433. 'datestart'=>$db->jdate($obj->dp),
  434. 'dateend'=>$db->jdate($obj->dp2),
  435. 'note'=>$obj->label,
  436. 'message'=>$obj->message,
  437. 'percent'=>$obj->percent,
  438. 'acode'=>$obj->acode,
  439. 'userid'=>$obj->user_id,
  440. 'login'=>$obj->user_login,
  441. 'userfirstname'=>$obj->user_firstname,
  442. 'userlastname'=>$obj->user_lastname,
  443. 'userphoto'=>$obj->user_photo
  444. );
  445. }
  446. $numaction++;
  447. $i++;
  448. }
  449. } else {
  450. dol_print_error($db);
  451. }
  452. if (!empty($conf->agenda->enabled) || (!empty($conf->mailing->enabled) && !empty($objcon->email)))
  453. {
  454. $delay_warning = $conf->global->MAIN_DELAY_ACTIONS_TODO * 24 * 60 * 60;
  455. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  456. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  457. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  458. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  459. $formactions = new FormActions($db);
  460. $actionstatic = new ActionComm($db);
  461. $userstatic = new User($db);
  462. $contactstatic = new Contact($db);
  463. $userGetNomUrlCache = array();
  464. $out .= '<div class="filters-container" >';
  465. $out .= '<form name="listactionsfilter" class="listactionsfilter" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  466. $out .= '<input type="hidden" name="token" value="'.newToken().'">';
  467. if ($objcon && get_class($objcon) == 'Contact' &&
  468. (is_null($filterobj) || get_class($filterobj) == 'Societe'))
  469. {
  470. $out .= '<input type="hidden" name="id" value="'.$objcon->id.'" />';
  471. } else {
  472. $out .= '<input type="hidden" name="id" value="'.$filterobj->id.'" />';
  473. }
  474. if ($filterobj && get_class($filterobj) == 'Societe') $out .= '<input type="hidden" name="socid" value="'.$filterobj->id.'" />';
  475. $out .= "\n";
  476. $out .= '<div class="div-table-responsive-no-min">';
  477. $out .= '<table class="noborder borderbottom centpercent">';
  478. $out .= '<tr class="liste_titre">';
  479. //$out.='<td class="liste_titre">';
  480. $out .= getTitleFieldOfList('Date', 0, $_SERVER["PHP_SELF"], 'a.datep', '', $param, '', $sortfield, $sortorder, '')."\n";
  481. //$out.='</td>';
  482. $out .= '<th class="liste_titre"><strong>'.$langs->trans("Search").' : </strong></th>';
  483. if ($donetodo)
  484. {
  485. $out .= '<th class="liste_titre"></th>';
  486. }
  487. $out .= '<th class="liste_titre">'.$langs->trans("Type").' ';
  488. $out .= $formactions->select_type_actions($actioncode, "actioncode", '', empty($conf->global->AGENDA_USE_EVENT_TYPE) ? 1 : -1, 0, 0, 1);
  489. $out .= '</th>';
  490. $out .= '<th class="liste_titre maxwidth100onsmartphone">';
  491. $out .= $langs->trans("Label").' ';
  492. $out .= '<input type="text" class="maxwidth100onsmartphone" name="search_agenda_label" value="'.$filters['search_agenda_label'].'">';
  493. $out .= '</th>';
  494. $out .= '<th class="liste_titre width50 middle">';
  495. $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
  496. $out .= $searchpicto;
  497. $out .= '</th>';
  498. $out .= '</tr>';
  499. $out .= '</table>';
  500. $out .= '</form>';
  501. $out .= '</div>';
  502. $out .= "\n";
  503. $out .= '<ul class="timeline">';
  504. if ($donetodo)
  505. {
  506. $tmp = '';
  507. if (get_class($filterobj) == 'Societe') $tmp .= '<a href="'.DOL_URL_ROOT.'/comm/action/list.php?action=show_list&socid='.$filterobj->id.'&status=done">';
  508. $tmp .= ($donetodo != 'done' ? $langs->trans("ActionsToDoShort") : '');
  509. $tmp .= ($donetodo != 'done' && $donetodo != 'todo' ? ' / ' : '');
  510. $tmp .= ($donetodo != 'todo' ? $langs->trans("ActionsDoneShort") : '');
  511. //$out.=$langs->trans("ActionsToDoShort").' / '.$langs->trans("ActionsDoneShort");
  512. if (get_class($filterobj) == 'Societe') $tmp .= '</a>';
  513. $out .= getTitleFieldOfList($tmp);
  514. }
  515. //require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
  516. //$caction=new CActionComm($db);
  517. //$arraylist=$caction->liste_array(1, 'code', '', (empty($conf->global->AGENDA_USE_EVENT_TYPE)?1:0), '', 1);
  518. $actualCycleDate = false;
  519. foreach ($histo as $key=>$value)
  520. {
  521. $actionstatic->fetch($histo[$key]['id']); // TODO Do we need this, we already have a lot of data of line into $histo
  522. $actionstatic->type_picto = $histo[$key]['apicto'];
  523. $actionstatic->type_code = $histo[$key]['acode'];
  524. $url = DOL_URL_ROOT.'/comm/action/card.php?id='.$histo[$key]['id'];
  525. $tmpa = dol_getdate($histo[$key]['datestart'], false);
  526. if ($actualCycleDate !== $tmpa['year'].'-'.$tmpa['yday']) {
  527. $actualCycleDate = $tmpa['year'].'-'.$tmpa['yday'];
  528. $out .= '<!-- timeline time label -->';
  529. $out .= '<li class="time-label">';
  530. $out .= '<span class="timeline-badge-date">';
  531. $out .= dol_print_date($histo[$key]['datestart'], 'daytext', 'tzserver', $langs);
  532. $out .= '</span>';
  533. $out .= '</li>';
  534. $out .= '<!-- /.timeline-label -->';
  535. }
  536. $out .= '<!-- timeline item -->'."\n";
  537. $out .= '<li class="timeline-code-'.strtolower($actionstatic->code).'">';
  538. $out .= '<!-- timeline icon -->'."\n";
  539. $iconClass = 'fa fa-comments';
  540. $img_picto = '';
  541. $colorClass = '';
  542. $pictoTitle = '';
  543. if ($histo[$key]['percent'] == -1) {
  544. $colorClass = 'timeline-icon-not-applicble';
  545. $pictoTitle = $langs->trans('StatusNotApplicable');
  546. } elseif ($histo[$key]['percent'] == 0) {
  547. $colorClass = 'timeline-icon-todo';
  548. $pictoTitle = $langs->trans('StatusActionToDo').' (0%)';
  549. } elseif ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100) {
  550. $colorClass = 'timeline-icon-in-progress';
  551. $pictoTitle = $langs->trans('StatusActionInProcess').' ('.$histo[$key]['percent'].'%)';
  552. } elseif ($histo[$key]['percent'] >= 100) {
  553. $colorClass = 'timeline-icon-done';
  554. $pictoTitle = $langs->trans('StatusActionDone').' (100%)';
  555. }
  556. if ($actionstatic->code == 'AC_TICKET_CREATE') {
  557. $iconClass = 'fa fa-ticket';
  558. } elseif ($actionstatic->code == 'AC_TICKET_MODIFY') {
  559. $iconClass = 'fa fa-pencil';
  560. } elseif ($actionstatic->code == 'TICKET_MSG') {
  561. $iconClass = 'fa fa-comments';
  562. } elseif ($actionstatic->code == 'TICKET_MSG_PRIVATE') {
  563. $iconClass = 'fa fa-mask';
  564. } elseif (!empty($conf->global->AGENDA_USE_EVENT_TYPE))
  565. {
  566. if ($actionstatic->type_picto) $img_picto = img_picto('', $actionstatic->type_picto);
  567. else {
  568. if ($actionstatic->type_code == 'AC_RDV') $iconClass = 'fa fa-handshake';
  569. elseif ($actionstatic->type_code == 'AC_TEL') $iconClass = 'fa fa-phone';
  570. elseif ($actionstatic->type_code == 'AC_FAX') $iconClass = 'fa fa-fax';
  571. elseif ($actionstatic->type_code == 'AC_EMAIL') $iconClass = 'fa fa-envelope';
  572. elseif ($actionstatic->type_code == 'AC_INT') $iconClass = 'fa fa-shipping-fast';
  573. elseif ($actionstatic->type_code == 'AC_OTH_AUTO') $iconClass = 'fa fa-robot';
  574. elseif (!preg_match('/_AUTO/', $actionstatic->type_code)) $iconClass = 'fa fa-robot';
  575. }
  576. }
  577. $out .= '<i class="'.$iconClass.' '.$colorClass.'" title="'.$pictoTitle.'">'.$img_picto.'</i>'."\n";
  578. $out .= '<div class="timeline-item">'."\n";
  579. $out .= '<span class="timeline-header-action">';
  580. if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') {
  581. $out .= '<a class="timeline-btn" href="'.DOL_URL_ROOT.'/comm/mailing/card.php?id='.$histo[$key]['id'].'">'.img_object($langs->trans("ShowEMailing"), "email").' ';
  582. $out .= $histo[$key]['id'];
  583. $out .= '</a> ';
  584. } else {
  585. $out .= $actionstatic->getNomUrl(1, -1, 'valignmiddle').' ';
  586. }
  587. //if ($user->rights->agenda->allactions->read || $actionstatic->authorid == $user->id)
  588. //{
  589. // $out.='<a href="'.$url.'" class="timeline-btn" title="'.$langs->trans('Show').'" ><i class="fa fa-calendar" ></i>'.$langs->trans('Show').'</a>';
  590. //}
  591. if ($user->rights->agenda->allactions->create ||
  592. (($actionstatic->authorid == $user->id || $actionstatic->userownerid == $user->id) && $user->rights->agenda->myactions->create))
  593. {
  594. $out .= '<a class="timeline-btn" href="'.DOL_MAIN_URL_ROOT.'/comm/action/card.php?action=edit&id='.$actionstatic->id.'"><i class="fa fa-pencil" title="'.$langs->trans("Modify").'" ></i></a>';
  595. }
  596. $out .= '</span>';
  597. // Date
  598. $out .= '<span class="time"><i class="fa fa-clock-o"></i> ';
  599. $out .= dol_print_date($histo[$key]['datestart'], 'dayhour');
  600. if ($histo[$key]['dateend'] && $histo[$key]['dateend'] != $histo[$key]['datestart'])
  601. {
  602. $tmpa = dol_getdate($histo[$key]['datestart'], true);
  603. $tmpb = dol_getdate($histo[$key]['dateend'], true);
  604. if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) $out .= '-'.dol_print_date($histo[$key]['dateend'], 'hour');
  605. else $out .= '-'.dol_print_date($histo[$key]['dateend'], 'dayhour');
  606. }
  607. $late = 0;
  608. if ($histo[$key]['percent'] == 0 && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) $late = 1;
  609. if ($histo[$key]['percent'] == 0 && !$histo[$key]['datestart'] && $histo[$key]['dateend'] && $histo[$key]['datestart'] < ($now - $delay_warning)) $late = 1;
  610. if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && $histo[$key]['dateend'] && $histo[$key]['dateend'] < ($now - $delay_warning)) $late = 1;
  611. if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && !$histo[$key]['dateend'] && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) $late = 1;
  612. if ($late) $out .= img_warning($langs->trans("Late")).' ';
  613. $out .= "</span>\n";
  614. // Ref
  615. $out .= '<h3 class="timeline-header">';
  616. // Author of event
  617. $out .= '<span class="messaging-author">';
  618. if ($histo[$key]['userid'] > 0)
  619. {
  620. if (!isset($userGetNomUrlCache[$histo[$key]['userid']])) { // is in cache ?
  621. $userstatic->fetch($histo[$key]['userid']);
  622. $userGetNomUrlCache[$histo[$key]['userid']] = $userstatic->getNomUrl(-1, '', 0, 0, 16, 0, 'firstelselast', '');
  623. }
  624. $out .= $userGetNomUrlCache[$histo[$key]['userid']];
  625. }
  626. $out .= '</span>';
  627. // Title
  628. $out .= ' <span class="messaging-title">';
  629. if ($actionstatic->code == 'TICKET_MSG') {
  630. $out .= $langs->trans('TicketNewMessage');
  631. } elseif ($actionstatic->code == 'TICKET_MSG_PRIVATE') {
  632. $out .= $langs->trans('TicketNewMessage').' <em>('.$langs->trans('Private').')</em>';
  633. } else {
  634. if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'action') {
  635. $transcode = $langs->trans("Action".$histo[$key]['acode']);
  636. $libelle = ($transcode != "Action".$histo[$key]['acode'] ? $transcode : $histo[$key]['alabel']);
  637. $libelle = $histo[$key]['note'];
  638. $actionstatic->id = $histo[$key]['id'];
  639. $out .= dol_trunc($libelle, 120);
  640. }
  641. if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') {
  642. $out .= '<a href="'.DOL_URL_ROOT.'/comm/mailing/card.php?id='.$histo[$key]['id'].'">'.img_object($langs->trans("ShowEMailing"), "email").' ';
  643. $transcode = $langs->trans("Action".$histo[$key]['acode']);
  644. $libelle = ($transcode != "Action".$histo[$key]['acode'] ? $transcode : 'Send mass mailing');
  645. $out .= dol_trunc($libelle, 120);
  646. }
  647. }
  648. $out .= '</span>';
  649. $out .= '</h3>';
  650. if (!empty($histo[$key]['message'])
  651. && $actionstatic->code != 'AC_TICKET_CREATE'
  652. && $actionstatic->code != 'AC_TICKET_MODIFY'
  653. )
  654. {
  655. $out .= '<div class="timeline-body">';
  656. $out .= $histo[$key]['message'];
  657. $out .= '</div>';
  658. }
  659. // Timeline footer
  660. $footer = '';
  661. // Contact for this action
  662. if (isset($histo[$key]['socpeopleassigned']) && is_array($histo[$key]['socpeopleassigned']) && count($histo[$key]['socpeopleassigned']) > 0) {
  663. $contactList = '';
  664. foreach ($histo[$key]['socpeopleassigned'] as $cid => $Tab) {
  665. $contact = new Contact($db);
  666. $result = $contact->fetch($cid);
  667. if ($result < 0)
  668. dol_print_error($db, $contact->error);
  669. if ($result > 0) {
  670. $contactList .= !empty($contactList) ? ', ' : '';
  671. $contactList .= $contact->getNomUrl(1);
  672. if (isset($histo[$key]['acode']) && $histo[$key]['acode'] == 'AC_TEL') {
  673. if (!empty($contact->phone_pro))
  674. $contactList .= '('.dol_print_phone($contact->phone_pro).')';
  675. }
  676. }
  677. }
  678. $footer .= $langs->trans('ActionOnContact').' : '.$contactList;
  679. } elseif (empty($objcon->id) && isset($histo[$key]['contact_id']) && $histo[$key]['contact_id'] > 0)
  680. {
  681. $contact = new Contact($db);
  682. $result = $contact->fetch($histo[$key]['contact_id']);
  683. if ($result < 0)
  684. dol_print_error($db, $contact->error);
  685. if ($result > 0) {
  686. $footer .= $contact->getNomUrl(1);
  687. if (isset($histo[$key]['acode']) && $histo[$key]['acode'] == 'AC_TEL') {
  688. if (!empty($contact->phone_pro))
  689. $footer .= '('.dol_print_phone($contact->phone_pro).')';
  690. }
  691. }
  692. }
  693. $documents = getTicketActionCommEcmList($actionstatic);
  694. if (!empty($documents))
  695. {
  696. $footer .= '<div class="timeline-documents-container">';
  697. foreach ($documents as $doc)
  698. {
  699. $footer .= '<span id="document_'.$doc->id.'" class="timeline-documents" ';
  700. $footer .= ' data-id="'.$doc->id.'" ';
  701. $footer .= ' data-path="'.$doc->filepath.'"';
  702. $footer .= ' data-filename="'.dol_escape_htmltag($doc->filename).'" ';
  703. $footer .= '>';
  704. $filePath = DOL_DATA_ROOT.'/'.$doc->filepath.'/'.$doc->filename;
  705. $mime = dol_mimetype($filePath);
  706. $file = $actionstatic->id.'/'.$doc->filename;
  707. $thumb = $actionstatic->id.'/thumbs/'.substr($doc->filename, 0, strrpos($doc->filename, '.')).'_mini'.substr($doc->filename, strrpos($doc->filename, '.'));
  708. $doclink = dol_buildpath('document.php', 1).'?modulepart=actions&attachment=0&file='.urlencode($file).'&entity='.$conf->entity;
  709. $viewlink = dol_buildpath('viewimage.php', 1).'?modulepart=actions&file='.urlencode($thumb).'&entity='.$conf->entity;
  710. $mimeAttr = ' mime="'.$mime.'" ';
  711. $class = '';
  712. if (in_array($mime, array('image/png', 'image/jpeg', 'application/pdf'))) {
  713. $class .= ' documentpreview';
  714. }
  715. $footer .= '<a href="'.$doclink.'" class="btn-link '.$class.'" target="_blank" '.$mimeAttr.' >';
  716. $footer .= img_mime($filePath).' '.$doc->filename;
  717. $footer .= '</a>';
  718. $footer .= '</span>';
  719. }
  720. $footer .= '</div>';
  721. }
  722. if (!empty($footer)) {
  723. $out .= '<div class="timeline-footer">'.$footer.'</div>';
  724. }
  725. $out .= '</div>'."\n"; // end timeline-item
  726. $out .= '</li>';
  727. $out .= '<!-- END timeline item -->';
  728. $i++;
  729. }
  730. $out .= "</ul>\n";
  731. }
  732. if ($noprint) return $out;
  733. else print $out;
  734. }
  735. /**
  736. * getTicketActionCommEcmList
  737. *
  738. * @param ActionComm $object Object ActionComm
  739. * @return array Array of documents in index table
  740. */
  741. function getTicketActionCommEcmList($object)
  742. {
  743. global $conf, $db;
  744. $documents = array();
  745. $sql = 'SELECT ecm.rowid as id, ecm.src_object_type, ecm.src_object_id, ecm.filepath, ecm.filename';
  746. $sql .= ' FROM '.MAIN_DB_PREFIX.'ecm_files ecm';
  747. $sql .= ' WHERE ecm.filepath = \'agenda/'.$object->id.'\'';
  748. //$sql.= ' ecm.src_object_type = \''.$object->element.'\' AND ecm.src_object_id = '.$object->id; // Actually upload file doesn't add type
  749. $sql .= ' ORDER BY ecm.position ASC';
  750. $resql = $db->query($sql);
  751. if ($resql) {
  752. if ($db->num_rows($resql)) {
  753. while ($obj = $db->fetch_object($resql)) {
  754. $documents[$obj->id] = $obj;
  755. }
  756. }
  757. }
  758. return $documents;
  759. }