agenda.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/admin/agenda.php
  22. * \ingroup agenda
  23. * \brief Autocreate actions for agenda module setup page
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
  28. if (!$user->admin)
  29. accessforbidden();
  30. // Load translation files required by the page
  31. $langs->loadLangs(array('admin', 'other', 'agenda'));
  32. $action = GETPOST('action','alpha');
  33. $cancel = GETPOST('cancel','alpha');
  34. $search_event = GETPOST('search_event', 'alpha');
  35. // Get list of triggers available
  36. $sql = "SELECT a.rowid, a.code, a.label, a.elementtype";
  37. $sql.= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a";
  38. $sql.= " ORDER BY a.rang ASC";
  39. $resql=$db->query($sql);
  40. if ($resql)
  41. {
  42. $num = $db->num_rows($resql);
  43. $i = 0;
  44. while ($i < $num)
  45. {
  46. $obj = $db->fetch_object($resql);
  47. $triggers[$i]['rowid'] = $obj->rowid;
  48. $triggers[$i]['code'] = $obj->code;
  49. $triggers[$i]['element'] = $obj->elementtype;
  50. $triggers[$i]['label'] = ($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label);
  51. $i++;
  52. }
  53. $db->free($resql);
  54. }
  55. else
  56. {
  57. dol_print_error($db);
  58. }
  59. /*
  60. * Actions
  61. */
  62. // Purge search criteria
  63. 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
  64. {
  65. $search_event = '';
  66. $action = '';
  67. }
  68. if (GETPOST('button_search_x','alpha') || GETPOST('button_search.x','alpha') ||GETPOST('button_search','alpha')) // To avoid the save when we click on search
  69. {
  70. $action = '';
  71. }
  72. if ($action == "save" && empty($cancel))
  73. {
  74. $i=0;
  75. $db->begin();
  76. foreach ($triggers as $trigger)
  77. {
  78. $keyparam='MAIN_AGENDA_ACTIONAUTO_'.$trigger['code'];
  79. //print "param=".$param." - ".$_POST[$param];
  80. if ($search_event === '' || preg_match('/'.preg_quote($search_event,'/').'/i', $keyparam))
  81. {
  82. $res = dolibarr_set_const($db,$keyparam,(GETPOST($keyparam,'alpha')?GETPOST($keyparam,'alpha'):''),'chaine',0,'',$conf->entity);
  83. if (! $res > 0) $error++;
  84. }
  85. }
  86. if (! $error)
  87. {
  88. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  89. $db->commit();
  90. }
  91. else
  92. {
  93. setEventMessages($langs->trans("Error"),null, 'errors');
  94. $db->rollback();
  95. }
  96. }
  97. /**
  98. * View
  99. */
  100. $wikihelp='EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda';
  101. llxHeader('', $langs->trans("AgendaSetup"), $wikihelp);
  102. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  103. print load_fiche_titre($langs->trans("AgendaSetup"),$linkback,'title_setup');
  104. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  105. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  106. print '<input type="hidden" name="action" value="save">';
  107. $param = '';
  108. $param.= '&search_event='.urlencode($search_event);
  109. $head=agenda_prepare_head();
  110. dol_fiche_head($head, 'autoactions', $langs->trans("Agenda"), -1, 'action');
  111. print $langs->trans("AgendaAutoActionDesc")."<br>\n";
  112. print $langs->trans("OnlyActiveElementsAreShown", 'modules.php').'<br>';
  113. print "<br>\n";
  114. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  115. print '<table class="noborder" width="100%">';
  116. print '<tr class="liste_titre">';
  117. print '<td class="liste_titre"><input type="text" name="search_event" value="'.dol_escape_htmltag($search_event).'"></td>';
  118. print '<td class="liste_titre"></td>';
  119. // Action column
  120. print '<td class="liste_titre" align="right">';
  121. $searchpicto=$form->showFilterButtons();
  122. print $searchpicto;
  123. print '</td>';
  124. print '</tr>';
  125. print '</tr>'."\n";
  126. print '<tr class="liste_titre">';
  127. print '<th class="liste_titre" colspan="2">'.$langs->trans("ActionsEvents").'</th>';
  128. 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>';
  129. print '</tr>'."\n";
  130. // Show each trigger (list is in c_action_trigger)
  131. if (! empty($triggers))
  132. {
  133. foreach ($triggers as $trigger)
  134. {
  135. $module = $trigger['element'];
  136. if ($module == 'order_supplier' || $module == 'invoice_supplier') $module = 'fournisseur';
  137. if ($module == 'shipping') $module = 'expedition_bon';
  138. if ($module == 'member') $module = 'adherent';
  139. if ($module == 'project') $module = 'projet';
  140. if ($module == 'proposal_supplier') $module = 'supplier_proposal';
  141. //print 'module='.$module.'<br>';
  142. if (! empty($conf->$module->enabled))
  143. {
  144. // Discard special case: If option FICHINTER_CLASSIFY_BILLED is not set, we discard both trigger FICHINTER_CLASSIFY_BILLED and FICHINTER_CLASSIFY_UNBILLED
  145. if ($trigger['code'] == 'FICHINTER_CLASSIFY_BILLED' && empty($conf->global->FICHINTER_CLASSIFY_BILLED)) continue;
  146. if ($trigger['code'] == 'FICHINTER_CLASSIFY_UNBILLED' && empty($conf->global->FICHINTER_CLASSIFY_BILLED)) continue;
  147. if ($search_event === '' || preg_match('/'.preg_quote($search_event,'/').'/i', $trigger['code']))
  148. {
  149. print '<tr class="oddeven">';
  150. print '<td>'.$trigger['code'].'</td>';
  151. print '<td>'.$trigger['label'].'</td>';
  152. print '<td align="right" width="40">';
  153. $key='MAIN_AGENDA_ACTIONAUTO_'.$trigger['code'];
  154. $value=$conf->global->$key;
  155. print '<input class="oddeven" type="checkbox" name="'.$key.'" value="1"'.((($action=='selectall'||$value) && $action!="selectnone")?' checked':'').'>';
  156. print '</td></tr>'."\n";
  157. }
  158. }
  159. }
  160. }
  161. print '</table>';
  162. print '</div>';
  163. dol_fiche_end();
  164. print '<div class="center">';
  165. print '<input type="submit" name="save" class="button" value="'.$langs->trans("Save").'">';
  166. print "</div>";
  167. print "</form>\n";
  168. print "<br>";
  169. // End of page
  170. llxFooter();
  171. $db->close();