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