Avatar billede runner19 Nybegynder
07. oktober 2004 - 15:08 Der er 19 kommentarer og
1 løsning

Link indeks

Hej..
Jeg kunne godt tænke mig et linkindeks/linkguide i stil med Yahoo - altså i meget mindre omfang! Jeg tænker på indeksering i kategorier og evt. en søge funktion...

Nogen der evt. ligger inde med noget? Det må gerne kunne udbygges...
Hvor mange points vil det koste?

Hilsen
Runner
Avatar billede vallemanden Nybegynder
07. oktober 2004 - 15:16 #1
noget i stil med dette???

http://www.night.dk/php_directory.php
Avatar billede runner19 Nybegynder
07. oktober 2004 - 15:19 #2
ja, præcis! Dog med visning af nogle af "underkategorierne" på hovedsiden frem for "7 subs"..
Avatar billede runner19 Nybegynder
07. oktober 2004 - 15:33 #3
Det så godt ud vallemanden... Ligger du inde med noget?
Avatar billede vallemanden Nybegynder
07. oktober 2004 - 15:46 #4
:) ja det gør jeg, det er på min HP
Avatar billede runner19 Nybegynder
07. oktober 2004 - 15:53 #5
Hvor mange points? ;) ej hm..
Avatar billede vallemanden Nybegynder
07. oktober 2004 - 19:14 #6
120 :) men så skal jeg have en email jeg kan sende det til
Avatar billede runner19 Nybegynder
07. oktober 2004 - 20:11 #7
Deal! :D Men er det underforstået, at jeg efterfølgende må ændre/rette i det?
Avatar billede runner19 Nybegynder
07. oktober 2004 - 20:15 #8
Hvis denne "tilladelse" kræver flere points er det forståeligt..
Min mail er: runestendk@yahoo.dk
Avatar billede vallemanden Nybegynder
07. oktober 2004 - 20:51 #9
Du må gøre som du selv lyster :)

du kan evt give mig karma :)
Avatar billede runner19 Nybegynder
07. oktober 2004 - 20:55 #10
Jamen fair nok 120+lidt karma vallemanden ;)
Hvis jeg nu skal være rigtig krævende kunne jeg så få dig til at lave en liste/dropdown af mysql tabeller, som bruges? :)
Avatar billede sukos Juniormester
07. oktober 2004 - 21:03 #11
ehh, ikke fordi jeg selv vil bruge det, men løsninger skal jo være tilgængelig for andre brugere også! :O)
Avatar billede runner19 Nybegynder
07. oktober 2004 - 21:16 #12
joe... ved jeg ik :)
Nå vallemanden, svar accepteret såå? :)
Avatar billede vallemanden Nybegynder
07. oktober 2004 - 21:51 #13
så er det sendt til dig
Avatar billede runner19 Nybegynder
07. oktober 2004 - 21:57 #14
hm.. underligt intet modtaget :/
Avatar billede runner19 Nybegynder
07. oktober 2004 - 22:03 #15
nå, hermed modtaget... takker ;)
Avatar billede vallemanden Nybegynder
08. oktober 2004 - 00:36 #16
nu skal du bare sige til hvis du har problemmer med det :)
Avatar billede runner19 Nybegynder
09. oktober 2004 - 00:04 #17
jo tak... vil lige tjekke det igennem :)
Avatar billede eagleeye Praktikant
09. oktober 2004 - 11:31 #18
runner19 og vallemanden >> Løsningen skal være tilgængelig på eksperten for der kan gives point. Det står i regelerne. 2.1.13 Det er ikke tilladt at tildele point for en opgave løst uden om Eksperten (feks. opgaver løst via mail, icq eller telefon).

Så vallemanden må give point tilbage. Eller må i ligge løsningen ind her.

eagleeye / CoAdmin
Avatar billede vallemanden Nybegynder
09. oktober 2004 - 13:52 #19
#
# 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;

}
?>
Avatar billede vallemanden Nybegynder
09. oktober 2004 - 13:53 #20
<?php


$dbhost = 'localhost';            // database server
$dbusername = 'phpuser';          // username
$dbuserpassword = 'phppass';      // user password
$default_dbname = 'sample_db';    // default database

$directory_tablename = 'php_directory';    // URL table
$category_tablename = 'php_category';    // Category table

$link_id = 0;
$category_id_length = 3;
$root_category_id = '000';
$max_desc_length = 250;
$new_window_width = 600;
$new_window_height = 500;
$welcome_message = "Welcome to PHP Directory!";
$records_per_page = 3;
$num_top_sites = 5;
$num_new_sites = 5;
$admin_script = 'dir_manager.php';
$send_mail = False;
$dirmaster_email = "dirmaster<phpdir@phpdirectory.com>";
$MYSQL_ERRNO = '';
$MYSQL_ERROR = '';


function directory_header() {
  global $new_window_width, $new_window_height;
?>
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
function open_window(url) {
  var NEW_WIN = null;
                 
  NEW_WIN =  window.open ("","RecordViewer","toolbar=no,width="+<?php echo $new_window_width ?>+",height="+<?php echo $new_window_height ?>+",directories=no,status=no,scrollbars=yes,resize=no,menubar=no");
  NEW_WIN.location.href = url;
}
//-->
</SCRIPT>
<TITLE>PHP Directory</TITLE>
</HEAD>
<BODY>
<?php
}

function directory_footer() {
?>
</BODY>
</HTML>
<?php
}

function db_connect($dbname='') {
  global $dbhost, $dbusername, $dbuserpassword, $default_dbname;
  global $MYSQL_ERRNO, $MYSQL_ERROR;

  $link_id = @mysql_connect($dbhost, $dbusername, $dbuserpassword);
  if(!$link_id) {
      $MYSQL_ERRNO = 0;
      $MYSQL_ERROR = "Connection failed to the host $dbhost.";
      return 0;
  }
  else if(empty($dbname) && !@mysql_select_db($default_dbname)) {
      $MYSQL_ERRNO = mysql_errno();
      $MYSQL_ERROR = mysql_error();
      return 0;
  }
  else if(!empty($dbname) && !@mysql_select_db($dbname)) {
      $MYSQL_ERRNO = mysql_errno();
      $MYSQL_ERROR = mysql_error();
      return 0;
  }
  else return $link_id;
}

function sql_error() {
  global $MYSQL_ERRNO, $MYSQL_ERROR;
if(empty($MYSQL_ERROR)) { 
      $MYSQL_ERRNO = mysql_errno();
      $MYSQL_ERROR = mysql_error();
  }
  return "$MYSQL_ERRNO: $MYSQL_ERROR";
}

function error_message($msg) {
  directory_header();
  echo "<SCRIPT>alert(\"Error: $msg\");history.go(-1)</SCRIPT>";
  directory_footer();
  exit;
}

function user_message($msg, $url='') {
  directory_header();
  if(empty($url)) echo "<SCRIPT>alert(\"$msg\");history.go(-1)</SCRIPT>";
  else echo "<SCRIPT>alert(\"$msg\");self.location.href='$url'</SCRIPT>";
 
  directory_footer();
  exit;
}

function get_category_info($category_id) {
  global $default_dbname, $category_tablename, $root_category_id, $category_id_length, $welcome_message, $PHP_SELF;
  global $link_id;
  if(!$link_id) $link_id = db_connect($default_dbname);
  if($category_id == $root_category_id) {
      $category_info_array["category"] = "Top";
      $category_info_array["num_item"] = 0; 
      $query = "SELECT max(category_id), count(*) FROM $category_tablename WHERE length(category_id) = $category_id_length";
      $result = mysql_query($query);
      if(!$result) echo sql_error();
      $query_data = mysql_fetch_row($result);
      $sibling_id = $query_data[0];
      $num_child = $query_data[1];
      $category_info_array["num_child"] = $num_child;
      if(!$sibling_id) $next_category_id = '001';
      else {
        $sibling_length = strlen($sibling_id);
        $next_category_id = $sibling_id + 1;
        for($i = strlen($next_category_id); $i < $sibling_length; $i++) $left_pad .= '0';
        $next_category_id = $left_pad . $next_category_id;
      }
      $category_info_array["next_id"] = $next_category_id;
      $category_info_array["depth"] = 1;
      $category_info_array["href_fullname"] = $welcome_message;
      $category_info_array["fullname"] = $welcome_message;
  }
    else {
      $query = "SELECT category, num_item FROM $category_tablename WHERE category_id = '$category_id'";
      $result = mysql_query($query);
      if(!$result) echo sql_error();
      $query_data = mysql_fetch_array($result);
      $category_info_array["category"] = $query_data["category"];
      $category_info_array["num_item"] = $query_data["num_item"];
      $query = "SELECT max(category_id), count(*) FROM $category_tablename WHERE (length(category_id) = length('$category_id') + $category_id_length) AND category_id LIKE '$category_id%'";
      $result = mysql_query($query);
      if(!$result) echo sql_error();
      $query_data = mysql_fetch_row($result);
      $sibling_id = $query_data[0];
      $num_child = $query_data[1];
      $category_info_array["num_child"] = $num_child;

      if(!$sibling_id) $next_category_id = $category_id . '001';
      else {
        $sibling_length = strlen($sibling_id);
        $next_category_id = $sibling_id + 1;
        for($i = strlen($next_category_id); $i < $sibling_length; $i++)
            $left_pad .= '0';
        $next_category_id = $left_pad . $next_category_id;
      }

      $category_info_array["next_id"] = $next_category_id;
      $category_info_array["depth"] = (strlen($category_id) / $category_id_length) + 1;
      $j = 0;
      for($i=0; $i < strlen($category_id); $i += $category_id_length) {
        $parent_id .= substr($category_id,$i,$category_id_length);
          $query = "SELECT category FROM $category_tablename WHERE category_id = '$parent_id'";
          $result = mysql_query($query);
        $query_data = mysql_fetch_row($result);
        $parent_href_array[$j] = "<A HREF=\"$PHP_SELF?action=show_list&category_id=$parent_id\">" . $query_data[0] ."</A>";
        $parent_array[$j] = $query_data[0];
        $j++;
      }
      $category_info_array["href_fullname"] = implode("->", $parent_href_array);
      $category_info_array["fullname"] = implode("->", $parent_array);
  }
  return $category_info_array;
}

function get_url_info($url_id) {
  global $link_id, $default_dbname, $directory_tablename;
 
  if(!$link_id) $link_id = db_connect($default_dbname);
  $query = "SELECT url_id, category_id, title, url, description,registerdate, date_format(registerdate, '%M, %e, %Y') as
                    formatted_registerdate, hit, lastaccesstime, date_format(lastaccesstime, '%M, %e, %Y %r') as
                    formatted_lastaccesstime, password, email, approved FROM $directory_tablename WHERE url_id = '$url_id'";
  $result = mysql_query($query);
  if(!$result) echo sql_error();
  return mysql_fetch_array($result);
}

function search_form($category_id) {
  global $root_category_id, $PHP_SELF;
 
  if(!isset($category_id)) $category_id = $root_category_id;
?>
<CENTER>
<FORM METHOD="POST" ACTION="<?php echo $PHP_SELF ?>">
<INPUT TYPE="HIDDEN" NAME="action" VALUE="show_list">
<INPUT TYPE="HIDDEN" NAME="search_on" VALUE="1">
  Search: <INPUT TYPE="TEXT" NAME="keywords" SIZE="20"><SELECT NAME="search_category" SIZE="1">
    <OPTION SELECTED VALUE="<?php echo $category_id ?>">Current Category</OPTION>
    <OPTION VALUE="<?php echo $root_category_id ?>">All Categories</OPTION>
</SELECT><INPUT TYPE="RADIO" VALUE="OR" NAME="search_type" CHECKED>OR <INPUT TYPE="RADIO"  VALUE="AND" NAME="search_type">AND <INPUT TYPE="SUBMIT" VALUE="Search">
</FORM>
</CENTER>
<?php
}

function show_list() {
  global $default_dbname, $directory_tablename, $category_tablename, $records_per_page, $root_category_id, $category_id_length, $welcome_message, $dirmaster_email;
  global $PHP_SELF, $link_id, $category_id, $admin_script, $cur_page, $search_on, $keywords, $search_type, $search_category;
  if(basename($PHP_SELF) == $admin_script) $admin = 1;
  if(!$link_id) $link_id = db_connect($default_dbname);
  $submittable = 1;
  if(empty($category_id) || $category_id==$root_category_id) {
      $category_info_array = get_category_info($root_category_id);
      $submittable = 0;
  }
  else {
      $parent_category_id = $category_id;
      $category_info_array = get_category_info($category_id);
      $category_fullname = $category_info_array["fullname"];
      $num_item = $category_info_array["num_item"];
  }
  $category_href_fullname = $category_info_array["href_fullname"];
  $category_depth = $category_info_array["depth"];
  $num_child = $category_info_array["num_child"];
?>

<CENTER>
<TABLE BORDER="0" WIDTH="90%" CELLSPACING="5" CELLPADDING="5">
  <TR>
    <TD WIDTH="70%" VALIGN="TOP">
<?php 
  if($num_child <= 1) $num_child_str = "$num_child subcategory";
  else $num_child_str = "$num_child subcategories";
  if($num_item <= 1) $num_item_str = "$num_item item";
  else $num_item_str = "$num_item items";
  if($submittable) echo "<H3>$category_href_fullname ($num_child_str, $num_item_str)</H3>\n";
  else echo "<H3>$category_href_fullname ($num_child_str)</H3>\n";
  search_form($category_id);
  $query = "SELECT category, category_id FROM $category_tablename WHERE (length(category_id) = $category_depth * $category_id_length) AND category_id LIKE '$category_id%' ORDER BY category";
  $result = mysql_query($query);
  if(!$result) echo sql_error();
  if(mysql_num_rows($result) > 0) {   
      ?>
      <CENTER>
      <TABLE BORDER="0" WIDTH="90%" CELLPADDING="5" CELLSPACING="5">
      <?php 
      $i = 1;
      while($query_data = mysql_fetch_array($result)) {
        $my_category = $query_data["category"];
        $my_category_id = $query_data["category_id"];
        $category_info_array = get_category_info($my_category_id);
        $num_child = $category_info_array["num_child"];
        $num_item = $category_info_array["num_item"];
        if($num_child <= 1) $num_child_str = "$num_child sub";
        else $num_child_str = "$num_child subs";
        if($num_item <= 1) $num_item_str = "$num_item item";
        else $num_item_str = "$num_item items";
        if(($i % 2)) echo "<TR>\n";
        echo "<TD WIDTH=\"50%\">\n";
        echo "<A HREF=\"$PHP_SELF?action=show_list&
                                  category_id=$my_category_id\">
              <STRONG>$my_category</STRONG>
              ($num_child_str, $num_item_str)</A>\n";
        echo "</TD>\n";
        if(!($i % 2)) echo "</TR>\n";     
        $i++;
      }
      if(!($i % 2)) {
        echo "<TD WIDTH=\"50%\">&nbsp;</TD>\n" ;
        echo "</TR>";
      }
      ?>
      </TABLE>
      </CENTER>
      <?php
  }
  $keyword_str = '';
  $category_str = "category_id = '$category_id'";
  if($search_on && !empty($keywords)) {
      if($search_category == $root_category_id) $category_str = '1';
      else $category_str = "category_id LIKE '$search_category%'";
      $keywords_array = explode(" ", $keywords);
      $temp_str = "description LIKE '%";
      $keyword_str = implode("%' $search_type $temp_str", $keywords_array);
      $keyword_str_desc = $temp_str . $keyword_str . "%'";
      $temp_str = "title LIKE '%";
      $keyword_str = implode("%' $search_type $temp_str", $keywords_array);
      $keyword_str_title = $temp_str . $keyword_str . "%'";
      $keyword_str = "AND (($keyword_str_title) OR ($keyword_str_desc))";
  }

  $query = "SELECT count(*) FROM $directory_tablename WHERE $category_str AND approved = 1 $keyword_str";
  $result = mysql_query($query);
  if(!$result) echo error_message(sql_error());
  $query_data = mysql_fetch_row($result);
  $total_num = $query_data[0];
  $limit_str = "LIMIT " . $cur_page * $records_per_page . ", $records_per_page";
  $page_num = $cur_page + 1;
  $total_num_page = $last_page_num = ceil($total_num/$records_per_page);
  if(!$total_num_page) $total_num_page++;
  if($total_num <= 1 ) $found_str = "$total_num URL found.";
  else $found_str = "$total_num URLs found.";
  if($search_on) echo "<H3>$found_str - Keyword(s): $keywords</H3><P>\n";
  if($total_num > 0) echo "<CENTER>Displaying page $page_num out of $last_page_num</CENTER><P>\n";
  $query = "SELECT url_id, category_id, title, url, description,
                    date_format(registerdate, '%M, %e, %Y') as
                    formatted_registerdate, hit,
                    date_format(lastaccesstime, '%M, %e, %Y %r') as
                    formatted_lastaccesstime, hit FROM $directory_tablename
                    WHERE $category_str AND approved = 1 $keyword_str
                    ORDER BY registerdate DESC $limit_str";
  $result = mysql_query($query);
  if(!$result) echo sql_error();
    $i = 1;
  while($query_data = mysql_fetch_array($result)) {
      $url_id = $query_data["url_id"];
      $formatted_registerdate = $query_data["formatted_registerdate"];
      $formatted_lastaccesstime = $query_data["formatted_lastaccesstime"];
      $url = "http://" . $query_data["url"];
      $title = $query_data["title"];
      $description = $query_data["description"];
      $hit = $query_data["hit"];
      echo "<STRONG>
            <A HREF=\"$PHP_SELF?action=go_url&url=$url&url_id=$url_id\">".
            ($i+($cur_page * $records_per_page)).".$title
            </A></STRONG>\n";
      echo "<BLOCKQUOTE>\n";
      echo $description;
      echo "<BR>\n";
      echo "<EM>Last Access: $formatted_lastaccesstime</EM><BR>\n";
      echo "<EM>Hit(s): " . number_format($hit) . "</EM><BR>\n";
      if($admin) echo "<A HREF=\"$PHP_SELF?action=delete_url&url_id=$url_id&
                                          category_id=$category_id&url=$url&
                                          title=$title&cur_page=$cur_page\"
                          OnClick=\"return confirm('Are you sure?');\">
                      [Delete]
                      </A>\n";
      echo "<A HREF=\"java script:open_window('$PHP_SELF?
                        action=modify_url_form&url_id=$url_id&
                        category_id=$category_id&cur_page=$cur_page');\">
            [Modify]
            </A>\n";
      if(!$admin) echo "<A HREF=\"mailto:$dirmaster_email?
                                    subject=PHPDirectory]SiteMissing&
                                    body=url_id:$url_id($url)\">
                        [Report Broken Link]
                        </A>\n";
      echo "</BLOCKQUOTE>\n";
     
      $i++;
  }
  if($search_on) $search_str = "&search_on=1&search_type=$search_type&keywords=$keywords&search_category=$search_category";
 
  echo "<CENTER>";
  if($page_num > 1) {
      $prev_page = $cur_page - 1;
      echo "<A HREF=\"$PHP_SELF?action=show_list&category_id=$category_id&cur_page=0$search_str\">[Top]</A>";     
      echo "<A HREF=\"$PHP_SELF?action=show_list&category_id=$category_id&cur_page=$prev_page$search_str\">[Prev]</A> ";
  }
  if($page_num < $total_num_page) {
      $next_page = $cur_page + 1;
      $last_page = $total_num_page - 1;
      echo "<A HREF=\"$PHP_SELF?action=show_list&category_id=$category_id&cur_page=$next_page$search_str\">[Next]</A> ";
      echo "<A HREF=\"$PHP_SELF?action=show_list&category_id=$category_id&cur_page=$last_page$search_str\">[Bottom]</A>";
  }
  echo "</CENTER>";
  echo "<P><STRONG><CENTER><A HREF=\"$PHP_SELF?action=show_list\">[Directory Home]</A> \n";
  if($submittable) echo "<A HREF=\"java script:open_window('$PHP_SELF?action=add_url_form&category_id=$category_id');\">[Submit a URL]</A>\n";
  echo "</CENTER></STRONG>";
?>
</TD>
    <TD WIDTH="30%" VALIGN="TOP">
    <?php
      list_sites('top', $category_id); echo "<P>";
      list_sites('new', $category_id);
    ?>
    </TD>
  </TR>
</TABLE>
</CENTER>
<?php 
}

function add_url_form() {
  global $PHP_SELF, $max_desc_length, $category_id;

  $category_info_array = get_category_info($category_id);
  $category_fullname = $category_info_array["fullname"];
  directory_header();
?>
<CENTER><H3>Submit a PHP Site!</H3></CENTER>
<FORM METHOD="POST" ACTION="<?php echo $PHP_SELF ?>">
<INPUT TYPE="HIDDEN" NAME="action" VALUE="add_url">
<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_fullname ?></TD>
    </TR>
    <TR>
      <TH WIDTH="20%" NOWRAP>Title</TH>
      <TD WIDTH="80%"><INPUT TYPE="TEXT" NAME="title"
                            SIZE="30" MAXLENGTH="150"></TD>
    </TR>
    <TR>
      <TH WIDTH="20%" NOWRAP>URL</TH>
      <TD WIDTH="80%"><INPUT TYPE="TEXT" NAME="url" VALUE="http://"
                            SIZE="30" MAXLENGTH="150"></TD>
    </TR>
    <TR>
      <TH WIDTH="20%" NOWRAP>Email</TH>
      <TD WIDTH="80%"><INPUT TYPE="TEXT" NAME="email"
                            SIZE="30" MAXLENGTH="150"></TD>
    </TR>
    <TR>
      <TH WIDTH="20%" NOWRAP>Password</TH>
      <TD WIDTH="80%"><INPUT TYPE="PASSWORD" NAME="password"
                            SIZE="20" MAXLENGTH="20"></TD>
    </TR>   
    <TR>
      <TH WIDTH="20%" NOWRAP>Retype Password</TH>
      <TD WIDTH="80%"><INPUT TYPE="PASSWORD" NAME="password2"
                            SIZE="20" MAXLENGTH="20"></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"></TEXTAREA>
      </TD>
    </TR>
    <TR>
      <TH WIDTH="100%" NOWRAP COLSPAN="2">
      <INPUT TYPE="SUBMIT" VALUE="Submit URL" NAME="Submit">
      <INPUT TYPE="RESET" VALUE="Reset"></TH>
    </TR>
  </TABLE>
  </CENTER>
</FORM>
<?php
  directory_footer();
}

function add_url() {
  global $default_dbname, $directory_tablename,
          $category_tablename, $max_desc_length, $PHP_SELF;
  global $category_id, $title, $url, $description,
          $email, $password, $password2, $email, $admin_script;
  global $dirmaster_email, $link_id, $send_mail;
  if(basename($PHP_SELF) == $admin_script) $admin = 1;
  $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($email))
      error_message("Please enter your email address!");
  if(empty($password))
      error_message("Please enter a password for later modification!");
  if(empty($password2))
      error_message("Please retype the password!");
  if($password != $password2)
      error_message("Desired password and retyped password mismatch!");
  if(empty($email))
      error_message("Please enter your email!");
  if(empty($description))
      error_message("Please enter the description!");
  if(strlen($description) > $max_desc_length)
      error_message("Description too long! $max_desc_length chars max!");
  $title = addslashes($title);
  $description = addslashes($description);
  $password = crypt($password, '.v');
  if(!$link_id) $link_id = db_connect($default_dbname);
  $query = "SELECT url FROM $directory_tablename
            WHERE url = '$url' AND category_id = '$category_id'";
  $result = mysql_query($query);
  if(!$result) error_message(sql_error());
  if(mysql_num_rows($result) != 0)
      error_message("$url already exists in the directory!");
  $approved = 0;
  if($admin) {
      $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());
      $approved = 1;
  }
  $query = "INSERT INTO $directory_tablename
                    VALUES(NULL, '$category_id', '$title', '$url',
                                '$description', curdate(), 0, NULL,
                                '$password', '$email', $approved)";
  $result = mysql_query($query);
  if(!$result) error_message(sql_error());
  if($send_mail){
      $mail_subject = "PHP Directory>> Thank your for your listing.";
      $mail_body = "Thank you for sharing your resources with us.\n";
      $mail_body = "Your contribution will be listed after
                                        review in a day or two.\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 submitted!\");
              opener.location.href='$PHP_SELF?action=show_list&category_id=$category_id';
              self.close();
              </SCRIPT>";
}

function modify_url_form() {
  global $PHP_SELF, $max_desc_length, $url_id,
          $category_id, $admin_script, $cur_page;
  directory_header();
  if(basename($PHP_SELF) == $admin_script) $admin = 1;
  $url_info_array = get_url_info($url_id);
  $category_info_array = get_category_info($url_info_array["category_id"]);
?>
<CENTER><H3>Update your PHP site!</H3></CENTER>
<UL>
<LI>Submitted on: <?php echo $url_info_array["formatted_registerdate"] ?></LI>
<LI>Hits: <?php echo $url_info_array["hit"] ?></LI>
<LI>Last Access: <?php echo $url_info_array["formatted_lastaccesstime"] ?></LI>
</UL>
<FORM METHOD="POST" ACTION="<?php echo $PHP_SELF ?>">
<INPUT TYPE="HIDDEN" NAME="action" VALUE="modify_url">
<INPUT TYPE="HIDDEN" NAME="url_id" VALUE="<?php echo $url_id ?>">
<INPUT TYPE="HIDDEN" NAME="category_id" VALUE="<?php 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>
<?php
  if(!$admin) {
?>   
    <TR>
      <TH WIDTH="20%" NOWRAP>Email</TH>
      <TD WIDTH="80%"><INPUT TYPE="TEXT" NAME="email"
                            SIZE="30" MAXLENGTH="150"></TD>
    </TR>   
    <TR>
      <TH WIDTH="20%" NOWRAP>Password</TH>
      <TD WIDTH="80%"><INPUT TYPE="PASSWORD" NAME="password"
                            SIZE="20" MAXLENGTH="20"></TD>
    </TR>   
<?php
  }
?>   
    <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="100%" NOWRAP COLSPAN="2">
      <INPUT TYPE="SUBMIT" VALUE="Modify URL" NAME="Submit">
      <INPUT TYPE="RESET" VALUE="Reset"></TH>
    </TR>
  </TABLE>
  </CENTER>
</FORM>
<?php
  directory_footer();
}

function modify_url() {
  global $default_dbname, $directory_tablename,
          $max_desc_length, $PHP_SELF, $cur_page;
  global $title, $url, $description, $category_id,
          $url_id, $email, $password, $admin_script;
  global $link_id;
  if(basename($PHP_SELF) == $admin_script) $admin = 1;
  $url = eregi_replace('http://', "", $url);
  $url = eregi_replace("/$", "", $url);
  if(!$admin && empty($email)) error_message("Please enter your email address!"); 
  if(!$admin && empty($password)) error_message("Please enter the password you used when posting your 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(strlen($description) > $max_desc_length) error_message("Description too long! $max_desc_length chars max!");
  $url_info_array = get_url_info($url_id);
  if(!$admin && (($url_info_array["password"] != crypt($password, '.v')) || ($url_info_array["email"] != $email))) error_message("You don't have permission to modify this URL!");
  $title = addslashes($title);
  $description = addslashes($description);
  if(!$link_id) $link_id = db_connect($default_dbname);
     
  $query = "UPDATE $directory_tablename SET title='$title', url='$url', description='$description' 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 modified!\");
opener.location.href='$PHP_SELF?action=show_list&category_id=$category_id&cur_page=$cur_page'; self.close();</SCRIPT>";

}


function go_url() {
  global $default_dbname, $directory_tablename;
  global $url_id, $url;
  if(isset($url_id) && isset($url)) {
      if(!$link_id) $link_id = db_connect($default_dbname); 
      $result = mysql_query("UPDATE $directory_tablename SET hit = hit + 1 WHERE url_id=$url_id");
      if(!$result) error_message(sql_error());
      header("Location: $url");
      exit;
  }
}

function list_sites($mode='top', $category_id='') {
  global $directory_tablename, $root_category_id, $PHP_SELF, $num_top_sites, $num_new_sites;
  if(!$link_id) $link_id = db_connect($default_dbname);
  if($mode=='top') {
      $order_by_str = 'ORDER BY hit DESC';
      $limit_str = "LIMIT $num_top_sites";
  }
  else {
      $order_by_str = 'ORDER BY registerdate DESC';
      $limit_str = "LIMIT $num_new_sites";
  }
  if($category_id == $root_category_id) $category_str = '1';
  else $category_str = "category_id LIKE '$category_id%'";
  $query = "SELECT url_id, title, url FROM $directory_tablename WHERE $category_str AND approved = 1 $order_by_str $limit_str";
  $result = mysql_query($query);
  if(!$result) echo sql_error();
  if(mysql_num_rows($result) > 0) {
      if($mode=='top') echo "<STRONG>Top $num_top_sites!</STRONG><BR>";
      else if($mode=='new') echo "<STRONG>New $num_new_sites!</STRONG><BR>";
  }
  $i = 1;
  while($query_data = mysql_fetch_array($result)) {
      $url_id = $query_data["url_id"];
      $url = "http://" . $query_data["url"];
      $title = $query_data["title"];
      echo "<STRONG> - <A HREF=\"$PHP_SELF?action=go_url&url=$url&url_id=$url_id\">$i. $title</A></STRONG><BR>\n";
      $i++;
  }
}
?>
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Computerworld tilbyder specialiserede kurser i database-management

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester