agenda.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. /* Copyright (C) 2008-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2011 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es>
  5. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  6. * Copyright (C) 2022 Frédéric France <frederic.france@netlogic.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/admin/agenda.php
  23. * \ingroup agenda
  24. * \brief Autocreate actions for agenda module setup page
  25. */
  26. // Load Dolibarr environment
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
  30. if (!$user->admin) {
  31. accessforbidden();
  32. }
  33. // Load translation files required by the page
  34. $langs->loadLangs(array('admin', 'other', 'agenda'));
  35. $action = GETPOST('action', 'aZ09');
  36. $cancel = GETPOST('cancel', 'alpha');
  37. $search_event = GETPOST('search_event', 'alpha');
  38. // Get list of triggers available
  39. $triggers = array();
  40. $sql = "SELECT a.rowid, a.code, a.label, a.elementtype, a.rang as position";
  41. $sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a";
  42. $sql .= " ORDER BY a.rang ASC";
  43. $resql = $db->query($sql);
  44. if ($resql) {
  45. $num = $db->num_rows($resql);
  46. $i = 0;
  47. while ($i < $num) {
  48. $obj = $db->fetch_object($resql);
  49. $triggers[$i]['rowid'] = $obj->rowid;
  50. $triggers[$i]['code'] = $obj->code;
  51. $triggers[$i]['element'] = $obj->elementtype;
  52. $triggers[$i]['label'] = ($langs->trans("Notify_".$obj->code) != "Notify_".$obj->code ? $langs->trans("Notify_".$obj->code) : $obj->label);
  53. $triggers[$i]['position'] = $obj->position;
  54. $i++;
  55. }
  56. $db->free($resql);
  57. } else {
  58. dol_print_error($db);
  59. }
  60. //$triggers = dol_sort_array($triggers, 'code', 'asc', 0, 0, 1);
  61. /*
  62. * Actions
  63. */
  64. // Purge search criteria
  65. 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
  66. $search_event = '';
  67. $action = '';
  68. }
  69. if (GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) { // To avoid the save when we click on search
  70. $action = '';
  71. }
  72. if ($action == "save" && empty($cancel)) {
  73. $i = 0;
  74. $db->begin();
  75. foreach ($triggers as $trigger) {
  76. $keyparam = 'MAIN_AGENDA_ACTIONAUTO_'.$trigger['code'];
  77. if ($search_event === '' || preg_match('/'.preg_quote($search_event, '/').'/i', $keyparam)) {
  78. $res = dolibarr_set_const($db, $keyparam, (GETPOST($keyparam, 'alpha') ?GETPOST($keyparam, 'alpha') : ''), 'chaine', 0, '', $conf->entity);
  79. if (!($res > 0)) {
  80. $error++;
  81. }
  82. }
  83. }
  84. if (!$error) {
  85. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  86. $db->commit();
  87. } else {
  88. setEventMessages($langs->trans("Error"), null, 'errors');
  89. $db->rollback();
  90. }
  91. }
  92. /**
  93. * View
  94. */
  95. // $wikihelp = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda';
  96. $help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda|DE:Modul_Terminplanung';
  97. llxHeader('', $langs->trans("AgendaSetup"), $help_url);
  98. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  99. print load_fiche_titre($langs->trans("AgendaSetup"), $linkback, 'title_setup');
  100. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  101. print '<input type="hidden" name="token" value="'.newToken().'">';
  102. print '<input type="hidden" name="action" value="save">';
  103. $param = '';
  104. $param .= '&search_event='.urlencode($search_event);
  105. $head = agenda_prepare_head();
  106. print dol_get_fiche_head($head, 'autoactions', $langs->trans("Agenda"), -1, 'action');
  107. print '<span class="opacitymedium">'.$langs->trans("AgendaAutoActionDesc")." ".$langs->trans("OnlyActiveElementsAreShown", 'modules.php').'</span><br>';
  108. print "<br>\n";
  109. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  110. print '<table class="noborder centpercent">';
  111. print '<tr class="liste_titre">';
  112. print '<td class="liste_titre"><input type="text" name="search_event" value="'.dol_escape_htmltag($search_event).'"></td>';
  113. print '<td class="liste_titre"></td>';
  114. // Action column
  115. print '<td class="liste_titre maxwidthsearch">';
  116. $searchpicto = $form->showFilterButtons();
  117. print $searchpicto;
  118. print '</td>';
  119. print '</tr>';
  120. print '</tr>'."\n";
  121. print '<tr class="liste_titre">';
  122. print '<th class="liste_titre" colspan="2">'.$langs->trans("ActionsEvents").'</th>';
  123. print '<th class="liste_titre"><a href="'.$_SERVER["PHP_SELF"].'?action=selectall'.($param ? $param : '').'">'.$langs->trans("All").'</a>/<a href="'.$_SERVER["PHP_SELF"].'?action=selectnone'.($param ? $param : '').'">'.$langs->trans("None").'</a></th>';
  124. print '</tr>'."\n";
  125. // Show each trigger (list is in c_action_trigger)
  126. if (!empty($triggers)) {
  127. foreach ($triggers as $trigger) {
  128. $module = $trigger['element'];
  129. if ($module == 'order_supplier' || $module == 'invoice_supplier') {
  130. $module = 'fournisseur';
  131. }
  132. if ($module == 'shipping') {
  133. $module = 'expedition';
  134. }
  135. if ($module == 'member') {
  136. $module = 'adherent';
  137. }
  138. if ($module == 'project') {
  139. $module = 'projet';
  140. }
  141. if ($module == 'proposal_supplier') {
  142. $module = 'supplier_proposal';
  143. }
  144. if ($module == 'contact') {
  145. $module = 'societe';
  146. }
  147. if ($module == 'facturerec') {
  148. $module = 'facture';
  149. }
  150. // If 'element' value is myobject@mymodule instead of mymodule
  151. $tmparray = explode('@', $module);
  152. if (!empty($tmparray[1])) {
  153. $module = $tmparray[1];
  154. }
  155. //print 'module='.$module.' code='.$trigger['code'].'<br>';
  156. if (isModEnabled($module)) {
  157. // Discard special case: If option FICHINTER_CLASSIFY_BILLED is not set, we discard both trigger FICHINTER_CLASSIFY_BILLED and FICHINTER_CLASSIFY_UNBILLED
  158. if ($trigger['code'] == 'FICHINTER_CLASSIFY_BILLED' && empty($conf->global->FICHINTER_CLASSIFY_BILLED)) {
  159. continue;
  160. }
  161. if ($trigger['code'] == 'FICHINTER_CLASSIFY_UNBILLED' && empty($conf->global->FICHINTER_CLASSIFY_BILLED)) {
  162. continue;
  163. }
  164. if ($trigger['code'] == 'ACTION_CREATE') {
  165. // This is the trigger to add an event, enabling it will create infinite loop
  166. continue;
  167. }
  168. if ($search_event === '' || preg_match('/'.preg_quote($search_event, '/').'/i', $trigger['code'])) {
  169. print '<!-- '.$trigger['position'].' -->';
  170. print '<tr class="oddeven">';
  171. print '<td>'.$trigger['code'].'</td>';
  172. print '<td>'.$trigger['label'].'</td>';
  173. print '<td class="right" width="40">';
  174. $key = 'MAIN_AGENDA_ACTIONAUTO_'.$trigger['code'];
  175. $value = getDolGlobalInt($key);
  176. print '<input class="oddeven" type="checkbox" name="'.$key.'" value="1"'.((($action == 'selectall' || $value) && $action != "selectnone") ? ' checked' : '').'>';
  177. print '</td></tr>'."\n";
  178. }
  179. }
  180. }
  181. }
  182. print '</table>';
  183. print '</div>';
  184. print dol_get_fiche_end();
  185. print $form->buttonsSaveCancel("Save", '');
  186. print "</form>\n";
  187. print "<br>";
  188. // End of page
  189. llxFooter();
  190. $db->close();