r714: OKAY, this is the last of the TABLE_PREFIX bugs
[bugdar.git] / admin / language.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # Bugdar [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
12
13 require_once('./global.php');
14 require_once('./includes/functions_datastore.php');
15
16 if (!can_perform('canadmintools'))
17 {
18 admin_login();
19 }
20
21 // ###################################################################
22
23 if (empty($_REQUEST['do']))
24 {
25 $_REQUEST['do'] = 'modify';
26 }
27
28 // ###################################################################
29
30 if ($_REQUEST['do'] == 'kill')
31 {
32 $count = $db->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "language");
33 if ($count['count'] < 2)
34 {
35 $admin->error($lang->string('At least one language needs to be present. Deleting this language would violate that.'));
36 }
37
38 if ($bugsys->options['defaultlanguage'] == intval($bugsys->in['languageid']))
39 {
40 $admin->error($lang->string('You cannot delete the default language. Please select another language to be the default language and then delete this one.'));
41 }
42
43 $db->query("DELETE FROM " . TABLE_PREFIX . "language WHERE languageid = " . intval($bugsys->in['languageid']));
44 $db->query("DELETE FROM " . TABLE_PREFIX . "localization WHERE languageid = " . intval($bugsys->in['languageid']));
45 build_languages();
46 $admin->redirect('language.php?do=modify');
47 }
48
49 // ###################################################################
50
51 if ($_REQUEST['do'] == 'delete')
52 {
53 $admin->page_confirm($lang->string('Are you sure you want to delete this language?'), 'language.php?do=kill&amp;languageid=' . intval($bugsys->in['languageid']));
54 }
55
56 // ###################################################################
57
58 if ($_POST['do'] == 'insert')
59 {
60 $languageid = $db->query("
61 INSERT INTO " . TABLE_PREFIX . "language
62 (title, charset, direction, userselect, debug, filename)
63 VALUES
64 ('" . $bugsys->in['title'] . "', '" . $bugsys->in['charset'] . "',
65 '" . $bugsys->in['direction'] . "', " . intval($bugsys->in['userselect']) . ",
66 " . intval($bugsys->in['debug']) . ", '" . $bugsys->in['filename'] . "'
67 )"
68 );
69
70 build_languages();
71
72 build_language_cache($db->insert_id());
73
74 $admin->redirect('language.php?do=modify');
75 }
76
77 // ###################################################################
78
79 if ($_REQUEST['do'] == 'add')
80 {
81 $admin->page_start($lang->string('New Language'));
82
83 $admin->form_start('language.php', 'insert');
84 $admin->table_start();
85 $admin->table_head($lang->string('New Language'), 2, 'language_edit');
86
87 $admin->row_input($lang->string('Title'), 'title');
88 $admin->row_input($lang->string('Character Set'), 'charset', 'utf-8');
89 $admin->list_item($lang->string('Left-to-Right'), 'ltr', true);
90 $admin->list_item($lang->string('Right-to-Left'), 'rtl');
91 $admin->row_list($lang->string('Direction'), 'direction');
92 $admin->row_input($lang->string('Path to XML'), 'filename');
93 $admin->row_yesno($lang->string('User Selectable'), 'userselect', true);
94 $admin->row_yesno($lang->string('Debug Mode (run directly from XML)'), 'langdebug', false);
95
96 $admin->row_submit();
97 $admin->table_end();
98 $admin->form_end();
99
100 $admin->page_end();
101 }
102
103 // ###################################################################
104
105 if ($_POST['do'] == 'update')
106 {
107 $db->query("
108 UPDATE " . TABLE_PREFIX . "language
109 SET title = '" . $bugsys->in['title'] . "',
110 charset = '" . $bugsys->in['charset'] . "',
111 direction = '" . $bugsys->in['direction'] . "',
112 userselect = " . intval($bugsys->in['userselect']) . ",
113 debug = " . intval($bugsys->in['langdebug']) . ",
114 filename = '" . $bugsys->in['filename'] . "'
115 WHERE languageid = " . intval($bugsys->in['languageid'])
116 );
117
118 build_languages();
119
120 $admin->redirect('language.php?do=modify');
121 }
122
123 // ###################################################################
124
125 if ($_REQUEST['do'] == 'edit')
126 {
127 $language = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "language WHERE languageid = " . intval($bugsys->in['languageid']));
128 if (!$language)
129 {
130 $admin->error($lang->getlex('error_invalid_id'));
131 }
132
133 $admin->page_start($lang->string('Edit Language'));
134
135 $admin->form_start('language.php', 'update');
136 $admin->table_start();
137 $admin->table_head(sprintf($lang->string('Edit Language - %1$s'), $language['title']), 2, 'language_edit');
138
139 $admin->form_hidden_field('languageid', $language['languageid']);
140
141 $admin->row_input($lang->string('Title'), 'title', $language['title']);
142 $admin->row_input($lang->string('Character Set'), 'charset', $language['charset']);
143 $admin->list_item($lang->string('Left-to-Right'), 'ltr', (($language['direction'] == 'ltr') ? true : false));
144 $admin->list_item($lang->string('Right-to-Left'), 'rtl', (($language['direction'] == 'rtl') ? true : false));
145 $admin->row_list($lang->string('Direction'), 'direction');
146 $admin->row_input($lang->string('Path to XML'), 'filename', $language['filename']);
147 $admin->row_yesno($lang->string('User Selectable'), 'userselect', $language['userselect']);
148 $admin->row_yesno($lang->string('Debug Mode (run directly from XML)'), 'langdebug', (bool)$language['debug']);
149
150 $admin->row_submit('<a href="language.php?do=delete&amp;languageid=' . $language['languageid'] . '">[' . $lang->string('Delete') . ']</a>');
151 $admin->table_end();
152 $admin->form_end();
153
154 $admin->page_end();
155 }
156
157 // ###################################################################
158
159 if ($_REQUEST['do'] == 'reload')
160 {
161 $language = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "language WHERE languageid = " . intval($bugsys->in['languageid']));
162 if (!$language)
163 {
164 $admin->error($lang->getlex('error_invalid_id'));
165 }
166
167 build_language_cache($language['languageid']);
168
169 $admin->redirect('language.php?do=modify');
170 }
171
172 // ###################################################################
173
174 if ($_REQUEST['do'] == 'modify')
175 {
176 $admin->page_start($lang->string('Manage Languages'));
177
178 $admin->table_start();
179 $admin->table_head($lang->string('Manage Languages'), 4, 'language_manage');
180
181 $admin->table_column_head(array($lang->string('Title'), $lang->string('Charset'), $lang->string('Options'), $lang->string('Actions')));
182
183 $languages = $db->query("SELECT * FROM " . TABLE_PREFIX . "language ORDER BY languageid ASC");
184 while ($language = $db->fetch_array($languages))
185 {
186 $admin->row_multi_item(array(
187 $language['title'] => 'l',
188 $language['charset'] => 'c',
189 (($bugsys->options['defaultlanguage'] == $language['languageid']) ? '<strong>' . $lang->string('DEFAULT LANGUAGE') . '</strong> / ' : '') . ($language['userselect'] ? $lang->string('User Selectable') : $lang->string('Private')) => 'c',
190 "<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'
191 ));
192 }
193
194 $admin->row_span('<a href="language.php?do=add">[' . $lang->string('Add New Language') . ']</a>', 'tfoot', 'center', 4);
195 $admin->table_end();
196
197 $admin->page_end();
198 }
199
200 /*=====================================================================*\
201 || ###################################################################
202 || # $HeadURL$
203 || # $Id$
204 || ###################################################################
205 \*=====================================================================*/
206 ?>