<?php
defined('PUBLIC_ACCESS') or die('Restricted Access');

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

class EntryInit {

  public $entryInit = array();
  
  public function __construct($location) {
    
    $dal = new DAL();
    
    $sql   = "SELECT CO.control, CI.instance, CE.property, CE.value " .
             "FROM controlinstance  CI, controlentry  CE, controlobject CO " .
             "WHERE CI.location = '$location' " .
             "AND CE.controlinstance_id = CI.id " .
             "AND CI.controlobject_id = CO.id " .
             "ORDER BY instance ";
    $locationControls = $dal->query($sql);

    $current = "";
    foreach ($locationControls as $element) {

      if ($element->instance != $current) {
        if ($current != "")
          $this->entryInit[] = "\$entry = (object)array( $entry ); $init";

        $init = "
          \$$element->instance = new $element->control (\$entry);
          \$this->".$element->instance."Layout = $".$element->instance."->outputLayout();
          \$this->".$element->instance."Script = $".$element->instance."->outputScript();";
         $comma = "";
         $entry = "";
         $current = $element->instance;
       }
       if ($element->value[0] == '$')
         $entry .= "$comma'$element->property' => $element->value";
       else
         $entry .= "$comma'$element->property' => '$element->value'";
         
       // Add comma separator after first element
       $comma = ',';
    }
    $this->entryInit[] = "\$entry = (object)array( $entry ); $init";

  }  

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

}
?>  
  
  
