source: trunk/client/class/charts.php@ 265

Last change on this file since 265 was 265, checked in by roby, 5 years ago
File size: 5.6 KB
Line 
1<?php
2// charts.php v4.7
3// ------------------------------------------------------------------------
4// Copyright (c) 2003-2007, maani.us
5// ------------------------------------------------------------------------
6// This file is part of "PHP/SWF Charts"
7//
8// PHP/SWF Charts is a shareware. See http://www.maani.us/charts/ for
9// more information.
10// ------------------------------------------------------------------------
11
12//====================================
13function InsertChart( $flash_file, $library_path, $php_source, $width=400, $height=250, $bg_color="666666", $transparent=false, $license=null ){
14
15 $php_source=urlencode($php_source);
16 $library_path=urlencode($library_path);
17 $protocol = (strtolower($_SERVER['HTTPS']) != 'on')? 'http': 'https';
18
19 $html="<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='".$protocol."://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' ";
20 $html.="width='".$width."' height='".$height."' id='charts' />";
21 $u=(strpos ($flash_file,"?")===false)? "?" : ((substr($flash_file, -1)==="&")? "":"&");
22 $html.="<PARAM NAME='movie' VALUE='".$flash_file.$u."library_path=".$library_path."&stage_width=".$width."&stage_height=".$height."&php_source=".$php_source;
23 if($license!=null){$html.="&license=".$license;}
24 $html.="' /> <PARAM NAME='quality' VALUE='high' /><param name='allowScriptAccess' value='sameDomain' /><PARAM NAME='bgcolor' VALUE='#".$bg_color."' /> ";
25 if($transparent){$html.="<PARAM NAME='wmode' VALUE='transparent' /> ";}
26 $html.="<EMBED src='".$flash_file.$u."library_path=".$library_path."&stage_width=".$width."&stage_height=".$height."&php_source=".$php_source;
27 if($license!=null){$html.="&license=".$license;}
28 $html.="' quality='high' bgcolor='#".$bg_color."' width='".$width."' height='".$height."' NAME='charts' allowScriptAccess='sameDomain' swLiveConnect='true' ";
29 if($transparent){$html.="wmode=transparent ";} //use wmode=opaque to prevent printing on black
30 $html.="TYPE='application/x-shockwave-flash' PLUGINSPAGE='".$protocol."://www.macromedia.com/go/getflashplayer'></EMBED></OBJECT>";
31 return $html;
32
33}
34
35//====================================
36function SendChartData( $chart=array() ){
37
38 //header("Content-Type: text/xml");
39 //header("Cache-Control: cache, must-revalidate");
40 //header("Pragma: public");
41
42 $xml="<chart>\r\n";
43 $Keys1= array_keys((array) $chart);
44 for ($i1=0;$i1<count($Keys1);$i1++){
45 if(is_array($chart[$Keys1[$i1]])){
46 $Keys2=array_keys($chart[$Keys1[$i1]]);
47 if(is_array($chart[$Keys1[$i1]][$Keys2[0]])){
48 $xml.="\t<".$Keys1[$i1].">\r\n";
49 for($i2=0;$i2<count($Keys2);$i2++){
50 $Keys3=array_keys((array) $chart[$Keys1[$i1]][$Keys2[$i2]]);
51 switch($Keys1[$i1]){
52 case "chart_data":
53 $xml.="\t\t<row>\r\n";
54 for($i3=0;$i3<count($Keys3);$i3++){
55 switch(true){
56 case ($chart[$Keys1[$i1]][$Keys2[$i2]][$Keys3[$i3]]===null):
57 $xml.="\t\t\t<null/>\r\n";
58 break;
59
60 case ($Keys2[$i2]>0 and $Keys3[$i3]>0):
61 $xml.="\t\t\t<number>".$chart[$Keys1[$i1]][$Keys2[$i2]][$Keys3[$i3]]."</number>\r\n";
62 break;
63
64 default:
65 $xml.="\t\t\t<string>".$chart[$Keys1[$i1]][$Keys2[$i2]][$Keys3[$i3]]."</string>\r\n";
66 break;
67 }
68 }
69 $xml.="\t\t</row>\r\n";
70 break;
71
72 case "chart_value_text":
73 $xml.="\t\t<row>\r\n";
74 $count=0;
75 for($i3=0;$i3<count($Keys3);$i3++){
76 if($chart[$Keys1[$i1]][$Keys2[$i2]][$Keys3[$i3]]===null){$xml.="\t\t\t<null/>\r\n";}
77 else{$xml.="\t\t\t<string>".$chart[$Keys1[$i1]][$Keys2[$i2]][$Keys3[$i3]]."</string>\r\n";}
78 }
79 $xml.="\t\t</row>\r\n";
80 break;
81
82 /*case "link_data_text":
83 $xml.="\t\t<row>\r\n";
84 $count=0;
85 for($i3=0;$i3<count($Keys3);$i3++){
86 if($chart[$Keys1[$i1]][$Keys2[$i2]][$Keys3[$i3]]===null){$xml.="\t\t\t<null/>\r\n";}
87 else{$xml.="\t\t\t<string>".$chart[$Keys1[$i1]][$Keys2[$i2]][$Keys3[$i3]]."</string>\r\n";}
88 }
89 $xml.="\t\t</row>\r\n";
90 break;*/
91
92 case "draw":
93 $text="";
94 $xml.="\t\t<".$chart[$Keys1[$i1]][$Keys2[$i2]]['type'];
95 for($i3=0;$i3<count($Keys3);$i3++){
96 if($Keys3[$i3]!="type"){
97 if($Keys3[$i3]=="text"){$text=$chart[$Keys1[$i1]][$Keys2[$i2]][$Keys3[$i3]];}
98 else{$xml.=" ".$Keys3[$i3]."=\"".$chart[$Keys1[$i1]][$Keys2[$i2]][$Keys3[$i3]]."\"";}
99 }
100 }
101 if($text!=""){$xml.=">".$text."</text>\r\n";}
102 else{$xml.=" />\r\n";}
103 break;
104
105
106 default://link, etc.
107 $xml.="\t\t<value";
108 for($i3=0;$i3<count($Keys3);$i3++){
109 $xml.=" ".$Keys3[$i3]."=\"".$chart[$Keys1[$i1]][$Keys2[$i2]][$Keys3[$i3]]."\"";
110 }
111 $xml.=" />\r\n";
112 break;
113 }
114 }
115 $xml.="\t</".$Keys1[$i1].">\r\n";
116 }else{
117 if($Keys1[$i1]=="chart_type" or $Keys1[$i1]=="series_color" or $Keys1[$i1]=="series_image" or $Keys1[$i1]=="series_explode" or $Keys1[$i1]=="axis_value_text"){
118 $xml.="\t<".$Keys1[$i1].">\r\n";
119 for($i2=0;$i2<count($Keys2);$i2++){
120 if($chart[$Keys1[$i1]][$Keys2[$i2]]===null){$xml.="\t\t<null/>\r\n";}
121 else{$xml.="\t\t<value>".$chart[$Keys1[$i1]][$Keys2[$i2]]."</value>\r\n";}
122 }
123 $xml.="\t</".$Keys1[$i1].">\r\n";
124 }else{//axis_category, etc.
125 $xml.="\t<".$Keys1[$i1];
126 for($i2=0;$i2<count($Keys2);$i2++){
127 $xml.=" ".$Keys2[$i2]."=\"".$chart[$Keys1[$i1]][$Keys2[$i2]]."\"";
128 }
129 $xml.=" />\r\n";
130 }
131 }
132 }else{//chart type, etc.
133 $xml.="\t<".$Keys1[$i1].">".$chart[$Keys1[$i1]]."</".$Keys1[$i1].">\r\n";
134 }
135 }
136 $xml.="</chart>\r\n";
137 echo $xml;
138}
139//====================================
140?>
Note: See TracBrowser for help on using the repository browser.