1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | database_migration - a plugin for Piwigo | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2010 Nicolas Roudaire http://www.nikrou.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | This program is free software; you can redistribute it and/or modify | |
---|
8 | // | it under the terms of the GNU General Public License version 2 as | |
---|
9 | // | published by the Free Software Foundation | |
---|
10 | // | | |
---|
11 | // | This program is distributed in the hope that it will be useful, but | |
---|
12 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
13 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
14 | // | 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, write to the Free Software | |
---|
18 | // | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
---|
19 | // | MA 02110-1301 USA | |
---|
20 | // +-----------------------------------------------------------------------+ |
---|
21 | |
---|
22 | if (!empty($_GET['dl']) && file_exists($conf['local_data_dir'].'/dm_'.$_GET['dl'])) |
---|
23 | { |
---|
24 | $filename = $conf['local_data_dir'].'/dm_'.$_GET['dl']; |
---|
25 | header('Cache-Control: no-cache, must-revalidate'); |
---|
26 | header('Pragma: no-cache'); |
---|
27 | header('Content-Disposition: attachment; filename="database.inc.php"'); |
---|
28 | header('Content-Transfer-Encoding: binary'); |
---|
29 | header('Content-Length: '.filesize($filename)); |
---|
30 | echo file_get_contents($filename); |
---|
31 | unlink($filename); |
---|
32 | exit(); |
---|
33 | } |
---|
34 | |
---|
35 | include_once DM_PLUGIN_ROOT . '/include/functions.inc.php'; |
---|
36 | |
---|
37 | load_language('install.lang', PHPWG_ROOT_PATH); |
---|
38 | |
---|
39 | $allConnections = $me->getAllConnections(); |
---|
40 | if (count($allConnections)>0) { |
---|
41 | foreach ($allConnections as $connection_dblayer => $connection) { |
---|
42 | $Connections[$connection_dblayer] = $connection['label']; |
---|
43 | } |
---|
44 | $GLOBALS['template']->assign('CONNECTIONS', $Connections); |
---|
45 | } else { |
---|
46 | $GLOBALS['template']->assign('U_DM_ADD_CONNECTION', $dm_base_url.'&tab=config&action=add'); |
---|
47 | } |
---|
48 | |
---|
49 | if (!empty($_POST['dblayer']) && isset($Connections[$_POST['dblayer']])) { |
---|
50 | $dblayer = $_POST['dblayer']; |
---|
51 | $connection = $me->getConnection($dblayer); |
---|
52 | $file_content = get_config_file_content($dblayer, $connection); |
---|
53 | |
---|
54 | $config_file = PHPWG_ROOT_PATH . 'local/config/database.inc.php'; |
---|
55 | save_mysql_config(); |
---|
56 | |
---|
57 | if ( !($fp=@fopen( $config_file, 'w' ))) { |
---|
58 | $tmp_filename = md5(uniqid('', true)); |
---|
59 | $fh = @fopen( $conf['local_data_dir'] . '/dm_' . $tmp_filename, 'w' ); |
---|
60 | @fputs($fh, $file_content, strlen($file_content)); |
---|
61 | @fclose($fh); |
---|
62 | |
---|
63 | $template->assign(array('config_creation_failed' => true, |
---|
64 | 'config_url' => $dm_base_url.'&tab=migration&dl='.$tmp_filename, |
---|
65 | 'config_file_content' => $file_content, |
---|
66 | ) |
---|
67 | ); |
---|
68 | } |
---|
69 | @fputs($fp, $file_content, strlen($file_content)); |
---|
70 | @fclose($fp); |
---|
71 | } |
---|
72 | ?> |
---|