dolibarr 23.0.3
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="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
133
134print load_fiche_titre($langs->trans("AgendaSetup"), $linkback, 'title_setup');
135
136print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
137print '<input type="hidden" name="token" value="'.newToken().'">';
138print '<input type="hidden" name="action" value="save">';
139
140$param = '';
141$param .= '&search_event='.urlencode($search_event);
142
143$head = agenda_prepare_head();
144
145print dol_get_fiche_head($head, 'autoactions', $langs->trans("Agenda"), -1, 'action');
146
147print '<span class="opacitymedium">'.$langs->trans("AgendaAutoActionDesc")." ".$langs->trans("OnlyActiveElementsAreShown", 'modules.php').'</span><br>';
148print "<br>\n";
149
150print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
151print '<table class="noborder centpercent">';
152print '<tr class="liste_titre">';
153print '<td class="liste_titre"><input type="text" name="search_event" value="'.dol_escape_htmltag($search_event).'"></td>';
154print '<td class="liste_titre"></td>';
155// Action column
156print '<td class="liste_titre maxwidthsearch">';
157$searchpicto = $form->showFilterButtons();
158print $searchpicto;
159print '</td>';
160print '</tr>';
161print '</tr>'."\n";
162
163print '<tr class="liste_titre">';
164print '<th class="liste_titre" colspan="2">'.$langs->trans("ActionsEvents").'</th>';
165print '<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>';
166print '</tr>'."\n";
167// Show each trigger (list is in c_action_trigger)
168if (!empty($triggers)) {
169 foreach ($triggers as $trigger) {
170 $module = $trigger['element'];
171 if ($module == 'order_supplier' || $module == 'invoice_supplier') {
172 $module = 'fournisseur';
173 }
174 if ($module == 'shipping') {
175 $module = 'expedition';
176 }
177 if ($module == 'member') {
178 $module = 'adherent';
179 }
180 if ($module == 'project') {
181 $module = 'projet';
182 }
183 if ($module == 'proposal_supplier') {
184 $module = 'supplier_proposal';
185 }
186 if ($module == 'contact') {
187 $module = 'societe';
188 }
189 if ($module == 'facturerec') {
190 $module = 'facture';
191 }
192
193 // If 'element' value is myobject@mymodule instead of mymodule
194 $tmparray = explode('@', $module);
195 if (!empty($tmparray[1])) {
196 $module = $tmparray[1];
197 }
198
199 //print 'module='.$module.' code='.$trigger['code'].'<br>';
200 if (isModEnabled($module)) {
201 // Discard special case: If option FICHINTER_CLASSIFY_BILLED is not set, we discard both trigger FICHINTER_CLASSIFY_BILLED and FICHINTER_CLASSIFY_UNBILLED
202 if ($trigger['code'] == 'FICHINTER_CLASSIFY_BILLED' && !getDolGlobalString('FICHINTER_CLASSIFY_BILLED')) {
203 continue;
204 }
205 if ($trigger['code'] == 'FICHINTER_CLASSIFY_UNBILLED' && !getDolGlobalString('FICHINTER_CLASSIFY_BILLED')) {
206 continue;
207 }
208 if ($trigger['code'] == 'ACTION_CREATE') {
209 // This is the trigger to add an event, enabling it will create infinite loop
210 continue;
211 }
212
213 if ($search_event === '' || preg_match('/'.preg_quote($search_event, '/').'/i', $trigger['code'])) {
214 print '<!-- '.$trigger['position'].' -->';
215 print '<tr class="oddeven">';
216 print '<td>'.$trigger['code'].'</td>';
217 print '<td>'.$trigger['label'].'</td>';
218 print '<td class="right" width="40">';
219 $key = 'MAIN_AGENDA_ACTIONAUTO_'.$trigger['code'];
220 $value = getDolGlobalInt($key);
221 print '<input class="oddeven" type="checkbox" name="'.$key.'" value="1"'.((($action == 'selectall' || $value) && $action != "selectnone") ? ' checked' : '').'>';
222 print '</td></tr>'."\n";
223 }
224 }
225 }
226}
227print '</table>';
228print '</div>';
229
230print dol_get_fiche_end();
231
232print $form->buttonsSaveCancel("Save", '');
233
234print "</form>\n";
235
236
237print "<br>";
238
239// End of page
240llxFooter();
241$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.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
Class to manage generation of HTML components Only common components must be here.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.