r883: - Updating the Admin CP navigation system
[bugdar.git] / admin / userhelp.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 NavLinks::userhelpAdd();
27 $navigator->set_focus('tab', 'options', null);
28
29 if (!can_perform('canadmintools'))
30 {
31 admin_login();
32 }
33
34 // don't allow deleting of these
35 $nokills = array(
36 'assignedto',
37 'bugid',
38 'dateline',
39 'dependency',
40 'duplicateof',
41 'priority',
42 'product',
43 'reporter',
44 'resolution',
45 'severity',
46 'status',
47 'summary',
48 'newreply'
49 );
50
51 // ###################################################################
52
53 if (empty($_REQUEST['do']))
54 {
55 $_REQUEST['do'] = 'modify';
56 }
57
58 // ###################################################################
59
60 if ($_REQUEST['do'] == 'kill')
61 {
62 if (in_array($bugsys->in['keystring'], $nokills))
63 {
64 $admin->error($lang->string('You cannot delete this help text because it is part of the default set.'));
65 }
66
67 $db->query("DELETE FROM " . TABLE_PREFIX . "fieldhelp WHERE keystring = '" . $bugsys->in['keystring'] . "'");
68
69 build_user_help();
70
71 $admin->redirect('userhelp.php?do=modify');
72 }
73
74 // ###################################################################
75
76 if ($_REQUEST['do'] == 'delete')
77 {
78 if (in_array($bugsys->in['keystring'], $nokills))
79 {
80 $admin->error($lang->string('You cannot delete this help text because it is part of the default set.'));
81 }
82
83 $admin->page_confirm($lang->string('Are you sure you want to delete help text?'), 'userhelp.php?do=kill&amp;keystring=' . $bugsys->in['keystring']);
84 }
85
86 // ###################################################################
87
88 if ($_POST['do'] == 'insert')
89 {
90 if (preg_match('#[^a-z0-9_]#', $bugsys->in['keystring']))
91 {
92 $admin->error($lang->string('The unique key can only contain lowercase letters, underscores, and numbers.'));
93 }
94
95 if ($db->query_first("SELECT * FROM " . TABLE_PREFIX . "fieldhelp WHERE keystring = '" . $bugsys->in['keystring'] . "'"))
96 {
97 $admin->error($lang->string('The unique key must be unique.'));
98 }
99
100 if (empty($bugsys->in['keystring']) OR empty($bugsys->in['title']) OR empty($bugsys->in['body']))
101 {
102 $admin->error($lang->string('All the fields are required. Please go back and fill each field in properly.'));
103 }
104
105 $db->query("INSERT INTO " . TABLE_PREFIX . "fieldhelp (keystring, title, body) VALUES ('" . $bugsys->in['keystring'] . "', '" . $bugsys->in['title'] . "', '" . $bugsys->in['body'] . "')");
106
107 build_user_help();
108
109 $admin->redirect('userhelp.php?do=modify');
110 }
111
112 // ###################################################################
113
114 if ($_REQUEST['do'] == 'add')
115 {
116 $navigator->set_focus('link', 'options-userhelp-add', 'options-userhelp');
117
118 $admin->page_start($lang->string('New Help Text'));
119
120 $admin->form_start('userhelp.php', 'insert');
121
122 $admin->table_start();
123 $admin->table_head($lang->string('New Help Text'), 2, 'user_help_manager');
124
125 $admin->row_input($lang->string('Topic Title'), 'title');
126 $admin->row_input($lang->string('Unique Key<br />(lowercase letters, underscores, and numbers only)'), 'keystring');
127 $admin->row_textarea($lang->string('Body Text'), 'body');
128
129 $admin->row_submit();
130
131 $admin->table_end();
132
133 $admin->form_end();
134
135 $admin->page_end();
136 }
137
138 // ###################################################################
139
140 if ($_POST['do'] == 'update')
141 {
142 foreach ($bugsys->in['help'] AS $keystring => $fields)
143 {
144 if (empty($fields['title']) OR empty($fields['body']))
145 {
146 $admin->error(sprintf($lang->string('No fields can be empty. Please correct this with the text for key <em>%1$s</em>.'), $keystring));
147 }
148 else
149 {
150 $query[] = "UPDATE " . TABLE_PREFIX . "fieldhelp SET title = '$fields[title]', body = '$fields[body]' WHERE keystring = '$keystring'";
151 }
152 }
153
154 foreach ($query AS $sql)
155 {
156 $db->query($sql);
157 }
158
159 build_user_help();
160
161 $admin->redirect('userhelp.php?do=modify');
162 }
163
164 // ###################################################################
165
166 if ($_REQUEST['do'] == 'modify')
167 {
168 $navigator->set_focus('link', 'options-pages-userhelp', 'options-pages');
169
170 $admin->page_start($lang->string('Edit User Help'));
171
172 $admin->form_start('userhelp.php', 'update');
173
174 $admin->table_start();
175 $admin->table_head($lang->string('Edit User Help'), 2, 'user_help_manager');
176
177 $topics = $db->query("SELECT * FROM " . TABLE_PREFIX . "fieldhelp ORDER BY keystring ASC");
178 while ($topic = $db->fetch_array($topics))
179 {
180 $inputfield = '<input type="text" class="input" name="help[' . $topic['keystring'] . '][title]" value="' . $topic['title'] . '" size="35" />';
181 $delete = (!in_array($topic['keystring'], $nokills) ? '<br /><br /><a href="userhelp.php?do=delete&amp;keystring=' . $topic['keystring'] . '">[' . $lang->string('Delete') . ']</a>' : '');
182
183 $admin->row_textarea($inputfield . '<br /><em>' . $topic['keystring'] . '</em>' . $delete, 'help[' . $topic['keystring'] . '][body]', $topic['body']);
184 }
185
186 $admin->table_end();
187
188 $admin->page_end();
189 }
190
191 /*=====================================================================*\
192 || ###################################################################
193 || # $HeadURL$
194 || # $Id$
195 || ###################################################################
196 \*=====================================================================*/
197 ?>