#
# Table structure for table 'php_category'
#
CREATE TABLE php_category (
category varchar(30) NOT NULL,
category_id varchar(15) NOT NULL,
num_item int(5) NOT NULL,
PRIMARY KEY (category_id)
);
#
# Dumping data for table 'php_category'
#
INSERT INTO php_category VALUES( 'General', '001', '2');
INSERT INTO php_category VALUES( 'Code Snippets', '005', '0');
INSERT INTO php_category VALUES( 'Articles', '004', '0');
INSERT INTO php_category VALUES( 'Portal', '002', '1');
INSERT INTO php_category VALUES( 'Applications', '003', '1');
INSERT INTO php_category VALUES( 'Books', '007', '1');
INSERT INTO php_category VALUES( 'Communities', '006', '0');
INSERT INTO php_category VALUES( 'Tutorials', '008', '10');
INSERT INTO php_category VALUES( 'Discussion Boards', '003001', '0');
INSERT INTO php_category VALUES( 'Chats', '003002', '3');
INSERT INTO php_category VALUES( 'Advertisements', '003003', '0');
INSERT INTO php_category VALUES( 'Shopping Carts', '003004', '0');
INSERT INTO php_category VALUES( 'File System', '003005', '0');
INSERT INTO php_category VALUES( 'Email', '003006', '0');
INSERT INTO php_category VALUES( 'Games', '003007', '1');
INSERT INTO php_category VALUES( 'Databases', '003008', '0');
INSERT INTO php_category VALUES( 'PHP General', '004001', '0');
INSERT INTO php_category VALUES( 'Functions', '004002', '0');
INSERT INTO php_category VALUES( 'Database Connectivity', '004003', '0');
INSERT INTO php_category VALUES( 'Session Management', '004004', '0');
INSERT INTO php_category VALUES( 'Extending PHP', '004005', '0');
INSERT INTO php_category VALUES( 'OOP', '004006', '0');
INSERT INTO php_category VALUES( 'PHP General', '005001', '0');
INSERT INTO php_category VALUES( 'Functions', '005002', '0');
INSERT INTO php_category VALUES( 'Database Connectivity', '005003', '1');
INSERT INTO php_category VALUES( 'Classes', '005004', '1');
INSERT INTO php_category VALUES( 'ETC', '005005', '0');
INSERT INTO php_category VALUES( 'Forums', '006001', '1');
INSERT INTO php_category VALUES( 'Mailing Lists', '006002', '0');
INSERT INTO php_category VALUES( 'Amazon', '007001', '1');
INSERT INTO php_category VALUES( 'Barnes & Nobles', '007002', '0');
INSERT INTO php_category VALUES( 'Publishers', '007003', '1');
INSERT INTO php_category VALUES( 'PHP General', '006002001', '0');
INSERT INTO php_category VALUES( 'Zend', '006002002', '0');
INSERT INTO php_category VALUES( 'Developers', '006002003', '0');
INSERT INTO php_category VALUES( 'Business', '009', '2');
INSERT INTO php_category VALUES( 'Reviews', '004007', '0');
INSERT INTO php_category VALUES( 'Generic Chats', '003002001', '0');
INSERT INTO php_category VALUES( 'PHP Chats', '003002002', '0');
#
# Table structure for table 'php_directory'
#
CREATE TABLE php_directory (
url_id int(10) NOT NULL auto_increment,
category_id varchar(15) NOT NULL,
title varchar(150) NOT NULL,
url varchar(150) NOT NULL,
description text NOT NULL,
registerdate date,
hit int(5) NOT NULL,
lastaccesstime timestamp(14),
password varchar(20) binary,
email varchar(100) NOT NULL,
approved char(1) NOT NULL,
PRIMARY KEY (url_id),
UNIQUE url (url, category_id)
);
#
# Dumping data for table 'php_directory'
#
INSERT INTO php_directory VALUES( '2', '008', 'Beginning PHP', '
www.wrox.com/beginning.html', 'A great tutorial on PHP for novice programmers.', '2000-08-06', '2', '20000807175258', '.vBFuC/XAvCJA', '111', '1');
INSERT INTO php_directory VALUES( '4', '008', 'PHP MySQL Connectivity', '
www.wrox.com/mysql.html', 'A tutorial on PHP MySQL Connectivity.', '2000-08-06', '0', '20000807121308', '.vcIuwC90zXcw', '222', '1');
INSERT INTO php_directory VALUES( '1', '003007', 'Game Programming', '
www.phpgames.com', 'Fun and Games!', '2000-08-06', '3', '20000808013608', '.vX/x4C0x/87k', 'wankyu@neoqst.com', '1');
INSERT INTO php_directory VALUES( '3', '008', 'A series of tutorials on file system', '
www.wrox.com/file.html', 'File System Tutorials.', '2000-08-06', '0', '20000807121348', '.vBFuC/XAvCJA', '111', '1');
INSERT INTO php_directory VALUES( '5', '008', 'Postgre Tutorial', '
www.wrox.com/Postgre.html', 'Postre Tutorial.', '2000-08-06', '0', '20000807121420', '.vuPSRSHFDcjw', '333', '1');
INSERT INTO php_directory VALUES( '6', '008', 'Sending Emails in PHP', '
www.wrox.com/email.html', 'Email tutorials.', '2000-08-06', '3', '20000807121452', '.v5yduNWrR8JM', '555', '1');
INSERT INTO php_directory VALUES( '7', '008', 'Creating Web Boards', '
www.wrox.com/board.html', 'Tutorials on discussion boards.', '2000-08-06', '0', '20000807121516', '.vHalmtJBzyMQ', '3', '1');
INSERT INTO php_directory VALUES( '8', '008', 'Object Oriented Programming in PHP', '
www.wrox.com/oop.html', 'Tutorials on OOP.', '2000-08-06', '0', '20000807121544', '.vYb1izGesU3Y', '1', '1');
INSERT INTO php_directory VALUES( '9', '008', 'Game Programming in PHP', '
www.wrox.com/game.html', 'Tutorials on Game Programming in PHP.', '2000-08-06', '0', '20000807121608', '.vHalmtJBzyMQ', '3', '1');
INSERT INTO php_directory VALUES( '10', '008', 'Data Types in PHP', '
www.wrox.com/data.html', 'Tutorials on working with PHP data types.', '2000-08-06', '0', '20000807121638', '.vHalmtJBzyMQ', '3', '1');
INSERT INTO php_directory VALUES( '11', '008', 'Creating Shopping Carts', '
www.wrox.com/cart.html', 'Tutorials on creating e-commerce applications in PHP.', '2000-08-06', '0', '20000807121721', '.vYb1izGesU3Y', '22', '1');
INSERT INTO php_directory VALUES( '13', '003002', 'A great chat site built in PHP', '
www.phpchat.com', 'Another PHP chat site!', '2000-08-06', '0', '20000807120522', '.vwK9w0qHJ98g', 'wankyu@neoqst.com', '1');
INSERT INTO php_directory VALUES( '14', '003002', 'PHP Chat', '
www.bestphpchat.com', 'The greatest PHP chat site on the net!', '2000-08-06', '0', '20000807120356', '.v/bKRi/.bnfk', 'sdf', '1');
INSERT INTO php_directory VALUES( '15', '007001', 'Beginning PHP', '
www.amazon.com', 'A great book on PHP!', '2000-08-07', '2', '20000808014317', '.vX/x4C0x/87k', 'wankyu@neoqst.com', '1');
INSERT INTO php_directory VALUES( '16', '009', 'PHP Biz!', '
www.phpbiz.com', 'PHP biz!', '2000-08-07', '0', '20000807120655', '.vX/x4C0x/87k', 'wankyu@neoqst.com', '1');
INSERT INTO php_directory VALUES( '17', '005004', 'MIME Mailer', '
www.mimemailer.com', 'A MIME Mailer class.', '2000-08-07', '1', '20000807223022', '.vX/x4C0x/87k', 'wankyu@neoqst.com', '1');
INSERT INTO php_directory VALUES( '18', '005003', 'MySQL Admin', '
www.mysqladmin.com', 'A MySQL admin script.', '2000-08-07', '0', '20000807120825', '.vX/x4C0x/87k', 'wankyu@neoqst.com', '1');
INSERT INTO php_directory VALUES( '19', '006001', 'PHP Forum', 'www.phpforumcom', 'PHP Forum.', '2000-08-07', '0', '20000807120905', '.vX/x4C0x/87k', 'wankyu@neoqst.com', '1');
INSERT INTO php_directory VALUES( '20', '001', 'PHP Home', '
www.php.net', 'PHP Homepage.', '2000-08-07', '0', '20000807121122', '.vX/x4C0x/87k', 'wankyu@neoqst.com', '1');
INSERT INTO php_directory VALUES( '21', '001', 'Zend Website', '
www.zend.com', 'Zend!', '2000-08-07', '2', '20000807175303', '.vX/x4C0x/87k', 'wankyu@neoqst.com', '1');
INSERT INTO php_directory VALUES( '22', '007003', 'Wrox Press Inc.', '
www.wrox.com', 'Wrox Press Inc.', '2000-08-07', '9', '20000808003129', '.vX/x4C0x/87k', 'wankyu@neoqst.com', '1');
INSERT INTO php_directory VALUES( '23', '002', 'One and Only PHP Portal', '
www.phpportal.com', 'One and Only PHP Portal.', '2000-08-07', '0', '20000807121839', '.vX/x4C0x/87k', 'wankyu@neoqst.com', '1');
INSERT INTO php_directory VALUES( '24', '003002', 'PHP Chat World!', '
www.phpchatworld.com', 'PHP Chat World! Come and get some!', '2000-08-07', '0', '20000807130014', '.vX/x4C0x/87k', 'wankyu@neoqst.com', '1');
INSERT INTO php_directory VALUES( '25', '009', 'Buy and Sell PHP Scripts', '
www.buyandsellphpscripts.com', 'Make bucks out of your scripts!', '2000-08-07', '0', '20000807130559', '.vX/x4C0x/87k', 'wankyu@neoqst.com', '1');
INSERT INTO php_directory VALUES( '26', '003', 'NeoQuest Communications, Inc.', '
www.neoqst.com', 'A great PHP showcase site!', '2000-08-07', '3', '20000812130908', '.vX/x4C0x/87k', 'wankyu@neoqst.com', '1');
INSERT INTO php_directory VALUES( '27', '007', 'Professional PHP Programming', '
www.wrox.com', 'A great book on PHP for advanced programmers.', '2000-08-07', '2', '20000807175252', '.vX/x4C0x/87k', 'wankyu@neoqst.com', '1');
INSERT INTO php_directory VALUES( '28', '001', 'Learning PHP!', '
www.learnphp.com', 'A great site where you can learn everything about PHP!', '2000-08-09', '0', '20000809191348', '.vX/x4C0x/87k', 'wankyu@neoqst.com', '0');
GRANT ALL ON php_category.* TO phpuser IDENTIFIED BY 'phppass';
GRANT ALL ON php_directory.* TO phpuser IDENTIFIED BY 'phppass';
<?php
include ("./php_directory.inc");
switch($action) {
case "add_url_form":
add_url_form();
break;
case "add_url":
add_url();
break;
case "modify_url_form":
modify_url_form();
break;
case "modify_url":
modify_url();
break;
case "go_url":
go_url();
break;
default:
directory_header();
show_list();
directory_footer();
break;
}
?>
<?php
include "./php_directory.inc";
function list_categories() {
global $default_dbname, $directory_tablename, $category_tablename, $PHP_SELF;
global $link_id, $mode, $root_category_id, $category_id_length;
if(!$link_id) $link_id = db_connect($default_dbname);
if(!isset($mode)) $mode = 'add_category';
$query = "SELECT count(*) FROM $category_tablename WHERE length(category_id) = $category_id_length";
$result = mysql_query($query);
if(!$result) die(sql_error());
$query_data = mysql_fetch_row($result);
$top_level_total = $query_data[0];
$query = "SELECT category_id FROM $category_tablename ORDER BY category_id";
$result = mysql_query($query);
if(!$result) die(sql_error());
directory_header();
top_menu();
$category_info_array = get_category_info($root_category_id);
if($mode == 'add_category') {
echo "<CENTER>Click on the level on which you want to add a new category.</CENTER><P>";
echo "<BLOCKQUOTE>\n";
echo "<A HREF=\"java script:open_window('$PHP_SELF?action=add_category_form&parent=$root_category_id')\">" . $category_info_array["category"] ." </A>(" . $category_info_array["num_child"] . ")";
}
else {
echo "<CENTER>Click on the category you want to edit.</CENTER><P>";
echo "<BLOCKQUOTE>\n";
echo "<A HREF=\"java script:open_window('$PHP_SELF?action=edit_category_form&category_id=$root_category_id')\">" . $category_info_array["category"] ." </A>(" . $category_info_array["num_child"] . ")";
}
echo "<BR>\n";
echo "<BLOCKQUOTE>\n";
while($query_data = mysql_fetch_array($result)) {
$category_id = $query_data[0];
$category_info_array = get_category_info($category_id);
for($i=0; $i < $category_info_array["depth"]; $i++) echo "---";
echo " <A HREF=\"$PHP_SELF?action=delete_category&category_id=$category_id&mode=$mode\" OnClick=\"return confirm('Are you sure? It holds " . $category_info_array["num_child"] . " subcategories and " . $category_info_array["num_item"] . " items.');\">X</A> \n";
if($mode == 'add_category')
echo "<A HREF=\"java script:open_window('$PHP_SELF?action=add_category_form&parent=$category_id')\">" . $category_info_array["category"] ." </A>(" . $category_info_array["num_child"] . ")";
else echo "<A HREF=\"java script:open_window('$PHP_SELF?action=edit_category_form&category_id=$category_id')\">" . $category_info_array["category"] ." </A>(" . $category_info_array["num_child"] . ")";
echo "<BR>\n";
}
echo "</BLOCKQUOTE>\n";
echo "</BLOCKQUOTE>\n";
directory_footer();
}
function add_category_form() {
global $default_dbname, $directory_tablename, $category_tablename, $PHP_SELF;
global $link_id, $parent;
$category_info_array = get_category_info($parent);
$category_id = $category_info_array["next_id"];
$category_fullname = $category_info_array["fullname"];
directory_header();
?>
<CENTER><H3>Adding a New Category: <?php echo $category_fullname ?></H3></CENTER>
<FORM METHOD="POST" ACTION="<?php echo $PHP_SELF ?>">
<INPUT TYPE="HIDDEN" NAME="action" VALUE="add_category">
<INPUT TYPE="HIDDEN" NAME="category_id" VALUE="<? echo $category_id ?>">
<CENTER><TABLE BORDER="1" WIDTH="90%">
<TR>
<TH WIDTH="30%" NOWRAP>Category ID</TH>
<TD WIDTH="70%"><?php echo $category_id ?></TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>Category Name</TH>
<TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="category" SIZE="20"></TD>
</TR>
<TR>
<TH WIDTH="100%" COLSPAN="2" NOWRAP><INPUT TYPE="SUBMIT" VALUE="Submit"> <INPUT TYPE="RESET" VALUE="Reset"></TH>
</TR>
</TABLE>
</CENTER>
</FORM>
<?php
directory_footer();
}
function add_category() {
global $default_dbname, $directory_tablename, $category_tablename, $PHP_SELF;
global $link_id, $category_id, $category;
if(empty($category)) error_message("Enter the category name!");
if(!$link_id) $link_id = db_connect($default_dbname);
$query = "INSERT INTO $category_tablename VALUES('$category', '$category_id', 0)";
$result = mysql_query($query);
if(!$result) error_message(sql_error());
directory_header();
echo "<SCRIPT>alert(\"$category was successfully added!\"); opener.location.href='$PHP_SELF'; self.close();</SCRIPT>";
directory_footer();
}
function edit_category_form() {
global $default_dbname, $directory_tablename, $category_tablename, $PHP_SELF;
global $link_id, $category_id;
$category_info_array = get_category_info($category_id);
directory_header();
?>
<CENTER><H3>Editing the Category: <?php echo $category_info_array["fullname"] ?></H3></CENTER>
<FORM METHOD="POST" ACTION="<?php echo $PHP_SELF ?>">
<INPUT TYPE="HIDDEN" NAME="action" VALUE="edit_category">
<INPUT TYPE="HIDDEN" NAME="category_id" VALUE="<? echo $category_id ?>">
<CENTER><TABLE BORDER="1" WIDTH="90%">
<TR>
<TH WIDTH="30%" NOWRAP>Category ID</TH>
<TD WIDTH="70%"><?php echo $category_id ?></TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>Category Name</TH>
<TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="category" VALUE="<?php echo $category_info_array["category"] ?>" SIZE="20"></TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>Resources</TH>
<TD WIDTH="70%"><?php echo $category_info_array["num_item"] ?></TD>
</TR>
<TR>
<TH WIDTH="100%" COLSPAN="2" NOWRAP><INPUT TYPE="SUBMIT" VALUE="Submit"> <INPUT TYPE="RESET" VALUE="Reset"></TH>
</TR>
</TABLE>
</CENTER>
</FORM>
<?php
directory_footer();
}
function edit_category() {
global $default_dbname, $directory_tablename, $category_tablename, $PHP_SELF;
global $link_id, $category_id, $category;
if(empty($category)) error_message("Enter the category name!");
if(!$link_id) $link_id = db_connect($default_dbname);
$query = "UPDATE $category_tablename SET category = '$category' WHERE category_id = '$category_id'";
$result = mysql_query($query);
if(!$result) error_message(sql_error());
if(!mysql_affected_rows($link_id)) error_message("Nothing changed!");
directory_header();
echo "<SCRIPT>alert(\"$category was successfully updated!\"); opener.location.href='$PHP_SELF?mode=edit_category'; self.close();</SCRIPT>";
directory_footer();
}
function delete_category() {
global $default_dbname, $directory_tablename, $category_tablename, $PHP_SELF;
global $link_id, $category_id, $mode;
if(empty($category_id)) error_message("Empty Category ID!");
if(!$link_id) $link_id = db_connect($default_dbname);
$query = "DELETE FROM $category_tablename WHERE category_id LIKE '$category_id%'";
$result = mysql_query($query);
if(!$result) error_message(sql_error());
$del_subs = mysql_affected_rows($link_id) - 1;
$query = "DELETE FROM $directory_tablename WHERE category_id LIKE '$category_id%'";
$result = mysql_query($query);
if(!$result) error_message(sql_error());
$del_items = mysql_affected_rows($link_id);
echo "<SCRIPT>alert(\"1 category, $del_subs subcategories, and $del_items items were deleted!\"); self.location.href='$PHP_SELF?mode=$mode';</SCRIPT>";
}
function update_db() {
global $default_dbname, $directory_tablename, $category_tablename, $PHP_SELF;
global $link_id, $category_id, $mode;
directory_header();
if(!$link_id) $link_id = db_connect($default_dbname);
$query = "SELECT category, category_id, num_item FROM $category_tablename";
$result = mysql_query($query);
if(!$result) error_message(sql_error());
$num_revs = 0;
while($query_data = mysql_fetch_row($result)) {
$category = $query_data[0];
$category_id = $query_data[1];
$num_item = $query_data[2];
$query = "SELECT count(*) FROM $directory_tablename WHERE category_id = '$category_id' AND approved = 1";
$result2 = mysql_query($query);
$query_data2 = mysql_fetch_row($result2);
$total = $query_data2[0];
if(!$result2) error_message(sql_error());
if($num_item != $total) {
$query = "UPDATE $category_tablename SET num_item = $total WHERE category_id = '$category_id'";
$result2 = mysql_query($query);
if(!$result2) die(sql_error());
echo "Number of resources in <STRONG>\"$category\"</STRONG> mismatch -> revised: $total resources.<BR>\n";
$num_revs++;
}
}
if(!$num_revs) echo "No inconsistency found.<BR>\n";
else if($num_revs) echo "$num_revs inconsistency has been corrected.<BR>\n";
else echo "$num_revs inconsistencies have been corrected.<BR>\n";
echo "Done.\n";
directory_footer();
}
function view_new() {
global $default_dbname, $directory_tablename, $category_tablename, $records_per_page, $PHP_SELF, $link_id;
global $cur_page;
if(!$link_id) $link_id = db_connect($default_dbname);
$query = "SELECT count(*) FROM $directory_tablename WHERE approved != 1";
$result = mysql_query($query);
if(!$result) echo error_message(sql_error());
$query_data = mysql_fetch_row($result);
$total_num = $query_data[0];
if(!$total_num) echo error_message("No new listing!");
$limit_str = "LIMIT " . $cur_page * $records_per_page . ", $records_per_page";
$query = "SELECT url_id, url, title, description, category_id FROM $directory_tablename WHERE approved = 0 ORDER BY registerdate $limit_str";
$result = mysql_query($query);
if(!$result) echo error_message(sql_error());
$page_num = $cur_page + 1;
$total_num_page = floor($total_num/$records_per_page);
$last_page_num = $total_num_page + 1;
directory_header();
top_menu();
echo "<CENTER><H3>Displaying the page $page_num out of $last_page_num.</H3></CENTER>";
echo "<UL>\n";
while($query_data = mysql_fetch_array($result)) {
$url_id = $query_data["url_id"];
$url = "
http://" . $query_data["url"];
$title = $query_data["title"];
$description = $query_data["description"];
$category_id = $query_data["category_id"];
$category_info_array = get_category_info($category_id);
$category_fullname = $category_info_array["fullname"];
echo "<LI>\n";
echo "<A HREF=\"java script:open_window('$PHP_SELF?action=edit_new_form&url_id=$url_id&category_id=$category_id');\">[Edit]</A> \n";
echo "<A HREF=\"$url\" TARGET=\"_BLANK\">$title ($category_fullname)</A> - $description\n";
echo "</LI>";
}
echo "</UL>\n";
echo "<BR>\n";
echo "<STRONG><CENTER>";
if($cur_page > 0) echo "<A HREF=\"$PHP_SELF?action=view_new&cur_page=0\">[Top]</A>";
if($cur_page != 0) {
$prev_page = $cur_page - 1;
echo "<A HREF=\"$PHP_SELF?action=view_new&cur_page=$prev_page\">[Prev]</A> ";
}
if($cur_page < $total_num_page) {
$next_page = $cur_page + 1;
echo "<A HREF=\"$PHP_SELF?action=view_new&cur_page=$next_page\">[Next]</A> ";
}
if($cur_page != $total_num_page) echo "<A HREF=\"$PHP_SELF?action=view_new&cur_page=$total_num_page\">[Bottom]</A>";
echo "</CENTER></STRONG>";
directory_footer();
}
function edit_new_form() {
global $PHP_SELF, $max_desc_length, $url_id, $category_id;
directory_header();
$url_info_array = get_url_info($url_id);
$category_info_array = get_category_info($url_info_array["category_id"]);
?>
<CENTER><H3>Editing a new listing.</H3></CENTER>
<UL>
<LI>Submitted on: <?php echo $url_info_array["formatted_registerdate"] ?></LI>
</UL>
<FORM METHOD="POST" ACTION="<?php echo $PHP_SELF ?>">
<INPUT TYPE="HIDDEN" NAME="action" VALUE="edit_new">
<INPUT TYPE="HIDDEN" NAME="url_id" VALUE="<? echo $url_id ?>">
<INPUT TYPE="HIDDEN" NAME="category_id" VALUE="<? echo $category_id ?>">
<CENTER><TABLE BORDER="1" WIDTH="90%">
<TR>
<TH WIDTH="20%" NOWRAP>Category</TH>
<TD WIDTH="80%"><?php echo $category_info_array["fullname"] ?></TD>
</TR>
<TR>
<TH WIDTH="20%" NOWRAP>Email</TH>
<TD WIDTH="80%"><?php echo $url_info_array["email"] ?><INPUT TYPE="HIDDEN" NAME="email" VALUE="<?php echo $url_info_array["email"] ?>"></TD>
</TR>
<TR>
<TH WIDTH="20%" NOWRAP>Title</TH>
<TD WIDTH="80%"><INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $url_info_array["title"] ?>" SIZE="30" MAXLENGTH="150"></TD>
</TR>
<TR>
<TH WIDTH="20%" NOWRAP>URL</TH>
<TD WIDTH="80%"><INPUT TYPE="TEXT" NAME="url" VALUE="<?php echo "
http://" . $url_info_array["url"]; ?>" SIZE="30" MAXLENGTH="150"></TD>
</TR>
<TR>
<TH WIDTH="20%" NOWRAP>Description<BR>(<?php echo $max_desc_length ?> Chars Max.)</TH>
<TD WIDTH="80%"><TEXTAREA NAME="description" ROWS="5" COLS="40"><?php echo $url_info_array["description"] ?></TEXTAREA></TD>
</TR>
<TR>
<TH WIDTH="20%" NOWRAP>Action</TH>
<TD WIDTH="80%"><INPUT TYPE="RADIO" VALUE="approve" NAME="option" CHECKED>Approve <INPUT TYPE="RADIO" VALUE="delete" NAME="option">Delete</TD>
</TR>
<TR>
<TH WIDTH="100%" NOWRAP COLSPAN="2"><INPUT TYPE="SUBMIT" VALUE="Edit URL" NAME="Submit"> <INPUT TYPE="RESET" VALUE="Reset"></TH>
</TR>
</TABLE>
</CENTER>
</FORM>
<?php
directory_footer();
}
function edit_new() {
global $default_dbname, $directory_tablename, $category_tablename, $max_desc_length;
global $title, $url, $description, $category_id, $url_id, $email, $option;
global $dirmaster_email, $link_id, $send_mail;
$url = eregi_replace('
http://', "", $url);
$url = eregi_replace("/$", "", $url);
if(empty($title)) error_message("Please enter the title!");
if(empty($url)) error_message("Please enter the URL!");
if(empty($description)) error_message("Please enter the description!");
if(!$link_id) $link_id = db_connect($default_dbname);
if($option == 'delete') {
$query = "DELETE FROM $directory_tablename WHERE url_id = '$url_id'";
$result = mysql_query($query);
if(!$result) error_message(sql_error());
$num_rows = mysql_affected_rows($link_id);
if($num_rows != 1) error_message(sql_error());
else echo "<SCRIPT>alert(\"$title($url) has been successfully deleted!\"); opener.location.href='$PHP_SELF?action=view_new'; self.close();</SCRIPT>";
}
else {
if(strlen($description) > $max_desc_length) error_message("Description too long! $max_desc_length chars max!");
$title = addslashes($title);
$description = addslashes($description);
$query = "UPDATE $category_tablename SET num_item = num_item + 1 WHERE category_id = '$category_id'";
$result = mysql_query($query);
if(!$result) error_message(sql_error());
$query = "UPDATE $directory_tablename SET title='$title', url='$url', description='$description', approved = 1 WHERE url_id='$url_id'";
$result = mysql_query($query);
if(!$result) error_message(sql_error());
if($send_mail){
$mail_subject = "PHP Directory>> Your contribution has been listed.";
$mail_body = "Thank you for sharing your resources with us.\n";
$mail_body = "Your contribution has been listed. Thank you.\n\n";
$mail_body .= "Title: $title\n";
$mail_body .= "URL: $url\n";
$mail_body .= "Description: $description";
mail($email, $mail_subject, $mail_body, "From: $dirmaster_email\nReply-to: $dirmaster_email");
}
$num_rows = mysql_affected_rows($link_id);
if($num_rows != 1) error_message(sql_error());
else echo "<SCRIPT>alert(\"$title($url) has been successfully approved!\"); self.close();</SCRIPT>";
}
}
function delete_url() {
global $default_dbname, $directory_tablename, $category_tablename, $category_id, $url_id, $url, $title;
global $PHP_SELF, $link_id;
if(!$link_id) $link_id = db_connect($default_dbname);
$query = "UPDATE $category_tablename SET num_item = num_item - 1 WHERE category_id = '$category_id'";
$result = mysql_query($query);
if(!$result) error_message(sql_error());
$query = "DELETE FROM $directory_tablename WHERE url_id = '$url_id'";
$result = mysql_query($query);
if(!$result) error_message(sql_error());
$num_rows = mysql_affected_rows($link_id);
if($num_rows != 1) error_message(sql_error());
else echo "<SCRIPT>alert(\"$title($url) has been successfully deleted!\"); self.location.href='$PHP_SELF?action=show_list&category_id=$category_id';</SCRIPT>";
}
function top_menu() {
global $PHP_SELF;
echo "<A HREF=\"$PHP_SELF\">Admin</A> ";
echo "| <A HREF=\"java script:open_window('$PHP_SELF?action=update_db');\">Update DB</A> ";
echo "| <A HREF=\"$PHP_SELF?mode=edit_category\">Edit Category Mode</A> ";
echo "| <A HREF=\"$PHP_SELF?mode=add_category\">Add Category Mode</A>\n";
echo "| <A HREF=\"$PHP_SELF?action=view_new\">New Listings</A>\n";
echo "| <A HREF=\"$PHP_SELF?action=show_list\">View Listings in Admin Mode</A>\n";
echo "<P>\n";
}
switch($action) {
case "add_category_form":
add_category_form();
break;
case "add_category":
add_category();
break;
case "edit_category_form":
edit_category_form();
break;
case "edit_category":
edit_category();
break;
case "delete_category":
delete_category();
break;
case "view_new":
view_new();
break;
case "edit_new_form":
edit_new_form();
break;
case "edit_new":
edit_new();
break;
case "add_url_form":
add_url_form();
break;
case "add_url":
add_url();
break;
case "modify_url_form":
modify_url_form();
break;
break;
case "modify_url":
modify_url();
break;
case "go_url":
go_url();
break;
case "delete_url":
delete_url();
break;
case "update_db":
update_db();
break;
case "show_list":
directory_header();
top_menu();
show_list();
directory_footer();
break;
default:
list_categories();
break;
}
?>
<?php
include "./php_directory.inc";
function list_categories() {
global $default_dbname, $directory_tablename, $category_tablename, $PHP_SELF;
global $link_id, $mode, $root_category_id, $category_id_length;
if(!$link_id) $link_id = db_connect($default_dbname);
if(!isset($mode)) $mode = 'add_category';
$query = "SELECT count(*) FROM $category_tablename WHERE length(category_id) = $category_id_length";
$result = mysql_query($query);
if(!$result) die(sql_error());
$query_data = mysql_fetch_row($result);
$top_level_total = $query_data[0];
$query = "SELECT category_id FROM $category_tablename ORDER BY category_id";
$result = mysql_query($query);
if(!$result) die(sql_error());
directory_header();
top_menu();
$category_info_array = get_category_info($root_category_id);
if($mode == 'add_category') {
echo "<CENTER>Click on the level on which you want to add a new category.</CENTER><P>";
echo "<BLOCKQUOTE>\n";
echo "<A HREF=\"java script:open_window('$PHP_SELF?action=add_category_form&parent=$root_category_id')\">" . $category_info_array["category"] ." </A>(" . $category_info_array["num_child"] . ")";
}
else {
echo "<CENTER>Click on the category you want to edit.</CENTER><P>";
echo "<BLOCKQUOTE>\n";
echo "<A HREF=\"java script:open_window('$PHP_SELF?action=edit_category_form&category_id=$root_category_id')\">" . $category_info_array["category"] ." </A>(" . $category_info_array["num_child"] . ")";
}
echo "<BR>\n";
echo "<BLOCKQUOTE>\n";
while($query_data = mysql_fetch_array($result)) {
$category_id = $query_data[0];
$category_info_array = get_category_info($category_id);
for($i=0; $i < $category_info_array["depth"]; $i++) echo "---";
echo " <A HREF=\"$PHP_SELF?action=delete_category&category_id=$category_id&mode=$mode\" OnClick=\"return confirm('Are you sure? It holds " . $category_info_array["num_child"] . " subcategories and " . $category_info_array["num_item"] . " items.');\">X</A> \n";
if($mode == 'add_category')
echo "<A HREF=\"java script:open_window('$PHP_SELF?action=add_category_form&parent=$category_id')\">" . $category_info_array["category"] ." </A>(" . $category_info_array["num_child"] . ")";
else echo "<A HREF=\"java script:open_window('$PHP_SELF?action=edit_category_form&category_id=$category_id')\">" . $category_info_array["category"] ." </A>(" . $category_info_array["num_child"] . ")";
echo "<BR>\n";
}
echo "</BLOCKQUOTE>\n";
echo "</BLOCKQUOTE>\n";
directory_footer();
}
function add_category_form() {
global $default_dbname, $directory_tablename, $category_tablename, $PHP_SELF;
global $link_id, $parent;
$category_info_array = get_category_info($parent);
$category_id = $category_info_array["next_id"];
$category_fullname = $category_info_array["fullname"];
directory_header();
?>
<CENTER><H3>Adding a New Category: <?php echo $category_fullname ?></H3></CENTER>
<FORM METHOD="POST" ACTION="<?php echo $PHP_SELF ?>">
<INPUT TYPE="HIDDEN" NAME="action" VALUE="add_category">
<INPUT TYPE="HIDDEN" NAME="category_id" VALUE="<? echo $category_id ?>">
<CENTER><TABLE BORDER="1" WIDTH="90%">
<TR>
<TH WIDTH="30%" NOWRAP>Category ID</TH>
<TD WIDTH="70%"><?php echo $category_id ?></TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>Category Name</TH>
<TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="category" SIZE="20"></TD>
</TR>
<TR>
<TH WIDTH="100%" COLSPAN="2" NOWRAP><INPUT TYPE="SUBMIT" VALUE="Submit"> <INPUT TYPE="RESET" VALUE="Reset"></TH>
</TR>
</TABLE>
</CENTER>
</FORM>
<?php
directory_footer();
}
function add_category() {
global $default_dbname, $directory_tablename, $category_tablename, $PHP_SELF;
global $link_id, $category_id, $category;
if(empty($category)) error_message("Enter the category name!");
if(!$link_id) $link_id = db_connect($default_dbname);
$query = "INSERT INTO $category_tablename VALUES('$category', '$category_id', 0)";
$result = mysql_query($query);
if(!$result) error_message(sql_error());
directory_header();
echo "<SCRIPT>alert(\"$category was successfully added!\"); opener.location.href='$PHP_SELF'; self.close();</SCRIPT>";
directory_footer();
}
function edit_category_form() {
global $default_dbname, $directory_tablename, $category_tablename, $PHP_SELF;
global $link_id, $category_id;
$category_info_array = get_category_info($category_id);
directory_header();
?>
<CENTER><H3>Editing the Category: <?php echo $category_info_array["fullname"] ?></H3></CENTER>
<FORM METHOD="POST" ACTION="<?php echo $PHP_SELF ?>">
<INPUT TYPE="HIDDEN" NAME="action" VALUE="edit_category">
<INPUT TYPE="HIDDEN" NAME="category_id" VALUE="<? echo $category_id ?>">
<CENTER><TABLE BORDER="1" WIDTH="90%">
<TR>
<TH WIDTH="30%" NOWRAP>Category ID</TH>
<TD WIDTH="70%"><?php echo $category_id ?></TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>Category Name</TH>
<TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="category" VALUE="<?php echo $category_info_array["category"] ?>" SIZE="20"></TD>
</TR>
<TR>
<TH WIDTH="30%" NOWRAP>Resources</TH>
<TD WIDTH="70%"><?php echo $category_info_array["num_item"] ?></TD>
</TR>
<TR>
<TH WIDTH="100%" COLSPAN="2" NOWRAP><INPUT TYPE="SUBMIT" VALUE="Submit"> <INPUT TYPE="RESET" VALUE="Reset"></TH>
</TR>
</TABLE>
</CENTER>
</FORM>
<?php
directory_footer();
}
function edit_category() {
global $default_dbname, $directory_tablename, $category_tablename, $PHP_SELF;
global $link_id, $category_id, $category;
if(empty($category)) error_message("Enter the category name!");
if(!$link_id) $link_id = db_connect($default_dbname);
$query = "UPDATE $category_tablename SET category = '$category' WHERE category_id = '$category_id'";
$result = mysql_query($query);
if(!$result) error_message(sql_error());
if(!mysql_affected_rows($link_id)) error_message("Nothing changed!");
directory_header();
echo "<SCRIPT>alert(\"$category was successfully updated!\"); opener.location.href='$PHP_SELF?mode=edit_category'; self.close();</SCRIPT>";
directory_footer();
}
function delete_category() {
global $default_dbname, $directory_tablename, $category_tablename, $PHP_SELF;
global $link_id, $category_id, $mode;
if(empty($category_id)) error_message("Empty Category ID!");
if(!$link_id) $link_id = db_connect($default_dbname);
$query = "DELETE FROM $category_tablename WHERE category_id LIKE '$category_id%'";
$result = mysql_query($query);
if(!$result) error_message(sql_error());
$del_subs = mysql_affected_rows($link_id) - 1;
$query = "DELETE FROM $directory_tablename WHERE category_id LIKE '$category_id%'";
$result = mysql_query($query);
if(!$result) error_message(sql_error());
$del_items = mysql_affected_rows($link_id);
echo "<SCRIPT>alert(\"1 category, $del_subs subcategories, and $del_items items were deleted!\"); self.location.href='$PHP_SELF?mode=$mode';</SCRIPT>";
}
function update_db() {
global $default_dbname, $directory_tablename, $category_tablename, $PHP_SELF;
global $link_id, $category_id, $mode;
directory_header();
if(!$link_id) $link_id = db_connect($default_dbname);
$query = "SELECT category, category_id, num_item FROM $category_tablename";
$result = mysql_query($query);
if(!$result) error_message(sql_error());
$num_revs = 0;
while($query_data = mysql_fetch_row($result)) {
$category = $query_data[0];
$category_id = $query_data[1];
$num_item = $query_data[2];
$query = "SELECT count(*) FROM $directory_tablename WHERE category_id = '$category_id' AND approved = 1";
$result2 = mysql_query($query);
$query_data2 = mysql_fetch_row($result2);
$total = $query_data2[0];
if(!$result2) error_message(sql_error());
if($num_item != $total) {
$query = "UPDATE $category_tablename SET num_item = $total WHERE category_id = '$category_id'";
$result2 = mysql_query($query);
if(!$result2) die(sql_error());
echo "Number of resources in <STRONG>\"$category\"</STRONG> mismatch -> revised: $total resources.<BR>\n";
$num_revs++;
}
}
if(!$num_revs) echo "No inconsistency found.<BR>\n";
else if($num_revs) echo "$num_revs inconsistency has been corrected.<BR>\n";
else echo "$num_revs inconsistencies have been corrected.<BR>\n";
echo "Done.\n";
directory_footer();
}
function view_new() {
global $default_dbname, $directory_tablename, $category_tablename, $records_per_page, $PHP_SELF, $link_id;
global $cur_page;
if(!$link_id) $link_id = db_connect($default_dbname);
$query = "SELECT count(*) FROM $directory_tablename WHERE approved != 1";
$result = mysql_query($query);
if(!$result) echo error_message(sql_error());
$query_data = mysql_fetch_row($result);
$total_num = $query_data[0];
if(!$total_num) echo error_message("No new listing!");
$limit_str = "LIMIT " . $cur_page * $records_per_page . ", $records_per_page";
$query = "SELECT url_id, url, title, description, category_id FROM $directory_tablename WHERE approved = 0 ORDER BY registerdate $limit_str";
$result = mysql_query($query);
if(!$result) echo error_message(sql_error());
$page_num = $cur_page + 1;
$total_num_page = floor($total_num/$records_per_page);
$last_page_num = $total_num_page + 1;
directory_header();
top_menu();
echo "<CENTER><H3>Displaying the page $page_num out of $last_page_num.</H3></CENTER>";
echo "<UL>\n";
while($query_data = mysql_fetch_array($result)) {
$url_id = $query_data["url_id"];
$url = "
http://" . $query_data["url"];
$title = $query_data["title"];
$description = $query_data["description"];
$category_id = $query_data["category_id"];
$category_info_array = get_category_info($category_id);
$category_fullname = $category_info_array["fullname"];
echo "<LI>\n";
echo "<A HREF=\"java script:open_window('$PHP_SELF?action=edit_new_form&url_id=$url_id&category_id=$category_id');\">[Edit]</A> \n";
echo "<A HREF=\"$url\" TARGET=\"_BLANK\">$title ($category_fullname)</A> - $description\n";
echo "</LI>";
}
echo "</UL>\n";
echo "<BR>\n";
echo "<STRONG><CENTER>";
if($cur_page > 0) echo "<A HREF=\"$PHP_SELF?action=view_new&cur_page=0\">[Top]</A>";
if($cur_page != 0) {
$prev_page = $cur_page - 1;
echo "<A HREF=\"$PHP_SELF?action=view_new&cur_page=$prev_page\">[Prev]</A> ";
}
if($cur_page < $total_num_page) {
$next_page = $cur_page + 1;
echo "<A HREF=\"$PHP_SELF?action=view_new&cur_page=$next_page\">[Next]</A> ";
}
if($cur_page != $total_num_page) echo "<A HREF=\"$PHP_SELF?action=view_new&cur_page=$total_num_page\">[Bottom]</A>";
echo "</CENTER></STRONG>";
directory_footer();
}
function edit_new_form() {
global $PHP_SELF, $max_desc_length, $url_id, $category_id;
directory_header();
$url_info_array = get_url_info($url_id);
$category_info_array = get_category_info($url_info_array["category_id"]);
?>
<CENTER><H3>Editing a new listing.</H3></CENTER>
<UL>
<LI>Submitted on: <?php echo $url_info_array["formatted_registerdate"] ?></LI>
</UL>
<FORM METHOD="POST" ACTION="<?php echo $PHP_SELF ?>">
<INPUT TYPE="HIDDEN" NAME="action" VALUE="edit_new">
<INPUT TYPE="HIDDEN" NAME="url_id" VALUE="<? echo $url_id ?>">
<INPUT TYPE="HIDDEN" NAME="category_id" VALUE="<? echo $category_id ?>">
<CENTER><TABLE BORDER="1" WIDTH="90%">
<TR>
<TH WIDTH="20%" NOWRAP>Category</TH>
<TD WIDTH="80%"><?php echo $category_info_array["fullname"] ?></TD>
</TR>
<TR>
<TH WIDTH="20%" NOWRAP>Email</TH>
<TD WIDTH="80%"><?php echo $url_info_array["email"] ?><INPUT TYPE="HIDDEN" NAME="email" VALUE="<?php echo $url_info_array["email"] ?>"></TD>
</TR>
<TR>
<TH WIDTH="20%" NOWRAP>Title</TH>
<TD WIDTH="80%"><INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $url_info_array["title"] ?>" SIZE="30" MAXLENGTH="150"></TD>
</TR>
<TR>
<TH WIDTH="20%" NOWRAP>URL</TH>
<TD WIDTH="80%"><INPUT TYPE="TEXT" NAME="url" VALUE="<?php echo "
http://" . $url_info_array["url"]; ?>" SIZE="30" MAXLENGTH="150"></TD>
</TR>
<TR>
<TH WIDTH="20%" NOWRAP>Description<BR>(<?php echo $max_desc_length ?> Chars Max.)</TH>
<TD WIDTH="80%"><TEXTAREA NAME="description" ROWS="5" COLS="40"><?php echo $url_info_array["description"] ?></TEXTAREA></TD>
</TR>
<TR>
<TH WIDTH="20%" NOWRAP>Action</TH>
<TD WIDTH="80%"><INPUT TYPE="RADIO" VALUE="approve" NAME="option" CHECKED>Approve <INPUT TYPE="RADIO" VALUE="delete" NAME="option">Delete</TD>
</TR>
<TR>
<TH WIDTH="100%" NOWRAP COLSPAN="2"><INPUT TYPE="SUBMIT" VALUE="Edit URL" NAME="Submit"> <INPUT TYPE="RESET" VALUE="Reset"></TH>
</TR>
</TABLE>
</CENTER>
</FORM>
<?php
directory_footer();
}
function edit_new() {
global $default_dbname, $directory_tablename, $category_tablename, $max_desc_length;
global $title, $url, $description, $category_id, $url_id, $email, $option;
global $dirmaster_email, $link_id, $send_mail;
$url = eregi_replace('
http://', "", $url);
$url = eregi_replace("/$", "", $url);
if(empty($title)) error_message("Please enter the title!");
if(empty($url)) error_message("Please enter the URL!");
if(empty($description)) error_message("Please enter the description!");
if(!$link_id) $link_id = db_connect($default_dbname);
if($option == 'delete') {
$query = "DELETE FROM $directory_tablename WHERE url_id = '$url_id'";
$result = mysql_query($query);
if(!$result) error_message(sql_error());
$num_rows = mysql_affected_rows($link_id);
if($num_rows != 1) error_message(sql_error());
else echo "<SCRIPT>alert(\"$title($url) has been successfully deleted!\"); opener.location.href='$PHP_SELF?action=view_new'; self.close();</SCRIPT>";
}
else {
if(strlen($description) > $max_desc_length) error_message("Description too long! $max_desc_length chars max!");
$title = addslashes($title);
$description = addslashes($description);
$query = "UPDATE $category_tablename SET num_item = num_item + 1 WHERE category_id = '$category_id'";
$result = mysql_query($query);
if(!$result) error_message(sql_error());
$query = "UPDATE $directory_tablename SET title='$title', url='$url', description='$description', approved = 1 WHERE url_id='$url_id'";
$result = mysql_query($query);
if(!$result) error_message(sql_error());
if($send_mail){
$mail_subject = "PHP Directory>> Your contribution has been listed.";
$mail_body = "Thank you for sharing your resources with us.\n";
$mail_body = "Your contribution has been listed. Thank you.\n\n";
$mail_body .= "Title: $title\n";
$mail_body .= "URL: $url\n";
$mail_body .= "Description: $description";
mail($email, $mail_subject, $mail_body, "From: $dirmaster_email\nReply-to: $dirmaster_email");
}
$num_rows = mysql_affected_rows($link_id);
if($num_rows != 1) error_message(sql_error());
else echo "<SCRIPT>alert(\"$title($url) has been successfully approved!\"); self.close();</SCRIPT>";
}
}
function delete_url() {
global $default_dbname, $directory_tablename, $category_tablename, $category_id, $url_id, $url, $title;
global $PHP_SELF, $link_id;
if(!$link_id) $link_id = db_connect($default_dbname);
$query = "UPDATE $category_tablename SET num_item = num_item - 1 WHERE category_id = '$category_id'";
$result = mysql_query($query);
if(!$result) error_message(sql_error());
$query = "DELETE FROM $directory_tablename WHERE url_id = '$url_id'";
$result = mysql_query($query);
if(!$result) error_message(sql_error());
$num_rows = mysql_affected_rows($link_id);
if($num_rows != 1) error_message(sql_error());
else echo "<SCRIPT>alert(\"$title($url) has been successfully deleted!\"); self.location.href='$PHP_SELF?action=show_list&category_id=$category_id';</SCRIPT>";
}
function top_menu() {
global $PHP_SELF;
echo "<A HREF=\"$PHP_SELF\">Admin</A> ";
echo "| <A HREF=\"java script:open_window('$PHP_SELF?action=update_db');\">Update DB</A> ";
echo "| <A HREF=\"$PHP_SELF?mode=edit_category\">Edit Category Mode</A> ";
echo "| <A HREF=\"$PHP_SELF?mode=add_category\">Add Category Mode</A>\n";
echo "| <A HREF=\"$PHP_SELF?action=view_new\">New Listings</A>\n";
echo "| <A HREF=\"$PHP_SELF?action=show_list\">View Listings in Admin Mode</A>\n";
echo "<P>\n";
}
switch($action) {
case "add_category_form":
add_category_form();
break;
case "add_category":
add_category();
break;
case "edit_category_form":
edit_category_form();
break;
case "edit_category":
edit_category();
break;
case "delete_category":
delete_category();
break;
case "view_new":
view_new();
break;
case "edit_new_form":
edit_new_form();
break;
case "edit_new":
edit_new();
break;
case "add_url_form":
add_url_form();
break;
case "add_url":
add_url();
break;
case "modify_url_form":
modify_url_form();
break;
break;
case "modify_url":
modify_url();
break;
case "go_url":
go_url();
break;
case "delete_url":
delete_url();
break;
case "update_db":
update_db();
break;
case "show_list":
directory_header();
top_menu();
show_list();
directory_footer();
break;
default:
list_categories();
break;
}
?>