ticket.lib.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975
  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-2020 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) && $conf->societe->enabled) {
  75. $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
  76. $head[$h][0] = DOL_URL_ROOT.'/ticket/contact.php?track_id='.$object->track_id;
  77. $head[$h][1] = $langs->trans('ContactsAddresses');
  78. if ($nbContact > 0) {
  79. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
  80. }
  81. $head[$h][2] = 'contact';
  82. $h++;
  83. }
  84. complete_head_from_modules($conf, $langs, $object, $head, $h, 'ticket');
  85. // Attached files
  86. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  87. $upload_dir = $conf->ticket->dir_output."/".$object->ref;
  88. $nbFiles = count(dol_dir_list($upload_dir, 'files'));
  89. $head[$h][0] = dol_buildpath('/ticket/document.php', 1).'?id='.$object->id;
  90. $head[$h][1] = $langs->trans("Documents");
  91. if ($nbFiles > 0) {
  92. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbFiles.'</span>';
  93. }
  94. $head[$h][2] = 'tabTicketDocument';
  95. $h++;
  96. // History
  97. $ticketViewType = "messaging";
  98. if (empty($_SESSION['ticket-view-type'])) {
  99. $_SESSION['ticket-view-type'] = $ticketViewType;
  100. } else {
  101. $ticketViewType = $_SESSION['ticket-view-type'];
  102. }
  103. if ($ticketViewType == "messaging") {
  104. $head[$h][0] = DOL_URL_ROOT.'/ticket/messaging.php?track_id='.$object->track_id;
  105. } else {
  106. // $ticketViewType == "list"
  107. $head[$h][0] = DOL_URL_ROOT.'/ticket/agenda.php?track_id='.$object->track_id;
  108. }
  109. $head[$h][1] = $langs->trans('Events');
  110. if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
  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. $url = dol_buildpath('/public/ticket/view.php', 3).'?track_id='.$object->track_id.'&email='.$email;
  133. }
  134. $out = '';
  135. if (empty($conf->global->TICKET_ENABLE_PUBLIC_INTERFACE)) {
  136. $langs->load('errors');
  137. $out .= '<span class="opacitymedium">'.$langs->trans("ErrorPublicInterfaceNotEnabled").'</span>';
  138. } else {
  139. $out .= img_picto('', 'object_globe.png').' <span class="opacitymedium">'.$langs->trans("TicketPublicAccess").'</span><br>';
  140. if ($url) {
  141. $out .= '<div class="urllink">';
  142. $out .= '<input type="text" id="directpubliclink" class="quatrevingtpercentminusx" value="'.$url.'">';
  143. $out .= '<a href="'.$url.'" target="_blank" rel="noopener">'.img_picto('', 'object_globe.png', 'class="paddingleft"').'</a>';
  144. $out .= '</div>';
  145. $out .= ajax_autoselect("directpubliclink", 0);
  146. } else {
  147. $out .= '<span class="opacitymedium">'.$langs->trans("TicketNotCreatedFromPublicInterface").'</span>';
  148. }
  149. }
  150. return $out;
  151. }
  152. /**
  153. * Generate a random id
  154. *
  155. * @param int $car Length of string to generate key
  156. * @return string
  157. */
  158. function generate_random_id($car = 16)
  159. {
  160. $string = "";
  161. $chaine = "abcdefghijklmnopqrstuvwxyz123456789";
  162. srand((double) microtime() * 1000000);
  163. for ($i = 0; $i < $car; $i++) {
  164. $string .= $chaine[rand() % strlen($chaine)];
  165. }
  166. return $string;
  167. }
  168. /**
  169. * Show header for public pages
  170. *
  171. * @param string $title Title
  172. * @param string $head Head array
  173. * @param int $disablejs More content into html header
  174. * @param int $disablehead More content into html header
  175. * @param array $arrayofjs Array of complementary js files
  176. * @param array $arrayofcss Array of complementary css files
  177. * @return void
  178. */
  179. function llxHeaderTicket($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '')
  180. {
  181. global $user, $conf, $langs, $mysoc;
  182. top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss, 0, 1); // Show html headers
  183. print '<body id="mainbody" class="publicnewticketform">';
  184. print '<div class="center">';
  185. // Define urllogo
  186. if (!empty($conf->global->TICKET_SHOW_COMPANY_LOGO) || !empty($conf->global->TICKET_PUBLIC_INTERFACE_TOPIC)) {
  187. // Print logo
  188. if (!empty($conf->global->TICKET_SHOW_COMPANY_LOGO)) {
  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. print '<div class="backgreypublicpayment">';
  202. print '<div class="logopublicpayment">';
  203. if ($urllogo) {
  204. print '<a href="'.($conf->global->TICKET_URL_PUBLIC_INTERFACE ? $conf->global->TICKET_URL_PUBLIC_INTERFACE : dol_buildpath('/public/ticket/index.php', 1)).'">';
  205. print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
  206. print '>';
  207. print '</a>';
  208. }
  209. if (!empty($conf->global->TICKET_PUBLIC_INTERFACE_TOPIC)) {
  210. print '<div class="clearboth"></div><strong>'.($conf->global->TICKET_PUBLIC_INTERFACE_TOPIC ? $conf->global->TICKET_PUBLIC_INTERFACE_TOPIC : $langs->trans("TicketSystem")).'</strong>';
  211. }
  212. print '</div>';
  213. if (empty($conf->global->MAIN_HIDE_POWERED_BY)) {
  214. print '<div class="poweredbypublicpayment opacitymedium right"><a class="poweredbyhref" href="https://www.dolibarr.org?utm_medium=website&utm_source=poweredby" target="dolibarr" rel="noopener">'.$langs->trans("PoweredBy").'<br><img src="'.DOL_URL_ROOT.'/theme/dolibarr_logo.svg" width="80px"></a></div>';
  215. }
  216. print '</div>';
  217. }
  218. if (!empty($conf->global->TICKET_IMAGE_PUBLIC_INTERFACE)) {
  219. print '<div class="backimagepublicticket">';
  220. print '<img id="idRECRUITMENT_IMAGE_PUBLIC_INTERFACE" src="'.$conf->global->MEMBER_IMAGE_PUBLIC_REGISTRATION.'">';
  221. print '</div>';
  222. }
  223. print '</div>';
  224. print '<div class="ticketlargemargin">';
  225. }
  226. /**
  227. * Show html area with actions for ticket messaging.
  228. * Note: Global parameter $param must be defined.
  229. *
  230. * @param Conf $conf Object conf
  231. * @param Translate $langs Object langs
  232. * @param DoliDB $db Object db
  233. * @param mixed $filterobj Filter on object Adherent|Societe|Project|Product|CommandeFournisseur|Dolresource|Ticket|... to list events linked to an object
  234. * @param Contact $objcon Filter on object contact to filter events on a contact
  235. * @param int $noprint Return string but does not output it
  236. * @param string $actioncode Filter on actioncode
  237. * @param string $donetodo Filter on event 'done' or 'todo' or ''=nofilter (all).
  238. * @param array $filters Filter on other fields
  239. * @param string $sortfield Sort field
  240. * @param string $sortorder Sort order
  241. * @return string|void Return html part or void if noprint is 1
  242. */
  243. function show_ticket_messaging($conf, $langs, $db, $filterobj, $objcon = '', $noprint = 0, $actioncode = '', $donetodo = 'done', $filters = array(), $sortfield = 'a.datep,a.id', $sortorder = 'DESC')
  244. {
  245. global $user, $conf;
  246. global $form;
  247. global $param, $massactionbutton;
  248. dol_include_once('/comm/action/class/actioncomm.class.php');
  249. // Check parameters
  250. if (!is_object($filterobj) && !is_object($objcon)) {
  251. dol_print_error('', 'BadParameter');
  252. }
  253. $histo = array();
  254. $numaction = 0;
  255. $now = dol_now();
  256. $sortfield_list = explode(',', $sortfield);
  257. $sortfield_label_list = array('a.id' => 'id', 'a.datep' => 'dp', 'a.percent' => 'percent');
  258. $sortfield_new_list = array();
  259. foreach ($sortfield_list as $sortfield_value) {
  260. $sortfield_new_list[] = $sortfield_label_list[trim($sortfield_value)];
  261. }
  262. $sortfield_new = implode(',', $sortfield_new_list);
  263. if (!empty($conf->agenda->enabled)) {
  264. // Search histo on actioncomm
  265. if (is_object($objcon) && $objcon->id > 0) {
  266. $sql = "SELECT DISTINCT a.id, a.label as label,";
  267. } else {
  268. $sql = "SELECT a.id, a.label as label,";
  269. }
  270. $sql .= " a.datep as dp,";
  271. $sql .= " a.note as message,";
  272. $sql .= " a.datep2 as dp2,";
  273. $sql .= " a.percent as percent, 'action' as type,";
  274. $sql .= " a.fk_element, a.elementtype,";
  275. $sql .= " a.fk_contact,";
  276. $sql .= " c.code as acode, c.libelle as alabel, c.picto as apicto,";
  277. $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";
  278. if (is_object($filterobj) && get_class($filterobj) == 'Societe') {
  279. $sql .= ", sp.lastname, sp.firstname";
  280. } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
  281. $sql .= ", m.lastname, m.firstname";
  282. } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
  283. $sql .= ", o.ref";
  284. } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
  285. $sql .= ", o.ref";
  286. } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
  287. $sql .= ", o.ref";
  288. } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
  289. $sql .= ", o.ref";
  290. } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
  291. $sql .= ", o.ref";
  292. }
  293. $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
  294. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = a.fk_user_action";
  295. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_actioncomm as c ON a.fk_action = c.id";
  296. $force_filter_contact = false;
  297. if (is_object($objcon) && $objcon->id > 0) {
  298. $force_filter_contact = true;
  299. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."actioncomm_resources as r ON a.id = r.fk_actioncomm";
  300. $sql .= " AND r.element_type = '".$db->escape($objcon->table_element)."' AND r.fk_element = ".((int) $objcon->id);
  301. }
  302. if (is_object($filterobj) && get_class($filterobj) == 'Societe') {
  303. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON a.fk_contact = sp.rowid";
  304. } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
  305. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."element_resources as er";
  306. $sql .= " ON er.resource_type = 'dolresource'";
  307. $sql .= " AND er.element_id = a.id";
  308. $sql .= " AND er.resource_id = ".((int) $filterobj->id);
  309. } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
  310. $sql .= ", ".MAIN_DB_PREFIX."adherent as m";
  311. } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
  312. $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as o";
  313. } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
  314. $sql .= ", ".MAIN_DB_PREFIX."product as o";
  315. } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
  316. $sql .= ", ".MAIN_DB_PREFIX."ticket as o";
  317. } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
  318. $sql .= ", ".MAIN_DB_PREFIX."bom_bom as o";
  319. } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
  320. $sql .= ", ".MAIN_DB_PREFIX."contrat as o";
  321. }
  322. $sql .= " WHERE a.entity IN (".getEntity('agenda').")";
  323. if ($force_filter_contact === false) {
  324. if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur')) && $filterobj->id) {
  325. $sql .= " AND a.fk_soc = ".((int) $filterobj->id);
  326. } elseif (is_object($filterobj) && get_class($filterobj) == 'Project' && $filterobj->id) {
  327. $sql .= " AND a.fk_project = ".((int) $filterobj->id);
  328. } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
  329. $sql .= " AND a.fk_element = m.rowid AND a.elementtype = 'member'";
  330. if ($filterobj->id) {
  331. $sql .= " AND a.fk_element = ".((int) $filterobj->id);
  332. }
  333. } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
  334. $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'order_supplier'";
  335. if ($filterobj->id) {
  336. $sql .= " AND a.fk_element = ".((int) $filterobj->id);
  337. }
  338. } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
  339. $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'product'";
  340. if ($filterobj->id) {
  341. $sql .= " AND a.fk_element = ".((int) $filterobj->id);
  342. }
  343. } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
  344. $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'ticket'";
  345. if ($filterobj->id) {
  346. $sql .= " AND a.fk_element = ".((int) $filterobj->id);
  347. }
  348. } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
  349. $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'bom'";
  350. if ($filterobj->id) {
  351. $sql .= " AND a.fk_element = ".((int) $filterobj->id);
  352. }
  353. } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
  354. $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'contract'";
  355. if ($filterobj->id) {
  356. $sql .= " AND a.fk_element = ".((int) $filterobj->id);
  357. }
  358. }
  359. }
  360. // Condition on actioncode
  361. if (!empty($actioncode)) {
  362. if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
  363. if ($actioncode == 'AC_NON_AUTO') {
  364. $sql .= " AND c.type != 'systemauto'";
  365. } elseif ($actioncode == 'AC_ALL_AUTO') {
  366. $sql .= " AND c.type = 'systemauto'";
  367. } else {
  368. if ($actioncode == 'AC_OTH') {
  369. $sql .= " AND c.type != 'systemauto'";
  370. } elseif ($actioncode == 'AC_OTH_AUTO') {
  371. $sql .= " AND c.type = 'systemauto'";
  372. }
  373. }
  374. } else {
  375. if ($actioncode == 'AC_NON_AUTO') {
  376. $sql .= " AND c.type != 'systemauto'";
  377. } elseif ($actioncode == 'AC_ALL_AUTO') {
  378. $sql .= " AND c.type = 'systemauto'";
  379. } else {
  380. $sql .= " AND c.code = '".$db->escape($actioncode)."'";
  381. }
  382. }
  383. }
  384. if ($donetodo == 'todo') {
  385. $sql .= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
  386. } elseif ($donetodo == 'done') {
  387. $sql .= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
  388. }
  389. if (is_array($filters) && $filters['search_agenda_label']) {
  390. $sql .= natural_search('a.label', $filters['search_agenda_label']);
  391. }
  392. }
  393. // Add also event from emailings. TODO This should be replaced by an automatic event ? May be it's too much for very large emailing.
  394. if (!empty($conf->mailing->enabled) && !empty($objcon->email)
  395. && (empty($actioncode) || $actioncode == 'AC_OTH_AUTO' || $actioncode == 'AC_EMAILING')) {
  396. $langs->load("mails");
  397. $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";
  398. $sql2 .= ", null as fk_element, '' as elementtype, null as contact_id";
  399. $sql2 .= ", 'AC_EMAILING' as acode, '' as alabel, '' as apicto";
  400. $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
  401. if (is_object($filterobj) && get_class($filterobj) == 'Societe') {
  402. $sql2 .= ", '' as lastname, '' as firstname";
  403. } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
  404. $sql2 .= ", '' as lastname, '' as firstname";
  405. } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
  406. $sql2 .= ", '' as ref";
  407. } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
  408. $sql2 .= ", '' as ref";
  409. } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
  410. $sql2 .= ", '' as ref";
  411. }
  412. $sql2 .= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."user as u";
  413. $sql2 .= " WHERE mc.email = '".$db->escape($objcon->email)."'"; // Search is done on email.
  414. $sql2 .= " AND mc.statut = 1";
  415. $sql2 .= " AND u.rowid = m.fk_user_valid";
  416. $sql2 .= " AND mc.fk_mailing=m.rowid";
  417. }
  418. if (!empty($sql) && !empty($sql2)) {
  419. $sql = $sql." UNION ".$sql2;
  420. } elseif (empty($sql) && !empty($sql2)) {
  421. $sql = $sql2;
  422. }
  423. // TODO Add limit in nb of results
  424. if ($sql) { // May not be defined if module Agenda is not enabled and mailing module disabled too
  425. $sql .= $db->order($sortfield_new, $sortorder);
  426. dol_syslog("company.lib::show_actions_done", LOG_DEBUG);
  427. $resql = $db->query($sql);
  428. if ($resql) {
  429. $i = 0;
  430. $num = $db->num_rows($resql);
  431. while ($i < $num) {
  432. $obj = $db->fetch_object($resql);
  433. if ($obj->type == 'action') {
  434. $contactaction = new ActionComm($db);
  435. $contactaction->id = $obj->id;
  436. $result = $contactaction->fetchResources();
  437. if ($result < 0) {
  438. dol_print_error($db);
  439. setEventMessage("company.lib::show_actions_done Error fetch ressource", 'errors');
  440. }
  441. //if ($donetodo == 'todo') $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
  442. //elseif ($donetodo == 'done') $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
  443. $tododone = '';
  444. if (($obj->percent >= 0 and $obj->percent < 100) || ($obj->percent == -1 && $obj->datep > $now)) {
  445. $tododone = 'todo';
  446. }
  447. $histo[$numaction] = array(
  448. 'type'=>$obj->type,
  449. 'tododone'=>$tododone,
  450. 'id'=>$obj->id,
  451. 'datestart'=>$db->jdate($obj->dp),
  452. 'dateend'=>$db->jdate($obj->dp2),
  453. 'note'=>$obj->label,
  454. 'message'=>$obj->message,
  455. 'percent'=>$obj->percent,
  456. 'userid'=>$obj->user_id,
  457. 'login'=>$obj->user_login,
  458. 'userfirstname'=>$obj->user_firstname,
  459. 'userlastname'=>$obj->user_lastname,
  460. 'userphoto'=>$obj->user_photo,
  461. 'contact_id'=>$obj->fk_contact,
  462. 'socpeopleassigned' => $contactaction->socpeopleassigned,
  463. 'lastname'=>$obj->lastname,
  464. 'firstname'=>$obj->firstname,
  465. 'fk_element'=>$obj->fk_element,
  466. 'elementtype'=>$obj->elementtype,
  467. // Type of event
  468. 'acode'=>$obj->acode,
  469. 'alabel'=>$obj->alabel,
  470. 'libelle'=>$obj->alabel, // deprecated
  471. 'apicto'=>$obj->apicto
  472. );
  473. } else {
  474. $histo[$numaction] = array(
  475. 'type'=>$obj->type,
  476. 'tododone'=>'done',
  477. 'id'=>$obj->id,
  478. 'datestart'=>$db->jdate($obj->dp),
  479. 'dateend'=>$db->jdate($obj->dp2),
  480. 'note'=>$obj->label,
  481. 'message'=>$obj->message,
  482. 'percent'=>$obj->percent,
  483. 'acode'=>$obj->acode,
  484. 'userid'=>$obj->user_id,
  485. 'login'=>$obj->user_login,
  486. 'userfirstname'=>$obj->user_firstname,
  487. 'userlastname'=>$obj->user_lastname,
  488. 'userphoto'=>$obj->user_photo
  489. );
  490. }
  491. $numaction++;
  492. $i++;
  493. }
  494. } else {
  495. dol_print_error($db);
  496. }
  497. }
  498. // Set $out to sow events
  499. $out = '';
  500. if (empty($conf->agenda->enabled)) {
  501. $langs->loadLangs(array("admin", "errors"));
  502. $out = info_admin($langs->trans("WarningModuleXDisabledSoYouMayMissEventHere", $langs->transnoentitiesnoconv("Module2400Name")), 0, 0, 'warning');
  503. }
  504. if (!empty($conf->agenda->enabled) || (!empty($conf->mailing->enabled) && !empty($objcon->email))) {
  505. $delay_warning = $conf->global->MAIN_DELAY_ACTIONS_TODO * 24 * 60 * 60;
  506. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  507. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  508. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  509. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  510. $formactions = new FormActions($db);
  511. $actionstatic = new ActionComm($db);
  512. $userstatic = new User($db);
  513. $contactstatic = new Contact($db);
  514. $userGetNomUrlCache = array();
  515. $out .= '<div class="filters-container" >';
  516. $out .= '<form name="listactionsfilter" class="listactionsfilter" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  517. $out .= '<input type="hidden" name="token" value="'.newToken().'">';
  518. if ($objcon && get_class($objcon) == 'Contact' &&
  519. (is_null($filterobj) || get_class($filterobj) == 'Societe')) {
  520. $out .= '<input type="hidden" name="id" value="'.$objcon->id.'" />';
  521. } else {
  522. $out .= '<input type="hidden" name="id" value="'.$filterobj->id.'" />';
  523. }
  524. if ($filterobj && get_class($filterobj) == 'Societe') {
  525. $out .= '<input type="hidden" name="socid" value="'.$filterobj->id.'" />';
  526. }
  527. $out .= "\n";
  528. $out .= '<div class="div-table-responsive-no-min">';
  529. $out .= '<table class="noborder borderbottom centpercent">';
  530. $out .= '<tr class="liste_titre">';
  531. $out .= getTitleFieldOfList('Date', 0, $_SERVER["PHP_SELF"], 'a.datep', '', $param, '', $sortfield, $sortorder, '')."\n";
  532. $out .= '<th class="liste_titre"><strong class="hideonsmartphone">'.$langs->trans("Search").' : </strong></th>';
  533. if ($donetodo) {
  534. $out .= '<th class="liste_titre"></th>';
  535. }
  536. $out .= '<th class="liste_titre">';
  537. $out .= '<span class="fas fa-square inline-block fawidth30" style=" color: #ddd;" title="'.$langs->trans("ActionType").'"></span>';
  538. //$out .= img_picto($langs->trans("Type"), 'type');
  539. $out .= $formactions->select_type_actions($actioncode, "actioncode", '', empty($conf->global->AGENDA_USE_EVENT_TYPE) ? 1 : -1, 0, 0, 1, 'minwidth200imp');
  540. $out .= '</th>';
  541. $out .= '<th class="liste_titre maxwidth100onsmartphone">';
  542. $out .= '<input type="text" class="maxwidth100onsmartphone" name="search_agenda_label" value="'.$filters['search_agenda_label'].'" placeholder="'.$langs->trans("Label").'">';
  543. $out .= '</th>';
  544. $out .= '<th class="liste_titre width50 middle">';
  545. $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
  546. $out .= $searchpicto;
  547. $out .= '</th>';
  548. $out .= '</tr>';
  549. $out .= '</table>';
  550. $out .= '</form>';
  551. $out .= '</div>';
  552. $out .= "\n";
  553. $out .= '<ul class="timeline">';
  554. if ($donetodo) {
  555. $tmp = '';
  556. if (get_class($filterobj) == 'Societe') {
  557. $tmp .= '<a href="'.DOL_URL_ROOT.'/comm/action/list.php?action=show_list&socid='.$filterobj->id.'&status=done">';
  558. }
  559. $tmp .= ($donetodo != 'done' ? $langs->trans("ActionsToDoShort") : '');
  560. $tmp .= ($donetodo != 'done' && $donetodo != 'todo' ? ' / ' : '');
  561. $tmp .= ($donetodo != 'todo' ? $langs->trans("ActionsDoneShort") : '');
  562. //$out.=$langs->trans("ActionsToDoShort").' / '.$langs->trans("ActionsDoneShort");
  563. if (get_class($filterobj) == 'Societe') {
  564. $tmp .= '</a>';
  565. }
  566. $out .= getTitleFieldOfList($tmp);
  567. }
  568. //require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
  569. //$caction=new CActionComm($db);
  570. //$arraylist=$caction->liste_array(1, 'code', '', (empty($conf->global->AGENDA_USE_EVENT_TYPE)?1:0), '', 1);
  571. $actualCycleDate = false;
  572. foreach ($histo as $key => $value) {
  573. $actionstatic->fetch($histo[$key]['id']); // TODO Do we need this, we already have a lot of data of line into $histo
  574. $actionstatic->type_picto = $histo[$key]['apicto'];
  575. $actionstatic->type_code = $histo[$key]['acode'];
  576. $url = DOL_URL_ROOT.'/comm/action/card.php?id='.$histo[$key]['id'];
  577. $tmpa = dol_getdate($histo[$key]['datestart'], false);
  578. if ($actualCycleDate !== $tmpa['year'].'-'.$tmpa['yday']) {
  579. $actualCycleDate = $tmpa['year'].'-'.$tmpa['yday'];
  580. $out .= '<!-- timeline time label -->';
  581. $out .= '<li class="time-label">';
  582. $out .= '<span class="timeline-badge-date">';
  583. $out .= dol_print_date($histo[$key]['datestart'], 'daytext', 'tzuserrel', $langs);
  584. $out .= '</span>';
  585. $out .= '</li>';
  586. $out .= '<!-- /.timeline-label -->';
  587. }
  588. $out .= '<!-- timeline item -->'."\n";
  589. $out .= '<li class="timeline-code-'.strtolower($actionstatic->code).'">';
  590. $out .= getTicketTimelineIcon($actionstatic, $histo, $key);
  591. $out .= '<div class="timeline-item">'."\n";
  592. $out .= '<span class="timeline-header-action">';
  593. if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') {
  594. $out .= '<a class="timeline-btn" href="'.DOL_URL_ROOT.'/comm/mailing/card.php?id='.$histo[$key]['id'].'">'.img_object($langs->trans("ShowEMailing"), "email").' ';
  595. $out .= $histo[$key]['id'];
  596. $out .= '</a> ';
  597. } else {
  598. $out .= $actionstatic->getNomUrl(1, -1, 'valignmiddle').' ';
  599. }
  600. //if ($user->rights->agenda->allactions->read || $actionstatic->authorid == $user->id)
  601. //{
  602. // $out.='<a href="'.$url.'" class="timeline-btn" title="'.$langs->trans('Show').'" ><i class="fa fa-calendar" ></i>'.$langs->trans('Show').'</a>';
  603. //}
  604. if ($user->rights->agenda->allactions->create ||
  605. (($actionstatic->authorid == $user->id || $actionstatic->userownerid == $user->id) && $user->rights->agenda->myactions->create)) {
  606. $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>';
  607. }
  608. $out .= '</span>';
  609. // Date
  610. $out .= '<span class="time"><i class="fa fa-clock-o"></i> ';
  611. $out .= dol_print_date($histo[$key]['datestart'], 'dayhour', 'tzuserrel');
  612. if ($histo[$key]['dateend'] && $histo[$key]['dateend'] != $histo[$key]['datestart']) {
  613. $tmpa = dol_getdate($histo[$key]['datestart'], true);
  614. $tmpb = dol_getdate($histo[$key]['dateend'], true);
  615. if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
  616. $out .= '-'.dol_print_date($histo[$key]['dateend'], 'hour', 'tzuserrel');
  617. } else {
  618. $out .= '-'.dol_print_date($histo[$key]['dateend'], 'dayhour', 'tzuserrel');
  619. }
  620. }
  621. $late = 0;
  622. if ($histo[$key]['percent'] == 0 && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
  623. $late = 1;
  624. }
  625. if ($histo[$key]['percent'] == 0 && !$histo[$key]['datestart'] && $histo[$key]['dateend'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
  626. $late = 1;
  627. }
  628. if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && $histo[$key]['dateend'] && $histo[$key]['dateend'] < ($now - $delay_warning)) {
  629. $late = 1;
  630. }
  631. if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && !$histo[$key]['dateend'] && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
  632. $late = 1;
  633. }
  634. if ($late) {
  635. $out .= img_warning($langs->trans("Late")).' ';
  636. }
  637. $out .= "</span>\n";
  638. // Ref
  639. $out .= '<h3 class="timeline-header">';
  640. // Author of event
  641. $out .= '<span class="messaging-author">';
  642. if ($histo[$key]['userid'] > 0) {
  643. if (!isset($userGetNomUrlCache[$histo[$key]['userid']])) { // is in cache ?
  644. $userstatic->fetch($histo[$key]['userid']);
  645. $userGetNomUrlCache[$histo[$key]['userid']] = $userstatic->getNomUrl(-1, '', 0, 0, 16, 0, 'firstelselast', '');
  646. }
  647. $out .= $userGetNomUrlCache[$histo[$key]['userid']];
  648. }
  649. $out .= '</span>';
  650. // Title
  651. $out .= ' <span class="messaging-title">';
  652. if ($actionstatic->code == 'TICKET_MSG') {
  653. $out .= $langs->trans('TicketNewMessage');
  654. } elseif ($actionstatic->code == 'TICKET_MSG_PRIVATE') {
  655. $out .= $langs->trans('TicketNewMessage').' <em>('.$langs->trans('Private').')</em>';
  656. } else {
  657. if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'action') {
  658. $transcode = $langs->trans("Action".$histo[$key]['acode']);
  659. $libelle = ($transcode != "Action".$histo[$key]['acode'] ? $transcode : $histo[$key]['alabel']);
  660. $libelle = $histo[$key]['note'];
  661. $actionstatic->id = $histo[$key]['id'];
  662. $out .= dol_trunc($libelle, 120);
  663. }
  664. if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') {
  665. $out .= '<a href="'.DOL_URL_ROOT.'/comm/mailing/card.php?id='.$histo[$key]['id'].'">'.img_object($langs->trans("ShowEMailing"), "email").' ';
  666. $transcode = $langs->trans("Action".$histo[$key]['acode']);
  667. $libelle = ($transcode != "Action".$histo[$key]['acode'] ? $transcode : 'Send mass mailing');
  668. $out .= dol_trunc($libelle, 120);
  669. }
  670. }
  671. $out .= '</span>';
  672. $out .= '</h3>';
  673. if (!empty($histo[$key]['message'])
  674. && $actionstatic->code != 'AC_TICKET_CREATE'
  675. && $actionstatic->code != 'AC_TICKET_MODIFY'
  676. ) {
  677. $out .= '<div class="timeline-body">';
  678. $out .= $histo[$key]['message'];
  679. $out .= '</div>';
  680. }
  681. // Timeline footer
  682. $footer = '';
  683. // Contact for this action
  684. if (isset($histo[$key]['socpeopleassigned']) && is_array($histo[$key]['socpeopleassigned']) && count($histo[$key]['socpeopleassigned']) > 0) {
  685. $contactList = '';
  686. foreach ($histo[$key]['socpeopleassigned'] as $cid => $Tab) {
  687. $contact = new Contact($db);
  688. $result = $contact->fetch($cid);
  689. if ($result < 0) {
  690. dol_print_error($db, $contact->error);
  691. }
  692. if ($result > 0) {
  693. $contactList .= !empty($contactList) ? ', ' : '';
  694. $contactList .= $contact->getNomUrl(1);
  695. if (isset($histo[$key]['acode']) && $histo[$key]['acode'] == 'AC_TEL') {
  696. if (!empty($contact->phone_pro)) {
  697. $contactList .= '('.dol_print_phone($contact->phone_pro).')';
  698. }
  699. }
  700. }
  701. }
  702. $footer .= $langs->trans('ActionOnContact').' : '.$contactList;
  703. } elseif (empty($objcon->id) && isset($histo[$key]['contact_id']) && $histo[$key]['contact_id'] > 0) {
  704. $contact = new Contact($db);
  705. $result = $contact->fetch($histo[$key]['contact_id']);
  706. if ($result < 0) {
  707. dol_print_error($db, $contact->error);
  708. }
  709. if ($result > 0) {
  710. $footer .= $contact->getNomUrl(1);
  711. if (isset($histo[$key]['acode']) && $histo[$key]['acode'] == 'AC_TEL') {
  712. if (!empty($contact->phone_pro)) {
  713. $footer .= '('.dol_print_phone($contact->phone_pro).')';
  714. }
  715. }
  716. }
  717. }
  718. $documents = getTicketActionCommEcmList($actionstatic);
  719. if (!empty($documents)) {
  720. $footer .= '<div class="timeline-documents-container">';
  721. foreach ($documents as $doc) {
  722. $footer .= '<span id="document_'.$doc->id.'" class="timeline-documents" ';
  723. $footer .= ' data-id="'.$doc->id.'" ';
  724. $footer .= ' data-path="'.$doc->filepath.'"';
  725. $footer .= ' data-filename="'.dol_escape_htmltag($doc->filename).'" ';
  726. $footer .= '>';
  727. $filePath = DOL_DATA_ROOT.'/'.$doc->filepath.'/'.$doc->filename;
  728. $mime = dol_mimetype($filePath);
  729. $file = $actionstatic->id.'/'.$doc->filename;
  730. $thumb = $actionstatic->id.'/thumbs/'.substr($doc->filename, 0, strrpos($doc->filename, '.')).'_mini'.substr($doc->filename, strrpos($doc->filename, '.'));
  731. $doclink = dol_buildpath('document.php', 1).'?modulepart=actions&attachment=0&file='.urlencode($file).'&entity='.$conf->entity;
  732. $viewlink = dol_buildpath('viewimage.php', 1).'?modulepart=actions&file='.urlencode($thumb).'&entity='.$conf->entity;
  733. $mimeAttr = ' mime="'.$mime.'" ';
  734. $class = '';
  735. if (in_array($mime, array('image/png', 'image/jpeg', 'application/pdf'))) {
  736. $class .= ' documentpreview';
  737. }
  738. $footer .= '<a href="'.$doclink.'" class="btn-link '.$class.'" target="_blank" '.$mimeAttr.' >';
  739. $footer .= img_mime($filePath).' '.$doc->filename;
  740. $footer .= '</a>';
  741. $footer .= '</span>';
  742. }
  743. $footer .= '</div>';
  744. }
  745. if (!empty($footer)) {
  746. $out .= '<div class="timeline-footer">'.$footer.'</div>';
  747. }
  748. $out .= '</div>'."\n"; // end timeline-item
  749. $out .= '</li>';
  750. $out .= '<!-- END timeline item -->';
  751. $i++;
  752. }
  753. $out .= "</ul>\n";
  754. }
  755. if ($noprint) {
  756. return $out;
  757. } else {
  758. print $out;
  759. }
  760. }
  761. /**
  762. * Get timeline icon
  763. * @param ActionComm $actionstatic actioncomm
  764. * @param array $histo histo
  765. * @param int $key key
  766. * @return string
  767. */
  768. function getTicketTimelineIcon($actionstatic, &$histo, $key)
  769. {
  770. global $conf, $langs;
  771. $out = '<!-- timeline icon -->'."\n";
  772. $iconClass = 'fa fa-comments';
  773. $img_picto = '';
  774. $colorClass = '';
  775. $pictoTitle = '';
  776. if ($histo[$key]['percent'] == -1) {
  777. $colorClass = 'timeline-icon-not-applicble';
  778. $pictoTitle = $langs->trans('StatusNotApplicable');
  779. } elseif ($histo[$key]['percent'] == 0) {
  780. $colorClass = 'timeline-icon-todo';
  781. $pictoTitle = $langs->trans('StatusActionToDo').' (0%)';
  782. } elseif ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100) {
  783. $colorClass = 'timeline-icon-in-progress';
  784. $pictoTitle = $langs->trans('StatusActionInProcess').' ('.$histo[$key]['percent'].'%)';
  785. } elseif ($histo[$key]['percent'] >= 100) {
  786. $colorClass = 'timeline-icon-done';
  787. $pictoTitle = $langs->trans('StatusActionDone').' (100%)';
  788. }
  789. if ($actionstatic->code == 'AC_TICKET_CREATE') {
  790. $iconClass = 'fa fa-ticket';
  791. } elseif ($actionstatic->code == 'AC_TICKET_MODIFY') {
  792. $iconClass = 'fa fa-pencilxxx';
  793. } elseif ($actionstatic->code == 'TICKET_MSG') {
  794. $iconClass = 'fa fa-comments';
  795. } elseif ($actionstatic->code == 'TICKET_MSG_PRIVATE') {
  796. $iconClass = 'fa fa-mask';
  797. } elseif (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
  798. if ($actionstatic->type_picto) {
  799. $img_picto = img_picto('', $actionstatic->type_picto);
  800. } else {
  801. if ($actionstatic->type_code == 'AC_RDV') {
  802. $iconClass = 'fa fa-handshake';
  803. } elseif ($actionstatic->type_code == 'AC_TEL') {
  804. $iconClass = 'fa fa-phone';
  805. } elseif ($actionstatic->type_code == 'AC_FAX') {
  806. $iconClass = 'fa fa-fax';
  807. } elseif ($actionstatic->type_code == 'AC_EMAIL') {
  808. $iconClass = 'fa fa-envelope';
  809. } elseif ($actionstatic->type_code == 'AC_INT') {
  810. $iconClass = 'fa fa-shipping-fast';
  811. } elseif ($actionstatic->type_code == 'AC_OTH_AUTO') {
  812. $iconClass = 'fa fa-robot';
  813. } elseif (!preg_match('/_AUTO/', $actionstatic->type_code)) {
  814. $iconClass = 'fa fa-robot';
  815. }
  816. }
  817. }
  818. $out .= '<i class="'.$iconClass.' '.$colorClass.'" title="'.$pictoTitle.'">'.$img_picto.'</i>'."\n";
  819. return $out;
  820. }
  821. /**
  822. * getTicketActionCommEcmList
  823. *
  824. * @param ActionComm $object Object ActionComm
  825. * @return array Array of documents in index table
  826. */
  827. function getTicketActionCommEcmList($object)
  828. {
  829. global $conf, $db;
  830. $documents = array();
  831. $sql = 'SELECT ecm.rowid as id, ecm.src_object_type, ecm.src_object_id, ecm.filepath, ecm.filename';
  832. $sql .= ' FROM '.MAIN_DB_PREFIX.'ecm_files ecm';
  833. $sql .= " WHERE ecm.filepath = 'agenda/".((int) $object->id)."'";
  834. //$sql.= " ecm.src_object_type = '".$db->escape($object->element)."' AND ecm.src_object_id = ".((int) $object->id); // Old version didn't add object_type during upload
  835. $sql .= ' ORDER BY ecm.position ASC';
  836. $resql = $db->query($sql);
  837. if ($resql) {
  838. if ($db->num_rows($resql)) {
  839. while ($obj = $db->fetch_object($resql)) {
  840. $documents[$obj->id] = $obj;
  841. }
  842. }
  843. }
  844. return $documents;
  845. }