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