PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/admin/tools/dolibarr_export.php

https://github.com/asterix14/dolibarr
PHP | 349 lines | 258 code | 64 blank | 27 comment | 22 complexity | 1b0c064cdbdced75d522e69acf539f92 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/admin/tools/dolibarr_export.php
  19. * \ingroup core
  20. * \brief Page to export database
  21. */
  22. require("../../main.inc.php");
  23. require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
  24. $langs->load("admin");
  25. if (! $user->admin)
  26. accessforbidden();
  27. $form=new Form($db);
  28. $formfile = new FormFile($db);
  29. /*
  30. * View
  31. */
  32. llxHeader('','','EN:Backups|FR:Sauvegardes|ES:Copias_de_seguridad');
  33. ?>
  34. <script type="text/javascript">
  35. jQuery(document).ready(function() {
  36. function hideoptions () {
  37. jQuery("#mysql_options").hide();
  38. jQuery("#mysql_options_nobin").hide();
  39. jQuery("#postgresql_options").hide();
  40. }
  41. hideoptions();
  42. jQuery("#radio_dump_mysql").click(function() {
  43. hideoptions();
  44. jQuery("#mysql_options").show();
  45. });
  46. jQuery("#radio_dump_mysql_nobin").click(function() {
  47. hideoptions();
  48. jQuery("#mysql_options_nobin").show();
  49. });
  50. jQuery("#radio_dump_postgresql").click(function() {
  51. hideoptions();
  52. jQuery("#postgresql_options").show();
  53. });
  54. });
  55. </script>
  56. <?php
  57. print_fiche_titre($langs->trans("Backup"),'','setup');
  58. print $langs->trans("BackupDesc",DOL_DATA_ROOT).'<br><br>';
  59. print $langs->trans("BackupDesc2",DOL_DATA_ROOT).'<br>';
  60. print $langs->trans("BackupDescX").'<br><br>';
  61. print $langs->trans("BackupDesc3",DOL_DATA_ROOT).'<br>';
  62. print $langs->trans("BackupDescY").'<br><br>';
  63. if ($_GET["msg"])
  64. {
  65. print '<div class="error">'.$_GET["msg"].'</div>';
  66. print '<br>';
  67. print "\n";
  68. }
  69. ?>
  70. <!-- Dump of a server -->
  71. <form method="post" action="export.php" name="dump"><input type="hidden"
  72. name="token" value="<?php echo $_SESSION['newtoken']; ?>" /> <input
  73. type="hidden" name="export_type" value="server" />
  74. <fieldset id="fieldsetexport">
  75. <?php print '<legend>'.$langs->trans("DatabaseName").' : <b>'.$dolibarr_main_db_name.'</b></legend>'; ?>
  76. <table>
  77. <tr>
  78. <td valign="top">
  79. <div id="div_container_exportoptions">
  80. <fieldset id="exportoptions"><legend><?php echo $langs->trans("ExportMethod"); ?></legend>
  81. <?php
  82. if ($db->label == 'MySQL')
  83. {
  84. ?>
  85. <div class="formelementrow"><input type="radio" name="what" value="mysql" id="radio_dump_mysql" />
  86. <label for="radio_dump_mysql">MySQL Dump (mysqldump)</label>
  87. </div>
  88. <?php if (! empty($conf->global->MAIN_FEATURES_LEVEL)) { ?>
  89. <div class="formelementrow"><input type="radio" name="what" value="mysqlnobin" id="radio_dump_mysql_nobin" />
  90. <label for="radio_dump_mysql">MySQL Dump (php) <?php print img_warning('Backup can\'t be guaranted with this method. Prefer previous one'); ?></label>
  91. </div>
  92. <?php
  93. }
  94. }
  95. else if ($db->label == 'PostgreSQL')
  96. {
  97. ?>
  98. <div class="formelementrow"><input type="radio" name="what" value="postgresql" id="radio_dump_postgresql" />
  99. <label for="radio_dump_postgresql">PostgreSQL Dump (pg_dump)</label>
  100. </div>
  101. <?php
  102. }
  103. else
  104. {
  105. print 'No method available with database '.$db->label;
  106. }
  107. ?>
  108. </fieldset>
  109. </div>
  110. </td>
  111. <td valign="top">
  112. <div id="div_container_sub_exportoptions">
  113. <?php
  114. if ($db->label == 'MySQL')
  115. {
  116. ?> <!-- Fieldset mysqldump -->
  117. <fieldset id="mysql_options"><legend><?php echo $langs->trans("MySqlExportParameters"); ?></legend>
  118. <div class="formelementrow"><?php echo $langs->trans("FullPathToMysqldumpCommand");
  119. if (empty($conf->global->SYSTEMTOOLS_MYSQLDUMP))
  120. {
  121. $fullpathofmysqldump=$db->getPathOfDump();
  122. }
  123. else
  124. {
  125. $fullpathofmysqldump=$conf->global->SYSTEMTOOLS_MYSQLDUMP;
  126. }
  127. ?><br>
  128. <input type="text" name="mysqldump" size="80"
  129. value="<?php echo $fullpathofmysqldump; ?>" /></div>
  130. <br>
  131. <fieldset><legend><?php echo $langs->trans("ExportOptions"); ?></legend>
  132. <div class="formelementrow"><input type="checkbox"
  133. name="use_transaction" value="yes" id="checkbox_use_transaction" /> <label
  134. for="checkbox_use_transaction"> <?php echo $langs->trans("UseTransactionnalMode"); ?></label>
  135. </div>
  136. <div class="formelementrow"><input type="checkbox" name="disable_fk"
  137. value="yes" id="checkbox_disable_fk" checked="checked" /> <label
  138. for="checkbox_disable_fk"> <?php echo $langs->trans("CommandsToDisableForeignKeysForImport"); ?></label>
  139. </div>
  140. <label for="select_sql_compat"> <?php echo $langs->trans("ExportCompatibility"); ?></label>
  141. <select name="sql_compat" id="select_sql_compat" class="flat">
  142. <option value="NONE" selected="selected">NONE</option>
  143. <option value="ANSI">ANSI</option>
  144. <option value="DB2">DB2</option>
  145. <option value="MAXDB">MAXDB</option>
  146. <option value="MYSQL323">MYSQL323</option>
  147. <option value="MYSQL40">MYSQL40</option>
  148. <option value="MSSQL">MSSQL</option>
  149. <option value="ORACLE">ORACLE</option>
  150. <option value="POSTGRESQL">POSTGRESQL</option>
  151. </select> <br>
  152. <!-- <input type="checkbox" name="drop_database" value="yes"
  153. id="checkbox_drop_database" /> <label for="checkbox_drop_database"><?php echo $langs->trans("AddDropDatabase"); ?></label>
  154. -->
  155. </fieldset>
  156. <br>
  157. <fieldset><legend> <input type="checkbox" name="sql_structure"
  158. value="structure" id="checkbox_sql_structure" checked="checked" /> <label
  159. for="checkbox_sql_structure"> Structure</label> </legend> <input
  160. type="checkbox" name="drop" value="1" id="checkbox_dump_drop" /> <label
  161. for="checkbox_dump_drop"><?php echo $langs->trans("AddDropTable"); ?></label><br>
  162. </fieldset>
  163. <br>
  164. <fieldset><legend> <input type="checkbox" name="sql_data" value="data"
  165. id="checkbox_sql_data" checked="checked" /> <label for="checkbox_sql_data">
  166. <?php echo $langs->trans("Datas"); ?></label> </legend> <input
  167. type="checkbox" name="showcolumns" value="yes"
  168. id="checkbox_dump_showcolumns" /> <label
  169. for="checkbox_dump_showcolumns"> <?php echo $langs->trans("NameColumn"); ?></label><br>
  170. <input type="checkbox" name="extended_ins" value="yes"
  171. id="checkbox_dump_extended_ins" /> <label
  172. for="checkbox_dump_extended_ins"> <?php echo $langs->trans("ExtendedInsert"); ?></label><br>
  173. <input type="checkbox" name="delayed" value="yes"
  174. id="checkbox_dump_delayed" /> <label for="checkbox_dump_delayed"> <?php echo $langs->trans("DelayedInsert"); ?></label><br>
  175. <input type="checkbox" name="sql_ignore" value="yes"
  176. id="checkbox_dump_ignore" /> <label for="checkbox_dump_ignore"> <?php echo $langs->trans("IgnoreDuplicateRecords"); ?></label><br>
  177. <input type="checkbox" name="hexforbinary" value="yes"
  178. id="checkbox_hexforbinary" checked="checked" /> <label
  179. for="checkbox_hexforbinary"> <?php echo $langs->trans("EncodeBinariesInHexa"); ?></label><br>
  180. </fieldset>
  181. </fieldset>
  182. <?php
  183. }
  184. if ($db->label == 'PostgreSQL')
  185. {
  186. ?> <!-- Fieldset pg_dump -->
  187. <fieldset id="postgresql_options"><legend><?php echo $langs->trans("PostgreSqlExportParameters"); ?></legend>
  188. <div class="formelementrow"><?php echo $langs->trans("FullPathToPostgreSQLdumpCommand");
  189. if (empty($conf->global->SYSTEMTOOLS_POSTGRESQLDUMP))
  190. {
  191. $fullpathofpgdump=$db->getPathOfDump();
  192. }
  193. else
  194. {
  195. $fullpathofpgdump=$conf->global->SYSTEMTOOLS_POSTGRESQLDUMP;
  196. }
  197. ?><br>
  198. <input type="text" name="postgresqldump" size="80"
  199. value="<?php echo $fullpathofpgdump; ?>" /></div>
  200. <br>
  201. <fieldset><legend><?php echo $langs->trans("ExportOptions"); ?></legend>
  202. <label for="select_sql_compat"> <?php echo $langs->trans("ExportCompatibility"); ?></label>
  203. <select name="sql_compat" id="select_sql_compat" class="flat">
  204. <option value="POSTGRESQL" selected="selected">POSTGRESQL</option>
  205. <option value="ANSI">ANSI</option>
  206. </select><br>
  207. <!-- <input type="checkbox" name="drop_database" value="yes"
  208. id="checkbox_drop_database" /> <label for="checkbox_drop_database"><?php echo $langs->trans("AddDropDatabase"); ?></label>
  209. -->
  210. </fieldset>
  211. <br>
  212. <fieldset><legend> <input type="checkbox" name="sql_structure"
  213. value="structure" id="checkbox_sql_structure" checked="checked" /> <label
  214. for="checkbox_sql_structure"> Structure</label> </legend></fieldset>
  215. <br>
  216. <fieldset><legend> <input type="checkbox" name="sql_data" value="data"
  217. id="checkbox_sql_data" checked="checked" /> <label for="checkbox_sql_data">
  218. <?php echo $langs->trans("Datas"); ?></label> </legend> <input
  219. type="checkbox" name="showcolumns" value="yes"
  220. id="checkbox_dump_showcolumns" /> <label
  221. for="checkbox_dump_showcolumns"> <?php echo $langs->trans("NameColumn"); ?></label><br>
  222. </fieldset>
  223. </fieldset>
  224. <?php
  225. }
  226. ?>
  227. </div>
  228. </td>
  229. </tr>
  230. </table>
  231. </fieldset>
  232. <fieldset><label for="filename_template"> <?php echo $langs->trans("FileNameToGenerate"); ?></label>:
  233. <input type="text" name="filename_template" size="60"
  234. id="filename_template"
  235. value="<?php
  236. $prefix='dump';
  237. if ($db->label == 'MySQL') $prefix='mysqldump';
  238. if ($db->label == 'PostgreSQL') $prefix='pg_dump';
  239. $file=$prefix.'_'.$dolibarr_main_db_name.'_'.dol_sanitizeFileName(DOL_VERSION).'_'.strftime("%Y%m%d%H%M").'.sql';
  240. echo $file;
  241. ?>" /> <br>
  242. <br>
  243. <?php
  244. // Define compressions array
  245. $compression=array(
  246. 'none' => array('function' => '', 'id' => 'radio_compression_none', 'label' => $langs->trans("None")),
  247. // 'zip' => array('function' => 'zip_open', 'id' => 'radio_compression_zip', 'label' => $langs->trans("Zip")), Not open source
  248. 'gz' => array('function' => 'gzopen', 'id' => 'radio_compression_gzip', 'label' => $langs->trans("Gzip")),
  249. );
  250. if ($db->label == 'MySQL')
  251. {
  252. $compression['bz']=array('function' => 'bzopen', 'id' => 'radio_compression_bzip', 'label' => $langs->trans("Bzip2"));
  253. }
  254. // Show compression choices
  255. print '<div class="formelementrow">';
  256. print "\n";
  257. print $langs->trans("Compression").': &nbsp; ';
  258. foreach($compression as $key => $val)
  259. {
  260. if (! $val['function'] || function_exists($val['function'])) // Enabled export format
  261. {
  262. print '<input type="radio" name="compression" value="'.$key.'" id="'.$val['id'].'" checked="checked">';
  263. print ' <label for="'.$val['id'].'">'.$val['label'].'</label>';
  264. }
  265. else // Disabled export format
  266. {
  267. print '<input type="radio" name="compression" value="'.$key.'" id="'.$val['id'].'" disabled="disabled">';
  268. print ' <label for="'.$val['id'].'">'.$val['label'].'</label>';
  269. print ' ('.$langs->trans("NotAvailable").')';
  270. }
  271. print ' &nbsp; &nbsp; ';
  272. }
  273. print '</div>';
  274. print "\n";
  275. ?></fieldset>
  276. <center><input type="submit" class="button"
  277. value="<?php echo $langs->trans("GenerateBackup") ?>" id="buttonGo" /><br>
  278. <br>
  279. </center>
  280. </form>
  281. <?php
  282. $result=$formfile->show_documents('systemtools','backup',$conf->admin->dir_output.'/backup',$_SERVER['PHP_SELF'],0,1,'',1,0,0,54,0,'',$langs->trans("PreviousDumpFiles"));
  283. //if ($result) print '<br><br>';
  284. llxFooter();
  285. $db->close();