} else {
    $width = 700;
}
if (is_numeric($_GET['height'])) {
    $height = $_GET['height'];
} else {
    $height = 300;
}
if (is_numeric($_GET['nb_months'])) {
    $nb_months = $_GET['nb_months'];
} else {
    $nb_months = 12;
}
if (preg_match("!^[0-9]+(|,[0-9]+)\$!", $_GET['limit_clients'])) {
    // Matches 5 and 10,5 and nothing else
    $limit_clients = "LIMIT " . $_GET['limit_clients'];
} else {
    $limit_clients = "";
}
global $User;
$bar = new barGraph($width, $height, $User->prefs->graphgrid);
$bar->setFont($GLOBALS['_SERVER']['DOCUMENT_ROOT'] . "/css/themes/" . $User->prefs->theme . "/buttonfont.ttf");
$bar->setBarColor(103, 133, 195);
# NBI blue
$result = mysql_query("SELECT sum(fl.prix_ht*fl.qtt) as total, count(f.id_facture) as nb_factures, c.nom\n                       FROM webfinance_invoices as f, webfinance_invoice_rows as fl, webfinance_clients as c\n                       WHERE fl.id_facture=f.id_facture\n                       AND f.type_doc = 'facture'\n                       AND f.id_client = c.id_client\n                       AND f.date_facture>=DATE_SUB(now(), INTERVAL {$nb_months} MONTH)\n                       GROUP BY c.id_client\n                       ORDER BY total DESC\n                       {$limit_clients}") or wf_mysqldie();
$count = mysql_num_rows($result);
while ($billed = mysql_fetch_object($result)) {
    $billed->total = sprintf("%d", $billed->total);
    $bar->addValue($billed->total, $count--, $billed->nom . "\n" . preg_replace("/\\./", ",", sprintf("%.1f", $billed->total / 1000)) . "K€", preg_replace("/\\./", ",", sprintf("%.1f", $billed->total / 1000)) . "K€");
}
$bar->realise();
    die("Argggl");
}
if (is_numeric($_GET['width'])) {
    $width = $_GET['width'];
} else {
    $width = 700;
}
if (is_numeric($_GET['height'])) {
    $height = $_GET['height'];
} else {
    $height = 300;
}
if (is_numeric($_GET['nb_months'])) {
    $nb_months = $_GET['nb_months'];
} else {
    $nb_months = 12;
}
global $User;
$bar = new barGraph($width, $height, $User->prefs->graphgrid);
$bar->setFont($GLOBALS['_SERVER']['DOCUMENT_ROOT'] . "/css/themes/" . $User->prefs->theme . "/buttonfont.ttf");
$bar->setBarColor(255, 92, 92);
for ($i = $nb_months - 1; $i >= 0; $i--) {
    $result = mysql_query("SELECT date_format(date_sub(now(), INTERVAL {$i} MONTH), '%m/%y') as mois_shown, date_format(date_sub(now(), INTERVAL {$i} MONTH), '%Y%m') as mois");
    list($mois_shown, $mois) = mysql_fetch_array($result);
    mysql_free_result($result);
    $result = mysql_query("SELECT sum(fl.prix_ht*fl.qtt) as total, count(f.id_facture) as nb_factures,\n                                 date_format(f.date_facture, '%Y%m') as groupme, date_format(f.date_facture, '%m/%y') as mois\n                         FROM webfinance_invoices as f, webfinance_invoice_rows as fl\n                         WHERE fl.id_facture=f.id_facture\n                         AND f.type_doc = 'facture'\n                         AND f.is_paye=0\n                         AND f.id_client=" . $_GET['id_client'] . "\n                         AND date_format(f.date_facture,'%Y%m') = '{$mois}' GROUP BY groupme") or wf_mysqldie();
    $billed = mysql_fetch_object($result);
    $billed->total = sprintf("%d", $billed->total);
    $bar->addValue($billed->total, $mois_shown, preg_replace("/\\./", ",", sprintf("%.1f", $billed->total / 1000)) . "K€");
}
$bar->realise();