<?PHP
//
// PHPMyServer - A PHP System Information Script - Old project name was PHPMyStats
// http://www.phpmyserver.com/
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// $Id: index.php/index.php4.php/index.php5.php/etc ,v 2.6 13-08-2005 16:30 precision Exp $
//
// Date in $Id is as DD-MM-YY
//PHPMyServer - Lite Client v2.6
//Build version:
// split version at the DOT, before the DOT is the CORE version, AFTER the DOT is de RELEASE
//Every new release will get an higher number, so when i released version 2 of the script for the 126523st time, its version v2.126523
//Copyright 2004-2005 by KingOfDos Intra/Extra/Internet WebServices
//http://www.phpmyserver.com
//http://www.kingofdos.com
include('includes/functions.php4.php');
function GeneratePie($width,$height,$tabel_colors,$tabel_values,$left_pos_dia,$top_pos_dia,$diameterx,$diametery,$shadow3d=1){
//
/*
$width=300;
$height=80;
$tabel_colors = array('#A9A9A9','#505050');//colors
$tabel_values = array(100,500);//value by the color
$left_pos_dia = 60;//left position diagram
$top_pos_dia = 40;//top position diagram
$diameterx = 100;//diameter width diagram
$diametery = 50;//diameter height diagram
$shadow3d = 1;//3d shadow colors
*/
$value_total = array_sum($tabel_values); //total
$value_n_total = "";
//make blanc image
$im = ImageCreate ($width, $height);
//set basic colors
$white = ImageColorAllocate ($im, 255, 255, 255);
$black = ImageColorAllocate ($im, 0, 0, 0);
$gray = ImageColorAllocate ($im, 32, 32, 32);
//begin draw
if(empty($shadow3d) or !function_exists('imagefilledarc')){//and $type == "0"
ImageArc($im, $left_pos_dia, $top_pos_dia+($diametery/10), $diameterx, $diametery, 0, 360, $gray); //make 3d
imagefilltoborder($im, $left_pos_dia, $top_pos_dia+10, $gray, $gray); //fill 3d
}
//$order=0;
//sort data and make pie of data
//if(empty($order)){
// array_multisort ($tabel_names, SORT_ASC, $tabel_values, $tabel_colors,$tabel_textcolors);
array_multisort (array(1,2), SORT_DESC, $tabel_values, $tabel_colors);
//}
//else{
// array_multisort ($tabel_values, SORT_DESC,$tabel_names,$tabel_colors,$tabel_textcolors);
//}
//reset($tabel_values);
if(!empty($shadow3d) and function_exists('imagefilledarc')){//and $type == "0"
for($i=0;$i<count($tabel_values);$i++){
if(!empty($value_n_total)){
$graden = @(GraphCalcSizeToBytes($tabel_values[$i])/$value_n_total)*360; //degrees
}
else{
$graden = @($tabel_values[$i]/$value_total)*360; //degrees
}
if(!empty($goud)){
$Start = $goud;
$End = $goud+$graden;
}
else{
$Start = 270;
$End = 270+$graden;
$goud = 270;
}
//echo $Start."-".$End."<br/>\n";
$shadows = array();
$dif=100;
foreach ($tabel_colors as $curColor) {
$curColorArr = Color($curColor);
$thisShadow = "";
foreach($curColorArr as $curShadow) {
if ($curShadow-$dif<=0)
$curShadow = 0;
else
$curShadow=$curShadow-$dif;
if (strlen($thisShadow)<=0)
$thisShadow = $curShadow;
else
$thisShadow .= ":".$curShadow;
}
$shadows[] = $thisShadow;
}
for ($k = ($top_pos_dia+($diametery/15)); $k > $top_pos_dia; $k--){
$shaarray = Color($shadows[$i]);
imagefilledarc($im, $left_pos_dia, $k, $diameterx, $diametery, $Start, $End, ImageColorAllocate ($im, $shaarray[0], $shaarray[1], $shaarray[2]), IMG_ARC_PIE);
}
$goud = $goud+$graden;
}
$goud = 0;
$Start =0;
$End = 0;
}
for($i=0;$i<count($tabel_values);$i++){
//get color
$piearray = Color($tabel_colors[$i]);
//$tcarray = Color($tabel_textcolors[$i]);
//draw index
if(empty($posoud)){
$posoud=0;
}
//caculate degrees
if(!empty($value_n_total)){
$procent = @round((GraphCalcSizeToBytes($tabel_values[$i])/$value_n_total)*100,2); //percents
$graden = @(GraphCalcSizeToBytes($tabel_values[$i])/$value_n_total)*360; //degrees
}
else{
$procent = @round(($tabel_values[$i]/$value_total)*100,2); //percents
$graden = $procent/100*360; //degrees
}
//draw pie-part
if(function_exists('imagefilledarc')){
if(!empty($goud)){
$Start = $goud;
$End = $goud+$graden;
}
else{
$Start = 270;
$End = 270+$graden;
$goud = 270;
}
imagefilledarc ($im, $left_pos_dia, $top_pos_dia, $diameterx, $diametery, $Start, $End, ImageColorAllocate ($im, $piearray[0], $piearray[1], $piearray[2]), IMG_ARC_PIE);
if(empty($shadow3d)){
imagefilledarc ($im, $left_pos_dia, $top_pos_dia, $diameterx, $diametery, $Start, $End, $black, IMG_ARC_NOFILL);
$x = $left_pos_dia + (cos(deg2rad($Start))*($diameterx/2));
$y = $top_pos_dia + (sin(deg2rad($Start))*($diameterx/4));
imageline($im, $x, $y, $left_pos_dia, $top_pos_dia, $black);
$x = $left_pos_dia + (cos(deg2rad($End))*($diameterx/2));
$y = $top_pos_dia + (sin(deg2rad($End))*($diameterx/4));
imageline($im, $x, $y, $left_pos_dia, $top_pos_dia, $black);
}
}
else{
if($procent>0){
if(!empty($goud)){
$Start = 640-$goud-$graden;
$End = 640-$goud;
}
else{
$Start = 640-$graden;
$End = 640;
$goud = 0;
}
imagearc($im, $left_pos_dia, $top_pos_dia, $diameterx, $diametery, $Start, $End, $black);
$x = $left_pos_dia + (cos(deg2rad($Start))*($diameterx/2));
$y = $top_pos_dia + (sin(deg2rad($Start))*($diametery/2));
imageline($im, $x, $y, $left_pos_dia, $top_pos_dia, $black);
$x = $left_pos_dia + (cos(deg2rad($End))*($diameterx/2));
$y = $top_pos_dia + (sin(deg2rad($End))*($diametery/2));
imageline($im, $x, $y, $left_pos_dia, $top_pos_dia, $black);
$x = $left_pos_dia + (cos(deg2rad(($End+$Start)/2))*(($diameterx-4)/2));
$y = $top_pos_dia + (sin(deg2rad(($End+$Start)/2))*(($diametery-4)/2));
//echo "$Start - $End<br/>";
imagefilltoborder($im, $x, $y, $black, ImageColorAllocate ($im, $piearray[0], $piearray[1], $piearray[2]));
imagesetpixel ( $im, $x, $y, ImageColorAllocate ($im, $piearray[0], $piearray[1], $piearray[2]));
imagesetpixel ( $im, $x-1, $y, ImageColorAllocate ($im, $piearray[0], $piearray[1], $piearray[2]));
imagesetpixel ( $im, $x+1, $y, ImageColorAllocate ($im, $piearray[0], $piearray[1], $piearray[2]));
imagesetpixel ( $im, $x, $y+1, ImageColorAllocate ($im, $piearray[0], $piearray[1], $piearray[2]));
imagesetpixel ( $im, $x, $y-1, ImageColorAllocate ($im, $piearray[0], $piearray[1], $piearray[2]));
}
}
$goud = $goud+$graden; //rember for next pie-part
$posoud++;
}
//make image transparant
imagecolortransparent($im, $white);
header("Content-type: image/png");
Header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
Header("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
Header("Pragma: no-cache");
//Header("Content-Size: ".strlen($im));
imagepng ($im);
imageDestroy ($im);
//exit;exit;exit;
}
function Color($color){
if(substr($color,0,1)=="#"){
$color = eregi_replace("#","",$color);
$red = hexdec(substr($color,0,2));
$green = hexdec(substr($color,2,2));
$blue = hexdec(substr($color,4,2));
}
else{
$color = explode(":", $color);
$red = $color[0];
$green = $color[1];
$blue = $color[2];
}
return(array($red,$green,$blue));
}
//echo gettype($_GET['values']);exit;
//if (isset($_GET)) print_r($_GET);
if (
isset($_GET) AND
isset($_GET['width']) AND is_numeric($_GET['width']) AND match_secure($_GET['width']) AND
isset($_GET['height']) AND is_numeric($_GET['height']) AND match_secure($_GET['height']) AND
isset($_GET['colors']) AND is_string($_GET['colors']) AND match_secure($_GET['colors']) AND
isset($_GET['values']) AND is_string($_GET['values']) AND match_secure($_GET['values']) AND
isset($_GET['pos_left']) AND is_numeric($_GET['pos_left']) AND match_secure($_GET['pos_left']) AND
isset($_GET['pos_top']) AND is_numeric($_GET['pos_top']) AND match_secure($_GET['pos_top']) AND
isset($_GET['dia_x']) AND is_numeric($_GET['dia_x']) AND match_secure($_GET['dia_x']) AND
isset($_GET['dia_y']) AND is_numeric($_GET['dia_y']) AND match_secure($_GET['dia_y']) AND
isset($_GET['shadow']) AND is_numeric($_GET['shadow']) AND match_secure($_GET['shadow'])
) {
$width=$_GET['width'];
$height=$_GET['height'];
if ($tmp_col = explode(':',$_GET['colors']) AND is_array($tmp_col)) {
//print_r($tmp_col);
$table_colors = array();
foreach ($tmp_col as $k => $v){
$table_colors[] = '#'.$v;
//echo $v.'<br>';
}
} else
die('No valid colors');
if ($tmp_val = explode(':',$_GET['values']) AND is_array($tmp_val))
$table_values = $tmp_val;
else
die('No valid values');
//$tabel_colors = array('#A9A9A9','#505050');//colors
//$tabel_values = array(100,500);//value by the color
$left_pos_dia = $_GET['pos_left'];//left position diagram
$top_pos_dia = $_GET['pos_top'];//top position diagram
$diameterx = $_GET['dia_x'];//diameter width diagram
$diametery = $_GET['dia_y'];//diameter height diagram
$shadow3d = (isset($_GET['shadow'])) ? $_GET['shadow'] : 1;//3d shadow colors
GeneratePie($width,$height,$table_colors,$table_values,$left_pos_dia,$top_pos_dia,$diameterx,$diametery,$shadow3d);
//exit;
} else {
echo 'graph_pie.php?width=110&height=60&colors=A9A9A9:505050&values=750:500&pos_left=55&pos_top=30&dia_x=105&dia_y=50&shadow=1';
}
?>