[766] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
| 4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
| 5 | // | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | |
---|
| 6 | // +-----------------------------------------------------------------------+ |
---|
| 7 | // | branch : BSF (Best So Far) |
---|
| 8 | // | file : $RCSfile$ |
---|
| 9 | // | last update : $Date: 2006-12-04 22:08:35 +0000 (Mon, 04 Dec 2006) $ |
---|
| 10 | // | last modifier : $Author: rub $ |
---|
| 11 | // | revision : $Revision: 1635 $ |
---|
| 12 | // +-----------------------------------------------------------------------+ |
---|
| 13 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 14 | // | it under the terms of the GNU General Public License as published by | |
---|
| 15 | // | the Free Software Foundation | |
---|
| 16 | // | | |
---|
| 17 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 18 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 19 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 20 | // | General Public License for more details. | |
---|
| 21 | // | | |
---|
| 22 | // | You should have received a copy of the GNU General Public License | |
---|
| 23 | // | along with this program; if not, write to the Free Software | |
---|
| 24 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 25 | // | USA. | |
---|
| 26 | // +-----------------------------------------------------------------------+ |
---|
| 27 | //----------------------------------------------------------- include |
---|
| 28 | define('PHPWG_ROOT_PATH','../../'); |
---|
| 29 | define('IN_ADMIN', true); |
---|
| 30 | include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
[1072] | 31 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
[766] | 32 | include_once( 'phpBarGraph.php' ); |
---|
| 33 | |
---|
[1072] | 34 | // +-----------------------------------------------------------------------+ |
---|
| 35 | // | Check Access and exit when user status is not ok | |
---|
| 36 | // +-----------------------------------------------------------------------+ |
---|
| 37 | check_status(ACCESS_ADMINISTRATOR); |
---|
| 38 | |
---|
[766] | 39 | //------------------------------------------------ variable definition |
---|
| 40 | $outputFormat = "png"; |
---|
[918] | 41 | $legend = $lang['stats_monthly_graph_title']; |
---|
[766] | 42 | $imageHeight = 256; |
---|
| 43 | $imageWidth = 512; |
---|
[775] | 44 | $sql = ' |
---|
| 45 | SELECT DISTINCT COUNT(*) |
---|
| 46 | , DAYOFMONTH(date) |
---|
| 47 | FROM '.HISTORY_TABLE.' |
---|
| 48 | WHERE YEAR(date) = '.$_GET['year'].' |
---|
| 49 | AND MONTH(date) = '.$_GET['month'].' |
---|
| 50 | GROUP BY DATE_FORMAT(date, \'%Y-%m-%d\') DESC |
---|
| 51 | ;'; |
---|
[766] | 52 | |
---|
| 53 | //------------------------------------------------ Image definition |
---|
| 54 | $image = ImageCreate($imageWidth, $imageHeight); |
---|
| 55 | //$image = ImageCreateTrueColor($imageWidth, $imageHeight); |
---|
| 56 | // Fill it with your favorite background color.. |
---|
| 57 | $backgroundColor = ImageColorAllocate($image, 184, 184, 184); |
---|
| 58 | ImageFill($image, 0, 0, $backgroundColor); |
---|
| 59 | $white = ImageColorAllocate($image, 0, 0, 0); |
---|
| 60 | |
---|
| 61 | // Interlace the image.. |
---|
| 62 | Imageinterlace($image, 1); |
---|
| 63 | |
---|
| 64 | // Create a new BarGraph.. |
---|
| 65 | $myBarGraph = new PhpBarGraph; |
---|
| 66 | $myBarGraph->SetX(10); // Set the starting x position |
---|
| 67 | $myBarGraph->SetY(10); // Set the starting y position |
---|
| 68 | $myBarGraph->SetWidth($imageWidth-20); // Set how wide the bargraph will be |
---|
| 69 | $myBarGraph->SetHeight($imageHeight-20); // Set how tall the bargraph will be |
---|
| 70 | $myBarGraph->SetNumOfValueTicks(3); // Set this to zero if you don't want to show any. These are the vertical bars to help see the values. |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | // You can try uncommenting these lines below for different looks. |
---|
| 74 | |
---|
| 75 | // $myBarGraph->SetShowLabels(false); // The default is true. Setting this to false will cause phpBarGraph to not print the labels of each bar. |
---|
| 76 | $myBarGraph->SetShowValues(false); // The default is true. Setting this to false will cause phpBarGraph to not print the values of each bar. |
---|
| 77 | // $myBarGraph->SetBarBorder(false); // The default is true. Setting this to false will cause phpBarGraph to not print the border of each bar. |
---|
| 78 | // $myBarGraph->SetShowFade(false); // The default is true. Setting this to false will cause phpBarGraph to not print each bar as a gradient. |
---|
| 79 | // $myBarGraph->SetShowOuterBox(false); // The default is true. Setting this to false will cause phpBarGraph to not print the outside box. |
---|
| 80 | $myBarGraph->SetBarSpacing(5); // The default is 10. This changes the space inbetween each bar. |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | // Add Values to the bargraph.. |
---|
| 84 | $result = pwg_query($sql) |
---|
| 85 | or die(mysql_errno().": ".mysql_error()."<BR>".$sql); |
---|
| 86 | |
---|
[775] | 87 | $days = array(); |
---|
| 88 | for ($i = 1; $i <= 31; $i++) |
---|
| 89 | { |
---|
| 90 | $days[$i] = 0; |
---|
| 91 | } |
---|
| 92 | |
---|
[766] | 93 | while ($r = mysql_fetch_row($result)) |
---|
| 94 | { |
---|
[775] | 95 | $days[$r[1]]= $r[0]; |
---|
[766] | 96 | } |
---|
| 97 | $o=0; |
---|
| 98 | while (list ($key,$value) = each($days )) |
---|
| 99 | { |
---|
| 100 | $myBarGraph->AddValue($key, $value); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | //$myBarGraph->SetDebug(true); |
---|
| 104 | // Set the colors of the bargraph.. |
---|
| 105 | $myBarGraph->SetStartBarColor("6666ff"); // This is the color on the top of every bar. |
---|
| 106 | $myBarGraph->SetEndBarColor("2222aa"); // This is the color on the bottom of every bar. This is not used when SetShowFade() is set to false. |
---|
| 107 | $myBarGraph->SetLineColor("000000"); // This is the color all the lines and text are printed out with. |
---|
| 108 | |
---|
| 109 | // Print the BarGraph to the image.. |
---|
| 110 | $myBarGraph->DrawBarGraph($image); |
---|
| 111 | Imagestring($image, 2, 2, $imageHeight-14, $legend, $white); |
---|
| 112 | |
---|
| 113 | //------------------------------------------------ Image output |
---|
| 114 | if ($outputFormat == "png") |
---|
| 115 | { |
---|
| 116 | header("Content-type: image/png"); |
---|
| 117 | ImagePNG($image); |
---|
| 118 | } |
---|
[1635] | 119 | else if (in_array($outputFormat, array("jpg", "jpeg"))) |
---|
[766] | 120 | { |
---|
| 121 | header("Content-type: image/jpeg"); |
---|
| 122 | Imagejpeg($image); |
---|
| 123 | } |
---|
| 124 | // Destroy the image. |
---|
| 125 | Imagedestroy($image); |
---|
| 126 | ?> |
---|