###################################################################### ### Hit Counter and Top Ten Hits List ### by leisurelee and JPDeni ### Last modified: 21 Apr 2000 ###################################################################### # This mod will allow you to keep track of the number of times a # record is accessed. You can then generate a top ten list of the # most accessed records. # To set up your record counter, create a directory within your # DBMan directory. Name the new directory "temp". Set the permissions # on the directory to 777 (-rwxrwxrwx) # Add the following to your .cfg file: $counter_dir = $db_script_path . "/temp"; # In sub html_record (or sub html_record_long, if you're using the # short/long display mod), after my (%rec) = @_; # add $count_up= "$counter_dir/$rec{$db_key}"; open (COUNT, "<$count_up"); $countup = ; close COUNT; open (COUNT, ">$count_up"); $countup2 = $countup + 1; print COUNT $countup2; close COUNT; # When you are defining the structure of the page layout, wherever # you want to show the number of hits made to the record, simply # reference $countup2. ##################################################################### # To include link to a top ten list of the most visited records, add # the following subroutine to the html.pl file: # -----beginning of subroutine-------------------- sub html_topten { opendir (TEMPDIR, "$counter_dir") or &cgierr("unable to open directory $counter_dir. Reason: $!"); @files = readdir(TEMPDIR); # Read in list of files in directory.. closedir (TEMPDIR); FILE: foreach $file (@files) { next if ($file =~ /^\./); # Skip "." and ".." entries.. next if ($file =~ /^index/); # Skip index.htm type files.. open (COUNTER, "<$counter_dir/$file") or &cgierr("unable to open file $counter_dir/$file. Reason: $!"); $count{$file} = int( ); close COUNTER; } foreach $key (sort {$count{$b} <=> $count{$a} } keys %count) { push (@top_ten,$key); } &html_print_headers; print qq| $html_title: Top Ten Records. header html code goes here |; for ($i=0;$i<10 ;$i++) { $toparray .= "$top_ten[$i],"; } chop $toparray; foreach my $toplist (split(/,/,$toparray)) { &html_record(&get_record($toplist)); } print qq|footer html code goes here|; &html_footer; print qq||; } # -------End of subroutine----------------------------- # If you're using the short/long display mod, instead of &html_record(&get_record($toplist)); # use %rec = (&get_record($toplist)); print qq| $rec{'FieldName'} |; # Change $rec{'FieldName'} to match your database. # Everyone will also need to delete (or comment out) the following # line in sub get_record in the db.cgi script: ($restricted = 1) if ($auth_modify_own and !$per_admin); # In html.pl, sub html_footer, add print qq!|Top Ten ! if ($per_view); # In db.cgi, sub main, after if ($in{'add_form'}) { if ($per_add) { &html_add_form; } else { &html_unauth; } } # add elsif ($in{'topten'}) { if ($per_view) { &html_topten; } else { &html_unauth; } }