<?php
 
require_once($_SERVER['DOCUMENT_ROOT'] . '/sys/db.php');

class modReportGenerator  {
  public $scope = "reportgenerator";  
  public $form_defs;  
  public $gen_reports;
  
  public function __construct() {
      
    $dal = new DAL();
    $sql = "SELECT id, name AS Name, repdescription AS Description, " .
           "querycriteria AS 'Condition Inputs' " .
           "FROM reportquery " .
           "WHERE active = 1 AND combineidx < 2 " .
           "ORDER BY name ";
    $this->gen_reports = $dal->query($sql);

    $default = array ("id"=>0, "reportname"=>"", "repdescription"=>"",
                      "queryselect"=>"", "queryfrom"=>"", "querywhere"=>"",
                      "queryorganize"=>"", "querycriteria"=>"");
    $this->form_defs = $this->toObject ($default);
  }

  private function toObject($array) {
    $object = new stdClass();
    foreach ($array as $key => $value) {
      if (is_array($value)) {
        $value = $this->toObject($value);
      }
      $object->$key = $value;
    }
    return $object;
  }


  public function get($prop) {
    return $this->$prop;
  }

}

?>