dolibarr 23.0.3
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-2025 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
44// Load translation files required by the page
45$langs->loadLangs(array("other", "admin"));
46
47if (!$user->admin) {
49}
50
51$radio_dump = GETPOST('radio_dump');
52$action = GETPOST('action', 'aZ09');
53
54
55/*
56 * View
57 */
58
59$label = $db::LABEL;
60$type = $db->type;
61
62
63$help_url = 'EN:Restores|FR:Restaurations|ES:Restauraciones';
64llxHeader('', '', $help_url, '', 0, 0, '', '', '', 'mod-admin page-tools_dolibarr_import');
65
66?>
67<script type="text/javascript">
68jQuery(document).ready(function() {
69 jQuery("#mysql_options").<?php echo $radio_dump == 'mysql_options' ? 'show()' : 'hide()'; ?>;
70 jQuery("#postgresql_options").<?php echo $radio_dump == 'postgresql_options' ? 'show()' : 'hide()'; ?>;
71
72 jQuery("#radio_dump_mysql").click(function() {
73 jQuery("#mysql_options").show();
74 });
75 jQuery("#radio_dump_postgresql").click(function() {
76 jQuery("#postgresql_options").show();
77 });
78 <?php
79 if ($label == 'MySQL') {
80 print 'jQuery("#radio_dump_mysql").click();';
81 }
82 if ($label == 'PostgreSQL') {
83 print 'jQuery("#radio_dump_postgresql").click();';
84 }
85 ?>
86});
87</script>
88<?php
89
90print load_fiche_titre($langs->trans("Restore"), '', 'title_setup');
91
92print '<div class="center">';
93print $langs->trans("RestoreDesc", 3);
94print '</div>';
95print '<br>';
96print '<span class="small opacitymedium">'.$langs->trans("RestoreDescMore").'</span><br>';
97print '<br>';
98
99?>
100<fieldset>
101<legend style="font-size: 3em">1</legend>
102<?php
103print '<span class="opacitymedium">';
104print $langs->trans("RestoreDesc2", DOL_DATA_ROOT).'<br><br>';
105print '</span>';
106?>
107</fieldset>
108
109<br>
110
111<fieldset>
112<legend style="font-size: 3em">2</legend>
113<?php
114print '<span class="opacitymedium">';
115print $langs->trans("RestoreDesc3", $dolibarr_main_db_name).'<br><br>';
116print '</span>';
117?>
118
119<?php print $langs->trans("DatabaseName").' : <b>'.$dolibarr_main_db_name.'</b>'; ?><br><br>
120
121<table class="centpercent"><tr><td class="tdtop">
122
123<?php if ($conf->use_javascript_ajax) { ?>
124<div id="div_container_exportoptions">
125<fieldset id="exportoptions">
126 <legend><?php echo $langs->trans("ImportMethod"); ?></legend>
127 <?php
128 if (in_array($type, array('mysql', 'mysqli'))) {
129 ?>
130 <div class="formelementrow">
131 <input type="radio" name="what" value="mysql" id="radio_dump_mysql"<?php echo($radio_dump == 'mysql_options' ? ' checked' : ''); ?> />
132 <label for="radio_dump_mysql">MySQL (mysql)</label>
133 </div>
134 <?php
135 } elseif (in_array($type, array('pgsql'))) {
136 ?>
137 <div class="formelementrow">
138 <input type="radio" name="what" value="mysql" id="radio_dump_postgresql"<?php echo($radio_dump == 'postgresql_options' ? ' checked' : ''); ?> />
139 <label for="radio_dump_postgresql">PostgreSQL Restore (pg_restore or psql)</label>
140 </div>
141 <?php
142 } else {
143 print 'No method available with database '.$label;
144 }
145 ?>
146</fieldset>
147<br>
148</div>
149<?php } ?>
150
151</td><td class="tdtop">
152
153
154<div id="div_container_sub_exportoptions" >
155<?php
156if (in_array($type, array('mysql', 'mysqli'))) {
157 print '<fieldset id="mysql_options">';
158 print '<legend>'.$langs->trans('RestoreMySQL').'</legend>';
159 print '<div class="formelementrow centpercent">';
160
161 // Parameters execution
162 $command = $db->getPathOfRestore();
163 if (preg_match("/\s/", $command)) {
164 $command = $command = escapeshellarg($command); // Use quotes on command
165 }
166
167 $param = $dolibarr_main_db_name;
168 $param .= " -h ".$dolibarr_main_db_host;
169 if (!empty($dolibarr_main_db_port)) {
170 $param .= " -P ".$dolibarr_main_db_port;
171 }
172 $param .= " -u ".$dolibarr_main_db_user;
173 $paramcrypted = $param;
174 $paramclear = $param;
175 if (!empty($dolibarr_main_db_pass)) {
176 $paramcrypted .= " -p".preg_replace('/./i', '*', $dolibarr_main_db_pass);
177 $paramclear .= " -p".$dolibarr_main_db_pass;
178 }
179
180 print $langs->trans("ImportMySqlDesc");
181 print '<br>';
182 print '<textarea rows="1" id="restorecommand" class="centpercent" spellcheck="false">'.$langs->trans("ImportMySqlCommand", $command, ($action == 'showpass' ? $paramclear : $paramcrypted)).'</textarea><br>';
183 print ajax_autoselect('restorecommand');
184
185 if (GETPOST("action") != 'showpass' && $dolibarr_main_db_pass) {
186 print '<br><a href="'.$_SERVER["PHP_SELF"].'?action=showpass&token='.newToken().'&radio_dump=mysql_options">'.$langs->trans("UnHidePassword").'</a>';
187 }
188 //else print '<br><a href="'.$_SERVER["PHP_SELF"].'?radio_dump=mysql_options">'.$langs->trans("HidePassword").'</a>';
189 print '</div>';
190
191 print '</fieldset>';
192 print '<br>';
193} elseif (in_array($type, array('pgsql'))) {
194 print '<fieldset id="postgresql_options">';
195 print '<legend>Restore PostgreSQL</legend>';
196 print '<div class="formelementrow">';
197 // Parameters execution
198 $command = $db->getPathOfRestore();
199 if (preg_match("/\s/", $command)) {
200 $command = $command = escapeshellarg($command); // Use quotes on command
201 }
202
203 $param = " -d ".$dolibarr_main_db_name;
204 $param .= " -h ".$dolibarr_main_db_host;
205 if (!empty($dolibarr_main_db_port)) {
206 $param .= " -p ".$dolibarr_main_db_port;
207 }
208 $param .= " -U ".$dolibarr_main_db_user;
209 $paramcrypted = $param;
210 $paramclear = $param;
211 /*if (!empty($dolibarr_main_db_pass))
212 {
213 $paramcrypted.=" -p".preg_replace('/./i','*',$dolibarr_main_db_pass);
214 $paramclear.=" -p".$dolibarr_main_db_pass;
215 }*/
216 $paramcrypted .= " -W";
217 $paramclear .= " -W";
218 // With psql:
219 $paramcrypted .= " -f";
220 $paramclear .= " -f";
221
222 echo $langs->trans("ImportPostgreSqlDesc");
223 print '<br>';
224 print '<textarea rows="1" id="restorecommand" class="centpercent">'.$langs->trans("ImportPostgreSqlCommand", $command, ($action == 'showpass' ? $paramclear : $paramcrypted)).'</textarea><br>';
225 print ajax_autoselect('restorecommand');
226 print '</div>';
227
228 print '<br>';
229
230 print '</fieldset>';
231}
232
233print '</div>';
234
235
236print '</td></tr></table>';
237print '</fieldset>';
238
239
240
241print "<br>\n";
242print "<!-- Save setup conf -->\n";
243
244print '<fieldset><legend class="legendforfieldsetstep" style="font-size: 3em">3</legend>';
245
246print '<br>';
247
248print '<span class="opacitymedium">';
249print $langs->trans("RestoreDesc4", 'dolibarr_main_instance_unique_id '.$langs->transnoentitiesnoconv("or").' dolibarr_main_dolcrypt_key').'<br>';
250print '</span>';
251
252print '<br>';
253
254print '<div id="backupfileright">';
255
256print $langs->trans("SeeValueIntoConfPhp");
257//print $langs->trans("SeeValueIntoConfPhp2");
258print '<br>';
259
260print '<br>';
261
262print '</div>';
263
264print '</fieldset>';
265
266
267
268// End of page
269llxFooter();
270$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
treeview li table
No Email.
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition repair.php:125
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:128
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.