############################################################## # Top Ten by Gender # by JPDeni and many other contributors # written 23 Jun 2000 last update 06/26/2000 ############################################################## # # The mod was written to create "Top Ten" lists by gender, but # it can refer to any field where there is a limited (not more # than 2 or 3) number of predefined choices. In other words, # this should only be used for a field that uses radio buttons # or a very short select list for field entry. ############################################################## # Create subdirectories in your $counter_dir, each one named # the same as one of the options in your field. Be sure that # they are the actual values that will be added to the database. # # Change the permission of these subdirectories to 777. ############################################################### # default.cfg #------------------------------------------------------------- # Add the following to your .cfg file: ############################################################### ### In the # File and URL's section add: # Full Path and File name of the record view count directory. $counter_dir = $db_script_path . "/temp"; ### After $auth_logoff = "http://www.yourdomain.com"; add: # How many seconds to remove the old ip addresses for record view count? # 3600 - One Hour (Recomended) $ipupdate = "3600"; ### Added for time interval # The options that are in your radio or select field for which # you would like to compute a top ten, separated by commas $top_ten_values = 'M,F'; # The name of the field for which you would like to compute the # top ten lists $top_ten_field = 'Sex'; ############################################################### # html.pl # #-------------------------------------------------------------# # In 'sub html_record' (or 'sub html_record_long', if you're # # using the short/long display mod): # ############################################################### ### After my (%rec) = @_; ### add &top10($rec{$db_key},$rec{$top_ten_field}); ############################################################### # Add the following subroutine sub html_topten { #------------------------------------------------------------- @top_ten_values_array = split (/,/,$top_ten_values); &html_print_headers; print qq| $html_title: top Ten Records. header html code goes here |; print "
"; for ($j=0;$j<=$#top_ten_values_array ;++$j) { ## fix undef @files; undef %count; undef @top_ten; undef $toparray; undef $toplist; opendir (TEMPDIR, "$counter_dir/$top_ten_values_array[$j]"); @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/$j/$file"); $count{$file} = int( ); close COUNTER; } foreach $key (sort {$count{$b} <=> $count{$a} } keys %count) { push (@top_ten,$key); } for ($i=0;$i<10 ;$i++) { $toparray .= "$top_ten[$i],"; } chop $toparray; print ""; } print "
"; foreach my $toplist (split(/,/,$toparray)) { &html_record(&get_record($toplist)); ## See below if you're using short/long display mod } print "
"; print qq|footer html code goes here|; &html_footer; print qq||; } #### For short/long display, use the following, and change $rec{'FieldName'} to match your database. %rec = (&get_record($toplist)); print qq| $rec{'FieldName'}
|; ### In 'sub html_footer', add print qq!|Top Ten ! if ($per_view); ############################################################### # db.cgi # #-------------------------------------------------------------# # Delete (or comment out) this line in sub get_record: # ($restricted = 1) if ($auth_modify_own and !$per_admin); ### In '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; } } ############################################################### # Add the following subroutine to db.cgi sub top10 { #----------------------------------------------------------- my ($key) = $_[0]; my ($gender) = $_[1]; $key =~ s///g; $gender =~ s///g; $iptime = time(); $remote = $ENV{'REMOTE_ADDR'}; $cheat = 0; if (-e "$counter_dir/iplog.txt") { open (iplog, "+<$counter_dir/iplog.txt"); if ($db_use_flock) { flock(iplog, 2); } @ipdata = ; seek (iplog, 0, 0); truncate (iplog,0); foreach $log (@ipdata) { @ips = split(/\|/, $log); $iptotal = $iptime - $ips[1]; if (($ips[0] == $remote) && ($ips[2] == $key) && ($iptotal < $ipupdate)) { $cheat = 1; } if ($iptotal < $ipupdate) { print iplog "$ips[0]|$ips[1]|$ips[2]\n"; } } unless ($cheat) { print iplog "$remote|$iptime|$db_key\n"; } close (iplog); } else { open(newip, ">$counter_dir/iplog.txt"); print newip "$remote|$iptime|$key\n"; close (newip); } if (!$cheat) { open (COUNT, "$counter_dir/$gender/$key"); if ($db_use_flock) { flock(COUNT, 2); } $countup = ; $countup++; close COUNT; open (COUNT, ">$counter_dir/$gender/$key"); if ($db_use_flock) { flock(COUNT, 2); } print COUNT $countup; close COUNT; } else { open (COUNT, "<$counter_dir/$gender/$key"); if ($db_use_flock) { flock(COUNT, 2); } $countup = ; close COUNT; } } =================================== # Top Ten by Gender ========================== Okay. I have written a mod file that should be general enough for anyone to use for anything they want. Please give it a try. It's at http://www.jpdeni.com/dbman/Mods/top_ten_gen.txt. If it works for you, I'll post it in the Resource Center. http://www.jpdeni.com/dbman/Mods/top_ten_gen.txt ========== 86392 johnny's top 10 ... modified to use with different applications removed much of the thread: this is like a new topic or question anyway :) ------------------------------------------------------------- Subject Re: Top Ten by Gender for Johnsonny Posted by ozozgur (Member) Posted on 23-Jun-00 07:30 AM -------------------------------------------------------------------------------------------- Question: I would like to use the same mod. I tried to use the one you sent to this thread but didn't work, perhaps because I use radio fields? I'm using radio fields and the values are 'Erkek' and 'Kadin'. I'll be very happy JP if you find time to help me with that. btw, how do you manage to do that? I mean answering so many people and solving so many problems so quickly? ---------------------------------------------------------- Response: The reason this doesn't work for you is that you have different values for the gender field. Let's see if I can work it out. Okay. I have written a mod file that should be general enough for anyone to use for anything they want. Please give it a try. It's at http://www.jpdeni.com/dbman/Mods/top_ten_gen.txt. If it works for you, I'll post it in the Resource Center. --------------------------------------------------------- Question: Thanks a lot Carol!!! It worked, with one small change: in sub html_topten, change for ($j=1;$j<=$#top_ten_values_array ;++$j) #to for ($j=0;$j<=$#top_ten_values_array ;++$j) I tried to see the problem myself (kind of training :-) ), so it took a day to find out that it was "j=1". I'm sure you would solve the problem in 10 sec.? But, you know, it's good to encourage rookies. So you can reply me lying "Goush! I would never solve that problem without your help! What a talent you have! Go on Ozgur!" lol Ok, enough nonsense... ---------------------------------------------------------- Response: Goush! I would never solve that problem without your help! What a talent you have! Go on Ozgur! You are absolutely right, though. I'll go change that right now.....There. All better now. Thanks much for being willing to test it out. I rely on people to be my test subjects because creating databases just to test the mods can take longer than writing them. I'm really glad it worked for you. =========== ############################################################## # Top Ten by Gender # by JPDeni and many other contributors # written 23 Jun 2000 ############################################################## # # The mod was written to create "Top Ten" lists by gender, but # it can refer to any field where there is a limited (not more # than 2 or 3) number of predefined choices. In other words, # this should only be used for a field that uses radio buttons # or a very short select list for field entry. ############################################################## # Create subdirectories in your $counter_dir, each one named # the same as one of the options in your field. Be sure that # they are the actual values that will be added to the database. # # Change the permission of these subdirectories to 777. ############################################################### # default.cfg #------------------------------------------------------------- # Add the following to your .cfg file: ############################################################### ### In the # File and URL's section add: # Full Path and File name of the record view count directory. $counter_dir = $db_script_path . "/temp"; ### After $auth_logoff = "http://www.yourdomain.com"; add: # How many seconds to remove the old ip addresses for record view count? # 3600 - One Hour (Recomended) $ipupdate = "3600"; ### Added for time interval # The options that are in your radio or select field for which # you would like to compute a top ten, separated by commas $top_ten_values = 'M,F'; # The name of the field for which you would like to compute the # top ten lists $top_ten_field = 'Sex'; ############################################################### # html.pl # #-------------------------------------------------------------# # In 'sub html_record' (or 'sub html_record_long', if you're # # using the short/long display mod): # ############################################################### ### After my (%rec) = @_; ### add &top10($rec{$db_key},$rec{$top_ten_field}); ############################################################### # Add the following subroutine sub html_topten { #------------------------------------------------------------- @top_ten_values_array = split (/,/,$top_ten_values); &html_print_headers; print qq| $html_title: top Ten Records. header html code goes here |; print ""; for ($j=1;$j<=$#top_ten_values_array ;++$j) { undef @files; undef %count; undef @top_ten; undef $toparray; undef $toplist; opendir (TEMPDIR, "$counter_dir/$top_ten_values_array[$j]"); @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/$j/$file"); $count{$file} = int( ); close COUNTER; } foreach $key (sort {$count{$b} <=> $count{$a} } keys %count) { push (@top_ten,$key); } for ($i=0;$i<10 ;$i++) { $toparray .= "$top_ten[$i],"; } chop $toparray; print ""; } print "
"; foreach my $toplist (split(/,/,$toparray)) { &html_record(&get_record($toplist)); ## See below if you're using short/long display mod } print "
"; print qq|footer html code goes here|; &html_footer; print qq||; } #### For short/long display, use the following, and change $rec{'FieldName'} to match your database. %rec = (&get_record($toplist)); print qq| $rec{'FieldName'}
|; ### In 'sub html_footer', add print qq!|Top Ten ! if ($per_view); ############################################################### # db.cgi # #-------------------------------------------------------------# # Delete (or comment out) this line in sub get_record: # ($restricted = 1) if ($auth_modify_own and !$per_admin); ### In '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; } } ############################################################### # Add the following subroutine to db.cgi sub top10 { #----------------------------------------------------------- my ($key) = $_[0]; my ($gender) = $_[1]; $key =~ s///g; $gender =~ s///g; $iptime = time(); $remote = $ENV{'REMOTE_ADDR'}; $cheat = 0; if (-e "$counter_dir/iplog.txt") { open (iplog, "+<$counter_dir/iplog.txt"); if ($db_use_flock) { flock(iplog, 2); } @ipdata = ; seek (iplog, 0, 0); truncate (iplog,0); foreach $log (@ipdata) { @ips = split(/\|/, $log); $iptotal = $iptime - $ips[1]; if (($ips[0] == $remote) && ($ips[2] == $key) && ($iptotal < $ipupdate)) { $cheat = 1; } if ($iptotal < $ipupdate) { print iplog "$ips[0]|$ips[1]|$ips[2]\n"; } } unless ($cheat) { print iplog "$remote|$iptime|$db_key\n"; } close (iplog); } else { open(newip, ">$counter_dir/iplog.txt"); print newip "$remote|$iptime|$key\n"; close (newip); } if (!$cheat) { open (COUNT, "$counter_dir/$gender/$key"); if ($db_use_flock) { flock(COUNT, 2); } $countup = ; $countup++; close COUNT; open (COUNT, ">$counter_dir/$gender/$key"); if ($db_use_flock) { flock(COUNT, 2); } print COUNT $countup; close COUNT; } else { open (COUNT, "<$counter_dir/$gender/$key"); if ($db_use_flock) { flock(COUNT, 2); } $countup = ; close COUNT; } } =================