1 |
<?php |
2 |
// Load globals |
3 |
require_once ("global_vars.php"); |
4 |
|
5 |
// Includes |
6 |
require_once ("db_connect.php"); |
7 |
|
8 |
|
9 |
|
10 |
// Error checking |
11 |
$page_id = (int) $page_id; |
12 |
$element_id = (int) $element_id; |
13 |
|
14 |
if ($page_id > 0 && $element_id > 0) { |
15 |
|
16 |
// Determine what sort of element |
17 |
$sql = "SELECT * FROM element e |
18 |
LEFT JOIN resource r using (resource_id) |
19 |
LEFT JOIN service v on e.service_id = v.service_id |
20 |
LEFT JOIN location l on e.location_id = l.location_id |
21 |
LEFT JOIN staff s on e.staff_id = s.staff_id |
22 |
LEFT JOIN subject b on e.subject_id = b.subject_id |
23 |
WHERE page_id = " |
24 |
. $page_id |
25 |
. " AND element_id = " |
26 |
. $element_id; |
27 |
|
28 |
$rs = mysql_tryquery($sql); |
29 |
$row = mysql_fetch_array($rs, MYSQL_ASSOC); |
30 |
|
31 |
// Resource |
32 |
$resource_id = $row["resource_id"]; |
33 |
$url = $row["url"]; |
34 |
|
35 |
// Location |
36 |
$location_id = $row["location_id"]; |
37 |
$mainURL = $row["mainURL"]; |
38 |
|
39 |
// Service |
40 |
$service_id = $row["service_id"]; |
41 |
$serviceURL = $row["serviceURL"]; |
42 |
|
43 |
// Staff |
44 |
$staff_id = $row["staff_id"]; |
45 |
$staff_account = $row["staff_account"]; |
46 |
$staff_email = $row["staff_email"]; |
47 |
|
48 |
// Subject |
49 |
$subject_id = $row["subject_id"]; |
50 |
$subjectURL = $GLOBAL_RQS_URL."rqs.phtml?subject_id=".$subject_id; |
51 |
|
52 |
// Unique |
53 |
$label_url = $row["label_url"]; |
54 |
|
55 |
// Initialize |
56 |
$redirect_url = ""; |
57 |
|
58 |
// Set others to NULL |
59 |
if ($resource_id < 1) $resource_id = "NULL"; |
60 |
if ($location_id < 1) $location_id = "NULL"; |
61 |
if ($service_id < 1) $service_id = "NULL"; |
62 |
if ($staff_id < 1) $staff_id = "NULL"; |
63 |
if ($subject_id < 1) $subject_id = "NULL"; |
64 |
|
65 |
// Determine the URL to use |
66 |
if ($resource_id > 0) $redirect_url = $url; |
67 |
else if ($location_id > 0) $redirect_url = $mainURL; |
68 |
else if ($service_id > 0) $redirect_url = $serviceURL; |
69 |
else if ($subject_id > 0) $redirect_url = $subjectURL; |
70 |
else if ($staff_id > 0 ) $redirect_url = "mailto:" . $staff_email; |
71 |
else if (strlen($label_url) > 0) $redirect_url = $label_url; |
72 |
|
73 |
// Fetch user ip |
74 |
$user_ip = $GLOBALS["REMOTE_ADDR"]; |
75 |
|
76 |
// Do the stat stuff here |
77 |
$sql = "INSERT INTO libstats.elementstats ( |
78 |
element_id, |
79 |
page_id, |
80 |
resource_id, |
81 |
location_id, |
82 |
service_id, |
83 |
staff_id, |
84 |
subject_id, |
85 |
visit_date, |
86 |
user_ip) VALUES (" |
87 |
. $element_id |
88 |
. ", " |
89 |
. $page_id |
90 |
. ", " |
91 |
. $resource_id |
92 |
. ", " |
93 |
. $location_id |
94 |
. ", " |
95 |
. $service_id |
96 |
. ", " |
97 |
. $staff_id |
98 |
. ", " |
99 |
. $subject_id |
100 |
. ", now(), '" |
101 |
. $user_ip |
102 |
. "')"; |
103 |
mysql_tryquery($sql); |
104 |
|
105 |
// Redirect the user |
106 |
header("Location: " . $redirect_url); |
107 |
} |
108 |
|
109 |
else printf("Resource not found..."); |
110 |
|
111 |
?> |