<?php

/* CLASS FILE
----------------------------------*/

class graph extends db {

  public $dt;
  public $settings;
  public $years;
  
  public function firstYear() {
    $q = db::db_query("SELECT YEAR(FROM_UNIXTIME(`ts`)) AS `dY` FROM `" . DB_PREFIX . "affiliates`
         ORDER BY `ts`
         LIMIT 1
         ");
    return db::db_object($q);
  }

  public function display() {
    $arr = array(array(0,0,0,0,0,0,0,0,0,0,0,0),array(0,0,0,0,0,0,0,0,0,0,0,0));
    $q = db::db_query("SELECT count(*) AS `dC`,
         MONTH(FROM_UNIXTIME(`ts`)) AS `dM`,
         YEAR(FROM_UNIXTIME(`ts`)) AS `dY`
         FROM `" . DB_PREFIX . "affiliates`
         WHERE YEAR(FROM_UNIXTIME(`ts`)) IN('{$this->years[0]}','{$this->years[1]}')
         AND `approved` = 'yes'
         AND `en` = 'yes'
         GROUP BY YEAR(FROM_UNIXTIME(`ts`)), MONTH(FROM_UNIXTIME(`ts`))
         ");
    while ($G = db::db_object($q)) {
      switch($G->dY) {
        case $this->years[0]:
          $arr[0][($G->dM - 1)] = mswNFM($G->dC);
          break;
        case $this->years[1]:
          $arr[1][($G->dM - 1)] = mswNFM($G->dC);
          break;
      }
    }
    return array(
      implode(',', $arr[0]),
      implode(',', $arr[1])
    );
  }

}

?>