r649: Adding base userhelp system for non-custom fields
[bugdar.git] / admin / userhelp.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # BugStrike [#]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 // set default branch for this script
26 $_REQUEST['do'] = 'modify';
27 }
28
29 // ###################################################################
30
31 if ($_REQUEST['do'] == 'kill')
32 {
33 // run code to remove item in database
34 }
35
36 // ###################################################################
37
38 if ($_REQUEST['do'] == 'delete')
39 {
40 // display delete confirmation message
41 }
42
43 // ###################################################################
44
45 if ($_POST['do'] == 'insert')
46 {
47 if (preg_match('#[^a-z0-9_]#', $bugsys->in['keystring']))
48 {
49 $admin->error($lang->string('The unique key can only contain lowercase letters, underscores, and numbers.'));
50 }
51
52 if ($db->query_first("SELECT * FROM " . TABLE_PREFIX . "fieldhelp WHERE keystring = '" . $bugsys->in['keystring'] . "'"))
53 {
54 $admin->error($lang->string('The unique key must be unique.'));
55 }
56
57 if (empty($bugsys->in['keystring']) OR empty($bugsys->in['title']) OR empty($bugsys->in['body']))
58 {
59 $admin->error($lang->string('All the fields are required. Please go back and fill each field in properly.'));
60 }
61
62 $db->query("INSERT INTO " . TABLE_PREFIX . "fieldhelp (keystring, title, body) VALUES ('" . $bugsys->in['keystring'] . "', '" . $bugsys->in['title'] . "', '" . $bugsys->in['body'] . "')");
63
64 build_user_help();
65
66 $admin->redirect('userhelp.php?do=modify');
67 }
68
69 // ###################################################################
70
71 if ($_REQUEST['do'] == 'add')
72 {
73 $admin->page_start($lang->string('New Help Text'));
74
75 $admin->form_start('userhelp.php', 'insert');
76
77 $admin->table_start();
78 $admin->table_head($lang->string('New Help Text'));
79
80 $admin->row_input($lang->string('Topic Title'), 'title');
81 $admin->row_input($lang->string('Unique Key<br />(lowercase letters, underscores, and numbers only)'), 'keystring');
82 $admin->row_textarea($lang->string('Body Text'), 'body');
83
84 $admin->row_submit();
85
86 $admin->table_end();
87
88 $admin->form_end();
89
90 $admin->page_end();
91 }
92
93 // ###################################################################
94
95 if ($_POST['do'] == 'update')
96 {
97 foreach ($bugsys->in['help'] AS $keystring => $fields)
98 {
99 if (empty($fields['title']) OR empty($fields['body']))
100 {
101 $admin->error(sprintf($lang->string('No fields can be empty. Please correct this with the text for key <em>%1$s</em>.'), $keystring));
102 }
103 else
104 {
105 $query[] = "UPDATE " . TABLE_PREFIX . "fieldhelp SET title = '$fields[title]', body = '$fields[body]' WHERE keystring = '$keystring'";
106 }
107 }
108
109 foreach ($query AS $sql)
110 {
111 $db->query($sql);
112 }
113
114 build_user_help();
115
116 $admin->redirect('userhelp.php?do=modify');
117 }
118
119 // ###################################################################
120
121 if ($_REQUEST['do'] == 'modify')
122 {
123 $admin->page_start($lang->string('Edit User Help'));
124
125 $admin->form_start('userhelp.php', 'update');
126
127 $admin->table_start();
128 $admin->table_head($lang->string('Edit User Help'));
129
130 $topics = $db->query("SELECT * FROM " . TABLE_PREFIX . "fieldhelp ORDER BY keystring ASC");
131 while ($topic = $db->fetch_array($topics))
132 {
133 $inputfield = '<input type="text" class="input" name="help[' . $topic['keystring'] . '][title]" value="' . $topic['title'] . '" size="35" />';
134 $admin->row_textarea($inputfield . '<br /><em>' . $topic['keystring'] . '</em>', 'help[' . $topic['keystring'] . '][body]', $topic['body']);
135 }
136
137 $admin->row_submit('<a href="userhelp.php?do=add">[' . $lang->string('Add New Help Text') . ']</a>');
138
139 $admin->table_end();
140
141 $admin->page_end();
142 }
143
144 /*=====================================================================*\
145 || ###################################################################
146 || # $HeadURL$
147 || # $Id$
148 || ###################################################################
149 \*=====================================================================*/
150 ?>