]>
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"');
23 sanitize(array('varname' => STR
, 'phrasetext' => STR
, 'matchmethod' => STR
, 'do' => STR
, 'doneinsert' => INT, 'oldvarname' => STR
));
24 $use['varname'] = (bool)$_REQUEST['use']['varname'];
25 $use['phrasetext'] = (bool)$_REQUEST['use']['phrasetext'];
26 $use['and'] = iff($vars['matchmethod'] == 'and', true, false);
27 $use['or'] = iff($use['and'], false, true);
28 $use['matcher'] = iff($use['and'], 'AND', 'OR');
30 $select['or'] = iff($use['or'], SELECTED
);
31 $select['and'] = iff($use['and'] , SELECTED
);
32 $select['search'] = iff($vars['do'] == 'search', SELECTED
);
33 $select['insert'] = iff($vars['do'] == 'insert' OR $vars['doneinsert'], SELECTED
);
34 $select['delete'] = iff($vars['do'] == 'delete', SELECTED
);
36 function sanitize_name($name)
38 $name = preg_replace('#[^a-zA-Z0-9_]#', '_', $name);
39 $name = preg_replace('#_{1,}#', '_', $name);
40 $name = preg_replace('#(^_|_$)#', '', $name);
44 // ###################################################################
49 <form action="phrasetools.php" method="post" name="newphrase">
50 <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>
51 <div><strong>Phrase <u>t</u>ext:</strong> <input type="checkbox" name="use[phrasetext]" value="1" /></div>
52 <div><textarea name="phrasetext" rows="7" cols="75" accesskey="t">$vars[phrasetext]</textarea></div>
54 <strong>Action:</strong>
55 <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>
58 <strong>Match Method:</strong>
59 <select name="matchmethod"><option value="or"$select[or]>* OR *</option><option value="and"$select[and]>+ AND +</option></select>
60 <input type="submit" name="submit" value=" Continue " accesskey="s" />
61 <input type="reset" name="reset" value=" Reset " />
68 echo "\n\n<hr />\n\n";
71 // ###################################################################
73 if ($_REQUEST['do'] == 'kill')
75 $DB_sql->query("DELETE FROM " . TABLE_PREFIX
. "phrase WHERE varname = '" . addslasheslike($vars['varname']) . "'");
76 header("Location: phrasetools.php");
79 // ###################################################################
81 if ($_REQUEST['do'] == 'delete')
83 $phrase = $DB_sql->query_first("SELECT * FROM " . TABLE_PREFIX
. "phrase WHERE varname = '" . addslasheslike($vars['varname']) . "'");
86 echo 'Not a valid phrase!';
90 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>";
93 // ###################################################################
95 if ($_POST['do'] == 'insert')
97 $vars['varname'] = str_replace(' ', '_', $vars['varname']);
99 INSERT INTO " . TABLE_PREFIX
. "phrase
100 (varname, phrasetext)
102 ('" . addslasheslike(sanitize_name($vars['varname'])) . "', '" . addslasheslike($vars['phrasetext']) . "'
105 header("Location: phrasetools.php?do=edit&doneinsert=1&varname=$vars[varname]");
108 // ###################################################################
110 if ($_POST['do'] == 'update')
113 UPDATE " . TABLE_PREFIX
. "phrase
114 SET varname = '" . addslasheslike(sanitize_name($vars['varname'])) . "',
115 phrasetext = '" . addslasheslike($vars['phrasetext']) . "'
116 WHERE varname = '" . addslasheslike($vars['oldvarname']) . "'"
118 header("Location: phrasetools.php?do=edit&varname=$vars[varname]");
121 // ###################################################################
123 if ($_REQUEST['do'] == 'edit')
125 $phrase = $DB_sql->query_first("SELECT * FROM " . TABLE_PREFIX
. "phrase WHERE varname = '" . addslasheslike($vars['varname']) . "'");
128 echo 'Not a valid phrase!';
135 <form action="phrasetools.php" method="post" name="editphrase">
136 <input type="hidden" name="do" value="update" />
137 <input type="hidden" name="oldvarname" value="$phrase[varname]" />
138 <div><strong>Varname:</strong> <input type="text" name="varname" value="$phrase[varname]" size="35" /></div>
139 <div><strong>Phrase text:</strong></div>
140 <div><textarea name="phrasetext" rows="7" cols="75">$phrase[phrasetext]</textarea></div>
142 <input type="submit" name="submit" value=" Continue " accesskey="e" />
143 <input type="reset" name="reset" value=" Reset " />
149 // ###################################################################
151 if ($_REQUEST['do'] == 'search')
153 if ($use['varname'] AND !$use['phrasetext'])
155 $where = "varname LIKE '%$vars[varname]%'";
157 else if (!$use['varname'] AND $use['phrasetext'])
159 $where = "phrasetext LIKE '%$vars[phrasetext]%'";
163 $where = "varname LIKE '%$vars[varname]%' $use[matcher] phrasetext LIKE '%$vars[phrasetext]%'";
166 $phrases = $DB_sql->query("SELECT * FROM " . TABLE_PREFIX
. "phrase WHERE $where");
167 $numrows = $DB_sql->num_rows($phrases);
171 echo 'No results found!';
177 while ($phrase = $DB_sql->fetch_array($phrases))
179 echo "<pre
><div
>\$bugsys
->language
['<strong><a href=\"phrasetools.php?do=edit&varname=$phrase[varname]\">$phrase[varname]</a></strong>'] =======> " . htmlspecialcharslike($phrase['phrasetext']) . "</div
></pre
>";
184 $phrase = $DB_sql->fetch_array($phrases);
185 header("Location
: phrasetools
.php
?do=edit
&varname
=$phrase[varname
]");