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