dolibarr 21.0.0-beta
agenda.php
Go to the documentation of this file.
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-2024 Frédéric France <frederic.france@free.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
28// Load Dolibarr environment
29require '../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
32
41if (!$user->admin) {
43}
44
45// Load translation files required by the page
46$langs->loadLangs(array('admin', 'other', 'agenda'));
47
48$action = GETPOST('action', 'aZ09');
49$cancel = GETPOST('cancel', 'alpha');
50
51$search_event = GETPOST('search_event', 'alpha');
52
53// Get list of triggers available
54$triggers = array();
55$sql = "SELECT a.rowid, a.code, a.label, a.elementtype, a.rang as position";
56$sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a";
57$sql .= " ORDER BY a.rang ASC";
58$resql = $db->query($sql);
59if ($resql) {
60 $num = $db->num_rows($resql);
61 $i = 0;
62 while ($i < $num) {
63 $obj = $db->fetch_object($resql);
64 $triggers[$i]['rowid'] = $obj->rowid;
65 $triggers[$i]['code'] = $obj->code;
66 $triggers[$i]['element'] = $obj->elementtype;
67 $triggers[$i]['label'] = ($langs->trans("Notify_".$obj->code) != "Notify_".$obj->code ? $langs->trans("Notify_".$obj->code) : $obj->label);
68 $triggers[$i]['position'] = $obj->position;
69
70 $i++;
71 }
72 $db->free($resql);
73} else {
74 dol_print_error($db);
75}
76
77//$triggers = dol_sort_array($triggers, 'code', 'asc', 0, 0, 1);
78
79
80/*
81 * Actions
82 */
83$error = 0;
84
85// Purge search criteria
86if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
87 $search_event = '';
88 $action = '';
89}
90
91if (GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) { // To avoid the save when we click on search
92 $action = '';
93}
94
95if ($action == "save" && empty($cancel)) {
96 $i = 0;
97
98 $db->begin();
99
100 foreach ($triggers as $trigger) {
101 $keyparam = 'MAIN_AGENDA_ACTIONAUTO_'.$trigger['code'];
102 if ($search_event === '' || preg_match('/'.preg_quote($search_event, '/').'/i', $keyparam)) {
103 $res = dolibarr_set_const($db, $keyparam, (GETPOST($keyparam, 'alpha') ? GETPOST($keyparam, 'alpha') : ''), 'chaine', 0, '', $conf->entity);
104 if (!($res > 0)) {
105 $error++;
106 }
107 }
108 }
109
110 if (!$error) {
111 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
112 $db->commit();
113 } else {
114 setEventMessages($langs->trans("Error"), null, 'errors');
115 $db->rollback();
116 }
117}
118
119
120
125$form = new Form($db);
126
127$title = $langs->trans("AgendaSetup");
128$help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda|DE:Modul_Terminplanung';
129
130llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-admin page-agenda');
131
132$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
133print load_fiche_titre($langs->trans("AgendaSetup"), $linkback, 'title_setup');
134
135print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
136print '<input type="hidden" name="token" value="'.newToken().'">';
137print '<input type="hidden" name="action" value="save">';
138
139$param = '';
140$param .= '&search_event='.urlencode($search_event);
141
142$head = agenda_prepare_head();
143
144print dol_get_fiche_head($head, 'autoactions', $langs->trans("Agenda"), -1, 'action');
145
146print '<span class="opacitymedium">'.$langs->trans("AgendaAutoActionDesc")." ".$langs->trans("OnlyActiveElementsAreShown", 'modules.php').'</span><br>';
147print "<br>\n";
148
149print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
150print '<table class="noborder centpercent">';
151print '<tr class="liste_titre">';
152print '<td class="liste_titre"><input type="text" name="search_event" value="'.dol_escape_htmltag($search_event).'"></td>';
153print '<td class="liste_titre"></td>';
154// Action column
155print '<td class="liste_titre maxwidthsearch">';
156$searchpicto = $form->showFilterButtons();
157print $searchpicto;
158print '</td>';
159print '</tr>';
160print '</tr>'."\n";
161
162print '<tr class="liste_titre">';
163print '<th class="liste_titre" colspan="2">'.$langs->trans("ActionsEvents").'</th>';
164print '<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>';
165print '</tr>'."\n";
166// Show each trigger (list is in c_action_trigger)
167if (!empty($triggers)) {
168 foreach ($triggers as $trigger) {
169 $module = $trigger['element'];
170 if ($module == 'order_supplier' || $module == 'invoice_supplier') {
171 $module = 'fournisseur';
172 }
173 if ($module == 'shipping') {
174 $module = 'expedition';
175 }
176 if ($module == 'member') {
177 $module = 'adherent';
178 }
179 if ($module == 'project') {
180 $module = 'projet';
181 }
182 if ($module == 'proposal_supplier') {
183 $module = 'supplier_proposal';
184 }
185 if ($module == 'contact') {
186 $module = 'societe';
187 }
188 if ($module == 'facturerec') {
189 $module = 'facture';
190 }
191
192 // If 'element' value is myobject@mymodule instead of mymodule
193 $tmparray = explode('@', $module);
194 if (!empty($tmparray[1])) {
195 $module = $tmparray[1];
196 }
197
198 //print 'module='.$module.' code='.$trigger['code'].'<br>';
199 if (isModEnabled($module)) {
200 // Discard special case: If option FICHINTER_CLASSIFY_BILLED is not set, we discard both trigger FICHINTER_CLASSIFY_BILLED and FICHINTER_CLASSIFY_UNBILLED
201 if ($trigger['code'] == 'FICHINTER_CLASSIFY_BILLED' && !getDolGlobalString('FICHINTER_CLASSIFY_BILLED')) {
202 continue;
203 }
204 if ($trigger['code'] == 'FICHINTER_CLASSIFY_UNBILLED' && !getDolGlobalString('FICHINTER_CLASSIFY_BILLED')) {
205 continue;
206 }
207 if ($trigger['code'] == 'ACTION_CREATE') {
208 // This is the trigger to add an event, enabling it will create infinite loop
209 continue;
210 }
211
212 if ($search_event === '' || preg_match('/'.preg_quote($search_event, '/').'/i', $trigger['code'])) {
213 print '<!-- '.$trigger['position'].' -->';
214 print '<tr class="oddeven">';
215 print '<td>'.$trigger['code'].'</td>';
216 print '<td>'.$trigger['label'].'</td>';
217 print '<td class="right" width="40">';
218 $key = 'MAIN_AGENDA_ACTIONAUTO_'.$trigger['code'];
219 $value = getDolGlobalInt($key);
220 print '<input class="oddeven" type="checkbox" name="'.$key.'" value="1"'.((($action == 'selectall' || $value) && $action != "selectnone") ? ' checked' : '').'>';
221 print '</td></tr>'."\n";
222 }
223 }
224 }
225}
226print '</table>';
227print '</div>';
228
229print dol_get_fiche_end();
230
231print $form->buttonsSaveCancel("Save", '');
232
233print "</form>\n";
234
235
236print "<br>";
237
238// End of page
239llxFooter();
240$db->close();
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
agenda_prepare_head()
Prepare array with list of tabs.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class to manage generation of HTML components Only common components must be here.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.