<?php
include_once("system.php");
include_once("_nemo.control.cls.php");

class NemoBasic
{
   public $SystemSettings = array();
   public $Content;
   public $Layout = "layout.basic.incl.php";
   public $controls;
   public $db;

   public $Message;

   public function __construct()
   {
      global $SystemSettings;

      $this->SystemSettings = $SystemSettings;
      $this->db = new NemoDatabase("");

      if(is_array($_SESSION))
      {//extend the $session into the SysSettings
         foreach($_SESSION as $key => $value)
         {
            $this->SystemSettings[$key] = $value;
         }
      }

      if(is_dir("layouts")){
         $dir = "";
      }else{
         $dir = "../";
      }
      self::loadFileArray("Layouts",$dir. "layouts");//wc
      self::loadFileArray("Modules",$dir. "modules");

      $this->controls = new NemoControl();
   }

   private function __autoload()
   {// only applies to zend

   }

   public function Display()
   {
      include_once($this->Layouts[$this->Layout]);
   }

   function loadFileArray($variable,$strDir)
   {//wc
      $this->$variable = self::readDirectory($strDir);
   }

   function readDirectory($strDir)
   {// wc
      $arrFiles = array();

      if ($handle = opendir($strDir))
      {
         while (false !== ($file = readdir($handle)))
         {
            if ($file != "." && $file != "..")
            {
               $arrFiles[$file] = $strDir."/".$file;
            }
         }
         closedir($handle);
      }

      return $arrFiles;
   }

   protected function headTitle()
   {//gets called from layout.basic
      return $this->SystemSettings["Title"];
   }

   protected function Header()
   {//gets called from layout.basic
      $db = "";
      if($this->SystemSettings[SERVER_NAME] == "lamp"){
         global $DATABASE_SETTINGS;
         $db = ": ". $DATABASE_SETTINGS[lamp]->database;
      }
      return "
      <div id='divHeader'>
         ". $this->SystemSettings["Brand"]. $db ."
      </div id='divHeader'>";//SystemSettings["Title"] ."
   }
   protected function Sandbox()
   {
      return "
      <div id='divContent'>
         ". $this->Content ."
      </div>";
   }
   protected function Footer()
   {//gets called from layout.basic
      return "
      <div id='divFooter' align='center'><BR>
         ". $this->SystemSettings["Brand"] ." &#0153; 2011
         | Developed by <a href='http://www.overdrive.co.za' target=_blank>Silicon Overdrive</a> &copy;
         | ". $this->SystemSettings["System Version"] ."</div>";
   }
   protected function Message()
   {

      switch($this->Message->class)
      {
         case "warning":
         case "restricted":
            $this->Message->class = "divWarning";
            break;
         case "error":
            $this->Message->class = "divError";
            break;
         case "success":
         case "good":
            $this->Message->class = "divGood";
            break;
         case "":
            $this->Message->class = "divMessage";
            break;
      }
      if($this->Message->Text != "")
      return "
      <div id='divMessage'>
         <div class='". $this->Message->class ."'>
         ". $this->Message->Text ."
         </div>
      </div id=message>
      ";
   }

   public function getBrand()
   {
      return $this->SystemSettings["Brand"];
   }
   public function getTitle()
   {
      return $this->SystemSettings["Title"];
   }

}




?>
