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 @@ + +// +// "$Id: links.php,v 1.1 2004/05/20 12:31:54 mike Exp $" +// +// Hierarchical link interface. +// +// Contents: +// +// + + +// +// Include necessary headers... +// + +include "data/html.php"; +include "data/common.php"; + + +// +// 'get_category()' - Get the category path. +// + +function // O - Category path +get_category($id, // I - Category ID + $with_links = 2) // I - 0 = no links, 1 = all links, 2 = all but root +{ + global $PHP_SELF; + + + if ($id == 0) + { + if ($with_links == 1) + return "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("
[ 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("[ Add New Category ]
\n"); + + print("The owner email address cannot be empty!
\n"); + break; + } + + if ($owner_password != "" && $owner_password != $OWNER_PASSWORD && + !$LOGIN_USER) + { + print("The password you supplied does not match the " + ."current password!
\n"); + break; + } + + if ($NEW_PASSWORD != "" && $NEW_PASSWORD != $NEW_PASSWORD2) + { + print("The passwords you supplied do not match!
\n"); + break; + } + + if ($NEW_PASSWORD == "" && $owner_password == "") + { + print("You must supply a password!
\n"); + break; + } + + if ($NEW_PASSWORD != "") + { + $owner_password = $NEW_PASSWORD; + } + + if ($id == 0) + { + // Insert a new record... + db_query("INSERT INTO link VALUES(0,$parent_id," + ."$is_category,$IS_PUBLISHED," + ."'$name','$version','$license'," + ."'$author','$owner_email','$owner_password'," + ."'$email','$homepage','$download'," + ."'$description',$date,$date,5,1,0,0)"); + + $id = db_insertID(); + } + else + { + // Modify the existing record... + db_query("UPDATE link SET is_published=$IS_PUBLISHED," + ."parent_id=$parent_id," + ."name='$name',version='$version',license='$license'," + ."author='$author',owner_email='$owner_email'," + ."owner_password='$owner_password',email='$email'," + ."homepage='$homepage',download='$download'," + ."description='$description',modify_date=$date " + ."WHERE id=$id"); + } + + if ($NEWS != "") + { + $news = mysql_escape_string($NEWS); + + if ($homepage) + $nhp = "links.php?SH$id"; + else + $nhp = ""; + + if ($download) + $ndl = "links.php?SD$id"; + else + $ndl = ""; + + db_query("INSERT INTO news VALUES(0,$id,'$name $version',$date," + ."'$author','$news','$nhp','$ndl',$date,'$email'," + ."0,'','PENDING')"); + } + + print("Your addition will be made visible as soon as one of " + ."moderators approves it.
\n"); + } + + if ($NEWS != "") + { + // Send email to moderators... + mail("cups-link", "$name $version Posted to CUPS News", + "An announcement for '$name $version' has been posted\n" + ."from the CUPS links page and requires your approval before it\n" + ."will be made visible on the CUPS site.\n" + ."\n" + ." http://www.cups.org/private/news.php\n"); + + // Let the user know that the moderator must approve it... + print("Your news announcement will be made visible as soon as one of " + ."moderators approves it.
\n"); + } + + print("\n"); + break; + + case 'V' : // View a listing... + $result = db_query("SELECT * FROM link WHERE id = $id"); + $row = db_next($result); + + $create_date = date("M d, Y", $row['create_date); + $modify_date = date("M d, Y", $row['modify_date); + $category = get_category($row['parent_id); + $rating = (int)(100 * $row['rating_total / $row['rating_count) * 0.01; + $email = sanitize_email($row['email); + + if (($row['homepage_visits + $row['download_visits) > 0) + { + $visits = db_query("SELECT MAX(homepage_visits), " + ."MAX(download_visits) FROM link"); + $visrow = db_next($visits); + + $maxhpv = "MAX(homepage_visits)"; + $maxdlv = "MAX(download_visits)"; + + $popularity = (int)(100 * + ($row['homepage_visits + $row['download_visits) / + ($visrow->$maxhpv + $visrow->$maxdlv)); + + if ($popularity < 0) + $popularity = 0; + + db_free($visits); + } + else + { + $popularity = "???"; + } + + + print("[ " + ."Return to Listings" + ." | " + ."Comments" + ." | " + ."Edit This Listing" + ." | " + ."Delete This Listing ]
\n"); + + print("Category: | " + ."$category | " + ."Rating: | " + ."" + ." | " + ."
---|---|---|---|
Name: | " + ."$row['name | " + ."Popularity: | " + ."$popularity% | " + ."
Version: | " + ."$row['version | " + ."License: | " + ."$row['license | " + ."
Author: | " + ."$row['author | " + ."EMail: | " + ."|
Home Page: | " + ."$row['homepage ($row['homepage_visits visits) | " + ."||
Download: | " + ."$row['download ($row['download_visits visits) | " + ."||
Description: | " + ."$row['description | " + ."
No link ID provided...
\n"); + break; + } + + $result = db_query("SELECT * FROM link WHERE id = $id"); + + if (!$result) + { + print("Link $id does not exist.
\n"); + break; + } + + $row = db_next($result); + + if (!$row) + { + print("Link $id does not exist.
\n"); + break; + } + + $name = $row['name; + $owner_email = $row['owner_email; + $owner_password = $row['owner_password; + + db_free($result); + + if (!$LOGIN_USER && !($OWNER_EMAIL && $OWNER_PASSWORD)) + { + print("Owner email or password doesn't match!
\n"); + break; + } + + db_query("DELETE FROM link WHERE id=$id"); + + print("