PageRenderTime 196ms CodeModel.GetById 71ms app.highlight 8ms RepoModel.GetById 72ms app.codeStats 25ms

/htdocs/admin/tools/dolibarr_import.php

https://github.com/asterix14/dolibarr
PHP | 187 lines | 126 code | 29 blank | 32 comment | 21 complexity | f16bcd9994fc60599fc66c4900777e9f MD5 | raw file
  1<?php
  2/* Copyright (C) 2006-2010 Laurent Destailleur  <eldy@users.sourceforge.net>
  3 *
  4 * This program is free software; you can redistribute it and/or modify
  5 * it under the terms of the GNU General Public License as published by
  6 * the Free Software Foundation; either version 2 of the License, or
  7 * (at your option) any later version.
  8 *
  9 * This program is distributed in the hope that it will be useful,
 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12 * GNU General Public License for more details.
 13 *
 14 * You should have received a copy of the GNU General Public License
 15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 16 */
 17
 18/**
 19 *		\file 		htdocs/admin/tools/dolibarr_import.php
 20 *		\ingroup	core
 21 * 		\brief      Page to import database
 22 */
 23
 24require("../../main.inc.php");
 25
 26$langs->load("admin");
 27$langs->load("other");
 28
 29if (! $user->admin)
 30  accessforbidden();
 31
 32
 33/*
 34 * View
 35 */
 36
 37llxHeader('','','EN:Restores|FR:Restaurations|ES:Restauraciones');
 38
 39?>
 40<script type="text/javascript">
 41jQuery(document).ready(function() {
 42	jQuery("#mysql_options").<?php echo GETPOST('radio_dump')=='mysql_options'?'show()':'hide()'; ?>;
 43	jQuery("#postgresql_options").<?php echo GETPOST('radio_dump')=='postgresql_options'?'show()':'hide()'; ?>;
 44
 45	jQuery("#radio_dump_mysql").click(function() {
 46		jQuery("#mysql_options").show();
 47	});
 48	jQuery("#radio_dump_postgresql").click(function() {
 49		jQuery("#postgresql_options").show();
 50	});
 51});
 52</script>
 53<?php
 54
 55print_fiche_titre($langs->trans("Restore"),'','setup');
 56
 57print $langs->trans("RestoreDesc",DOL_DATA_ROOT).'<br><br>';
 58print $langs->trans("RestoreDesc2",DOL_DATA_ROOT).'<br><br>';
 59print $langs->trans("RestoreDesc3",DOL_DATA_ROOT).'<br><br>';
 60
 61?>
 62
 63<fieldset id="fieldsetexport">
 64<?php print '<legend>'.$langs->trans("DatabaseName").' : <b>'.$dolibarr_main_db_name.'</b></legend>'; ?>
 65<table><tr><td valign="top">
 66
 67<?php if ($conf->use_javascript_ajax) { ?>
 68<div id="div_container_exportoptions">
 69<fieldset id="exportoptions">
 70	<legend><?php echo $langs->trans("ImportMethod"); ?></legend>
 71    <?php
 72    if ($db->label == 'MySQL')
 73    {
 74    ?>
 75    <div class="formelementrow">
 76        <input type="radio" name="what" value="mysql" id="radio_dump_mysql"	<?php echo ($_GET["radio_dump"]=='mysql_options'?' checked':''); ?> />
 77        <label for="radio_dump_mysql">MySQL (mysql)</label>
 78    </div>
 79    <?php
 80    }
 81    else if ($db->label == 'PostgreSQL')
 82    {
 83    ?>
 84    <div class="formelementrow">
 85        <input type="radio" name="what" value="mysql" id="radio_dump_postgresql" <?php echo ($_GET["radio_dump"]=='postgresql_options'?' checked':''); ?> />
 86        <label for="radio_dump_postgresql">PostgreSQL Restore (pg_restore)</label>
 87    </div>
 88    <?php
 89    }
 90    else
 91    {
 92        print 'No method available with database '.$db->label;
 93    }
 94    ?>
 95</fieldset>
 96</div>
 97<?php } ?>
 98
 99</td><td valign="top">
100
101
102<div id="div_container_sub_exportoptions">
103<?php
104if ($db->label == 'MySQL')
105{
106?>
107	<fieldset id="mysql_options">
108    <legend>Import MySql</legend>
109	<div class="formelementrow">
110	<?php
111	// Parameteres execution
112	$command=$db->getPathOfRestore();
113	if (preg_match("/\s/",$command)) $command=$command=escapeshellarg($command);	// Use quotes on command
114
115	$param=$dolibarr_main_db_name;
116	$param.=" -h ".$dolibarr_main_db_host;
117	if (! empty($dolibarr_main_db_port)) $param.=" -P ".$dolibarr_main_db_port;
118	$param.=" -u ".$dolibarr_main_db_user;
119	$paramcrypted=$param;
120	$paramclear=$param;
121	if (! empty($dolibarr_main_db_pass))
122	{
123		$paramcrypted.=" -p".preg_replace('/./i','*',$dolibarr_main_db_pass);
124		$paramclear.=" -p".$dolibarr_main_db_pass;
125	}
126
127	echo $langs->trans("ImportMySqlDesc");
128	print '<br>';
129	print '<textarea rows="1" cols="120">'.$langs->trans("ImportMySqlCommand",$command,$_GET["showpass"]?$paramclear:$paramcrypted).'</textarea><br>';
130
131	if (empty($_GET["showpass"]) && $dolibarr_main_db_pass) print '<br><a href="'.$_SERVER["PHP_SELF"].'?showpass=1&amp;radio_dump=mysql_options">'.$langs->trans("UnHidePassword").'</a>';
132	//else print '<br><a href="'.$_SERVER["PHP_SELF"].'?showpass=0&amp;radio_dump=mysql_options">'.$langs->trans("HidePassword").'</a>';
133	?>
134	</div>
135    </fieldset>
136<?php
137}
138else if ($db->label == 'PostgreSQL')
139{
140?>
141    <fieldset id="postgresql_options">
142    <legend>Restore PostgreSQL</legend>
143    <div class="formelementrow">
144    <?php
145    // Parameteres execution
146    $command=$db->getPathOfRestore();
147    if (preg_match("/\s/",$command)) $command=$command=escapeshellarg($command);    // Use quotes on command
148
149    $param=" -d ".$dolibarr_main_db_name;
150    $param.=" -h ".$dolibarr_main_db_host;
151    if (! empty($dolibarr_main_db_port)) $param.=" -p ".$dolibarr_main_db_port;
152    $param.=" -U ".$dolibarr_main_db_user;
153    $paramcrypted=$param;
154    $paramclear=$param;
155    /*if (! empty($dolibarr_main_db_pass))
156    {
157        $paramcrypted.=" -p".preg_replace('/./i','*',$dolibarr_main_db_pass);
158        $paramclear.=" -p".$dolibarr_main_db_pass;
159    }*/
160    $paramcrypted.=" -W";
161    $paramclear.=" -W";
162
163    echo $langs->trans("ImportPostgreSqlDesc");
164    print '<br>';
165    print '<textarea rows="1" cols="120">'.$langs->trans("ImportPostgreSqlCommand",$command,$_GET["showpass"]?$paramclear:$paramcrypted).'</textarea><br>';
166
167    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>';
168    //else print '<br><a href="'.$_SERVER["PHP_SELF"].'?showpass=0&amp;radio_dump=mysql_options">'.$langs->trans("HidePassword").'</a>';
169    ?>
170    </div>
171    </fieldset>
172<?php
173}
174?>
175
176</div>
177
178
179</td></tr></table>
180</fieldset>
181
182<?php
183
184$db->close();
185
186llxFooter();
187?>