dolibarr  19.0.0-dev
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 // Load Dolibarr environment
29 require '../../main.inc.php';
30 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
31 
32 $langs->load("admin");
33 
34 $action = GETPOST('action', 'aZ09');
35 $confirm = GETPOST('confirm', 'alpha');
36 $choice = GETPOST('choice', 'aZ09');
37 $nbsecondsold = GETPOSTINT('nbsecondsold');
38 
39 // Define filelog to discard it from purge
40 $filelog = '';
41 if (isModEnabled('syslog')) {
42  $filelog = getDolGlobalString('SYSLOG_FILE');
43  $filelog = preg_replace('/DOL_DATA_ROOT/i', DOL_DATA_ROOT, $filelog);
44 }
45 
46 // Security
47 if (!$user->admin) {
49 }
50 
51 
52 /*
53  * Actions
54  */
55 
56 if ($action == 'purge' && !preg_match('/^confirm/i', $choice) && ($choice != 'allfiles' || $confirm == 'yes')) {
57  // Increase limit of time. Works only if we are not in safe mode
58  $ExecTimeLimit = 600;
59  if (!empty($ExecTimeLimit)) {
60  $err = error_reporting();
61  error_reporting(0); // Disable all errors
62  //error_reporting(E_ALL);
63  @set_time_limit($ExecTimeLimit); // Need more than 240 on Windows 7/64
64  error_reporting($err);
65  }
66 
67  require_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php';
68  $utils = new Utils($db);
69 
70  $result = $utils->purgeFiles($choice, $nbsecondsold);
71 
72  $mesg = $utils->output;
73  setEventMessages($mesg, null, 'mesgs');
74 }
75 
76 
77 /*
78  * View
79  */
80 
81 llxHeader();
82 
83 $form = new Form($db);
84 
85 print load_fiche_titre($langs->trans("Purge"), '', 'title_setup');
86 
87 print '<span class="opacitymedium">'.$langs->trans("PurgeAreaDesc", $dolibarr_main_data_root).'</span><br>';
88 print '<br>';
89 
90 
91 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
92 print '<input type="hidden" name="token" value="'.newToken().'" />';
93 print '<input type="hidden" name="action" value="purge" />';
94 
95 print '<table class="border centpercent">';
96 
97 print '<tr class="border"><td style="padding: 4px">';
98 
99 if (isModEnabled('syslog')) {
100  print '<input type="radio" name="choice" id="choicelogfile" value="logfile"';
101  print ($choice && $choice == 'logfile') ? ' checked' : '';
102  $filelogparam = $filelog;
103  if ($user->admin && preg_match('/^dolibarr.*\.log$/', basename($filelog))) {
104  $filelogparam = '<a class="wordbreak" href="'.DOL_URL_ROOT.'/document.php?modulepart=logs&file=';
105  $filelogparam .= basename($filelog);
106  $filelogparam .= '">'.$filelog.'</a>';
107  }
108  $desc = $langs->trans("PurgeDeleteLogFile", '{filelogparam}');
109  $desc = str_replace('{filelogparam}', $filelogparam, $desc);
110  print '> <label for="choicelogfile">'.$desc.'</label>';
111  print '<br><br>';
112 }
113 
114 print '<input type="radio" name="choice" id="choicetempfiles" value="tempfiles"';
115 print (!$choice || $choice == 'tempfiles' || $choice == 'allfiles') ? ' checked' : '';
116 print '> <label for="choicetempfiles">'.$langs->trans("PurgeDeleteTemporaryFilesShort").'</label><br><br>';
117 
118 print '<input type="radio" name="choice" id="choiceallfiles" value="confirm_allfiles"';
119 print ($choice && $choice == 'confirm_allfiles') ? ' checked' : '';
120 print '> <label for="choiceallfiles">'.$langs->trans("PurgeDeleteAllFilesInDocumentsDir", $dolibarr_main_data_root).'</label>';
121 print '<br>';
122 if (getDolGlobalInt('MAIN_PURGE_ACCEPT_NBSECONDSOLD')) {
123  print 'NbSecondsOld = <input class="width50 right" type="text" name="nbsecondsold" value="'.$nbsecondsold.'">';
124 }
125 print '</td></tr></table>';
126 
127 //if ($choice != 'confirm_allfiles')
128 //{
129  print '<br>';
130  print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("PurgeRunNow").'"></div>';
131 //}
132 
133 print '</form>';
134 
135 if (preg_match('/^confirm/i', $choice)) {
136  print '<br>';
137  $formquestion = array();
138  print $form->formconfirm($_SERVER["PHP_SELF"].'?choice=allfiles&nbsecondsold='.$nbsecondsold, $langs->trans('Purge'), $langs->trans('ConfirmPurge').img_warning().' ', 'purge', $formquestion, 'no', 2);
139 }
140 
141 // End of page
142 llxFooter();
143 $db->close();
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 generation of HTML components Only common components must be here.
Class to manage utility methods.
Definition: utils.class.php:31
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOSTINT($paramname, $method=0)
Return value of a param into GET or POST supervariable.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.