|
1 <?php |
|
2 // read user ID from cookie, if cookie doesn't exist, set to 1 (master) |
|
3 $currID = $_COOKIE['h4c_ID']; |
|
4 |
|
5 if ($currID == "") |
|
6 { |
|
7 $currID = 1; |
|
8 } |
|
9 |
|
10 $status = $_GET['alert']; |
|
11 $view_mode = $_GET['view_mode']; |
|
12 $view_order = $_GET['view_order']; |
|
13 |
|
14 |
|
15 // connect to the database |
|
16 $conn = mysql_connect('localhost','root','') or die(mysql_error()); |
|
17 mysql_select_db('h4c_db'); |
|
18 |
|
19 // search server cache for received websites |
|
20 if ($currID != 1) |
|
21 { |
|
22 $query_cache = mysql_query("SELECT * FROM requests_tbl WHERE (user_ID = '$currID' OR user_ID = 1)"); |
|
23 } |
|
24 else |
|
25 { |
|
26 $query_cache = mysql_query("SELECT * FROM requests_tbl WHERE (user_ID = 1)"); |
|
27 } |
|
28 |
|
29 while ($db_fieldcache = mysql_fetch_assoc($query_cache)) |
|
30 { |
|
31 // send command to squid and return value |
|
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"; |
|
34 exec($commandline, $cache_results); |
|
35 |
|
36 // find out if site is available and update the database |
|
37 if (strpos($cache_results, "HIT") == true) |
|
38 { |
|
39 $query_update = mysql_query("UPDATE responses_tbl SET req_response = '1' WHERE req_ID = '$curr_reqID'"); |
|
40 } |
|
41 else |
|
42 { |
|
43 $query_update = mysql_query("UPDATE responses_tbl SET req_response = '0' WHERE req_ID = '$curr_reqID'"); |
|
44 } |
|
45 } |
|
46 |
|
47 |
|
48 // pick order to show (user specified) |
|
49 |
|
50 if ($view_order == "pend") |
|
51 { |
|
52 $order_sql = "req_response ASC"; |
|
53 } |
|
54 else if ($view_order == "date_asc") |
|
55 { |
|
56 $order_sql = "req_created ASC"; |
|
57 } |
|
58 else if ($view_order == "avail") |
|
59 { |
|
60 $order_sql = "req_response DESC"; |
|
61 } |
|
62 else |
|
63 { |
|
64 $order_sql = "req_created DESC"; |
|
65 } |
|
66 |
|
67 // pick relervant mySQl QUERY |
|
68 if ($view_mode == "public") |
|
69 { |
|
70 $query = mysql_query("SELECT * FROM requests_tbl WHERE (user_ID = 1) ORDER BY " . $order_sql); |
|
71 } |
|
72 else if ($view_mode == "all") |
|
73 { |
|
74 $query = mysql_query("SELECT * FROM requests_tbl WHERE (user_ID = '$currID' OR user_ID = 1) ORDER BY " . $order_sql); |
|
75 } |
|
76 else |
|
77 { |
|
78 $query = mysql_query("SELECT * FROM requests_tbl WHERE (user_ID = '$currID') ORDER BY " . $order_sql); |
|
79 } |
|
80 |
|
81 |
|
82 // Construct search information message |
|
83 if ($view_mode == "public") |
|
84 { |
|
85 $search_info = "There are " . mysql_num_rows($query) . " saved public searches."; |
|
86 } else if ($view_mode == "private") { |
|
87 $search_info = "You have " . mysql_num_rows($query) . " saved private searches."; |
|
88 } else { |
|
89 $search_info = "There are " . mysql_num_rows($query) . " saved searches."; |
|
90 } |
|
91 ?> |
|
92 |
|
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"> |
|
95 <head> |
|
96 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
|
97 <title>H4C - Welcome. <?php print $search_info; ?></title> |
|
98 <link href="files/h4c_main.css" rel="stylesheet" type="text/css" media="screen" /> |
|
99 </head> |
|
100 |
|
101 <body> |
|
102 <div id="container"> |
|
103 <div id="header"> |
|
104 <h1><span>H4C</span></h1> |
|
105 <p id="credits">HTML Requester v. 1.00</p> |
|
106 </div> |
|
107 <?php |
|
108 // show status messages based on user interaction |
|
109 if ($status == "del") |
|
110 { |
|
111 print "<div id='delete_alert'><span>You have successfully deleted the selected search.</span><a href='details.php'><img class='img_right' src='images/x.gif' width='14' height='20' /></a><div class='clear'></div></div>"; |
|
112 } else if ($status == "add") |
|
113 { |
|
114 print "<div id='add_alert'><span>You have successfully added a new search.</span><a href='details.php'><img class='img_right' src='images/x.gif' width='14' height='20' /></a><div class='clear'></div></div>"; |
|
115 } else if ($status == "urlerror") |
|
116 { |
|
117 print "<div id='delete_alert'><span>You have entered an malformed url. Please use this format: <em><strong>http://www.yourwebsite.com</strong></em></span><a href='details.php'><img class='img_right' src='images/x.gif' width='14' height='20' /></a><div class='clear'></div></div>"; |
|
118 } |
|
119 ?> |
|
120 <div id="search"> |
|
121 <h2>Open a new search:</h2> |
|
122 <form action="add_search.php" method="get" enctype="multipart/form-data" name="search" target="_parent"> |
|
123 <input name="search_term" type="text" value="http://www.yourwebsite.com" size="21" /> |
|
124 <?php |
|
125 // |
|
126 if ($currID != 1) |
|
127 { |
|
128 print "<select name='search_type' size='1'>"; |
|
129 print "<option value='public' selected>Public</option>"; |
|
130 print "<option value='private'>Private</option></select>"; |
|
131 } |
|
132 ?> |
|
133 <input id="search_button" name="submit" type="submit" value="Search" /> |
|
134 </form> |
|
135 </div> |
|
136 <div id="results"> |
|
137 <h2><?php print $search_info; ?></h2> |
|
138 <?php |
|
139 // customise view links based on view |
|
140 |
|
141 print "<div id='view_options'><form action='details.php' method='get' enctype='multipart/form-data' name='search' target='_parent'>"; |
|
142 |
|
143 if ($currID != 1) |
|
144 { |
|
145 print "<select name='view_mode' size='1'>"; |
|
146 print "<option value='private' selected>Private searches</option>"; |
|
147 print "<option value='public'>Public searches</option>"; |
|
148 print "<option value='all'>All searches</option></select> "; |
|
149 } |
|
150 |
|
151 print "<select name='view_order' size='1'>"; |
|
152 print "<option value='date_desc' selected>Newest > Oldest</option>"; |
|
153 print "<option value='date_asc'>Oldest > Newest</option>"; |
|
154 print "<option value='avail'>Available > Pending</option> "; |
|
155 print "<option value='pend'>Pending > Available</option></select> "; |
|
156 print "<input name='submit' type='submit' value='Update view' /></form></div>"; |
|
157 ?> |
|
158 <?php |
|
159 //display current search requests |
|
160 $search_count = 1; |
|
161 |
|
162 while ($db_field = mysql_fetch_assoc($query)) |
|
163 { |
|
164 if ($db_field['user_ID'] != 1 and $view_mode == "all") |
|
165 { |
|
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> "; |
|
168 } else { |
|
169 print "<div class='search_result'><span class='result_no'>" . $search_count . "</span> "; |
|
170 print "<span class='search_txt'>Search:</span><span class='search_input'><em>" . $db_field['req_val'] . "</em></span> "; |
|
171 } |
|
172 |
|
173 print "<span class='results_txt'>Status:</span>"; |
|
174 |
|
175 if ($db_field['req_response'] == 0) |
|
176 { |
|
177 print "<span class='result_output_none'>Result pending</span>"; |
|
178 print "<a href='delete.php?req_id=" . $db_field['req_ID'] . "'><img src='images/x.gif' width='14' height='20' /></a>"; |
|
179 } else { |
|
180 print "<span class='result_output'><a href='" . $db_field['req_val'] ."' target='_blank'>View website</a></span>"; |
|
181 print "<a href='delete.php?req_id=" . $db_field['req_ID'] . "'><img src='images/x.gif' width='14' height='20' /></a>"; |
|
182 } |
|
183 print "<div class='clear'></div></div>"; |
|
184 |
|
185 $search_count++; |
|
186 } |
|
187 |
|
188 // if no requests, display message |
|
189 if (mysql_num_rows($query) < 1) |
|
190 { |
|
191 print '<p>You have no previous searches please use the search form to create a new search.</p>'; |
|
192 } |
|
193 |
|
194 mysql_close(); |
|
195 ?> |
|
196 </div> |
|
197 </div> |
|
198 </body> |
|
199 </html> |