dolibarr  13.0.2
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 require '../../main.inc.php';
25 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
26 
27 $langs->load("admin");
28 
29 if (!$user->admin)
31 
32 $action = GETPOST('action', 'aZ09');
33 $confirm = GETPOST('confirm', 'alpha');
34 $choice = GETPOST('choice', 'aZ09');
35 
36 
37 // Define filelog to discard it from purge
38 $filelog = '';
39 if (!empty($conf->syslog->enabled))
40 {
41  $filelog = $conf->global->SYSLOG_FILE;
42  $filelog = preg_replace('/DOL_DATA_ROOT/i', DOL_DATA_ROOT, $filelog);
43 }
44 
45 
46 /*
47  * Actions
48  */
49 if ($action == 'purge' && !preg_match('/^confirm/i', $choice) && ($choice != 'allfiles' || $confirm == 'yes'))
50 {
51  // Increase limit of time. Works only if we are not in safe mode
52  $ExecTimeLimit = 600;
53  if (!empty($ExecTimeLimit))
54  {
55  $err = error_reporting();
56  error_reporting(0); // Disable all errors
57  //error_reporting(E_ALL);
58  @set_time_limit($ExecTimeLimit); // Need more than 240 on Windows 7/64
59  error_reporting($err);
60  }
61 
62  require_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php';
63  $utils = new Utils($db);
64  $result = $utils->purgeFiles($choice);
65 
66  $mesg = $utils->output;
67  setEventMessages($mesg, null, 'mesgs');
68 }
69 
70 
71 /*
72  * View
73  */
74 
75 llxHeader();
76 
77 $form = new Form($db);
78 
79 print load_fiche_titre($langs->trans("Purge"), '', 'title_setup');
80 
81 print '<span class="opacitymedium">'.$langs->trans("PurgeAreaDesc", $dolibarr_main_data_root).'</span><br>';
82 print '<br>';
83 
84 
85 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
86 print '<input type="hidden" name="token" value="'.newToken().'" />';
87 print '<input type="hidden" name="action" value="purge" />';
88 
89 print '<table class="border centpercent">';
90 
91 print '<tr class="border"><td style="padding: 4px">';
92 
93 if (!empty($conf->syslog->enabled)) {
94  print '<input type="radio" name="choice" id="choicelogfile" value="logfile"';
95  print ($choice && $choice == 'logfile') ? ' checked' : '';
96  $filelogparam = $filelog;
97  if ($user->admin && preg_match('/^dolibarr.*\.log$/', basename($filelog))) {
98  $filelogparam = '<a class="wordbreak" href="'.DOL_URL_ROOT.'/document.php?modulepart=logs&file=';
99  $filelogparam .= basename($filelog);
100  $filelogparam .= '">'.$filelog.'</a>';
101  }
102  $desc = $langs->trans("PurgeDeleteLogFile", '{filelogparam}');
103  $desc = str_replace('{filelogparam}', $filelogparam, $desc);
104  print '> <label for="choicelogfile">'.$desc.'</label>';
105  print '<br><br>';
106 }
107 
108 print '<input type="radio" name="choice" id="choicetempfiles" value="tempfiles"';
109 print (!$choice || $choice == 'tempfiles' || $choice == 'allfiles') ? ' checked' : '';
110 print '> <label for="choicetempfiles">'.$langs->trans("PurgeDeleteTemporaryFiles").'</label><br><br>';
111 
112 print '<input type="radio" name="choice" id="choiceallfiles" value="confirm_allfiles"';
113 print ($choice && $choice == 'confirm_allfiles') ? ' checked' : '';
114 print '> <label for="choiceallfiles">'.$langs->trans("PurgeDeleteAllFilesInDocumentsDir", $dolibarr_main_data_root).'</label><br>';
115 
116 print '</td></tr></table>';
117 
118 //if ($choice != 'confirm_allfiles')
119 //{
120  print '<br>';
121  print '<div class="center"><input class="button" type="submit" value="'.$langs->trans("PurgeRunNow").'"></div>';
122 //}
123 
124 print '</form>';
125 
126 if (preg_match('/^confirm/i', $choice)) {
127  print '<br>';
128  $formquestion = array();
129  print $form->formconfirm($_SERVER["PHP_SELF"].'?choice=allfiles', $langs->trans('Purge'), $langs->trans('ConfirmPurge').img_warning().' ', 'purge', $formquestion, 'no', 2);
130 }
131 
132 // End of page
133 llxFooter();
134 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage utility methods.
Definition: utils.class.php:28
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
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 ...
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
Definition: index.php:89
llxFooter()
Empty footer.
Definition: wrapper.php:59