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