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

class modRunProcedure  {
  public $scope = "runprocedure";  
  public $form_defs;  
  public $gen_reports;
  
  public function __construct() {

    $dal = new DAL();

    $sql = "SELECT CI.instance AS field, " .
           "COL.value AS dbcolumn, LAB.value AS label, " .
           "0 AS newvalue, 0 AS dbvalue, '' AS newtext, '' AS dbtext, " .
           "CF.mandatory, CF.uniquekey, CF.confirm, CF.action, " .
           "CF.sequent, CF.sequent_frm, CF.sequent_upd, CF.sequent_ent, CF.sequent_chk " .
           "FROM controlinstance CI, controlform CF, " .
           "controlentry COL, controlentry LAB " . 
           "WHERE LAB.controlinstance_id = CI.id " .
           "AND LAB.property IN ('label', 'noLabel') " .
           "AND COL.controlinstance_id = CI.id AND COL.property = 'column' " .
           "AND CF.controlinstance_id = CI.id AND CF.formhandler_id = " .
           "(SELECT FH.id FROM controlinstance FH " .
           "WHERE FH.instance = 'frmStoredProcedure') ";
    $this->spform_data = $dal->query($sql);  
    
    $default = array ("id"=>0,              "sumid"=>1,
                      "procedurename"=>"",  "procedurename_text"=>"",
                      "proceduredescr"=>"", "proceduredescr_text"=>"",
                      "routinename"=>"",    "routinename_text"=>"",
                      "comments"=>"",       "comments_text"=>"",
                      "parameters"=>"",     "parameters_text"=>"",
                      "filename"=>"",       "filename_text"=>"");
    $this->spform_defs = $this->toObject ($default);

    $header = array('1' => array("mp_id"=>"0", "Procedure Name"=>"", "Description"=>""));
    $this->spheader = $this->toObject ($header);
  }

  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;
  }

}

?>