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/html.formfile.class.php';
30 $langs->load(
"admin");
32 $action =
GETPOST(
'action',
'aZ09');
34 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
35 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
37 if (!$sortorder) $sortorder =
"DESC";
38 if (!$sortfield) $sortfield =
"date";
39 if (empty($page) || $page == -1) { $page = 0; }
40 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
41 $offset = $limit * $page;
51 if ($action ==
'delete')
53 if (preg_match(
'/^backup\//',
GETPOST(
'urlfile',
'alpha')))
55 $file = $conf->admin->dir_output.
'/backup/'.basename(
GETPOST(
'urlfile',
'alpha'));
60 $file = $conf->admin->dir_output.
'/documents/'.basename(
GETPOST(
'urlfile',
'alpha'));
73 $form =
new Form($db);
80 $help_url =
'EN:Backups|FR:Sauvegardes|ES:Copias_de_seguridad';
83 print '<script type="text/javascript">
84 jQuery(document).ready(function() {';
87 function hideoptions () {
88 jQuery(
"#mysql_options").hide();
89 jQuery(
"#mysql_nobin_options").hide();
90 jQuery(
"#postgresql_options").hide();
94 jQuery(
"#radio_dump_mysql").click(
function() {
96 jQuery(
"#mysql_options").show();
98 jQuery(
"#radio_dump_mysql_nobin").click(
function() {
100 jQuery(
"#mysql_nobin_options").show();
102 jQuery(
"#radio_dump_postgresql").click(
function() {
104 jQuery(
"#postgresql_options").show();
106 jQuery(
"#select_sql_compat").click(
function() {
107 if (jQuery(
"#select_sql_compat").val() ==
'POSTGRESQL')
109 jQuery(
"#checkbox_dump_disable-add-locks").prop(
'checked',
true);
114 if (in_array($type, array(
'mysql',
'mysqli'))) {
115 print 'jQuery("#radio_dump_mysql").click();';
117 if (in_array($type, array(
'pgsql'))) {
118 print 'jQuery("#radio_dump_postgresql").click();';
123 $title = $langs->trans(
"Backup");
128 print '<div class="center opacitymedium">';
129 print $langs->trans(
"BackupDesc", DOL_DATA_ROOT);
133 print "<!-- Dump of a server -->\n";
134 print '<form method="post" action="export.php" name="dump">';
135 print '<input type="hidden" name="token" value="'.newToken().
'" />';
136 print '<input type="hidden" name="export_type" value="server" />';
137 print '<fieldset id="fieldsetexport"><legend class="legendforfieldsetstep" style="font-size: 3em">1</legend>';
139 print $langs->trans(
"BackupDesc3", $dolibarr_main_db_name).
'<br>';
143 print '<div id="backupdatabaseleft" class="fichehalfleft" >';
145 $title = $langs->trans(
"BackupDumpWizard");
149 print '<table width="100%" class="'.($useinecm ?
'nobordernopadding' :
'liste').
' nohover">';
150 print '<tr class="liste_titre">';
151 print
'<td class="liste_titre">';
152 print $langs->trans(
"DatabaseName").
' : <b>'.$dolibarr_main_db_name.
'</b><br>';
155 print
'<tr class="oddeven nohover"><td style="padding-left: 8px" class="nohover">';
156 print
'<table class="centpercent">';
158 print
'<td class="tdtop">';
160 print
'<div id="div_container_exportoptions">';
161 print
'<fieldset id="exportoptions"><legend>'.$langs->trans(
"ExportMethod").
'</legend>';
162 if (in_array($type, array(
'mysql',
'mysqli'))) {
163 print
'<div class="formelementrow"><input type="radio" name="what" value="mysql" id="radio_dump_mysql" />';
164 print
'<label for="radio_dump_mysql">MySQL Dump (mysqldump)</label>';
167 print
'<div class="formelementrow"><input type="radio" name="what" value="mysqlnobin" id="radio_dump_mysql_nobin" />';
168 print
'<label for="radio_dump_mysql_nobin">MySQL Dump (php) '.img_warning($langs->trans(
'BackupPHPWarning')).
'</label>';
170 } elseif (in_array($type, array(
'pgsql'))) {
171 print
'<div class="formelementrow"><input type="radio" name="what" value="postgresql" id="radio_dump_postgresql" />';
172 print
'<label for="radio_dump_postgresql">PostgreSQL Dump (pg_dump)</label>';
175 print
'No method available with database '.$label;
181 print
'<td class="tdtop">';
184 print
'<div id="div_container_sub_exportoptions">';
185 if (in_array($type, array(
'mysql',
'mysqli'))) {
186 print
"<!-- Fieldset mysqldump -->\n";
187 print
'<fieldset id="mysql_options"><legend>'.$langs->trans(
"MySqlExportParameters").
'</legend>';
189 print
'<div class="formelementrow">'.$langs->trans(
"FullPathToMysqldumpCommand");
190 if (empty($conf->global->SYSTEMTOOLS_MYSQLDUMP))
192 $fullpathofmysqldump = $db->getPathOfDump();
194 $fullpathofmysqldump = $conf->global->SYSTEMTOOLS_MYSQLDUMP;
197 print
'<input type="text" name="mysqldump" style="width: 80%" value="'.$fullpathofmysqldump.
'" /></div>';
200 print
'<fieldset><legend>'.$langs->trans(
"ExportOptions").
'</legend>';
201 print
'<div class="formelementrow">';
202 print
'<input type="checkbox" name="use_transaction" value="yes" id="checkbox_use_transaction" />';
203 print
'<label for="checkbox_use_transaction">'.$langs->trans(
"UseTransactionnalMode").
'</label>';
206 if (!empty($conf->global->MYSQL_OLD_OPTION_DISABLE_FK)) {
207 print
'<div class="formelementrow">';
208 print
'<input type="checkbox" name="disable_fk" value="yes" id="checkbox_disable_fk" checked />';
209 print
'<label for="checkbox_disable_fk">'.$langs->trans(
"CommandsToDisableForeignKeysForImport").
' '.
img_info($langs->trans(
'CommandsToDisableForeignKeysForImportWarning')).
'</label>';
213 print
'<label for="select_sql_compat">'.$langs->trans(
"ExportCompatibility").
'</label>';
215 print
'<select name="sql_compat" id="select_sql_compat" class="flat">';
216 print
'<option value="NONE" selected>NONE</option>';
217 print
'<option value="ANSI">ANSI</option>';
218 print
'<option value="DB2">DB2</option>';
219 print
'<option value="MAXDB">MAXDB</option>';
220 print
'<option value="MYSQL323">MYSQL323</option>';
221 print
'<option value="MYSQL40">MYSQL40</option>';
222 print
'<option value="MSSQL">MSSQL</option>';
223 print
'<option value="ORACLE">ORACLE</option>';
224 print
'<option value="POSTGRESQL">POSTGRESQL</option>';
228 print
'<input type="checkbox" name="use_mysql_quick_param" value="yes" id="checkbox_use_quick" />';
229 print
'<label for="checkbox_use_quick">';
230 print $form->textwithpicto($langs->trans(
'ExportUseMySQLQuickParameter'), $langs->trans(
'ExportUseMySQLQuickParameterHelp'));
234 print
'<!-- <input type="checkbox" name="drop_database" value="yes" id="checkbox_drop_database" />';
235 print
'<label for="checkbox_drop_database">'.$langs->trans(
"AddDropDatabase").
'</label>';
242 print
'<input type="checkbox" name="sql_structure" value="structure" id="checkbox_sql_structure" checked />';
243 print
'<label for="checkbox_sql_structure">'.$langs->trans(
'ExportStructure').
'</label>';
246 print
'<input type="checkbox" name="drop"'.((!
GETPOSTISSET(
"drop") ||
GETPOST(
'drop')) ?
' checked' :
'').
' id="checkbox_dump_drop" />';
247 print
'<label for="checkbox_dump_drop">'.$langs->trans(
"AddDropTable").
'</label>';
254 print
'<input type="checkbox" name="sql_data" value="data" id="checkbox_sql_data" checked />';
255 print
'<label for="checkbox_sql_data">'.$langs->trans(
"Datas").
'</label>';
257 print
'<input type="checkbox" name="showcolumns" value="yes" id="checkbox_dump_showcolumns" checked />';
258 print
'<label for="checkbox_dump_showcolumns">'.$langs->trans(
"NameColumn").
'</label>';
261 print
'<input type="checkbox" name="extended_ins" value="yes" id="checkbox_dump_extended_ins" checked />';
262 print
'<label for="checkbox_dump_extended_ins">'.$langs->trans(
"ExtendedInsert").
'</label>';
265 print
'<input type="checkbox" name="disable-add-locks" value="no" id="checkbox_dump_disable-add-locks" />';
266 print
'<label for="checkbox_dump_disable-add-locks">'.$langs->trans(
"NoLockBeforeInsert").
'</label>';
269 print
'<input type="checkbox" name="delayed" value="yes" id="checkbox_dump_delayed" />';
270 print
'<label for="checkbox_dump_delayed">'.$langs->trans(
"DelayedInsert").
'</label>';
273 print
'<input type="checkbox" name="sql_ignore" value="yes" id="checkbox_dump_ignore" />';
274 print
'<label for="checkbox_dump_ignore">'.$langs->trans(
"IgnoreDuplicateRecords").
'</label>';
277 print
'<input type="checkbox" name="hexforbinary" value="yes" id="checkbox_hexforbinary" checked />';
278 print
'<label for="checkbox_hexforbinary">'.$langs->trans(
"EncodeBinariesInHexa").
'</label>';
281 print
'<input type="checkbox" name="charset_utf8" value="yes" id="checkbox_charset_utf8" checked disabled />';
282 print
'<label for="checkbox_charset_utf8">'.$langs->trans(
"UTF8").
'</label>';
287 print
"<!-- Fieldset mysql_nobin -->\n";
288 print
'<fieldset id="mysql_nobin_options">';
289 print
'<legend>'.$langs->trans(
"MySqlExportParameters").
'</legend>';
291 print
'<legend>'.$langs->trans(
"ExportOptions").
'</legend>';
292 print
'<div class="formelementrow">';
293 print
'<input type="checkbox" name="nobin_use_transaction" value="yes" id="checkbox_use_transaction" />';
294 print
'<label for="checkbox_use_transaction">'.$langs->trans(
"UseTransactionnalMode").
'</label>';
297 if (!empty($conf->global->MYSQL_OLD_OPTION_DISABLE_FK)) {
298 print
'<div class="formelementrow">';
299 print
'<input type="checkbox" name="nobin_disable_fk" value="yes" id="checkbox_disable_fk" checked />';
300 print
'<label for="checkbox_disable_fk">'.$langs->trans(
"CommandsToDisableForeignKeysForImport").
' '.
img_info($langs->trans(
'CommandsToDisableForeignKeysForImportWarning')).
'</label>';
306 print
'<fieldset><legend>'.$langs->trans(
'ExportStructure').
'</legend>';
307 print
'<input type="checkbox" name="nobin_drop"'.((!
GETPOSTISSET(
"nobin_drop") ||
GETPOST(
'nobin_drop')) ?
' checked' :
'').
' id="checkbox_dump_drop" />';
308 print
'<label for="checkbox_dump_drop">'.$langs->trans(
"AddDropTable").
'</label>';
314 print
'<legend>'.$langs->trans(
"Datas").
'</legend>';
316 print
'<input type="checkbox" name="nobin_nolocks" value="no" id="checkbox_dump_disable-add-locks" />';
317 print
'<label for="checkbox_dump_disable-add-locks">'.$langs->trans(
"NoLockBeforeInsert").
'</label>';
320 print
'<input type="checkbox" name="nobin_delayed" value="yes" id="checkbox_dump_delayed" />';
321 print
'<label for="checkbox_dump_delayed">'.$langs->trans(
"DelayedInsert").
'</label>';
324 print
'<input type="checkbox" name="nobin_sql_ignore" value="yes" id="checkbox_dump_ignore" />';
325 print
'<label for="checkbox_dump_ignore">'.$langs->trans(
"IgnoreDuplicateRecords").
'</label>';
328 print
'<input type="checkbox" name="nobin_charset_utf8" value="yes" id="checkbox_charset_utf8" checked disabled />';
329 print
'<label for="checkbox_charset_utf8">'.$langs->trans(
"UTF8").
'</label>';
336 if (in_array($type, array(
'pgsql'))) {
337 print
"<!-- Fieldset pg_dump -->\n";
338 print
'<fieldset id="postgresql_options"><legend>'.$langs->trans(
"PostgreSqlExportParameters").
'</legend>';
340 print
'<div class="formelementrow">'.$langs->trans(
"FullPathToPostgreSQLdumpCommand");
341 if (empty($conf->global->SYSTEMTOOLS_POSTGRESQLDUMP)) {
342 $fullpathofpgdump = $db->getPathOfDump();
344 $fullpathofpgdump = $conf->global->SYSTEMTOOLS_POSTGRESQLDUMP;
347 print
'<input type="text" name="postgresqldump" style="width: 80%" value="'.$fullpathofpgdump.
'" /></div>';
351 print
'<legend>'.$langs->trans(
"ExportOptions").
'</legend>';
352 print
'<label for="select_sql_compat">'.$langs->trans(
"ExportCompatibility").
'</label>';
353 print
'<select name="sql_compat" id="select_sql_compat" class="flat">';
354 print
'<option value="POSTGRESQL" selected>POSTGRESQL</option>';
355 print
'<option value="ANSI">ANSI</option>';
358 print
'<!-- <input type="checkbox" name="drop_database" value="yes" id="checkbox_drop_database" />';
359 print
'<label for="checkbox_drop_database">'.$langs->trans(
"AddDropDatabase").
'</label>';
365 print
'<input type="checkbox" name="sql_structure" value="structure" id="checkbox_sql_structure" checked />';
366 print
'<label for="checkbox_sql_structure">'.$langs->trans(
'ExportStructure').
'</label>';
372 print
'<input type="checkbox" name="sql_data" value="data" id="checkbox_sql_data" checked />';
373 print
'<label for="checkbox_sql_data">'.$langs->trans(
"Datas").
'</label>';
375 print
'<input type="checkbox" name="showcolumns" value="yes" id="checkbox_dump_showcolumns" checked />';
376 print
'<label for="checkbox_dump_showcolumns">'.$langs->trans(
"NameColumn").
'</label>';
388 print
'<!--<fieldset>';
389 print
'<legend>'.$langs->trans(
"Destination").
'</legend> -->';
391 print
'<label for="filename_template">'.$langs->trans(
"FileNameToGenerate").
'</label>';
395 if (in_array($type, array(
'mysql',
'mysqli'))) {
396 $prefix =
'mysqldump';
403 if (in_array($type, array(
'pgsql'))) {
407 $file = $prefix.
'_'.$dolibarr_main_db_name.
'_'.
dol_sanitizeFileName(DOL_VERSION).
'_'.strftime(
"%Y%m%d%H%M").
'.'.$ext;
408 print
'<input type="text" name="filename_template" style="width: 90%" id="filename_template" value="'.$file.
'" />';
413 $compression = array();
414 if (in_array($type, array(
'mysql',
'mysqli'))) {
415 $compression[
'gz'] = array(
416 'function' =>
'gzopen',
417 'id' =>
'radio_compression_gzip',
418 'label' => $langs->trans(
"Gzip")
426 $compression[
'bz'] = array(
427 'function' =>
'bzopen',
428 'id' =>
'radio_compression_bzip',
429 'label' => $langs->trans(
"Bzip2")
431 $compression[
'none'] = array(
433 'id' =>
'radio_compression_none',
434 'label' => $langs->trans(
"None")
437 $compression[
'none'] = array(
439 'id' =>
'radio_compression_none',
440 'label' => $langs->trans(
"None")
442 $compression[
'gz'] = array(
443 'function' =>
'gzopen',
444 'id' =>
'radio_compression_gzip',
445 'label' => $langs->trans(
"Gzip")
450 print
'<div class="formelementrow">';
453 print $langs->trans(
"Compression").
': ';
456 foreach ($compression as $key => $val)
458 if (!$val[
'function'] || function_exists($val[
'function'])) {
461 if ($key ==
'gz') $checked =
' checked';
462 print
'<input type="radio" name="compression" value="'.$key.
'" id="'.$val[
'id'].
'"'.$checked.
'>';
463 print
' <label for="'.$val[
'id'].
'">'.$val[
'label'].
'</label>';
466 print
'<input type="radio" name="compression" value="'.$key.
'" id="'.$val[
'id'].
'" disabled>';
467 print
' <label for="'.$val[
'id'].
'">'.$val[
'label'].
'</label>';
468 print
' <span class="opacitymedium">('.$langs->trans(
"NotAvailable").
')</span>';
470 print
' ';
477 print
"<!--</fieldset>--> <!-- End destination -->\n";
480 print
'<div class="center">';
481 print
'<input type="submit" class="button reposition" value="'.$langs->trans(
"GenerateBackup").
'" id="buttonGo">';
482 print
'<input type="hidden" name="page_y" value="'.GETPOST(
'page_y',
'int').
'">';
486 if (!empty($_SESSION[
"commandbackuplastdone"]))
488 print
'<br><b>'.$langs->trans(
"RunCommandSummary").
':</b><br>'.
"\n";
489 print
'<textarea rows="'.ROWS_2.
'" class="centpercent">'.$_SESSION[
"commandbackuplastdone"].
'</textarea><br>'.
"\n";
495 print
'<b>'.$langs->trans(
"BackupResult").
':</b> ';
496 print $_SESSION[
"commandbackupresult"];
498 $_SESSION[
"commandbackuplastdone"] =
'';
499 $_SESSION[
"commandbackuptorun"] =
'';
500 $_SESSION[
"commandbackupresult"] =
'';
502 if (!empty($_SESSION[
"commandbackuptorun"]))
504 print
'<br><font class="warning">'.$langs->trans(
"YouMustRunCommandFromCommandLineAfterLoginToUser", $dolibarr_main_db_user, $dolibarr_main_db_user).
':</font><br>'.
"\n";
505 print
'<textarea id="commandbackuptoruntext" rows="'.ROWS_2.
'" class="centpercent">'.$_SESSION[
"commandbackuptorun"].
'</textarea><br>'.
"\n";
511 $_SESSION[
"commandbackuplastdone"] =
'';
512 $_SESSION[
"commandbackuptorun"] =
'';
513 $_SESSION[
"commandbackupresult"] =
'';
516 print
"</div> <!-- end div center button -->\n";
521 print
"</div> <!-- end div fichehalfleft -->\n";
524 print
'<div id="backupdatabaseright" class="fichehalfright" style="height:480px; overflow: auto;">';
525 print
'<div class="ficheaddleft">';
527 $filearray =
dol_dir_list($conf->admin->dir_output.
'/backup',
'files', 0,
'',
'', $sortfield, (strtolower($sortorder) ==
'asc' ?SORT_ASC:SORT_DESC), 1);
528 $result = $formfile->list_of_documents($filearray, null,
'systemtools',
'', 1,
'backup/', 1, 0, $langs->trans(
"NoBackupFileAvailable"), 0, $langs->trans(
"PreviousDumpFiles"));
539 print
"<!-- Dump of a server -->\n";
541 print
'<form method="post" action="export_files.php" name="dump">';
542 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
543 print
'<input type="hidden" name="export_type" value="server" />';
544 print
'<input type="hidden" name="page_y" value="" />';
546 print
'<fieldset><legend class="legendforfieldsetstep" style="font-size: 3em">2</legend>';
548 print $langs->trans(
"BackupDesc2", DOL_DATA_ROOT).
'<br>';
549 print $langs->trans(
"BackupDescX").
'<br><br>';
551 print
'<div id="backupfilesleft" class="fichehalfleft">';
555 print
'<label for="zipfilename_template">'.$langs->trans(
"FileNameToGenerate").
'</label><br>';
556 $prefix =
'documents';
558 $file = $prefix.
'_'.$dolibarr_main_db_name.
'_'.
dol_sanitizeFileName(DOL_VERSION).
'_'.strftime(
"%Y%m%d%H%M");
559 print
'<input type="text" name="zipfilename_template" style="width: 90%" id="zipfilename_template" value="'.$file.
'" /> <br>';
565 print
'<div class="formelementrow">';
568 print $langs->trans(
"Compression").
': ';
569 $filecompression = $compression;
570 unset($filecompression[
'none']);
571 $filecompression[
'zip'] = array(
'function' =>
'dol_compress_dir',
'id' =>
'radio_compression_zip',
'label' => $langs->trans(
"FormatZip"));
574 foreach ($filecompression as $key => $val)
576 if (!$val[
'function'] || function_exists($val[
'function']))
579 if ($key ==
'gz') $checked =
' checked';
580 print
'<input type="radio" name="compression" value="'.$key.
'" id="'.$val[
'id'].
'"'.$checked.
'>';
581 print
' <label for="'.$val[
'id'].
'">'.$val[
'label'].
'</label>';
584 print
'<input type="radio" name="compression" value="'.$key.
'" id="'.$val[
'id'].
'" disabled>';
585 print
' <label for="'.$val[
'id'].
'">'.$val[
'label'].
'</label>';
586 print
' <span class="opacitymedium">('.$langs->trans(
"NotAvailable").
')</span>';
588 print
' ';
596 print
'<div class="center">';
597 print
'<input type="submit" class="button reposition" value="'.$langs->trans(
"GenerateBackup").
'" id="buttonGo" /><br>';
603 print
'<div id="backupdatabaseright" class="fichehalfright" style="height:480px; overflow: auto;">';
604 print
'<div class="ficheaddleft">';
606 $filearray =
dol_dir_list($conf->admin->dir_output.
'/documents',
'files', 0,
'',
'', $sortfield, (strtolower($sortorder) ==
'asc' ?SORT_ASC:SORT_DESC), 1);
607 $result = $formfile->list_of_documents($filearray, null,
'systemtools',
'', 1,
'documents/', 1, 0, $langs->trans(
"NoBackupFileAvailable"), 0, $langs->trans(
"PreviousArchiveFiles"));
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= '')
Set event messages in dol_events session object.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
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.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
ajax_autoselect($htmlname, $addlink= '')
Make content of an input box selected when we click into input field.
print
Draft customers invoices.
img_info($titlealt= 'default')
Show info logo.