From 6aec8c479b21b4017dff04f8d75430a47a334e4a Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Thu, 20 May 2004 12:31:54 +0000 Subject: [PATCH] Tweek poll stuff. Tweek link stuff. Add initial links page. --- www/data/mxml.sql | 6 +- www/links.php | 963 +++++++++++++++++++++++++++++++++++++++++ www/phplib/globals.php | 6 +- www/poll.php | 6 +- 4 files changed, 972 insertions(+), 9 deletions(-) create mode 100644 www/links.php diff --git a/www/data/mxml.sql b/www/data/mxml.sql index 3c45544..7fb45e9 100644 --- a/www/data/mxml.sql +++ b/www/data/mxml.sql @@ -1,5 +1,5 @@ -- --- "$Id: mxml.sql,v 1.4 2004/05/20 03:38:42 mike Exp $" +-- "$Id: mxml.sql,v 1.5 2004/05/20 12:31:54 mike Exp $" -- -- Database schema for the Mini-XML web pages. -- @@ -90,7 +90,7 @@ CREATE TABLE link ( email VARCHAR(255), -- Public email address homepage_url VARCHAR(255), -- Home page download_url VARCHAR(255), -- Download page - description TEXT, -- HTML description of link + description TEXT, -- Description of link rating_total INTEGER, -- Total of all ratings rating_count INTEGER, -- Number of ratings homepage_visits INTEGER, -- Number of clicks to the home page @@ -242,5 +242,5 @@ CREATE TABLE vote ( ); -- --- End of "$Id: mxml.sql,v 1.4 2004/05/20 03:38:42 mike Exp $". +-- End of "$Id: mxml.sql,v 1.5 2004/05/20 12:31:54 mike Exp $". -- diff --git a/www/links.php b/www/links.php new file mode 100644 index 0000000..789ba77 --- /dev/null +++ b/www/links.php @@ -0,0 +1,963 @@ +Root"; + else + return "Root"; + } + else if ($id < 0) + { + return "All"; + } + + $result = db_query("SELECT name, id, parent_id FROM link WHERE id = $id"); + $category = ""; + + if ($result) + { + $row = db_next($result); + + if ($row) + { + if ($with_links || $row['parent_id'] > 0) + $category = get_category($row['parent_id'], 1) . "/"; + + if ($with_links == 1) + $category .= "" + . htmlspecialchars($row[name]) . ""; + else + $category .= htmlspecialchars($row['name']); + } + + db_free($result); + } + + return ($category); +} + + +// +// 'select_category()' - Get a list of all categories. +// + +function +select_category($parent_id = 0, // I - Parent ID + $is_category = 0) // I - Selecting for category? +{ + // Scan the table for categories... We add "C" to the ID to + // avoid PHP thinking we want an actual index in the array. + $result = db_query("SELECT name,id FROM link " + ."WHERE is_published != 0 AND is_category != 0 " + ."ORDER BY name"); + + $cats = array(); + + while ($row = db_next($result)) + $cats["C$row[id]"] = get_category($row['id'], 0); + + db_free($result); + + // Add the Root category if we are adding or modifying a category. + if ($is_category) + $cats["C0"] = "Root"; + + // Sort the category list... + asort($cats); + + // List the categories for selection... + print(""); +} + + +// Set globals... +$id = 0; +$parent_id = 0; +$query = ''; + +if ($LOGIN_LEVEL >= AUTH_DEVEL) +{ + $op = 'Z'; +} +else +{ + $op = 'L'; +} + +// Check command-line... +$redirect = 0; + +for ($i = 0; $i < $argc; $i ++) +{ + switch ($argv[$i][0]) + { + case 'F' : // Form + case 'U' : // Update/add + $op = $argv[$i][0]; + $type = $argv[$i][1]; + $id = (int)substr($argv[$i], 2); + break; + + case 'L' : // List or search + $op = 'L'; + if (strlen($argv[$i]) > 1 && $argv[$i][1] == 'A') + $parent_id = -1; + break; + + case 'P' : // Parent + $parent_id = (int)substr($argv[$i], 1); + break; + + case 'V' : // View + $op = 'V'; + $id = (int)substr($argv[$i], 1); + break; + + case 'X' : // Delete + $op = 'X'; + $id = (int)substr($argv[$i], 1); + break; + + case 'Z' : // List new entries + $op = 'Z'; + break; + + case 'r' : // Rate + $op = $argv[$i][0]; + $id = (int)substr($argv[$i], 1); + $redirect = 1; + break; + + case 'S' : // Show web or download page + if (strncmp($argv[$i], "SEARCH", 6)) + { + // Don't treat SEARCH as a show command... + $op = $argv[$i][0]; + $type = $argv[$i][1]; + $id = (int)substr($argv[$i], 2); + $redirect = 1; + } + break; + + default : + header("Location: $PHP_SELF"); + exit(); + } +} + +// Check for form search data... +if (array_key_exists("SEARCH", $_GET)) + $SEARCH = $_GET["SEARCH"]; +else if (array_key_exists("SEARCH", $_POST)) + $SEARCH = $_POST["SEARCH"]; +else + $SEARCH = ""; + +if (!$redirect) +{ + html_header("Links"); + print("

Links

\n"); + print("
\n" + ."
" + ."" + ."" + ."
\n" + ."
\n" + ."
\n"); +} + +if ($SEARCH) +{ + // Yes, construct a query... + $op = 'L'; + $search_string = $SEARCH; + $search_string = str_replace("'", " ", $search_string); + $search_string = str_replace("\"", " ", $search_string); + $search_string = str_replace("\\", " ", $search_string); + $search_string = str_replace("%20", " ", $search_string); + $search_string = str_replace("%27", " ", $search_string); + $search_string = str_replace(" ", " ", $search_string); + $search_words = explode(' ', $search_string); + + // Loop through the array of words, adding them to the + $prefix = ""; + $next = "OR"; + + reset($search_words); + while ($keyword = current($search_words)) + { + next($search_words); + $keyword = ltrim(rtrim($keyword)); + + if (strcasecmp($keyword, 'or') == 0) + { + $next = 'OR'; + if ($prefix != '') + $prefix = 'OR'; + } + else if (strcasecmp($keyword, 'and') == 0) + { + $next = 'AND'; + if ($prefix != '') + $prefix = 'AND'; + } + else + { + $query = "$query $prefix name LIKE '%$keyword%'"; + $prefix = $next; + } + } +} + +switch ($op) +{ + case 'F' : // Form... + if ($type == 'C') + $typename = 'Category'; + else + $typename = 'Listing'; + + if ($id > 0) + $opname = 'Update'; + else + $opname = 'Add'; + + print("

$opname $typename

\n"); + + if ($id > 0) + { + $result = db_query("SELECT * FROM link WHERE id = $id"); + $row = db_next($result); + + $parent_id = $row['parent_id']; + $is_category = $row['is_category']; + $is_published = $row['is_published']; + $name = htmlspecialchars($row['name'], ENT_QUOTES); + $version = htmlspecialchars($row['version'], ENT_QUOTES); + $license = htmlspecialchars($row['license'], ENT_QUOTES); + $author = htmlspecialchars($row['author'], ENT_QUOTES); + $email = htmlspecialchars($row['email'], ENT_QUOTES); + $homepage = htmlspecialchars($row['homepage'], ENT_QUOTES); + $download = htmlspecialchars($row['download'], ENT_QUOTES); + $description = htmlspecialchars($row['description'], ENT_QUOTES); + $create_date = $row['create_date']; + $modify_date = $row['modify_date']; + + db_free($result); + } + else + { + if ($type == 'C') + $is_category = 1; + else + $is_category = 0; + + $is_published = 0; + $name = ""; + $version = ""; + $license = ""; + $author = ""; + $owner_email = ""; + $owner_password = ""; + $email = ""; + $homepage = "http://"; + $download = "ftp://"; + $description = ""; + $create_date = time(); + $modify_date = time(); + } + + print("
\n" + ."
\n"); + + if ($LOGIN_LEVEL >= AUTH_DEVEL) + { + print("\n"); + } + else + { + print("\n"); + } + + print("" + ."" + ."" + ."\n"); + + print("\n"); + + if (!$is_category) + { + print("" + ."" + ."" + ."\n"); + + print("" + ."" + ."" + ."\n"); + + print("" + ."" + ."" + ."\n"); + + print("" + ."" + ."" + ."\n"); + + print("" + ."" + ."" + ."\n"); + + print("" + ."" + ."" + ."\n"); + + print("" + ."" + ."" + ."\n"); + } + + print("" + ."" + ."" + ."\n"); + print("" + ."" + ."" + ."\n"); + + print("
Published:"); + select_is_published($is_published); + print("
Name:
Category:"); + select_category($parent_id, $is_category); + print("
Version:
License:
Author:
EMail:
Home Page URL:
Download URL:
Description:
Announcment:
\n"); + print("
"); + break; + + case 'L' : // List... + print("

Show All Listings | " + ."Show Listings by " + ."Category ]

\n"); + + if ($SEARCH == "") + $category = get_category($parent_id); + else + $category = "Search"; + + // Show the categories... + if ($query != "") + $result = db_query("SELECT * FROM link " + ."WHERE is_published = 1 AND is_category = 1 AND " + ."($query) " + ."ORDER BY name"); + else if ($parent_id >= 0) + $result = db_query("SELECT * FROM link " + ."WHERE is_published = 1 AND is_category = 1 AND " + ."parent_id = $parent_id " + ."ORDER BY name"); + else + $result = db_query("SELECT * FROM link " + ."WHERE is_published = 1 AND is_category = 1 " + ."ORDER BY name"); + + if ($parent_id < 0) + { + print("

All Categories