r883: - Updating the Admin CP navigation system
[bugdar.git] / admin / language.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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 as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
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 MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 require_once('./global.php');
23 require_once('./includes/functions_datastore.php');
24
25 NavLinks::optionsPages();
26 $navigator->set_focus('tab', 'options', null);
27
28 if (!can_perform('canadmintools'))
29 {
30 admin_login();
31 }
32
33 // ###################################################################
34
35 if (empty($_REQUEST['do']))
36 {
37 $_REQUEST['do'] = 'modify';
38 }
39
40 // ###################################################################
41
42 if ($_REQUEST['do'] == 'kill')
43 {
44 $count = $db->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "language");
45 if ($count['count'] < 2)
46 {
47 $admin->error($lang->string('At least one language needs to be present. Deleting this language would violate that.'));
48 }
49
50 if ($bugsys->options['defaultlanguage'] == intval($bugsys->in['languageid']))
51 {
52 $admin->error($lang->string('You cannot delete the default language. Please select another language to be the default language and then delete this one.'));
53 }
54
55 $db->query("DELETE FROM " . TABLE_PREFIX . "language WHERE languageid = " . intval($bugsys->in['languageid']));
56 $db->query("DELETE FROM " . TABLE_PREFIX . "localization WHERE languageid = " . intval($bugsys->in['languageid']));
57 build_languages();
58 $admin->redirect('language.php?do=modify');
59 }
60
61 // ###################################################################
62
63 if ($_REQUEST['do'] == 'delete')
64 {
65 $admin->page_confirm($lang->string('Are you sure you want to delete this language?'), 'language.php?do=kill&amp;languageid=' . intval($bugsys->in['languageid']));
66 }
67
68 // ###################################################################
69
70 if ($_POST['do'] == 'insert')
71 {
72 $languageid = $db->query("
73 INSERT INTO " . TABLE_PREFIX . "language
74 (title, charset, direction, userselect, debug, filename)
75 VALUES
76 ('" . $bugsys->in['title'] . "', '" . $bugsys->in['charset'] . "',
77 '" . $bugsys->in['direction'] . "', " . intval($bugsys->in['userselect']) . ",
78 " . intval($bugsys->in['debug']) . ", '" . $bugsys->in['filename'] . "'
79 )"
80 );
81
82 build_languages();
83
84 build_language_cache($db->insert_id());
85
86 $admin->redirect('language.php?do=modify');
87 }
88
89 // ###################################################################
90
91 if ($_REQUEST['do'] == 'add')
92 {
93 NavLinks::languagesAdd();
94 $navigator->set_focus('link', 'options-languages-add', 'options-languages');
95
96 $admin->page_start($lang->string('New Language'));
97
98 $admin->form_start('language.php', 'insert');
99 $admin->table_start();
100 $admin->table_head($lang->string('New Language'), 2, 'language_edit');
101
102 $admin->row_input($lang->string('Title'), 'title');
103 $admin->row_input($lang->string('Character Set'), 'charset', 'utf-8');
104 $admin->list_item($lang->string('Left-to-Right'), 'ltr', true);
105 $admin->list_item($lang->string('Right-to-Left'), 'rtl');
106 $admin->row_list($lang->string('Direction'), 'direction');
107 $admin->row_input($lang->string('Path to XML'), 'filename');
108 $admin->row_yesno($lang->string('User Selectable'), 'userselect', true);
109 $admin->row_yesno($lang->string('Debug Mode (run directly from XML)'), 'langdebug', false);
110
111 $admin->row_submit();
112 $admin->table_end();
113 $admin->form_end();
114
115 $admin->page_end();
116 }
117
118 // ###################################################################
119
120 if ($_POST['do'] == 'update')
121 {
122 $db->query("
123 UPDATE " . TABLE_PREFIX . "language
124 SET title = '" . $bugsys->in['title'] . "',
125 charset = '" . $bugsys->in['charset'] . "',
126 direction = '" . $bugsys->in['direction'] . "',
127 userselect = " . intval($bugsys->in['userselect']) . ",
128 debug = " . intval($bugsys->in['langdebug']) . ",
129 filename = '" . $bugsys->in['filename'] . "'
130 WHERE languageid = " . intval($bugsys->in['languageid'])
131 );
132
133 build_languages();
134
135 $admin->redirect('language.php?do=modify');
136 }
137
138 // ###################################################################
139
140 if ($_REQUEST['do'] == 'edit')
141 {
142 $bugsys->input_clean('languageid', TYPE_UINT);
143
144 NavLinks::languagesEdit($bugsys->in['languageid']);
145 $navigator->set_focus('link', 'options-languages-edit', 'options-languages');
146
147 $language = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "language WHERE languageid = " . $bugsys->in['languageid']);
148 if (!$language)
149 {
150 $admin->error($lang->getlex('error_invalid_id'));
151 }
152
153 $admin->page_start($lang->string('Edit Language'));
154
155 $admin->form_start('language.php', 'update');
156 $admin->table_start();
157 $admin->table_head(sprintf($lang->string('Edit Language - %1$s'), $language['title']), 2, 'language_edit');
158
159 $admin->form_hidden_field('languageid', $language['languageid']);
160
161 $admin->row_input($lang->string('Title'), 'title', $language['title']);
162 $admin->row_input($lang->string('Character Set'), 'charset', $language['charset']);
163 $admin->list_item($lang->string('Left-to-Right'), 'ltr', (($language['direction'] == 'ltr') ? true : false));
164 $admin->list_item($lang->string('Right-to-Left'), 'rtl', (($language['direction'] == 'rtl') ? true : false));
165 $admin->row_list($lang->string('Direction'), 'direction');
166 $admin->row_input($lang->string('Path to XML'), 'filename', $language['filename']);
167 $admin->row_yesno($lang->string('User Selectable'), 'userselect', $language['userselect']);
168 $admin->row_yesno($lang->string('Debug Mode (run directly from XML)'), 'langdebug', (bool)$language['debug']);
169
170 $admin->row_submit();
171 $admin->table_end();
172 $admin->form_end();
173
174 $admin->page_end();
175 }
176
177 // ###################################################################
178
179 if ($_REQUEST['do'] == 'reload')
180 {
181 $language = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "language WHERE languageid = " . intval($bugsys->in['languageid']));
182 if (!$language)
183 {
184 $admin->error($lang->getlex('error_invalid_id'));
185 }
186
187 build_language_cache($language['languageid']);
188
189 $admin->redirect('language.php?do=modify');
190 }
191
192 // ###################################################################
193
194 if ($_REQUEST['do'] == 'modify')
195 {
196 NavLinks::languagesAdd();
197 $navigator->set_focus('link', 'options-pages-languages', 'options-pages');
198
199 $admin->page_start($lang->string('Manage Languages'));
200
201 $admin->table_start();
202 $admin->table_head($lang->string('Manage Languages'), 4, 'language_manage');
203
204 $admin->table_column_head(array($lang->string('Title'), $lang->string('Charset'), $lang->string('Options'), $lang->string('Actions')));
205
206 $languages = $db->query("SELECT * FROM " . TABLE_PREFIX . "language ORDER BY languageid ASC");
207 while ($language = $db->fetch_array($languages))
208 {
209 $admin->row_multi_item(array(
210 $language['title'] => 'l',
211 $language['charset'] => 'c',
212 (($bugsys->options['defaultlanguage'] == $language['languageid']) ? '<strong>' . $lang->string('DEFAULT LANGUAGE') . '</strong> / ' : '') . ($language['userselect'] ? $lang->string('User Selectable') : $lang->string('Private')) => 'c',
213 "<a href=\"language.php?do=edit&amp;languageid=$language[languageid]\">[" . $lang->string('Edit Settings') . "]</a> <a href=\"language.php?do=reload&amp;languageid=$language[languageid]\">[" . $lang->string('Reload XML') . "]</a>" => 'c'
214 ));
215 }
216
217 $admin->table_end();
218
219 $admin->page_end();
220 }
221
222 /*=====================================================================*\
223 || ###################################################################
224 || # $HeadURL$
225 || # $Id$
226 || ###################################################################
227 \*=====================================================================*/
228 ?>