home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / cgi-bin / graphapplet.pm < prev    next >
Encoding:
Text File  |  2004-05-20  |  5.1 KB  |  130 lines

  1. #!/usr/bin/perl
  2. #-----------------------------------------------------------------------------
  3. # GraphApplet AWStats plugin
  4. # Allow AWStats to replace bar graphs with an Applet (awgraphapplet) that draw
  5. # 3D graphs instead.
  6. #-----------------------------------------------------------------------------
  7. # Perl Required Modules: None
  8. #-----------------------------------------------------------------------------
  9. # $Revision: 1.2 $ - $Author: joker $ - $Date: 2004/05/20 20:38:42 $
  10.  
  11.  
  12. # <-----
  13. # ENTER HERE THE USE COMMAND FOR ALL REQUIRED PERL MODULES
  14. # ----->
  15. use strict;no strict "refs";
  16.  
  17.  
  18.  
  19. #-----------------------------------------------------------------------------
  20. # PLUGIN VARIABLES
  21. #-----------------------------------------------------------------------------
  22. # <-----
  23. # ENTER HERE THE MINIMUM AWSTATS VERSION REQUIRED BY YOUR PLUGIN
  24. # AND THE NAME OF ALL FUNCTIONS THE PLUGIN MANAGE.
  25. my $PluginNeedAWStatsVersion="6.0";
  26. my $PluginHooksFunctions="ShowGraph";
  27. # ----->
  28.  
  29. # <-----
  30. # IF YOUR PLUGIN NEED GLOBAL VARIABLES, THEY MUST BE DECLARED HERE.
  31. use vars qw/
  32. $DirClasses
  33. /;
  34. # ----->
  35.  
  36.  
  37. #-----------------------------------------------------------------------------
  38. # PLUGIN FUNCTION: Init_pluginname
  39. #-----------------------------------------------------------------------------
  40. sub Init_graphapplet {
  41.     my $InitParams=shift;
  42.     my $checkversion=&Check_Plugin_Version($PluginNeedAWStatsVersion);
  43.  
  44.     # <-----
  45.     # ENTER HERE CODE TO DO INIT PLUGIN ACTIONS
  46.     $DirClasses=$InitParams;
  47.     # ----->
  48.  
  49.     return ($checkversion?$checkversion:"$PluginHooksFunctions");
  50. }
  51.  
  52.  
  53. #-------------------------------------------------------
  54. # PLUGIN FUNCTION: ShowGraph_pluginname
  55. # UNIQUE: YES (Only one plugin using this function can be loaded)
  56. # Add the code for call to applet awgraphapplet
  57. # Parameters:    $title $type $showmonthstats \@blocklabel,\@vallabel,\@valcolor,\@valmax,\@valtotal
  58. # Input:        None
  59. # Output:       HTML code for awgraphapplet insertion
  60. # Return:        0 OK, 1 Error
  61. #-------------------------------------------------------
  62. sub ShowGraph_graphapplet() {
  63.     my $title=shift;
  64.     my $type=shift;
  65.     my $showmonthstats=shift;
  66.     my $blocklabel=shift;
  67.     my $vallabel=shift;
  68.     my $valcolor=shift;
  69.     my $valmax=shift;
  70.     my $valtotal=shift;
  71.     my $valaverage=shift;
  72.     my $valdata=shift;
  73.  
  74.     my $graphwidth=780;
  75.     my $graphheight=400;
  76.     my $blockspacing=5;
  77.     my $valspacing=1;
  78.     my $valwidth=5;
  79.     my $barsize=0;
  80.     my $blockfontsize=11;
  81.     if ($type eq 'month')             { $graphwidth=540; $graphheight=160; $blockspacing=8; $valspacing=0; $valwidth=6; $barsize=$BarHeight; $blockfontsize=11; }
  82.     elsif ($type eq 'daysofmonth')  { $graphwidth=640; $graphheight=160; $blockspacing=3; $valspacing=0; $valwidth=4; $barsize=$BarHeight; $blockfontsize=9; }
  83.     elsif ($type eq 'daysofweek')     { $graphwidth=300; $graphheight=160; $blockspacing=10; $valspacing=0; $valwidth=6; $barsize=$BarHeight; $blockfontsize=10; }
  84.     elsif ($type eq 'hours')         { $graphwidth=600; $graphheight=160; $blockspacing=4; $valspacing=0; $valwidth=6; $barsize=$BarHeight; $blockfontsize=11; }
  85.     else { error("Unknown type parameter in ShowGraph_graphapplet function"); }
  86.  
  87. #    print "<applet code=\"AWGraphApplet.class\" codebase=\"/classes\" width=\"$graphwidth\" height=\"$graphheight\">\n";
  88.     print "<applet name=\"$type\" archive=\"awgraphapplet.jar\" code=\"AWGraphApplet.class\" codebase=\"".($DirClasses||"/")."\" width=\"$graphwidth\" height=\"$graphheight\" alt= \"Your browser does not support Java correctly. Change browser or disable AWStats graphapplet plugin.\">\n";
  89. print <<EOF;
  90. <param name="title" value="$title" />
  91. <param name="special" value="$type" />
  92. <param name="orientation" value="vertical" />
  93. <param name="barsize" value="$barsize" />
  94. <param name="background_color" value="$color_Background" />
  95. <param name="border_color" value="$color_Background" />
  96. <param name="special_color" value="$color_weekend" />
  97. EOF
  98.     print "<param name=\"nbblocks\" value=\"".(scalar @$blocklabel)."\" />\n";
  99.     print "<param name=\"b_fontsize\" value=\"$blockfontsize\" />\n";
  100.     foreach my $i (1..(scalar @$blocklabel)) {
  101.         print "<param name=\"b${i}_label\" value=\"".@$blocklabel[$i-1]."\" />\n";
  102.     }
  103.     print "<param name=\"nbvalues\" value=\"".(scalar @$vallabel)."\" />\n";
  104.     foreach my $i (1..(scalar @$vallabel)) {
  105.         print "<param name=\"v${i}_label\" value=\"".@$vallabel[$i-1]."\" />\n";
  106.         print "<param name=\"v${i}_color\" value=\"".@$valcolor[$i-1]."\" />\n";
  107.         print "<param name=\"v${i}_max\" value=\"".@$valmax[$i-1]."\" />\n";
  108.         print "<param name=\"v${i}_total\" value=\"".@$valtotal[$i-1]."\" />\n";
  109.         print "<param name=\"v${i}_average\" value=\"".@$valaverage[$i-1]."\" />\n";
  110.     }
  111. print <<EOF;
  112. <param name="blockSpacing" value="$blockspacing" />
  113. <param name="valSpacing" value="$valspacing" />
  114. <param name="valwidth" value="$valwidth" />
  115. EOF
  116.     foreach my $j (1..(scalar @$blocklabel)) {
  117.         my $b='';
  118.         foreach my $i (0..(scalar @$vallabel)-1) { $b.=@$valdata[($j-1)*(scalar @$vallabel)+$i]." "; }
  119.         $b=~s/\s$//;
  120.         print "<param name=\"b${j}\" value=\"$b\" />\n";
  121.     }
  122.     print "</applet><br />\n";
  123.  
  124.     return 0;
  125. }
  126.  
  127.  
  128.  
  129. 1;    # Do not remove this line
  130.