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