2 /*********************************************************************************
3 * SugarCRM 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/Jit/Jit.php");
42 class JitReports extends Jit {
44 private $processed_report_keys = array();
46 function __construct() {
47 parent::__construct();
50 function calculateReportGroupTotal($dataset){
52 foreach ($dataset as $value){
53 $total += $value['numerical_value'];
59 function processReportData($dataset, $level=1, $first=false){
62 // rearrange $dataset to get the correct order for the first row
64 $temp_dataset = array();
65 foreach ($this->super_set as $key){
66 $temp_dataset[$key] = (isset($dataset[$key])) ? $dataset[$key] : array();
68 $dataset = $temp_dataset;
71 foreach ($dataset as $key=>$value){
72 if ($first && empty($value)){
73 $data .= $this->processDataGroup(4, $key, 'NULL', '', '');
75 else if (array_key_exists('numerical_value', $dataset)){
76 $link = (isset($dataset['link'])) ? '#'.$dataset['link'] : '';
77 $data .= $this->processDataGroup($level, $dataset['group_base_text'], $dataset['numerical_value'], $dataset['numerical_value'], $link);
78 array_push($this->processed_report_keys, $dataset['group_base_text']);
82 $data .= $this->processReportData($value, $level+1);
89 function processReportGroup($dataset){
92 foreach($dataset as $groupBy => $groups){
93 $prev_super_set = $super_set;
94 if (count($groups) > count($super_set)){
95 $super_set = array_keys($groups);
96 foreach($prev_super_set as $prev_group){
97 if (!in_array($prev_group, $groups)){
98 array_push($super_set, $prev_group);
103 foreach($groups as $group => $groupData){
104 if (!in_array($group, $super_set)){
105 array_push($super_set, $group);
110 $super_set = array_unique($super_set);
115 function xmlDataReportSingleValue(){
117 foreach ($this->data_set as $key => $dataset){
118 $total = $this->calculateReportGroupTotal($dataset);
119 $this->checkYAxis($total);
121 $data .= $this->tab('<group>', 2);
122 $data .= $this->tab('<title>' . $key . '</title>', 3);
123 $data .= $this->tab('<subgroups>', 3);
124 $data .= $this->tab('<group>',4);
125 $data .= $this->tab('<title>' . $total . '</title>',5);
126 $data .= $this->tab('<value>' . $total . '</value>',5);
127 $data .= $this->tab('<label>' . $key . '</label>',5);
128 $data .= $this->tab('<link></link>',5);
129 $data .= $this->tab('</group>',4);
130 $data .= $this->tab('</subgroups>', 3);
131 $data .= $this->tab('</group>', 2);
136 function xmlDataReportChart(){
138 // correctly process the first row
140 foreach ($this->data_set as $key => $dataset){
142 $total = $this->calculateReportGroupTotal($dataset);
143 $this->checkYAxis($total);
145 $data .= $this->tab('<group>', 2);
146 $data .= $this->tab('<title>' . $key . '</title>', 3);
147 $data .= $this->tab('<value>' . $total . '</value>', 3);
148 $data .= $this->tab('<label>' . $total . '</label>', 3);
149 $data .= $this->tab('<subgroups>', 3);
151 if ((isset($dataset[$total]) && $total != $dataset[$total]['numerical_value']) || !array_key_exists($key, $dataset)){
152 $data .= $this->processReportData($dataset, 4, $first);
156 $not_processed = array_diff($this->super_set, $this->processed_report_keys);
157 $processed_diff_count = count($this->super_set) - count($not_processed);
159 if ($processed_diff_count != 0){
160 foreach ($not_processed as $title){
161 $data .= $this->processDataGroup(4, $title, 'NULL', '', '');
165 $data .= $this->tab('</subgroups>', 3);
166 $data .= $this->tab('</group>', 2);
167 $this->processed_report_keys = array();
168 // we're done with the first row!
174 public function processXmlData(){
177 $this->super_set = $this->processReportGroup($this->data_set);
178 $single_value = false;
180 foreach ($this->data_set as $key => $dataset){
181 if ((isset($dataset[$key]) && count($this->data_set[$key]) == 1)){
182 $single_value = true;
185 $single_value = false;
188 if ($this->chart_properties['type'] == 'line chart' && $single_value){
189 $data .= $this->xmlDataReportSingleValue();
192 $data .= $this->xmlDataReportChart();
199 * wrapper function to return the html code containing the chart in a div
201 * @param string $name name of the div
202 * string $xmlFile location of the XML file
203 * string $style optional additional styles for the div
204 * @return string returns the html code through smarty
206 function display($name, $xmlFile, $width='320', $height='480', $reportChartDivStyle, $resize=false){
209 parent::display($name, $xmlFile, $width, $height, $resize=false);
211 return $this->ss->fetch('include/SugarCharts/Jit/tpls/chart.tpl');