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

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