// function to detect crawlers include("crawler.php"); // setup the db connection $user="deb12177_user"; $password="tf][HTZ)(vt^L2010"; $database="deb12177_photos"; mysql_connect(localhost, $user, $password); @mysql_select_db($database) or die ( "Unable to select database"); // retrieve the category the user wants to see $cat = mysql_real_escape_string($_GET['cat']); // get the category data from the db $query = "SELECT * FROM category WHERE id = " . $cat; $result = mysql_query($query); $catrow = mysql_fetch_assoc($result); // update the hit count for this category $nostats = $_GET['nostats']; // check if we have to keep statistics, indicated through the nostats parameter: // nostats = 2: administrator mode, no statistics // nostats = 1: single view without statistics, e.g. when posting a comment if ($nostats == 2) { // administrator mode, we append the parameter setting to all links $refnostats = "&nostats=2"; } else { // single view without stats, we don't pass it on to links $refnostats = ""; if ($nostats != 1) { // check if the visitor is a bot $crawler = crawlerDetect($_SERVER['HTTP_USER_AGENT']); if ($crawler) { // it is crawler, don't update the hitcount } else { $query = "UPDATE category SET hits = ". ($catrow['hits'] + 1) ." WHERE id = ". $cat; mysql_query($query); // store the visitor in the visitors table $query = "INSERT INTO visitors (user_agent, date, bot, pic, cat) VALUES ('". mysql_real_escape_string($_SERVER['HTTP_USER_AGENT'])."', NOW(), '".($crawler ? "1" : "0")."', '0', '".$cat."')"; mysql_query($query); } } } // we now proceed with printing the page header ?>
// print a tree with all categories // first, find in which main branch this category belongs $currcat = $cat; $branch = $cat; while (!(($currcat == 2) || ($currcat == 3) || ($currcat == 4) || ($currcat == 34))) { $query = "SELECT parent FROM category WHERE id = ". $currcat; $prow = mysql_fetch_array(mysql_query($query)); $currcat = $prow[0]; $branch = $prow[0]; } // prints the contents of a specific category, up to a certain level function printcat($catid, $cat, $showlevel, $refnostats) { $query = "SELECT DISTINCT category.name_short, category.showpics, category.level, category.id, COUNT(pic_cat.cat_id) ". "FROM category JOIN pic_cat ON pic_cat.cat_id = category.id WHERE category.id = ". $catid; $pcrow = mysql_fetch_array(mysql_query($query)); if ($pcrow[2] <= $showlevel) { // indent according to level depth for ($i = 0; $i < $pcrow[2]; $i++) echo " "; echo ""; if ($pcrow[3] == $cat) echo "". $pcrow[0] .""; else echo $pcrow[0]; echo ""; if ($pcrow[1] == TRUE) { // this category has pictures, show how many echo " (". $pcrow[4] .") "; } else { echo " "; // get all subcategories $query = "SELECT id FROM category WHERE parent = ". $catid ." ORDER BY name_short"; $result = mysql_query($query); // recursive call to print subcategories while ($pcsubcatrow = mysql_fetch_array($result)) printcat($pcsubcatrow[0], $cat, $showlevel, $refnostats); } } } if ($branch == 2) printcat(2, $cat, $catrow['level'] + ($catrow['showpics'] == 0 ? 1 : 0), $refnostats); else printcat(2, $cat, 0, $refnostats); if ($branch == 3) printcat(3, $cat, $catrow['level'] + ($catrow['showpics'] == 0 ? 1 : 0), $refnostats); else printcat(3, $cat, 0, $refnostats); if ($branch == 4) printcat(4, $cat, $catrow['level'] + ($catrow['showpics'] == 0 ? 1 : 0), $refnostats); else printcat(4, $cat, 0, $refnostats); if ($branch == 34) printcat(34, $cat, $catrow['level'] + ($catrow['showpics'] == 0 ? 1 : 0), $refnostats); else printcat(34, $cat, 0, $refnostats); ?> |
// we can now print the category's content // print table header echo "
| ||||||||
|
}
// close the category thumbs table
echo "
Total echo $entrytype; ?>: echo $numentries; ?> | Hits: echo ($catrow['hits'] + 1); ?> | Last update: echo $catrow['modified']; ?> | Design by Chameleon |