Example #1
0
 /**
  * Generates data for OFC2 line chart in json format
  *
  * @return void
  */
 public function get_laba_rugi()
 {
     $this->load->plugin('ofc2');
     $this->load->model('jurnal_model');
     $model_data = $this->jurnal_model->get_laba_rugi_data();
     $bulan_data = array("Jan", "Feb", "Mar", "Apr", "Mei", "Jun", "Jul", "Agu", "Sep", "Okt", "Nov", "Des");
     for ($i = date('n') + 1; $i <= 12; $i++) {
         $pendapatan_kredit = isset($model_data[$i][date('Y') - 1][4][0]) ? $model_data[$i][date('Y') - 1][4][0] : 0;
         $pendapatan_debit = isset($model_data[$i][date('Y') - 1][4][1]) ? $model_data[$i][date('Y') - 1][4][1] : 0;
         $beban_kredit = isset($model_data[$i][date('Y') - 1][5][0]) ? $model_data[$i][date('Y') - 1][5][0] : 0;
         $beban_debit = isset($model_data[$i][date('Y') - 1][5][1]) ? $model_data[$i][date('Y') - 1][5][1] : 0;
         $data[] = $pendapatan_kredit - $pendapatan_debit - ($beban_debit - $beban_kredit);
         $thn = date('y') - 1;
         $thn = strlen($thn) == 1 ? '0' . $thn : $thn;
         $x_data[] = $bulan_data[$i - 1] . "'" . $thn;
     }
     for ($i = 1; $i <= date('n'); $i++) {
         $pendapatan_kredit = isset($model_data[$i][date('Y')][4][0]) ? $model_data[$i][date('Y')][4][0] : 0;
         $pendapatan_debit = isset($model_data[$i][date('Y')][4][1]) ? $model_data[$i][date('Y')][4][1] : 0;
         $beban_kredit = isset($model_data[$i][date('Y')][5][0]) ? $model_data[$i][date('Y')][5][0] : 0;
         $beban_debit = isset($model_data[$i][date('Y')][5][1]) ? $model_data[$i][date('Y')][5][1] : 0;
         $data[] = $pendapatan_kredit - $pendapatan_debit - ($beban_debit - $beban_kredit);
         $x_data[] = $bulan_data[$i - 1] . "'" . date('y');
     }
     $max = (int) max($data);
     $maxlen = strlen($max);
     $up = round($max, -($maxlen - 1));
     $min = (int) min($data);
     $minlen = strlen($min);
     $down = round($min, -($minlen - 1));
     $abs_max = (int) max(abs($max), abs($min));
     $len = strlen($abs_max);
     $round = round($abs_max, -($len - 1));
     $step = '1' . substr($round, 1);
     $up = $max > $up ? $up + $step : $up;
     $down = $min < $down ? $down - $step : $down;
     $d = new hollow_dot();
     $d->size(4)->halo_size(1)->colour('#668053');
     $line = new line();
     $line->set_values($data);
     $line->set_default_dot_style($d);
     $line->set_width(5);
     $line->set_colour('#7491a0');
     $x_labels = new x_axis_labels();
     $x_labels->set_labels($x_data);
     $x = new x_axis();
     $x->set_labels($x_labels);
     $x->set_grid_colour('#bfb8b3');
     $y = new y_axis();
     $y->set_grid_colour('#bfb8b3');
     $y->set_range($down, $up, $step);
     $chart = new open_flash_chart();
     $chart->add_element($line);
     $chart->set_x_axis($x);
     $chart->set_y_axis($y);
     $chart->set_bg_colour('#FFFFFF');
     echo $chart->toPrettyString();
 }
Example #2
0
 function build($options = array())
 {
     if (empty($options)) {
         return false;
     }
     require_once WWW_ROOT . 'php-ofc-library/open-flash-chart.php';
     $chart = new open_flash_chart();
     if (isset($options['title']['txt'])) {
         $title = new title($options['title']['txt']);
         if (isset($options['title']['style'])) {
             $title->set_style("{" . $options['title']['style'] . "}");
         }
         $chart->set_title($title);
     }
     if (isset($options['chart']['bg'])) {
         $chart->set_bg_colour($options['chart']['bg']);
     }
     if (isset($xOptions['color'])) {
         $x->colour($xOptions['color']);
     }
     if (isset($xOptions['grid_colour'])) {
         $x->grid_colour($xOptions['grid_colour']);
     }
     $col = isset($options['color']) ? $options['color'] : null;
     $outlineCol = isset($options['outline_col']) ? $options['outline_col'] : null;
     if (isset($options['charts'])) {
         foreach ($options['charts'] as $chartOpts) {
             $type = isset($chartOpts['type']) ? $chartOpts['type'] : 'bar_filled';
             $diagram = new $type($chartOpts['col'], $chartOpts['outline']);
             if ($type == 'bar_3d') {
                 $diagram->colour = $col;
             }
             $diagram->set_values($chartOpts['values']);
             if (isset($chartOpts['key'])) {
                 $diagram->key($chartOpts['key'], 12);
             }
             $xAxis = $this->xAxis($options);
             if ($xAxis !== null) {
                 $chart->set_x_axis($xAxis);
             }
             $yAxis = $this->yAxis($options);
             if ($xAxis !== null) {
                 $chart->set_y_axis($yAxis);
             }
             if (isset($chartOpts['tooltip'])) {
                 $diagram->set_tooltip($chartOpts['tooltip']);
             }
             $chart->add_element($diagram);
         }
     }
     return $chart->toPrettyString();
 }
Example #3
0
 function get_statistic()
 {
     $this->load->library('OpenFlashChartLib', NULL, 'OFCL');
     $data_1 = array();
     $data_2 = array();
     // generate 7 data points
     for ($i = 0; $i <= 7; $i++) {
         $x = mktime(0, 0, 0, date("m"), date("d") - $i, date('Y'));
         $param['sms_date'] = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d") - $i, date("Y")));
         $param['user_id'] = $this->session->userdata('id_user');
         $y = $this->Kalkun_model->get_sms_used('date', $param);
         $data_1[] = new scatter_value($x, $y);
         $data_2[] = $y;
     }
     $def = new solid_dot();
     $def->size(4)->halo_size(0)->colour('#21759B')->tooltip('#date:d M y#<br>#val# SMS');
     $line = new scatter_line('#21759B', 3);
     $line->set_values($data_1);
     $line->set_default_dot_style($def);
     $line->set_key("SMS used in last 7 days", 10);
     $x = new x_axis();
     // grid line and tick every 10
     $x->set_range(mktime(0, 0, 0, date("m"), date("d") - 7, date('Y')), mktime(0, 0, 0, date("m"), date("d"), date('Y')));
     // show ticks and grid lines for every day:
     $x->set_steps(86400);
     $labels = new x_axis_labels();
     // tell the labels to render the number as a date:
     $labels->text('#date:M-d#');
     // generate labels for every day
     $labels->set_steps(86400);
     // only display every other label (every other day)
     $labels->visible_steps(1);
     $labels->rotate(45);
     // finally attach the label definition to the x axis
     $x->set_labels($labels);
     $y = new y_axis();
     if (max($data_2) > 0) {
         $max = max($data_2);
     } else {
         $max = 10;
     }
     $y->set_range(0, $max, 10);
     $chart = new open_flash_chart();
     //$chart->set_title( $title );
     $chart->add_element($line);
     $chart->set_x_axis($x);
     $chart->set_y_axis($y);
     echo $chart->toPrettyString();
 }
Example #4
0
$title = new title('Jumlah Data Peserta KB Per RT, RW ' . $aRw[$_REQUEST['rwId']]['nama'] . ' Total : ' . $total . ' ( ' . date("D M d Y") . ' ) ');
$title->set_style('{font-size:15px; color: #bcd6ff; margin:0px; background-color: #5E83BF;}');
$bar = new bar_3d();
$bar->set_values($jumlah);
$bar->colour = '#9999FF';
$bar->set_on_show(new bar_on_show('grow-up', 1, 0));
$labels = new x_axis_labels();
$labels->set_labels($rt);
$y_base = new y_axis_base();
$y_base->set_range(0, $maxJumlah + round($maxJumlah / 2), round($maxJumlah / 10));
$x = new x_axis();
$x->set_labels($labels);
$x->set_3d(5);
$y = new y_axis();
$y->set_labels($y_labels);
$tags = new ofc_tags();
$tags->font('Verdana', 10)->colour('#000000')->align_x_center()->text('#y#');
$i = 0;
foreach ($jumlah as $j) {
    $tags->append_tag(new ofc_tag($i, $j));
    $i++;
}
$chart = new open_flash_chart();
$chart->set_title($title);
$chart->add_element($bar);
$chart->add_element($tags);
$chart->set_x_axis($x);
$chart->set_y_axis($y_base);
echo $chart->toString();
?>
 
Example #5
0
 function _setChartdata($config)
 {
     require_once JLG_PATH_SITE . '/assets/classes/open-flash-chart/open-flash-chart.php';
     $data = $this->get('ChartData');
     // Calculate Values for Chart Object
     $forSum = array();
     $againstSum = array();
     $matchDayGoalsCount = array();
     $round_labels = array();
     foreach ($data as $rw) {
         if (!$rw->homegoalspd) {
             $rw->homegoalspd = 0;
         }
         if (!$rw->guestgoalspd) {
             $rw->guestgoalspd = 0;
         }
         $homeSum[] = (int) $rw->homegoalspd;
         $awaySum[] = (int) $rw->guestgoalspd;
         // check, if both results are missing and avoid drawing the flatline of "0" goals for not played games yet
         if (!$rw->homegoalspd && !$rw->guestgoalspd) {
             $matchDayGoalsCount[] = null;
         } else {
             $matchDayGoalsCount[] = (int) $rw->homegoalspd + $rw->guestgoalspd;
         }
         $round_labels[] = $rw->roundcode;
     }
     $chart = new open_flash_chart();
     //$chart->set_title( $title );
     $chart->set_bg_colour($config['bg_colour']);
     if (!empty($homeSum) && !empty($awaySum)) {
         if ($config['home_away_stats']) {
             $bar1 = new $config['bartype_1']();
             $bar1->set_values($homeSum);
             $bar1->set_tooltip(JText::_('COM_JOOMLEAGUE_STATS_HOME') . ": #val#");
             $bar1->set_colour($config['bar1']);
             $bar1->set_on_show(new bar_on_show($config['animation_1'], $config['cascade_1'], $config['delay_1']));
             $bar1->set_key(JText::_('COM_JOOMLEAGUE_STATS_HOME'), 12);
             $bar2 = new $config['bartype_2']();
             $bar2->set_values($awaySum);
             $bar2->set_tooltip(JText::_('COM_JOOMLEAGUE_STATS_AWAY') . ": #val#");
             $bar2->set_colour($config['bar2']);
             $bar2->set_on_show(new bar_on_show($config['animation_2'], $config['cascade_2'], $config['delay_2']));
             $bar2->set_key(JText::_('COM_JOOMLEAGUE_STATS_AWAY'), 12);
             $chart->add_element($bar1);
             $chart->add_element($bar2);
         }
     }
     // total
     $d = new $config['dotstyle_3']();
     $d->size((int) $config['line3_dot_strength']);
     $d->halo_size(1);
     $d->colour($config['line3']);
     $d->tooltip(JText::_('COM_JOOMLEAGUE_STATS_TOTAL2') . ' #val#');
     $line = new line();
     $line->set_default_dot_style($d);
     $line->set_values($matchDayGoalsCount);
     $line->set_width((int) $config['line3_strength']);
     $line->set_key(JText::_('COM_JOOMLEAGUE_STATS_TOTAL'), 12);
     $line->set_colour($config['line3']);
     $line->on_show(new line_on_show($config['l_animation_3'], $config['l_cascade_3'], $config['l_delay_3']));
     $chart->add_element($line);
     $x = new x_axis();
     $x->set_colours($config['x_axis_colour'], $config['x_axis_colour_inner']);
     $x->set_labels_from_array($round_labels);
     $chart->set_x_axis($x);
     $x_legend = new x_legend(JText::_('COM_JOOMLEAGUE_STATS_ROUNDS'));
     $x_legend->set_style('{font-size: 15px; color: #778877}');
     $chart->set_x_legend($x_legend);
     $y = new y_axis();
     $y->set_range(0, @max($matchDayGoalsCount) + 2, 1);
     $y->set_steps(round(@max($matchDayGoalsCount) / 8));
     $y->set_colours($config['y_axis_colour'], $config['y_axis_colour_inner']);
     $chart->set_y_axis($y);
     $y_legend = new y_legend(JText::_('COM_JOOMLEAGUE_STATS_GOALS'));
     $y_legend->set_style('{font-size: 15px; color: #778877}');
     $chart->set_y_legend($y_legend);
     $this->chartdata = $chart;
 }
    protected function RenderChart($oPage, $sId, $aValues, $sDrillDown = '', $aRows = array())
    {
        // 1- Compute Open Flash Chart data
        //
        $aValueKeys = array();
        $index = 0;
        if (count($aValues) > 0 && $sDrillDown != '') {
            $oFilter = DBObjectSearch::FromOQL($sDrillDown);
            $sClass = $oFilter->GetClass();
            $sOQLClause = str_replace('SELECT ' . $sClass, '', $sDrillDown);
            $aSQLColNames = array_keys(current($aRows));
            // Read the list of columns from the current (i.e. first) element of the array
            $oAppContext = new ApplicationContext();
            $sURL = utils::GetAbsoluteUrlAppRoot() . 'pages/UI.php?operation=search_oql&search_form=0&oql_class=' . $sClass . '&format=html&' . $oAppContext->GetForLink() . '&oql_clause=';
        }
        $aURLs = array();
        foreach ($aValues as $key => $value) {
            // Make sure that values are integers (so that max() will work....)
            // and build an array of STRING with the keys (numeric keys are transformed into string by PHP :-(
            $aValues[$key] = (int) $value;
            $aValueKeys[] = (string) $key;
            // Build the custom query for the 'drill down' on each element
            if ($sDrillDown != '') {
                $sFilter = $sOQLClause;
                foreach ($aSQLColNames as $sColName) {
                    $sFilter = str_replace(':' . $sColName, "'" . addslashes($aRows[$key][$sColName]) . "'", $sFilter);
                    $aURLs[$index] = $sURL . urlencode($sFilter);
                }
            }
            $index++;
        }
        $oChart = new open_flash_chart();
        if ($this->m_sType == 'bars') {
            $oChartElement = new bar_glass();
            if (count($aValues) > 0) {
                $maxValue = max($aValues);
            } else {
                $maxValue = 1;
            }
            $oYAxis = new y_axis();
            $aMagicValues = array(1, 2, 5, 10);
            $iMultiplier = 1;
            $index = 0;
            $iTop = $aMagicValues[$index % count($aMagicValues)] * $iMultiplier;
            while ($maxValue > $iTop) {
                $index++;
                $iTop = $aMagicValues[$index % count($aMagicValues)] * $iMultiplier;
                if ($index % count($aMagicValues) == 0) {
                    $iMultiplier = $iMultiplier * 10;
                }
            }
            //echo "oYAxis->set_range(0, $iTop, $iMultiplier);\n";
            $oYAxis->set_range(0, $iTop, $iMultiplier);
            $oChart->set_y_axis($oYAxis);
            $aBarValues = array();
            foreach ($aValues as $iValue) {
                $oBarValue = new bar_value($iValue);
                $oBarValue->on_click("ofc_drilldown_{$sId}");
                $aBarValues[] = $oBarValue;
            }
            $oChartElement->set_values($aBarValues);
            //$oChartElement->set_values(array_values($aValues));
            $oXAxis = new x_axis();
            $oXLabels = new x_axis_labels();
            // set them vertical
            $oXLabels->set_vertical();
            // set the label text
            $oXLabels->set_labels($aValueKeys);
            // Add the X Axis Labels to the X Axis
            $oXAxis->set_labels($oXLabels);
            $oChart->set_x_axis($oXAxis);
        } else {
            $oChartElement = new pie();
            $oChartElement->set_start_angle(35);
            $oChartElement->set_animate(true);
            $oChartElement->set_tooltip('#label# - #val# (#percent#)');
            $oChartElement->set_colours(array('#FF8A00', '#909980', '#2C2B33', '#CCC08D', '#596664'));
            $aData = array();
            foreach ($aValues as $sValue => $iValue) {
                $oPieValue = new pie_value($iValue, $sValue);
                //@@ BUG: not passed via ajax !!!
                $oPieValue->on_click("ofc_drilldown_{$sId}");
                $aData[] = $oPieValue;
            }
            $oChartElement->set_values($aData);
            $oChart->x_axis = null;
        }
        // Title given in HTML
        //$oTitle = new title($this->m_sTitle);
        //$oChart->set_title($oTitle);
        $oChart->set_bg_colour('#FFFFFF');
        $oChart->add_element($oChartElement);
        $sData = $oChart->toPrettyString();
        $sData = json_encode($sData);
        // 2- Declare the Javascript function that will render the chart data\
        //
        $oPage->add_script(<<<EOF
function ofc_get_data_{$sId}()
{
\treturn {$sData};
}
EOF
);
        if (count($aURLs) > 0) {
            $sURLList = '';
            foreach ($aURLs as $index => $sURL) {
                $sURLList .= "\taURLs[{$index}] = '" . addslashes($sURL) . "';\n";
            }
            $oPage->add_script(<<<EOF
function ofc_drilldown_{$sId}(index)
{
\tvar aURLs = new Array();
{$sURLList}
\tvar sURL = aURLs[index];
\t
\twindow.location.href = sURL; // Navigate ! 
}
EOF
);
        }
        // 3- Insert the Open Flash chart
        //
        $oPage->add("<div id=\"{$sId}\"><div>\n");
        $oPage->add_ready_script(<<<EOF
swfobject.embedSWF(\t"../images/open-flash-chart.swf", 
\t"{$sId}", 
\t"100%", "300","9.0.0",
\t"expressInstall.swf",
\t{"get-data":"ofc_get_data_{$sId}", "id":"{$sId}"}, 
\t{'wmode': 'transparent'}
);
EOF
);
    }
Example #7
0
    protected function renderHTML()
    {
        global $g_BizSystem;
        include_once MODULE_PATH . '/ser/config/cms.ChartsStatsAccCfg.php';
        $fetchInterval = $cfg_stats_acc_fetch_interval;
        $sql = "SELECT method, sip_code, time, UNIX_TIMESTAMP(time) as tstamp FROM acc WHERE DATE_SUB(NOW(), INTERVAL " . $fetchInterval . " HOUR) <= time";
        $db = $g_BizSystem->GetDBConnection("Serdb");
        $resultSet = $db->query($sql);
        if ($resultSet === false) {
            $err = $db->ErrorMsg();
            echo $err;
            exit;
        }
        $chart_colors = array();
        $chart_colors[0] = '#FF0000';
        $chart_colors[1] = '#00FF00';
        $chart_colors[2] = '#0000FF';
        $chart_colors[3] = '#408080';
        $chart_colors[4] = '#330000';
        $chart_colors[5] = '#FDD017';
        $chart_colors[6] = '#52D017';
        $chart_colors[7] = '#6698FF';
        $chart_colors[8] = '#00FFFF';
        $chart_colors[9] = '#FF00FF';
        $chart_colors[10] = '#2554C7';
        $chart_colors[11] = '#806D7E';
        $chart_colors[12] = '#FF8040';
        $chart_colors[13] = '#C0C0C0';
        $chart_colors[14] = '#808000';
        $chart_colors[15] = '#800000';
        $chart_colors_size = 16;
        $acc_records = array();
        $acc_records['invite'] = array();
        $acc_records['bye'] = array();
        $acc_records['message'] = array();
        $acc_records['other'] = array();
        $acc_records['invite200'] = array();
        $acc_records['invite404'] = array();
        $acc_records['invite487'] = array();
        $acc_records['inviteXYZ'] = array();
        for ($i = 0; $i <= $fetchInterval; $i++) {
            $acc_records['invite'][$i] = 0;
            $acc_records['bye'][$i] = 0;
            $acc_records['message'][$i] = 0;
            $acc_records['other'][$i] = 0;
            $acc_records['invite200'][$i] = 0;
            $acc_records['invite404'][$i] = 0;
            $acc_records['invite487'][$i] = 0;
            $acc_records['inviteXYZ'][$i] = 0;
        }
        $ymax = 0;
        $ymin = 0xfffffff;
        $yidx = 0;
        $ousr = 0;
        $ctime = time();
        $stime = $ctime - 3600 * $fetchInterval;
        while ($row = $resultSet->fetch()) {
            $r_method = $row[0];
            $r_sip_code = $row[1];
            $r_time = $row[2];
            $r_tstamp = $row[3];
            $idx = (int) (($r_tstamp - $stime) / 3600);
            /* method stats */
            if (isset($r_method)) {
                if ($r_method == "INVITE") {
                    $acc_records['invite'][$idx] = $acc_records['invite'][$idx] + 1;
                    if ($r_sip_code == "200") {
                        $acc_records['invite200'][$idx] = $acc_records['invite200'][$idx] + 1;
                    } else {
                        if ($r_sip_code == "404") {
                            $acc_records['invite404'][$idx] = $acc_records['invite404'][$idx] + 1;
                        } else {
                            if ($r_sip_code == "487") {
                                $acc_records['invite487'][$idx] = $acc_records['invite487'][$idx] + 1;
                            } else {
                                $acc_records['inviteXYZ'][$idx] = $acc_records['inviteXYZ'][$idx] + 1;
                            }
                        }
                    }
                } else {
                    if ($r_method == "BYE") {
                        $acc_records['bye'][$idx] = $acc_records['bye'][$idx] + 1;
                    } else {
                        if ($r_method == "MESSAGE") {
                            $acc_records['message'][$idx] = $acc_records['message'][$idx] + 1;
                        } else {
                            $acc_records['other'][$idx] = $acc_records['other'][$idx] + 1;
                        }
                    }
                }
            }
            $yidx = $yidx + 1;
        }
        /* sip method types chart */
        $mtsobj = new open_flash_chart();
        $ctitle = "SIP Method Types";
        $x = new x_axis();
        $xstep = (int) ($fetchInterval / 12);
        if ($fetchInterval % 2 != 0) {
            $xstep = $xstep + 1;
        }
        $x->set_steps($xstep);
        $time_min = $stime;
        $time_max = $ctime;
        $ctitle .= " - From " . date('Y-m-d H:i:s', $time_min);
        $ctitle .= " To " . date('Y-m-d H:i:s', $time_max);
        $time_x_labels = new x_axis_labels();
        $time_x_labels->rotate(20);
        $chart_lbls = array();
        for ($i = 0; $i < $fetchInterval; $i = $i + 1) {
            $chart_lbls[] = date('H:i', $stime + 3600 * $i);
        }
        $time_x_labels->visible_steps($xstep);
        $time_x_labels->set_labels($chart_lbls);
        $x->set_labels($time_x_labels);
        $mtsobj->set_title(new title($ctitle));
        $dot_style = new dot();
        $dot_style->size(3)->halo_size(1);
        $clr = 0;
        $i = 0;
        $line[$i] = new line();
        $line[$i]->set_default_dot_style($dot_style);
        $line[$i]->set_colour($chart_colors[$clr++ % $chart_colors_size]);
        $line[$i]->set_key("INVITE", 10);
        $line[$i]->set_values($acc_records['invite']);
        $mtsobj->add_element($line[$i]);
        $i++;
        $line[$i] = new line();
        $line[$i]->set_default_dot_style($dot_style);
        $line[$i]->set_colour($chart_colors[$clr++ % $chart_colors_size]);
        $line[$i]->set_key("BYE", 10);
        $line[$i]->set_values($acc_records['bye']);
        $mtsobj->add_element($line[$i]);
        $i++;
        if ($cfg_stats_acc_message) {
            $line[$i] = new line();
            $line[$i]->set_default_dot_style($dot_style);
            $line[$i]->set_colour($chart_colors[$clr++ % $chart_colors_size]);
            $line[$i]->set_key("MESSAGE", 10);
            $line[$i]->set_values($acc_records['message']);
            $mtsobj->add_element($line[$i]);
            $i++;
        }
        if ($cfg_stats_acc_other) {
            $line[$i] = new line();
            $line[$i]->set_default_dot_style($dot_style);
            $line[$i]->set_colour($chart_colors[$clr++ % $chart_colors_size]);
            $line[$i]->set_key("OTHER", 10);
            $line[$i]->set_values($acc_records['other']);
            $mtsobj->add_element($line[$i]);
            $i++;
        }
        $val = max($acc_records['invite']);
        if ($ymax < $val) {
            $ymax = $val;
        }
        $val = max($acc_records['bye']);
        if ($ymax < $val) {
            $ymax = $val;
        }
        if ($cfg_stats_acc_message) {
            $val = max($acc_records['message']);
            if ($ymax < $val) {
                $ymax = $val;
            }
        }
        if ($cfg_stats_acc_other) {
            $val = max($acc_records['other']);
            if ($ymax < $val) {
                $ymax = $val;
            }
        }
        $val = min($acc_records['invite']);
        if ($ymin > $val) {
            $ymin = $val;
        }
        $val = min($acc_records['bye']);
        if ($ymin > $val) {
            $ymin = $val;
        }
        if ($cfg_stats_acc_message) {
            $val = min($acc_records['message']);
            if ($ymin > $val) {
                $ymin = $val;
            }
        }
        if ($cfg_stats_acc_other) {
            $val = min($acc_records['other']);
            if ($ymin > $val) {
                $ymin = $val;
            }
        }
        if ($ymax > 10) {
            $y = new y_axis();
            if ($ymin > 10) {
                $y->set_range($ymin - 10, $ymax, (int) (($ymax - $ymin + 10) / 10));
            } else {
                $y->set_range(0, $ymax, (int) ($ymax / 10));
            }
            $mtsobj->set_y_axis($y);
        }
        $mtsobj->set_x_axis($x);
        $mtsobj->set_bg_colour("#A0C0B0");
        /* sip invites chart */
        $ivsobj = new open_flash_chart();
        $ctitle = "SIP INVITEs";
        $ctitle .= " - From " . date('Y-m-d H:i:s', $time_min);
        $ctitle .= " To " . date('Y-m-d H:i:s', $time_max);
        $ivsobj->set_title(new title($ctitle));
        $ymax = 0;
        $ymin = 0xfffffff;
        $i = 0;
        $line[$i] = new line();
        $line[$i]->set_default_dot_style($dot_style);
        $line[$i]->set_colour($chart_colors[$clr++ % $chart_colors_size]);
        $line[$i]->set_key("200", 10);
        $line[$i]->set_values($acc_records['invite200']);
        $ivsobj->add_element($line[$i]);
        $i++;
        $line[$i] = new line();
        $line[$i]->set_default_dot_style($dot_style);
        $line[$i]->set_colour($chart_colors[$clr++ % $chart_colors_size]);
        $line[$i]->set_key("404", 10);
        $line[$i]->set_values($acc_records['invite404']);
        $ivsobj->add_element($line[$i]);
        $i++;
        $line[$i] = new line();
        $line[$i]->set_default_dot_style($dot_style);
        $line[$i]->set_colour($chart_colors[$clr++ % $chart_colors_size]);
        $line[$i]->set_key("487", 10);
        $line[$i]->set_values($acc_records['invite487']);
        $ivsobj->add_element($line[$i]);
        $i++;
        $line[$i] = new line();
        $line[$i]->set_default_dot_style($dot_style);
        $line[$i]->set_colour($chart_colors[$clr++ % $chart_colors_size]);
        $line[$i]->set_key("XYZ", 10);
        $line[$i]->set_values($acc_records['inviteXYZ']);
        $ivsobj->add_element($line[$i]);
        $i++;
        $val = max($acc_records['invite200']);
        if ($ymax < $val) {
            $ymax = $val;
        }
        $val = max($acc_records['invite404']);
        if ($ymax < $val) {
            $ymax = $val;
        }
        $val = max($acc_records['invite487']);
        if ($ymax < $val) {
            $ymax = $val;
        }
        $val = max($acc_records['inviteXYZ']);
        if ($ymax < $val) {
            $ymax = $val;
        }
        $val = min($acc_records['invite200']);
        if ($ymin > $val) {
            $ymin = $val;
        }
        $val = min($acc_records['invite404']);
        if ($ymin > $val) {
            $ymin = $val;
        }
        $val = min($acc_records['invite487']);
        if ($ymin > $val) {
            $ymin = $val;
        }
        $val = min($acc_records['inviteXYZ']);
        if ($ymin > $val) {
            $ymin = $val;
        }
        if ($ymax > 10) {
            $y = new y_axis();
            if ($ymin > 10) {
                $y->set_range($ymin - 10, $ymax, (int) (($ymax - $ymin + 10) / 10));
            } else {
                $y->set_range(0, $ymax, (int) ($ymax / 10));
            }
            $ivsobj->set_y_axis($y);
        }
        $ivsobj->set_x_axis($x);
        $ivsobj->set_bg_colour("#C0C0A0");
        $sHTML = '';
        $sHTML .= '
			<div align="center">
				<p><b>Processed ' . $yidx . ' records. <br />Timezone: ' . date_default_timezone_get() . ' </b></p>
			</div>
			';
        if ($yidx > 0) {
            $sHTML .= '
			<script type="text/javascript" src="' . APP_URL . '/js/swfobject.js"></script>
			<script type="text/javascript">
				swfobject.embedSWF(
					"' . APP_URL . '/modules/ser/pages/open-flash-chart.swf",
				   	"div_chart_acc_methods",
					"600", "300", "9.0.0", "expressInstall.swf",
					{"get-data":"get_data_acc_methods"} );
				swfobject.embedSWF(
					"' . APP_URL . '/modules/ser/pages/open-flash-chart.swf",
				   	"div_chart_acc_invites",
					"600", "300", "9.0.0", "expressInstall.swf",
					{"get-data":"get_data_acc_invites"} );
			</script> 
			';
            $sHTML .= '
			<br />
			<div align="center">
				<div id="div_chart_acc_methods">
				</div>
				<br />
				<br />
				<div id="div_chart_acc_invites">
				</div>
				<br />
				<br />
			</div>
			';
            $sHTML .= '
			<script type="text/javascript">
				function get_data_acc_methods()
				{
					data = \'' . $mtsobj->toString() . '\';
					return data;
				}
				function get_data_acc_invites()
				{
					data = \'' . $ivsobj->toString() . '\';
					return data;
				}
			</script>
			';
        }
        /* if $yidx */
        return $sHTML;
    }
 function _setRankingChartdata($config)
 {
     require_once JLG_PATH_SITE . DS . "assets" . DS . "classes" . DS . "open-flash-chart" . DS . "open-flash-chart.php";
     //$data = $this->get('RankChartData');
     //some example data....fixme!!!
     $data_1 = array();
     $data_2 = array();
     for ($i = 0; $i < 6.2; $i += 0.2) {
         $data_1[] = sin($i) * 1.9 + 10;
     }
     for ($i = 0; $i < 6.2; $i += 0.2) {
         $data_2[] = sin($i) * 1.3 + 10;
     }
     $chart = new open_flash_chart();
     //***********
     //line 1
     $d = new $config['dotstyle_1']();
     $d->size((int) $config['line1_dot_strength']);
     $d->halo_size(1);
     $d->colour($config['line1']);
     $d->tooltip('Rank: #val#');
     $line = new line();
     $line->set_default_dot_style($d);
     $line->set_values($data_1);
     $line->set_width((int) $config['line1_strength']);
     ///$line->set_key($team->name, 12);
     $line->set_colour($config['line1']);
     $line->on_show(new line_on_show($config['l_animation_1'], $config['l_cascade_1'], $config['l_delay_1']));
     $chart->add_element($line);
     //Line 2
     $d = new $config['dotstyle_2']();
     $d->size((int) $config['line2_dot_strength']);
     $d->halo_size(1);
     $d->colour($config['line2']);
     $d->tooltip('Rank: #val#');
     $line = new line();
     $line->set_default_dot_style($d);
     $line->set_values($data_2);
     $line->set_width((int) $config['line2_strength']);
     //$line->set_key($team->name, 12);
     $line->set_colour($config['line2']);
     $line->on_show(new line_on_show($config['l_animation_2'], $config['l_cascade_2'], $config['l_delay_2']));
     $chart->add_element($line);
     //X-axis
     $x = new x_axis();
     $x->set_colours($config['x_axis_colour'], $config['x_axis_colour_inner']);
     //$x->set_labels_from_array($round_labels);
     $chart->set_x_axis($x);
     $x_legend = new x_legend(JText::_('COM_JOOMLEAGUE_PRED_USER_ROUNDS'));
     $x_legend->set_style('{font-size: 15px; color: #778877}');
     $chart->set_x_legend($x_legend);
     //Y-axis
     $y = new y_axis();
     $y->set_range(0, @max($data_1) + 2, 1);
     $y->set_steps(round(@max($data_1) / 8));
     $y->set_colours($config['y_axis_colour'], $config['y_axis_colour_inner']);
     $chart->set_y_axis($y);
     $y_legend = new y_legend(JText::_('COM_JOOMLEAGUE_PRED_USER_POINTS'));
     $y_legend->set_style('{font-size: 15px; color: #778877}');
     $chart->set_y_legend($y_legend);
     $this->assignRef('rankingchartdata', $chart);
 }
    public function GetRenderContent(WebPage $oPage, $aExtraParams = array(), $sId)
    {
        $sHtml = '';
        // Add the extra params into the filter if they make sense for such a filter
        $bDoSearch = utils::ReadParam('dosearch', false);
        if ($this->m_oSet == null) {
            $aQueryParams = array();
            if (isset($aExtraParams['query_params'])) {
                $aQueryParams = $aExtraParams['query_params'];
            }
            if ($this->m_sStyle != 'links') {
                $oAppContext = new ApplicationContext();
                $sClass = $this->m_oFilter->GetClass();
                $aFilterCodes = array_keys(MetaModel::GetClassFilterDefs($sClass));
                $aCallSpec = array($sClass, 'MapContextParam');
                if (is_callable($aCallSpec)) {
                    foreach ($oAppContext->GetNames() as $sContextParam) {
                        $sParamCode = call_user_func($aCallSpec, $sContextParam);
                        //Map context parameter to the value/filter code depending on the class
                        if (!is_null($sParamCode)) {
                            $sParamValue = $oAppContext->GetCurrentValue($sContextParam, null);
                            if (!is_null($sParamValue)) {
                                $aExtraParams[$sParamCode] = $sParamValue;
                            }
                        }
                    }
                }
                foreach ($aFilterCodes as $sFilterCode) {
                    $externalFilterValue = utils::ReadParam($sFilterCode, '', false, 'raw_data');
                    $condition = null;
                    if (isset($aExtraParams[$sFilterCode])) {
                        $condition = $aExtraParams[$sFilterCode];
                    }
                    if ($bDoSearch && $externalFilterValue != "") {
                        // Search takes precedence over context params...
                        unset($aExtraParams[$sFilterCode]);
                        if (!is_array($externalFilterValue)) {
                            $condition = trim($externalFilterValue);
                        } else {
                            if (count($externalFilterValue) == 1) {
                                $condition = trim($externalFilterValue[0]);
                            } else {
                                $condition = $externalFilterValue;
                            }
                        }
                    }
                    if (!is_null($condition)) {
                        $sOpCode = null;
                        // default operator
                        if (is_array($condition)) {
                            // Multiple values, add them as AND X IN (v1, v2, v3...)
                            $sOpCode = 'IN';
                        }
                        $this->AddCondition($sFilterCode, $condition, $sOpCode);
                    }
                }
                if ($bDoSearch) {
                    // Keep the table_id identifying this table if we're performing a search
                    $sTableId = utils::ReadParam('_table_id_', null, false, 'raw_data');
                    if ($sTableId != null) {
                        $aExtraParams['table_id'] = $sTableId;
                    }
                }
            }
            $aOrderBy = array();
            if (isset($aExtraParams['order_by'])) {
                // Convert the string describing the order_by parameter into an array
                // The syntax is +attCode1,-attCode2
                // attCode1 => ascending, attCode2 => descending
                $aTemp = explode(',', $aExtraParams['order_by']);
                foreach ($aTemp as $sTemp) {
                    $aMatches = array();
                    if (preg_match('/^([+-])?(.+)$/', $sTemp, $aMatches)) {
                        $bAscending = true;
                        if ($aMatches[1] == '-') {
                            $bAscending = false;
                        }
                        $aOrderBy[$aMatches[2]] = $bAscending;
                    }
                }
            }
            $this->m_oSet = new CMDBObjectSet($this->m_oFilter, $aOrderBy, $aQueryParams);
        }
        switch ($this->m_sStyle) {
            case 'count':
                if (isset($aExtraParams['group_by'])) {
                    if (isset($aExtraParams['group_by_label'])) {
                        $oGroupByExp = Expression::FromOQL($aExtraParams['group_by']);
                        $sGroupByLabel = $aExtraParams['group_by_label'];
                    } else {
                        // Backward compatibility: group_by is simply a field id
                        $sAlias = $this->m_oFilter->GetClassAlias();
                        $oGroupByExp = new FieldExpression($aExtraParams['group_by'], $sAlias);
                        $sGroupByLabel = MetaModel::GetLabel($this->m_oFilter->GetClass(), $aExtraParams['group_by']);
                    }
                    $aGroupBy = array();
                    $aGroupBy['grouped_by_1'] = $oGroupByExp;
                    $sSql = $this->m_oFilter->MakeGroupByQuery($aQueryParams, $aGroupBy, true);
                    $aRes = CMDBSource::QueryToArray($sSql);
                    $aGroupBy = array();
                    $aLabels = array();
                    $aValues = array();
                    $iTotalCount = 0;
                    foreach ($aRes as $iRow => $aRow) {
                        $sValue = $aRow['grouped_by_1'];
                        $aValues[$iRow] = $sValue;
                        $sHtmlValue = $oGroupByExp->MakeValueLabel($this->m_oFilter, $sValue, $sValue);
                        $aLabels[$iRow] = $sHtmlValue;
                        $aGroupBy[$iRow] = (int) $aRow['_itop_count_'];
                        $iTotalCount += $aRow['_itop_count_'];
                    }
                    $aData = array();
                    $oAppContext = new ApplicationContext();
                    $sParams = $oAppContext->GetForLink();
                    foreach ($aGroupBy as $iRow => $iCount) {
                        // Build the search for this subset
                        $oSubsetSearch = $this->m_oFilter->DeepClone();
                        $oCondition = new BinaryExpression($oGroupByExp, '=', new ScalarExpression($aValues[$iRow]));
                        $oSubsetSearch->AddConditionExpression($oCondition);
                        $sFilter = urlencode($oSubsetSearch->serialize());
                        $aData[] = array('group' => $aLabels[$iRow], 'value' => "<a href=\"" . utils::GetAbsoluteUrlAppRoot() . "pages/UI.php?operation=search&dosearch=1&{$sParams}&filter={$sFilter}\">{$iCount}</a>");
                        // TO DO: add the context information
                    }
                    $aAttribs = array('group' => array('label' => $sGroupByLabel, 'description' => ''), 'value' => array('label' => Dict::S('UI:GroupBy:Count'), 'description' => Dict::S('UI:GroupBy:Count+')));
                    $sFormat = isset($aExtraParams['format']) ? $aExtraParams['format'] : 'UI:Pagination:HeaderNoSelection';
                    $sHtml .= $oPage->GetP(Dict::Format($sFormat, $iTotalCount));
                    $sHtml .= $oPage->GetTable($aAttribs, $aData);
                } else {
                    // Simply count the number of elements in the set
                    $iCount = $this->m_oSet->Count();
                    $sFormat = 'UI:CountOfObjects';
                    if (isset($aExtraParams['format'])) {
                        $sFormat = $aExtraParams['format'];
                    }
                    $sHtml .= $oPage->GetP(Dict::Format($sFormat, $iCount));
                }
                break;
            case 'join':
                $aDisplayAliases = isset($aExtraParams['display_aliases']) ? explode(',', $aExtraParams['display_aliases']) : array();
                if (!isset($aExtraParams['group_by'])) {
                    $sHtml .= $oPage->GetP(Dict::S('UI:Error:MandatoryTemplateParameter_group_by'));
                } else {
                    $aGroupByFields = array();
                    $aGroupBy = explode(',', $aExtraParams['group_by']);
                    foreach ($aGroupBy as $sGroupBy) {
                        $aMatches = array();
                        if (preg_match('/^(.+)\\.(.+)$/', $sGroupBy, $aMatches) > 0) {
                            $aGroupByFields[] = array('alias' => $aMatches[1], 'att_code' => $aMatches[2]);
                        }
                    }
                    if (count($aGroupByFields) == 0) {
                        $sHtml .= $oPage->GetP(Dict::Format('UI:Error:InvalidGroupByFields', $aExtraParams['group_by']));
                    } else {
                        $aResults = array();
                        $aCriteria = array();
                        while ($aObjects = $this->m_oSet->FetchAssoc()) {
                            $aKeys = array();
                            foreach ($aGroupByFields as $aField) {
                                $sAlias = $aField['alias'];
                                if (is_null($aObjects[$sAlias])) {
                                    $aKeys[$sAlias . '.' . $aField['att_code']] = '';
                                } else {
                                    $aKeys[$sAlias . '.' . $aField['att_code']] = $aObjects[$sAlias]->Get($aField['att_code']);
                                }
                            }
                            $sCategory = implode($aKeys, ' ');
                            $aResults[$sCategory][] = $aObjects;
                            $aCriteria[$sCategory] = $aKeys;
                        }
                        $sHtml .= "<table>\n";
                        // Construct a new (parametric) query that will return the content of this block
                        $oBlockFilter = $this->m_oFilter->DeepClone();
                        $aExpressions = array();
                        $index = 0;
                        foreach ($aGroupByFields as $aField) {
                            $aExpressions[] = '`' . $aField['alias'] . '`.`' . $aField['att_code'] . '` = :param' . $index++;
                        }
                        $sExpression = implode(' AND ', $aExpressions);
                        $oExpression = Expression::FromOQL($sExpression);
                        $oBlockFilter->AddConditionExpression($oExpression);
                        $aExtraParams['menu'] = false;
                        foreach ($aResults as $sCategory => $aObjects) {
                            $sHtml .= "<tr><td><h1>{$sCategory}</h1></td></tr>\n";
                            if (count($aDisplayAliases) == 1) {
                                $aSimpleArray = array();
                                foreach ($aObjects as $aRow) {
                                    $oObj = $aRow[$aDisplayAliases[0]];
                                    if (!is_null($oObj)) {
                                        $aSimpleArray[] = $oObj;
                                    }
                                }
                                $oSet = CMDBObjectSet::FromArray($this->m_oFilter->GetClass(), $aSimpleArray);
                                $sHtml .= "<tr><td>" . cmdbAbstractObject::GetDisplaySet($oPage, $oSet, $aExtraParams) . "</td></tr>\n";
                            } else {
                                $index = 0;
                                $aArgs = array();
                                foreach ($aGroupByFields as $aField) {
                                    $aArgs['param' . $index] = $aCriteria[$sCategory][$aField['alias'] . '.' . $aField['att_code']];
                                    $index++;
                                }
                                $oSet = new CMDBObjectSet($oBlockFilter, array(), $aArgs);
                                $sHtml .= "<tr><td>" . cmdbAbstractObject::GetDisplayExtendedSet($oPage, $oSet, $aExtraParams) . "</td></tr>\n";
                            }
                        }
                        $sHtml .= "</table>\n";
                    }
                }
                break;
            case 'list':
                $aClasses = $this->m_oSet->GetSelectedClasses();
                $aAuthorizedClasses = array();
                if (count($aClasses) > 1) {
                    // Check the classes that can be read (i.e authorized) by this user...
                    foreach ($aClasses as $sAlias => $sClassName) {
                        if (UserRights::IsActionAllowed($sClassName, UR_ACTION_READ, $this->m_oSet) && (UR_ALLOWED_YES || UR_ALLOWED_DEPENDS)) {
                            $aAuthorizedClasses[$sAlias] = $sClassName;
                        }
                    }
                    if (count($aAuthorizedClasses) > 0) {
                        if ($this->m_oSet->Count() > 0) {
                            $sHtml .= cmdbAbstractObject::GetDisplayExtendedSet($oPage, $this->m_oSet, $aExtraParams);
                        } else {
                            // Empty set
                            $sHtml .= $oPage->GetP(Dict::S('UI:NoObjectToDisplay'));
                        }
                    } else {
                        // Not authorized
                        $sHtml .= $oPage->GetP(Dict::S('UI:NoObjectToDisplay'));
                    }
                } else {
                    // The list is made of only 1 class of objects, actions on the list are possible
                    if ($this->m_oSet->Count() > 0 && UserRights::IsActionAllowed($this->m_oSet->GetClass(), UR_ACTION_READ, $this->m_oSet) == UR_ALLOWED_YES) {
                        $sHtml .= cmdbAbstractObject::GetDisplaySet($oPage, $this->m_oSet, $aExtraParams);
                    } else {
                        $sHtml .= $oPage->GetP(Dict::S('UI:NoObjectToDisplay'));
                        $sClass = $this->m_oFilter->GetClass();
                        $bDisplayMenu = isset($aExtraParams['menu']) ? $aExtraParams['menu'] == true : true;
                        if ($bDisplayMenu) {
                            if (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY) == UR_ALLOWED_YES) {
                                $sLinkTarget = '';
                                $oAppContext = new ApplicationContext();
                                $sParams = $oAppContext->GetForLink();
                                // 1:n links, populate the target object as a default value when creating a new linked object
                                if (isset($aExtraParams['target_attr'])) {
                                    $sLinkTarget = ' target="_blank" ';
                                    $aExtraParams['default'][$aExtraParams['target_attr']] = $aExtraParams['object_id'];
                                }
                                $sDefault = '';
                                if (!empty($aExtraParams['default'])) {
                                    foreach ($aExtraParams['default'] as $sKey => $sValue) {
                                        $sDefault .= "&default[{$sKey}]={$sValue}";
                                    }
                                }
                                $sHtml .= $oPage->GetP("<a{$sLinkTarget} href=\"" . utils::GetAbsoluteUrlAppRoot() . "pages/UI.php?operation=new&class={$sClass}&{$sParams}{$sDefault}\">" . Dict::Format('UI:ClickToCreateNew', Metamodel::GetName($sClass)) . "</a>\n");
                            }
                        }
                    }
                }
                break;
            case 'links':
                //$bDashboardMode = isset($aExtraParams['dashboard']) ? ($aExtraParams['dashboard'] == 'true') : false;
                //$bSelectMode = isset($aExtraParams['select']) ? ($aExtraParams['select'] == 'true') : false;
                if ($this->m_oSet->Count() > 0 && UserRights::IsActionAllowed($this->m_oSet->GetClass(), UR_ACTION_READ, $this->m_oSet) == UR_ALLOWED_YES) {
                    //$sLinkage = isset($aExtraParams['linkage']) ? $aExtraParams['linkage'] : '';
                    $sHtml .= cmdbAbstractObject::GetDisplaySet($oPage, $this->m_oSet, $aExtraParams);
                } else {
                    $sClass = $this->m_oFilter->GetClass();
                    $oAttDef = MetaModel::GetAttributeDef($sClass, $this->m_aParams['target_attr']);
                    $sTargetClass = $oAttDef->GetTargetClass();
                    $sHtml .= $oPage->GetP(Dict::Format('UI:NoObject_Class_ToDisplay', MetaModel::GetName($sTargetClass)));
                    $bDisplayMenu = isset($this->m_aParams['menu']) ? $this->m_aParams['menu'] == true : true;
                    if ($bDisplayMenu) {
                        if (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY) == UR_ALLOWED_YES) {
                            $oAppContext = new ApplicationContext();
                            $sParams = $oAppContext->GetForLink();
                            $sDefaults = '';
                            if (isset($this->m_aParams['default'])) {
                                foreach ($this->m_aParams['default'] as $sName => $sValue) {
                                    $sDefaults .= '&' . urlencode($sName) . '=' . urlencode($sValue);
                                }
                            }
                            $sHtml .= $oPage->GetP("<a href=\"" . utils::GetAbsoluteUrlAppRoot() . "pages/UI.php?operation=modify_links&class={$sClass}&sParams&link_attr=" . $aExtraParams['link_attr'] . "&id=" . $aExtraParams['object_id'] . "&target_class={$sTargetClass}&addObjects=true{$sDefaults}\">" . Dict::Format('UI:ClickToCreateNew', Metamodel::GetName($sClass)) . "</a>\n");
                        }
                    }
                }
                break;
            case 'details':
                while ($oObj = $this->m_oSet->Fetch()) {
                    $sHtml .= $oObj->GetDetails($oPage);
                    // Still used ???
                }
                break;
            case 'actions':
                $sClass = $this->m_oFilter->GetClass();
                $oAppContext = new ApplicationContext();
                $bContextFilter = isset($aExtraParams['context_filter']) ? isset($aExtraParams['context_filter']) != 0 : false;
                if ($bContextFilter) {
                    $aFilterCodes = array_keys(MetaModel::GetClassFilterDefs($this->m_oFilter->GetClass()));
                    foreach ($oAppContext->GetNames() as $sFilterCode) {
                        $sContextParamValue = $oAppContext->GetCurrentValue($sFilterCode, null);
                        if (!is_null($sContextParamValue) && !empty($sContextParamValue) && MetaModel::IsValidFilterCode($sClass, $sFilterCode)) {
                            $this->AddCondition($sFilterCode, $sContextParamValue);
                        }
                    }
                    $aQueryParams = array();
                    if (isset($aExtraParams['query_params'])) {
                        $aQueryParams = $aExtraParams['query_params'];
                    }
                    $this->m_oSet = new CMDBObjectSet($this->m_oFilter, array(), $aQueryParams);
                }
                $iCount = $this->m_oSet->Count();
                $sHyperlink = utils::GetAbsoluteUrlAppRoot() . 'pages/UI.php?operation=search&' . $oAppContext->GetForLink() . '&filter=' . urlencode($this->m_oFilter->serialize());
                $sHtml .= '<p><a class="actions" href="' . $sHyperlink . '">';
                // Note: border set to 0 due to various browser interpretations (IE9 adding a 2px border)
                $sHtml .= MetaModel::GetClassIcon($sClass, true, 'float;left;margin-right:10px;border:0;');
                $sHtml .= MetaModel::GetName($sClass) . ': ' . $iCount . '</a></p>';
                $sParams = $oAppContext->GetForLink();
                $sHtml .= '<p>';
                if (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY)) {
                    $sHtml .= "<a href=\"" . utils::GetAbsoluteUrlAppRoot() . "pages/UI.php?operation=new&class={$sClass}&{$sParams}\">" . Dict::Format('UI:ClickToCreateNew', MetaModel::GetName($sClass)) . "</a><br/>\n";
                }
                $sHtml .= "<a href=\"" . utils::GetAbsoluteUrlAppRoot() . "pages/UI.php?operation=search_form&do_search=0&class={$sClass}&{$sParams}\">" . Dict::Format('UI:SearchFor_Class', MetaModel::GetName($sClass)) . "</a>\n";
                $sHtml .= '</p>';
                break;
            case 'summary':
                $sClass = $this->m_oFilter->GetClass();
                $oAppContext = new ApplicationContext();
                $sTitle = isset($aExtraParams['title[block]']) ? $aExtraParams['title[block]'] : '';
                $sLabel = isset($aExtraParams['label[block]']) ? $aExtraParams['label[block]'] : '';
                $sStateAttrCode = isset($aExtraParams['status[block]']) ? $aExtraParams['status[block]'] : 'status';
                $sStatesList = isset($aExtraParams['status_codes[block]']) ? $aExtraParams['status_codes[block]'] : '';
                $bContextFilter = isset($aExtraParams['context_filter']) ? isset($aExtraParams['context_filter']) != 0 : false;
                if ($bContextFilter) {
                    $aFilterCodes = array_keys(MetaModel::GetClassFilterDefs($this->m_oFilter->GetClass()));
                    foreach ($oAppContext->GetNames() as $sFilterCode) {
                        $sContextParamValue = $oAppContext->GetCurrentValue($sFilterCode, null);
                        if (!is_null($sContextParamValue) && !empty($sContextParamValue) && MetaModel::IsValidFilterCode($sClass, $sFilterCode)) {
                            $this->AddCondition($sFilterCode, $sContextParamValue);
                        }
                    }
                    $aQueryParams = array();
                    if (isset($aExtraParams['query_params'])) {
                        $aQueryParams = $aExtraParams['query_params'];
                    }
                    $this->m_oSet = new CMDBObjectSet($this->m_oFilter, array(), $aQueryParams);
                }
                // Summary details
                $aCounts = array();
                $aStateLabels = array();
                if (!empty($sStateAttrCode) && !empty($sStatesList)) {
                    $aStates = explode(',', $sStatesList);
                    $oAttDef = MetaModel::GetAttributeDef($sClass, $sStateAttrCode);
                    foreach ($aStates as $sStateValue) {
                        $oFilter = $this->m_oFilter->DeepClone();
                        $oFilter->AddCondition($sStateAttrCode, $sStateValue, '=');
                        $oSet = new DBObjectSet($oFilter);
                        $aCounts[$sStateValue] = $oSet->Count();
                        $aStateLabels[$sStateValue] = htmlentities($oAttDef->GetValueLabel($sStateValue), ENT_QUOTES, 'UTF-8');
                        if ($aCounts[$sStateValue] == 0) {
                            $aCounts[$sStateValue] = '-';
                        } else {
                            $sHyperlink = utils::GetAbsoluteUrlAppRoot() . 'pages/UI.php?operation=search&' . $oAppContext->GetForLink() . '&filter=' . urlencode($oFilter->serialize());
                            $aCounts[$sStateValue] = "<a href=\"{$sHyperlink}\">{$aCounts[$sStateValue]}</a>";
                        }
                    }
                }
                $sHtml .= '<div class="summary-details"><table><tr><th>' . implode('</th><th>', $aStateLabels) . '</th></tr>';
                $sHtml .= '<tr><td>' . implode('</td><td>', $aCounts) . '</td></tr></table></div>';
                // Title & summary
                $iCount = $this->m_oSet->Count();
                $sHyperlink = utils::GetAbsoluteUrlAppRoot() . 'pages/UI.php?operation=search&' . $oAppContext->GetForLink() . '&filter=' . urlencode($this->m_oFilter->serialize());
                $sHtml .= '<h1>' . Dict::S(str_replace('_', ':', $sTitle)) . '</h1>';
                $sHtml .= '<a class="summary" href="' . $sHyperlink . '">' . Dict::Format(str_replace('_', ':', $sLabel), $iCount) . '</a>';
                $sHtml .= '<div style="clear:both;"></div>';
                break;
            case 'csv':
                $bAdvancedMode = utils::ReadParam('advanced', false);
                $sCsvFile = strtolower($this->m_oFilter->GetClass()) . '.csv';
                $sDownloadLink = utils::GetAbsoluteUrlAppRoot() . 'webservices/export.php?expression=' . urlencode($this->m_oFilter->ToOQL(true)) . '&format=csv&filename=' . urlencode($sCsvFile);
                $sLinkToToggle = utils::GetAbsoluteUrlAppRoot() . 'pages/UI.php?operation=search&' . $oAppContext->GetForLink() . '&filter=' . urlencode($this->m_oFilter->serialize()) . '&format=csv';
                if ($bAdvancedMode) {
                    $sDownloadLink .= '&fields_advanced=1';
                    $sChecked = 'CHECKED';
                } else {
                    $sLinkToToggle = $sLinkToToggle . '&advanced=1';
                    $sChecked = '';
                }
                $sAjaxLink = $sDownloadLink . '&charset=UTF-8';
                // Includes &fields_advanced=1 if in advanced mode
                /*
                			$sCSVData = cmdbAbstractObject::GetSetAsCSV($this->m_oSet, array('fields_advanced' => $bAdvancedMode));
                			$sCharset = MetaModel::GetConfig()->Get('csv_file_default_charset');
                			if ($sCharset == 'UTF-8')
                			{
                				$bLostChars = false;
                			}
                			else
                			{
                				$sConverted = @iconv('UTF-8', $sCharset, $sCSVData);
                				$sRestored = @iconv($sCharset, 'UTF-8', $sConverted);
                				$bLostChars = ($sRestored != $sCSVData);
                			}
                			if ($bLostChars)
                			{
                				$sCharsetNotice = "&nbsp;&nbsp;<span id=\"csv_charset_issue\">";
                				$sCharsetNotice .= '<img src="../images/error.png"  style="vertical-align:middle"/>';
                				$sCharsetNotice .= "</span>";
                				$sTip = "<p>".htmlentities(Dict::S('UI:CSVExport:LostChars'), ENT_QUOTES, 'UTF-8')."</p>";
                				$sTip .= "<p>".htmlentities(Dict::Format('UI:CSVExport:LostChars+', $sCharset), ENT_QUOTES, 'UTF-8')."</p>";
                				$oPage->add_ready_script("$('#csv_charset_issue').qtip( { content: '$sTip', show: 'mouseover', hide: 'mouseout', style: { name: 'dark', tip: 'leftTop' }, position: { corner: { target: 'rightMiddle', tooltip: 'leftTop' }} } );");
                			}
                			else
                			{
                				$sCharsetNotice = '';
                			}
                */
                $sCharsetNotice = false;
                $sHtml .= "<div>";
                $sHtml .= '<table style="width:100%" class="transparent">';
                $sHtml .= '<tr>';
                $sHtml .= '<td><a href="' . $sDownloadLink . '">' . Dict::Format('UI:Download-CSV', $sCsvFile) . '</a>' . $sCharsetNotice . '</td>';
                $sHtml .= '<td style="text-align:right"><input type="checkbox" ' . $sChecked . ' onClick="window.location.href=\'' . $sLinkToToggle . '\'">&nbsp;' . Dict::S('UI:CSVExport:AdvancedMode') . '</td>';
                $sHtml .= '</tr>';
                $sHtml .= '</table>';
                if ($bAdvancedMode) {
                    $sHtml .= "<p>";
                    $sHtml .= htmlentities(Dict::S('UI:CSVExport:AdvancedMode+'), ENT_QUOTES, 'UTF-8');
                    $sHtml .= "</p>";
                }
                $sHtml .= "</div>";
                $sHtml .= "<div id=\"csv_content_loading\"><div style=\"width: 250px; height: 20px; background: url(../setup/orange-progress.gif); border: 1px #999 solid; margin-left:auto; margin-right: auto; text-align: center;\">" . Dict::S('UI:Loading') . "</div></div><textarea id=\"csv_content\" style=\"display:none;\">\n";
                //$sHtml .= htmlentities($sCSVData, ENT_QUOTES, 'UTF-8');
                $sHtml .= "</textarea>\n";
                $oPage->add_ready_script("\$.post('{$sAjaxLink}', {}, function(data) { \$('#csv_content').html(data); \$('#csv_content_loading').hide(); \$('#csv_content').show();} );");
                break;
            case 'modify':
                if (UserRights::IsActionAllowed($this->m_oSet->GetClass(), UR_ACTION_MODIFY, $this->m_oSet) == UR_ALLOWED_YES) {
                    while ($oObj = $this->m_oSet->Fetch()) {
                        $sHtml .= $oObj->GetModifyForm($oPage);
                    }
                }
                break;
            case 'search':
                $sStyle = isset($aExtraParams['open']) && $aExtraParams['open'] == 'true' ? 'SearchDrawer' : 'SearchDrawer DrawerClosed';
                $sHtml .= "<div id=\"ds_{$sId}\" class=\"{$sStyle}\">\n";
                $oPage->add_ready_script(<<<EOF
\t\$("#dh_{$sId}").click( function() {
\t\t\$("#ds_{$sId}").slideToggle('normal', function() { \$("#ds_{$sId}").parent().resize(); FixSearchFormsDisposition(); } );
\t\t\$("#dh_{$sId}").toggleClass('open');
\t});
EOF
);
                $aExtraParams['currentId'] = $sId;
                $sHtml .= cmdbAbstractObject::GetSearchForm($oPage, $this->m_oSet, $aExtraParams);
                $sHtml .= "</div>\n";
                $sHtml .= "<div class=\"HRDrawer\"></div>\n";
                $sHtml .= "<div id=\"dh_{$sId}\" class=\"DrawerHandle\">" . Dict::S('UI:SearchToggle') . "</div>\n";
                break;
            case 'open_flash_chart':
                static $iChartCounter = 0;
                $oAppContext = new ApplicationContext();
                $sContext = $oAppContext->GetForLink();
                if (!empty($sContext)) {
                    $sContext = '&' . $sContext;
                }
                $sChartType = isset($aExtraParams['chart_type']) ? $aExtraParams['chart_type'] : 'pie';
                $sTitle = isset($aExtraParams['chart_title']) ? $aExtraParams['chart_title'] : '';
                $sGroupBy = isset($aExtraParams['group_by']) ? $aExtraParams['group_by'] : '';
                $sGroupByExpr = isset($aExtraParams['group_by_expr']) ? '&params[group_by_expr]=' . $aExtraParams['group_by_expr'] : '';
                $sFilter = $this->m_oFilter->serialize();
                $sHtml .= "<div id=\"my_chart_{$sId}{$iChartCounter}\">If the chart does not display, <a href=\"http://get.adobe.com/flash/\" target=\"_blank\">install Flash</a></div>\n";
                $oPage->add_script("function ofc_resize(left, width, top, height) { /* do nothing special */ }");
                if (isset($aExtraParams['group_by_label'])) {
                    $sUrl = urlencode(utils::GetAbsoluteUrlAppRoot() . "pages/ajax.render.php?operation=open_flash_chart&params[group_by]={$sGroupBy}{$sGroupByExpr}&params[group_by_label]={$aExtraParams['group_by_label']}&params[chart_type]={$sChartType}&params[chart_title]={$sTitle}&params[currentId]={$sId}&id={$sId}&filter=" . urlencode($sFilter));
                } else {
                    $sUrl = urlencode(utils::GetAbsoluteUrlAppRoot() . "pages/ajax.render.php?operation=open_flash_chart&params[group_by]={$sGroupBy}{$sGroupByExpr}&params[chart_type]={$sChartType}&params[chart_title]={$sTitle}&params[currentId]={$sId}&id={$sId}&filter=" . urlencode($sFilter));
                }
                $oPage->add_ready_script("swfobject.embedSWF(\"../images/open-flash-chart.swf\", \"my_chart_{$sId}{$iChartCounter}\", \"100%\", \"300\",\"9.0.0\", \"expressInstall.swf\",\n\t\t\t\t{\"data-file\":\"" . $sUrl . "\"}, {wmode: 'transparent'} );\n");
                $iChartCounter++;
                if (isset($aExtraParams['group_by'])) {
                    if (isset($aExtraParams['group_by_label'])) {
                        $oGroupByExp = Expression::FromOQL($aExtraParams['group_by']);
                        $sGroupByLabel = $aExtraParams['group_by_label'];
                    } else {
                        // Backward compatibility: group_by is simply a field id
                        $sAlias = $this->m_oFilter->GetClassAlias();
                        $oGroupByExp = new FieldExpression($aExtraParams['group_by'], $sAlias);
                        $sGroupByLabel = MetaModel::GetLabel($this->m_oFilter->GetClass(), $aExtraParams['group_by']);
                    }
                    $aGroupBy = array();
                    $aGroupBy['grouped_by_1'] = $oGroupByExp;
                    $sSql = $this->m_oFilter->MakeGroupByQuery($aQueryParams, $aGroupBy, true);
                    $aRes = CMDBSource::QueryToArray($sSql);
                    $aGroupBy = array();
                    $aLabels = array();
                    $aValues = array();
                    $iTotalCount = 0;
                    foreach ($aRes as $iRow => $aRow) {
                        $sValue = $aRow['grouped_by_1'];
                        $aValues[$iRow] = $sValue;
                        $sHtmlValue = $oGroupByExp->MakeValueLabel($this->m_oFilter, $sValue, $sValue);
                        $aLabels[$iRow] = $sHtmlValue;
                        $aGroupBy[$iRow] = (int) $aRow['_itop_count_'];
                        $iTotalCount += $aRow['_itop_count_'];
                    }
                    $aData = array();
                    $idx = 0;
                    $aURLs = array();
                    foreach ($aGroupBy as $iRow => $iCount) {
                        // Build the search for this subset
                        $oSubsetSearch = $this->m_oFilter->DeepClone();
                        $oCondition = new BinaryExpression($oGroupByExp, '=', new ScalarExpression($aValues[$iRow]));
                        $oSubsetSearch->AddConditionExpression($oCondition);
                        $aURLs[$idx] = $oSubsetSearch->serialize();
                        $idx++;
                    }
                    $sURLList = '';
                    foreach ($aURLs as $index => $sURL) {
                        $sURLList .= "\taURLs[{$index}] = '" . utils::GetAbsoluteUrlAppRoot() . "pages/UI.php?operation=search&format=html{$sContext}&filter=" . urlencode($sURL) . "';\n";
                    }
                    $oPage->add_script(<<<EOF
function ofc_drill_down_{$sId}(index)
{
\tvar aURLs = new Array();
{$sURLList}
\twindow.location.href=aURLs[index];
}
EOF
);
                }
                break;
            case 'open_flash_chart_ajax':
                require_once APPROOT . '/pages/php-ofc-library/open-flash-chart.php';
                $sChartType = isset($aExtraParams['chart_type']) ? $aExtraParams['chart_type'] : 'pie';
                $sId = utils::ReadParam('id', '');
                $oChart = new open_flash_chart();
                switch ($sChartType) {
                    case 'bars':
                        $oChartElement = new bar_glass();
                        if (isset($aExtraParams['group_by'])) {
                            if (isset($aExtraParams['group_by_label'])) {
                                $oGroupByExp = Expression::FromOQL($aExtraParams['group_by']);
                                $sGroupByLabel = $aExtraParams['group_by_label'];
                            } else {
                                // Backward compatibility: group_by is simply a field id
                                $sAlias = $this->m_oFilter->GetClassAlias();
                                $oGroupByExp = new FieldExpression($aExtraParams['group_by'], $sAlias);
                                $sGroupByLabel = MetaModel::GetLabel($this->m_oFilter->GetClass(), $aExtraParams['group_by']);
                            }
                            $aGroupBy = array();
                            $aGroupBy['grouped_by_1'] = $oGroupByExp;
                            $sSql = $this->m_oFilter->MakeGroupByQuery($aQueryParams, $aGroupBy, true);
                            $aRes = CMDBSource::QueryToArray($sSql);
                            $aGroupBy = array();
                            $aLabels = array();
                            $iTotalCount = 0;
                            foreach ($aRes as $iRow => $aRow) {
                                $sValue = $aRow['grouped_by_1'];
                                $sHtmlValue = $oGroupByExp->MakeValueLabel($this->m_oFilter, $sValue, $sValue);
                                $aLabels[$iRow] = strip_tags($sHtmlValue);
                                $aGroupBy[$iRow] = (int) $aRow['_itop_count_'];
                                $iTotalCount += $aRow['_itop_count_'];
                            }
                            $aData = array();
                            $aChartLabels = array();
                            $maxValue = 0;
                            foreach ($aGroupBy as $iRow => $iCount) {
                                $oBarValue = new bar_value($iCount);
                                $oBarValue->on_click("ofc_drill_down_{$sId}");
                                $aData[] = $oBarValue;
                                if ($iCount > $maxValue) {
                                    $maxValue = $iCount;
                                }
                                $aChartLabels[] = html_entity_decode($aLabels[$iRow], ENT_QUOTES, 'UTF-8');
                            }
                            $oYAxis = new y_axis();
                            $aMagicValues = array(1, 2, 5, 10);
                            $iMultiplier = 1;
                            $index = 0;
                            $iTop = $aMagicValues[$index % count($aMagicValues)] * $iMultiplier;
                            while ($maxValue > $iTop) {
                                $index++;
                                $iTop = $aMagicValues[$index % count($aMagicValues)] * $iMultiplier;
                                if ($index % count($aMagicValues) == 0) {
                                    $iMultiplier = $iMultiplier * 10;
                                }
                            }
                            //echo "oYAxis->set_range(0, $iTop, $iMultiplier);\n";
                            $oYAxis->set_range(0, $iTop, $iMultiplier);
                            $oChart->set_y_axis($oYAxis);
                            $oChartElement->set_values($aData);
                            $oXAxis = new x_axis();
                            $oXLabels = new x_axis_labels();
                            // set them vertical
                            $oXLabels->set_vertical();
                            // set the label text
                            $oXLabels->set_labels($aChartLabels);
                            // Add the X Axis Labels to the X Axis
                            $oXAxis->set_labels($oXLabels);
                            $oChart->set_x_axis($oXAxis);
                        }
                        break;
                    case 'pie':
                    default:
                        $oChartElement = new pie();
                        $oChartElement->set_start_angle(35);
                        $oChartElement->set_animate(true);
                        $oChartElement->set_tooltip('#label# - #val# (#percent#)');
                        $oChartElement->set_colours(array('#FF8A00', '#909980', '#2C2B33', '#CCC08D', '#596664'));
                        if (isset($aExtraParams['group_by'])) {
                            if (isset($aExtraParams['group_by_label'])) {
                                $oGroupByExp = Expression::FromOQL($aExtraParams['group_by']);
                                $sGroupByLabel = $aExtraParams['group_by_label'];
                            } else {
                                // Backward compatibility: group_by is simply a field id
                                $sAlias = $this->m_oFilter->GetClassAlias();
                                $oGroupByExp = new FieldExpression($aExtraParams['group_by'], $sAlias);
                                $sGroupByLabel = MetaModel::GetLabel($this->m_oFilter->GetClass(), $aExtraParams['group_by']);
                            }
                            $aGroupBy = array();
                            $aGroupBy['grouped_by_1'] = $oGroupByExp;
                            $sSql = $this->m_oFilter->MakeGroupByQuery($aQueryParams, $aGroupBy, true);
                            $aRes = CMDBSource::QueryToArray($sSql);
                            $aGroupBy = array();
                            $aLabels = array();
                            $iTotalCount = 0;
                            foreach ($aRes as $iRow => $aRow) {
                                $sValue = $aRow['grouped_by_1'];
                                $sHtmlValue = $oGroupByExp->MakeValueLabel($this->m_oFilter, $sValue, $sValue);
                                $aLabels[$iRow] = strip_tags($sHtmlValue);
                                $aGroupBy[$iRow] = (int) $aRow['_itop_count_'];
                                $iTotalCount += $aRow['_itop_count_'];
                            }
                            $aData = array();
                            foreach ($aGroupBy as $iRow => $iCount) {
                                $sFlashLabel = html_entity_decode($aLabels[$iRow], ENT_QUOTES, 'UTF-8');
                                $PieValue = new pie_value($iCount, $sFlashLabel);
                                //@@ BUG: not passed via ajax !!!
                                $PieValue->on_click("ofc_drill_down_{$sId}");
                                $aData[] = $PieValue;
                            }
                            $oChartElement->set_values($aData);
                            $oChart->x_axis = null;
                        }
                }
                if (isset($aExtraParams['chart_title'])) {
                    // The title has been given in an url, and urlencoded...
                    // and urlencode transforms utf-8 into something similar to ISO-8859-1
                    // Example: é (C3A9 becomes %E9)
                    // As a consequence, json_encode (called within open-flash-chart.php)
                    // was returning 'null' and the graph was not displayed at all
                    // To make sure that the graph is displayed AND to get a correct title
                    // (at least for european characters) let's transform back into utf-8 !
                    $sTitle = iconv("ISO-8859-1", "UTF-8//IGNORE", $aExtraParams['chart_title']);
                    // If the title is a dictionnary entry, fetch it
                    $sTitle = Dict::S($sTitle);
                    $oTitle = new title($sTitle);
                    $oChart->set_title($oTitle);
                    $oTitle->set_style("{font-size: 16px; font-family: Tahoma; font-weight: bold; text-align: center;}");
                }
                $oChart->set_bg_colour('#FFFFFF');
                $oChart->add_element($oChartElement);
                $sHtml = $oChart->toPrettyString();
                break;
            default:
                // Unsupported style, do nothing.
                $sHtml .= Dict::format('UI:Error:UnsupportedStyleOfBlock', $this->m_sStyle);
        }
        return $sHtml;
    }
Example #10
0
');
$deposits = array();
$withdrawals = array();
$weeks = array();
while ($row = mysql_fetch_assoc($result)) {
    $weeks[] = date('d.m.Y', $row['stamp']);
    $deposits[] = round($row['deposits'], 2);
    $withdrawals[] = -round($row['withdrawals'], 2);
}
//lines
$line1 = new line();
$line1->set_values($deposits);
$line1->set_colour('#00FF00');
$line2 = new line();
$line2->set_values($withdrawals);
$line2->set_colour('#FF0000');
//axises
$axis_x = new x_axis();
$axis_x_labels = new x_axis_labels();
$axis_x_labels->set_labels($weeks);
$axis_x->set_labels($axis_x_labels);
$axis_y = new y_axis();
$axis_y->range(0, max(max($deposits), max($withdrawals)), 1000);
//chart
$chart = new open_flash_chart();
$chart->set_y_axis($axis_y);
$chart->set_x_axis($axis_x);
$chart->add_element($line1);
$chart->add_element($line2);
$chart->set_bg_colour('#FFFFFF');
echo $chart->toPrettyString();
    public function RenderNoData($oPage, $bEditMode = false, $aExtraParams = array())
    {
        $sTitle = $this->aProperties['title'];
        $aDisplayValues = $this->MakeSimulatedData();
        require_once APPROOT . '/pages/php-ofc-library/open-flash-chart.php';
        $oChart = new open_flash_chart();
        $aGroupBy = array();
        $aLabels = array();
        foreach ($aDisplayValues as $iRow => $aDisplayData) {
            $aLabels[$iRow] = $aDisplayData['label'];
            $aGroupBy[$iRow] = (int) $aDisplayData['count'];
        }
        $oChartElement = new bar_glass();
        $aData = array();
        $aChartLabels = array();
        $maxValue = 0;
        foreach ($aGroupBy as $iRow => $iCount) {
            $oBarValue = new bar_value($iCount);
            $aData[] = $oBarValue;
            if ($iCount > $maxValue) {
                $maxValue = $iCount;
            }
            $aChartLabels[] = html_entity_decode($aLabels[$iRow], ENT_QUOTES, 'UTF-8');
        }
        $oYAxis = new y_axis();
        $aMagicValues = array(1, 2, 5, 10);
        $iMultiplier = 1;
        $index = 0;
        $iTop = $aMagicValues[$index % count($aMagicValues)] * $iMultiplier;
        while ($maxValue > $iTop) {
            $index++;
            $iTop = $aMagicValues[$index % count($aMagicValues)] * $iMultiplier;
            if ($index % count($aMagicValues) == 0) {
                $iMultiplier = $iMultiplier * 10;
            }
        }
        //echo "oYAxis->set_range(0, $iTop, $iMultiplier);\n";
        $oYAxis->set_range(0, $iTop, $iMultiplier);
        $oChart->set_y_axis($oYAxis);
        $oChartElement->set_values($aData);
        $oXAxis = new x_axis();
        $oXLabels = new x_axis_labels();
        // set them vertical
        $oXLabels->set_vertical();
        // set the label text
        $oXLabels->set_labels($aChartLabels);
        // Add the X Axis Labels to the X Axis
        $oXAxis->set_labels($oXLabels);
        $oChart->set_x_axis($oXAxis);
        if (!empty($sTitle)) {
            // The title has been given in an url, and urlencoded...
            // and urlencode transforms utf-8 into something similar to ISO-8859-1
            // Example: é (C3A9 becomes %E9)
            // As a consequence, json_encode (called within open-flash-chart.php)
            // was returning 'null' and the graph was not displayed at all
            // To make sure that the graph is displayed AND to get a correct title
            // (at least for european characters) let's transform back into utf-8 !
            $sTitle = iconv("ISO-8859-1", "UTF-8//IGNORE", $sTitle);
            // If the title is a dictionnary entry, fetch it
            $sTitle = $this->oModelReflection->DictString($sTitle);
            $oTitle = new title($sTitle);
            $oChart->set_title($oTitle);
            $oTitle->set_style("{font-size: 16px; font-family: Tahoma; font-weight: bold; text-align: center;}");
        }
        $oChart->set_bg_colour('#FFFFFF');
        $oChart->add_element($oChartElement);
        $sData = $oChart->toPrettyString();
        $sData = json_encode($sData);
        $oPage->add_script(<<<EOF
function ofc_get_data_dashlet_{$this->sId}()
{
\treturn {$sData};
}
EOF
);
        $oPage->add('<div class="dashlet-content">');
        $oPage->add("<div id=\"dashlet_chart_{$this->sId}\">If the chart does not display, <a href=\"http://get.adobe.com/flash/\" target=\"_blank\">install Flash</a></div>\n");
        $oPage->add('</div>');
        //		$oPage->add_script("function ofc_resize(left, width, top, height) { /* do nothing special */ }");
        $oPage->add_ready_script(<<<EOF
swfobject.embedSWF(\t"../images/open-flash-chart.swf", 
\t"dashlet_chart_{$this->sId}", 
\t"100%", "300","9.0.0",
\t"expressInstall.swf",
\t{"get-data":"ofc_get_data_dashlet_{$this->sId}", "id":"dashlet_chart_{$this->sId}"}, 
\t{'wmode': 'transparent'}
);
EOF
);
    }
Example #12
0
 function loadaverage()
 {
     sleep(1);
     $uptime = trim(shell_exec("cat /proc/uptime  |awk '{print \$1}' |cut -d '.' -f 1"));
     $load_average_1min = trim(shell_exec("cat /proc/loadavg |awk '{print \$1}'"));
     $load_average_5min = trim(shell_exec("cat /proc/loadavg |awk '{print \$2}'"));
     $load_average_15min = trim(shell_exec("cat /proc/loadavg |awk '{print \$3}'"));
     if ($load_average_1min <= 1) {
         $stats = '当前系统空闲';
     } elseif ($load_average_1min <= 4) {
         $stats = '当前系统正常';
     } else {
         $stats = '当前系统繁忙';
     }
     $days = floor($uptime / 86400);
     $hours = floor($uptime % 86400 / 3600);
     $minutes = floor($uptime % 3600 / 60);
     $title = new title("系统平均负载\n{$stats}");
     $title->set_style("{font-size: 12px; font-family: Times New Roman; font-weight: bold; color: #A2ACBA; text-align: center;}");
     settype($load_average_1min, "float");
     settype($load_average_5min, "float");
     settype($load_average_15min, "float");
     $load_average = array($load_average_1min, $load_average_5min, $load_average_15min);
     function colour($value)
     {
         if ($value <= 1) {
             $colour = "#339900";
         } elseif ($value <= 4) {
             $colour = "#FFFF00";
         } else {
             $colour = "#FF0033";
         }
         return $colour;
     }
     if (max($load_average) <= 0.5) {
         $y_axis_max = 0.5;
     } elseif (max($load_average) <= 1) {
         $y_axis_max = 1;
     } elseif (max($load_average) <= 5) {
         $y_axis_max = 5;
     } elseif (max($load_average) <= 10) {
         $y_axis_max = 10;
     } elseif (max($load_average) <= 50) {
         $y_axis_max = 50;
     } else {
         $y_axis_max = 100;
     }
     $y_axis_step = $y_axis_max / 5;
     if ($load_average_1min == 0) {
         $data[0] = new bar_value($y_axis_max / 100);
         $data[0]->set_colour(colour($load_average_1min));
         $data[0]->set_tooltip(0);
     } else {
         $data[0] = new bar_value($load_average_1min);
         $data[0]->set_colour(colour($load_average_1min));
         $data[0]->set_tooltip('#val#');
     }
     if ($load_average_5min == 0) {
         $data[1] = new bar_value($y_axis_max / 100);
         $data[1]->set_colour(colour($load_average_5min));
         $data[1]->set_tooltip(0);
     } else {
         $data[1] = new bar_value($load_average_5min);
         $data[1]->set_colour(colour($load_average_5min));
         $data[1]->set_tooltip('#val#');
     }
     if ($load_average_15min == 0) {
         $data[2] = new bar_value($y_axis_max / 100);
         $data[2]->set_colour(colour($load_average_15min));
         $data[2]->set_tooltip(0);
     } else {
         $data[2] = new bar_value($load_average_15min);
         $data[2]->set_colour(colour($load_average_15min));
         $data[2]->set_tooltip('#val#');
     }
     $bar = new bar_glass();
     $bar->set_values($data);
     $x = new x_axis();
     $x->set_labels_from_array(array('1分钟', '5分钟', '15分钟'));
     $y = new y_axis();
     $y->set_range(0, $y_axis_max, $y_axis_step);
     $chart = new open_flash_chart();
     $chart->set_title($title);
     $chart->add_element($bar);
     $chart->set_bg_colour('#FFFFFF');
     $chart->set_x_axis($x);
     $chart->set_y_axis($y);
     $x_legend = new x_legend("系统当前已运行 {$days} 天 {$hours} 小时 {$minutes} 分钟");
     $x_legend->set_style('{font-size: 12px; color: #778877}');
     $chart->set_x_legend($x_legend);
     header("Cache-Control: cache, must-revalidate");
     header("Pragma: public");
     echo $chart->toString();
 }
Example #13
0
function siremis_get_chart_data($groupId, $chartId, $debug = 0)
{
    global $g_BizSystem;
    $cgobj = $g_BizSystem->GetService("ser.service.siremisCharts");
    $cgrp = $cgobj->GetChartGroup($groupId);
    if ($debug == 1) {
        echo "Chart found {$id} :: " . $cgobj->GetChartGroupCount() . " ::: ";
    }
    $chart = $cgrp->GetChart($chartId);
    if (!$chart) {
        echo "Chart not found {$id}\n";
        exit;
    }
    if ($debug == 1) {
        echo "Chart :: " . $cgrp->GetChartCount() . " ::: ";
    }
    $sql = "SELECT * ";
    $xydata = array();
    // XAxis
    $xax = $chart->GetXAxisList();
    foreach ($xax as $it) {
        $sql = "SELECT " . $it->GetXYData();
        $xydata[0] = $it;
    }
    // YAxis
    $yax = $chart->GetYAxisList();
    $yn = 0;
    foreach ($yax as $it) {
        $sql .= "," . $it->GetXYData();
        $yn = $yn + 1;
        $xydata[$yn] = $it;
    }
    if ($debug == 1) {
        echo "::::::: {$yn} ::: " . $chart->GetYAxisCount();
    }
    $sql .= " FROM " . $chart->GetTable();
    if ($chart->GetOrderBy() && $chart->GetOrderBy() != "") {
        $sql .= " " . $chart->GetOrderBy();
    }
    if ($chart->GetLimit() && $chart->GetLimit() != "") {
        $sql .= " " . $chart->GetLimit();
    }
    // " ORDER BY id DESC LIMIT 30";
    $db = $g_BizSystem->GetDBConnection("Serdb");
    $resultSet = $db->query($sql);
    if ($resultSet === false) {
        $err = $db->ErrorMsg();
        echo $err;
        exit;
    }
    $xdata = array();
    $ydata = array();
    for ($i = 0; $i < $yn; $i = $i + 1) {
        $ydata[$i] = array();
    }
    $k = 0;
    $ymin = 0;
    $ymax = 0;
    while ($row = $resultSet->fetch()) {
        $xdata[$k] = $row[0];
        for ($i = 0; $i < $yn; $i = $i + 1) {
            $ydata[$i][$k] = 0 + $row[$i + 1];
            if ($k == 0) {
                $ymin = $ydata[$i][$k];
                $ymax = $ydata[$i][$k];
            } else {
                if ($ydata[$i][$k] < $ymin) {
                    $ymin = $ydata[$i][$k];
                }
                if ($ydata[$i][$k] > $ymax) {
                    $ymax = $ydata[$i][$k];
                }
            }
        }
        $k = $k + 1;
    }
    $ofcobj = new open_flash_chart();
    $ctitle = $chart->GetTitle();
    $rev = 0;
    if ($chart->GetOrder() && $chart->GetOrder() == "reverse") {
        $rev = 1;
    }
    $x = new x_axis();
    $xstep = (int) ($k / 20);
    if ($k % 20 != 0) {
        $xstep = $xstep + 1;
    }
    $x->set_steps($xstep);
    if ($xydata[0]->getXYType() == "timestamp") {
        if ($rev == 1) {
            $time_min = $xdata[$k - 1];
            $time_max = $xdata[0];
        } else {
            $time_min = $xdata[0];
            $time_max = $xdata[$k - 1];
        }
        $ctitle .= " - From " . date('Y-m-d H:i:s', $time_min);
        $ctitle .= " To " . date('Y-m-d H:i:s', $time_max);
        $time_x_labels = new x_axis_labels();
        $time_x_labels->rotate(20);
        $chart_lbls = array();
        for ($i = 0; $i < $k; $i = $i + 1) {
            if ($rev == 0) {
                $chart_lbls[] = date('H:i', $xdata[$i]);
            } else {
                $chart_lbls[] = date('H:i', $xdata[$k - $i - 1]);
            }
        }
        $time_x_labels->visible_steps($xstep);
        $time_x_labels->set_labels($chart_lbls);
        $x->set_labels($time_x_labels);
    } else {
        $time_x_labels->visible_steps($xstep);
        if ($rev == 1) {
            $ctitle .= " - From " . $xdata[$k - 1] . " To " . $xdata[0];
        } else {
            $ctitle .= " - From " . $xdata[0] . " To " . $xdata[$k - 1];
        }
    }
    $ofcobj->set_title(new title($ctitle));
    $dot_style = new dot();
    $dot_style->size(3)->halo_size(1);
    for ($i = 0; $i < $yn; $i++) {
        if ($chart->GetChartType() == "area") {
            $line[$i] = new area();
            $line[$i]->set_fill_alpha(0.3);
            $line[$i]->set_default_dot_style($dot_style);
        } else {
            if ($chart->GetChartType() == "line_dot") {
                $line[$i] = new line_dot();
                $line[$i]->set_default_dot_style($dot_style);
            } else {
                $line[$i] = new line();
                $line[$i]->set_default_dot_style($dot_style);
            }
        }
        if ($xydata[$i + 1]->GetXYColor() && $xydata[$i + 1]->GetXYColor() != "") {
            $line[$i]->set_colour($xydata[$i + 1]->GetXYColor());
        }
        if ($xydata[$i + 1]->GetXYTitle() && $xydata[$i + 1]->GetXYTitle() != "") {
            $line[$i]->set_key($xydata[$i + 1]->GetXYTitle(), 10);
        } else {
            $line[$i]->set_key("Key " . $i, 10);
        }
        if ($rev == 1) {
            $line[$i]->set_values(array_reverse($ydata[$i]));
        } else {
            $line[$i]->set_values($ydata[$i]);
        }
        $ofcobj->add_element($line[$i]);
    }
    if ($ymax > 10) {
        $y = new y_axis();
        if ($ymin > 10) {
            $y->set_range($ymin - 10, $ymax, (int) (($ymax - $ymin + 10) / 10));
        } else {
            $y->set_range(0, $ymax, (int) ($ymax / 10));
        }
        $ofcobj->set_y_axis($y);
    }
    $ofcobj->set_x_axis($x);
    if ($chart->GetBGColor() && $chart->GetBGColor() != "") {
        $ofcobj->set_bg_colour($chart->GetBGColor());
    }
    // return $ofcobj->toPrettyString();
    return $ofcobj->toString();
}
Example #14
0
function render_service_reports()
{
    $content = "<h1>Service Reports</h1>";
    // Start Filter for  service type
    $allServiceTypes = ServiceType::get_service_types();
    #	$allServiceTypes = array('all' => 'all');
    #$allServiceTypes = array_merge($allServiceTypes, ServiceType::get_service_types());
    $allServiceTypes['all'] = 'all';
    $service_type = $_GET['service_type'];
    $service_filter = $_GET['service_type'];
    if ($service_type == '' || !isset($service_type) || !is_numeric($service_type)) {
        $service_type = 'all';
        $service_filter = '';
    }
    $filter = "\r\n\t\t<FORM>\r\n\t\t<DIV style=\" \">\r\n\t\t<SELECT name'=service_type_report'\r\n\t\t\tonChange=\"window.location='services.php?&action=serviceReports&service_type='+this.options[this.selectedIndex].value;\">";
    foreach ($allServiceTypes as $id => $name) {
        if ($service_type == $id) {
            $selected = "SELECTED";
        } else {
            $selected = '';
        }
        $filter .= "<OPTION value='{$id}' {$selected}>{$name}\n";
    }
    $filter .= "\r\n\t\t</SELECT>\r\n\t\t</DIV>\r\n\t\t</FORM>\r\n\t";
    // End filter
    $max_date = strtotime("2009-01-01");
    $start_date = date("Y-m") . "-01";
    // Get all months since start
    $workdate = strtotime($start_date);
    $now = strtotime("Now");
    $form = new Form(auto, 3);
    $headings = array("Period", "In production", "Out of Production");
    $data = array();
    $x_ax_data = array();
    $y_ax_data = array();
    $handlers = array();
    while ($workdate > $max_date) {
        $sql_enddate = date("Y-m-d", $workdate);
        $month_period = date("m-Y", $workdate);
        // This is for the chart
        $month_label = date("M\nY", $workdate);
        $graph_date = strtotime("-1 month", $workdate);
        $month_label = date("M\nY", $graph_date);
        $sql_startdate = date("Y-m-d", $workdate);
        array_push($x_ax_data, $month_label);
        array_push($y_ax_data, count(Service::get_inprod_services_at_date($sql_startdate, $service_filter)));
        // Add one month
        $workdate = strtotime("-1 month", $workdate);
        $sql_startdate = date("Y-m-d", $workdate);
        $out_of_prod = count(Service::get_outprod_services_diff_date($sql_startdate, $sql_enddate, $service_filter));
        $in_prod = count(Service::get_inprod_services_diff_date($sql_startdate, $sql_enddate, $service_filter));
        array_push($data, "{$sql_startdate} {$sql_enddate}");
        array_push($data, $in_prod);
        array_push($data, $out_of_prod);
        array_push($handlers, "handleEvent('services.php?action=detailedServiceReports&start_date={$sql_startdate}&end_date={$sql_enddate}&service_type={$service_type}')");
    }
    $form->setTableWidth("224px");
    $form->setData($data);
    $form->setEventHandler($handlers);
    $form->setHeadings($headings);
    $form->setSortable(true);
    $content .= "<div style=\"float: left; clear: both; margin-right:28px\">" . $form->showForm() . "</div>";
    // Chart
    //
    // This is the MODEL section:
    //
    include 'open-flash-chart/php-ofc-library/open-flash-chart.php';
    // create an X Axis object
    //
    $y_ax_data = array_reverse($y_ax_data);
    $x_ax_data = array_reverse($x_ax_data);
    $x = new x_axis();
    $x->set_steps(3);
    $x->set_labels_from_array($x_ax_data);
    $max = max($y_ax_data);
    $y = new y_axis();
    $y->set_range(0, $max);
    // Bar
    $bar = new bar();
    $bar->set_values($y_ax_data);
    // Bar
    // ------- LINE 2 -----
    $line_2_default_dot = new dot();
    $line_2_default_dot->size(3)->halo_size(1)->colour('#3D5C56');
    $line_2 = new line();
    $line_2->set_default_dot_style($line_2_default_dot);
    $line_2->set_values($y_ax_data);
    $line_2->set_width(3);
    $line_2->set_colour('#3D5C56');
    $chart = new open_flash_chart();
    $title = new title("In Production Services over Time");
    $title->set_style("{font-size: 10px; font-family: Times New Roman; font-weight: bold; color: #000; text-align: center;}");
    $chart->set_bg_colour('#FFFFFF');
    $chart->set_title($title);
    $chart->add_element($bar);
    //$chart->add_element( $line1 );
    $chart->add_element($line_2);
    $chart->set_x_axis($x);
    $chart->set_y_axis($y);
    //
    // This is the VIEW section:
    // Should print this first.
    //
    $heading = "\r\n\t<script type='text/javascript' src='open-flash-chart/js/json/json2.js'></script>\r\n\t<script type='text/javascript' src='open-flash-chart/js/swfobject.js'></script>\r\n\t<script type='text/javascript'>\r\n\tswfobject.embedSWF('open-flash-chart/open-flash-chart.swf', 'my_chart', '660', '350', '9.0.0');\r\n\t</script>\r\n\r\n\t<script type='text/javascript'>\r\n\r\n\tfunction open_flash_chart_data() {\r\n\t\treturn JSON.stringify(data);\r\n\t}\r\n\r\n\tfunction findSWF(movieName) {\r\n  \t\tif (navigator.appName.indexOf('Microsoft')!= -1) {\r\n    \t\t\treturn window[movieName];\r\n  \t\t} else {\r\n    \t\t\treturn document[movieName];\r\n  \t\t}\r\n\t}\r\n    \r\n\tvar data = " . $chart->toPrettyString() . "\r\n\r\n\t</script>\r\n\r\n\r\n\t<script type=\"text/javascript\">\r\n \r\n\tOFC = {};\r\n \r\n\tOFC.jquery = {\r\n    \tname: 'jQuery',\r\n    \tversion: function(src) { return \$('#'+ src)[0].get_version() },\r\n    \trasterize: function (src, dst) { \$('#'+ dst).replaceWith(OFC.jquery.image(src)) },\r\n    \timage: function(src) { return \"<img src='data:image/png;base64,\" + \$('#'+src)[0].get_img_binary() + \"' />\"},\r\n    \tpopup: function(src) {\r\n        var img_win = window.open('', 'Charts: Export as Image')\r\n        with(img_win.document) {\r\n            write('<html><head><title>Charts: Export as Image<\\/title><\\/head><body>' + OFC.jquery.image(src) + '<\\/body><\\/html>') }\r\n\t\t// stop the 'loading...' message\r\n\t\timg_win.document.close();\r\n     \t}\r\n\t}\r\n \r\n\t// Using_ an object as namespaces is JS Best Practice. I like the Control.XXX style.\r\n\t//if (!Control) {var Control = {}}\r\n\t//if (typeof(Control == \"undefined\")) {var Control = {}}\r\n\tif (typeof(Control == \"undefined\")) {var Control = {OFC: OFC.jquery}}\r\n \r\n \r\n\t// By default, right-clicking on OFC and choosing \"save image locally\" calls this function.\r\n\t// You are free to change the code in OFC and call my wrapper (Control.OFC.your_favorite_save_method)\r\n\t// function save_image() { alert(1); Control.OFC.popup('my_chart') }\r\n\tfunction save_image() { alert(\"Your image will be displayed in a new window\"); OFC.jquery.popup('my_chart') }\r\n\t</script>\r\n\t<div id='my_chart' style='float:left; margin-left:28px;'></div>\r\n\t";
    print " {$content}\n \r\n\t\t<div style=''<b>Select Service Type:</b>{$filter} <br></div>\n\r\n\t\t{$heading} ";
}
Example #15
0
 function subscription()
 {
     acymailing::setTitle(JText::_('CHARTS'), 'stats', 'diagram&task=subscription');
     $listsClass = acymailing::get('class.list');
     $lists = $listsClass->getLists('listid');
     $db =& JFactory::getDBO();
     $db->setQuery('SELECT min(subdate) as minsubdate, min(unsubdate) as minunsubdate FROM ' . acymailing::table('listsub'));
     $dates = $db->loadObject();
     $spaces = array();
     $intervals = 10;
     $dates->maxsubdate = time();
     $delay = ($dates->maxsubdate - $dates->minsubdate) / $intervals;
     for ($i = 0; $i < $intervals; $i++) {
         $spaces[$i] = (int) ($dates->minsubdate + $delay * $i);
     }
     $spaces[$intervals] = $dates->maxsubdate;
     $results = array();
     $legendX = array();
     for ($i = 0; $i <= $intervals; $i++) {
         $legendX[] = acymailing::getDate($spaces[$i]);
         $db->setQuery('SELECT count(subid) as total, listid FROM ' . acymailing::table('listsub') . ' WHERE `status` != 2 AND `subdate` < ' . $spaces[$i] . ' AND (`status` = 1 OR `unsubdate`>' . $spaces[$i] . ') GROUP BY listid');
         $results[$i] = $db->loadObjectList('listid');
     }
     $title = new title(JText::_('SUB_HISTORY'));
     $title->set_style('font-size:20px; color: #FF8040');
     $lines = array();
     $maxSub = 0;
     foreach ($lists as $listid => $oneList) {
         $lines[$listid] = new line_base();
         $values = array();
         for ($i = 0; $i <= $intervals; $i++) {
             $values[] = empty($results[$i][$listid]->total) ? 0 : (int) $results[$i][$listid]->total;
         }
         $lines[$listid]->set_values($values);
         $lines[$listid]->set_text($oneList->name);
         $lines[$listid]->set_colour($oneList->color);
         $maxSub = max($maxSub, max($values));
     }
     $x_axis = new x_axis();
     $xlabelobject = new x_axis_labels();
     $xlabelobject->rotate(-20);
     $xlabelobject->set_labels($legendX);
     $x_axis->set_labels($xlabelobject);
     $y_axis = new y_axis();
     $y_axis->range(0, $maxSub, intval($maxSub / 10));
     $chart = new open_flash_chart();
     $chart->set_x_axis($x_axis);
     $chart->set_y_axis($y_axis);
     $chart->set_title($title);
     foreach ($lines as $oneLine) {
         $chart->add_element($oneLine);
     }
     $this->assignRef('chart', $chart);
 }
Example #16
0
 private static function make_bandwidth_chart($values, $options = array())
 {
     if (!$values || !count($values)) {
         return false;
     }
     $title = !empty($options['title']) ? $options['title'] : 'Chart';
     //array_check_value($options, 'title', 'BI Chart');
     $step = !empty($options['step']) ? $options['step'] : 0.75;
     //array_check_value($options, 'step', 0.75);
     $max = !empty($options['max']) ? $options['max'] : 0;
     //array_check_value($options, 'max', 0);
     $value_mod = !empty($options['value_modifier']) ? $options['value_modifier'] : 1;
     //array_check_value($options, 'value_modifier', 1);
     $input_title = !empty($options['input_title']) ? $options['input_title'] : 'Downloads for :key: #val#';
     //array_check_value($options, 'input_title', 'Downloads for :key: #val#');
     $output_title = !empty($options['output_title']) ? $options['output_title'] : 'Uploads for :key: #val#';
     //array_check_value($options, 'output_title', 'Uploads for :key: #val#');
     $total_title = !empty($options['total_title']) ? $options['total_title'] : 'Total for :key: #val#';
     //array_check_value($options, 'total_title', 'Total for :key: #val#');
     $on_click = !empty($options['on_click']) ? $options['on_click'] : false;
     //array_check_value($options, 'on_click', false);
     $x_labels = !empty($options['x_labels']) ? $options['x_labels'] : array_keys($values);
     //array_check_value($options, 'x_labels', array_keys($values));
     include_once APP_FOLDER . '/libraries/php-ofc-library/ofc_title.php';
     include_once APP_FOLDER . '/libraries/php-ofc-library/open-flash-chart.php';
     //include(APP_FOLDER . '/libraries/php-ofc-library/ofc_bar_glass_value.php');
     include_once APP_FOLDER . '/libraries/php-ofc-library/ofc_line_dot.php';
     include_once APP_FOLDER . '/libraries/php-ofc-library/ofc_line_base.php';
     include_once APP_FOLDER . '/libraries/php-ofc-library/ofc_x_axis.php';
     $title = new title($title);
     $chart = new open_flash_chart();
     $chart->set_title($title);
     $input = array();
     $ouput = array();
     $total = array();
     $clicks = array();
     foreach ($values as $key => $value) {
         $this_value = (double) number_format($value['input'] / $value_mod, 2, '.', '');
         $tmp = new bar_glass_value($this_value);
         $tmp->set_tooltip(preg_replace('/:key/', $key, $input_title));
         $input[] = $tmp;
         $this_value = (double) number_format($value['output'] / $value_mod, 2, '.', '');
         $tmp = new bar_glass_value($this_value);
         $tmp->set_tooltip(preg_replace('/:key/', $key, $output_title));
         $output[] = $tmp;
         $this_value = (double) number_format(($value['input'] + $value['output']) / $value_mod, 2, '.', '');
         $tmp = new dot_value($this_value, '#000066');
         $tmp->set_tooltip(preg_replace('/:key/', $key, $total_title));
         $total[] = $tmp;
         if ($on_click) {
             $tmp = (double) number_format(($value['input'] + $value['output']) / $value_mod, 2, '.', '');
             $clicks[] = $tmp;
         }
         $max = ceil(max(($value['input'] + $value['output']) / $value_mod, $max));
     }
     $x_axis = new x_axis();
     $x_axis->set_labels_from_array($x_labels);
     $x_axis->set_3d(5);
     $x_axis->colour = '#909090';
     if ($max > 0) {
         //Don't know why we sometimes get a division by zero error
         @($max = $max + ($step - $max % $step));
     }
     if ($max / $step > 5) {
         $step = floor($max / 5);
     } else {
         if ($max / $step <= 1) {
             $step = floor($max / 2);
         }
     }
     $y_axis = new y_axis();
     $y_axis->set_range(0, $max, $step);
     $input_bar = new bar_glass();
     $input_bar->set_values($input);
     $input_bar->colour = '#D54C78';
     $output_bar = new bar_glass();
     $output_bar->set_values($output);
     $output_bar->colour = '#78D54C';
     $total_graph = new line_hollow();
     $total_graph->set_colour('#9999FF');
     $total_graph->set_values($total);
     if ($on_click) {
         $click_graph = new line();
         $click_graph->set_values($clicks);
         $click_graph->set_on_click($on_click);
         $chart->add_element($click_graph);
     }
     $chart->set_x_axis($x_axis);
     $chart->set_y_axis($y_axis);
     $chart->add_element($input_bar);
     $chart->add_element($output_bar);
     $chart->add_element($total_graph);
     //$decoded = json_decode($chart->toString());
     return $chart->toString();
 }
 function get_daily_entries($form, $colors = false, $type = "DATE")
 {
     global $wpdb, $frmdb;
     if (!$colors) {
         $colors = array('#EF8C08', '#21759B', '#1C9E05');
     }
     $type = strtoupper($type);
     //Chart for Entries Submitted
     $values = array();
     $labels = array();
     if ($type == 'HOUR') {
         $start_timestamp = strtotime('-48 hours');
     } else {
         if ($type == 'MONTH') {
             $start_timestamp = strtotime('-1 year');
         } else {
             if ($type == 'YEAR') {
                 $start_timestamp = strtotime('-10 years');
             } else {
                 $start_timestamp = strtotime('-1 month');
             }
         }
     }
     $end_timestamp = time();
     if ($type == 'HOUR') {
         $query = "SELECT en.created_at as endate,COUNT(*) as encount FROM {$frmdb->entries} en WHERE en.created_at >= '" . date("Y-n-j H", $start_timestamp) . ":00:00' AND en.form_id={$form->id} GROUP BY endate";
     } else {
         $query = "SELECT DATE(en.created_at) as endate,COUNT(*) as encount FROM {$frmdb->entries} en WHERE en.created_at >= '" . date("Y-n-j", $start_timestamp) . " 00:00:00' AND en.form_id={$form->id} GROUP BY {$type}(en.created_at)";
     }
     $entries_array = $wpdb->get_results($query);
     $temp_array = $counts_array = $dates_array = array();
     // Refactor Array for use later on
     foreach ($entries_array as $e) {
         $e_key = $e->endate;
         if ($type == 'HOUR') {
             $e_key = date('Y-m-d H', strtotime($e->endate)) . ':00:00';
         } else {
             if ($type == 'MONTH') {
                 $e_key = date('Y-m', strtotime($e->endate)) . '-01';
             } else {
                 if ($type == 'YEAR') {
                     $e_key = date('Y', strtotime($e->endate)) . '-01-01';
                 }
             }
         }
         $temp_array[$e_key] = $e->encount;
     }
     // Get the dates array
     if ($type == 'HOUR') {
         for ($e = $start_timestamp; $e <= $end_timestamp; $e += 60 * 60) {
             if (!in_array(date('Y-m-d H', $e) . ':00:00', $dates_array)) {
                 $dates_array[] = date('Y-m-d H', $e) . ':00:00';
             }
         }
         $date_format = get_option('time_format');
     } else {
         if ($type == 'MONTH') {
             for ($e = $start_timestamp; $e <= $end_timestamp; $e += 60 * 60 * 24 * 25) {
                 if (!in_array(date('Y-m', $e) . '-01', $dates_array)) {
                     $dates_array[] = date('Y-m', $e) . '-01';
                 }
             }
             $date_format = 'F Y';
         } else {
             if ($type == 'YEAR') {
                 for ($e = $start_timestamp; $e <= $end_timestamp; $e += 60 * 60 * 24 * 364) {
                     if (!in_array(date('Y', $e) . '-01-01', $dates_array)) {
                         $dates_array[] = date('Y', $e) . '-01-01';
                     }
                 }
                 $date_format = 'Y';
             } else {
                 for ($e = $start_timestamp; $e <= $end_timestamp; $e += 60 * 60 * 24) {
                     $dates_array[] = date("Y-m-d", $e);
                 }
                 $date_format = get_option('date_format');
             }
         }
     }
     // Make sure counts array is in order and includes zero click days
     foreach ($dates_array as $date_str) {
         if (isset($temp_array[$date_str])) {
             $counts_array[$date_str] = $temp_array[$date_str];
         } else {
             $counts_array[$date_str] = 0;
         }
     }
     foreach ($counts_array as $date => $count) {
         $labels[] = date_i18n($date_format, strtotime($date));
         $values[] = (int) $count;
     }
     if ($type == 'MONTH') {
         $title = __('Monthly Entries', 'formidable');
     } else {
         if ($type == 'YEAR') {
             $title = __('Yearly Entries', 'formidable');
         } else {
             if ($type == 'HOUR') {
                 $title = __('Hourly Entries', 'formidable');
             } else {
                 $title = __('Daily Entries', 'formidable');
             }
         }
     }
     $title = new title($title);
     $line_1_default_dot = new dot();
     $line_1_default_dot->colour($colors[0]);
     $line_1_default_dot->tooltip('#x_label#<br>#val# Entries');
     $line_1 = new line();
     $line_1->set_default_dot_style($line_1_default_dot);
     $line_1->set_values($values);
     $line_1->set_colour($colors[1]);
     $chart = new open_flash_chart();
     $chart->set_title($title);
     $chart->set_bg_colour('#FFFFFF');
     $x = new x_axis();
     $x_labels = new x_axis_labels();
     $x_labels->rotate(340);
     $x_labels->set_labels($labels);
     if (count($labels) > 15) {
         $x_labels->visible_steps(2);
     }
     $x->set_labels($x_labels);
     $chart->set_x_axis($x);
     $y = new y_axis();
     if (!empty($values)) {
         $max = max($values) + 1;
         $step = ceil($max / 10);
         $y->set_range(0, $max, $step);
     }
     $chart->add_element($line_1);
     $chart->set_y_axis($y);
     return $chart->toPrettyString();
 }
Example #18
0
 /**
  * assign the chartdata object for open flash chart library
  * @param $config
  * @return unknown_type
  */
 function _setChartdata($config)
 {
     $model = $this->getModel();
     $rounds = $this->get('Rounds');
     $round_labels = array();
     foreach ($rounds as $r) {
         $round_labels[] = $r->name;
     }
     $division = $this->get('division');
     $data = $model->getDataByDivision($division->id);
     //create a line
     $length = count($rounds) - 0.5;
     $linewidth = $config['color_legend_line_width'];
     $lines = array();
     //$title = $division->name;
     $chart = new open_flash_chart();
     //$chart->set_title( $title );
     $chart->set_bg_colour($config['bg_colour']);
     //colors defined for ranking table lines
     //todo: add support for more than 2 lines
     foreach ($this->colors as $color) {
         foreach ($rounds as $r) {
             for ($n = $color['from']; $n <= $color['to']; $n++) {
                 $lines[$color['color']][$n][] = $n;
             }
         }
     }
     //set lines on the graph
     foreach ($lines as $key => $value) {
         foreach ($value as $line => $key2) {
             $chart->add_element(hline($key, $length, $line, $linewidth));
         }
     }
     //load team1, first team in the dropdown
     $team = $this->team1;
     $d = new $config['dotstyle_1']();
     $d->size((int) $config['line1_dot_strength']);
     $d->halo_size(1);
     $d->colour($config['line1']);
     $d->tooltip('Rank: #val#');
     $line = new line();
     $line->set_default_dot_style($d);
     $line->set_values($team->rankings);
     $line->set_width((int) $config['line1_strength']);
     $line->set_key($team->name, 12);
     $line->set_colour($config['line1']);
     $line->on_show(new line_on_show($config['l_animation_1'], $config['l_cascade_1'], $config['l_delay_1']));
     $chart->add_element($line);
     //load team2, second team in the dropdown
     $team = $this->team2;
     $d = new $config['dotstyle_2']();
     $d->size((int) $config['line2_dot_strength']);
     $d->halo_size(1);
     $d->colour($config['line2']);
     $d->tooltip('Rank: #val#');
     $line = new line();
     $line->set_default_dot_style($d);
     $line->set_values($team->rankings);
     $line->set_width((int) $config['line2_strength']);
     $line->set_key($team->name, 12);
     $line->set_colour($config['line2']);
     $line->on_show(new line_on_show($config['l_animation_2'], $config['l_cascade_2'], $config['l_delay_2']));
     $chart->add_element($line);
     $x = new x_axis();
     if ($config['x_axis_label'] == 1) {
         $xlabels = new x_axis_labels();
         $xlabels->set_labels($round_labels);
         $xlabels->set_vertical();
     }
     $x->set_labels($xlabels);
     $x->set_colours($config['x_axis_colour'], $config['x_axis_colour_inner']);
     $chart->set_x_axis($x);
     $x_legend = new x_legend(JText::_('COM_JOOMLEAGUE_CURVE_ROUNDS'));
     $x_legend->set_style('{font-size: 15px; color: #778877}');
     $chart->set_x_legend($x_legend);
     $y = new y_axis();
     $y->set_range(count($data), 1, -1);
     $y->set_colours($config['x_axis_colour'], $config['x_axis_colour_inner']);
     $chart->set_y_axis($y);
     $y_legend = new y_legend(JText::_('COM_JOOMLEAGUE_CURVE_RANK'));
     $y_legend->set_style('{font-size: 15px; color: #778877}');
     $chart->set_y_legend($y_legend);
     ob_clean();
     echo $chart->toString();
 }
 function admin_graphs($id = null)
 {
     App::import('Vendor', 'Newsletter.php-ofc-library', array('file' => 'php-ofc-library/open-flash-chart.php'));
     //Configure::write('debug', 0);
     //$this->layout = null;
     // generate some random data
     srand((double) microtime() * 1000000);
     $title = new title(__d("newsletter", "Views per time", true));
     $chart = new open_flash_chart();
     $chart->set_title($title);
     $newsletter = $this->Newsletter->read(null, $id);
     // Views
     $dates = array();
     $values = array();
     //// init sender class ////
     App::import('Lib', 'Newsletter.ClassCollection');
     $senderOpt = NewsletterConfig::load('sender');
     if (!is_array($senderOpt)) {
         $senderOpt = array('name' => $senderOpt);
     }
     $sender = ClassCollection::getObject('NewsletterSender', $senderOpt['name']);
     //// query ////
     $opt = array('type' => 'graph', 'query' => array('fields' => array('count(*) as nb', 'DATE(NewsletterEvent.date) as date'), 'conditions' => array('NewsletterSended.newsletter_id' => $id, 'or' => array('NewsletterEvent.action' => 'view', array('NewsletterEvent.action IS NULL', 'NewsletterEvent.url' => null))), 'group' => 'DATE(NewsletterEvent.date)', 'order' => 'DATE(NewsletterEvent.date)', 'model' => 'NewsletterEvent'));
     $data = $this->_get_stats(array('viewByDays' => $opt), $newsletter, $sender);
     //debug($data);
     $dates = $data['viewByDays'];
     $min_value = 99999999;
     $max_value = 0;
     foreach ($dates as $d => $val) {
         if ($val < $min_value) {
             $min_value = $val;
         }
         if ($val > $max_value) {
             $max_value = $val;
         }
     }
     if ($max_value == $min_value) {
         $max_value++;
         $min_value--;
     }
     $min_value = 0;
     //debug($dates);
     $min_date = key($dates);
     end($dates);
     $max_date = key($dates);
     for ($cur_date = $min_date; $cur_date <= $max_date; $cur_date = $cur_date + 86400) {
         $x = strtotime('00:00:00', $cur_date);
         if (isset($dates[$cur_date])) {
             $values[] = new scatter_value($x, $dates[$cur_date]);
         } else {
             $values[] = new scatter_value($x, 0);
         }
     }
     if ($max_date == $min_date) {
         $max_date += 86400;
     }
     //debug($values);
     //pr($views);
     $line_dot = new line();
     $line_dot->set_values($values);
     $line_dot->set_text("Views");
     $chart->add_element($line_dot);
     $y = new y_axis();
     $y->set_range($min_value, $max_value, ($max_value - $min_value) / 10);
     $x = new x_axis();
     // grid line and tick every 10
     $x->set_range(mktime(0, 0, 0, date("m", $min_date), date("d", $min_date), date("Y", $min_date)), mktime(0, 0, 0, date("m", $max_date), date("d", $max_date), date("Y", $max_date)));
     // show ticks and grid lines for every day:
     $x->set_steps(86400);
     $labels = new x_axis_labels();
     // tell the labels to render the number as a date:
     $labels->text('#date:d-m-Y#');
     // generate labels for every day
     $labels->set_steps(86400);
     // only display every other label (every other day)
     $labels->visible_steps(ceil(($max_date - $min_date) / 86400 / 20));
     $labels->rotate(90);
     $x->set_labels($labels);
     $chart->set_x_axis($x);
     $chart->set_y_axis($y);
     $chart->set_bg_colour("#FFFFFF");
     //print_r($views);
     //$this->set("allviews",$views[0][0]['count(*)']);
     $line_dot = new line();
     $line_dot->set_values(array(2, 1));
     $line_dot->set_text("Unique views");
     $line_dot->colour("#0000000");
     //$chart->add_element($line_dot);
     //
     echo $chart->toPrettyString();
     exit;
     //$this->render(false);
 }
 /**
  * assign the chartdata object for open flash chart library
  * @param $config
  * @return unknown_type
  */
 function _setChartdata($config)
 {
     require_once JLG_PATH_SITE . DS . "assets" . DS . "classes" . DS . "open-flash-chart" . DS . "open-flash-chart.php";
     $data = $this->get('ChartData');
     // Calculate Values for Chart Object
     $forSum = array();
     $againstSum = array();
     $matchDayGoalsCount = array();
     $matchDayGoalsCount[] = 0;
     $round_labels = array();
     $matchDayGoalsCountMax = 0;
     foreach ($data as $rw) {
         if (!$rw->goalsfor) {
             $rw->goalsfor = 0;
         }
         if (!$rw->goalsagainst) {
             $rw->goalsagainst = 0;
         }
         $forSum[] = intval($rw->goalsfor);
         $againstSum[] = intval($rw->goalsagainst);
         // check, if both results are missing and avoid drawing the flatline of "0" goals for not played games yet
         if (!$rw->goalsfor && !$rw->goalsagainst) {
             $matchDayGoalsCount[] = 0;
         } else {
             $matchDayGoalsCount[] = intval($rw->goalsfor + $rw->goalsagainst);
         }
         $round_labels[] = $rw->roundcode;
     }
     $chart = new open_flash_chart();
     //$chart->set_title( $title );
     $chart->set_bg_colour($config['bg_colour']);
     $barfor = new $config['bartype_1']();
     $barfor->set_values($forSum);
     $barfor->set_tooltip(JText::_('COM_JOOMLEAGUE_TEAMSTATS_GOALS_FOR') . ": #val#");
     $barfor->set_colour($config['bar1']);
     $barfor->set_on_show(new bar_on_show($config['animation_1'], $config['cascade_1'], $config['delay_1']));
     $barfor->set_key(JText::_('COM_JOOMLEAGUE_TEAMSTATS_GOALS_FOR'), 12);
     $baragainst = new $config['bartype_2']();
     $baragainst->set_values($againstSum);
     $baragainst->set_tooltip(JText::_('COM_JOOMLEAGUE_TEAMSTATS_GOALS_AGAINST') . ": #val#");
     $baragainst->set_colour($config['bar2']);
     $baragainst->set_on_show(new bar_on_show($config['animation_2'], $config['cascade_2'], $config['delay_2']));
     $baragainst->set_key(JText::_('COM_JOOMLEAGUE_TEAMSTATS_GOALS_AGAINST'), 12);
     $chart->add_element($barfor);
     $chart->add_element($baragainst);
     // total
     $d = new $config['dotstyle_3']();
     $d->size((int) $config['line3_dot_strength']);
     $d->halo_size(1);
     $d->colour($config['line3']);
     $d->tooltip(JText::_('COM_JOOMLEAGUE_TEAMSTATS_TOTAL2') . ' #val#');
     $line = new line();
     $line->set_default_dot_style($d);
     $line->set_values(array_slice($matchDayGoalsCount, 1));
     $line->set_width((int) $config['line3_strength']);
     $line->set_key(JText::_('COM_JOOMLEAGUE_TEAMSTATS_TOTAL'), 12);
     $line->set_colour($config['line3']);
     $line->on_show(new line_on_show($config['l_animation_3'], $config['l_cascade_3'], $config['l_delay_3']));
     $chart->add_element($line);
     $x = new x_axis();
     $x->set_colours($config['x_axis_colour'], $config['x_axis_colour_inner']);
     $x->set_labels_from_array($round_labels);
     $chart->set_x_axis($x);
     $x_legend = new x_legend(JText::_('COM_JOOMLEAGUE_TEAMSTATS_ROUNDS'));
     $x_legend->set_style('{font-size: 15px; color: #778877}');
     $chart->set_x_legend($x_legend);
     $y = new y_axis();
     $y->set_range(0, max($matchDayGoalsCount) + 2, $config['y_axis_steps']);
     $y->set_colours($config['y_axis_colour'], $config['y_axis_colour_inner']);
     $chart->set_y_axis($y);
     $y_legend = new y_legend(JText::_('COM_JOOMLEAGUE_TEAMSTATS_GOALS'));
     $y_legend->set_style('{font-size: 15px; color: #778877}');
     $chart->set_y_legend($y_legend);
     $this->assignRef('chartdata', $chart);
 }
Example #21
0
        }
        $labels2 = new x_axis_labels();
        $labels2->set_labels($tab_libelles2);
        $labels2->rotate(270);
        // Absisses
        $x2 = new x_axis();
        //$x->set_labels( $x_labels );
        $x2->set_stroke(2);
        $x2->set_tick_height(2);
        $x2->set_colour("#d000d0");
        $x2->set_labels($labels2);
        // Tooltip du graphe !
        $chart2->set_tooltip($t);
        $title2 = new title("Evolution par joueur");
        $chart2->set_title($title2);
        $chart2->set_y_axis($y2);
        $chart2->set_x_axis($x2);
        $fp = fopen($fichierImage, "w");
        // ouverture du fichier en écriture
        fputs($fp, $chart2->toPrettyString());
        // on écrit les données
        fclose($fp);
    }
    echo "<div id=\"my_chart2\"> </div>";
    ferme_base($db_link);
}
?>
     
      
      
      
Example #22
0
$user_line->set_values($user_signups);
$user_line->colour('#0099cc');
$user_line->set_key('User', 14);
$grp_line = new line();
$grp_line->set_values($groups_added);
$grp_line->colour('#990000');
$grp_line->set_key('Groups', 14);
$max = $max;
$steps = round($max / 5, 0.49);
$y = new y_axis();
$y->set_range(0, $max, $steps);
$chart = new open_flash_chart();
$chart->set_title($title);
$chart->add_element($vid_line);
$chart->add_element($user_line);
$chart->add_element($grp_line);
$x_labels = new x_axis_labels();
$x_labels->set_steps(1);
$x_labels->set_vertical();
$x_labels->set_colour('#A2ACBA');
$x_labels->set_labels($year);
$x = new x_axis();
$x->set_colour('#A2ACBA');
$x->set_grid_colour('#D7E4A3');
$x->set_offset(false);
$x->set_steps(4);
// Add the X Axis Labels to the X Axis
$x->set_labels($x_labels);
$chart->set_x_axis($x);
$chart->set_y_axis($y);
echo $chart->toString();
Example #23
0
            }
        }
    }
}
$title = new title($title);
$title->set_style("{font-size: 20px; color: #A2ACBA; text-align: center;}");
$bar = new bar_3d();
$bar->set_values($data);
$bar->colour = '#D54C78';
$x_labels = new x_axis_labels();
$x_labels->set_labels($x_date);
$x_axis = new x_axis();
$x_axis->set_3d(3);
$x_axis->colour = '#909090';
$x_axis->set_labels($x_labels);
$x_legend = new x_legend($x_title);
$x_legend->set_style('{font-size: 20px; color: #778877}');
$y_axis = new y_axis();
$max = arr_max($data);
$mix = arr_min($data);
$per = round($max / 10);
$max = round($max + $per + $per);
$temp = '$y_axis->set_range(0,' . $max . ',' . $per . ');';
eval($temp);
$chart = new open_flash_chart();
$chart->set_title($title);
$chart->add_element($bar);
$chart->set_x_axis($x_axis);
$chart->set_x_legend($x_legend);
$chart->set_y_axis($y_axis);
echo $chart->toPrettyString();
Example #24
0
 function _render_statistic($x = array(), $yout = array(), $yin = array(), $type = 'bar', $points)
 {
     $this->load->helper('date');
     $this->load->library('OpenFlashChartLib', NULL, 'OFCL');
     $data_1 = array();
     $data_2 = array();
     $data_3 = array();
     switch ($type) {
         case 'bar':
             for ($i = 0; $i <= $points; $i++) {
                 $data_1[$i] = $x[$i];
                 $data_2[$i] = (int) $yout[$i];
                 // force to integer
                 $data_3[$i] = (int) $yin[$i];
                 // force to integer
             }
             $data_1 = array_reverse($data_1);
             $data_2 = array_reverse($data_2);
             $data_3 = array_reverse($data_3);
             $bar_1 = new bar();
             $bar_1->set_values($data_3);
             $bar_1->set_colour('#639F45');
             $bar_1->key(lang('kalkun_incoming_sms'), 10);
             $bar_1->set_tooltip('#x_label#<br>#val# SMS');
             //$bar_1->set_key("SMS used in last 7 days", 10);
             $bar_2 = new bar();
             $bar_2->set_values($data_2);
             $bar_2->set_colour('#21759B');
             $bar_2->key(lang('kalkun_outgoing_sms'), 10);
             $bar_2->set_tooltip('#x_label#<br>#val# SMS');
             $x = new x_axis();
             $labels = new x_axis_labels();
             $labels->set_labels($data_1);
             $labels->set_steps(1);
             $x->set_labels($labels);
             $y = new y_axis();
             $max = max(max($data_2), max($data_3));
             if ($max < 10) {
                 $max = 10;
             }
             $max = ceil($max / 5) * 5;
             $range = ceil($max / 5);
             $range = ceil($range / 10) * 10;
             $y->set_range(0, $max, $range);
             $element1 = $bar_1;
             $element2 = $bar_2;
             break;
         case 'line':
             for ($i = 0; $i <= 7; $i++) {
                 $data_1[$i] = new scatter_value($x[$i], $yin[$i]);
                 $data_2[$i] = new scatter_value($x[$i], $yout[$i]);
                 $data_3[$i] = (int) $yin[$i];
                 $data_4[$i] = (int) $yout[$i];
             }
             $def = new solid_dot();
             $def->size(4)->halo_size(0)->colour('#21759B')->tooltip('#date:d M y#<br>#val# SMS');
             $line_1 = new scatter_line('#639F45', 3);
             $line_1->set_values($data_1);
             $line_1->set_default_dot_style($def);
             $line_1->set_key("Incoming SMS", 10);
             $line_2 = new scatter_line('#21759B', 3);
             $line_2->set_values($data_2);
             $line_2->set_default_dot_style($def);
             $line_2->set_key("Outgoing SMS", 10);
             $x = new x_axis();
             // grid line and tick every 10
             $x->set_range(mktime(0, 0, 0, date("m"), date("d") - 7, date('Y')), mktime(0, 0, 0, date("m"), date("d"), date('Y')));
             // show ticks and grid lines for every day:
             $x->set_steps(86400);
             $labels = new x_axis_labels();
             // tell the labels to render the number as a date:
             $labels->text('#date:M-d#');
             // generate labels for every day
             $labels->set_steps(86400);
             // only display every other label (every other day)
             $labels->visible_steps(1);
             $labels->rotate(45);
             // finally attach the label definition to the x axis
             $x->set_labels($labels);
             $y = new y_axis();
             $max = max(max($data_3), max($data_4));
             if ($max < 1) {
                 $max = 10;
             }
             $y->set_range(0, $max, round($max / 100) * 10);
             $element1 = $line_1;
             $element2 = $line_2;
             break;
     }
     $chart = new open_flash_chart();
     $chart->add_element($element1);
     $chart->add_element($element2);
     $chart->set_x_axis($x);
     $chart->set_y_axis($y);
     echo $chart->toPrettyString();
 }
Example #25
0
 function gsitedata()
 {
     $this->autoRender = false;
     $solid = $this->Session->read('sol');
     $host_id = $this->Session->read('host_id');
     $tinterval = 3600;
     $host_srch = "";
     if (!empty($host_id) && $host_id != 0) {
         $host_srch = " AND source_id = " . $host_id;
     }
     $this->DnsMessage->recursive = -1;
     $site_count = $this->DnsMessage->query('SELECT hostname, COUNT(*) FROM dns_messages WHERE sol_id = ' . $solid . $host_srch . ' GROUP BY hostname ORDER BY COUNT(*) DESC LIMIT 50');
     //sort($site_count);
     $data = array();
     $x = array();
     $max_resp = 0;
     foreach ($site_count as $site) {
         $data[] = array((int) $site[0]['COUNT(*)'], 0);
         if ($max_resp < (int) $site[0]['COUNT(*)']) {
             $max_resp = (int) $site[0]['COUNT(*)'];
         }
         if (empty($site[0]['hostname'])) {
             $x[] = (string) $site['dns_messages']['hostname'];
         } else {
             $x[] = (string) $site[0]['hostname'];
         }
     }
     // joson data format
     $title = new title(__("Host Popularity", true));
     $title->set_style("{font-size: 14px; color: #990000; text-align: center; font-weight:bold;}");
     $bar = new bar_stack();
     $bar->set_colours(array('#e77919', '#577261'));
     $bar->set_on_show(new bar_on_show('grow-up', 0, 0.5));
     $bar->set_values($data);
     $bar->set_tooltip('Host: #x_label#<br>Response #val#<br>');
     $tooltip = new tooltip();
     $tooltip->set_hover();
     $tooltip->set_shadow(false);
     $tooltip->set_stroke(5);
     $tooltip->set_colour("#6E604F");
     $tooltip->set_background_colour("#BDB396");
     $data_labels = new x_axis_labels();
     $data_labels->rotate(90);
     $data_labels->set_labels($x);
     $x_axis = new x_axis();
     $x_axis->set_labels($data_labels);
     $y = new y_axis();
     $y->set_range(0, $max_resp * 1.1, (int) ($max_resp / 10));
     $chart = new open_flash_chart();
     $chart->set_bg_colour('#F9F9F9');
     $chart->set_title($title);
     $chart->add_element($bar);
     $chart->set_x_axis($x_axis);
     $chart->set_y_axis($y);
     $chart->set_tooltip($tooltip);
     // menu'
     $m = new ofc_menu("#f0E0ff", "#878787");
     $m->values(array(new ofc_menu_item(__('DNS Response', true), 'go_gpage')));
     $chart->set_menu($m);
     header("Content-Type: text/plain");
     echo $chart->toPrettyString();
     die;
 }