2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Affero General Public License version 3 as published by the
8 * Free Software Foundation with the addition of the following permission added
9 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
18 * You should have received a copy of the GNU Affero General Public License along with
19 * this program; if not, see http://www.gnu.org/licenses or write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26 * The interactive user interfaces in modified source and object code versions
27 * of this program must display Appropriate Legal Notices, as required under
28 * Section 5 of the GNU Affero General Public License version 3.
30 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31 * these Appropriate Legal Notices must retain the display of the "Powered by
32 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33 * technical reasons, the Appropriate Legal Notices must display the words
34 * "Powered by SugarCRM".
35 ********************************************************************************/
40 require_once("include/SugarCharts/SugarChart.php");
42 class JsChart extends SugarChart {
51 function __construct() {
52 parent::__construct();
55 function isSupported($chartType) {
57 "stacked group by chart",
60 "horizontal group by chart",
62 "horizontal bar chart",
69 if(in_array($chartType,$charts)) {
77 function tab($str, $depth){
78 // $str = preg_replace('/(<\w+>)(.*)(<\/\w+>)/e', "'\\1'.htmlentities(from_html('\\2')).'\\3'", $str);
79 return str_repeat("\t", $depth) . $str . "\n";
82 function display($name, $xmlFile, $width='320', $height='480', $resize=false) {
85 $this->chartId = $name;
86 $this->height = $height;
87 $this->width = $width;
88 $this->xmlFile = $xmlFile;
89 $this->chartType = $this->chart_properties['type'];
92 $chartConfig = array();
94 $xmlStr = $this->processXML($this->xmlFile);
95 $json = $this->buildJson($xmlStr);
98 $GLOBALS['log']->fatal("Unable to return chart data, invalid xml for file {$this->xmlFile}");
101 $this->saveJsonFile($json);
102 $this->ss->assign("chartId", $this->chartId);
103 $this->ss->assign("filename", $this->jsonFilename);
104 global $mod_strings, $app_strings;
105 if (isset($mod_strings['LBL_REPORT_SHOW_CHART']))
106 $this->ss->assign("showchart", $mod_strings['LBL_REPORT_SHOW_CHART']);
108 $dimensions = $this->getChartDimensions($xmlStr);
109 $this->ss->assign("width", $dimensions['width']);
110 $this->ss->assign("height", $dimensions['height']);
111 $config = $this->getConfigProperties();
112 $style['gridLineColor'] = str_replace("0x","#",$config->gridLines);
113 $style['font-family'] = $config->labelFontFamily;
114 $style['color'] = str_replace("0x","#",$config->labelFontColor);
115 $this->ss->assign("css", $style);
116 foreach($this->getChartConfigParams($xmlStr) as $key => $value) {
117 $chartConfig[$key] = $value;
119 $chartConfig['imageExportType'] = $this->image_export_type;
120 $this->ss->assign("config", $chartConfig);
121 if($json == "No Data") {
122 $this->ss->assign("error", $app_strings['LBL_NO_DATA']);
125 if(!$this->isSupported($this->chartType)) {
126 $this->ss->assign("error", "Unsupported Chart Type");
132 function getDashletScript($id,$xmlFile="") {
134 global $sugar_config, $current_user, $current_language;
136 $this->chartId = $id;
137 $this->xmlFile = (!$xmlFile) ? sugar_cached("xml/".$current_user->getUserPrivGuid()."_{$this->id}.xml") : $xmlFile;
141 $chartConfig = array();
142 $this->ss->assign("chartId", $this->chartId);
143 $this->ss->assign("filename", str_replace(".xml",".js",$this->xmlFile));
144 $config = $this->getConfigProperties();
145 $style['gridLineColor'] = str_replace("0x","#",$config->gridLines);
146 $style['font-family'] = $config->labelFontFamily;
147 $style['color'] = str_replace("0x","#",$config->labelFontColor);
148 $this->ss->assign("css", $style);
149 $xmlStr = $this->processXML($this->xmlFile);
150 foreach($this->getChartConfigParams($xmlStr) as $key => $value) {
151 $chartConfig[$key] = $value;
154 $chartConfig['imageExportType'] = $this->image_export_type;
155 $this->ss->assign("config", $chartConfig);
159 function chartArray($chartsArray) {
161 $customChartsArray = array();
163 $chartConfig = array();
164 foreach($chartsArray as $id => $data) {
165 $customChartsArray[$id] = array();
166 $customChartsArray[$id]['chartId'] = $id;
167 $customChartsArray[$id]['filename'] = str_replace(".xml",".js",$data['xmlFile']);
168 $customChartsArray[$id]['width'] = $data['width'];
169 $customChartsArray[$id]['height'] = $data['height'];
171 $config = $this->getConfigProperties();
172 $style['gridLineColor'] = str_replace("0x","#",$config->gridLines);
173 $style['font-family'] = (string)$config->labelFontFamily;
174 $style['color'] = str_replace("0x","#",$config->labelFontColor);
175 $customChartsArray[$id]['css'] = $style;
176 $xmlStr = $this->processXML($data['xmlFile']);
177 $xml = new SimpleXMLElement($xmlStr);
178 $params = $this->getChartConfigParams($xmlStr);
179 $customChartsArray[$id]['supported'] = ($this->isSupported($xml->properties->type)) ? "true" : "false";
180 foreach($params as $key => $value) {
181 $chartConfig[$key] = $value;
183 $chartConfig['imageExportType'] = $this->image_export_type;
184 $customChartsArray[$id]['chartConfig'] = $chartConfig;
187 return $customChartsArray;
190 function getChartConfigParams($xmlStr) {
192 $xml = new SimpleXMLElement($xmlStr);
194 $chartType = $xml->properties->type;
195 if($chartType == "pie chart") {
196 return array ("pieType" => "basic","tip" => "name","chartType" => "pieChart");
197 } elseif($chartType == "line chart") {
198 return array ("lineType" => "basic","tip" => "name","chartType" => "lineChart");
199 } elseif($chartType == "funnel chart 3D") {
200 return array ("funnelType" => "basic","tip" => "name","chartType" => "funnelChart");
201 } elseif($chartType == "gauge chart") {
202 return array ("gaugeType" => "basic","tip" => "name","chartType" => "gaugeChart");
203 } elseif($chartType == "stacked group by chart") {
204 return array ("orientation" => "vertical","barType" => "stacked","tip" => "name","chartType" => "barChart");
205 } elseif($chartType == "group by chart") {
206 return array("orientation" => "vertical", "barType" => "grouped", "tip" => "title","chartType" => "barChart");
207 } elseif($chartType == "bar chart") {
208 return array("orientation" => "vertical", "barType" => "basic", "tip" => "label","chartType" => "barChart");
209 } elseif ($chartType == "horizontal group by chart") {
210 return array("orientation" => "horizontal", "barType" => "stacked", "tip" => "name","chartType" => "barChart");
211 } elseif ($chartType == "horizontal bar chart" || "horizontal") {
212 return array("orientation" => "horizontal","barType" => "basic","tip" => "label","chartType" => "barChart");
214 return array("orientation" => "vertical","barType" => "stacked","tip" => "name","chartType" => "barChart");
217 function getChartDimensions($xmlStr) {
218 if($this->getNumNodes($xmlStr) > 9 && $this->chartType != "pie chart") {
219 if($this->chartType == "horizontal group by chart" || $this->chartType == "horizontal bar chart") {
220 $height = ($this->getNumNodes($xmlStr) * 60) + 100;
221 return array("width"=>$this->width, "height"=>($height));
223 return array("width"=>($this->width * 2), "height"=>$this->height);
226 return array("width"=>"100%", "height"=>$this->height);
230 function checkData($xmlstr) {
231 $xml = new SimpleXMLElement($xmlstr);
232 if(sizeof($xml->data->group) > 0) {
239 function getNumNodes($xmlstr) {
240 $xml = new SimpleXMLElement($xmlstr);
241 return sizeof($xml->data->group);
244 function buildProperties($xmlstr) {
245 $content = $this->tab("\"properties\": [\n",1);
246 $properties = array();
247 $xml = new SimpleXMLElement($xmlstr);
248 foreach($xml->properties->children() as $property) {
249 $properties[] = $this->tab("\"".$property->getName()."\":"."\"".$this->processSpecialChars($property)."\"",2);
251 $content .= $this->tab("{\n",1);
252 $content .= join(",\n",$properties)."\n";
253 $content .= $this->tab("}\n",1);
254 $content .= $this->tab("],\n",1);
258 function buildLabelsBarChartStacked($xmlstr) {
259 $content = $this->tab("\"label\": [\n",1);
261 $xml = new SimpleXMLElement($xmlstr);
262 foreach($xml->data->group[0]->subgroups->group as $group) {
263 $labels[] = $this->tab("\"".$this->processSpecialChars($group->title)."\"",2);
265 $content .= join(",\n",$labels)."\n";
266 $content .= $this->tab("],\n",1);
270 function buildLabelsBarChart($xmlstr) {
272 // fix for bug42326: if there is label data that is deeper than that of a normal bar chart, render the labels
273 // like a stacked bar chart, this applies when a stacked chart has been converted in templates_chart.php to a bar chart due to it
274 // having nothing but single value columns
275 $xml = new SimpleXMLElement($xmlstr);
276 if (count($xml->data->group[0]->subgroups->group) > 0) {
277 return $this->buildLabelsBarChartStacked($xmlstr);
280 $content = $this->tab("\"label\": [\n",1);
283 foreach($xml->data->group as $group) {
284 $labels[] = $this->tab("\"".$this->processSpecialChars($group->title)."\"",2);
286 $labelStr = join(",\n",$labels)."\n";
287 $content .= $labelStr;
288 $content .= $this->tab("],\n",1);
292 function buildDataBarChartStacked($xmlstr) {
293 $content = $this->tab("\"values\": [\n",1);
295 $xml = new SimpleXMLElement($xmlstr);
296 foreach($xml->data->group as $group) {
297 $groupcontent = $this->tab("{\n",1);
298 $groupcontent .= $this->tab("\"label\": \"".$this->processSpecialChars($group->title)."\",\n",2);
299 $groupcontent .= $this->tab("\"gvalue\": \"{$group->value}\",\n",2);
300 $groupcontent .= $this->tab("\"gvaluelabel\": \"{$group->label}\",\n",2);
301 $subgroupValues = array();
302 $subgroupValueLabels = array();
303 $subgroupLinks = array();
304 foreach($group->subgroups->group as $subgroups) {
305 $subgroupValues[] = $this->tab(($subgroups->value == "NULL") ? 0 : $subgroups->value,3);
306 $subgroupValueLabels[] = $this->tab("\"".$this->processSpecialChars($subgroups->label)."\"",3);
307 $subgroupLinks[] = $this->tab("\"".$subgroups->link."\"",3);
309 $subgroupValuesStr = join(",\n",$subgroupValues)."\n";
310 $subgroupValueLabelsStr = join(",\n",$subgroupValueLabels)."\n";
311 $subgroupLinksStr = join(",\n",$subgroupLinks)."\n";
313 $groupcontent .= $this->tab("\"values\": [\n".$subgroupValuesStr,2);
314 $groupcontent .= $this->tab("],\n",2);
315 $groupcontent .= $this->tab("\"valuelabels\": [\n".$subgroupValueLabelsStr,2);
316 $groupcontent .= $this->tab("],\n",2);
317 $groupcontent .= $this->tab("\"links\": [\n".$subgroupLinksStr,2);
318 $groupcontent .= $this->tab("]\n",2);
319 $groupcontent .= $this->tab("}",1);
320 $data[] = $groupcontent;
322 $content .= join(",\n",$data)."\n";
323 $content .= $this->tab("]",1);
327 function buildDataBarChartGrouped($xmlstr) {
328 $content = $this->tab("\"values\": [\n",1);
330 $xml = new SimpleXMLElement($xmlstr);
331 foreach($xml->data->group as $group) {
332 $groupcontent = $this->tab("{\n",1);
333 $groupcontent .= $this->tab("\"label\": \"".$this->processSpecialChars($group->title)."\",\n",2);
334 $groupcontent .= $this->tab("\"gvalue\": \"{$group->value}\",\n",2);
335 $groupcontent .= $this->tab("\"gvaluelabel\": \"{$group->label}\",\n",2);
336 $subgroupValues = array();
337 $subgroupValueLabels = array();
338 $subgroupLinks = array();
339 $subgroupTitles = array();
340 foreach($group->subgroups->group as $subgroups) {
341 $subgroupValues[] = $this->tab(($subgroups->value == "NULL") ? 0 : $subgroups->value,3);
342 $subgroupValueLabels[] = $this->tab("\"".$subgroups->label."\"",3);
343 $subgroupLinks[] = $this->tab("\"".$subgroups->link."\"",3);
344 $subgroupTitles[] = $this->tab("\"".$this->processSpecialChars($subgroups->title)."\"",3);
346 $subgroupValuesStr = join(",\n",$subgroupValues)."\n";
347 $subgroupValueLabelsStr = join(",\n",$subgroupValueLabels)."\n";
348 $subgroupLinksStr = join(",\n",$subgroupLinks)."\n";
349 $subgroupTitlesStr = join(",\n",$subgroupTitles)."\n";
351 $groupcontent .= $this->tab("\"values\": [\n".$subgroupValuesStr,2);
352 $groupcontent .= $this->tab("],\n",2);
353 $groupcontent .= $this->tab("\"valuelabels\": [\n".$subgroupValueLabelsStr,2);
354 $groupcontent .= $this->tab("],\n",2);
355 $groupcontent .= $this->tab("\"links\": [\n".$subgroupLinksStr,2);
356 $groupcontent .= $this->tab("],\n",2);
357 $groupcontent .= $this->tab("\"titles\": [\n".$subgroupTitlesStr,2);
358 $groupcontent .= $this->tab("]\n",2);
359 $groupcontent .= $this->tab("}",1);
360 $data[] = $groupcontent;
362 $content .= join(",\n",$data)."\n";
363 $content .= $this->tab("]",1);
367 function buildDataBarChart($xmlstr) {
368 $content = $this->tab("\"values\": [\n",1);
370 $xml = new SimpleXMLElement($xmlstr);
372 $groupcontentArr = array();
374 foreach($xml->data->group as $group) {
375 $groupcontent = $this->tab("{\n",1);
376 $groupcontent .= $this->tab("\"label\": [\n",2);
377 $groupcontent .= $this->tab("\"".$this->processSpecialChars($group->title)."\"\n",3);
378 $groupcontent .= $this->tab("],\n",2);
379 $groupcontent .= $this->tab("\"values\": [\n",2);
380 $groupcontent .= $this->tab(($group->value == "NULL") ? 0 : $group->value."\n",3);
381 $groupcontent .= $this->tab("],\n",2);
383 $groupcontent .= $this->tab("\"valuelabels\": [\n",2);
384 $groupcontent .= $this->tab("\"{$group->label}\"\n",3);
385 $groupcontent .= $this->tab("],\n",2);
387 $groupcontent .= $this->tab("\"links\": [\n",2);
388 $groupcontent .= $this->tab("\"{$group->link}\"\n",3);
389 $groupcontent .= $this->tab("]\n",2);
390 $groupcontent .= $this->tab("}",1);
391 $groupcontentArr[] = $groupcontent;
393 $content .= join(",\n",$groupcontentArr)."\n";
394 $content .= $this->tab("]",1);
398 function buildLabelsPieChart($xmlstr) {
399 $content = $this->tab("\"label\": [\n",1);
401 $xml = new SimpleXMLElement($xmlstr);
402 foreach($xml->data->group as $group) {
403 $labels[] = $this->tab("\"".$this->processSpecialChars($group->title)."\"",2);
405 $labelStr = join(",\n",$labels)."\n";
406 $content .= $labelStr;
407 $content .= $this->tab("],\n",1);
412 function buildDataPieChart($xmlstr) {
413 $content = $this->tab("\"values\": [\n",1);
415 $xml = new SimpleXMLElement($xmlstr);
417 $groupcontentArr = array();
419 foreach($xml->data->group as $group) {
420 $groupcontent = $this->tab("{\n",1);
421 $groupcontent .= $this->tab("\"label\": [\n",2);
422 $groupcontent .= $this->tab("\"".$this->processSpecialChars($group->title)."\"\n",3);
423 $groupcontent .= $this->tab("],\n",2);
424 $groupcontent .= $this->tab("\"values\": [\n",2);
425 $groupcontent .= $this->tab("{$group->value}\n",3);
426 $groupcontent .= $this->tab("],\n",2);
427 $groupcontent .= $this->tab("\"valuelabels\": [\n",2);
428 $groupcontent .= $this->tab("\"{$group->label}\"\n",3);
429 $groupcontent .= $this->tab("],\n",2);
430 $groupcontent .= $this->tab("\"links\": [\n",2);
431 $groupcontent .= $this->tab("\"{$group->link}\"\n",3);
432 $groupcontent .= $this->tab("]\n",2);
433 $groupcontent .= $this->tab("}",1);
434 $groupcontentArr[] = $groupcontent;
438 $content .= join(",\n",$groupcontentArr)."\n";
439 $content .= $this->tab("\n]",1);
443 function buildLabelsGaugeChart($xmlstr) {
444 $content = $this->tab("\"label\": [\n",1);
446 $xml = new SimpleXMLElement($xmlstr);
447 foreach($xml->data->group as $group) {
448 $labels[] = $this->tab("\"".$this->processSpecialChars($group->title)."\"",2);
450 $labelStr = join(",\n",$labels)."\n";
451 $content .= $labelStr;
452 $content .= $this->tab("],\n",1);
456 function buildDataGaugeChart($xmlstr) {
457 $content = $this->tab("\"values\": [\n",1);
459 $xml = new SimpleXMLElement($xmlstr);
460 foreach($xml->data->group as $group) {
461 $groupcontent = $this->tab("{\n",1);
462 $groupcontent .= $this->tab("\"label\": \"".$this->processSpecialChars($group->title)."\",\n",2);
463 $groupcontent .= $this->tab("\"gvalue\": \"{$group->value}\",\n",2);
464 $finalComma = ($group->title != "GaugePosition") ? "," : "";
465 $groupcontent .= $this->tab("\"gvaluelabel\": \"{$group->label}\"{$finalComma}\n",2);
466 $subgroupTitles = array();
467 $subgroupValues = array();
468 $subgroupValueLabels = array();
469 $subgroupLinks = array();
471 if(is_object($group->subgroups->group)) {
472 foreach($group->subgroups->group as $subgroups) {
473 $subgroupTitles[] = $this->tab("\"".$subgroups->title."\"",3);
474 //$subgroupValues[] = $this->tab($subgroups->value,3);
475 $subgroupValues[] = $subgroups->value;
476 $subgroupValueLabels[] = $this->tab("\"".$subgroups->label."\"",3);
477 $subgroupLinks[] = $this->tab("\"".$subgroups->link."\"",3);
479 $subgroupTitlesStr = join(",\n",$subgroupTitles)."\n";
480 $subgroupValuesStr = join(",\n",$subgroupValues)."\n";
481 $subgroupValueLabelsStr = join(",\n",$subgroupValueLabels)."\n";
482 $subgroupLinksStr = join(",\n",$subgroupLinks)."\n";
484 //$groupcontent .= $this->tab("\"labels\": [\n".$subgroupTitlesStr,2);
485 //$groupcontent .= $this->tab("],\n",2);
486 $val = ((int)$subgroupValues[1] == (int)$subgroupValues[0]) ? $this->tab($subgroupValues[1],3)."\n" : $this->tab($subgroupValues[1] - $subgroupValues[0],3)."\n";
488 $groupcontent .= $this->tab("\"values\": [\n".$val,2);
489 $groupcontent .= $this->tab("],\n",2);
490 $groupcontent .= $this->tab("\"valuelabels\": [\n".$subgroupValueLabelsStr,2);
491 $groupcontent .= $this->tab("]\n",2);
492 //$groupcontent .= $this->tab("\"links\": [\n".$subgroupLinksStr,2);
493 //$groupcontent .= $this->tab("]\n",2);
497 $groupcontent .= $this->tab("}",1);
498 $data[] = $groupcontent;
502 $content .= join(",\n",$data)."\n";
505 $content .= $this->tab("]",1);
510 function getConfigProperties() {
511 $path = SugarThemeRegistry::current()->getImageURL('sugarColors.xml',false);
513 if(!file_exists($path)) {
514 $GLOBALS['log']->debug("Cannot open file ($path)");
516 $xmlstr = file_get_contents($path);
517 $xml = new SimpleXMLElement($xmlstr);
521 function buildChartColors() {
523 $content = $this->tab("\"color\": [\n",1);
525 $xml = $this->getConfigProperties();
526 $colors = ($this->chartType == "gauge chart") ? $xml->gaugeChartElementColors->color : $xml->chartElementColors->color;
527 foreach($colors as $color) {
528 $colorArr[] = $this->tab("\"".str_replace("0x","#",$color)."\"",2);
530 $content .= join(",\n",$colorArr)."\n";
531 $content .= $this->tab("],\n",1);
537 function buildJson($xmlstr){
538 if($this->checkData($xmlstr)) {
540 if ($this->chartType == "pie chart" || $this->chartType == "funnel chart 3D") {
541 $content .= $this->buildProperties($xmlstr);
542 $content .= $this->buildLabelsPieChart($xmlstr);
543 $content .= $this->buildChartColors();
544 $content .= $this->buildDataPieChart($xmlstr);
546 elseif ($this->chartType == "gauge chart") {
547 $content .= $this->buildProperties($xmlstr);
548 $content .= $this->buildLabelsGaugeChart($xmlstr);
549 $content .= $this->buildChartColors();
550 $content .= $this->buildDataGaugeChart($xmlstr);
552 elseif ($this->chartType == "horizontal bar chart" || $this->chartType == "bar chart") {
553 $content .= $this->buildProperties($xmlstr);
554 $content .= $this->buildLabelsBarChart($xmlstr);
555 $content .= $this->buildChartColors();
556 $content .= $this->buildDataBarChart($xmlstr);
558 elseif ($this->chartType == "group by chart") {
559 $content .= $this->buildProperties($xmlstr);
560 $content .= $this->buildLabelsBarChartStacked($xmlstr);
561 $content .= $this->buildChartColors();
562 $content .= $this->buildDataBarChartGrouped($xmlstr);
564 $content .= $this->buildProperties($xmlstr);
565 $content .= $this->buildLabelsBarChartStacked($xmlstr);
566 $content .= $this->buildChartColors();
567 $content .= $this->buildDataBarChartStacked($xmlstr);
576 function buildHTMLLegend($xmlFile) {
577 $xmlstr = $this->processXML($xmlFile);
578 $xml = new SimpleXMLElement($xmlstr);
579 $this->chartType = $xml->properties->type;
580 $html = "<table align=\"left\" cellpadding=\"2\" cellspacing=\"2\">";
583 $this->chartType == "group by chart"
584 || $this->chartType == "horizontal group by chart"
585 || $this->chartType == 'line chart'
586 || $this->chartType == 'stacked group by chart'
589 $groups = $xml->data->group[0]->subgroups->group;
590 $items = (sizeof($xml->data->group[0]->subgroups->group) <= 5) ? 5 : sizeof($xml->data->group[0]->subgroups->group);
592 if ($this->chartType == "funnel chart 3D") {
595 foreach($xml->data->group as $group) {
596 array_unshift($groups, $group);
599 $groups = $xml->data->group;
601 $items = (sizeof($xml->data->group) <= 5) ? 5 : sizeof($xml->data->group);
604 $rows = ceil($items/5);
605 $fullItems = $rows * 5;
606 $remainder = ($items < $fullItems) ? $fullItems - $items : 0;
612 $xmlColors = $this->getConfigProperties();
613 $colors = ($this->chartType == "gauge chart") ? $xmlColors->gaugeChartElementColors->color : $xmlColors->chartElementColors->color;
615 foreach($colors as $color) {
616 $colorArr[] = str_replace("0x","#",$color);
620 foreach($groups as $group) {
621 if($i == 5) {$i = 0;}
622 $html .= ($i == 0) ? "<tr>" : "";
623 $html .= "<td width=\"50\">";
624 $html .= "<div style=\"background-color:".$colorArr[$x].";\"> </div>";
627 $html .= $group->title;
629 $html .= ($x+1 == $items) ? "<td colspan=".($remainder*2)."></td>" : "";
642 if ($isTrClosed == false)
651 function saveJsonFile($jsonContents) {
652 $this->jsonFilename = str_replace(".xml",".js",$this->xmlFile);
653 //$jsonContents = $GLOBALS['locale']->translateCharset($jsonContents, 'UTF-8', 'UTF-16LE');
656 if (!$fh = sugar_fopen($this->jsonFilename, 'w')) {
657 $GLOBALS['log']->debug("Cannot open file ($this->jsonFilename)");
661 // write the contents to the file
662 if (fwrite($fh,$jsonContents) === FALSE) {
663 $GLOBALS['log']->debug("Cannot write to file ($this->jsonFilename)");
667 $GLOBALS['log']->debug("Success, wrote ($jsonContents) to file ($this->jsonFilename)");
673 function get_image_cache_file_name ($xmlFile,$ext = ".png") {
674 $filename = str_replace("/xml/","/images/",str_replace(".xml",$ext,$xmlFile));
680 function getXMLChartProperties($xmlStr) {
682 $xml = new SimpleXMLElement($xmlstr);
683 foreach($xml->properties->children() as $properties) {
684 $props[$properties->getName()] = $properties;
689 function processSpecialChars($str) {
690 return addslashes(html_entity_decode($str,ENT_QUOTES));
693 function processXML($xmlFile) {
695 if(!file_exists($xmlFile)) {
696 $GLOBALS['log']->debug("Cannot open file ($xmlFile)");
700 $replacement = array();
701 $content = file_get_contents($xmlFile);
702 $content = $GLOBALS['locale']->translateCharset($content,'UTF-16LE', 'UTF-8');
703 $pattern[] = '/\<link\>([a-zA-Z0-9#?&%.;\[\]\/=+_-\s]+)\<\/link\>/e';
704 $replacement[] = "'<link>'.urlencode(\"$1\").'</link>'";
705 // $pattern[] = '/NULL/e';
706 // $replacement[] = "";
707 return preg_replace($pattern,$replacement, $content);