Index: modules/recorder.module
===================================================================
RCS file: d:/cvsroot/newdrupal/modules/recorder.module,v
retrieving revision 1.1
diff -u -r1.1 recorder.module
--- modules/recorder.module	10 Feb 2004 17:32:03 -0000	1.1
+++ modules/recorder.module	10 Feb 2004 21:04:26 -0000
@@ -1,7 +1,7 @@
 <?php
 // $Id: recorder.module,v 1.1 2004/02/10 17:32:03 Jose Exp $
 
-recorder_init();
+//recorder_init();
 
 function recorder_system($field){
   $system["description"] = t("Record (track/log) specific visitors.");
@@ -13,8 +13,8 @@
 }
 
 function recorder_link($type) {
-  if ($type == "admin" && user_access("administer recorder")) {
-    $links[] = la(t("recorder"), array("mod" => "recorder"));
+  if ($type == "system" && user_access("administer recorder")) {
+    menu("admin/recorder",t("recorder"),"recorder_admin",0);
   }
   return $links ? $links : array();
 }
@@ -23,7 +23,7 @@
   /// TODO clean database, guard against excessive recording
 }
 
-function recorder_conf_options() {
+function recorder_settings() {
   $output .= form_select(t("Tracks"), "recorder_max_tracks", variable_get("recorder_max_tracks", 32), array("8" => "8", "16" => "16", "32" => "32", "48" => "48", "64" => "64", "96" => "96"), "Select maximum number of tracks available.");
   $output .= form_select(t("Session timeout"), "recorder_timeout", variable_get("recorder_timeout", 1800), array("1800" => "30 minutes", "2700" => "45 minutes", "3600" => "1 hour", "86400" => "1 day", "31536000" => "1 year"), "Select the period after which sessions should be timed out.");
   $output .= form_select(t("Cookie expire"), "recorder_cookie_expire", variable_get("recorder_cookie_expire", 365), array("1" => "1 day", "7" => "1 week", "30" => "1 month", "60" => "2 months", "90" => "3 months", "180" => "6 months", "365" => "1 year"), "Select the period after which the filter cookies should expire.");
@@ -48,12 +48,19 @@
   return $output;
 }
 
+// Set up some global variables used in this module.
+function recorder_init_globals(){
+	global $REMOTE_ADDR, $HTTP_USER_AGENT, $HTTP_REFERER;
+	$REMOTE_ADDR=$_SERVER["REMOTE_ADDR"];
+	$HTTP_USER_AGENT=$_SERVER["HTTP_USER_AGENT"];
+	$HTTP_REFERER=$_SERVER["HTTP_REFERER"];
+}
+
 // Main function
 function recorder_init() {
   global $user, $HTTP_COOKIE_VARS;
-  
+  recorder_init_globals();
   $tracks = recorder_get_tracks();
-  
   foreach($tracks as $track) {
     $var = "rec" . $track['rid'];
     
@@ -98,7 +105,7 @@
       }
       else if ($track['target'] && $track['filter'] == "ip") {
         $host = recorder_get_ip();
-        $proxy = recorder_get_proxy();      
+        $proxy = recorder_get_proxy();
         if (strstr($host, $track['target']) || strstr($proxy, $track['target'])) { 
           recorder_record($track['rid']);
           if ($track['cookie'] == 1) {
@@ -214,7 +221,7 @@
 function recorder_session_note() {
   global $op, $rid, $rsid;
 
-  $result = db_query("SELECT note FROM rec_sess WHERE sid = '%s'", $rsid);
+  $result = db_query("SELECT note FROM {rec_sess} WHERE sid = '%s'", $rsid);
   $note = db_fetch_object($result);
   
   $output .= "<h3>Recorder Session Note</h3>";
@@ -229,7 +236,7 @@
 }
 
 function recorder_save_note($edit) {
-  db_query("UPDATE rec_sess SET note = '%s' WHERE sid = '%s'", $edit['note'], $edit['rsid']);
+  db_query("UPDATE {rec_sess} SET note = '%s' WHERE sid = '%s'", $edit['note'], $edit['rsid']);
 }
 
 function recorder_save_track($edit) {
@@ -296,8 +303,8 @@
   if (!count($new_tracks)) variable_del("recorder_tracks");
   else variable_set("recorder_tracks", $new_tracks);
   
-  db_query("DELETE FROM rec_sess WHERE rid = '$rid'");
-  db_query("DELETE FROM rec_log WHERE rid = '$rid'");
+  db_query("DELETE FROM {rec_sess} WHERE rid = '$rid'");
+  db_query("DELETE FROM {rec_log} WHERE rid = '$rid'");
 }
 
 function recorder_delete_session($rid, $sid) {
@@ -305,8 +312,8 @@
   $track['recs'] = $track['recs'] - 1; 
   recorder_save_track($track); 
   
-  db_query("DELETE FROM rec_sess WHERE sid = '$sid'");
-  db_query("DELETE FROM rec_log WHERE sid = '$sid'");
+  db_query("DELETE FROM {rec_sess} WHERE sid = '$sid'");
+  db_query("DELETE FROM {rec_log} WHERE sid = '$sid'");
 }
 
 function recorder_move_session($rid, $rsid, $nrid) {
@@ -318,8 +325,8 @@
   $track2['recs'] = $track2['recs'] + 1;
   recorder_save_track($track2); 
   
-  db_query("UPDATE rec_sess SET rid = '$nrid' WHERE sid = '$rsid'");
-  db_query("UPDATE rec_log SET rid = '$nrid' WHERE sid = '$rsid'");
+  db_query("UPDATE {rec_sess} SET rid = '$nrid' WHERE sid = '$rsid'");
+  db_query("UPDATE {rec_log} SET rid = '$nrid' WHERE sid = '$rsid'");
 }
 
 function recorder_format_row($track, $rid) {
@@ -346,12 +353,12 @@
     $output .= "<td>&nbsp;</td>";
   } 
   $output .= "<td align=\"right\">";
-  if ($track['recs']) $output .= la("view", array("mod" => "recorder", "op" => "view", "rid" => $rid)) . " - ";
-  $output .= la("edit", array("mod" => "recorder", "op" => "edit", "rid" => $rid)) . " - ";
-    $output .= "<a href=\"" . drupal_url(array("mod" => "recorder", "op" => "delete", "rid" => $rid), "admin") . "\" onClick=\"return confirm('Are you sure you want to delete this track?')\">";
+  if ($track['recs']) $output .= l("view", "admin/recorder/view/$rid") . " - ";
+  $output .= l("edit", "admin/recorder/edit/$rid") . " - ";
+    $output .= "<a href=\"" . url("admin/recorder/delete/$rid") . "\" onClick=\"return confirm('Are you sure you want to delete this track?')\">";
     $output .= "delete</a> - ";
-  if ($track['pause']) $output .= la("record", array("mod" => "recorder", "op" => "record", "rid" => $rid));
-  else $output .= la("pause", array("mod" => "recorder", "op" => "pause", "rid" => $rid)) . "</td></tr>";    
+  if ($track['pause']) $output .= l("record", "admin/recorder/record/$rid");
+  else $output .= l("pause", "admin/recorder/pause/$rid") . "</td></tr>";    
   
   if ($track) return $output;
 }
@@ -473,7 +480,7 @@
   $post = unserialize($details->post);
   if (count($post)) $output .= "<td align=\"center\"><small>yes</small></td>";
   else $output .= "<td>&nbsp;</td>";
-  $output .= "<td align=\"center\">" . la("view", array("mod" => "recorder", "op" => "headers", "rid" => $details->rid, "rsid" => $details->sid, "lid" => $details->lid)) . "</td>";  
+  $output .= "<td align=\"center\">" . l("view", "admin/recorder/headers/$details->rid/$details->sid/$details->lid") . "</td>";  
   $output .= "</tr>";
 
   return $output;
@@ -491,11 +498,11 @@
     $output .= $date . "</td><td><small>";
     $output .= $value['note'];
     $output .= "&nbsp;</small></td><td>";
-    $output .= "<a href=\"" . drupal_url(array("mod" => "recorder", "op" => "delete", "rid" => $rid, "rsid" => $key), "admin") . "\" onClick=\"return confirm('Are you sure you want to delete this session?')\">";
+    $output .= "<a href=\"" . url("admin/recorder/delete/$rid/$key") . "\" onClick=\"return confirm('Are you sure you want to delete this session?')\">";
     $output .= "delete</a> - ";
-    $output .= la("move", array("mod" => "recorder", "op" => "move", "rid" => $rid, "rsid" => $key));
+    $output .= l("move", "admin/recorder/move/$rid/$key");
     $output .= " - ";  
-    $output .= la("view", array("mod" => "recorder", "op" => "view", "rid" => $rid, "rsid" => $key));
+    $output .= l("view", "admin/recorder/view/$rid/$key");
     $output .= " - playback";
     $output .= "</td></tr>";
   }
@@ -518,7 +525,7 @@
 }
 
 function recorder_session_headers($lid) {
-  $result = db_query("SELECT * FROM rec_log WHERE lid = '%s'", $lid);
+  $result = db_query("SELECT * FROM {rec_log} WHERE lid = '%s'", $lid);
   $headers = db_fetch_array($result);
      
   $entries['Referer'] = $headers['referer'];
@@ -600,7 +607,7 @@
   $details = array();
   $notes = array();
   
-  $result = db_query("SELECT * FROM rec_sess WHERE rid = '$rid' ORDER BY timestamp");
+  $result = db_query("SELECT * FROM {rec_sess} WHERE rid = '$rid' ORDER BY timestamp");
 
   while ($sessions = db_fetch_object($result)) {
     $agents[$sessions->sid] = $sessions->agent;
@@ -645,7 +652,7 @@
 function recorder_view_session($rid, $rsid) {
   $track = recorder_get_track($rid);
   
-  $result = db_query("SELECT * FROM rec_sess WHERE sid = '$rsid' ORDER BY timestamp");
+  $result = db_query("SELECT * FROM {rec_sess} WHERE sid = '$rsid' ORDER BY timestamp");
 
   if ($session = db_fetch_object($result)) {
     $track['init'] = format_date($session->timestamp, "custom", "D j M - H:i");
@@ -671,7 +678,7 @@
     $track['usernames'] = $session->username;
     $track['note'] = $session->note;
 
-    $result = db_query("SELECT flags FROM rec_log WHERE sid = '$rsid'");
+    $result = db_query("SELECT flags FROM {rec_log} WHERE sid = '$rsid'");
     while ($flags = db_fetch_array($result)) {
       $flag_vars[] = unserialize($flags['flags']);
     }
@@ -688,7 +695,7 @@
       }
     }
   }
-  $result = db_query("SELECT * FROM rec_log WHERE sid = '$rsid' ORDER by timestamp");
+  $result = db_query("SELECT * FROM {rec_log} WHERE sid = '$rsid' ORDER by timestamp");
 
   $details .= "<table border=\"1\" cellpadding=\"3\" cellspacing=\"0\">\n";
   $details .= "<tr><th>Time</th><th>Source</th><th>Destination</th><th>Post</th><th>Options</th></tr>";
@@ -742,7 +749,7 @@
     else $username = $HTTP_COOKIE_VARS['aid'];
     $note = "";
     
-    db_query("INSERT INTO rec_sess (rid, timestamp, host, domain, proxy, agent, username, note) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $rid, $timestamp, $host, $domain, $proxy, $agent, $username, $note);
+    db_query("INSERT INTO {rec_sess} (rid, timestamp, host, domain, proxy, agent, username, note) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $rid, $timestamp, $host, $domain, $proxy, $agent, $username, $note);
 
     $track['recs'] = $track['recs'] + 1; 
     $HTTP_SESSION_VARS[$var] = 1; 
@@ -770,7 +777,7 @@
     $session = serialize($HTTP_SESSION_VARS);
     $flags = serialize(recorder_get_flags());
     
-    db_query("INSERT INTO rec_log (rid, sid, phpsid, timestamp, referer, request, get, post, cookie, session, flags) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $rid, $sid, $phpsid, $timestamp, $referer, $request, $get, $post, $cookie, $session, $flags);
+    db_query("INSERT INTO {rec_log} (rid, sid, phpsid, timestamp, referer, request, get, post, cookie, session, flags) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $rid, $sid, $phpsid, $timestamp, $referer, $request, $get, $post, $cookie, $session, $flags);
     
     $update = 1;
   }
@@ -783,86 +790,91 @@
 
 function recorder_admin() {
   global $op, $rid, $edit, $rsid, $lid;
-  
+  $op=$_POST["op"];
+  if(!$op) $op=arg(2);
+  $rid=arg(3);
+  $rsid=arg(4);
+  $lid=arg(5);
+  $edit=$_POST["edit"];
   if (!$edit) $edit = recorder_get_track($rid);
 
   if (user_access("administer recorder")) {
-    print "<small>". la(t("track list"), array("mod" => "recorder", "op" => "list")) ." | ";
-    if (count(variable_get("recorder_tracks", 0)) <= variable_get("recorder_max_tracks", 32)) print la(t("add track"), array("mod" => "recorder", "op" => "add")) ." | "; 
-    if ($rid != "" && $rsid == "" && $op == "view") print la(t("settings"), array("mod" => "recorder", "op" => "edit", "rid" => $rid)) ." | ";
-    if ($rsid != "") print la(t("track"), array("mod" => "recorder", "op" => "view", "rid" => $rid)) ." | ";
-    if ($lid != "") print la(t("session"), array("mod" => "recorder", "op" => "view", "rid" => $rid, "rsid" => $rsid)) ." | ";
-    if ($rsid != "" && $op != "note" && $op != "move" && $edit['op'] != "move") print la(t("add note"), array("mod" => "recorder", "op" => "note", "rid" => $rid, "rsid" => $rsid)) ." | ";
-    print la(t("help"), array("mod" => "recorder", "op" => "help")) ."</small><hr />\n";
+    $output .= "<small>". l(t("track list"), "admin/recorder/list") ." | ";
+    if (count(variable_get("recorder_tracks", 0)) <= variable_get("recorder_max_tracks", 32)) $output .= l(t("add track"), "admin/recorder/add") ." | "; 
+    if ($rid != "" && $rsid == "" && $op == "view") $output .= l(t("settings"), "admin/recorder/edit/$rid" ) ." | ";
+    if ($rsid != "") $output .= l(t("track"), "admin/recorder/view/$rid") ." | ";
+    if ($lid != "") $output .= l(t("session"), "admin/recorder/view/$rid/$rsid") ." | ";
+    if ($rsid != "" && $op != "note" && $op != "move" && $edit['op'] != "move") $output .= l(t("add note"), "admin/recorder/note/$rid/$rsid") ." | ";
+    $output .= l(t("help"), "admin/help#recorder") ."</small><hr />\n";
 
     switch ($op) {
       case "help":
-        print recorder_help();
+        $output .= recorder_help();
         break;
       case "Delete":
       case "delete":
         if ($rsid != "") { 
           recorder_delete_session($rid, $rsid);
-          print recorder_view_track($rid);
+          $output .= recorder_view_track($rid);
         } 
         else { 
           recorder_delete_track($rid);
-          print recorder_list_tracks();
+          $output .= recorder_list_tracks();
         }
         break;
       case "add":          
       case "edit":
-        print recorder_edit_track($edit);
+        $output .= recorder_edit_track($edit);
         break;
       case "Save":
         if ($edit['op'] == "note") { 
           recorder_save_note($edit);
-          print recorder_view_track($edit['rid']);
+          $output .= recorder_view_track($edit['rid']);
         } 
         else { 
           recorder_save_track($edit);
-          print recorder_list_tracks();
+          $output .= recorder_list_tracks();
         }
         break;
       case "view":
-        if ($rsid) print recorder_view_session($rid, $rsid);
-        else print recorder_view_track($rid);
+        if ($rsid) $output .= recorder_view_session($rid, $rsid);
+        else $output .= recorder_view_track($rid);
         break;
       case "record":
         recorder_start($rid);
-        print recorder_list_tracks();
+        $output .= recorder_list_tracks();
         break;
       case "pause":
         recorder_pause($rid);
-        print recorder_list_tracks();
+        $output .= recorder_list_tracks();
         break;
       case "move":
       case "Move":
         if ($edit['nrid'] == "") { 
-          print recorder_choose_track($rid, $rsid);
+          $output .= recorder_choose_track($rid, $rsid);
         } 
         else { 
           recorder_move_session($edit['rid'], $edit['rsid'], $edit['nrid']);
-          print recorder_list_tracks();
+          $output .= recorder_list_tracks();
         }
         break;
       case "note":
-        print recorder_session_note();
+        $output .= recorder_session_note();
         break;
       case "headers":
-        print recorder_session_headers($lid);
+        $output .= recorder_session_headers($lid);
         break;
       case "list":
       default:
-        print recorder_list_tracks();
+        $output .= recorder_list_tracks();
         break;
     }
   }
+  print theme("page",$output);
 }
 
 function recorder_get_ip() {
   global $REMOTE_ADDR;
-  
   $headers = getallheaders();
   $address = $headers['X-Forwarded-For'];
   
@@ -1003,20 +1015,28 @@
   }
 }
 
-function recorder_help() {
-  $output = "<h3>Recorder Help</h3>";
-  $output .= "<p>With this Drupal module you can record (detect, track and log) specific visitors, hosts, and user agents.</p>";
-  $output .= "<p>The recorder can be used for several purposes, as debugging and solving user problems, monitoring security, tracking trolls and search engine spiders, page and site statistics (samples), and simple usability research.</p>";
-  $output .= "<p>When a new track is added and a target is set (this can be a Drupal User id, Username, IP, Domain, User Agent, URL or content phrase) it will record or log the session when the target is detected.</p>";
-  $output .= "<p>The current configuration enables you to use a maximum of " . variable_get("recorder_max_tracks", 32) . " tracks. Each track has its own filter type and target. These two are set first when adding a new track, and can be changed in its settings later. A track can record several sessions, and sessions can be deleted and moved to other tracks. </p>";
-  $output .= "<p>The targets for the filters 'IPs', 'Domains', 'User agents', 'Referer URLs' and 'Request URLs' only have to match partially. For example if you enter a C-Net as target for an IP filter, it will record all sessions from this C-Net. If you enter '/directory/' as target for the 'Request URL' it will record visitors requesting URLs containing the string '/directory/'. The 'Submissions' filter uses the entered phrase as target for filtering new node content.</p>";
-  $output .= "<p>If 'Set and track cookie' is enabled, the recorder will set a (permanent) cookie when the target is first detected, and next will use this cookie as filter target (does not work with the 'Submissions' filter). Else only the filter target will be used. Use the cookie settings when you want to track a specific visitor.</p>";
-  $output .= "<p>If 'Use only cookie filter' is enabled, the recorder will, after it has set its cookie, only record the visitor with this cookie. Else the filter will also check other visitors for the non cookie target. Use this setting to limit noise from other visitors who match the filter's target.</p>";
-  $output .= "<p>If 'Record details' is enabled, page views will be recorded, and if the check.php script is installed and your theme is modified (or if polder theme is used), it will detect some user agent details (as if Javascript, Java, Flash and images are enabled, and the browser inner size and screen resolution). Else a target is logged only once per session.</p>";
-  $output .= "<p>If 'Timeout sessions' is enabled, sessions will be timed out after a defined period (in current configuration after " . variable_get("recorder_timeout", 1800) . " seconds). Else PHP will be used for sessioning visitors. Use the timeout setting when a agent does not follows PHP's sessioning (or when you have not enabled sessioning for anonymous users), or to combine several sessions into one.</p>";
-  $output .= "The maximum number of tracks can be changed in the site configuration, like the session timeout period, and the filter cookie expire period.";
-  $output .= "<br /><br />";
-  
+function recorder_help($section = "admin/help#recorder") {
+	
+	switch($section) {
+    case 'admin/system/modules#description':
+      $output = t("Record (track/log) specific visitors.");
+      break;
+		case "admin/help#recorder":
+		  $output = "<h3>Recorder Help</h3>";
+		  $output .= "<p>With this Drupal module you can record (detect, track and log) specific visitors, hosts, and user agents.</p>";
+		  $output .= "<p>The recorder can be used for several purposes, as debugging and solving user problems, monitoring security, tracking trolls and search engine spiders, page and site statistics (samples), and simple usability research.</p>";
+		  $output .= "<p>When a new track is added and a target is set (this can be a Drupal User id, Username, IP, Domain, User Agent, URL or content phrase) it will record or log the session when the target is detected.</p>";
+		  $output .= "<p>The current configuration enables you to use a maximum of " . variable_get("recorder_max_tracks", 32) . " tracks. Each track has its own filter type and target. These two are set first when adding a new track, and can be changed in its settings later. A track can record several sessions, and sessions can be deleted and moved to other tracks. </p>";
+		  $output .= "<p>The targets for the filters 'IPs', 'Domains', 'User agents', 'Referer URLs' and 'Request URLs' only have to match partially. For example if you enter a C-Net as target for an IP filter, it will record all sessions from this C-Net. If you enter '/directory/' as target for the 'Request URL' it will record visitors requesting URLs containing the string '/directory/'. The 'Submissions' filter uses the entered phrase as target for filtering new node content.</p>";
+		  $output .= "<p>If 'Set and track cookie' is enabled, the recorder will set a (permanent) cookie when the target is first detected, and next will use this cookie as filter target (does not work with the 'Submissions' filter). Else only the filter target will be used. Use the cookie settings when you want to track a specific visitor.</p>";
+		  $output .= "<p>If 'Use only cookie filter' is enabled, the recorder will, after it has set its cookie, only record the visitor with this cookie. Else the filter will also check other visitors for the non cookie target. Use this setting to limit noise from other visitors who match the filter's target.</p>";
+		  $output .= "<p>If 'Record details' is enabled, page views will be recorded, and if the check.php script is installed and your theme is modified (or if polder theme is used), it will detect some user agent details (as if Javascript, Java, Flash and images are enabled, and the browser inner size and screen resolution). Else a target is logged only once per session.</p>";
+		  $output .= "<p>If 'Timeout sessions' is enabled, sessions will be timed out after a defined period (in current configuration after " . variable_get("recorder_timeout", 1800) . " seconds). Else PHP will be used for sessioning visitors. Use the timeout setting when a agent does not follows PHP's sessioning (or when you have not enabled sessioning for anonymous users), or to combine several sessions into one.</p>";
+		  $output .= "The maximum number of tracks can be changed in the site configuration, like the session timeout period, and the filter cookie expire period.";
+		  $output .= "<br /><br />";
+		  break;
+	}
+	
   return $output;
 }
-?>
+?>
\ No newline at end of file
