<?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 CC.control, CI.instance, CE.property, CE.value " .
             "FROM controlinit  CI, controlentry  CE, controlconfig CC " .
             "WHERE CI.location = '$location' " .
             "AND CE.controlinit_id = CI.id AND CI.controlconfig_id = CC.id " .
             "AND CC.active = 1 AND CE.active = 1 AND CI.active = 1 " .
             "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();";

         $entry = "'$element->property' => $element->value";      
         $current = $element->instance;
       }
       else
         $entry .= ",'$element->property' => $element->value";
    }
    $this->entryInit[] = "\$entry = (object)array( $entry ); $init";

  }  

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

}
?>  
  
  
