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
');
$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 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 #5
0
/** flowview_viewchart()
 *
 *  This function is taken from Slowlog.  Given
 *  a title, chart type and chart data, it will
 *  echo the required syntax for the Callback
 *  from the chart page to operate corectly.
 */
function flowview_viewchart()
{
    global $colors, $config;
    include $config['base_path'] . "/plugins/flowview/lib/open-flash-chart-object.php";
    include $config['base_path'] . "/plugins/flowview/lib/open-flash-chart.php";
    $title = $_REQUEST["title"];
    $chart_type = "bar";
    $column = $_REQUEST["type"];
    $sessionid = $_REQUEST["session"];
    /* get the chart data from the session */
    if (isset($_SESSION['flowview_flows'][$sessionid]['data'])) {
        $data = $_SESSION['flowview_flows'][$sessionid]['data'];
    } else {
        $filter = createfilter($sessionid);
        $data = $_SESSION['flowview_flows'][$sessionid]['data'];
    }
    switch ($column) {
        case 'flows':
            $unit = ucfirst($column);
            $suffix = "Total Flows";
            $_SESSION['sess_flows_flows'] = 'on';
            break;
        case 'bytes':
            $unit = ucfirst($column);
            $suffix = "Bytes Exchanged";
            $_SESSION['sess_flows_bytes'] = 'on';
            break;
        case 'packets':
            $unit = ucfirst($column);
            $suffix = "Packets Examined";
            $_SESSION['sess_flows_packets'] = 'on';
            break;
    }
    $columns = $_SESSION['flowview_flows'][$sessionid]['columns'];
    foreach ($columns as $key => $cdata) {
        if (strtolower($cdata) == $column) {
            $column = $key;
        }
    }
    if (sizeof($data)) {
        $elements = array();
        $legend = array();
        $maxvalue = 0;
        if (isset($_REQUEST['exclude']) && $_REQUEST['exclude'] > 0) {
            for ($i = 0; $i < $_REQUEST['exclude']; $i++) {
                array_shift($data);
            }
        }
        foreach ($data as $row) {
            if ($maxvalue < $row[$column]) {
                $maxvalue = $row[$column];
                $scaling = flowview_autoscale($row[$column]);
            }
        }
        $maxvalue = flowview_getmax($maxvalue);
        $autorange = flowview_autoscale($maxvalue);
        $maxvalue = $maxvalue / $autorange[0];
        $i = 0;
        foreach ($data as $row) {
            $elements[$i] = new bar_value(round($row[$column] / $autorange[0], 3));
            $elements[$i]->set_colour(flowview_get_color());
            $elements[$i]->set_tooltip($unit . ": #val# " . $autorange[1]);
            if (sizeof($row) == 4) {
                $legend[] = $row[0];
            } else {
                $legend[] = $row[0] . " -\n" . $row[1];
            }
            $i++;
        }
        $bar = new bar_glass();
        $bar->set_values($elements);
        $title = new title($title . " (" . $suffix . ")");
        $title->set_style("{font-size: 18px; color: #444444; text-align: center;}");
        $x_axis_labels = new x_axis_labels();
        $x_axis_labels->set_size(10);
        $x_axis_labels->rotate(45);
        $x_axis_labels->set_labels($legend);
        $x_axis = new x_axis();
        //$x_axis->set_3d( 3 );
        $x_axis->set_colours('#909090', '#909090');
        $x_axis->set_labels($x_axis_labels);
        $y_axis = new y_axis();
        $y_axis->set_offset(true);
        $y_axis->set_colours('#909090', '#909090');
        $y_axis->set_range(0, $maxvalue, $maxvalue / 10);
        $y_axis->set_label_text("#val# " . $autorange[1]);
        $chart = new open_flash_chart();
        $chart->set_title($title);
        $chart->add_element($bar);
        $chart->set_x_axis($x_axis);
        $chart->add_y_axis($y_axis);
        $chart->set_bg_colour('#FEFEFE');
        echo $chart->toString();
    }
}
Example #6
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
);
    }
 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 #9
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 #10
0
    //Pie 3
    //Pie 1
    $chart1 = new open_flash_chart();
    $chart1->set_bg_colour('#EEEEEE');
    $chart1->set_title($title1);
    $chart1->add_element($pie1);
    $chart1->x_axis = null;
    //Pie 2
    $chart2 = new open_flash_chart();
    $chart2->set_bg_colour('#EEEEEE');
    $chart2->set_title($title2);
    $chart2->add_element($pie2);
    $chart2->x_axis = null;
    //Pie 3
    $chart3 = new open_flash_chart();
    $chart3->set_bg_colour('#EEEEEE');
    $chart3->set_title($title3);
    $chart3->add_element($pie3);
    $chart3->x_axis = null;
}
if ($hasData == true) {
    ?>
<script type="text/javascript" src="http://noisestats.radumicu.info/OFC/js/json/json2.js"></script>
<script type="text/javascript" src="http://noisestats.radumicu.info/OFC/js/swfobject.js"></script>
<script type="text/javascript">
swfobject.embedSWF("http://noisestats.radumicu.info/OFC/open-flash-chart.swf", "my_chart_1", "400", "300", "9.0.0", "expressInstall.swf", {"get-data":"get_data_1"},{"wmode":"transparent"});
swfobject.embedSWF("http://noisestats.radumicu.info/OFC/open-flash-chart.swf", "my_chart_2", "400", "300", "9.0.0", "expressInstall.swf", {"get-data":"get_data_2"},{"wmode":"transparent"});
swfobject.embedSWF("http://noisestats.radumicu.info/OFC/open-flash-chart.swf", "my_chart_3", "360", "300", "9.0.0", "expressInstall.swf", {"get-data":"get_data_3"},{"wmode":"transparent"});
function ofc_ready() {/*alert('ofc_ready');*/}
function get_data_1(){return JSON.stringify(data_1);}
function get_data_2(){return JSON.stringify(data_2);}
Example #11
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;
    }
Example #12
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;
 }
 /**
  * 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);
 }
 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);
 }
Example #15
0
function report_chart($data)
{
    // Chart
    //
    // This is the MODEL section:
    //
    include 'open-flash-chart/php-ofc-library/open-flash-chart.php';
    $title = new title("Availability Report ");
    $pie = new pie();
    $pie->set_alpha(0.9);
    $pie->radius(90);
    //$pie->start_angle(100);
    $pie->add_animation(new pie_fade());
    $pie->set_tooltip('#label#: #percent#<br>#val# of #total#<br>');
    $status_colors = array(ok => '#77CC6D', critical => '#FF0000', warning => '#FFD40F', unknown => '#6D86CC', no_data => '#848484');
    $status_name = array(ok => 'Ok', critical => 'Critical', warning => 'Warning', unknown => 'Unknown', no_data => 'No Data');
    $col = array();
    $d = array();
    foreach ($data as $name => $value) {
        if ($value > 0) {
            $d[] = new pie_value($value * 1, "{$status_name[$name]}");
            array_push($col, $status_colors[$name]);
        }
    }
    $pie->set_values($d);
    $pie->set_colours($col);
    $chart = new open_flash_chart();
    $chart->set_title($title);
    $chart->add_element($pie);
    $chart->x_axis = null;
    $chart->set_bg_colour('#202020');
    $title->set_style("{font-size: 16px; font-family: Times New Roman; font-weight: bold; color: #000; text-align: center;}");
    $chart->set_bg_colour('#FFFFFF');
    $chart->set_title($title);
    // This is the VIEW section:
    // Should print this first.
    //
    $heading = "\n        <script type='text/javascript' src='open-flash-chart/js/json/json2.js'></script>\n        <script type='text/javascript' src='open-flash-chart/js/swfobject.js'></script>\n        <script type='text/javascript'>\n        swfobject.embedSWF('open-flash-chart/open-flash-chart.swf', 'my_chart', '300', '300', '9.0.0');\n        </script>\n\n        <script type='text/javascript'>\n\n        function open_flash_chart_data() {\n                return JSON.stringify(data);\n        }\n\n        function findSWF(movieName) {\n                if (navigator.appName.indexOf('Microsoft')!= -1) {\n                        return window[movieName];\n                } else {\n                        return document[movieName];\n                }\n        }\n    \n        var data = " . $chart->toPrettyString() . "\n\n        </script>\n\n\n        <script type=\"text/javascript\">\n \n        OFC = {};\n \n        OFC.jquery = {\n        name: 'jQuery',\n        version: function(src) { return \$('#'+ src)[0].get_version() },\n        rasterize: function (src, dst) { \$('#'+ dst).replaceWith(OFC.jquery.image(src)) },\n        image: function(src) { return \"<img src='data:image/png;base64,\" + \$('#'+src)[0].get_img_binary() + \"' />\"},\n        popup: function(src) {\n        var img_win = window.open('', 'Charts: Export as Image')\n        with(img_win.document) {\n            write('<html><head><title>Charts: Export as Image<\\/title><\\/head><body>' + OFC.jquery.image(src) + '<\\/body><\\/html>') }\n                // stop the 'loading...' message\n                img_win.document.close();\n        }\n        }\n \n        // Using_ an object as namespaces is JS Best Practice. I like the Control.XXX style.\n        //if (!Control) {var Control = {}}\n        //if (typeof(Control == \"undefined\")) {var Control = {}}\n        if (typeof(Control == \"undefined\")) {var Control = {OFC: OFC.jquery}}\n \n \n        // By default, right-clicking on OFC and choosing \"save image locally\" calls this function.\n        // You are free to change the code in OFC and call my wrapper (Control.OFC.your_favorite_save_method)\n        // function save_image() { alert(1); Control.OFC.popup('my_chart') }\n        function save_image() { alert(\"Your image will be displayed in a new window\"); OFC.jquery.popup('my_chart') }\n        </script>\n        <div id='my_chart' style='float:left; margin-left:28px;'></div>\n        ";
    return $heading;
}
Example #16
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} ";
}
 function _setPointsChartdata($config)
 {
     require_once JLG_PATH_SITE . DS . "assets" . DS . "classes" . DS . "open-flash-chart" . DS . "open-flash-chart.php";
     $data = $this->get('PointsChartData');
     //echo 'data -> <pre> '.print_r($data,true).'</pre><br>';
     // Calculate Values for Chart Object
     $userpoints = array();
     $round_labels = array();
     foreach ($data as $rw) {
         if (!$rw->points) {
             $rw->points = 0;
         }
         $userpoints[] = (int) $rw->points;
         $round_labels[] = $rw->roundcode;
     }
     $chart = new open_flash_chart();
     $chart->set_bg_colour($config['bg_colour']);
     if (!empty($userpoints)) {
         $bar = new $config['bartype_1']();
         $bar->set_values($userpoints);
         $bar->set_tooltip(JText::_('COM_JOOMLEAGUE_PRED_USER_POINTS') . ": #val#");
         $bar->set_colour($config['bar1']);
         $bar->set_on_show(new bar_on_show($config['animation_1'], $config['cascade_1'], $config['delay_1']));
         $chart->add_element($bar);
     }
     //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($userpoints) + 2, 1);
     $y->set_steps(round(@max($userpoints) / 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('pointschartdata', $chart);
 }
    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
);
    }
 public function get_jx_json_bar($info, $type = '')
 {
     $year = array_keys($info);
     $price = array_values($info);
     $chart = new open_flash_chart();
     $chart->set_bg_colour('#FFFFFF');
     //flash背景颜色
     $x_labels = new x_axis_labels();
     $x_labels->set_steps(1);
     $x_labels->set_size(12);
     $x_labels->set_colour('#000000');
     if (count($year) > 0) {
         $x_labels->set_vertical();
     }
     $x_labels->set_labels($year);
     //		// 插入数据
     $x = new x_axis();
     $x->set_colour('#000000');
     $x->set_grid_colour('#dadada');
     $x->set_offset(true);
     $x->set_steps(1);
     // Add the X Axis Labels to the X Axis
     $x->set_labels($x_labels);
     $x->set_offset(true);
     $chart->set_x_axis($x);
     //		$bar = new bar_filled( '#74b1e0', '#9dc7e8' );
     //		$bar->set_values( $price );
     $price_array = array();
     foreach ($price as $k => $v) {
         $price_array[$k] = new bar_value($v);
         $price_array[$k]->set_colour('#74b1e0');
         if ($type == 'percent') {
             //$y->set_label_text("#val#%");
             $price_array[$k]->set_tooltip($year[$k] . '<br>' . '' . number_format($v) . '%');
         } else {
             $price_array[$k]->set_tooltip($year[$k] . '<br>' . '' . number_format($v));
         }
     }
     $bar = new bar_glass();
     $bar->set_values($price_array);
     $chart->add_element($bar);
     //
     // LOOK:
     //
     //$x_legend = new x_legend( '1983 to 2008' );
     //$x_legend->set_style( '{font-size: 20px; color: #778877}' );
     //$chart->set_x_legend( $x_legend );
     //
     // remove this when the Y Axis is smarter
     //
     $y = new y_axis();
     $max = $this->get_the_right_y(max($price));
     $max = $max > 0 ? $max : 1;
     $y->set_range(0, ($max / 5 + 1) * 5, $max / 5 + 1);
     //		if ($max > 20 && $max <= 100) {
     //
     //			$y->set_range(0, $max, 10);
     //		}elseif($max >= 10&&$max<=20){
     //			$y->set_range(0, $max, 5);
     //		}
     //		else {
     //			$y->set_range(0, $max);
     //		}
     $y->set_colour('#000000');
     $y->set_grid_colour('#dadada');
     if ($type == 'percent') {
         $y->set_label_text("       #val#%");
     } else {
         $y->set_label_text("       #val#");
     }
     $chart->add_y_axis($y);
     $info = $chart->toPrettyString();
     return $info;
 }
Example #20
0
 function netio()
 {
     function bit_to_kb($n)
     {
         return round($n / 1000, 2);
     }
     function bit_to_mb($n)
     {
         return round($n / 1000000, 2);
     }
     function get_data()
     {
         $recv_l = trim(shell_exec("cat /sys/class/net/eth0/statistics/rx_bytes")) / 8;
         sleep(1);
         $recv_n = trim(shell_exec("cat /sys/class/net/eth0/statistics/rx_bytes")) / 8;
         return $recv_n - $recv_l;
     }
     if (array_key_exists('netio', $_SESSION) && array_key_exists('recv_l', $_SESSION)) {
         if (count($_SESSION['netio']) == 10) {
             array_shift($_SESSION['netio']);
             $_SESSION['netio'][] = get_data();
         } else {
             $_SESSION['netio'][] = get_data();
             $_SESSION['recv_l'] = end($_SESSION['netio']);
         }
     } else {
         $_SESSION['netio'] = array(0, 0, 0, 0, 0, 0, 0, 0, 0);
         $_SESSION['netio'][] = get_data();
         $_SESSION['recv_l'] = end($_SESSION['netio']);
     }
     $data = $_SESSION['netio'];
     /*
       $data = array();
     
       for($i=0;$i<40;$i++){
       $data[] = rand(1000000,10000000);
       }
     */
     foreach (range(1, 10) as $i) {
         settype($i, 'string');
         $second[] = $i;
     }
     if (max($data) <= 1000) {
         $data = array_map("bit_to_kb", $data);
         $y_axis_max = 1;
         $y_axis_key_text = " KB/s";
     } elseif (max($data) <= 10000) {
         $data = array_map("bit_to_kb", $data);
         $y_axis_max = 10;
         $y_axis_key_text = " KB/s";
     } elseif (max($data) <= 100000) {
         $data = array_map("bit_to_kb", $data);
         $y_axis_max = 100;
         $y_axis_key_text = " KB/s";
     } elseif (max($data) <= 1000000) {
         $data = array_map("bit_to_kb", $data);
         $y_axis_max = 1000;
         $y_axis_key_text = " KB/s";
     } elseif (max($data) <= 10000000) {
         $data = array_map("bit_to_mb", $data);
         $y_axis_max = 10;
         $y_axis_key_text = " MB/s";
     } else {
         $data = array_map("bit_to_mb", $data);
         $y_axis_max = 100;
         $y_axis_key_text = " MB/s";
     }
     $y_axis_step = $y_axis_max / 5;
     $chart = new open_flash_chart();
     $title = new title("实时流量显示");
     $title->set_style("{font-size: 12px; color: #A2ACBA; text-align: center;}");
     $chart->set_title($title);
     #点是指曲线图上的顶点
     #		$d = new dot();
     #		$d->colour('#9C0E57')->size(3);
     $area = new area();
     #width是指曲线的宽度
     #		$area->set_width(3);
     #		$area->set_default_dot_style($d);
     $area->set_colour('#5B56B6');
     #value即曲线顶的值
     $area->set_values($data);
     #左上角的文字
     $area->set_key($y_axis_key_text, 10);
     $area->set_fill_colour('#CCCAAA');
     #设透明度
     $area->set_fill_alpha(0.3);
     #area设置结束,使用add_element方法把area加进来
     $chart->add_element($area);
     $chart->set_bg_colour('#FFFFFF');
     #设置label
     $x_labels = new x_axis_labels();
     $x_labels->set_steps(1);
     $x_labels->set_colour('#A2ACBA');
     $x_labels->set_labels($second);
     #设置X轴
     $x_axis = new x_axis();
     $x_axis->set_colour('#A2ACBA');
     $x_axis->set_grid_colour('#D7E4A3');
     $x_axis->set_offset(false);
     $x_axis->set_steps(1);
     $x_axis->set_labels($x_labels);
     $chart->set_x_axis($x_axis);
     #设置X轴的文件说明,即x_legend
     $legend_text = "当前网络流量 " . end($data) . $y_axis_key_text;
     $x_legend = new x_legend($legend_text);
     $x_legend->set_style('{font-size: 12px; color: #778877}');
     $chart->set_x_legend($x_legend);
     #设置轴
     $y_axis = new y_axis();
     $y_axis->set_range(0, $y_axis_max, $y_axis_step);
     $y_axis->labels = null;
     $y_axis->set_offset(false);
     $chart->add_y_axis($y_axis);
     header("Cache-Control: cache, must-revalidate");
     header("Pragma: public");
     echo $chart->toPrettyString();
 }
Example #21
0
<?php

$this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate');
$this->output->set_header('Pragma: public');
$title = new title($title);
$pie = new pie();
$pie->set_alpha(0.6);
$pie->set_start_angle(35);
$pie->add_animation(new pie_fade());
$pie->set_tooltip('#val# of #total#<br>#percent# of 100%');
$pie->set_colours(get_random_colors(count($data)));
$pie_values = [];
foreach ($data as $label => $value) {
    $pie_values[] = new pie_value((double) $value, (string) $label);
}
$pie->set_values($pie_values);
$chart = new open_flash_chart();
$chart->set_title($title);
$chart->set_bg_colour('#f3f3f3');
$chart->add_element($pie);
$chart->x_axis = null;
echo $chart->toPrettyString();
Example #22
0
function report_chart($data)
{
    $title = new title("Availability Report ");
    $pie = new pie();
    $pie->set_alpha(0.9);
    $pie->radius(90);
    //$pie->start_angle(100);
    $pie->add_animation(new pie_fade());
    $pie->set_tooltip('#label#: #percent#<br>#val# of #total#<br>');
    $status_colors = array(free => '#77CC6D', assigned => '#FF0000', reserved => '#6D86CC', free2 => '#77CC6D', assigned2 => '#FF0000', reserved2 => '#6D86CC');
    $status_name = array(free => 'FREE', assigned => 'ASSIGNED', reserved => 'RESERVED', free2 => 'FREE', assigned2 => 'ASSIGNED', reserved2 => 'RESERVED');
    $col = array();
    $d = array();
    foreach ($data as $name => $value) {
        if ($value > 0) {
            $d[] = new pie_value($value * 1, "{$status_name[$name]}");
            array_push($col, $status_colors[$name]);
        }
    }
    $pie->set_values($d);
    $pie->set_colours($col);
    $chart = new open_flash_chart();
    $chart->set_title($title);
    $chart->add_element($pie);
    $chart->x_axis = null;
    $chart->set_bg_colour('#202020');
    $title->set_style("{font-size: 16px; font-family: Times New Roman; font-weight: bold; color: #000; text-align: center;}");
    $chart->set_bg_colour('#FFFFFF');
    $chart->set_title($title);
    // This is the VIEW section:
    // Should print this first.
    //
    $heading = "\n        <script type='text/javascript'>\n    \n        var data = " . $chart->toPrettyString() . "\n\n        </script>\n\n\n        <script type=\"text/javascript\">\n \n        OFC = {};\n \n        OFC.jquery = {\n        name: 'jQuery',\n        version: function(src) { return \$('#'+ src)[0].get_version() },\n        rasterize: function (src, dst) { \$('#'+ dst).replaceWith(OFC.jquery.image(src)) },\n        image: function(src) { return \"<img src='data:image/png;base64,\" + \$('#'+src)[0].get_img_binary() + \"' />\"},\n        popup: function(src) {\n        var img_win = window.open('', 'Charts: Export as Image')\n        with(img_win.document) {\n            write('<html><head><title>Charts: Export as Image<\\/title><\\/head><body>' + OFC.jquery.image(src) + '<\\/body><\\/html>') }\n                // stop the 'loading...' message\n                img_win.document.close();\n        }\n        }\n \n        // Using_ an object as namespaces is JS Best Practice. I like the Control.XXX style.\n        //if (!Control) {var Control = {}}\n        //if (typeof(Control == \"undefined\")) {var Control = {}}\n        if (typeof(Control == \"undefined\")) {var Control = {OFC: OFC.jquery}}\n \n \n        // By default, right-clicking on OFC and choosing \"save image locally\" calls this function.\n        // You are free to change the code in OFC and call my wrapper (Control.OFC.your_favorite_save_method)\n        // function save_image() { alert(1); Control.OFC.popup('my_chart') }\n        function save_image() { alert(\"Your image will be displayed in a new window\"); OFC.jquery.popup('my_chart') }\n        </script>\n        <div id='my_chart' style='float:left; margin-left:28px;'></div>\n        ";
    return $heading;
}
Example #23
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();
 }
Example #24
0
$candle->set_values($data);
$candle->set_tooltip('#x_label#<br>High: #high#<br>Open: #open#<br>Close: #close#<br>Low: #low#');
$y = new y_axis();
$range = $highest - $lowest;
if ($range < 15) {
    $y->set_range(round($lowest - 1), round($highest + 1), 1);
} else {
    if ($range < 100) {
        $y->set_range(round($lowest - 1), round($highest + 1), 5);
    } else {
        $y->set_range(round($lowest - 10, -1), round($highest + 10, -1), 10);
    }
}
$y->set_grid_colour("#E3E3E3");
$chart = new open_flash_chart();
$chart->set_bg_colour("#FCFCFC");
$chart->set_title($title);
$chart->add_element($candle);
if ($sma_50 == 1) {
    $chart->add_element($line_sma50);
}
if ($sma_25 == 1) {
    $chart->add_element($line_sma25);
}
if ($sma_15 == 1) {
    $chart->add_element($line_sma15);
}
if ($sma_10 == 1) {
    $chart->add_element($line_sma10);
}
if ($sma_5 == 1) {
Example #25
0
}
$chart = new open_flash_chart();
$chart->set_title($title);
$chart->add_element($hbar);
$step_count = $max_value > 0 ? $max_value / 10 : 1;
$x = new x_axis();
$x->set_offset(false);
$x->set_steps($max_value / 10);
$chart->set_x_axis($x);
$y = new y_axis();
$y->set_offset(true);
$y->set_labels($y_labels);
$chart->add_y_axis($y);
if (isset($yaxis_label)) {
    $y_legend = new y_legend($yaxis_label);
    $y_legend->set_style('{font-size: 20px; color: #000000}');
    $chart->set_y_legend($y_legend);
}
if (isset($xaxis_label)) {
    $x_legend = new x_legend($xaxis_label);
    $x_legend->set_style('{font-size: 20px; color: #000000}');
    $chart->set_x_legend($x_legend);
}
$chart->set_bg_colour("#f3f3f3");
$tooltip = new tooltip();
$tooltip->set_hover();
$tooltip->set_stroke(1);
$tooltip->set_colour("#000000");
$tooltip->set_background_colour("#ffffff");
$chart->set_tooltip($tooltip);
echo $chart->toPrettyString();
Example #26
0
 /**
  * public static function to generate two pie charts for the mailing reports
  * It was extracted because there are two graph in mailing for each mailing and general mailing which is the total
  *
  * @param array $results data needed for graph values
  */
 public static function mailingPieChart($results)
 {
     $data = array();
     //First Pie, Pie Chart for HTML/TEXT format
     $valuesFormat = array();
     $pieHtmlValues = new pie_value((int) $results['html_sent'], _JNEWS_GRAPH_LBL_HTML);
     $pieTextValues = new pie_value((int) $results['text_sent'], _JNEWS_GRAPH_LBL_TEXT);
     $valuesFormat[] = $pieHtmlValues;
     $valuesFormat[] = $pieTextValues;
     if (empty($results['html_sent']) && empty($results['text_sent'])) {
         $data['pie1'] = 'empty';
     } else {
         $css = '{font-size:15px;font-weight:bold;color:#0B55C4;}';
         $title = new title(_JNEWS_GRAPH_TITLE_FORMAT);
         //Name of the newsletter
         $title->set_style($css);
         $pieMailing = new pie();
         $pieMailing->set_alpha(0.6);
         $pieMailing->set_start_angle(35);
         $pieMailing->add_animation(new pie_fade());
         $pieMailing->set_tooltip('#val#<br>#percent# of 100%');
         $pieMailing->set_colours(array('#156cbd', '#368d03', '#f7941d', '#ed145a', '#92278f', '#156cbd', '#182972', '#3e5d2b', '#db4b19', '#9d0039', '#440e62'));
         $pieMailing->set_values($valuesFormat);
         $chartPie = new open_flash_chart();
         $chartPie->set_title($title);
         $chartPie->add_element($pieMailing);
         $chartPie->set_bg_colour('#FFFFFF');
         $data['pie1'] = $chartPie->toPrettyString();
     }
     //Second chart, Pie chart for the status of mailing process
     $valuesProcess = array();
     //$pieFailedlValues = new pie_value((int)$results['failed'], _JNEWS_MAILING_FAILED);
     //$pieBounceValues = new pie_value((int)$results['bounces'], _JNEWS_MAILING_BOUNCES);
     $piePendingValues = new pie_value((int) $results['pending'], _JNEWS_MAILING_PENDING);
     $pieSentValues = new pie_value((int) $results['sent'], _JNEWS_MAILING_SENT);
     //$valuesProcess[] = $pieFailedlValues;
     //$valuesProcess[] = $pieBounceValues;
     $valuesProcess[] = $piePendingValues;
     $valuesProcess[] = $pieSentValues;
     //if(!empty($results['failed']) && !empty($results['pending']) && !empty($results['bounces'])){
     if (!empty($results['sent']) || !empty($results['pending'])) {
         $css = '{font-size:15px;font-weight:bold;color:#0B55C4;}';
         $title = new title(_JNEWS_GRAPH_PIE_TITLE_MAIL);
         //Name of the newsletter
         $title->set_style($css);
         $pieMailing = new pie();
         $pieMailing->set_alpha(0.6);
         $pieMailing->set_start_angle(35);
         $pieMailing->add_animation(new pie_fade());
         $pieMailing->set_tooltip('#val#<br>#percent# of 100%');
         $pieMailing->set_colours(array('#156cbd', '#368d03', '#f7941d', '#ed145a', '#92278f', '#156cbd', '#182972', '#3e5d2b', '#db4b19', '#9d0039', '#440e62'));
         $pieMailing->set_values($valuesProcess);
         $chartPie = new open_flash_chart();
         $chartPie->set_title($title);
         $chartPie->add_element($pieMailing);
         $chartPie->set_bg_colour('#FFFFFF');
         $data['pie2'] = $chartPie->toPrettyString();
     } else {
         $data['pie2'] = 'empty';
     }
     return $data;
 }
Example #27
0
    $line_tot->set_width(2);
    $line_tot->set_key('Gesamt (kWh)', 10);
    $line_tot->set_tooltip("#val# kWh");
    $max = max(max($data_watt), $max_val) * 1.15;
    $y = new y_axis();
    $y->set_range(0, $max, round($max * 0.1, -1));
    $x_labels = new x_axis_labels();
    $x_labels->set_vertical();
    $x_labels->set_steps(6);
    $x_labels->set_colour('#333333');
    $x_labels->set_labels($time_axis);
    $x = new x_axis();
    $x->set_colour('#333333');
    $x->set_grid_colour('#ffffff');
    $x->set_offset(false);
    $x->set_steps(3);
    // Add the X Axis Labels to the X Axis
    $x->set_labels($x_labels);
    $chart = new open_flash_chart();
    $chart->set_tooltip($tooltip);
    $chart->set_title($title);
    //$chart->add_element( $line_max );
    $chart->add_element($line_watt);
    $chart->add_element($bars_curr);
    //$chart->add_element( $line_tot );
    //$chart->add_element( $sline );
    $chart->set_bg_colour('#ffffff');
    $chart->set_y_axis($y);
    $chart->set_x_axis($x);
    echo $chart->toString();
}
Example #28
0
 private function getChart($aGraphs)
 {
     $this->prepareData();
     $oLabels = new x_axis_labels();
     $oLabels->set_labels($this->aData[0]);
     $oLabels->rotate(-45);
     $oX = new x_axis();
     $oX->set_labels($oLabels);
     $oX->set_colours('#000000', '#ffffff');
     $oChart = new open_flash_chart();
     $oChart->set_bg_colour('#FFFFFF');
     $oTitle = new title($this->getTitle());
     $oTitle->set_style('font-size: 12px; font-weight: bold;');
     $oChart->set_title($oTitle);
     $oTooltip = new tooltip('#val#');
     $oTooltip->set_body_style('font-size: 10px');
     $oTooltip->set_stroke(1);
     $oTooltip->set_shadow(true);
     $oTooltip->set_background_colour('#ffffcc');
     $oTooltip->set_colour('#cccc99');
     $oChart->set_tooltip($oTooltip);
     $aY = array();
     foreach ($aGraphs as $k => $v) {
         $y = empty($v['y-right']) ? 0 : 1;
         $scale = empty($v['scale']) ? 1 : $v['scale'];
         if (!isset($aY[$y])) {
             $aY[$y] = new y_axis();
             $aY[$y]->set_colours($v['colour'], '#f6f6f6');
         }
         if (empty($v['y-remap'])) {
             $this->setAxisRange($aY[$y], $k, $scale);
         } else {
             $this->remapSeries($aY[$y], $k, $scale);
         }
         $oSeries = $this->getSeries($k, $v['type'], $v['colour']);
         if (!empty($this->drillDown)) {
             $oSeries->set_on_click($this->drillDown);
         }
         $oSeries->set_on_show($v['effect']);
         if ($y) {
             $oSeries->attach_to_right_y_axis();
         }
         $aGraphs[$k] = $oSeries;
     }
     $oChart->set_x_axis($oX);
     foreach ($aY as $y => $e) {
         $method = $y ? 'set_y_axis_right' : 'set_y_axis';
         $oChart->{$method}($e);
     }
     foreach ($aGraphs as $e) {
         $oChart->add_element($e);
     }
     return $oChart;
 }
Example #29
0
$brval[]=620;
$brval[]=350;
$brval[]=470;
$brval[]=134;
$brval[]=267;
$brval[]=534;
*/
$tmp = 0;
$d = array();
for ($i = 0; $i < $ii; $i++) {
    $tmp = new pie_value(intval($brval[$i]), "");
    //
    // this slice would normally be light green
    // but we are overriding the colour here:
    //
    //$tmp->set_colour( '#'.$i.'F'.$i.'3C'.$i );
    $tmp->set_label($br[$i], '#BFFF00', 10);
    $d[] = $tmp;
    //
    // here the colour cycle wraps and this gets the
    // first colour:
    //
}
$pie = new pie();
$pie->start_angle(35)->add_animation(new pie_fade())->add_animation(new pie_bounce(4))->gradient_fill()->tooltip('#val# of #total#<br>#percent# of 100%')->colours(array('#B8001F', '#4400A4', '#CD6600', '#E6FE00', '#007ED5', '#54E300'));
$pie->set_values($d);
$chart = new open_flash_chart();
$chart->set_title($title);
$chart->add_element($pie);
$chart->set_bg_colour('#AB4800');
echo $chart->toPrettyString();
Example #30
0
function get_linear_graph($dates, $vals, $keys = array())
{
    include 'php-ofc-library/open-flash-chart.php';
    $max_y = 0;
    $arr_filled = array();
    for ($i = 0; $i < count($dates); $i++) {
        $year[] = $dates[$i];
        for ($m = 0; $m < count($vals); $m++) {
            $price[$m][] = (int) $vals[$m][$i];
            if ($max_y < (int) $vals[$m][$i]) {
                $max_y = (int) $vals[$m][$i];
            }
            if (@$arr_filled[$m] != $vals[$m][$i] and @$arr_filled[$m] == 0) {
                @($arr_filled[$m] = (int) $vals[$m][$i]);
            }
        }
    }
    while ($max_y % 10 != 0) {
        $max_y++;
    }
    $chart = new open_flash_chart();
    //$title = new title( 'UK Petrol price (pence) per Litre' );
    $d = new anchor();
    if (count($dates) > 60) {
        $d->size(2);
    } else {
        $d->size(3);
    }
    $d->halo_size(1);
    $d->colour('#3D5C56');
    $d->rotation(0);
    $d->sides(4);
    for ($i = 0; $i < count($price); $i++) {
        if ($arr_filled[$i] == 0) {
            continue;
        }
        if ($i == 0) {
            $color = '#5E0722';
        } elseif ($i == 1) {
            $color = '#00FF00';
        } else {
            $color = '#FF0000';
        }
        $area = new area();
        $area->set_colour($color);
        $area->set_default_dot_style($d);
        $area->set_values($price[$i]);
        if (isset($keys[$i])) {
            $area->set_key($keys[$i], 12);
        }
        // mb_convert_encoding($keys[$i], "UTF-8", "Windows-1251")
        $area->set_width(2);
        $chart->add_element($area);
    }
    $x_labels = new x_axis_labels();
    if (count($dates) > 40) {
        $x_labels->set_steps(7);
    } else {
        $x_labels->set_steps(1);
    }
    $x_labels->set_vertical();
    $x_labels->set_colour('#000000');
    $x_labels->set_labels($year);
    $x_labels->rotate(-55);
    $x_labels->set_size(12);
    $x = new x_axis();
    $x->set_colour('#000000');
    $x->set_grid_colour('#DDDDDD');
    //$x->set_offset( false );
    $x->set_steps(1);
    // Add the X Axis Labels to the X Axis
    $x->set_labels($x_labels);
    $chart->set_x_axis($x);
    $y = new y_axis();
    $y->set_range(0, $max_y);
    $y->set_colour('#000000');
    $y->set_grid_colour('#DDDDDD');
    $chart->add_y_axis($y);
    $chart->set_bg_colour("#FFFFFF");
    ?>


<script type="text/javascript" src="script/json/json2.js"></script>
<script type="text/javascript" src="script/swfobject.js"></script>
<script type="text/javascript">
swfobject.embedSWF("open-flash-chart.swf", "my_chart", "600", "350", "9.0.0");
</script>

<script type="text/javascript">

function ofc_ready()
{

}

function open_flash_chart_data()
{
	return JSON.stringify(data);
}

function findSWF(movieName) {
	if (navigator.appName.indexOf("Microsoft")!= -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}

var data = <?php 
    echo $chart->toPrettyString();
    ?>
;

</script>
<?php 
}