dolibarr  16.0.5
dolibarr_import.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2006-2021 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2006-2012 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 
25 if (! defined('CSRFCHECK_WITH_TOKEN')) {
26  define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
27 }
28 
29 require '../../main.inc.php';
30 
31 // Load translation files required by the page
32 $langs->loadLangs(array("other", "admin"));
33 
34 if (!$user->admin) {
36 }
37 
38 $radio_dump = GETPOST('radio_dump');
39 $showpass = GETPOST('showpass');
40 
41 
42 /*
43  * View
44  */
45 
46 $label = $db::LABEL;
47 $type = $db->type;
48 
49 
50 $help_url = 'EN:Restores|FR:Restaurations|ES:Restauraciones';
51 llxHeader('', '', $help_url);
52 
53 ?>
54 <script type="text/javascript">
55 jQuery(document).ready(function() {
56  jQuery("#mysql_options").<?php echo $radio_dump == 'mysql_options' ? 'show()' : 'hide()'; ?>;
57  jQuery("#postgresql_options").<?php echo $radio_dump == 'postgresql_options' ? 'show()' : 'hide()'; ?>;
58 
59  jQuery("#radio_dump_mysql").click(function() {
60  jQuery("#mysql_options").show();
61  });
62  jQuery("#radio_dump_postgresql").click(function() {
63  jQuery("#postgresql_options").show();
64  });
65  <?php
66  if ($label == 'MySQL') {
67  print 'jQuery("#radio_dump_mysql").click();';
68  }
69  if ($label == 'PostgreSQL') {
70  print 'jQuery("#radio_dump_postgresql").click();';
71  }
72  ?>
73 });
74 </script>
75 <?php
76 
77 print load_fiche_titre($langs->trans("Restore"), '', 'title_setup');
78 
79 print '<div class="center">';
80 print $langs->trans("RestoreDesc", DOL_DATA_ROOT);
81 print '</div>';
82 print '<br>';
83 
84 ?>
85 <fieldset>
86 <legend style="font-size: 3em">1</legend>
87 <?php
88 print '<span class="opacitymedium">';
89 print $langs->trans("RestoreDesc2", DOL_DATA_ROOT).'<br><br>';
90 print '</span>';
91 ?>
92 </fieldset>
93 
94 <br>
95 
96 <fieldset>
97 <legend style="font-size: 3em">2</legend>
98 <?php
99 print '<span class="opacitymedium">';
100 print $langs->trans("RestoreDesc3", $dolibarr_main_db_name).'<br><br>';
101 print '</span>';
102 ?>
103 
104 <?php print $langs->trans("DatabaseName").' : <b>'.$dolibarr_main_db_name.'</b>'; ?><br><br>
105 
106 <table class="centpercent"><tr><td class="tdtop">
107 
108 <?php if ($conf->use_javascript_ajax) { ?>
109 <div id="div_container_exportoptions">
110 <fieldset id="exportoptions">
111  <legend><?php echo $langs->trans("ImportMethod"); ?></legend>
112  <?php
113  if (in_array($type, array('mysql', 'mysqli'))) {
114  ?>
115  <div class="formelementrow">
116  <input type="radio" name="what" value="mysql" id="radio_dump_mysql"<?php echo ($radio_dump == 'mysql_options' ? ' checked' : ''); ?> />
117  <label for="radio_dump_mysql">MySQL (mysql)</label>
118  </div>
119  <?php
120  } elseif (in_array($type, array('pgsql'))) {
121  ?>
122  <div class="formelementrow">
123  <input type="radio" name="what" value="mysql" id="radio_dump_postgresql"<?php echo ($radio_dump == 'postgresql_options' ? ' checked' : ''); ?> />
124  <label for="radio_dump_postgresql">PostgreSQL Restore (pg_restore or psql)</label>
125  </div>
126  <?php
127  } else {
128  print 'No method available with database '.$label;
129  }
130  ?>
131 </fieldset>
132 </div>
133 <?php } ?>
134 
135 </td><td class="tdtop">
136 
137 
138 <div id="div_container_sub_exportoptions" >
139 <?php
140 if (in_array($type, array('mysql', 'mysqli'))) {
141  print '<fieldset id="mysql_options">';
142  print '<legend>'.$langs->trans('RestoreMySQL').'</legend>';
143  print '<div class="formelementrow centpercent">';
144  // Parameteres execution
145  $command = $db->getPathOfRestore();
146  if (preg_match("/\s/", $command)) {
147  $command = $command = escapeshellarg($command); // Use quotes on command
148  }
149 
150  $param = $dolibarr_main_db_name;
151  $param .= " -h ".$dolibarr_main_db_host;
152  if (!empty($dolibarr_main_db_port)) {
153  $param .= " -P ".$dolibarr_main_db_port;
154  }
155  $param .= " -u ".$dolibarr_main_db_user;
156  $paramcrypted = $param;
157  $paramclear = $param;
158  if (!empty($dolibarr_main_db_pass)) {
159  $paramcrypted .= " -p".preg_replace('/./i', '*', $dolibarr_main_db_pass);
160  $paramclear .= " -p".$dolibarr_main_db_pass;
161  }
162 
163  echo $langs->trans("ImportMySqlDesc");
164  print '<br>';
165  print '<textarea rows="1" id="restorecommand" class="centpercent">'.$langs->trans("ImportMySqlCommand", $command, ($showpass ? $paramclear : $paramcrypted)).'</textarea><br>';
166  print ajax_autoselect('restorecommand');
167 
168  if (empty($_GET["showpass"]) && $dolibarr_main_db_pass) {
169  print '<br><a href="'.$_SERVER["PHP_SELF"].'?showpass=1&amp;radio_dump=mysql_options">'.$langs->trans("UnHidePassword").'</a>';
170  }
171  //else print '<br><a href="'.$_SERVER["PHP_SELF"].'?showpass=0&amp;radio_dump=mysql_options">'.$langs->trans("HidePassword").'</a>';
172  print '</div>';
173  print '</fieldset>';
174 } elseif (in_array($type, array('pgsql'))) {
175  print '<fieldset id="postgresql_options">';
176  print '<legend>Restore PostgreSQL</legend>';
177  print '<div class="formelementrow">';
178  // Parameteres execution
179  $command = $db->getPathOfRestore();
180  if (preg_match("/\s/", $command)) {
181  $command = $command = escapeshellarg($command); // Use quotes on command
182  }
183 
184  $param = " -d ".$dolibarr_main_db_name;
185  $param .= " -h ".$dolibarr_main_db_host;
186  if (!empty($dolibarr_main_db_port)) {
187  $param .= " -p ".$dolibarr_main_db_port;
188  }
189  $param .= " -U ".$dolibarr_main_db_user;
190  $paramcrypted = $param;
191  $paramclear = $param;
192  /*if (!empty($dolibarr_main_db_pass))
193  {
194  $paramcrypted.=" -p".preg_replace('/./i','*',$dolibarr_main_db_pass);
195  $paramclear.=" -p".$dolibarr_main_db_pass;
196  }*/
197  $paramcrypted .= " -W";
198  $paramclear .= " -W";
199  // With psql:
200  $paramcrypted .= " -f";
201  $paramclear .= " -f";
202 
203  echo $langs->trans("ImportPostgreSqlDesc");
204  print '<br>';
205  print '<textarea rows="1" id="restorecommand" class="centpercent">'.$langs->trans("ImportPostgreSqlCommand", $command, ($showpass ? $paramclear : $paramcrypted)).'</textarea><br>';
206  print ajax_autoselect('restorecommand');
207  //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>';
208  //else print '<br><a href="'.$_SERVER["PHP_SELF"].'?showpass=0&amp;radio_dump=mysql_options">'.$langs->trans("HidePassword").'</a>';
209  print '</div>';
210 
211  print '<br>';
212 
213  print '</fieldset>';
214 }
215 
216 print '</div>';
217 
218 
219 print '</td></tr></table>';
220 print '</fieldset>';
221 
222 // End of page
223 llxFooter();
224 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
name
$conf db name
Definition: repair.php:122
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
accessforbidden
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 ...
Definition: security.lib.php:933
ajax_autoselect
ajax_autoselect($htmlname, $addlink='', $textonlink='Link')
Make content of an input box selected when we click into input field.
Definition: functions.lib.php:9681
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59