Esempio n. 1
0
function guifi_stats_chart07()
{
    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 = "0";
        }
        //"3671";
    } else {
        $zone_id = "0";
    }
    $avalue = array();
    $adata = array();
    for ($i = 0; $i < 10; $i++) {
        $adata[] = array(0, 0);
    }
    $vsql = "select sum(if(timestamp_created >= " . $datemin . ",1,0)) as num, count(*) as total, zone_id\n      from {guifi_location}\n      where 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)) {
        if ($record->total >= 20) {
            $vn = $record->num / $record->total * 100;
            $vmin = 0;
            for ($i = 1; $i < 10; $i++) {
                if ($adata[$vmin][1] > $adata[$i][1]) {
                    $vmin = $i;
                }
            }
            if ($vn > $adata[$vmin][1]) {
                $adata[$vmin][0] = $record->zone_id;
                $adata[$vmin][1] = $vn;
            }
        }
    }
    for ($i = 0; $i < 10; $i++) {
        if ($adata[$i][1] != 0) {
            $avalue[$adata[$i][0]] = $adata[$i][1];
        }
    }
    arsort($avalue);
    foreach ($avalue as $key => $value) {
        if ($value != 0) {
            $data[] = array(substr(guifi_get_zone_name($key), 0, 20) . "  �", $value);
        }
    }
    $shapes = array('none');
    $plot = new PHPlot($gwidth, $gheight);
    $plot->SetPlotAreaWorld(0, 0, NULL, NULL);
    $plot->SetFileFormat('png');
    $plot->SetDataType("text-data");
    $plot->SetDataValues($data);
    $plot->SetPlotType("bars");
    $plot->SetXTickIncrement(1);
    $plot->SetSkipBottomTick(TRUE);
    $plot->SetSkipLeftTick(TRUE);
    $plot->SetTickLength(0);
    //$plot->SetXTickPos('none');
    $plot->SetYDataLabelPos('plotin');
    $plot->SetYLabelType('data', 0);
    $plot->SetTickColor('grey');
    $plot->SetTTFPath($gDirTTFfonts);
    $plot->SetFontTTF('title', 'Vera.ttf', 12);
    $plot->SetFontTTF('x_label', 'Vera.ttf', 8);
    if (isset($_GET['title'])) {
        $plot->SetTitle("guifi.net      \n" . t($_GET['title']));
    } else {
        if ($zone_id == "0") {
            $plot->SetTitle("guifi.net      \n" . t('Largest annual increase'));
        } else {
            $plot->SetTitle("guifi.net    " . t('zone') . ": " . guifi_get_zone_name($zone_id) . "\n" . t('Largest annual increase'));
        }
    }
    //$plot->SetXTitle(t('Zones'));
    $plot->SetYTitle(t('% increase'));
    $plot->SetXDataLabelPos('plotdown');
    //$plot->SetXLabelAngle(45);
    $plot->SetXDataLabelAngle(75);
    $plot->SetGridColor('red');
    $plot->SetPlotBorderType('left');
    $plot->SetDataColors(array('orange'));
    $plot->SetTextColor('DimGrey');
    $plot->SetTitleColor('DimGrey');
    $plot->SetLightGridColor('grey');
    $plot->SetBackgroundColor('white');
    $plot->SetTransparentColor('white');
    $plot->SetIsInline(TRUE);
    $plot->DrawGraph();
}
Esempio n. 2
0
function budgets_supplier_sla($supplier, $type, $pager = 50)
{
    guifi_log(GUIFILOG_TRACE, 'budgets_supplier_sla (supplier)', $type);
    if ($type != 'all') {
        $swt = ' AND subject_type = "' . $type . '" ';
    }
    $qquery = 'SELECT * ' . 'FROM {guifi_maintainers} ' . 'WHERE supplier_id=' . $supplier->id . ' ' . $swt . 'ORDER BY timestamp_created desc ';
    guifi_log(GUIFILOG_TRACE, 'budgets_supplier_sla (budgets query)', $qquery);
    $pager = pager_query($qquery, variable_get('default_nodes_main', $pager));
    $output = '';
    $rows = array();
    while ($s = db_fetch_object($pager)) {
        guifi_log(GUIFILOG_TRACE, 'budgets_supplier_sla (row)', $s);
        switch ($s->subject_type) {
            case 'location':
                $n = guifi_get_nodename($s->subject_id);
                $l = 'node/' . $s->subject_id;
                break;
            case 'zone':
                $n = guifi_get_zone_name($s->subject_id);
                $l = 'node/' . $s->subject_id;
                break;
            case 'device':
                $n = guifi_get_devicename($s->subject_id);
                $l = 'guifi/device/' . $s->subject_id . '/view';
                break;
        }
        if ($type == 'all') {
            $n .= ' (' . t($s->subject_type) . ')';
        }
        $u = user_load($s->user_created);
        $rows[] = array(l($s->subject_id . '-' . $n, $l), $s->commitment, $s->sla, $s->sla_resp, $s->sla_fix, l(t('by') . ' ' . $u->name, 'user/' . $s->user_created), format_date($s->timestamp_created));
    }
    if (count($rows) == 0) {
        $rows[] = array(array('data' => t('none'), 'colspan' => 8));
    }
    $header = array(t($type), t('type'), t('SLA'), t('resp.'), t('fix.'), t('created'), null);
    $output = theme('table', $header, $rows);
    $output .= theme('pager', NULL, $pager);
    print theme('page', $output, FALSE);
    return;
}
Esempio n. 3
0
function guifi_ipv4_print_data($zone, $list = 'parents', $ips_allocated)
{
    global $user;
    $header = array(array('data' => t('network')), t('start / end'), array('data' => t('hosts'), 'style' => 'text-align: right;'), t('type'), t('min / max'), array('data' => t('ips used'), 'style' => 'text-align: right;'), array('data' => t('used %'), 'style' => 'text-align: right;'));
    if (user_access('administer guifi networks')) {
        $header = array_merge($header, array(t('operations')));
    }
    if ($list == 'childs') {
        $zones = guifi_zone_childs($zone->id);
        $pager = 1;
        $k = array_search($zone->id, $zones);
        unset($zones[$k]);
    } else {
        $zones = guifi_zone_get_parents($zone->id);
        $pager = 0;
    }
    if (empty($zones)) {
        return t('There is no zones to look at');
    }
    $sql = 'SELECT
            zone, id, base, mask, network_type
          FROM {guifi_networks}
          WHERE zone IN (' . implode(',', $zones) . ')
          ORDER BY FIND_IN_SET(zone,"' . implode(',', $zones) . '")';
    $rows = array();
    $result = pager_query($sql, variable_get('guifi_pagelimit', 10));
    $current_zoneid = -1;
    while ($net = db_fetch_object($result)) {
        $item = _ipcalc($net->base, $net->mask);
        // obtaing the used ip's
        $min = ip2long($item['netstart']);
        $max = ip2long($item['netend']);
        $ips = 0;
        $k = $min;
        $amin = NULL;
        $amax = NULL;
        while ($k <= $max) {
            if (isset($ips_allocated[$k])) {
                $ips++;
                $amax = $k;
                if ($ips == 1) {
                    $amin = $k;
                }
            }
            $k++;
        }
        if ($current_zoneid != $net->zone) {
            $current_zoneid = $net->zone;
            $rows[] = array(array('data' => l(guifi_get_zone_name($net->zone), 'node/' . $net->zone . '/view/ipv4'), 'colspan' => '0'));
        }
        $row = array($net->base . '/' . $item['maskbits'] . ' (' . $net->mask . ')', $item['netstart'] . ' / ' . $item['netend'], array('data' => number_format($item['hosts']), 'align' => 'right'), $net->network_type, long2ip($amin) . ' / ' . long2ip($amax), array('data' => number_format($ips), 'align' => 'right'), array('data' => round($ips * 100 / $item['hosts']) . '%', 'align' => 'right'));
        if (user_access('administer guifi networks')) {
            $row[] = array('data' => l(guifi_img_icon('edit.png'), 'guifi/ipv4/' . $net->id . '/edit', array('html' => TRUE, 'title' => t('edit network'), 'attributes' => array('target' => '_blank'))) . l(guifi_img_icon('drop.png'), 'guifi/ipv4/' . $net->id . '/delete', array('html' => TRUE, 'title' => t('delete device'), 'attributes' => array('target' => '_blank'))), 'align' => 'center');
        }
        $rows[] = $row;
    }
    if (count($rows)) {
        $output .= theme('table', $header, $rows);
        $output .= theme('pager', NULL, variable_get('guifi_pagelimit', 10));
    } else {
        $output .= t('None');
    }
    return $output;
}
Esempio n. 4
0
function guifi_service_str($id, $emptystr = 'Take from parents')
{
    if (empty($id)) {
        return t($emptystr);
    }
    if ($id == -1) {
        return t('No service');
    }
    // there is a value, create the string
    $proxy = guifi_service_load($id);
    $proxystr = $id . '-' . guifi_get_zone_name($proxy->zone_id) . ', ' . $proxy->nick;
    return $proxystr;
}
Esempio n. 5
0
/** guifi_zone_l(): Creates a link to the zone
**/
function guifi_zone_l($id, $title = NULL, $linkto = 'node/')
{
    if ($id == 0) {
        $id = guifi_zone_root();
    }
    if (empty($title)) {
        $title = guifi_get_zone_name($id);
    }
    return l($title, $linkto . $id);
}