2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 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);
106 $dimensions = $this->getChartDimensions($xmlStr);
107 $this->ss->assign("width", $dimensions['width']);
108 $this->ss->assign("height", $dimensions['height']);
109 $config = $this->getConfigProperties();
110 $style['gridLineColor'] = str_replace("0x","#",$config->gridLines);
111 $style['font-family'] = $config->labelFontFamily;
112 $style['color'] = str_replace("0x","#",$config->labelFontColor);
113 $this->ss->assign("css", $style);
114 foreach($this->getChartConfigParams($xmlStr) as $key => $value) {
115 $chartConfig[$key] = $value;
117 $chartConfig['imageExportType'] = $this->image_export_type;
118 $this->ss->assign("config", $chartConfig);
119 if($json == "No Data") {
120 $this->ss->assign("error", "No Data");
123 if(!$this->isSupported($this->chartType)) {
124 $this->ss->assign("error", "Unsupported Chart Type");
130 function getDashletScript($id,$xmlFile="") {
132 global $sugar_config, $current_user, $current_language;
134 $this->chartId = $id;
135 $this->xmlFile = (!$xmlFile) ? $sugar_config['tmp_dir']. $current_user->id . '_' . $this->id . '.xml' : $xmlFile;
139 $chartConfig = array();
140 $this->ss->assign("chartId", $this->chartId);
141 $this->ss->assign("filename", str_replace(".xml",".js",$this->xmlFile));
142 $config = $this->getConfigProperties();
143 $style['gridLineColor'] = str_replace("0x","#",$config->gridLines);
144 $style['font-family'] = $config->labelFontFamily;
145 $style['color'] = str_replace("0x","#",$config->labelFontColor);
146 $this->ss->assign("css", $style);
147 $xmlStr = $this->processXML($this->xmlFile);
148 foreach($this->getChartConfigParams($xmlStr) as $key => $value) {
149 $chartConfig[$key] = $value;
152 $chartConfig['imageExportType'] = $this->image_export_type;
153 $this->ss->assign("config", $chartConfig);
157 function chartArray($chartsArray) {
159 $customChartsArray = array();
161 $chartConfig = array();
162 foreach($chartsArray as $id => $data) {
163 $customChartsArray[$id] = array();
164 $customChartsArray[$id]['chartId'] = $id;
165 $customChartsArray[$id]['filename'] = str_replace(".xml",".js",$data['xmlFile']);
166 $customChartsArray[$id]['width'] = $data['width'];
167 $customChartsArray[$id]['height'] = $data['height'];
169 $config = $this->getConfigProperties();
170 $style['gridLineColor'] = str_replace("0x","#",$config->gridLines);
171 $style['font-family'] = (string)$config->labelFontFamily;
172 $style['color'] = str_replace("0x","#",$config->labelFontColor);
173 $customChartsArray[$id]['css'] = $style;
174 $xmlStr = $this->processXML($data['xmlFile']);
175 $xml = new SimpleXMLElement($xmlStr);
176 $params = $this->getChartConfigParams($xmlStr);
177 $customChartsArray[$id]['supported'] = ($this->isSupported($xml->properties->type)) ? "true" : "false";
178 foreach($params as $key => $value) {
179 $chartConfig[$key] = $value;
181 $chartConfig['imageExportType'] = $this->image_export_type;
182 $customChartsArray[$id]['chartConfig'] = $chartConfig;
185 return $customChartsArray;
188 function getChartConfigParams($xmlStr) {
190 $xml = new SimpleXMLElement($xmlStr);
192 $chartType = $xml->properties->type;
193 if($chartType == "pie chart") {
194 return array ("pieType" => "basic","tip" => "name","chartType" => "pieChart");
195 } elseif($chartType == "line chart") {
196 return array ("lineType" => "basic","tip" => "name","chartType" => "lineChart");
197 } elseif($chartType == "funnel chart 3D") {
198 return array ("funnelType" => "basic","tip" => "name","chartType" => "funnelChart");
199 } elseif($chartType == "gauge chart") {
200 return array ("gaugeType" => "basic","tip" => "name","chartType" => "gaugeChart");
201 } elseif($chartType == "stacked group by chart") {
202 return array ("orientation" => "vertical","barType" => "stacked","tip" => "name","chartType" => "barChart");
203 } elseif($chartType == "group by chart") {
204 return array("orientation" => "vertical", "barType" => "grouped", "tip" => "title","chartType" => "barChart");
205 } elseif($chartType == "bar chart") {
206 return array("orientation" => "vertical", "barType" => "basic", "tip" => "label","chartType" => "barChart");
207 } elseif ($chartType == "horizontal group by chart") {
208 return array("orientation" => "horizontal", "barType" => "stacked", "tip" => "name","chartType" => "barChart");
209 } elseif ($chartType == "horizontal bar chart" || "horizontal") {
210 return array("orientation" => "horizontal","barType" => "basic","tip" => "label","chartType" => "barChart");
212 return array("orientation" => "vertical","barType" => "stacked","tip" => "name","chartType" => "barChart");
215 function getChartDimensions($xmlStr) {
216 if($this->getNumNodes($xmlStr) > 9 && $this->chartType != "pie chart") {
217 if($this->chartType == "horizontal group by chart" || $this->chartType == "horizontal bar chart") {
218 $height = ($this->getNumNodes($xmlStr) * 60) + 100;
219 return array("width"=>$this->width, "height"=>($height));
221 return array("width"=>($this->width * 2), "height"=>$this->height);
224 return array("width"=>"100%", "height"=>$this->height);
228 function checkData($xmlstr) {
229 $xml = new SimpleXMLElement($xmlstr);
230 if(sizeof($xml->data->group) > 0) {
237 function getNumNodes($xmlstr) {
238 $xml = new SimpleXMLElement($xmlstr);
239 return sizeof($xml->data->group);
242 function buildProperties($xmlstr) {
243 $content = $this->tab("'properties': [\n",1);
244 $properties = array();
245 $xml = new SimpleXMLElement($xmlstr);
246 foreach($xml->properties->children() as $property) {
247 $properties[] = $this->tab("'".$property->getName()."':"."'".$this->processSpecialChars($property)."'",2);
249 $content .= $this->tab("{\n",1);
250 $content .= join(",\n",$properties)."\n";
251 $content .= $this->tab("}\n",1);
252 $content .= $this->tab("],\n",1);
256 function buildLabelsBarChartStacked($xmlstr) {
257 $content = $this->tab("'label': [\n",1);
259 $xml = new SimpleXMLElement($xmlstr);
260 foreach($xml->data->group[0]->subgroups->group as $group) {
261 $labels[] = $this->tab("'".$this->processSpecialChars($group->title)."'",2);
263 $content .= join(",\n",$labels)."\n";
264 $content .= $this->tab("],\n",1);
268 function buildLabelsBarChart($xmlstr) {
270 // fix for bug42326: if there is label data that is deeper than that of a normal bar chart, render the labels
271 // 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
272 // having nothing but single value columns
273 $xml = new SimpleXMLElement($xmlstr);
274 if (count($xml->data->group[0]->subgroups->group) > 0) {
275 return $this->buildLabelsBarChartStacked($xmlstr);
278 $content = $this->tab("'label': [\n",1);
281 foreach($xml->data->group as $group) {
282 $labels[] = $this->tab("'".$this->processSpecialChars($group->title)."'",2);
284 $labelStr = join(",\n",$labels)."\n";
285 $content .= $labelStr;
286 $content .= $this->tab("],\n",1);
290 function buildDataBarChartStacked($xmlstr) {
291 $content = $this->tab("'values': [\n",1);
293 $xml = new SimpleXMLElement($xmlstr);
294 foreach($xml->data->group as $group) {
295 $groupcontent = $this->tab("{\n",1);
296 $groupcontent .= $this->tab("'label': '".$this->processSpecialChars($group->title)."',\n",2);
297 $groupcontent .= $this->tab("'gvalue': '{$group->value}',\n",2);
298 $groupcontent .= $this->tab("'gvaluelabel': '{$group->label}',\n",2);
299 $subgroupValues = array();
300 $subgroupValueLabels = array();
301 $subgroupLinks = array();
302 foreach($group->subgroups->group as $subgroups) {
303 $subgroupValues[] = $this->tab(($subgroups->value == "NULL") ? 0 : $subgroups->value,3);
304 $subgroupValueLabels[] = $this->tab("'".$this->processSpecialChars($subgroups->label)."'",3);
305 $subgroupLinks[] = $this->tab("'".$subgroups->link."'",3);
307 $subgroupValuesStr = join(",\n",$subgroupValues)."\n";
308 $subgroupValueLabelsStr = join(",\n",$subgroupValueLabels)."\n";
309 $subgroupLinksStr = join(",\n",$subgroupLinks)."\n";
311 $groupcontent .= $this->tab("'values': [\n".$subgroupValuesStr,2);
312 $groupcontent .= $this->tab("],\n",2);
313 $groupcontent .= $this->tab("'valuelabels': [\n".$subgroupValueLabelsStr,2);
314 $groupcontent .= $this->tab("],\n",2);
315 $groupcontent .= $this->tab("'links': [\n".$subgroupLinksStr,2);
316 $groupcontent .= $this->tab("]\n",2);
317 $groupcontent .= $this->tab("}",1);
318 $data[] = $groupcontent;
320 $content .= join(",\n",$data)."\n";
321 $content .= $this->tab("]",1);
325 function buildDataBarChartGrouped($xmlstr) {
326 $content = $this->tab("'values': [\n",1);
328 $xml = new SimpleXMLElement($xmlstr);
329 foreach($xml->data->group as $group) {
330 $groupcontent = $this->tab("{\n",1);
331 $groupcontent .= $this->tab("'label': '".$this->processSpecialChars($group->title)."',\n",2);
332 $groupcontent .= $this->tab("'gvalue': '{$group->value}',\n",2);
333 $groupcontent .= $this->tab("'gvaluelabel': '{$group->label}',\n",2);
334 $subgroupValues = array();
335 $subgroupValueLabels = array();
336 $subgroupLinks = array();
337 $subgroupTitles = array();
338 foreach($group->subgroups->group as $subgroups) {
339 $subgroupValues[] = $this->tab(($subgroups->value == "NULL") ? 0 : $subgroups->value,3);
340 $subgroupValueLabels[] = $this->tab("'".$subgroups->label."'",3);
341 $subgroupLinks[] = $this->tab("'".$subgroups->link."'",3);
342 $subgroupTitles[] = $this->tab("'".$this->processSpecialChars($subgroups->title)."'",3);
344 $subgroupValuesStr = join(",\n",$subgroupValues)."\n";
345 $subgroupValueLabelsStr = join(",\n",$subgroupValueLabels)."\n";
346 $subgroupLinksStr = join(",\n",$subgroupLinks)."\n";
347 $subgroupTitlesStr = join(",\n",$subgroupTitles)."\n";
349 $groupcontent .= $this->tab("'values': [\n".$subgroupValuesStr,2);
350 $groupcontent .= $this->tab("],\n",2);
351 $groupcontent .= $this->tab("'valuelabels': [\n".$subgroupValueLabelsStr,2);
352 $groupcontent .= $this->tab("],\n",2);
353 $groupcontent .= $this->tab("'links': [\n".$subgroupLinksStr,2);
354 $groupcontent .= $this->tab("],\n",2);
355 $groupcontent .= $this->tab("'titles': [\n".$subgroupTitlesStr,2);
356 $groupcontent .= $this->tab("]\n",2);
357 $groupcontent .= $this->tab("}",1);
358 $data[] = $groupcontent;
360 $content .= join(",\n",$data)."\n";
361 $content .= $this->tab("]",1);
365 function buildDataBarChart($xmlstr) {
366 $content = $this->tab("'values': [\n",1);
368 $xml = new SimpleXMLElement($xmlstr);
370 $groupcontentArr = array();
372 foreach($xml->data->group as $group) {
373 $groupcontent = $this->tab("{\n",1);
374 $groupcontent .= $this->tab("'label': [\n",2);
375 $groupcontent .= $this->tab("'".$this->processSpecialChars($group->title)."'\n",3);
376 $groupcontent .= $this->tab("],\n",2);
377 $groupcontent .= $this->tab("'values': [\n",2);
378 $groupcontent .= $this->tab(($group->value == "NULL") ? 0 : $group->value."\n",3);
379 $groupcontent .= $this->tab("],\n",2);
381 $groupcontent .= $this->tab("'valuelabels': [\n",2);
382 $groupcontent .= $this->tab("'{$group->label}'\n",3);
383 $groupcontent .= $this->tab("],\n",2);
385 $groupcontent .= $this->tab("'links': [\n",2);
386 $groupcontent .= $this->tab("'{$group->link}'\n",3);
387 $groupcontent .= $this->tab("]\n",2);
388 $groupcontent .= $this->tab("}",1);
389 $groupcontentArr[] = $groupcontent;
391 $content .= join(",\n",$groupcontentArr)."\n";
392 $content .= $this->tab("]",1);
396 function buildLabelsPieChart($xmlstr) {
397 $content = $this->tab("'label': [\n",1);
399 $xml = new SimpleXMLElement($xmlstr);
400 foreach($xml->data->group as $group) {
401 $labels[] = $this->tab("'".$this->processSpecialChars($group->title)."'",2);
403 $labelStr = join(",\n",$labels)."\n";
404 $content .= $labelStr;
405 $content .= $this->tab("],\n",1);
410 function buildDataPieChart($xmlstr) {
411 $content = $this->tab("'values': [\n",1);
413 $xml = new SimpleXMLElement($xmlstr);
415 $groupcontentArr = array();
417 foreach($xml->data->group as $group) {
418 $groupcontent = $this->tab("{\n",1);
419 $groupcontent .= $this->tab("'label': [\n",2);
420 $groupcontent .= $this->tab("'".$this->processSpecialChars($group->title)."'\n",3);
421 $groupcontent .= $this->tab("],\n",2);
422 $groupcontent .= $this->tab("'values': [\n",2);
423 $groupcontent .= $this->tab("{$group->value}\n",3);
424 $groupcontent .= $this->tab("],\n",2);
425 $groupcontent .= $this->tab("'valuelabels': [\n",2);
426 $groupcontent .= $this->tab("'{$group->label}'\n",3);
427 $groupcontent .= $this->tab("],\n",2);
428 $groupcontent .= $this->tab("'links': [\n",2);
429 $groupcontent .= $this->tab("'{$group->link}'\n",3);
430 $groupcontent .= $this->tab("]\n",2);
431 $groupcontent .= $this->tab("}",1);
432 $groupcontentArr[] = $groupcontent;
436 $content .= join(",\n",$groupcontentArr)."\n";
437 $content .= $this->tab("\n]",1);
441 function buildLabelsGaugeChart($xmlstr) {
442 $content = $this->tab("'label': [\n",1);
444 $xml = new SimpleXMLElement($xmlstr);
445 foreach($xml->data->group as $group) {
446 $labels[] = $this->tab("'".$this->processSpecialChars($group->title)."'",2);
448 $labelStr = join(",\n",$labels)."\n";
449 $content .= $labelStr;
450 $content .= $this->tab("],\n",1);
454 function buildDataGaugeChart($xmlstr) {
455 $content = $this->tab("'values': [\n",1);
457 $xml = new SimpleXMLElement($xmlstr);
458 foreach($xml->data->group as $group) {
459 $groupcontent = $this->tab("{\n",1);
460 $groupcontent .= $this->tab("'label': '".$this->processSpecialChars($group->title)."',\n",2);
461 $groupcontent .= $this->tab("'gvalue': '{$group->value}',\n",2);
462 $finalComma = ($group->title != "GaugePosition") ? "," : "";
463 $groupcontent .= $this->tab("'gvaluelabel': '{$group->label}'{$finalComma}\n",2);
464 $subgroupTitles = array();
465 $subgroupValues = array();
466 $subgroupValueLabels = array();
467 $subgroupLinks = array();
469 if(is_object($group->subgroups->group)) {
470 foreach($group->subgroups->group as $subgroups) {
471 $subgroupTitles[] = $this->tab("'".$subgroups->title."'",3);
472 //$subgroupValues[] = $this->tab($subgroups->value,3);
473 $subgroupValues[] = $subgroups->value;
474 $subgroupValueLabels[] = $this->tab("'".$subgroups->label."'",3);
475 $subgroupLinks[] = $this->tab("'".$subgroups->link."'",3);
477 $subgroupTitlesStr = join(",\n",$subgroupTitles)."\n";
478 $subgroupValuesStr = join(",\n",$subgroupValues)."\n";
479 $subgroupValueLabelsStr = join(",\n",$subgroupValueLabels)."\n";
480 $subgroupLinksStr = join(",\n",$subgroupLinks)."\n";
482 //$groupcontent .= $this->tab("'labels': [\n".$subgroupTitlesStr,2);
483 //$groupcontent .= $this->tab("],\n",2);
484 $val = ((int)$subgroupValues[1] == (int)$subgroupValues[0]) ? $this->tab($subgroupValues[1],3)."\n" : $this->tab($subgroupValues[1] - $subgroupValues[0],3)."\n";
486 $groupcontent .= $this->tab("'values': [\n".$val,2);
487 $groupcontent .= $this->tab("],\n",2);
488 $groupcontent .= $this->tab("'valuelabels': [\n".$subgroupValueLabelsStr,2);
489 $groupcontent .= $this->tab("]\n",2);
490 //$groupcontent .= $this->tab("'links': [\n".$subgroupLinksStr,2);
491 //$groupcontent .= $this->tab("]\n",2);
495 $groupcontent .= $this->tab("}",1);
496 $data[] = $groupcontent;
500 $content .= join(",\n",$data)."\n";
503 $content .= $this->tab("]",1);
508 function getConfigProperties() {
509 $path = SugarThemeRegistry::current()->getImageURL('sugarColors.xml',false);
511 if(!file_exists($path)) {
512 $GLOBALS['log']->debug("Cannot open file ($path)");
514 $xmlstr = file_get_contents($path);
515 $xml = new SimpleXMLElement($xmlstr);
519 function buildChartColors() {
521 $content = $this->tab("'color': [\n",1);
523 $xml = $this->getConfigProperties();
524 $colors = ($this->chartType == "gauge chart") ? $xml->gaugeChartElementColors->color : $xml->chartElementColors->color;
525 foreach($colors as $color) {
526 $colorArr[] = $this->tab("'".str_replace("0x","#",$color)."'",2);
528 $content .= join(",\n",$colorArr)."\n";
529 $content .= $this->tab("],\n",1);
535 function buildJson($xmlstr){
536 if($this->checkData($xmlstr)) {
538 if ($this->chartType == "pie chart" || $this->chartType == "funnel chart 3D") {
539 $content .= $this->buildProperties($xmlstr);
540 $content .= $this->buildLabelsPieChart($xmlstr);
541 $content .= $this->buildChartColors();
542 $content .= $this->buildDataPieChart($xmlstr);
544 elseif ($this->chartType == "gauge chart") {
545 $content .= $this->buildProperties($xmlstr);
546 $content .= $this->buildLabelsGaugeChart($xmlstr);
547 $content .= $this->buildChartColors();
548 $content .= $this->buildDataGaugeChart($xmlstr);
550 elseif ($this->chartType == "horizontal bar chart" || $this->chartType == "bar chart") {
551 $content .= $this->buildProperties($xmlstr);
552 $content .= $this->buildLabelsBarChart($xmlstr);
553 $content .= $this->buildChartColors();
554 $content .= $this->buildDataBarChart($xmlstr);
556 elseif ($this->chartType == "group by chart") {
557 $content .= $this->buildProperties($xmlstr);
558 $content .= $this->buildLabelsBarChartStacked($xmlstr);
559 $content .= $this->buildChartColors();
560 $content .= $this->buildDataBarChartGrouped($xmlstr);
562 $content .= $this->buildProperties($xmlstr);
563 $content .= $this->buildLabelsBarChartStacked($xmlstr);
564 $content .= $this->buildChartColors();
565 $content .= $this->buildDataBarChartStacked($xmlstr);
574 function buildHTMLLegend($xmlFile) {
575 $xmlstr = $this->processXML($xmlFile);
576 $xml = new SimpleXMLElement($xmlstr);
577 $this->chartType = $xml->properties->type;
578 $html = "<table align=\"left\" cellpadding=\"2\" cellspacing=\"2\">";
580 if ($this->chartType == "group by chart" || $this->chartType == "horizontal group by chart") {
581 $groups = $xml->data->group[0]->subgroups->group;
582 $items = (sizeof($xml->data->group[0]->subgroups->group) <= 5) ? 5 : sizeof($xml->data->group[0]->subgroups->group);
584 $groups = $xml->data->group;
585 $items = (sizeof($xml->data->group) <= 5) ? 5 : sizeof($xml->data->group);
588 $rows = ceil($items/5);
589 $fullItems = $rows * 5;
590 $remainder = ($items < $fullItems) ? $fullItems - $items : 0;
596 $xmlColors = $this->getConfigProperties();
597 $colors = ($this->chartType == "gauge chart") ? $xmlColors->gaugeChartElementColors->color : $xmlColors->chartElementColors->color;
599 foreach($colors as $color) {
600 $colorArr[] = str_replace("0x","#",$color);
604 foreach($groups as $group) {
605 if($i == 5) {$i = 0;}
606 $html .= ($i == 0) ? "<tr>" : "";
607 $html .= "<td width=\"50\">";
608 $html .= "<div style=\"background-color:".$colorArr[$x].";\"> </div>";
611 $html .= $group->title;
613 $html .= ($x+1 == $items) ? "<td colspan=".($remainder*2)."></td>" : "";
614 $html .= ($i == 4) ? "</tr>" : "";
624 function saveJsonFile($jsonContents) {
626 $this->jsonFilename = str_replace(".xml",".js",$this->xmlFile);
627 //$jsonContents = mb_convert_encoding($jsonContents, 'UTF-16LE', 'UTF-8');
630 if (!$fh = sugar_fopen($this->jsonFilename, 'w')) {
631 $GLOBALS['log']->debug("Cannot open file ($this->jsonFilename)");
635 // write the contents to the file
636 if (fwrite($fh,$jsonContents) === FALSE) {
637 $GLOBALS['log']->debug("Cannot write to file ($this->jsonFilename)");
641 $GLOBALS['log']->debug("Success, wrote ($jsonContents) to file ($this->jsonFilename)");
647 function get_image_cache_file_name ($xmlFile,$ext = ".png") {
648 $filename = str_replace("/xml/","/images/",str_replace(".xml",$ext,$xmlFile));
654 function getXMLChartProperties($xmlStr) {
656 $xml = new SimpleXMLElement($xmlstr);
657 foreach($xml->properties->children() as $properties) {
658 $props[$properties->getName()] = $properties;
663 function processSpecialChars($str) {
664 return addslashes(html_entity_decode($str,ENT_QUOTES));
667 function processXML($xmlFile) {
669 if(!file_exists($xmlFile)) {
670 $GLOBALS['log']->debug("Cannot open file ($xmlFile)");
674 $replacement = array();
675 $content = file_get_contents($xmlFile);
676 $content = mb_convert_encoding($content, 'UTF-8','UTF-16LE' );
677 $pattern[] = '/\<link\>([a-zA-Z0-9#?&%.;\[\]\/=+_-\s]+)\<\/link\>/e';
678 $replacement[] = "'<link>'.urlencode(\"$1\").'</link>'";
679 // $pattern[] = '/NULL/e';
680 // $replacement[] = "";
681 return preg_replace($pattern,$replacement, $content);