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