dolibarr 21.0.0-beta
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26if (! defined('CSRFCHECK_WITH_TOKEN')) {
27 define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
28}
29
30// Load Dolibarr environment
31require '../../main.inc.php';
32
41// Load translation files required by the page
42$langs->loadLangs(array("other", "admin"));
43
44if (!$user->admin) {
46}
47
48$radio_dump = GETPOST('radio_dump');
49$action = GETPOST('action', 'aZ09');
50
51
52/*
53 * View
54 */
55
56$label = $db::LABEL;
57$type = $db->type;
58
59
60$help_url = 'EN:Restores|FR:Restaurations|ES:Restauraciones';
61llxHeader('', '', $help_url, '', 0, 0, '', '', '', 'mod-admin page-tools_dolibarr_import');
62
63?>
64<script type="text/javascript">
65jQuery(document).ready(function() {
66 jQuery("#mysql_options").<?php echo $radio_dump == 'mysql_options' ? 'show()' : 'hide()'; ?>;
67 jQuery("#postgresql_options").<?php echo $radio_dump == 'postgresql_options' ? 'show()' : 'hide()'; ?>;
68
69 jQuery("#radio_dump_mysql").click(function() {
70 jQuery("#mysql_options").show();
71 });
72 jQuery("#radio_dump_postgresql").click(function() {
73 jQuery("#postgresql_options").show();
74 });
75 <?php
76 if ($label == 'MySQL') {
77 print 'jQuery("#radio_dump_mysql").click();';
78 }
79 if ($label == 'PostgreSQL') {
80 print 'jQuery("#radio_dump_postgresql").click();';
81 }
82 ?>
83});
84</script>
85<?php
86
87print load_fiche_titre($langs->trans("Restore"), '', 'title_setup');
88
89print '<div class="center">';
90print $langs->trans("RestoreDesc", DOL_DATA_ROOT);
91print '</div>';
92print '<br>';
93
94?>
95<fieldset>
96<legend style="font-size: 3em">1</legend>
97<?php
98print '<span class="opacitymedium">';
99print $langs->trans("RestoreDesc2", DOL_DATA_ROOT).'<br><br>';
100print '</span>';
101?>
102</fieldset>
103
104<br>
105
106<fieldset>
107<legend style="font-size: 3em">2</legend>
108<?php
109print '<span class="opacitymedium">';
110print $langs->trans("RestoreDesc3", $dolibarr_main_db_name).'<br><br>';
111print '</span>';
112?>
113
114<?php print $langs->trans("DatabaseName").' : <b>'.$dolibarr_main_db_name.'</b>'; ?><br><br>
115
116<table class="centpercent"><tr><td class="tdtop">
117
118<?php if ($conf->use_javascript_ajax) { ?>
119<div id="div_container_exportoptions">
120<fieldset id="exportoptions">
121 <legend><?php echo $langs->trans("ImportMethod"); ?></legend>
122 <?php
123 if (in_array($type, array('mysql', 'mysqli'))) {
124 ?>
125 <div class="formelementrow">
126 <input type="radio" name="what" value="mysql" id="radio_dump_mysql"<?php echo($radio_dump == 'mysql_options' ? ' checked' : ''); ?> />
127 <label for="radio_dump_mysql">MySQL (mysql)</label>
128 </div>
129 <?php
130 } elseif (in_array($type, array('pgsql'))) {
131 ?>
132 <div class="formelementrow">
133 <input type="radio" name="what" value="mysql" id="radio_dump_postgresql"<?php echo($radio_dump == 'postgresql_options' ? ' checked' : ''); ?> />
134 <label for="radio_dump_postgresql">PostgreSQL Restore (pg_restore or psql)</label>
135 </div>
136 <?php
137 } else {
138 print 'No method available with database '.$label;
139 }
140 ?>
141</fieldset>
142</div>
143<?php } ?>
144
145</td><td class="tdtop">
146
147
148<div id="div_container_sub_exportoptions" >
149<?php
150if (in_array($type, array('mysql', 'mysqli'))) {
151 print '<fieldset id="mysql_options">';
152 print '<legend>'.$langs->trans('RestoreMySQL').'</legend>';
153 print '<div class="formelementrow centpercent">';
154
155 // Parameters execution
156 $command = $db->getPathOfRestore();
157 if (preg_match("/\s/", $command)) {
158 $command = $command = escapeshellarg($command); // Use quotes on command
159 }
160
161 $param = $dolibarr_main_db_name;
162 $param .= " -h ".$dolibarr_main_db_host;
163 if (!empty($dolibarr_main_db_port)) {
164 $param .= " -P ".$dolibarr_main_db_port;
165 }
166 $param .= " -u ".$dolibarr_main_db_user;
167 $paramcrypted = $param;
168 $paramclear = $param;
169 if (!empty($dolibarr_main_db_pass)) {
170 $paramcrypted .= " -p".preg_replace('/./i', '*', $dolibarr_main_db_pass);
171 $paramclear .= " -p".$dolibarr_main_db_pass;
172 }
173
174 print $langs->trans("ImportMySqlDesc");
175 print '<br>';
176 print '<textarea rows="1" id="restorecommand" class="centpercent">'.$langs->trans("ImportMySqlCommand", $command, ($action == 'showpass' ? $paramclear : $paramcrypted)).'</textarea><br>';
177 print ajax_autoselect('restorecommand');
178
179 if (GETPOST("action") != 'showpass' && $dolibarr_main_db_pass) {
180 print '<br><a href="'.$_SERVER["PHP_SELF"].'?action=showpass&token='.newToken().'&radio_dump=mysql_options">'.$langs->trans("UnHidePassword").'</a>';
181 }
182 //else print '<br><a href="'.$_SERVER["PHP_SELF"].'?radio_dump=mysql_options">'.$langs->trans("HidePassword").'</a>';
183 print '</div>';
184 print '</fieldset>';
185} elseif (in_array($type, array('pgsql'))) {
186 print '<fieldset id="postgresql_options">';
187 print '<legend>Restore PostgreSQL</legend>';
188 print '<div class="formelementrow">';
189 // Parameters execution
190 $command = $db->getPathOfRestore();
191 if (preg_match("/\s/", $command)) {
192 $command = $command = escapeshellarg($command); // Use quotes on command
193 }
194
195 $param = " -d ".$dolibarr_main_db_name;
196 $param .= " -h ".$dolibarr_main_db_host;
197 if (!empty($dolibarr_main_db_port)) {
198 $param .= " -p ".$dolibarr_main_db_port;
199 }
200 $param .= " -U ".$dolibarr_main_db_user;
201 $paramcrypted = $param;
202 $paramclear = $param;
203 /*if (!empty($dolibarr_main_db_pass))
204 {
205 $paramcrypted.=" -p".preg_replace('/./i','*',$dolibarr_main_db_pass);
206 $paramclear.=" -p".$dolibarr_main_db_pass;
207 }*/
208 $paramcrypted .= " -W";
209 $paramclear .= " -W";
210 // With psql:
211 $paramcrypted .= " -f";
212 $paramclear .= " -f";
213
214 echo $langs->trans("ImportPostgreSqlDesc");
215 print '<br>';
216 print '<textarea rows="1" id="restorecommand" class="centpercent">'.$langs->trans("ImportPostgreSqlCommand", $command, ($action == 'showpass' ? $paramclear : $paramcrypted)).'</textarea><br>';
217 print ajax_autoselect('restorecommand');
218 print '</div>';
219
220 print '<br>';
221
222 print '</fieldset>';
223}
224
225print '</div>';
226
227
228print '</td></tr></table>';
229print '</fieldset>';
230
231// End of page
232llxFooter();
233$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
llxFooter()
Footer empty.
Definition document.php:107
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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:149
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:152
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.