1<?php
2/* Copyright (C) 2008-2011 Laurent Destailleur  <eldy@users.sourceforge.net>
3 * Copyright (C) 2013	   Juanjo Menent		<jmenent@2byte.es>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19/**
20 *	    \file       htdocs/admin/events.php
21 *      \ingroup    core
22 *      \brief      Log event setup page
23 */
24
25require '../main.inc.php';
26require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
27require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
28require_once DOL_DOCUMENT_ROOT.'/core/class/events.class.php';
29
30
31if (!$user->admin) {
32	accessforbidden();
33}
34
35// Load translation files required by the page
36$langs->loadLangs(array("users", "admin", "other"));
37
38$action = GETPOST('action', 'aZ09');
39$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'auditeventslist'; // To manage different context of search
40$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
41
42// Load variable for pagination
43$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
44$sortfield = GETPOST('sortfield', 'aZ09comma');
45$sortorder = GETPOST('sortorder', 'aZ09comma');
46$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
47if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) { $page = 0; }     // If $page is not defined, or '' or -1 or if we click on clear filters
48$offset = $limit * $page;
49$pageprev = $page - 1;
50$pagenext = $page + 1;
51
52$securityevent = new Events($db);
53$eventstolog = $securityevent->eventstolog;
54
55
56/*
57 *	Actions
58 */
59
60if ($action == "save")
61{
62	$i = 0;
63
64	$db->begin();
65
66	foreach ($eventstolog as $key => $arr)
67	{
68		$param = 'MAIN_LOGEVENTS_'.$arr['id'];
69		if (GETPOST($param, 'alphanohtml')) dolibarr_set_const($db, $param, GETPOST($param, 'alphanohtml'), 'chaine', 0, '', $conf->entity);
70		else dolibarr_del_const($db, $param, $conf->entity);
71	}
72
73	$db->commit();
74	setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
75}
76
77
78
79/*
80 * View
81 */
82
83$form = new Form($db);
84
85$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
86$selectedfields = '';
87$selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
88
89$wikihelp = 'EN:Setup_Security|FR:Paramétrage_Sécurité|ES:Configuración_Seguridad';
90llxHeader('', $langs->trans("Audit"), $wikihelp);
91
92//$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
93print load_fiche_titre($langs->trans("SecuritySetup"), '', 'title_setup');
94
95print '<span class="opacitymedium">'.$langs->trans("LogEventDesc", $langs->transnoentitiesnoconv("AdminTools"), $langs->transnoentitiesnoconv("Audit"))."</span><br>\n";
96print "<br>\n";
97
98
99print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
100print '<input type="hidden" name="token" value="'.newToken().'">';
101print '<input type="hidden" name="action" value="save">';
102
103$head = security_prepare_head();
104
105print dol_get_fiche_head($head, 'audit', '', -1);
106
107print '<table class="noborder" width="100%">';
108print "<tr class=\"liste_titre\">";
109print getTitleFieldOfList("LogEvents", 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, '')."\n";
110print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
111print "</tr>\n";
112// Loop on each event type
113foreach ($eventstolog as $key => $arr)
114{
115	if ($arr['id'])
116	{
117		print '<tr class="oddeven">';
118		print '<td>'.$arr['id'].'</td>';
119		print '<td class="center">';
120		$key = 'MAIN_LOGEVENTS_'.$arr['id'];
121		$value = empty($conf->global->$key) ? '' : $conf->global->$key;
122		print '<input class="oddeven checkforselect" type="checkbox" name="'.$key.'" value="1"'.($value ? ' checked' : '').'>';
123		print '</td></tr>'."\n";
124	}
125}
126print '</table>';
127
128print dol_get_fiche_end();
129
130print '<div class="center">';
131print '<input type="submit" name="save" class="button button-save" value="'.$langs->trans("Save").'">';
132print '</div>';
133
134print "</form>\n";
135
136// End of page
137llxFooter();
138$db->close();
139