diff --git a/src/www/ui/admin-tag.php b/src/www/ui/admin-tag.php index 82484ef3..8b2cc69f 100644 --- a/src/www/ui/admin-tag.php +++ b/src/www/ui/admin-tag.php @@ -1,165 +1,163 @@ Name = "admin_tag"; - $this->Title = TITLE_admin_tag; + $this->Name = "admin_tag"; + $this->Title = TITLE_admin_tag; $this->MenuList = "Admin::Tag::Create Tag"; - $this->Version = "1.3"; + $this->Version = "1.3"; $this->DBaccess = PLUGIN_DB_ADMIN; parent::__construct(); } /** * \brief Create Tag without tagging anything * * \return null for success or error text */ function CreateTag() { global $PG_CONN; $tag_name = GetParm('tag_name', PARM_TEXT); $tag_desc = GetParm('tag_desc', PARM_TEXT); if (empty($tag_name)) { $text = _("TagName must be specified. Tag Not created."); return ($text); } + if(!preg_match('/^[A-Za-z0-9_~\-!@#\$%\^&\*\(\)]+$/i', $tag_name)){ + $text = _("A Tag is only allowed to contain characters from ".htmlentities("A-Za-z0-9_~-!@#$%^&*()").". Tag Not created."); + return ($text); + } /* See if the tag already exists */ - $sql = "SELECT * FROM tag WHERE tag = '$tag_name'"; + $sql = "SELECT * FROM tag WHERE tag = '".pg_escape_string($tag_name)."'"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); if (pg_num_rows($result) < 1) { pg_free_result($result); $Val = str_replace("'", "''", $tag_name); $Val1 = str_replace("'", "''", $tag_desc); - $sql = "INSERT INTO tag (tag,tag_desc) VALUES ('$Val', '$Val1');"; + $sql = "INSERT INTO tag (tag,tag_desc) VALUES ('".pg_escape_string($Val)."', '".pg_escape_string($Val1)."');"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); - pg_free_result($result); - }else{ - pg_free_result($result); } - + pg_free_result($result); + /* Make sure it was added */ - $sql = "SELECT * FROM tag WHERE tag = '$tag_name' LIMIT 1;"; + $sql = "SELECT * FROM tag WHERE tag = '".pg_escape_string($tag_name)."' LIMIT 1;"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); if (pg_num_rows($result) < 1) { pg_free_result($result); $text = _("Failed to create tag."); return ($text); } - - $row = pg_fetch_assoc($result); - $tag_pk = $row["tag_pk"]; pg_free_result($result); return (NULL); } /** * \brief Show all tags */ function ShowExistTags() { global $PG_CONN; - $VE = ""; $VE = _("

Current Tags:

\n"); $sql = "SELECT tag_pk, tag, tag_desc FROM tag ORDER BY tag_pk desc;"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); if (pg_num_rows($result) > 0) { $VE .= "\n"; $text1 = _("Tag pk"); $text2 = _("Tag"); $text3 = _("Tag Description"); $VE .= "\n"; while ($row = pg_fetch_assoc($result)) { - $VE .= ""; + $VE .= ""; } $VE .= "
$text1$text2$text3
" . $row['tag_pk'] . "" . $row['tag'] . "" . $row['tag_desc'] . "
" . $row['tag_pk'] . "" . htmlspecialchars($row['tag']) . "" . htmlspecialchars($row['tag_desc']) . "

\n"; } pg_free_result($result); return $VE; } /** * \brief Display the create tag page. */ function ShowCreateTagPage() { $VC = ""; $VC .= _("

Create Tag:

\n"); $VC.= "
\n"; $VC .= "

"; $text = _("Tag"); $VC .= "$text: "; $VC .= "

"; $text = _("Tag description:"); $VC .= "

$text

"; $text = _("Create"); $VC .= "\n"; $VC .= "\n"; $VC .= "
\n"; return $VC; } public function Output() { $V=""; $action = GetParm('action', PARM_TEXT); if ($action == 'add') { $rc = $this->CreateTag(); if (!empty($rc)) { $text = _("Create Tag Failed"); $V .= displayMessage("$text: $rc"); } else { $text = _("Create Tag Successful!"); $V .= displayMessage($text); } } $V .= $this->ShowCreateTagPage(); $V .= $this->ShowExistTags(); return $V; } - } + $NewPlugin = new admin_tag; $NewPlugin->Initialize();