// start a session session_start(); // 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 picture and category $pic = mysql_real_escape_string($_GET['pic']); $cat = mysql_real_escape_string($_GET['cat']); $nostats = $_GET['nostats']; // get the picture data from the db $query = "SELECT * FROM picture WHERE id = " . $pic; $result = mysql_query($query); $picrow = mysql_fetch_assoc($result); // 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 { // update the picture's hit counter $query = "UPDATE picture SET hits = ". ($picrow['hits'] + 1) ." WHERE id = ". $pic; 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")."', '".$pic."', '".$cat."')"; mysql_query($query); } } } // get the category data from the db $query = "SELECT * FROM category WHERE id = " . $cat; $result = mysql_query($query); $catrow = mysql_fetch_assoc($result); // get the id's of the other pictures in this category // to determine thumbnails, prev, next, and last picture in slide show $query = "SELECT id, name, filename FROM picture JOIN pic_cat ON (picture.id = pic_cat.pic_id) ". "WHERE pic_cat.cat_id = ". $cat ." ORDER BY pic_cat.position, picture.id"; $picsresult = mysql_query($query); $numpics = mysql_num_rows($picsresult); // find the index of the current picture in this array for ($i = 0; $i < $numpics; $i++) if (mysql_result($picsresult, $i, 0) == $pic) { $currindex = $i; break; } // find the first, previous, next and last picture in this category $first_id = mysql_result($picsresult, 0, 0); if ($currindex > 0) { $prev_id = mysql_result($picsresult, $currindex - 1, 0); $prev_name = mysql_result($picsresult, $currindex - 1, 1); $prev_filename = mysql_result($picsresult, $currindex - 1, 2); } if ($currindex < ($numpics - 1)) { $next_id = mysql_result($picsresult, $currindex + 1, 0); $next_name = mysql_result($picsresult, $currindex + 1, 1); $next_filename = mysql_result($picsresult, $currindex + 1, 2); } $last_id = mysql_result($picsresult, $numpics - 1, 0); $last_name = mysql_result($picsresult, $numpics - 1, 1); $last_filename = mysql_result($picsresult, $numpics - 1, 2); // get the id's of all categories this picture belongs to $query = "SELECT cat_id FROM pic_cat WHERE pic_id = ". $pic; $catsresult = mysql_query($query); // we can now proceed with filling in the page content ?>
// print a tree with all categories // first, find in which main branch this picture belongs $currcat = $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'], $refnostats); else printcat(2, $cat, 0, $refnostats); if ($branch == 3) printcat(3, $cat, $catrow['level'], $refnostats); else printcat(3, $cat, 0, $refnostats); if ($branch == 4) printcat(4, $cat, $catrow['level'], $refnostats); else printcat(4, $cat, 0, $refnostats); if ($branch == 34) printcat(34, $cat, $catrow['level'], $refnostats); else printcat(34, $cat, 0, $refnostats); ?> |
// see if there are comments for this picture $commentsresult = mysql_query("SELECT * FROM comments WHERE (pic_id=". $pic ." AND spam=0)"); if (mysql_num_rows($commentsresult) > 0) { ?>
} ?>
|