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