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

class modContextSelector {

  private $lo_id;
  private $login_name;
  private $selectors;
  private $table_header;
  
  
  public function __construct($lo_id, $en_id, $ig_id, $ic_id, $it_id) {

    $this->lo_id = isset($lo_id) ? $lo_id : 0;
    $en_id = isset($en_id) ? $en_id : 0;
    $ig_id = isset($ig_id) ? $ig_id : 0;
    $ic_id = isset($ic_id) ? $ic_id : 0;
    $it_id = isset($it_id) ? $it_id : 0;

    $dal = new DAL();

    $sql = "SELECT name FROM login WHERE id = $this->lo_id LIMIT 1 ";
    $this->login_name = $dal->query($sql)->name;

    $sql = "DELETE FROM controlcontexttmp WHERE login_id = $this->lo_id ";
    $this->result = $dal->query($sql);

    $sql = "INSERT controlcontexttmp (login_id, summaryid, selectid, field) VALUES " .
           "($this->lo_id, $en_id, $ig_id, 'fkyInstrumentGroup'), " .
           "($this->lo_id, $ig_id, $ic_id, 'fkyInstrumentClass'), " .
           "($this->lo_id, $ic_id, $it_id, 'fkyInstrumentType');  ";
    $this->result = $dal->query($sql);

    $sql = "SELECT CC.field, label, idx, filter, refine, " .
           "targetform, summaryid, selectid, width, type, attr " .
           "FROM menuitem MI, controlcontext CC, controlcontexttmp CT " .
           "WHERE MI.path = 'contextselector' AND CC.menuitem_id = MI.id " .
           "AND CT.field = CC.field AND CT.login_id = $this->lo_id " .
           "ORDER by idx DESC";
    $this->selectors = $dal->query($sql);

    $this->table_header = ["0", "Instrument Name", "Group", "Class", "Type"];
  }

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

?>