dolibarr  16.0.5
purge.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2006-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2006-2012 Regis Houssin <regis.houssin@inodbox.com>
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 
24 if (! defined('CSRFCHECK_WITH_TOKEN')) {
25  define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
26 }
27 
28 require '../../main.inc.php';
29 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
30 
31 $langs->load("admin");
32 
33 $action = GETPOST('action', 'aZ09');
34 $confirm = GETPOST('confirm', 'alpha');
35 $choice = GETPOST('choice', 'aZ09');
36 
37 
38 // Define filelog to discard it from purge
39 $filelog = '';
40 if (!empty($conf->syslog->enabled)) {
41  $filelog = $conf->global->SYSLOG_FILE;
42  $filelog = preg_replace('/DOL_DATA_ROOT/i', DOL_DATA_ROOT, $filelog);
43 }
44 
45 if (!$user->admin) {
47 }
48 
49 
50 /*
51  * Actions
52  */
53 
54 if ($action == 'purge' && !preg_match('/^confirm/i', $choice) && ($choice != 'allfiles' || $confirm == 'yes')) {
55  // Increase limit of time. Works only if we are not in safe mode
56  $ExecTimeLimit = 600;
57  if (!empty($ExecTimeLimit)) {
58  $err = error_reporting();
59  error_reporting(0); // Disable all errors
60  //error_reporting(E_ALL);
61  @set_time_limit($ExecTimeLimit); // Need more than 240 on Windows 7/64
62  error_reporting($err);
63  }
64 
65  require_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php';
66  $utils = new Utils($db);
67  $result = $utils->purgeFiles($choice);
68 
69  $mesg = $utils->output;
70  setEventMessages($mesg, null, 'mesgs');
71 }
72 
73 
74 /*
75  * View
76  */
77 
78 llxHeader();
79 
80 $form = new Form($db);
81 
82 print load_fiche_titre($langs->trans("Purge"), '', 'title_setup');
83 
84 print '<span class="opacitymedium">'.$langs->trans("PurgeAreaDesc", $dolibarr_main_data_root).'</span><br>';
85 print '<br>';
86 
87 
88 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
89 print '<input type="hidden" name="token" value="'.newToken().'" />';
90 print '<input type="hidden" name="action" value="purge" />';
91 
92 print '<table class="border centpercent">';
93 
94 print '<tr class="border"><td style="padding: 4px">';
95 
96 if (!empty($conf->syslog->enabled)) {
97  print '<input type="radio" name="choice" id="choicelogfile" value="logfile"';
98  print ($choice && $choice == 'logfile') ? ' checked' : '';
99  $filelogparam = $filelog;
100  if ($user->admin && preg_match('/^dolibarr.*\.log$/', basename($filelog))) {
101  $filelogparam = '<a class="wordbreak" href="'.DOL_URL_ROOT.'/document.php?modulepart=logs&file=';
102  $filelogparam .= basename($filelog);
103  $filelogparam .= '">'.$filelog.'</a>';
104  }
105  $desc = $langs->trans("PurgeDeleteLogFile", '{filelogparam}');
106  $desc = str_replace('{filelogparam}', $filelogparam, $desc);
107  print '> <label for="choicelogfile">'.$desc.'</label>';
108  print '<br><br>';
109 }
110 
111 print '<input type="radio" name="choice" id="choicetempfiles" value="tempfiles"';
112 print (!$choice || $choice == 'tempfiles' || $choice == 'allfiles') ? ' checked' : '';
113 print '> <label for="choicetempfiles">'.$langs->trans("PurgeDeleteTemporaryFilesShort").'</label><br><br>';
114 
115 print '<input type="radio" name="choice" id="choiceallfiles" value="confirm_allfiles"';
116 print ($choice && $choice == 'confirm_allfiles') ? ' checked' : '';
117 print '> <label for="choiceallfiles">'.$langs->trans("PurgeDeleteAllFilesInDocumentsDir", $dolibarr_main_data_root).'</label><br>';
118 
119 print '</td></tr></table>';
120 
121 //if ($choice != 'confirm_allfiles')
122 //{
123  print '<br>';
124  print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("PurgeRunNow").'"></div>';
125 //}
126 
127 print '</form>';
128 
129 if (preg_match('/^confirm/i', $choice)) {
130  print '<br>';
131  $formquestion = array();
132  print $form->formconfirm($_SERVER["PHP_SELF"].'?choice=allfiles', $langs->trans('Purge'), $langs->trans('ConfirmPurge').img_warning().' ', 'purge', $formquestion, 'no', 2);
133 }
134 
135 // End of page
136 llxFooter();
137 $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
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
Utils
Class to manage utility methods.
Definition: utils.class.php:30
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8136
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