コード例 #1
0
function guifi_stats_chart06()
{
    include drupal_get_path('module', 'guifi') . '/contrib/phplot/phplot.php';
    $gDirTTFfonts = drupal_get_path('module', 'guifi') . '/contrib/fonts/';
    if (isset($_GET['width'])) {
        $gwidth = $_GET['width'];
    } else {
        $gwidth = 500;
    }
    if (isset($_GET['height'])) {
        $gheight = $_GET['height'];
    } else {
        $gheight = 450;
    }
    $today = getdate();
    $year = $today[year];
    $month = $today[mon];
    $month = $month - 12;
    $n = 0;
    $tot = 0;
    if ($month < 1) {
        $year = $year - 1;
        $month = 12 + $month;
    }
    $datemin = mktime(0, 0, 0, $month, 1, $year);
    if (isset($_GET['zone'])) {
        $zone_id = $_GET['zone'];
        if ($zone_id == "0") {
            $zone_id = "3671";
        }
    } else {
        $zone_id = "3671";
    }
    $azone = array();
    $avalue = array();
    $azone[$zone_id] = array($zone_id);
    $achilds = array_keys(guifi_zone_childs_tree($zone_id, 1));
    foreach ($achilds as $key => $child) {
        if ($child != $zone_id) {
            $azone[$child] = array();
            $avalue[$child] = 0;
            $aschilds = guifi_zone_childs($child);
            foreach ($aschilds as $skey => $schild) {
                array_push($azone[$child], $schild);
            }
        }
    }
    $vsql = "select COUNT(*) as num, zone_id\n      from {guifi_location}\n      where timestamp_created >= " . $datemin . " and status_flag='Working' ";
    if ($zone_id != "0") {
        $achilds = guifi_zone_childs($zone_id);
        $v = "";
        foreach ($achilds as $key => $child) {
            if ($v == "") {
                $v .= "zone_id=" . $child;
            } else {
                $v .= " or zone_id=" . $child;
            }
        }
        $vsql .= "AND (" . $v . ") ";
    }
    $vsql .= "GROUP BY zone_id ";
    $result = db_query($vsql);
    while ($record = db_fetch_object($result)) {
        foreach ($azone as $key => $grupzone) {
            if (in_array($record->zone_id, $grupzone)) {
                $avalue[$key] = $avalue[$key] + $record->num;
            }
        }
    }
    foreach ($avalue as $key => $value) {
        if ($value != 0) {
            $data[] = array(guifi_get_zone_name($key), $value);
            $tot = $tot + $value;
        }
    }
    $shapes = array('none');
    $plot = new PHPlot($gwidth, $gheight);
    $plot->SetPlotAreaWorld(0, 0, NULL, NULL);
    $plot->SetImageBorderType('plain');
    $plot->SetFileFormat('png');
    $plot->SetPlotType("pie");
    $plot->SetDataType("text-data-single");
    $plot->SetDataValues($data);
    $plot->SetDataColors(array('red', 'green', 'blue', 'yellow', 'cyan', 'magenta', 'brown', 'lavender', 'pink', 'gray', 'orange'));
    $plot->SetTTFPath($gDirTTFfonts);
    $plot->SetFontTTF('title', 'Vera.ttf', 12);
    $plot->SetFontTTF('legend', 'Vera.ttf', 7);
    if (isset($_GET['title'])) {
        $plot->SetTitle("guifi.net      \n" . t($_GET['title']));
    } else {
        if ($zone_id == "0") {
            $plot->SetTitle("guifi.net      \n" . t('Last year'));
        } else {
            $plot->SetTitle("guifi.net    \n" . t('zone') . ": " . guifi_get_zone_name($zone_id) . "\n" . t('Last year'));
        }
    }
    $plot->SetShading(1);
    $plot->SetLabelScalePosition(0.45);
    $plot->SetLegendStyle("left", "left");
    $plot->SetLegendPixels(0, 0);
    foreach ($data as $row) {
        $plot->SetLegend(implode(': ', $row));
    }
    $plot->SetIsInline(TRUE);
    $plot->DrawGraph();
}
コード例 #2
0
function guifi_zone_childs_tree_depth($parents, $maxdepth = 1, &$depth = 0)
{
    if (is_numeric($parents)) {
        $parents = array($parents => array('depth' => 0, 'master' => 0));
    }
    guifi_log(GUIFILOG_TRACE, 'function guifi_zone_childs_tree_depth(childs)', $parents);
    // check only current depth
    $current_depth = array();
    foreach ($parents as $k => $v) {
        if ($v['depth'] == $depth) {
            $current_depth[] = $k;
        }
    }
    $depth++;
    $result = db_query('SELECT z.id, z.master ' . 'FROM {guifi_zone} z ' . 'WHERE z.master IN (' . implode(',', $current_depth) . ')');
    $childs = $parents;
    $found = FALSE;
    while ($child = db_fetch_object($result)) {
        $childs[$child->id] = array('depth' => $depth, 'master' => $child->master);
        $found = TRUE;
    }
    if ($found and $depth < $maxdepth) {
        $childs = guifi_zone_childs_tree($childs, $maxdepth, $depth);
    }
    return $childs;
}