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