#!/usr/bin/php
<?php

    //define('TTF_DIR', '/home/porwig/lcsi/graphs/fonts/');
    define('TTF_DIR', dirname(__FILE__) . '/fonts/');
    ini_set('include_path', ini_get('include_path') . ':/data/sites/www.landscapeonline.com/includes:/usr/share/php4/jpgraph');
    error_reporting(E_ALL ^ E_NOTICE);

    include('jpgraph.php');
    include('jpgraph_line.php');

    $requiredClasses[] = 'base/lcsi_class.php';

    include('lol_common.inc');

    $lcsi = new lcsi_class();
    $monthly = $lcsi->getCurrentMonthSums();

    unset($lcsi);

    foreach($monthly as $ar) {
        $xlabels[] = date('M') . ' ' . $ar['day'];
        $ydata[]   = $ar['price'];
    }

    $title  = 'LCSI - ' . date('F Y');
    $fname = date('Ym') . 'lcsi.jpg';

    $graph = new Graph(800,600);
    $graph->img->SetImgFormat('jpeg');
    $graph->SetMargin(80,80,80,80);
    $graph->SetMarginColor(array(250,250,250));
    $graph->SetScale('textlin',925,1800);
    
    $graph->title->Set($title);
    $graph->title->SetFont(FF_VERDANA,FS_BOLD,14);

    $graph->yaxis->scale->SetGrace(0,0);
    $graph->yaxis->SetFont(FF_ARIAL,FS_NORMAL,10);
    $graph->yaxis->scale->ticks->SupressFirst();
    $graph->xaxis->SetPos('min'); 
    $graph->xaxis->scale->setGrace(10,10);
    $graph->xaxis->SetTickLabels($xlabels);
    $graph->xaxis->SetLabelAngle(45);
    $graph->xaxis->SetFont(FF_ARIAL,FS_BOLD, 12);

    $graph->SetTickDensity(TICKD_DENSE);

    $p1 = new LinePlot($ydata);
    $p1->SetColor('black');
    $p1->SetFillGradient('yellow@0.4', 'red@0.4');
    $p1->value->SetAngle(45);
    $p1->value->SetFont(FF_ARIAL,FS_NORMAL);
    $p1->value->SetFormat("$%0.2f");
    $p1->SetCenter();
    $p1->value->Show();
    $p1->mark->SetType(MARK_FILLEDCIRCLE);

    $graph->Add($p1);

    $fnameLocal = '/data/sites/www.landscapeonline.com/web/lcsi/' . date('Y') . '/' . $fname;

    $graph->Stroke($fnameLocal);
    
    //$remote = "/web/lcsi/" . date('Y') . '/' . $fname;
    /*
    $fh = ftp_connect('www.landscapeonline.com') or die('unable to clear old file');
    if(ftp_login($fh, 'phil-osophy', '30smarts02')) {
        ftp_pasv($fh, TRUE);
        $contents = ftp_nlist($fh, "/web/lcsi");
        if(in_array($fname, $contents) {
            // if the file already exists
            ftp_delete($fh,"/web/lcsi/$fname");
        } 
        ftp_put($fh, $remote, $fnameLocal, FTP_BINARY) or die('unable to upload file');
    } else {
        die('unable to connect to ftp server');
    }
    ftp_close($fh);
    */

    //unlink($fname);

    //$uri = 'ftp://phil-osophy:30smarts02@www.landscapeonline.com/web/lcsi/' . $fname;
?>
