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

/htdocs/admin/tools/dolibarr_import.php

https://github.com/asterix14/dolibarr
PHP | 187 lines | 126 code | 29 blank | 32 comment | 21 complexity | f16bcd9994fc60599fc66c4900777e9f MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2006-2010 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_import.php
  19. * \ingroup core
  20. * \brief Page to import database
  21. */
  22. require("../../main.inc.php");
  23. $langs->load("admin");
  24. $langs->load("other");
  25. if (! $user->admin)
  26. accessforbidden();
  27. /*
  28. * View
  29. */
  30. llxHeader('','','EN:Restores|FR:Restaurations|ES:Restauraciones');
  31. ?>
  32. <script type="text/javascript">
  33. jQuery(document).ready(function() {
  34. jQuery("#mysql_options").<?php echo GETPOST('radio_dump')=='mysql_options'?'show()':'hide()'; ?>;
  35. jQuery("#postgresql_options").<?php echo GETPOST('radio_dump')=='postgresql_options'?'show()':'hide()'; ?>;
  36. jQuery("#radio_dump_mysql").click(function() {
  37. jQuery("#mysql_options").show();
  38. });
  39. jQuery("#radio_dump_postgresql").click(function() {
  40. jQuery("#postgresql_options").show();
  41. });
  42. });
  43. </script>
  44. <?php
  45. print_fiche_titre($langs->trans("Restore"),'','setup');
  46. print $langs->trans("RestoreDesc",DOL_DATA_ROOT).'<br><br>';
  47. print $langs->trans("RestoreDesc2",DOL_DATA_ROOT).'<br><br>';
  48. print $langs->trans("RestoreDesc3",DOL_DATA_ROOT).'<br><br>';
  49. ?>
  50. <fieldset id="fieldsetexport">
  51. <?php print '<legend>'.$langs->trans("DatabaseName").' : <b>'.$dolibarr_main_db_name.'</b></legend>'; ?>
  52. <table><tr><td valign="top">
  53. <?php if ($conf->use_javascript_ajax) { ?>
  54. <div id="div_container_exportoptions">
  55. <fieldset id="exportoptions">
  56. <legend><?php echo $langs->trans("ImportMethod"); ?></legend>
  57. <?php
  58. if ($db->label == 'MySQL')
  59. {
  60. ?>
  61. <div class="formelementrow">
  62. <input type="radio" name="what" value="mysql" id="radio_dump_mysql" <?php echo ($_GET["radio_dump"]=='mysql_options'?' checked':''); ?> />
  63. <label for="radio_dump_mysql">MySQL (mysql)</label>
  64. </div>
  65. <?php
  66. }
  67. else if ($db->label == 'PostgreSQL')
  68. {
  69. ?>
  70. <div class="formelementrow">
  71. <input type="radio" name="what" value="mysql" id="radio_dump_postgresql" <?php echo ($_GET["radio_dump"]=='postgresql_options'?' checked':''); ?> />
  72. <label for="radio_dump_postgresql">PostgreSQL Restore (pg_restore)</label>
  73. </div>
  74. <?php
  75. }
  76. else
  77. {
  78. print 'No method available with database '.$db->label;
  79. }
  80. ?>
  81. </fieldset>
  82. </div>
  83. <?php } ?>
  84. </td><td valign="top">
  85. <div id="div_container_sub_exportoptions">
  86. <?php
  87. if ($db->label == 'MySQL')
  88. {
  89. ?>
  90. <fieldset id="mysql_options">
  91. <legend>Import MySql</legend>
  92. <div class="formelementrow">
  93. <?php
  94. // Parameteres execution
  95. $command=$db->getPathOfRestore();
  96. if (preg_match("/\s/",$command)) $command=$command=escapeshellarg($command); // Use quotes on command
  97. $param=$dolibarr_main_db_name;
  98. $param.=" -h ".$dolibarr_main_db_host;
  99. if (! empty($dolibarr_main_db_port)) $param.=" -P ".$dolibarr_main_db_port;
  100. $param.=" -u ".$dolibarr_main_db_user;
  101. $paramcrypted=$param;
  102. $paramclear=$param;
  103. if (! empty($dolibarr_main_db_pass))
  104. {
  105. $paramcrypted.=" -p".preg_replace('/./i','*',$dolibarr_main_db_pass);
  106. $paramclear.=" -p".$dolibarr_main_db_pass;
  107. }
  108. echo $langs->trans("ImportMySqlDesc");
  109. print '<br>';
  110. print '<textarea rows="1" cols="120">'.$langs->trans("ImportMySqlCommand",$command,$_GET["showpass"]?$paramclear:$paramcrypted).'</textarea><br>';
  111. if (empty($_GET["showpass"]) && $dolibarr_main_db_pass) print '<br><a href="'.$_SERVER["PHP_SELF"].'?showpass=1&amp;radio_dump=mysql_options">'.$langs->trans("UnHidePassword").'</a>';
  112. //else print '<br><a href="'.$_SERVER["PHP_SELF"].'?showpass=0&amp;radio_dump=mysql_options">'.$langs->trans("HidePassword").'</a>';
  113. ?>
  114. </div>
  115. </fieldset>
  116. <?php
  117. }
  118. else if ($db->label == 'PostgreSQL')
  119. {
  120. ?>
  121. <fieldset id="postgresql_options">
  122. <legend>Restore PostgreSQL</legend>
  123. <div class="formelementrow">
  124. <?php
  125. // Parameteres execution
  126. $command=$db->getPathOfRestore();
  127. if (preg_match("/\s/",$command)) $command=$command=escapeshellarg($command); // Use quotes on command
  128. $param=" -d ".$dolibarr_main_db_name;
  129. $param.=" -h ".$dolibarr_main_db_host;
  130. if (! empty($dolibarr_main_db_port)) $param.=" -p ".$dolibarr_main_db_port;
  131. $param.=" -U ".$dolibarr_main_db_user;
  132. $paramcrypted=$param;
  133. $paramclear=$param;
  134. /*if (! empty($dolibarr_main_db_pass))
  135. {
  136. $paramcrypted.=" -p".preg_replace('/./i','*',$dolibarr_main_db_pass);
  137. $paramclear.=" -p".$dolibarr_main_db_pass;
  138. }*/
  139. $paramcrypted.=" -W";
  140. $paramclear.=" -W";
  141. echo $langs->trans("ImportPostgreSqlDesc");
  142. print '<br>';
  143. print '<textarea rows="1" cols="120">'.$langs->trans("ImportPostgreSqlCommand",$command,$_GET["showpass"]?$paramclear:$paramcrypted).'</textarea><br>';
  144. if (empty($_GET["showpass"]) && $dolibarr_main_db_pass) print '<br><a href="'.$_SERVER["PHP_SELF"].'?showpass=1&amp;radio_dump=postgresql_options">'.$langs->trans("UnHidePassword").'</a>';
  145. //else print '<br><a href="'.$_SERVER["PHP_SELF"].'?showpass=0&amp;radio_dump=mysql_options">'.$langs->trans("HidePassword").'</a>';
  146. ?>
  147. </div>
  148. </fieldset>
  149. <?php
  150. }
  151. ?>
  152. </div>
  153. </td></tr></table>
  154. </fieldset>
  155. <?php
  156. $db->close();
  157. llxFooter();
  158. ?>