r37: Added two new language tools so we can migrate phrases to the database.
[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 // phrase tools for managing DB phrase system
13 // SVN: $Id$
14
15 chdir('./../');
16 require_once('./global.php');
17
18 define('SELECTED', ' selected="selected"');
19 define('CHECKED', ' checked="checked"');
20
21 sanitize(array('varname' => STR, 'phrasetext' => STR, 'matchmethod' => STR, 'do' => STR));
22 $use['varname'] = (bool)$_REQUEST['use']['varname'];
23 $use['phrasetext'] = (bool)$_REQUEST['use']['phrasetext'];
24 $use['and'] = iff($vars['matchmethod'] == 'and', true, false);
25 $use['or'] = iff($use['and'], false, true);
26 $use['matcher'] = iff($use['and'], 'AND', 'OR');
27
28 $select['or'] = iff($use['or'], SELECTED);
29 $select['and'] = iff($use['and'] , SELECTED);
30 $select['search'] = iff($vars['do'] == 'search', SELECTED);
31 $select['insert'] = iff($vars['do'] == 'insert', SELECTED);
32 $select['delete'] = iff($vars['do'] == 'delete', SELECTED);
33
34 error_reporting(E_ALL & ~E_NOTICE);
35
36 echo "<h2>Input</h2>\n<pre>\n";
37 var_dump($vars);
38 echo "\n</pre>\n\n<hr />\n\n";
39
40 // ###################################################################
41
42 echo <<<HTML
43 <h2>Search</h2>
44
45 <form action="phrasetools.php" method="post" name="newphrase">
46 <div><strong>Varname:</strong> <input type="text" name="varname" value="$vars[varname]" size="35" /> <input type="checkbox" name="use[varname]" value="1" checked="checked" /></div>
47 <div><strong>Phrase text:</strong> <input type="checkbox" name="use[phrasetext]" value="1" /></div>
48 <div><textarea name="phrasetext" rows="7" cols="75">$vars[phrasetext]</textarea></div>
49 <div>
50 <strong>Action:</strong>
51 <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>
52 </div>
53 <div>
54 <strong>Match Method:</strong>
55 <select name="matchmethod"><option value="or"$select[or]>* OR *</option><option value="and"$select[and]>+ AND +</option></select>
56 <input type="submit" name="submit" value=" Continue " />
57 <input type="reset" name="reset" value=" Reset " />
58 </div>
59 </form>
60 HTML;
61
62 if ($_REQUEST['do'])
63 {
64 echo "\n\n<hr />\n\n";
65 }
66
67 // ###################################################################
68
69 if ($_REQUEST['do'] == 'kill')
70 {
71 $DB_sql->query("DELETE FROM " . TABLE_PREFIX . "phrase WHERE varname = '" . addslasheslike($vars['varname']) . "'");
72 header("Location: phrasetools.php");
73 }
74
75 // ###################################################################
76
77 if ($_REQUEST['do'] == 'delete')
78 {
79 $phrase = $DB_sql->query_first("SELECT * FROM " . TABLE_PREFIX . "phrase WHERE varname = '" . addslasheslike($vars['varname']) . "'");
80 if (!$phrase)
81 {
82 echo 'Not a valid phrase!';
83 exit;
84 }
85
86 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>";
87 }
88
89 // ###################################################################
90
91 if ($_POST['do'] == 'insert')
92 {
93 $vars['varname'] = str_replace(' ', '_', $vars['varname']);
94 $DB_sql->query("
95 INSERT INTO " . TABLE_PREFIX . "phrase
96 (varname, phrasetext)
97 VALUES
98 ('" . addslasheslike($vars['varname']) . "', '" . addslasheslike($vars['phrasetext']) . "'
99 )"
100 );
101 header("Location: phrasetools.php?do=edit&varname=$vars[varname]");
102 }
103
104 // ###################################################################
105
106 if ($_POST['do'] == 'update')
107 {
108 $DB_sql->query("
109 UPDATE " . TABLE_PREFIX . "phrase
110 SET varname = '" . addslasheslike($vars['varname']) . "',
111 phrasetext = '" . addslasheslike($vars['phrasetext']) . "'
112 WHERE varname = '" . addslasheslike($vars['varname']) . "'"
113 );
114 header("Location: phrasetools.php?do=edit&varname=$vars[varname]");
115 }
116
117 // ###################################################################
118
119 if ($_REQUEST['do'] == 'edit')
120 {
121 $phrase = $DB_sql->query_first("SELECT * FROM " . TABLE_PREFIX . "phrase WHERE varname = '" . addslasheslike($vars['varname']) . "'");
122 if (!$phrase)
123 {
124 echo 'Not a valid phrase!';
125 exit;
126 }
127
128 echo <<<HTML
129 <h2>Edit</h2>
130
131 <form action="phrasetools.php" method="post" name="editphrase">
132 <input type="hidden" name="do" value="update" />
133 <div><strong>Varname:</strong> <input type="text" name="varname" value="$phrase[varname]" size="35" /></div>
134 <div><strong>Phrase text:</strong></div>
135 <div><textarea name="phrasetext" rows="7" cols="75">$phrase[phrasetext]</textarea></div>
136 <div>
137 <input type="submit" name="submit" value=" Continue " />
138 <input type="reset" name="reset" value=" Reset " />
139 </div>
140 </form>
141 HTML;
142 }
143
144 // ###################################################################
145
146 if ($_REQUEST['do'] == 'search')
147 {
148 if ($use['varname'] AND !$use['phrasetext'])
149 {
150 $where = "varname LIKE '%$vars[varname]%'";
151 }
152 else if (!$use['varname'] AND $use['phrasetext'])
153 {
154 $where = "phrasetext LIKE '%$vars[phrasetext]%'";
155 }
156 else
157 {
158 $where = "varname LIKE '%$vars[varname]%' $use[matcher] phrasetext LIKE '%$vars[phrasetext]%'";
159 }
160
161 $phrases = $DB_sql->query("SELECT * FROM " . TABLE_PREFIX . "phrase WHERE $where");
162 $numrows = $DB_sql->num_rows($phrases);
163
164 if ($numrows < 1)
165 {
166 echo 'No results found!';
167 exit;
168 }
169
170 if ($numrows > 2)
171 {
172 while ($phrase = $DB_sql->fetch_array($phrases))
173 {
174 echo "<pre><div>\$bugsys->language['<strong><a href=\"phrasetools.php?do=edit&amp;varname=$phrase[varname]\">$phrase[varname]</a></strong>'] =======> " . htmlspecialcharslike($phrase['phrasetext']) . "</div></pre>";
175 }
176 }
177 else
178 {
179 $phrase = $DB_sql->fetch_array($phrases);
180 header("Location: phrasetools.php?do=edit&varname=$phrase[varname]");
181 }
182 }
183
184 ?>
185
186 </body>
187 </html>