init()) { echo "Cannot open database
\n"; exit; } // Prepare SMTP class $smtp = new smtp_class; $smtp->host_name = "smtp.rhodesia.com"; $smtp->localhost = "localhost"; // Send mail function function smtp_mail($from, $to, $subject, $body, $replyto = "", $bcc = "") { global $smtp; $hdr = array( "From: $from", "To: $to", "Subject: $subject" ); if ($replyto) { $hdr[] = "Reply-to: $replyto"; } if ($bcc) { $hdr[] = "Bcc: $bcc"; } if (!$smtp->SendMessage($from, array($to), $hdr, $body)) { echo "

Could not send the message to $to.\nError: ".$smtp->error."

\n"; } } // Expand CatID to whole trail function breadcrumbs($CatID="") { global $db; global $PHP_SELF; if(empty($CatID)) { return; } $db->get_ParentsInt($CatID); $path = $db->TRAIL; if(!empty($path)) { while ( list ( $key,$val ) = each ($path)) { $CatID = stripslashes($val["CatID"]); $CatName = stripslashes($val["CatName"]); $trail = " > $CatName$trail"; } } else { $trail = ""; } return $trail; } function breadcrumbs_txt($CatID="") { global $db; global $PHP_SELF; if(empty($CatID)) { return; } $db->get_ParentsInt($CatID); $path = $db->TRAIL; if(!empty($path)) { while ( list ( $key,$val ) = each ($path)) { $CatID = stripslashes($val["CatID"]); $CatName = stripslashes($val["CatName"]); if ($trail) { $trail = "$CatName: $trail"; } else { $trail = $CatName; } } } else { $trail = "-"; } return $trail; } // Print page header based on template file function print_header($CatID="",$title="") { global $TEMPLATE_FILE; $trail = breadcrumbs($CatID); $filename = $TEMPLATE_FILE; $fd = fopen ($filename, "r"); $c = fread ($fd, filesize ($filename)); fclose ($fd); $c = eregi_replace("@PHPHOO_BODY@.*", "", $c); $c = str_replace("@TRAIL@", $trail, $c); $c = str_replace("@TITLE@", $title, $c); print ($c); } // Print page footer based on template file function print_footer() { global $db; global $TEMPLATE_FILE; $lnk_cnt = $db->get_approved_cnt(); $new_cnt = $db->get_not_approved_cnt(); $filename = $TEMPLATE_FILE; $fd = fopen ($filename, "r"); $c = fread ($fd, filesize ($filename)); fclose ($fd); $c = eregi_replace(".*@PHPHOO_BODY@", "", $c); $c = str_replace("@LNK_CNT@", $lnk_cnt, $c); $c = str_replace("@NEW_CNT@", $new_cnt, $c); print ($c); } function show_submissions_list($CatID) { global $PHP_SELF; global $db; global $SEE_ALL_SUBMISSIONS; global $TOP_CAT_NAME; if ($SEE_ALL_SUBMISSIONS) { $sub = $db->get_Submissions(); } else { // Need to replace with function to show only for this CatID $sub = $db->get_Submissions(); }; print "\n"; return; } function start_page($CatID="",$title="",$msg="") { global $PHP_SELF; global $SITE_URL; print_header($CatID,$title); if(!empty($msg)) { print "\n
$msg
\n"; } print "

\n"; print '

'; return; } function start_browse($CatID="") { global $PHP_SELF; global $db; global $ADMIN_MODE; global $TOP_CAT_NAME; $data = $db->get_Cats($CatID); $links = $db->get_Links($CatID); $OurCatID = $CatID; if(empty($CatID) || ($CatID == "0")) { $currentID = "top"; $currentName = "$TOP_CAT_NAME"; } else { $currentID = $CatID; $currentName = $db->get_CatNames($CatID); } // Print list of sub categories if(!empty($data)) { $data_cnt = count ($data); $data_left = $data_cnt >> 1; print '
'; print "
    \n"; while ( list ( $key,$val ) = each ($data)) { $CatID = stripslashes($val["CatID"]); $CatName = stripslashes($val["CatName"]); $LinksInCat = $db->get_TotalLinksInCat_cnt($CatID); print "
  • $CatName"; print " ($LinksInCat)"; print "
  • \n"; $data_cnt--; if ($data_cnt == $data_left) { print '
'; print '
'; print '
    '; } } print "
\n"; print "
\n"; } $CatID = $OurCatID; // restore CatID print "$currentName:\n"; // Print list of links print "\n"; print "

"; print " Suggest new link "; print "

\n"; if ($ADMIN_MODE) { print "\n
\n"; print "

Submissions

\n"; show_submissions_list($CatID); $CatID = $OurCatID; // restore CatID // Show form to add a subcategory print "\n
\n"; print "

New Category:

\n"; } // Print the footer print_footer(); return; } // Print drop-down box for available categories function show_cat_selection($SelName = "CatID", $IncludeTop = true, $SecSel = 0, $IncludeNone = false) { global $PHP_SELF; global $db; global $ADMIN_MODE; global $TOP_CAT_NAME; print "\n"; return; } function show_edit_link($LinkID="",$title="",$msg="") { global $PHP_SELF; global $db; global $TOP_CAT_NAME; global $FULL_ADMIN_ACCESS; print_header($CatID,$title,$msg); $thislink = $db->get_OneLink($LinkID); if (empty($thislink)) { print "

Bad LinkID, nothing returned


\n"; return; } while ( list ( $key,$val ) = each ($thislink)) { $CatID = stripslashes($val["CatID"]); $Url = stripslashes($val["Url"]); $LinkName = stripslashes($val["LinkName"]); $Desc = stripslashes($val["Description"]); $Name = stripslashes($val["SubmitName"]); $Email = stripslashes($val["SubmitEmail"]); $SDate = date("D M j G:i:s T Y", $val["SubmitDate"]); } if(!empty($CatID)) { $LinkCatName = $db->get_CatNames($CatID); } else { $LinkCatName = "$TOP_CAT_NAME"; } print "

Edit a Resource in: $LinkCatName


URL:
Title:
Description:
Your Name:
Your Email:
Category:"; show_cat_selection("CatID", True, $CatID); print " Date: $SDate
\n"; print_footer(); return; } function show_add_link($add = "NULL", $CatName = "Unknown") { global $PHP_SELF; global $db; global $TOP_CAT_NAME; global $FULL_ADMIN_ACCESS; global $UserName; // Cookie global $UserEmail; // Cookie session_start(); if(($_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSION['security_code'])) ) { // Insert you code for processing the form here, e.g emailing the submission, entering it into a database. echo 'Thank you. Your message said "'.$_POST['message'].'"'; unset($_SESSION['security_code']); } else { // Insert your code for showing an error message here echo 'Sorry, you have provided an invalid security code'; } print_header($add); print "

Add a link in: $CatName


URL:
Title:
Description:
Your Name:
Your Email:
\"Security <== Enter Security Code
 

\n "; print_footer(); return; } // Mail the admin anytime a new link is submitted function mail_new_link($postData = "") { global $PHP_SELF; global $db; global $ADMIN_EMAIL; if( (empty($postData)) or (!is_array($postData)) ) { return false; } if ($ADMIN_EMAIL == "") { return false; } $CatID = $postData["CatID"]; $Url = addslashes($postData["Url"]); $Description = addslashes($postData["Description"]); $LinkName = addslashes($postData["LinkName"]); $SubmitName = addslashes($postData["SubmitName"]); $SubmitEmail = addslashes($postData["SubmitEmail"]); $SubmitDate = time(); // Get category information $CatName = breadcrumbs_txt($CatID); if (empty($CatName)) { $CatName = "Unknown"; } $Subject = "New Link: "; $Subject .= substr($LinkName, 0, 60); if ($LinkName != substr($LinkName, 0, 60)) { $LinkName .= "..."; } $Subject = trim($Subject); $Body = "User \"$SubmitName\" <".$SubmitEmail."> submitted this link in category $CatName:\n\n"; $Body .= "$LinkName at <$Url>\n\n"; $Body .= "$Description\n\n"; if ($AUTOAPPROVEQUE) { $Body .= "This link was auto-approved.\n"; } else { $Body .= "This link needs approval.\n"; $Body .= "(Use $PHP_SELF? for admin rights!)\n"; } $From = "$SubmitName<".$SubmitEmail.">"; // Send the email notice if email defined if ($ADMIN_EMAIL) { // function smtp_mail($from, $to, $subject, $body, $replyto = "", $bcc = "") smtp_mail($ADMIN_EMAIL, $ADMIN_EMAIL, $Subject, $Body, $From); } return; } // ***************************************************************** // Check cookie to see if we are in admin mode if($HooPass == $ADMIN_COOKIE) { $ADMIN_MODE = true; } $query = getenv("QUERY_STRING"); if( ($viewCat) or ( (!$HTTP_POST_VARS) and (!$query) ) ) { start_page($viewCat); start_browse($viewCat); exit; } elseif($add) { if (("$add" == "top") || empty($add)) { $add = 0; $CatName = "$TOP_CAT_NAME"; } else { $CatName = stripslashes($db->get_CatNames($add)); if (empty($CatName)) { $CatName = "$TOP_CAT_NAME"; } } show_add_link($add, $CatName); exit; } elseif($add_cat) { $err_msg = ""; if ($ADMIN_MODE && $FULL_ADMIN_ACCESS) { if(!$db->add_cat($HTTP_POST_VARS,$err_msg)) { $title = "Error Creating Category"; $msg = "Category not created. ".$err_msg; } else { $title = "Category Created"; $msg = "New subcategory created"; } } else { $title = "Error Creating Category"; $msg = "Not authorized for creating categories"; } start_page($CatID,$title,$msg); start_browse($CatID); exit; } elseif ($suggest) { $err_msg = ""; if(!$db->suggest($HTTP_POST_VARS,$err_msg)) { $title = "Suggestion Error"; $msg = "Suggestion not accepted: ".$err_msg; } else { $title = "Suggestion Submitted"; $msg = "Suggestion submitted for approval"; // Also tell the admin about it mail_new_link($HTTP_POST_VARS); } start_page($CatID,$title,$msg); start_browse($CatID); exit; } elseif ($update) { $err_msg = ""; if ($ADMIN_MODE) { if(!$db->update($HTTP_POST_VARS,$err_msg)) { $title = "Update Error"; $msg = "Update failed: ".$err_msg; } else { $title = "Updated"; $msg = "Updated entry submitted for approval"; } } else { $title = "Update Error"; $msg = "Not authorized"; } start_page($CatID,$title,$msg); start_browse($CatID); exit; } elseif ($approve) { if ($ADMIN_MODE) { if(!$db->approve($approve,$err_msg)) { $title = "Approval Error"; $msg = $err_msg; } else { $title = "Approved"; $msg = "Suggestion approved"; } } else { $title = "Approval Error"; $msg = "Not authorized"; } start_page($CatID,$title,$msg); start_browse($CatID); exit; } elseif ($disapprove) { if ($ADMIN_MODE) { if(!$db->disapprove($disapprove,$err_msg)) { $title = "Disapproval Error"; $msg = $err_msg; } else { $title = "Disapproved"; $msg = "Link disapproved"; } } else { $title = "Disapproval Error"; $msg = "Not authorized"; } start_page($CatID,$title,$msg); start_browse($CatID); exit; } elseif ($delete_link) { if ($ADMIN_MODE) { if(!$db->delete_link($delete_link,$err_msg)) { $title = "Error deleting submission"; $msg = $err_msg; } else { $title = "Deleted"; $msg = "Suggestion deleted"; } } else { $title = "Error deleting submission"; $msg = "Not authorized"; } start_page($CatID,$title,$msg); start_browse($CatID); exit; } elseif ($edit_link) { show_edit_link($edit_link,$title,$msg); exit; } elseif ($KeyWords) { //start_page(); $hits = $db->search($KeyWords); if( (!$hits) or (empty($hits)) ) { $junk = ""; $title = "Search Results"; $msg = "No Matches"; start_page($junk,$title,$msg); } else { $total = count($hits); $title = "Search Results"; $msg = "Search returned $total matches"; $junk = ""; start_page($junk,$title,$msg); while ( list ($key,$hit) = each ($hits)) { if(!empty($hit)) { $LinkID = $hit["LinkID"]; $LinkName = stripslashes($hit["LinkName"]); $LinkDesc = stripslashes($hit["Description"]); $LinkURL = stripslashes($hit["Url"]); $CatID = $hit["CatID"]; $CatName = stripslashes($db->get_CatNames($CatID)); print "
\n"; print "
$LinkName\n"; print "
$LinkDesc\n"; print "
Found In: $CatName\n"; print "
\n"; } } } print "


\n"; start_browse($CatID); exit; } else { // Something terribly bad happened - start fresh start_page("","Error","Unknown error"); start_browse(""); exit; } ?>