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