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 | define('DEFAULT_DB_SQLITE', 'native'); |
---|
23 | |
---|
24 | load_language('install.lang', PHPWG_ROOT_PATH); |
---|
25 | |
---|
26 | include_once PHPWG_ROOT_PATH . 'admin/include/functions_install.inc.php'; |
---|
27 | |
---|
28 | $Params = array('db_host', 'db_user', 'db_password', 'db_base'); |
---|
29 | $extraParams = array('prefix'); |
---|
30 | $mandatoryParams['sqlite'] = array('db_base'); |
---|
31 | $mandatoryParams['pgsql'] = array('db_host', 'db_user', 'db_password', 'db_base'); |
---|
32 | |
---|
33 | $dblayer = ''; |
---|
34 | $default_prefix = 'piwigo_'; |
---|
35 | $Actions = array('add', 'edit', 'del'); |
---|
36 | $action = null; |
---|
37 | |
---|
38 | foreach (available_engines() as $key => $engine) { |
---|
39 | if ($key=='mysql') { |
---|
40 | continue; |
---|
41 | } |
---|
42 | $engines[$key] = $engine['label']; |
---|
43 | } |
---|
44 | |
---|
45 | $Connections = $me->getAllConnections(); |
---|
46 | $connection = array('prefix' => $default_prefix); |
---|
47 | |
---|
48 | if (!empty($_GET['action']) && in_array($_GET['action'], $Actions)) { |
---|
49 | $action = $_GET['action']; |
---|
50 | } |
---|
51 | |
---|
52 | if ($action=='del') { |
---|
53 | if (empty($_GET['id']) || ($connection = $me->getConnection($_GET['id']))==null) { |
---|
54 | $action = null; |
---|
55 | } else { |
---|
56 | $me->removeConnection($_GET['id']); |
---|
57 | $me->save_config(); |
---|
58 | $_SESSION['dm_messages']['infos'] = l10n('Connection deleted successfully'); |
---|
59 | redirect($dm_base_url.'&tab=config'); |
---|
60 | } |
---|
61 | } |
---|
62 | |
---|
63 | if ($action=='edit') { |
---|
64 | if (empty($_GET['id']) || ($connection = $me->getConnection($_GET['id']))==null) { |
---|
65 | $action = null; |
---|
66 | } else { |
---|
67 | $dblayer = $_GET['id']; |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | if (($action=='add') || ($action=='edit')) { |
---|
72 | if (!empty($_POST) && isset($_POST['dblayer'])) { |
---|
73 | $dblayer = $_POST['dblayer']; |
---|
74 | |
---|
75 | foreach ($Params as $param) { |
---|
76 | if (!empty($_POST[$param]) && in_array($param, $mandatoryParams[$dblayer])) { |
---|
77 | $connection[$param] = trim($_POST[$param]," /\n\t\r\0\x0B"); |
---|
78 | } elseif (in_array($param, $mandatoryParams[$dblayer])) { |
---|
79 | $GLOBALS['page']['errors'][] = l10n(sprintf('%s is required', ucfirst($param))); |
---|
80 | } else { |
---|
81 | $connection[$param] = ''; |
---|
82 | } |
---|
83 | } |
---|
84 | foreach ($extraParams as $param) { |
---|
85 | if (!empty($_POST[$param])) { |
---|
86 | $connection[$param] = trim($_POST['prefix'], " /\n\t\r\0\x0B"); |
---|
87 | } else { |
---|
88 | $connection[$param] = ''; |
---|
89 | } |
---|
90 | } |
---|
91 | } |
---|
92 | |
---|
93 | if (!empty($_POST) && count($GLOBALS['page']['errors'])==0) { |
---|
94 | $connection['label'] = $engines[$dblayer]; |
---|
95 | $me->addConnection($dblayer, $connection); |
---|
96 | $me->save_config(); |
---|
97 | if ($action=='add') { |
---|
98 | $_SESSION['dm_messages']['infos'] = l10n('Connection added successfully'); |
---|
99 | } else { |
---|
100 | $_SESSION['dm_messages']['infos'] = l10n('Connection updated successfully'); |
---|
101 | } |
---|
102 | redirect($dm_base_url.'&tab=config'); |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | if ($action=='edit' || $action=='add') { |
---|
107 | foreach ($Params as $param) { |
---|
108 | if (!empty($connection[$param])) { |
---|
109 | $GLOBALS['template']->assign(strtoupper($param), $connection[$param]); |
---|
110 | } |
---|
111 | } |
---|
112 | foreach ($extraParams as $param) { |
---|
113 | $GLOBALS['template']->assign(strtoupper($param), $connection[$param]); |
---|
114 | } |
---|
115 | $GLOBALS['template']->assign('DBLAYER', $dblayer); |
---|
116 | } |
---|
117 | |
---|
118 | if (count($Connections)>0) { |
---|
119 | $GLOBALS['template']->assign('CONNECTIONS', $Connections); |
---|
120 | } |
---|
121 | |
---|
122 | $GLOBALS['template']->assign('DM_ACTION', $action); |
---|
123 | $GLOBALS['template']->assign('F_DB_ENGINES', $engines); |
---|
124 | $GLOBALS['template']->assign('U_DM_LIST', $dm_base_url.'&tab=config'); |
---|
125 | $GLOBALS['template']->assign('U_DM_ADD_CONNECTION', $dm_base_url.'&tab=config&action=add'); |
---|
126 | $GLOBALS['template']->assign('U_DM_DELETE_CONNECTION', $dm_base_url.'&tab=config&action=del&id='); |
---|
127 | $GLOBALS['template']->assign('U_DM_EDIT_CONNECTION', $dm_base_url.'&tab=config&action=edit&id='); |
---|
128 | ?> |
---|