r394: Add access keys to the checkboxes
[bugdar.git] / docs / phrasetools.php
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4 <head>
5 <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
6 <title>Phrase Tools</title>
7 </head>
8 <body>
9
10 <?php
11
12 error_reporting(E_ALL & ~E_NOTICE);
13
14 // phrase tools for managing DB phrase system
15 // SVN: $Id$
16
17 chdir('./../');
18 require_once('./global.php');
19
20 define('SELECTED', ' selected="selected"');
21 define('CHECKED', ' checked="checked"');
22
23
24 $vars['varname'] = $bugsys->in['varname'];
25 $vars['phrasetext'] = $bugsys->unsanitize($bugsys->in['phrasetext']);
26 $vars['matchmethod'] = $bugsys->in['matchmethod'];
27 $vars['do'] = $bugsys->in['do'];
28 $vars['doneinsert'] = intval($bugsys->in['doneinsert']);
29 $vars['oldvarname'] = $bugsys->in['oldvarname'];
30 $use['varname'] = (bool)$_REQUEST['use']['varname'];
31 $use['phrasetext'] = (bool)$_REQUEST['use']['phrasetext'];
32 $use['and'] = (($vars['matchmethod'] == 'and') ? true : false);
33 $use['or'] = (($use['and']) ? false : true);
34 $use['matcher'] = (($use['and']) ? 'AND' : 'OR');
35
36 $select['or'] = (($use['or']) ? SELECTED : '');
37 $select['and'] = (($use['and']) ? SELECTED : '');
38 $select['search'] = (($vars['do'] == 'search') ? SELECTED : '');
39 $select['insert'] = (($vars['do'] == 'insert' OR $vars['doneinsert']) ? SELECTED : '');
40 $select['delete'] = (($vars['do'] == 'delete') ? SELECTED : '');
41
42 function sanitize_name($name)
43 {
44 $name = preg_replace('#[^a-zA-Z0-9_]#', '_', $name);
45 $name = preg_replace('#_{1,}#', '_', $name);
46 $name = preg_replace('#(^_|_$)#', '', $name);
47 return $name;
48 }
49
50 // ###################################################################
51
52 echo <<<HTML
53 <h2>Search | <a href="phrasetools.php?do=export">Export</a></h2>
54
55 <form action="phrasetools.php" method="post" name="newphrase">
56 <div><strong><u>V</u>arname:</strong> <input type="text" name="varname" value="$vars[varname]" size="35" accesskey="v" /> <input type="checkbox" name="use[varname]" value="1" accesskey="c" checked="checked" /></div>
57 <div><strong>Phrase <u>t</u>ext:</strong> <input type="checkbox" name="use[phrasetext]" value="1" accesskey="r" /></div>
58 <div><textarea name="phrasetext" rows="7" cols="75" accesskey="t">$vars[phrasetext]</textarea></div>
59 <div>
60 <strong>Action:</strong>
61 <select name="do"><option value="search"$select[search]>Search</option><option value="insert"$select[insert]>Insert</option><option value="delete"$select[delete]>Delete</option></select>
62 </div>
63 <div>
64 <strong>Match Method:</strong>
65 <select name="matchmethod"><option value="or"$select[or]>* OR *</option><option value="and"$select[and]>+ AND +</option></select>
66 <input type="submit" name="submit" value=" Continue " accesskey="s" />
67 <input type="reset" name="reset" value=" Reset " />
68 </div>
69 </form>
70 HTML;
71
72 if ($_REQUEST['do'])
73 {
74 echo "\n\n<hr />\n\n";
75 }
76
77 // ###################################################################
78
79 if ($_REQUEST['do'] == 'kill')
80 {
81 $db->query("DELETE FROM " . TABLE_PREFIX . "phrase WHERE varname = '" . $vars['varname'] . "'");
82 header("Location: phrasetools.php");
83 }
84
85 // ###################################################################
86
87 if ($_REQUEST['do'] == 'delete')
88 {
89 $phrase = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "phrase WHERE varname = '" . $vars['varname'] . "'");
90 if (!$phrase)
91 {
92 echo 'Not a valid phrase!';
93 exit;
94 }
95
96 echo "<h2>Delete</h2>\n\n<pre><a href=\"phrasetools.php?do=kill&amp;varname=$phrase[varname]\">Found: <strong>$phrase[varname]</strong> ===> $phrase[phrasetext]</a></pre>";
97 }
98
99 // ###################################################################
100
101 if ($_POST['do'] == 'insert')
102 {
103 $vars['varname'] = str_replace(' ', '_', $vars['varname']);
104 $db->query("
105 INSERT INTO " . TABLE_PREFIX . "phrase
106 (varname, phrasetext)
107 VALUES
108 ('" . sanitize_name($vars['varname']) . "', '" . $vars['phrasetext'] . "'
109 )"
110 );
111 header("Location: phrasetools.php?do=edit&doneinsert=1&varname=$vars[varname]");
112 }
113
114 // ###################################################################
115
116 if ($_POST['do'] == 'update')
117 {
118 $db->query("
119 UPDATE " . TABLE_PREFIX . "phrase
120 SET varname = '" . sanitize_name($vars['varname']) . "',
121 phrasetext = '" . $vars['phrasetext'] . "'
122 WHERE varname = '" . $vars['oldvarname'] . "'"
123 );
124 header("Location: phrasetools.php?do=edit&varname=$vars[varname]");
125 }
126
127 // ###################################################################
128
129 if ($_REQUEST['do'] == 'edit')
130 {
131 $phrase = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "phrase WHERE varname = '" . $vars['varname'] . "'");
132 if (!$phrase)
133 {
134 echo 'Not a valid phrase!';
135 exit;
136 }
137
138 echo <<<HTML
139 <h2>Edit</h2>
140
141 <form action="phrasetools.php" method="post" name="editphrase">
142 <input type="hidden" name="do" value="update" />
143 <input type="hidden" name="oldvarname" value="$phrase[varname]" />
144 <div><strong>Varname:</strong> <input type="text" name="varname" value="$phrase[varname]" size="35" /></div>
145 <div><strong>Phrase text:</strong></div>
146 <div><textarea name="phrasetext" rows="7" cols="75">$phrase[phrasetext]</textarea></div>
147 <div>
148 <input type="submit" name="submit" value=" Continue " accesskey="e" />
149 <input type="reset" name="reset" value=" Reset " />
150 </div>
151 </form>
152 HTML;
153 }
154
155 // ###################################################################
156
157 if ($_REQUEST['do'] == 'search')
158 {
159 if ($use['varname'] AND !$use['phrasetext'])
160 {
161 $where = "varname LIKE '%$vars[varname]%'";
162 }
163 else if (!$use['varname'] AND $use['phrasetext'])
164 {
165 $where = "phrasetext LIKE '%$vars[phrasetext]%'";
166 }
167 else
168 {
169 $where = "varname LIKE '%$vars[varname]%' $use[matcher] phrasetext LIKE '%$vars[phrasetext]%'";
170 }
171
172 $phrases = $db->query("SELECT * FROM " . TABLE_PREFIX . "phrase WHERE $where");
173 $numrows = $db->num_rows($phrases);
174
175 if ($numrows < 1)
176 {
177 echo 'No results found!';
178 exit;
179 }
180
181 if ($numrows > 2)
182 {
183 while ($phrase = $db->fetch_array($phrases))
184 {
185 echo "<pre><div>\$bugsys->language['<strong><a href=\"phrasetools.php?do=edit&amp;varname=$phrase[varname]\">$phrase[varname]</a></strong>'] =======> " . $bugsys->sanitize($phrase['phrasetext']) . "</div></pre>";
186 }
187 }
188 else
189 {
190 $phrase = $db->fetch_array($phrases);
191 header("Location: phrasetools.php?do=edit&varname=$phrase[varname]");
192 }
193 }
194
195 // ###################################################################
196
197 if ($_REQUEST['do'] == 'export')
198 {
199 require_once('./includes/class_xml_language.php');
200 $lang = new XML_Language();
201 $output = $lang->export(-1);
202
203 $output = $bugsys->sanitize($output);
204
205 echo <<<HTML
206 <textarea style="width: 100%; height: 500px" rows="10" cols="10">$output</textarea>
207 HTML;
208 }
209
210 ?>
211
212 </body>
213 </html>