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