messaging.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005 Brice Davoleau <brice.davoleau@gmail.com>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2006-2019 Laurent Destailleur <eldy@users.sourceforge.net>
  6. * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
  7. * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
  8. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/societe/messaging.php
  25. * \ingroup societe
  26. * \brief Page of third party events
  27. */
  28. // Load Dolibarr environment
  29. require '../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  33. // Load translation files required by the page
  34. $langs->loadLangs(array('agenda', 'bills', 'companies', 'orders', 'propal'));
  35. if (GETPOST('actioncode', 'array')) {
  36. $actioncode = GETPOST('actioncode', 'array', 3);
  37. if (!count($actioncode)) {
  38. $actioncode = '0';
  39. }
  40. } else {
  41. $actioncode = GETPOST("actioncode", "alpha", 3) ?GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT'));
  42. }
  43. $search_rowid = GETPOST('search_rowid');
  44. $search_agenda_label = GETPOST('search_agenda_label');
  45. // Security check
  46. $socid = GETPOST('socid', 'int');
  47. if ($user->socid) {
  48. $socid = $user->socid;
  49. }
  50. $result = restrictedArea($user, 'societe', $socid, '&societe');
  51. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  52. $sortfield = GETPOST('sortfield', 'aZ09comma');
  53. $sortorder = GETPOST('sortorder', 'aZ09comma');
  54. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  55. if (empty($page) || $page == -1) {
  56. $page = 0;
  57. } // If $page is not defined, or '' or -1
  58. $offset = $limit * $page;
  59. $pageprev = $page - 1;
  60. $pagenext = $page + 1;
  61. if (!$sortfield) {
  62. $sortfield = 'a.datep,a.id';
  63. }
  64. if (!$sortorder) {
  65. $sortorder = 'DESC,DESC';
  66. }
  67. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  68. $hookmanager->initHooks(array('agendathirdparty'));
  69. /*
  70. * Actions
  71. */
  72. $parameters = array('id'=>$socid);
  73. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  74. if ($reshook < 0) {
  75. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  76. }
  77. if (empty($reshook)) {
  78. // Cancel
  79. if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
  80. header("Location: ".$backtopage);
  81. exit;
  82. }
  83. // Purge search criteria
  84. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
  85. $actioncode = '';
  86. $search_agenda_label = '';
  87. }
  88. }
  89. /*
  90. * View
  91. */
  92. $form = new Form($db);
  93. if ($socid > 0) {
  94. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  95. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  96. $object = new Societe($db);
  97. $result = $object->fetch($socid);
  98. $title = $langs->trans("Agenda");
  99. if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) {
  100. $title = $object->name." - ".$title;
  101. }
  102. llxHeader('', $title);
  103. if (isModEnabled('notification')) {
  104. $langs->load("mails");
  105. }
  106. $head = societe_prepare_head($object);
  107. print dol_get_fiche_head($head, 'agenda', $langs->trans("ThirdParty"), -1, 'company');
  108. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  109. dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
  110. print '<div class="fichecenter">';
  111. print '<div class="underbanner clearboth"></div>';
  112. $object->info($socid);
  113. dol_print_object_info($object, 1);
  114. print '</div>';
  115. print dol_get_fiche_end();
  116. // Actions buttons
  117. $objthirdparty = $object;
  118. $objcon = new stdClass();
  119. $out = '';
  120. $permok = $user->hasRight('agenda', 'myactions', 'create');
  121. if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) {
  122. if (is_object($objthirdparty) && get_class($objthirdparty) == 'Societe') {
  123. $out .= '&amp;originid='.$objthirdparty->id.($objthirdparty->id > 0 ? '&amp;socid='.$objthirdparty->id : '').'&amp;backtopage='.urlencode($_SERVER['PHP_SELF'].($objthirdparty->id > 0 ? '?socid='.$objthirdparty->id : ''));
  124. }
  125. $out .= (!empty($objcon->id) ? '&amp;contactid='.$objcon->id : '');
  126. $out .= '&amp;datep='.dol_print_date(dol_now(), 'dayhourlog');
  127. }
  128. $morehtmlright = '';
  129. $messagingUrl = DOL_URL_ROOT.'/societe/messaging.php?socid='.$object->id;
  130. $morehtmlright .= dolGetButtonTitle($langs->trans('ShowAsConversation'), '', 'fa fa-comments imgforviewmode', $messagingUrl, '', 2);
  131. $messagingUrl = DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id;
  132. $morehtmlright .= dolGetButtonTitle($langs->trans('MessageListViewType'), '', 'fa fa-bars imgforviewmode', $messagingUrl, '', 1);
  133. // // Show link to send an email (if read and not closed)
  134. // $btnstatus = $object->status < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage";
  135. // $url = 'card.php?track_id='.$object->track_id.'&action=presend_addmessage&mode=init&private_message=0&send_email=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?track_id='.$object->track_id).'#formmailbeforetitle';
  136. // $morehtmlright .= dolGetButtonTitle($langs->trans('SendMail'), '', 'fa fa-paper-plane', $url, 'email-title-button', $btnstatus);
  137. // // Show link to add a private message (if read and not closed)
  138. // $btnstatus = $object->status < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage";
  139. // $url = 'card.php?track_id='.$object->track_id.'&action=presend_addmessage&mode=init&backtopage='.urlencode($_SERVER["PHP_SELF"].'?track_id='.$object->track_id).'#formmailbeforetitle';
  140. // $morehtmlright .= dolGetButtonTitle($langs->trans('TicketAddMessage'), '', 'fa fa-comment-dots', $url, 'add-new-ticket-title-button', $btnstatus);
  141. if (isModEnabled('agenda')) {
  142. if ($user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create')) {
  143. $morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out);
  144. }
  145. }
  146. if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
  147. print '<br>';
  148. $param = '&socid='.urlencode($socid);
  149. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  150. $param .= '&contextpage='.urlencode($contextpage);
  151. }
  152. if ($limit > 0 && $limit != $conf->liste_limit) {
  153. $param .= '&limit='.((int) $limit);
  154. }
  155. // Try to know count of actioncomm from cache
  156. require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
  157. $cachekey = 'count_events_thirdparty_'.$object->id;
  158. $nbEvent = dol_getcache($cachekey);
  159. // print load_fiche_titre($langs->trans("ActionsOnCompany"), $newcardbutton, '');
  160. print_barre_liste($langs->trans("ActionsOnCompany").(is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">('.$nbEvent.')</span>' : ''), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $morehtmlright, '', 0, 1, 0);
  161. // List of all actions
  162. $filters = array();
  163. $filters['search_agenda_label'] = $search_agenda_label;
  164. $filters['search_rowid'] = $search_rowid;
  165. // TODO Replace this with same code than into list.php
  166. show_actions_messaging($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder);
  167. }
  168. }
  169. // End of page
  170. llxFooter();
  171. $db->close();