dolibarr 18.0.6
agenda_other.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2008-2016 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2011 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2011-2017 Juanjo Menent <jmenent@2byte.es>
5 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
6 * Copyright (C) 2016 Charlie Benke <charlie@patas-monkey.com>
7 * Copyright (C) 2017 Open-DSI <support@open-dsi.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/defaultvalues.class.php';
35
36if (!$user->admin) {
38}
39
40// Load translation files required by the page
41$langs->loadLangs(array('admin', 'other', 'agenda', 'users'));
42
43$action = GETPOST('action', 'aZ09');
44$value = GETPOST('value', 'alpha');
45$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
46
47$param = GETPOST('param', 'alpha');
48$cancel = GETPOST('cancel', 'alpha');
49$scandir = GETPOST('scan_dir', 'alpha');
50$type = 'action';
51
52
53/*
54 * Actions
55 */
56
57$error = 0;
58$errors = array();
59
60include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
61
62$reg = array();
63if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) {
64 $code = $reg[1];
65 $value = (GETPOST($code, 'alpha') ? GETPOST($code, 'alpha') : 1);
66 if (dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity) > 0) {
67 Header("Location: ".$_SERVER["PHP_SELF"]);
68 exit;
69 } else {
70 dol_print_error($db);
71 }
72}
73
74if (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) {
75 $code = $reg[1];
76 if (dolibarr_del_const($db, $code, $conf->entity) > 0) {
77 Header("Location: ".$_SERVER["PHP_SELF"]);
78 exit;
79 } else {
80 dol_print_error($db);
81 }
82}
83if ($action == 'set') {
84 $getDefaultFilter = GETPOST('AGENDA_DEFAULT_FILTER_TYPE');
85 $defaultfilter = (is_array($getDefaultFilter)) ? implode(',', $getDefaultFilter) : $getDefaultFilter;
86 dolibarr_set_const($db, 'AGENDA_USE_EVENT_TYPE_DEFAULT', GETPOST('AGENDA_USE_EVENT_TYPE_DEFAULT'), 'chaine', 0, '', $conf->entity);
87 dolibarr_set_const($db, 'AGENDA_DEFAULT_FILTER_TYPE', $defaultfilter, 'chaine', 0, '', $conf->entity);
88 dolibarr_set_const($db, 'AGENDA_DEFAULT_FILTER_STATUS', GETPOST('AGENDA_DEFAULT_FILTER_STATUS'), 'chaine', 0, '', $conf->entity);
89 dolibarr_set_const($db, 'AGENDA_DEFAULT_VIEW', GETPOST('AGENDA_DEFAULT_VIEW'), 'chaine', 0, '', $conf->entity);
90
91 $defaultValues = new DefaultValues($db);
92 $result = $defaultValues->fetchAll('', '', 0, 0, array('t.page'=>'comm/action/card.php', 't.param'=>'complete', 't.user_id'=>'0', 't.type'=>'createform', 't.entity'=>$conf->entity));
93 if (!is_array($result) && $result < 0) {
94 setEventMessages($defaultValues->error, $defaultValues->errors, 'errors');
95 } elseif (count($result) > 0) {
96 foreach ($result as $defval) {
97 $defaultValues->id = $defval->id;
98 $resultDel = $defaultValues->delete($user);
99 if ($resultDel < 0) {
100 setEventMessages($defaultValues->error, $defaultValues->errors, 'errors');
101 }
102 }
103 }
104 $defaultValues->type = 'createform';
105 $defaultValues->entity = $conf->entity;
106 $defaultValues->user_id = 0;
107 $defaultValues->page = 'comm/action/card.php';
108 $defaultValues->param = 'complete';
109 $defaultValues->value = GETPOST('AGENDA_EVENT_DEFAULT_STATUS');
110 $resultCreat = $defaultValues->create($user);
111 if ($resultCreat < 0) {
112 setEventMessages($defaultValues->error, $defaultValues->errors, 'errors');
113 } else {
114 setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
115 }
116} elseif ($action == 'specimen') { // For orders
117 $modele = GETPOST('module', 'alpha');
118
119 $commande = new CommandeFournisseur($db);
120 $commande->initAsSpecimen();
121 $commande->thirdparty = $specimenthirdparty;
122
123 // Search template files
124 $file = ''; $classname = ''; $filefound = 0;
125 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
126 foreach ($dirmodels as $reldir) {
127 $file = dol_buildpath($reldir."core/modules/action/doc/pdf_".$modele.".modules.php", 0);
128 if (file_exists($file)) {
129 $filefound = 1;
130 $classname = "pdf_".$modele;
131 break;
132 }
133 }
134
135 if ($filefound) {
136 require_once $file;
137
138 $module = new $classname($db, $commande);
139
140 if ($module->write_file($commande, $langs) > 0) {
141 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=action&file=SPECIMEN.pdf");
142 return;
143 } else {
144 setEventMessages($module->error, $module->errors, 'errors');
145 dol_syslog($module->error, LOG_ERR);
146 }
147 } else {
148 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
149 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
150 }
151} elseif ($action == 'setmodel') {
152 // Activate a model
153 //print "sssd".$value;
154 $ret = addDocumentModel($value, $type, $label, $scandir);
155} elseif ($action == 'del') {
156 $ret = delDocumentModel($value, $type);
157 if ($ret > 0) {
158 if ($conf->global->ACTION_EVENT_ADDON_PDF == "$value") {
159 dolibarr_del_const($db, 'ACTION_EVENT_ADDON_PDF', $conf->entity);
160 }
161 }
162} elseif ($action == 'setdoc') {
163 // Set default model
164 if (dolibarr_set_const($db, "ACTION_EVENT_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
165 // La constante qui a ete lue en avant du nouveau set
166 // on passe donc par une variable pour avoir un affichage coherent
167 $conf->global->ACTION_EVENT_ADDON_PDF = $value;
168 }
169
170 // On active le modele
171 $ret = delDocumentModel($value, $type);
172 if ($ret > 0) {
173 $ret = addDocumentModel($value, $type, $label, $scandir);
174 }
175}
176
177
183$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
184
185$wikihelp = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda|DE:Modul_Terminplanung';
186llxHeader('', $langs->trans("AgendaSetup"), $wikihelp);
187
188$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
189print load_fiche_titre($langs->trans("AgendaSetup"), $linkback, 'title_setup');
190
191
192
193$head = agenda_prepare_head();
194
195print dol_get_fiche_head($head, 'other', $langs->trans("Agenda"), -1, 'action');
196
197
198/*
199 * Miscellaneous
200 */
201
202// Define array def of models
203$def = array();
204
205$sql = "SELECT nom";
206$sql .= " FROM ".MAIN_DB_PREFIX."document_model";
207$sql .= " WHERE type = 'action'";
208$sql .= " AND entity = ".$conf->entity;
209
210$resql = $db->query($sql);
211if ($resql) {
212 $i = 0;
213 $num_rows = $db->num_rows($resql);
214 while ($i < $num_rows) {
215 $array = $db->fetch_array($resql);
216 array_push($def, $array[0]);
217 $i++;
218 }
219} else {
220 dol_print_error($db);
221}
222
223if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
224 print load_fiche_titre($langs->trans("AgendaModelModule"), '', '');
225
226 print '<table class="noborder centpercent">'."\n";
227 print '<tr class="liste_titre">'."\n";
228 print '<td width="100">'.$langs->trans("Name").'</td>'."\n";
229 print '<td>'.$langs->trans("Description").'</td>'."\n";
230 print '<td class="center" width="60">'.$langs->trans("Status").'</td>'."\n";
231 print '<td class="center" width="60">'.$langs->trans("Default").'</td>'."\n";
232 print '<td class="center" width="40">'.$langs->trans("ShortInfo").'</td>';
233 print '<td class="center" width="40">'.$langs->trans("Preview").'</td>';
234 print '</tr>'."\n";
235
236 clearstatcache();
237
238 foreach ($dirmodels as $reldir) {
239 $dir = dol_buildpath($reldir."core/modules/action/doc");
240
241 if (is_dir($dir)) {
242 $handle = opendir($dir);
243 if (is_resource($handle)) {
244 while (($file = readdir($handle)) !== false) {
245 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
246 $name = substr($file, 4, dol_strlen($file) - 16);
247 $classname = substr($file, 0, dol_strlen($file) - 12);
248
249 require_once $dir.'/'.$file;
250 $module = new $classname($db, new ActionComm($db));
251
252 print '<tr class="oddeven">'."\n";
253 print "<td>";
254 print (empty($module->name) ? $name : $module->name);
255 print "</td>\n";
256 print "<td>\n";
257 require_once $dir.'/'.$file;
258 $module = new $classname($db, $specimenthirdparty);
259 if (method_exists($module, 'info')) {
260 print $module->info($langs);
261 } else {
262 print $module->description;
263 }
264 print "</td>\n";
265
266 // Active
267 if (in_array($name, $def)) {
268 print '<td class="center">'."\n";
269 if ($conf->global->ACTION_EVENT_ADDON_PDF != "$name") {
270 print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.$name.'&scan_dir='.$module->scandir.'&label='.urlencode($module->name).'&type=action">';
271 print img_picto($langs->trans("Enabled"), 'switch_on');
272 print '</a>';
273 } else {
274 print img_picto($langs->trans("Enabled"), 'switch_on');
275 }
276 print "</td>";
277 } else {
278 print '<td class="center">'."\n";
279 print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmodel&token='.newToken().'&value='.$name.'&scan_dir='.$module->scandir.'&label='.urlencode($module->name).'&type=action">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
280 print "</td>";
281 }
282
283 // Default
284 print '<td class="center">';
285 if ($conf->global->ACTION_EVENT_ADDON_PDF == "$name") {
286 print img_picto($langs->trans("Default"), 'on');
287 } else {
288 print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&token='.newToken().'&value='.urlencode($name).'&amp;scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'&amp;type=action"" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
289 }
290 print '</td>';
291
292 // Info
293 $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
294 $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
295 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
296 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
297 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
298 print '<td class="center">';
299 print $form->textwithpicto('', $htmltooltip, 1, 0);
300 print '</td>';
301 print '<td class="center">';
302 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&amp;module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
303 print '</td>';
304
305 print "</tr>\n";
306 }
307 }
308 closedir($handle);
309 }
310 }
311 }
312 print '</table><br>';
313
314 print load_fiche_titre($langs->trans('MiscellaneousOptions'), '', '');
315}
316
317
318print '<form action="'.$_SERVER["PHP_SELF"].'" name="agenda">';
319print '<input type="hidden" name="token" value="'.newToken().'">';
320print '<input type="hidden" name="action" value="set">';
321
322print '<table class="noborder allwidth">'."\n";
323print '<tr class="liste_titre">'."\n";
324print '<td>'.$langs->trans("Parameters").'</td>'."\n";
325print '<td class="center">&nbsp;</td>'."\n";
326print '<td class="right">'.$langs->trans("Value").'</td>'."\n";
327print '</tr>'."\n";
328
329// AGENDA_DEFAULT_VIEW
330print '<tr class="oddeven">'."\n";
331$htmltext = $langs->trans("ThisValueCanOverwrittenOnUserLevel", $langs->transnoentitiesnoconv("UserGUISetup"));
332print '<td>'.$form->textwithpicto($langs->trans("AGENDA_DEFAULT_VIEW"), $htmltext).'</td>'."\n";
333print '<td class="center">&nbsp;</td>'."\n";
334print '<td class="right">'."\n";
335$tmplist = array(''=>'&nbsp;', 'show_list'=>$langs->trans("ViewList"), 'show_month'=>$langs->trans("ViewCal"), 'show_week'=>$langs->trans("ViewWeek"), 'show_day'=>$langs->trans("ViewDay"), 'show_peruser'=>$langs->trans("ViewPerUser"));
336print $form->selectarray('AGENDA_DEFAULT_VIEW', $tmplist, getDolGlobalString('AGENDA_DEFAULT_VIEW'));
337print '</td></tr>'."\n";
338
339// Manual or automatic
340
341print '<tr class="oddeven">'."\n";
342print '<td>'.$langs->trans("AGENDA_USE_EVENT_TYPE").'</td>'."\n";
343print '<td class="center">&nbsp;</td>'."\n";
344print '<td class="right">'."\n";
345//print ajax_constantonoff('AGENDA_USE_EVENT_TYPE'); Do not use ajax here, we need to reload page to change other combo list
346if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
347 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_AGENDA_USE_EVENT_TYPE&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
348} else {
349 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_AGENDA_USE_EVENT_TYPE&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'switch_on').'</a>';
350}
351print '</td></tr>'."\n";
352
353if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
354 print '<!-- AGENDA_USE_EVENT_TYPE_DEFAULT -->';
355 print '<tr class="oddeven">'."\n";
356 print '<td>'.$langs->trans("AGENDA_USE_EVENT_TYPE_DEFAULT").'</td>'."\n";
357 print '<td class="center">&nbsp;</td>'."\n";
358 print '<td class="right nowrap">'."\n";
359 $formactions->select_type_actions(getDolGlobalString('AGENDA_USE_EVENT_TYPE_DEFAULT'), "AGENDA_USE_EVENT_TYPE_DEFAULT", 'systemauto', 0, 1);
360 print '</td></tr>'."\n";
361}
362
363// AGENDA_EVENT_DEFAULT_STATUS
364print '<tr class="oddeven">'."\n";
365print '<td>'.$langs->trans("AGENDA_EVENT_DEFAULT_STATUS").'</td>'."\n";
366print '<td class="center">&nbsp;</td>'."\n";
367print '<td class="right nowrap">'."\n";
368$defval = 'na';
369$defaultValues = new DefaultValues($db);
370$result = $defaultValues->fetchAll('', '', 0, 0, array('t.page'=>'comm/action/card.php', 't.param'=>'complete', 't.user_id'=>'0', 't.type'=>'createform', 't.entity'=>$conf->entity));
371if (!is_array($result) && $result < 0) {
372 setEventMessages($defaultValues->error, $defaultValues->errors, 'errors');
373} elseif (count($result) > 0) {
374 $defval = reset($result)->value;
375}
376$formactions->form_select_status_action('agenda', $defval, 1, "AGENDA_EVENT_DEFAULT_STATUS", 0, 1, 'maxwidth200 onrightofpage');
377print '</td></tr>'."\n";
378
379// AGENDA_DEFAULT_FILTER_TYPE
380print '<tr class="oddeven">'."\n";
381print '<td>'.$langs->trans("AGENDA_DEFAULT_FILTER_TYPE").'</td>'."\n";
382print '<td class="center">&nbsp;</td>'."\n";
383print '<td class="right nowrap">'."\n";
384$multiselect = 0;
385if (!empty($conf->global->MAIN_ENABLE_MULTISELECT_TYPE)) {
386 // We use an option here because it adds bugs when used on agenda page "peruser" and "list"
387 $multiselect = (!empty($conf->global->AGENDA_USE_EVENT_TYPE));
388}
389$formactions->select_type_actions(getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE'), "AGENDA_DEFAULT_FILTER_TYPE", '', (getDolGlobalString('AGENDA_USE_EVENT_TYPE') ? -1 : 1), 1, $multiselect);
390print '</td></tr>'."\n";
391
392// AGENDA_DEFAULT_FILTER_STATUS
393// TODO Remove to use the default generic feature
394print '<tr class="oddeven">'."\n";
395print '<td>'.$langs->trans("AGENDA_DEFAULT_FILTER_STATUS").'</td>'."\n";
396print '<td class="center">&nbsp;</td>'."\n";
397print '<td class="right">'."\n";
398$formactions->form_select_status_action('agenda', getDolGlobalString('AGENDA_DEFAULT_FILTER_STATUS'), 1, 'AGENDA_DEFAULT_FILTER_STATUS', 1, 2, 'minwidth100');
399print '</td></tr>'."\n";
400
401print '</table>';
402
403print $form->buttonsSaveCancel("Save", '');
404
405print '</form>';
406
407
408print dol_get_fiche_end();
409
410// End of page
411llxFooter();
412$db->close();
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
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).
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
delDocumentModel($name, $type)
Delete document model used by doc generator.
agenda_prepare_head()
Prepare array with list of tabs.
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') elseif( $action=='specimen') elseif($action=='setmodel') elseif( $action=='del') elseif($action=='setdoc') $formactions
View.
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
llxFooter()
Empty footer.
Definition wrapper.php:70
Class to manage agenda events (actions)
Class to manage predefined suppliers products.
Class for MyObject.
Class to manage building of HTML components.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:123
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.