messaging.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  35. // Load translation files required by the page
  36. $langs->loadLangs(array('agenda', 'bills', 'companies', 'orders', 'propal'));
  37. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'thirdpartyagenda';
  38. if (GETPOST('actioncode', 'array')) {
  39. $actioncode = GETPOST('actioncode', 'array', 3);
  40. if (!count($actioncode)) {
  41. $actioncode = '0';
  42. }
  43. } else {
  44. $actioncode = GETPOST("actioncode", "alpha", 3) ? GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT'));
  45. }
  46. $search_rowid = GETPOST('search_rowid');
  47. $search_agenda_label = GETPOST('search_agenda_label');
  48. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  49. $sortfield = GETPOST('sortfield', 'aZ09comma');
  50. $sortorder = GETPOST('sortorder', 'aZ09comma');
  51. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  52. if (empty($page) || $page == -1) {
  53. $page = 0;
  54. } // If $page is not defined, or '' or -1
  55. $offset = $limit * $page;
  56. $pageprev = $page - 1;
  57. $pagenext = $page + 1;
  58. if (!$sortfield) {
  59. $sortfield = 'a.datep,a.id';
  60. }
  61. if (!$sortorder) {
  62. $sortorder = 'DESC,DESC';
  63. }
  64. // Initialize technical objects
  65. $object = new Societe($db);
  66. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  67. $hookmanager->initHooks(array('agendathirdparty', 'globalcard'));
  68. // Security check
  69. $socid = GETPOST('socid', 'int');
  70. if ($user->socid) {
  71. $socid = $user->socid;
  72. }
  73. $result = $object->fetch($socid);
  74. if ($result <= 0) {
  75. accessforbidden('Third party not found');
  76. }
  77. $result = restrictedArea($user, 'societe', $socid, '&societe');
  78. /*
  79. * Actions
  80. */
  81. $parameters = array('id'=>$socid);
  82. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  83. if ($reshook < 0) {
  84. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  85. }
  86. if (empty($reshook)) {
  87. // Cancel
  88. if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
  89. header("Location: ".$backtopage);
  90. exit;
  91. }
  92. // Purge search criteria
  93. 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
  94. $actioncode = '';
  95. $search_agenda_label = '';
  96. }
  97. }
  98. /*
  99. * View
  100. */
  101. $form = new Form($db);
  102. $title = $langs->trans("Agenda");
  103. if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) {
  104. $title = $object->name." - ".$title;
  105. }
  106. llxHeader('', $title);
  107. if (isModEnabled('notification')) {
  108. $langs->load("mails");
  109. }
  110. $head = societe_prepare_head($object);
  111. print dol_get_fiche_head($head, 'agenda', $langs->trans("ThirdParty"), -1, $object->picto);
  112. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  113. $morehtmlref = '';
  114. dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom', $morehtmlref);
  115. print '<div class="fichecenter">';
  116. print '<div class="underbanner clearboth"></div>';
  117. $object->info($socid);
  118. dol_print_object_info($object, 1);
  119. print '</div>';
  120. print dol_get_fiche_end();
  121. // Actions buttons
  122. $objthirdparty = $object;
  123. $objcon = new stdClass();
  124. $out = '';
  125. $permok = $user->hasRight('agenda', 'myactions', 'create');
  126. if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) {
  127. if (is_object($objthirdparty) && get_class($objthirdparty) == 'Societe') {
  128. $out .= '&amp;originid='.$objthirdparty->id.($objthirdparty->id > 0 ? '&amp;socid='.$objthirdparty->id : '').'&amp;backtopage='.urlencode($_SERVER['PHP_SELF'].($objthirdparty->id > 0 ? '?socid='.$objthirdparty->id : ''));
  129. }
  130. $out .= (!empty($objcon->id) ? '&amp;contactid='.$objcon->id : '');
  131. $out .= '&amp;datep='.dol_print_date(dol_now(), 'dayhourlog', 'tzuserrel');
  132. }
  133. $morehtmlright = '';
  134. $messagingUrl = DOL_URL_ROOT.'/societe/messaging.php?socid='.$object->id;
  135. $morehtmlright .= dolGetButtonTitle($langs->trans('ShowAsConversation'), '', 'fa fa-comments imgforviewmode', $messagingUrl, '', 2);
  136. $messagingUrl = DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id;
  137. $morehtmlright .= dolGetButtonTitle($langs->trans('MessageListViewType'), '', 'fa fa-bars imgforviewmode', $messagingUrl, '', 1);
  138. // // Show link to send an email (if read and not closed)
  139. // $btnstatus = $object->status < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage";
  140. // $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';
  141. // $morehtmlright .= dolGetButtonTitle($langs->trans('SendMail'), '', 'fa fa-paper-plane', $url, 'email-title-button', $btnstatus);
  142. // // Show link to add a private message (if read and not closed)
  143. // $btnstatus = $object->status < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage";
  144. // $url = 'card.php?track_id='.$object->track_id.'&action=presend_addmessage&mode=init&backtopage='.urlencode($_SERVER["PHP_SELF"].'?track_id='.$object->track_id).'#formmailbeforetitle';
  145. // $morehtmlright .= dolGetButtonTitle($langs->trans('TicketAddMessage'), '', 'fa fa-comment-dots', $url, 'add-new-ticket-title-button', $btnstatus);
  146. if (isModEnabled('agenda')) {
  147. if ($user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create')) {
  148. $morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out);
  149. }
  150. }
  151. if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
  152. print '<br>';
  153. $param = '&socid='.urlencode($socid);
  154. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  155. $param .= '&contextpage='.urlencode($contextpage);
  156. }
  157. if ($limit > 0 && $limit != $conf->liste_limit) {
  158. $param .= '&limit='.((int) $limit);
  159. }
  160. // Try to know count of actioncomm from cache
  161. require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
  162. $cachekey = 'count_events_thirdparty_'.$object->id;
  163. $nbEvent = dol_getcache($cachekey);
  164. $titlelist = $langs->trans("ActionsOnCompany").(is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">('.$nbEvent.')</span>' : '');
  165. if (!empty($conf->dol_optimize_smallscreen)) {
  166. $titlelist = $langs->trans("Actions").(is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">('.$nbEvent.')</span>' : '');
  167. }
  168. print_barre_liste($titlelist, 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $morehtmlright, '', 0, 1, 0);
  169. // List of all actions
  170. $filters = array();
  171. $filters['search_agenda_label'] = $search_agenda_label;
  172. $filters['search_rowid'] = $search_rowid;
  173. // TODO Replace this with same code than into list.php
  174. show_actions_messaging($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder);
  175. }
  176. // End of page
  177. llxFooter();
  178. $db->close();