dolibarr_export.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. <?php
  2. /* Copyright (C) 2006-2018 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2006-2021 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. /**
  19. * \file htdocs/admin/tools/dolibarr_export.php
  20. * \ingroup core
  21. * \brief Page to export database
  22. */
  23. // Load Dolibarr environment
  24. require '../../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  28. $langs->load("admin");
  29. $action = GETPOST('action', 'aZ09');
  30. $sortfield = GETPOST('sortfield', 'aZ09comma');
  31. $sortorder = GETPOST('sortorder', 'aZ09comma');
  32. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  33. if (!$sortorder) {
  34. $sortorder = "DESC";
  35. }
  36. if (!$sortfield) {
  37. $sortfield = "date";
  38. }
  39. if (empty($page) || $page == -1) {
  40. $page = 0;
  41. }
  42. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  43. $offset = $limit * $page;
  44. if (!$user->admin) {
  45. accessforbidden();
  46. }
  47. /*
  48. * Actions
  49. */
  50. if ($action == 'deletefile') {
  51. if (preg_match('/^backup\//', GETPOST('urlfile', 'alpha'))) {
  52. $file = $conf->admin->dir_output.'/backup/'.basename(GETPOST('urlfile', 'alpha'));
  53. $ret = dol_delete_file($file, 1);
  54. if ($ret) {
  55. setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs');
  56. } else {
  57. setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors');
  58. }
  59. } else {
  60. $file = $conf->admin->dir_output.'/documents/'.basename(GETPOST('urlfile', 'alpha'));
  61. $ret = dol_delete_file($file, 1);
  62. if ($ret) {
  63. setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs');
  64. } else {
  65. setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors');
  66. }
  67. }
  68. $action = '';
  69. }
  70. /*
  71. * View
  72. */
  73. $form = new Form($db);
  74. $formfile = new FormFile($db);
  75. $label = $db::LABEL;
  76. $type = $db->type;
  77. //var_dump($db);
  78. $help_url = 'EN:Backups|FR:Sauvegardes|ES:Copias_de_seguridad';
  79. llxHeader('', '', $help_url);
  80. print '<script type="text/javascript">
  81. jQuery(document).ready(function() {';
  82. ?>
  83. function hideoptions () {
  84. jQuery("#mysql_options").hide();
  85. jQuery("#mysql_nobin_options").hide();
  86. jQuery("#postgresql_options").hide();
  87. }
  88. hideoptions();
  89. jQuery("#radio_dump_mysql").click(function() {
  90. hideoptions();
  91. jQuery("#mysql_options").show();
  92. });
  93. jQuery("#radio_dump_mysql_nobin").click(function() {
  94. hideoptions();
  95. jQuery("#mysql_nobin_options").show();
  96. });
  97. jQuery("#radio_dump_postgresql").click(function() {
  98. hideoptions();
  99. jQuery("#postgresql_options").show();
  100. });
  101. jQuery("#select_sql_compat").click(function() {
  102. if (jQuery("#select_sql_compat").val() == 'POSTGRESQL')
  103. {
  104. jQuery("#checkbox_dump_disable-add-locks").prop('checked',true);
  105. }
  106. });
  107. <?php
  108. if (in_array($type, array('mysql', 'mysqli'))) {
  109. print 'jQuery("#radio_dump_mysql").click();';
  110. }
  111. if (in_array($type, array('pgsql'))) {
  112. print 'jQuery("#radio_dump_postgresql").click();';
  113. }
  114. print "});\n";
  115. print "</script>\n";
  116. $title = $langs->trans("Backup");
  117. print load_fiche_titre($title, '', 'title_setup');
  118. //print_barre_liste($langs->trans("Backup"), '', '', '', '', '', $langs->trans("BackupDesc",DOL_DATA_ROOT), 0, 0, 'title_setup');
  119. print '<div class="center">';
  120. print $langs->trans("BackupDesc", DOL_DATA_ROOT);
  121. print '</div>';
  122. print '<br>';
  123. print "<!-- Dump of a server -->\n";
  124. print '<form method="post" action="export.php" name="dump">';
  125. print '<input type="hidden" name="token" value="'.newToken().'" />';
  126. print '<input type="hidden" name="export_type" value="server" />';
  127. print '<input type="hidden" name="page_y" value="" />';
  128. print '<fieldset id="fieldsetexport"><legend class="legendforfieldsetstep" style="font-size: 3em">1</legend>';
  129. print '<span class="opacitymedium">';
  130. print $langs->trans("BackupDesc3", $dolibarr_main_db_name).'<br>';
  131. //print $langs->trans("BackupDescY").'<br>';
  132. print '</span>';
  133. print '<br>';
  134. print '<div id="backupdatabaseleft" class="fichehalfleft" >';
  135. $title = $langs->trans("BackupDumpWizard");
  136. print load_fiche_titre($title);
  137. print '<table class="liste nohover centpercent noborderbottom">';
  138. print '<tr class="liste_titre">';
  139. print '<td class="liste_titre">';
  140. print $langs->trans("DatabaseName").' : <b>'.$dolibarr_main_db_name.'</b><br>';
  141. print '</td>';
  142. print '</tr>';
  143. print '<tr class="oddeven nohover"><td style="class="nohover">';
  144. print '<table class="centpercent noborderbottom">';
  145. print '<tr>';
  146. print '<td class="tdtop nopaddingleftimp">';
  147. print '<div id="div_container_exportoptions">';
  148. print '<fieldset id="exportoptions"><legend>'.$langs->trans("ExportMethod").'</legend>';
  149. if (in_array($type, array('mysql', 'mysqli'))) {
  150. print '<div class="formelementrow"><input type="radio" name="what" value="mysql" id="radio_dump_mysql" />';
  151. print '<label for="radio_dump_mysql">MySQL Dump (mysqldump)</label>';
  152. print '</div>';
  153. print '<br>';
  154. print '<div class="formelementrow"><input type="radio" name="what" value="mysqlnobin" id="radio_dump_mysql_nobin" />';
  155. print '<label for="radio_dump_mysql_nobin">MySQL Dump (php) '.img_warning($langs->trans('BackupPHPWarning')).'</label>';
  156. print '</div>';
  157. } elseif (in_array($type, array('pgsql'))) {
  158. print '<div class="formelementrow"><input type="radio" name="what" value="postgresql" id="radio_dump_postgresql" />';
  159. print '<label for="radio_dump_postgresql">PostgreSQL Dump (pg_dump)</label>';
  160. print '</div>';
  161. } else {
  162. print 'No method available with database '.$label;
  163. }
  164. print '</fieldset>';
  165. print '</div>';
  166. print '</td>';
  167. print '</tr>';
  168. print '<tr>';
  169. print '<td class="tdtop nopaddingleftimp">';
  170. print '<div class="centpercent center"><a id="lnk" href="javascript:hideoptions()"> '.$langs->trans("ShowAdvancedOptions").'...</a></div>';
  171. print '<script type="text/javascript">
  172. function hideoptions(){
  173. const lnk = document.getElementById("lnk");
  174. const div = document.getElementById("div_container_sub_exportoptions");
  175. if (div.style.display === "none") {
  176. div.style.display = "block";
  177. lnk.innerText="'.dol_escape_js($langs->transnoentitiesnoconv("HideAdvancedoptions")).'";
  178. } else {
  179. div.style.display = "none";
  180. lnk.innerText="'.dol_escape_js($langs->transnoentitiesnoconv("ShowAdvancedOptions")).'...";
  181. }
  182. }
  183. </script>';
  184. print '<div id="div_container_sub_exportoptions" style="display: none;">';
  185. print '<br>';
  186. if (in_array($type, array('mysql', 'mysqli'))) {
  187. print "<!-- Fieldset mysqldump -->\n";
  188. 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)) {
  191. $fullpathofmysqldump = $db->getPathOfDump();
  192. } else {
  193. $fullpathofmysqldump = $conf->global->SYSTEMTOOLS_MYSQLDUMP;
  194. }
  195. print '<br>';
  196. print '<input type="text" name="mysqldump" style="width: 80%" value="'.$fullpathofmysqldump.'" /></div>';
  197. print '<br>';
  198. print '<fieldset><legend>'.$langs->trans("ExportOptions").'</legend>';
  199. if (!empty($conf->global->MYSQL_OLD_OPTION_DISABLE_FK)) {
  200. print '<div class="formelementrow">';
  201. print '<input type="checkbox" name="disable_fk" value="yes" id="checkbox_disable_fk" checked />';
  202. print '<label for="checkbox_disable_fk">'.$langs->trans("CommandsToDisableForeignKeysForImport").' '.img_info($langs->trans('CommandsToDisableForeignKeysForImportWarning')).'</label>';
  203. print '</div>';
  204. }
  205. print '<label for="select_sql_compat">'.$langs->trans("ExportCompatibility").'</label>';
  206. print '<select name="sql_compat" id="select_sql_compat" class="flat">';
  207. print '<option value="NONE" selected>NONE</option>';
  208. print '<option value="ANSI">ANSI</option>';
  209. print '<option value="DB2">DB2</option>';
  210. print '<option value="MAXDB">MAXDB</option>';
  211. print '<option value="MYSQL323">MYSQL323</option>';
  212. print '<option value="MYSQL40">MYSQL40</option>';
  213. print '<option value="MSSQL">MSSQL</option>';
  214. print '<option value="ORACLE">ORACLE</option>';
  215. print '<option value="POSTGRESQL">POSTGRESQL</option>';
  216. print '</select>';
  217. print '<br><br>';
  218. print '<div class="formelementrow">';
  219. print '<input type="checkbox" name="use_transaction" value="yes" id="checkbox_use_transaction" checked="checked" />';
  220. print '<label for="checkbox_use_transaction">'.$langs->trans("UseTransactionnalMode").'</label>';
  221. print '</div>';
  222. print '<input type="checkbox" name="use_mysql_quick_param" value="yes" id="checkbox_use_quick" checked="checked" />';
  223. print '<label for="checkbox_use_quick">';
  224. print $form->textwithpicto($langs->trans('ExportUseMySQLQuickParameter'), $langs->trans('ExportUseMySQLQuickParameterHelp'));
  225. print '</label>';
  226. print '<br>';
  227. $execmethod = 0;
  228. if (!empty($conf->global->MAIN_EXEC_USE_POPEN)) {
  229. $execmethod = $conf->global->MAIN_EXEC_USE_POPEN;
  230. }
  231. if (empty($execmethod)) {
  232. $execmethod = 1;
  233. }
  234. if ($execmethod == 1) {
  235. // If we use the "exec" method for shell, we ask if we need to use the alternative low memory exec mode.
  236. print '<input type="checkbox" name="lowmemorydump" value="yes" id="lowmemorydump"'.((GETPOSTISSET('lowmemorydump') ? GETPOST('lowmemorydump', 'alpha') : getDolGlobalString('MAIN_LOW_MEMORY_DUMP')) ? ' checked="checked"' : '').'" />';
  237. print '<label for="lowmemorydump">';
  238. print $form->textwithpicto($langs->trans('ExportUseLowMemoryMode'), $langs->trans('ExportUseLowMemoryModeHelp'));
  239. print '</label>';
  240. print '<br>';
  241. }
  242. print '<!-- <input type="checkbox" name="drop_database" value="yes" id="checkbox_drop_database" />';
  243. print '<label for="checkbox_drop_database">'.$langs->trans("AddDropDatabase").'</label>';
  244. print '-->';
  245. print '</fieldset>';
  246. print '<br>';
  247. print '<fieldset>';
  248. print '<legend>';
  249. print '<input type="checkbox" name="sql_structure" value="structure" id="checkbox_sql_structure" checked />';
  250. print '<label for="checkbox_sql_structure">'.$langs->trans('ExportStructure').'</label>';
  251. print '</legend>';
  252. print '<input type="checkbox" name="drop"'.((!GETPOSTISSET("drop") || GETPOST('drop')) ? ' checked' : '').' id="checkbox_dump_drop" />';
  253. print '<label for="checkbox_dump_drop">'.$langs->trans("AddDropTable").'</label>';
  254. print '<br>';
  255. print '</fieldset>';
  256. print '<br>';
  257. print '<fieldset>';
  258. print '<legend>';
  259. print '<input type="checkbox" name="sql_data" value="data" id="checkbox_sql_data" checked />';
  260. print '<label for="checkbox_sql_data">'.$langs->trans("Datas").'</label>';
  261. print '</legend>';
  262. print '<input type="checkbox" name="showcolumns" value="yes" id="checkbox_dump_showcolumns" checked />';
  263. print '<label for="checkbox_dump_showcolumns">'.$langs->trans("NameColumn").'</label>';
  264. print '<br>';
  265. print '<input type="checkbox" name="extended_ins" value="yes" id="checkbox_dump_extended_ins" checked />';
  266. print '<label for="checkbox_dump_extended_ins">'.$langs->trans("ExtendedInsert").'</label>';
  267. print '<br>';
  268. print '<input type="checkbox" name="disable-add-locks" value="no" id="checkbox_dump_disable-add-locks" />';
  269. print '<label for="checkbox_dump_disable-add-locks">'.$langs->trans("NoLockBeforeInsert").'</label>';
  270. print '<br>';
  271. print '<input type="checkbox" name="delayed" value="yes" id="checkbox_dump_delayed" />';
  272. print '<label for="checkbox_dump_delayed">'.$langs->trans("DelayedInsert").'</label>';
  273. print '<br>';
  274. print '<input type="checkbox" name="sql_ignore" value="yes" id="checkbox_dump_ignore" />';
  275. print '<label for="checkbox_dump_ignore">'.$langs->trans("IgnoreDuplicateRecords").'</label>';
  276. print '<br>';
  277. print '<input type="checkbox" name="hexforbinary" value="yes" id="checkbox_hexforbinary" checked />';
  278. print '<label for="checkbox_hexforbinary">'.$langs->trans("EncodeBinariesInHexa").'</label>';
  279. print '<br>';
  280. print '<input type="checkbox" name="charset_utf8" value="yes" id="checkbox_charset_utf8" checked disabled />';
  281. print '<label for="checkbox_charset_utf8">'.$langs->trans("UTF8").'</label>';
  282. print '<br>';
  283. print '</fieldset>';
  284. print '</fieldset>';
  285. print "<!-- Fieldset mysql_nobin -->\n";
  286. print '<fieldset id="mysql_nobin_options">';
  287. print '<legend>'.$langs->trans("MySqlExportParameters").'</legend>';
  288. print '<fieldset>';
  289. print '<legend>'.$langs->trans("ExportOptions").'</legend>';
  290. print '<div class="formelementrow">';
  291. print '<input type="checkbox" name="nobin_use_transaction" value="yes" id="checkbox_use_transaction" />';
  292. print '<label for="checkbox_use_transaction">'.$langs->trans("UseTransactionnalMode").'</label>';
  293. print '</div>';
  294. if (!empty($conf->global->MYSQL_OLD_OPTION_DISABLE_FK)) {
  295. print '<div class="formelementrow">';
  296. print '<input type="checkbox" name="nobin_disable_fk" value="yes" id="checkbox_disable_fk" checked />';
  297. print '<label for="checkbox_disable_fk">'.$langs->trans("CommandsToDisableForeignKeysForImport").' '.img_info($langs->trans('CommandsToDisableForeignKeysForImportWarning')).'</label>';
  298. print '</div>';
  299. }
  300. print '</fieldset>';
  301. print '<br>';
  302. print '<fieldset><legend>'.$langs->trans('ExportStructure').'</legend>';
  303. print '<input type="checkbox" name="nobin_drop"'.((!GETPOSTISSET("nobin_drop") || GETPOST('nobin_drop')) ? ' checked' : '').' id="checkbox_dump_drop" />';
  304. print '<label for="checkbox_dump_drop">'.$langs->trans("AddDropTable").'</label>';
  305. print '<br>';
  306. print '</fieldset>';
  307. print '<br>';
  308. print '<fieldset>';
  309. print '<legend>'.$langs->trans("Datas").'</legend>';
  310. print '<input type="checkbox" name="nobin_nolocks" value="no" id="checkbox_dump_disable-add-locks" />';
  311. print '<label for="checkbox_dump_disable-add-locks">'.$langs->trans("NoLockBeforeInsert").'</label>';
  312. print '<br>';
  313. print '<input type="checkbox" name="nobin_delayed" value="yes" id="checkbox_dump_delayed" />';
  314. print '<label for="checkbox_dump_delayed">'.$langs->trans("DelayedInsert").'</label>';
  315. print '<br>';
  316. print '<input type="checkbox" name="nobin_sql_ignore" value="yes" id="checkbox_dump_ignore" />';
  317. print '<label for="checkbox_dump_ignore">'.$langs->trans("IgnoreDuplicateRecords").'</label>';
  318. print '<br>';
  319. print '<input type="checkbox" name="nobin_charset_utf8" value="yes" id="checkbox_charset_utf8" checked disabled />';
  320. print '<label for="checkbox_charset_utf8">'.$langs->trans("UTF8").'</label>';
  321. print '<br>';
  322. print '</fieldset>';
  323. print '</fieldset>';
  324. }
  325. if (in_array($type, array('pgsql'))) {
  326. print "<!-- Fieldset pg_dump -->\n";
  327. print '<fieldset id="postgresql_options"><legend>'.$langs->trans("PostgreSqlExportParameters").'</legend>';
  328. print '<div class="formelementrow">'.$langs->trans("FullPathToPostgreSQLdumpCommand");
  329. if (empty($conf->global->SYSTEMTOOLS_POSTGRESQLDUMP)) {
  330. $fullpathofpgdump = $db->getPathOfDump();
  331. } else {
  332. $fullpathofpgdump = $conf->global->SYSTEMTOOLS_POSTGRESQLDUMP;
  333. }
  334. print '<br>';
  335. print '<input type="text" name="postgresqldump" style="width: 80%" value="'.$fullpathofpgdump.'" /></div>';
  336. print '<br>';
  337. print '<fieldset>';
  338. print '<legend>'.$langs->trans("ExportOptions").'</legend>';
  339. print '<label for="select_sql_compat">'.$langs->trans("ExportCompatibility").'</label>';
  340. print '<select name="sql_compat" id="select_sql_compat" class="flat">';
  341. print '<option value="POSTGRESQL" selected>POSTGRESQL</option>';
  342. print '<option value="ANSI">ANSI</option>';
  343. print '</select>';
  344. print '<br>';
  345. print '<!-- <input type="checkbox" name="drop_database" value="yes" id="checkbox_drop_database" />';
  346. print '<label for="checkbox_drop_database">'.$langs->trans("AddDropDatabase").'</label>';
  347. print '-->';
  348. print '</fieldset>';
  349. print '<br>';
  350. print '<fieldset>';
  351. print '<legend>';
  352. print '<input type="checkbox" name="sql_structure" value="structure" id="checkbox_sql_structure" checked />';
  353. print '<label for="checkbox_sql_structure">'.$langs->trans('ExportStructure').'</label>';
  354. print '</legend>';
  355. print '</fieldset>';
  356. print '<br>';
  357. print '<fieldset>';
  358. print '<legend>';
  359. print '<input type="checkbox" name="sql_data" value="data" id="checkbox_sql_data" checked />';
  360. print '<label for="checkbox_sql_data">'.$langs->trans("Datas").'</label>';
  361. print '</legend>';
  362. print '<input type="checkbox" name="showcolumns" value="yes" id="checkbox_dump_showcolumns" checked />';
  363. print '<label for="checkbox_dump_showcolumns">'.$langs->trans("NameColumn").'</label>';
  364. print '<br>';
  365. print '</fieldset>';
  366. print '</fieldset>';
  367. }
  368. print '</div>';
  369. print '</td>';
  370. print '</tr>';
  371. print '</table>';
  372. print '<!--<fieldset>';
  373. print '<legend>'.$langs->trans("Destination").'</legend> -->';
  374. print '<br>';
  375. print '<label for="filename_template" class="line-height-large">'.$langs->trans("FileNameToGenerate").'</label>';
  376. print '<br>';
  377. $prefix = 'dump';
  378. $ext = '.sql';
  379. if (in_array($type, array('mysql', 'mysqli'))) {
  380. $prefix = 'mysqldump';
  381. $ext = 'sql';
  382. }
  383. //if ($label == 'PostgreSQL') {
  384. // $prefix='pg_dump';
  385. // $ext='dump';
  386. //}
  387. if (in_array($type, array('pgsql'))) {
  388. $prefix = 'pg_dump';
  389. $ext = 'sql';
  390. }
  391. $file = $prefix.'_'.$dolibarr_main_db_name.'_'.dol_sanitizeFileName(DOL_VERSION).'_'.dol_print_date(dol_now('gmt'), "dayhourlogsmall", 'tzuser').'.'.$ext;
  392. print '<input type="text" name="filename_template" style="width: 90%" id="filename_template" value="'.$file.'" />';
  393. print '<br>';
  394. print '<br>';
  395. // Define compressions array
  396. $compression = array();
  397. if (in_array($type, array('mysql', 'mysqli'))) {
  398. $compression['gz'] = array(
  399. 'function' => 'gzopen',
  400. 'id' => 'radio_compression_gzip',
  401. 'label' => $langs->trans("Gzip")
  402. );
  403. // Not open source format. Must implement dol_compress function
  404. // $compression['zip']= array(
  405. // 'function' => 'dol_compress',
  406. // 'id' => 'radio_compression_zip',
  407. // 'label' => $langs->trans("FormatZip")
  408. // );
  409. $compression['bz'] = array(
  410. 'function' => 'bzopen',
  411. 'id' => 'radio_compression_bzip',
  412. 'label' => $langs->trans("Bzip2")
  413. );
  414. $compression['zstd'] = array(
  415. 'function' => 'zstd_compress',
  416. 'id' => 'radio_compression_zstd',
  417. 'label' => $langs->trans("Zstd")
  418. );
  419. $compression['none'] = array(
  420. 'function' => '',
  421. 'id' => 'radio_compression_none',
  422. 'label' => $langs->trans("None")
  423. );
  424. } else {
  425. $compression['none'] = array(
  426. 'function' => '',
  427. 'id' => 'radio_compression_none',
  428. 'label' => $langs->trans("None")
  429. );
  430. $compression['gz'] = array(
  431. 'function' => 'gzopen',
  432. 'id' => 'radio_compression_gzip',
  433. 'label' => $langs->trans("Gzip")
  434. );
  435. }
  436. // Show compression choices
  437. print '<div class="formelementrow">';
  438. print "\n";
  439. print $langs->trans("Compression").': &nbsp; ';
  440. $i = 0;
  441. foreach ($compression as $key => $val) {
  442. if (!$val['function'] || function_exists($val['function'])) {
  443. // Enabled export format
  444. $checked = '';
  445. if ($key == 'gz') {
  446. $checked = ' checked';
  447. }
  448. print '<input type="radio" name="compression" value="'.$key.'" id="'.$val['id'].'"'.$checked.'>';
  449. print ' <label for="'.$val['id'].'">'.$val['label'].'</label>';
  450. } else {
  451. // Disabled export format
  452. print '<input type="radio" name="compression" value="'.$key.'" id="'.$val['id'].'" disabled>';
  453. print ' <label for="'.$val['id'].'">'.$val['label'].'</label>';
  454. print ' <span class="opacitymedium">('.$langs->trans("NotAvailable").')</span>';
  455. }
  456. print ' &nbsp; &nbsp; ';
  457. $i++;
  458. }
  459. print '</div>';
  460. print "\n";
  461. print "<!--</fieldset>--> <!-- End destination -->\n";
  462. print '<br>';
  463. print '<div class="center">';
  464. print '<input type="submit" class="button reposition" value="'.$langs->trans("GenerateBackup").'" id="buttonGo">';
  465. print '<br>';
  466. print '<br>';
  467. if (!empty($_SESSION["commandbackuplastdone"])) {
  468. print '<br><b>'.$langs->trans("RunCommandSummary").':</b><br>'."\n";
  469. print '<textarea rows="'.ROWS_2.'" class="centpercent">'.$_SESSION["commandbackuplastdone"].'</textarea><br>'."\n";
  470. print '<br>';
  471. //print $paramclear;
  472. // Now show result
  473. print '<b>'.$langs->trans("BackupResult").':</b> ';
  474. print $_SESSION["commandbackupresult"];
  475. $_SESSION["commandbackuplastdone"] = '';
  476. $_SESSION["commandbackuptorun"] = '';
  477. $_SESSION["commandbackupresult"] = '';
  478. }
  479. if (!empty($_SESSION["commandbackuptorun"])) {
  480. print '<br><span class="warning">'.$langs->trans("YouMustRunCommandFromCommandLineAfterLoginToUser", $dolibarr_main_db_user, $dolibarr_main_db_user).':</span><br>'."\n";
  481. print '<textarea id="commandbackuptoruntext" rows="'.ROWS_2.'" class="centpercent">'.$_SESSION["commandbackuptorun"].'</textarea><br>'."\n";
  482. print ajax_autoselect("commandbackuptoruntext", 0);
  483. print '<br>';
  484. //print $paramclear;
  485. $_SESSION["commandbackuplastdone"] = '';
  486. $_SESSION["commandbackuptorun"] = '';
  487. $_SESSION["commandbackupresult"] = '';
  488. }
  489. print "</div> <!-- end div center button -->\n";
  490. print '</td></tr>';
  491. print '</table>';
  492. print "</div> <!-- end div fichehalfleft -->\n";
  493. print '<div id="backupdatabaseright" class="fichehalfright">';
  494. $filearray = dol_dir_list($conf->admin->dir_output.'/backup', 'files', 0, '', '', $sortfield, (strtolower($sortorder) == 'asc' ?SORT_ASC:SORT_DESC), 1);
  495. $result = $formfile->list_of_documents($filearray, null, 'systemtools', '', 1, 'backup/', 1, 0, $langs->trans("NoBackupFileAvailable"), 0, $langs->trans("PreviousDumpFiles"), '', 0, -1, '', '', 'ASC', 1, 0, -1, 'style="height:480px; overflow: auto;"');
  496. print '<br>';
  497. print '</div>';
  498. print '</form>';
  499. print '</fieldset>';
  500. $title = $langs->trans("BackupZipWizard");
  501. print "<br>\n";
  502. print "<!-- Dump of a server -->\n";
  503. print '<form method="post" action="export_files.php" name="dump">';
  504. print '<input type="hidden" name="token" value="'.newToken().'" />';
  505. print '<input type="hidden" name="export_type" value="server" />';
  506. print '<input type="hidden" name="page_y" value="" />';
  507. print '<fieldset><legend class="legendforfieldsetstep" style="font-size: 3em">2</legend>';
  508. print '<span class="opacitymedium">';
  509. print $langs->trans("BackupDesc2", DOL_DATA_ROOT).'<br>';
  510. print $langs->trans("BackupDescX").'<br><br>';
  511. print '</span>';
  512. print '<div id="backupfilesleft" class="fichehalfleft">';
  513. print load_fiche_titre($title);
  514. print '<label for="zipfilename_template" class="line-height-large paddingbottom">'.$langs->trans("FileNameToGenerate").'</label><br>';
  515. $prefix = 'documents';
  516. $ext = 'zip';
  517. $file = $prefix.'_'.$dolibarr_main_db_name.'_'.dol_sanitizeFileName(DOL_VERSION).'_'.dol_print_date(dol_now('gmt'), "dayhourlogsmall", 'tzuser');
  518. print '<input type="text" name="zipfilename_template" style="width: 90%" id="zipfilename_template" value="'.$file.'" /> <br>';
  519. print '<br>';
  520. // Show compression choices
  521. // Example: With gz choice, you can compress in 5mn, a file of 2GB directory (after compression) with 10 Mb memory.
  522. print '<div class="formelementrow">';
  523. print "\n";
  524. print $langs->trans("Compression").': &nbsp; ';
  525. $filecompression = $compression;
  526. unset($filecompression['none']);
  527. $filecompression['zip'] = array('function' => 'dol_compress_dir', 'id' => 'radio_compression_zip', 'label' => $langs->trans("FormatZip"));
  528. $i = 0;
  529. foreach ($filecompression as $key => $val) {
  530. if (!$val['function'] || function_exists($val['function'])) { // Enabled export format
  531. $checked = '';
  532. if ($key == 'gz') {
  533. $checked = ' checked';
  534. }
  535. print '<input type="radio" name="compression" value="'.$key.'" id="'.$val['id'].'"'.$checked.'>';
  536. print ' <label for="'.$val['id'].'">'.$val['label'].'</label>';
  537. } else // Disabled export format
  538. {
  539. print '<input type="radio" name="compression" value="'.$key.'" id="'.$val['id'].'" disabled>';
  540. print ' <label for="'.$val['id'].'">'.$val['label'].'</label>';
  541. print ' <span class="opacitymedium">('.$langs->trans("NotAvailable").')</span>';
  542. }
  543. print ' &nbsp; &nbsp; ';
  544. $i++;
  545. }
  546. print '</div>';
  547. print "\n";
  548. print '<br>';
  549. print '<div class="center">';
  550. print '<input type="submit" class="button reposition" value="'.$langs->trans("GenerateBackup").'" id="buttonGo" /><br>';
  551. print '<br>';
  552. print '</div>';
  553. print '</div>';
  554. print '<div id="backupfileright" class="fichehalfright">';
  555. $filearray = dol_dir_list($conf->admin->dir_output.'/documents', 'files', 0, '', '', $sortfield, (strtolower($sortorder) == 'asc' ?SORT_ASC:SORT_DESC), 1);
  556. $result = $formfile->list_of_documents($filearray, null, 'systemtools', '', 1, 'documents/', 1, 0, $langs->trans("NoBackupFileAvailable"), 0, $langs->trans("PreviousArchiveFiles"), '', 0, -1, '', '', 'ASC', 1, 0, -1, 'style="height:250px; overflow: auto;"');
  557. print '<br>';
  558. print '</div>';
  559. print '</fieldset>';
  560. print '</form>';
  561. // End of page
  562. llxFooter();
  563. $db->close();