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