25 require
'../../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/class/utils.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
31 $langs->load(
"admin");
33 $action =
GETPOST(
'action',
'aZ09');
34 $what =
GETPOST(
'what',
'alpha');
35 $export_type =
GETPOST(
'export_type',
'alpha');
36 $file = trim(
GETPOST(
'zipfilename_template',
'alpha'));
37 $compression =
GETPOST(
'compression',
'aZ09');
40 $file = preg_replace(
'/(\.zip|\.tar|\.tgz|\.gz|\.tar\.gz|\.bz2)$/i',
'', $file);
42 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
43 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
45 if (!$sortorder) $sortorder =
"DESC";
46 if (!$sortfield) $sortfield =
"date";
47 if ($page < 0) { $page = 0; } elseif (empty($page)) $page = 0;
48 $limit =
GETPOST('limit', '
int') ?
GETPOST('limit', '
int') : $conf->liste_limit;
49 $offset = $limit * $page;
60 if ($action == 'delete')
63 $filepath = $conf->admin->dir_output.
'/'.$filerelative;
65 if ($ret)
setEventMessages($langs->trans(
"FileWasRemoved", $filerelative), null,
'mesgs');
66 else setEventMessages($langs->trans(
"ErrorFailToDeleteFile", $filerelative), null,
'errors');
76 $ExecTimeLimit = 1800;
77 if (!empty($ExecTimeLimit))
79 $err = error_reporting();
82 @set_time_limit($ExecTimeLimit);
83 error_reporting($err);
86 if (!empty($MemoryLimit))
88 @ini_set(
'memory_limit', $MemoryLimit);
91 $form =
new Form($db);
102 $dump_buffer_len = 0;
105 $time_start = time();
108 $outputdir = $conf->admin->dir_output.
'/documents';
111 $utils =
new Utils($db);
113 if ($compression ==
'zip')
116 $excludefiles =
'/(\.back|\.old|\.log|[\/\\\]temp[\/\\\]|documents[\/\\\]admin[\/\\\]documents[\/\\\])/i';
117 $ret = dol_compress_dir(DOL_DATA_ROOT, $outputdir.
"/".$file, $compression, $excludefiles);
121 $langs->load(
"errors");
122 $errormsg = $langs->trans(
"ErrNoZipEngine");
124 $langs->load(
"errors");
125 $errormsg = $langs->trans(
"ErrorFailedToWriteInDir", $outputdir);
128 } elseif (in_array($compression, array(
'gz',
'bz')))
130 $userlogin = ($user->login ? $user->login :
'unknown');
132 $outputfile = $conf->admin->dir_temp.
'/export_files.'.$userlogin.
'.out';
136 $cmd =
"tar -cf ".$outputdir.
"/".$file.
" --exclude-vcs --exclude 'temp' --exclude 'dolibarr.log' --exclude 'dolibarr_*.log' --exclude 'documents/admin/documents' -C ".dirname(DOL_DATA_ROOT).
" ".basename(DOL_DATA_ROOT);
138 $result = $utils->executeCLI($cmd, $outputfile);
140 $retval = $result[
'error'];
141 if ($result[
'result'] || !empty($retval))
143 $langs->load(
"errors");
144 dol_syslog(
"Documents tar retval after exec=".$retval, LOG_ERR);
145 $errormsg =
'Error tar generation return '.$retval;
147 if ($compression ==
'gz')
149 $cmd =
"gzip -f ".$outputdir.
"/".$file;
151 if ($compression ==
'bz')
153 $cmd =
"bzip2 -f ".$outputdir.
"/".$file;
156 $result = $utils->executeCLI($cmd, $outputfile);
158 $retval = $result[
'error'];
159 if ($result[
'result'] || !empty($retval))
161 $errormsg =
'Error '.$compression.
' generation return '.$retval;
162 unlink($outputdir.
"/".$file);
173 header(
"Location: dolibarr_export.php");
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.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1)
Remove a file or several files with a mask.
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 ...
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)