| [ PHPXref.com ] | [ Generated: Sun Jul 20 19:34:47 2008 ] | [ phpDenora 1.0.1 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: piegraphs.php 187 2006-05-27 17:40:50Z Hal9000 $ 3 4 define( '_VALID_PARENT', 1 ); 5 6 ini_set('display_errors','on'); 7 error_reporting(E_ALL); 8 9 require ("../phpdenora.cfg.php"); # Load phpDenora configuration file 10 require("ircds/$denora_server_type.php"); # Load ircd definition file 11 12 if ($pd_debug < 2) 13 { 14 ini_set('display_errors','off'); 15 error_reporting(E_ERROR); 16 } 17 18 require_once ("sql.php"); # Load SQL library 19 20 // Load the appropriate JPGraph library based on PHP version 21 $phpver = phpversion(); 22 if (version_compare("5.0", $phpver, "<") == 1) { 23 require_once ("../libs/jpgraph/php5/jpgraph.php"); 24 require_once ("../libs/jpgraph/php5/jpgraph_pie.php"); 25 require_once ("../libs/jpgraph/php5/jpgraph_pie3d.php"); 26 } 27 else { 28 require_once ("../libs/jpgraph/php4/jpgraph.php"); 29 require_once ("../libs/jpgraph/php4/jpgraph_pie.php"); 30 require_once ("../libs/jpgraph/php4/jpgraph_pie3d.php"); 31 } 32 33 // Compensate missing configuration parameters 34 if (!isset($np_db_host)) { $np_db_host = "localhost"; } 35 if (!isset($np_db_port)) { $np_db_port = "3306"; } 36 if (!isset($pd_style)) { $pd_style = "modern"; } 37 if (!isset($pd_lang)) { $pd_lang = "en"; } 38 if (!isset($denora_user_db)) { $denora_user_db = "user"; } 39 if (!isset($denora_chan_db)) { $denora_chan_db = "chan"; } 40 if (!isset($denora_ison_db)) { $denora_ison_db = "ison"; } 41 if (!isset($denora_tld_db)) { $denora_tld_db = "tld"; } 42 43 // Load the appropriate theme file 44 $theme = isset($_GET['theme']) ? htmlspecialchars($_GET['theme']) : $pd_style; 45 $themefile = "../themes/".$theme."/theme.php"; 46 if (file_exists($themefile)) 47 { 48 require ($themefile); 49 } 50 else 51 { 52 $theme = "modern"; 53 require ( '../themes/modern/theme.php' ); 54 } 55 56 // Load appropriate language file 57 $lang = isset($_GET['lang']) ? htmlspecialchars($_GET['lang']) : $pd_lang; 58 $langfile = "../lang/".$lang."/lang.php"; 59 if (file_exists($langfile)) 60 { 61 include ($langfile); 62 } 63 else { 64 $lang = "en"; 65 include ( '../lang/en/lang.php' ); 66 } 67 68 // Set the language encoding 69 if (!isset($charset)) { $charset = "iso-8859-1"; } 70 ini_set('default_charset',$charset); 71 72 // Get the needed variables from URL 73 $mode = isset($_GET['mode']) ? htmlspecialchars($_GET['mode']) : NULL; 74 $chan = isset($_GET['chan']) ? html_entity_decode(stripslashes($_GET['chan'])) : "global"; 75 if ($chan != "global" && $chan{0} != "#") { $chan = "#" . $chan; } 76 77 // Some variables initialization 78 $data = array(); $labels = array(); 79 $np_db_maxd = 10; $i=0; $buf=0; $sum=0; 80 81 // Do the appropriate query 82 if ($mode == "version" && $chan == "global") { 83 $a1 = ""; $a2 = ""; 84 if ($ircd['services_protection'] == 1) { 85 $a1 = "AND ".$ircd['services_protection_mode']."=\"N\""; 86 $a2 = "AND ".$denora_user_db.".".$ircd['services_protection_mode']."=\"N\" "; 87 } 88 $q = sql_query("SELECT COUNT(nickid) FROM ".$denora_user_db." WHERE online=\"Y\" ".$a1.";"); 89 $sum = sql_result($q,0); 90 $q = sql_query("SELECT ".$denora_user_db.".ctcpversion, COUNT(*) AS version_count ". 91 "FROM ".$denora_user_db." ". 92 "WHERE ".$denora_user_db.".online=\"Y\" ". 93 $a2. 94 "GROUP by ".$denora_user_db.".ctcpversion ". 95 "ORDER BY version_count DESC;"); 96 $filename = "pie-version-global"; 97 } 98 elseif ($mode == "version" && $chan != "global") { 99 $a1 = ($ircd['chanhide'] == 1 && $pd_hidesecret == true) ? "AND ".$denora_user_db.".".$ircd['chanhide_mode']."=\"N\" " : NULL; 100 $sum = sql_query_num_rows("SELECT ".$denora_user_db.".nickid FROM ".$denora_user_db.", ".$denora_chan_db.", ".$denora_ison_db." ". 101 "WHERE ".$denora_chan_db.".chanid = ".$denora_ison_db.".chanid ". 102 "AND ".$denora_user_db.".nickid = ".$denora_ison_db.".nickid ". 103 "AND ".$denora_user_db.".online=\"Y\" ". 104 $a1. 105 "AND channel=LOWER(\"".sql_escape_string($chan)."\");"); 106 $q = sql_query("SELECT ".$denora_user_db.".ctcpversion, COUNT(*) AS version_count ". 107 "FROM ".$denora_user_db.", ".$denora_chan_db.", ".$denora_ison_db." ". 108 "WHERE ".$denora_user_db.".nickid=".$denora_ison_db.".nickid ". 109 "AND ".$denora_ison_db.".chanid=".$denora_chan_db.".chanid ". 110 "AND ".$denora_chan_db.".channel=LOWER(\"".sql_escape_string($chan)."\") ". 111 "AND ".$denora_user_db.".online=\"Y\" ". 112 $a1. 113 "GROUP by ".$denora_user_db.".ctcpversion ". 114 "ORDER BY version_count DESC;"); 115 $filename = "pie-version-$chan"; 116 } 117 elseif ($mode == "country" && $chan == "global") { 118 $q = sql_query("SELECT SUM(".$denora_tld_db.".count) FROM ".$denora_tld_db." WHERE ".$denora_tld_db.".count != 0;"); 119 $sum = sql_result($q,0); 120 $q = sql_query("SELECT ".$denora_tld_db.".country, ".$denora_tld_db.".count ". 121 "FROM ".$denora_tld_db." WHERE ".$denora_tld_db.".count != 0 ". 122 "ORDER BY ".$denora_tld_db.".count DESC;"); 123 $filename = "pie-country-global"; 124 } 125 elseif ($mode == "country" && $chan != "global") { 126 $a1 = ($ircd['chanhide'] == 1 && $pd_hidesecret == true) ? "AND ".$denora_user_db.".".$ircd['chanhide_mode']."=\"N\" " : NULL; 127 $sum = sql_query_num_rows("SELECT ".$denora_user_db.".nickid FROM ".$denora_chan_db.", ".$denora_ison_db.", ".$denora_user_db." ". 128 "WHERE ".$denora_chan_db.".chanid = ".$denora_ison_db.".chanid ". 129 "AND ".$denora_ison_db.".nickid = ".$denora_user_db.".nickid ". 130 "AND channel=LOWER(\"".sql_escape_string($chan)."\") ". 131 "AND ".$denora_user_db.".online=\"Y\" ". 132 $a1.";"); 133 $q = sql_query("SELECT ".$denora_user_db.".country, COUNT(*) AS country_count ". 134 "FROM ".$denora_user_db.", ".$denora_chan_db.", ".$denora_ison_db." ". 135 "WHERE ".$denora_user_db.".nickid=".$denora_ison_db.".nickid ". 136 "AND ".$denora_ison_db.".chanid=".$denora_chan_db.".chanid ". 137 "AND ".$denora_chan_db.".channel=LOWER(\"".sql_escape_string($chan)."\") ". 138 "AND ".$denora_user_db.".online=\"Y\" ". 139 $a1. 140 "GROUP by ".$denora_user_db.".country ". 141 "ORDER BY country_count DESC;"); 142 $filename = "pie-country-$chan"; 143 } 144 else { 145 die("Invalid mode parameter. Must die!"); 146 } 147 148 // Parse the collected data 149 while ($r = sql_fetch_array($q)) { 150 if ($i == ($np_db_maxd - 1)) { 151 $labels[$i] = _GD_OTHER; 152 $data[$i] = $sum - $buf; 153 break; 154 } 155 if ($r[0]) { 156 if (strlen($r[0]) > 35) { 157 $labels[$i] = substr($r[0], 0, 35) . "..."; 158 } 159 else { 160 $labels[$i] = $r[0]; 161 } 162 } 163 else { 164 $labels[$i] = _GD_UNKNOWN; 165 } 166 $data[$i] = $r[1]; 167 $buf = $buf + $data[$i]; 168 $i++; 169 } 170 171 if ($data == NULL) { $data[0] = 1; } 172 if ($labels == NULL) { 173 $labels[0] = _ER_NODATA; 174 } 175 else { 176 // Add percentages to legend 177 for ($i=0; $i < sizeof($data); $i++) { 178 $labels[$i] .= " (" . round(($data[$i] * 100) / $sum, 2) . "%%)"; 179 } 180 } 181 182 // HTTP Header definitions 183 if ($pd_debug < 2) { 184 header("Content-Type: image/png"); 185 header("Content-Disposition: attachment; filename=$filename"); 186 } 187 188 setlocale(LC_ALL, 'en_US', 'en', 'eng'); # Work around jpgraph bug 189 190 // Generate the graph 191 $graph = new PieGraph(560,200,"auto"); 192 $graph->SetAntiAliasing(); 193 $graph->legend->Pos(0.44, 0.05, "left", "top"); 194 $pieplot = new PiePlot3D($data); 195 $pieplot->ExplodeSlice(0); 196 $pieplot->SetCenter(0.22); 197 $pieplot->SetLegends($labels); 198 $pieplot->value->Show(false); 199 200 $graph->SetMarginColor($tpl_graph_bg); # graph frame bg 201 $graph->SetFrame(true,$tpl_graph_bg,0); # graph frame margin 202 $graph->SetColor($tpl_graph_bg); # graph plot bg 203 $graph->legend->SetColor($tpl_graph_labels,$tpl_graph_axis); # legend text and border colors 204 $graph->legend->SetFillColor($tpl_graph_bg); # legend fill color 205 $graph->legend->SetShadow($tpl_graph_bg,0); # turn off legend shadow 206 $pieplot->value->SetColor($tpl_graph_labels); # labels color 207 $pieplot->SetTheme($tpl_pie_theme); # pie color theme 208 209 $graph->Add($pieplot); 210 $graph->Stroke(); 211 212 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| [ Powered by PHPXref - Served by Debian GNU/Linux ] |