details.php
changeset 1 29ae580f12bd
parent 0 a4bc6ef5dbfe
child 3 ad69d332e9dc
equal deleted inserted replaced
0:a4bc6ef5dbfe 1:29ae580f12bd
     1 <?php 
     1 <?php 
     2 	// read user ID from cookie, if cookie doesn't exist, set to 1 (master)
     2 	// read user ID from cookie, if cookie doesn't exist, set to 1 (master)
     3 	$currID = $_COOKIE['h4c_ID'];
     3 	$currID = $_COOKIE['n4c_ID'];
     4 	
     4 	
     5 	if ($currID == "") 
     5 	if ($currID == "") 
     6 	{
     6 	{
     7 		$currID = 1;
     7 		$currID = 1;
     8 	}
     8 	}
    11 	$view_mode = $_GET['view_mode'];
    11 	$view_mode = $_GET['view_mode'];
    12 	$view_order = $_GET['view_order'];
    12 	$view_order = $_GET['view_order'];
    13 	
    13 	
    14 	
    14 	
    15 	// connect to the database
    15 	// connect to the database
    16 	$conn = mysql_connect('localhost','root','') or die(mysql_error());
    16 	$conn = mysql_connect('localhost','www-data','www-data') or die(mysql_error());
    17 	mysql_select_db('h4c_db');
    17 	mysql_select_db('members');
    18 	
    18 	
    19 	// search server cache for received websites
    19 	// search server cache for received websites
    20 	if ($currID != 1)
    20 	if ($currID != 1)
    21 	{
    21 	{
    22 		$query_cache = mysql_query("SELECT * FROM requests_tbl WHERE (user_ID = '$currID' OR user_ID = 1)");
    22 		$query_cache = mysql_query("SELECT * FROM requests_tbl WHERE (uid = '$currID' OR uid = 1)");
    23 	} 
    23 	} 
    24 	else 
    24 	else 
    25 	{
    25 	{
    26 		$query_cache = mysql_query("SELECT * FROM requests_tbl WHERE (user_ID = 1)");
    26 		$query_cache = mysql_query("SELECT * FROM requests_tbl WHERE (uid = 1)");
    27 	}
    27 	}
    28 	
    28 	
    29 	while ($db_fieldcache = mysql_fetch_assoc($query_cache)) 
    29 	while ($db_fieldcache = mysql_fetch_assoc($query_cache)) 
    30 	{
    30 	{
    31 		// send command to squid and return value
    31 		// send command to squid and return value
    32 		$curr_reqID = $db_fieldcache["req_ID"];
    32 		$curr_reqID = $db_fieldcache["req_ID"];
    33 		$commandline = "squidclient -m HEAD -p 8080 -H \"Cache-Control: only-if-cached\n\" -u " . $db_fieldcache["req_ID"] . " -w " . $db_fieldcache["user_ID"] . " " . $db_fieldcache["req_val"] . " |grep X-Cache: |grep MISS";
    33 #		$commandline = "squidclient -m HEAD -p 8080 -H \"Cache-Control: only-if-cached\n\" -u " . $db_fieldcache["req_ID"] . " -w " . $db_fieldcache["uid"] . " " . $db_fieldcache["req_val"] . " |grep X-Cache: |grep MISS";
    34 		exec($commandline, $cache_results);
    34 #		exec($commandline, $cache_results);
    35 		
    35 		
    36 		// find out if site is available and update the database
    36 		// find out if site is available and update the database
    37 		if (strpos($cache_results, "HIT") == true)
    37 		if (strpos($cache_results, "HIT") == true)
    38 		{
    38 		{
    39 			$query_update = mysql_query("UPDATE responses_tbl SET req_response = '1' WHERE req_ID = '$curr_reqID'");
    39 			$query_update = mysql_query("UPDATE responses_tbl SET req_response = '1' WHERE req_ID = '$curr_reqID'");
    65 	} 
    65 	} 
    66 	
    66 	
    67 	// pick relervant mySQl QUERY
    67 	// pick relervant mySQl QUERY
    68 	if ($view_mode == "public")
    68 	if ($view_mode == "public")
    69 	{
    69 	{
    70 		$query = mysql_query("SELECT * FROM requests_tbl WHERE (user_ID = 1) ORDER BY " . $order_sql);
    70 		$query = mysql_query("SELECT * FROM requests_tbl WHERE (uid = 1) ORDER BY " . $order_sql);
    71 	}
    71 	}
    72 	else if ($view_mode == "all")
    72 	else if ($view_mode == "all")
    73 	{
    73 	{
    74 		$query = mysql_query("SELECT * FROM requests_tbl WHERE (user_ID = '$currID' OR user_ID = 1) ORDER BY " . $order_sql);
    74 		$query = mysql_query("SELECT * FROM requests_tbl WHERE (uid = '$currID' OR uid = 1) ORDER BY " . $order_sql);
    75 	}
    75 	}
    76 	else 
    76 	else 
    77 	{
    77 	{
    78 		$query = mysql_query("SELECT * FROM requests_tbl WHERE (user_ID = '$currID') ORDER BY " . $order_sql);
    78 		$query = mysql_query("SELECT * FROM requests_tbl WHERE (uid = '$currID') ORDER BY " . $order_sql);
    79 	}
    79 	}
    80 	
    80 	
    81 	
    81 	
    82 	// Construct search information message
    82 	// Construct search information message
    83 	if ($view_mode == "public") 
    83 	if ($view_mode == "public") 
    92 
    92 
    93 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    93 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    94 <html xmlns="http://www.w3.org/1999/xhtml">
    94 <html xmlns="http://www.w3.org/1999/xhtml">
    95 <head>
    95 <head>
    96 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    96 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    97 <title>H4C - Welcome. <?php print $search_info; ?></title>
    97 <title>N4C - Welcome. <?php print $search_info; ?></title>
    98 <link href="files/h4c_main.css" rel="stylesheet" type="text/css" media="screen" />
    98 <link href="files/n4c_main.css" rel="stylesheet" type="text/css" media="screen" />
    99 </head>
    99 </head>
   100 
   100 
   101 <body>
   101 <body>
   102 <div id="container">
   102 <div id="container">
   103     <div id="header">
   103     <div id="header">
   104         <h1><span>H4C</span></h1>
   104         <h1><span>N4C</span></h1>
   105     	<p id="credits">HTML Requester v. 1.00</p>
   105     	<p id="credits">HTML Requester v. 1.00</p>
   106     </div>
   106     </div>
   107     <?php 
   107     <?php 
   108 		// show status messages based on user interaction
   108 		// show status messages based on user interaction
   109 		if ($status == "del") 
   109 		if ($status == "del") 
   159             //display current search requests
   159             //display current search requests
   160             $search_count = 1;
   160             $search_count = 1;
   161 			
   161 			
   162 			while ($db_field = mysql_fetch_assoc($query)) 
   162 			while ($db_field = mysql_fetch_assoc($query)) 
   163 			{		 
   163 			{		 
   164 				if ($db_field['user_ID'] != 1 and $view_mode == "all")
   164 				if ($db_field['uid'] != 1 and $view_mode == "all")
   165 				{
   165 				{
   166 					print "<div class='search_result_private'><span class='result_no'>" . $search_count . "</span> ";
   166 					print "<div class='search_result_private'><span class='result_no'>" . $search_count . "</span> ";
   167 					print "<span class='search_txt'>Search:</span><span class='search_input'><em>" . $db_field['req_val'] . "</em></span> ";
   167 					print "<span class='search_txt'>Search:</span><span class='search_input'><em>" . $db_field['req_val'] . "</em></span> ";
   168 				} else {
   168 				} else {
   169 					print "<div class='search_result'><span class='result_no'>" . $search_count . "</span> ";
   169 					print "<div class='search_result'><span class='result_no'>" . $search_count . "</span> ";