]>
src.bluestatic.org Git - bugdar.git/blob - 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">
5 <meta http
-equiv
="content-type" content
="text/html; charset=iso-8859-1" />
6 <title
>Phrase Tools
</title
>
12 error_reporting(E_ALL
& ~E_NOTICE
);
14 // phrase tools for managing DB phrase system
18 require_once('./global.php');
20 define('SELECTED', ' selected="selected"');
21 define('CHECKED', ' checked="checked"');
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');
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
: '');
42 function sanitize_name($name)
44 $name = preg_replace('#[^a-zA-Z0-9_]#', '_', $name);
45 $name = preg_replace('#_{1,}#', '_', $name);
46 $name = preg_replace('#(^_|_$)#', '', $name);
50 // ###################################################################
53 <h2>Search | <a href="phrasetools.php?do=export">Export</a></h2>
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" checked="checked" /></div>
57 <div><strong>Phrase <u>t</u>ext:</strong> <input type="checkbox" name="use[phrasetext]" value="1" /></div>
58 <div><textarea name="phrasetext" rows="7" cols="75" accesskey="t">$vars[phrasetext]</textarea></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>
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 " />
74 echo "\n\n<hr />\n\n";
77 // ###################################################################
79 if ($_REQUEST['do'] == 'kill')
81 $db->query("DELETE FROM " . TABLE_PREFIX
. "phrase WHERE varname = '" . $vars['varname'] . "'");
82 header("Location: phrasetools.php");
85 // ###################################################################
87 if ($_REQUEST['do'] == 'delete')
89 $phrase = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "phrase WHERE varname = '" . $vars['varname'] . "'");
92 echo 'Not a valid phrase!';
96 echo "<h2>Delete</h2>\n\n<pre><a href=\"phrasetools.php?do=kill&varname=$phrase[varname]\">Found: <strong>$phrase[varname]</strong> ===> $phrase[phrasetext]</a></pre>";
99 // ###################################################################
101 if ($_POST['do'] == 'insert')
103 $vars['varname'] = str_replace(' ', '_', $vars['varname']);
105 INSERT INTO " . TABLE_PREFIX
. "phrase
106 (varname, phrasetext)
108 ('" . sanitize_name($vars['varname']) . "', '" . $vars['phrasetext'] . "'
111 header("Location: phrasetools.php?do=edit&doneinsert=1&varname=$vars[varname]");
114 // ###################################################################
116 if ($_POST['do'] == 'update')
119 UPDATE " . TABLE_PREFIX
. "phrase
120 SET varname = '" . sanitize_name($vars['varname']) . "',
121 phrasetext = '" . $vars['phrasetext'] . "'
122 WHERE varname = '" . $vars['oldvarname'] . "'"
124 header("Location: phrasetools.php?do=edit&varname=$vars[varname]");
127 // ###################################################################
129 if ($_REQUEST['do'] == 'edit')
131 $phrase = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "phrase WHERE varname = '" . $vars['varname'] . "'");
134 echo 'Not a valid phrase!';
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>
148 <input type="submit" name="submit" value=" Continue " accesskey="e" />
149 <input type="reset" name="reset" value=" Reset " />
155 // ###################################################################
157 if ($_REQUEST['do'] == 'search')
159 if ($use['varname'] AND !$use['phrasetext'])
161 $where = "varname LIKE '%$vars[varname]%'";
163 else if (!$use['varname'] AND $use['phrasetext'])
165 $where = "phrasetext LIKE '%$vars[phrasetext]%'";
169 $where = "varname LIKE '%$vars[varname]%' $use[matcher] phrasetext LIKE '%$vars[phrasetext]%'";
172 $phrases = $db->query("SELECT * FROM " . TABLE_PREFIX
. "phrase WHERE $where");
173 $numrows = $db->num_rows($phrases);
177 echo 'No results found!';
183 while ($phrase = $db->fetch_array($phrases))
185 echo "<pre
><div
>\$bugsys
->language
['<strong><a href=\"phrasetools.php?do=edit&varname=$phrase[varname]\">$phrase[varname]</a></strong>'] =======> " . $bugsys->sanitize($phrase['phrasetext']) . "</div
></pre
>";
190 $phrase = $db->fetch_array($phrases);
191 header("Location
: phrasetools
.php
?do=edit
&varname
=$phrase[varname
]");
195 // ###################################################################
197 if ($_REQUEST['do'] == 'export')
199 $output = "// Language configuration variables
201 'title' => 'English (US)',
202 'languagecode' => 'en',
203 'charset' => 'ISO-8859-1',
208 \$language
= array(";
210 $phrases = $db->query("SELECT
* FROM
" . TABLE_PREFIX . "phrase ORDER BY varname
");
211 while ($phrase = $db->fetch_array($phrases))
213 $phrase['phrasetext'] = str_replace("'", "\'", $phrase['phrasetext
']);
214 $phrasebits[] = "\n\t'$phrase[varname
]' => '$phrase[phrasetext
]'";
217 $output .= implode(',', $phrasebits);
222 $output = $bugsys->sanitize($output);
225 <textarea style="width: 100%; height: 500px" rows="10" cols="10">$output</textarea>