From d43e3d7808c48024a1cd78cf1a632cd4b3ab40df Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Tue, 28 Dec 2004 09:11:28 +0000 Subject: [PATCH] r37: Added two new language tools so we can migrate phrases to the database. --- docs/lang_file_to_db.php | 30 +++++++ docs/phrasetools.php | 187 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 217 insertions(+) create mode 100644 docs/lang_file_to_db.php create mode 100644 docs/phrasetools.php diff --git a/docs/lang_file_to_db.php b/docs/lang_file_to_db.php new file mode 100644 index 0000000..90a2734 --- /dev/null +++ b/docs/lang_file_to_db.php @@ -0,0 +1,30 @@ + $phrase) +{ + $sqlbits[] = " + ('" . addslasheslike($varname) . "', '" . addslasheslike($phrase) . "', " . time() . ")"; +} + +$sql .= implode(',', $sqlbits); + +echo "
$sql
"; + +$DB_sql->query($sql); + +?> \ No newline at end of file diff --git a/docs/phrasetools.php b/docs/phrasetools.php new file mode 100644 index 0000000..a92df2b --- /dev/null +++ b/docs/phrasetools.php @@ -0,0 +1,187 @@ + + + + + Phrase Tools + + + + STR, 'phrasetext' => STR, 'matchmethod' => STR, 'do' => STR)); +$use['varname'] = (bool)$_REQUEST['use']['varname']; +$use['phrasetext'] = (bool)$_REQUEST['use']['phrasetext']; +$use['and'] = iff($vars['matchmethod'] == 'and', true, false); +$use['or'] = iff($use['and'], false, true); +$use['matcher'] = iff($use['and'], 'AND', 'OR'); + +$select['or'] = iff($use['or'], SELECTED); +$select['and'] = iff($use['and'] , SELECTED); +$select['search'] = iff($vars['do'] == 'search', SELECTED); +$select['insert'] = iff($vars['do'] == 'insert', SELECTED); +$select['delete'] = iff($vars['do'] == 'delete', SELECTED); + +error_reporting(E_ALL & ~E_NOTICE); + +echo "

Input

\n
\n";
+var_dump($vars);
+echo "\n
\n\n
\n\n"; + +// ################################################################### + +echo <<Search + +
+
Varname:
+
Phrase text:
+
+
+ Action: + +
+
+ Match Method: + + + +
+
+HTML; + +if ($_REQUEST['do']) +{ + echo "\n\n
\n\n"; +} + +// ################################################################### + +if ($_REQUEST['do'] == 'kill') +{ + $DB_sql->query("DELETE FROM " . TABLE_PREFIX . "phrase WHERE varname = '" . addslasheslike($vars['varname']) . "'"); + header("Location: phrasetools.php"); +} + +// ################################################################### + +if ($_REQUEST['do'] == 'delete') +{ + $phrase = $DB_sql->query_first("SELECT * FROM " . TABLE_PREFIX . "phrase WHERE varname = '" . addslasheslike($vars['varname']) . "'"); + if (!$phrase) + { + echo 'Not a valid phrase!'; + exit; + } + + echo "

Delete

\n\n
Found: $phrase[varname] ===> $phrase[phrasetext]
"; +} + +// ################################################################### + +if ($_POST['do'] == 'insert') +{ + $vars['varname'] = str_replace(' ', '_', $vars['varname']); + $DB_sql->query(" + INSERT INTO " . TABLE_PREFIX . "phrase + (varname, phrasetext) + VALUES + ('" . addslasheslike($vars['varname']) . "', '" . addslasheslike($vars['phrasetext']) . "' + )" + ); + header("Location: phrasetools.php?do=edit&varname=$vars[varname]"); +} + +// ################################################################### + +if ($_POST['do'] == 'update') +{ + $DB_sql->query(" + UPDATE " . TABLE_PREFIX . "phrase + SET varname = '" . addslasheslike($vars['varname']) . "', + phrasetext = '" . addslasheslike($vars['phrasetext']) . "' + WHERE varname = '" . addslasheslike($vars['varname']) . "'" + ); + header("Location: phrasetools.php?do=edit&varname=$vars[varname]"); +} + +// ################################################################### + +if ($_REQUEST['do'] == 'edit') +{ + $phrase = $DB_sql->query_first("SELECT * FROM " . TABLE_PREFIX . "phrase WHERE varname = '" . addslasheslike($vars['varname']) . "'"); + if (!$phrase) + { + echo 'Not a valid phrase!'; + exit; + } + + echo <<Edit + +
+ +
Varname:
+
Phrase text:
+
+
+ + +
+
+HTML; +} + +// ################################################################### + +if ($_REQUEST['do'] == 'search') +{ + if ($use['varname'] AND !$use['phrasetext']) + { + $where = "varname LIKE '%$vars[varname]%'"; + } + else if (!$use['varname'] AND $use['phrasetext']) + { + $where = "phrasetext LIKE '%$vars[phrasetext]%'"; + } + else + { + $where = "varname LIKE '%$vars[varname]%' $use[matcher] phrasetext LIKE '%$vars[phrasetext]%'"; + } + + $phrases = $DB_sql->query("SELECT * FROM " . TABLE_PREFIX . "phrase WHERE $where"); + $numrows = $DB_sql->num_rows($phrases); + + if ($numrows < 1) + { + echo 'No results found!'; + exit; + } + + if ($numrows > 2) + { + while ($phrase = $DB_sql->fetch_array($phrases)) + { + echo "
\$bugsys->language['$phrase[varname]'] =======> " . htmlspecialcharslike($phrase['phrasetext']) . "
"; + } + } + else + { + $phrase = $DB_sql->fetch_array($phrases); + header("Location: phrasetools.php?do=edit&varname=$phrase[varname]"); + } +} + +?> + + + \ No newline at end of file -- 2.43.5