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

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

class MainMenu {

private $path;
  
  public function __construct($path) {
    if (isset($path)) 
      $this->path = $path;
  }

  public function before() {

    $dal = new DAL();

    $sql = "SELECT path, name FROM mainmenu " . 
           "WHERE rank > 0 AND rank <= " .
           "(SELECT MM.rank FROM mainmenu MM WHERE MM.path = '$this->path') " .
           "ORDER by rank ";
    $items = $dal->query($sql);
  
    $menuBefore = "";
    foreach ($items as $item) {
      $menuBefore .= "
<div onclick='location.href=\"/$item->path\";' 
  style='width:100%;height:50px;background-color:#f1f1f1;cursor:pointer;border: 1px solid black;
         border-radius:5px 5px 0px 0px;border-bottom:none;'>
  <h4>$item->name</h4>
</div>
      ";
    }
    return $menuBefore;
  }
  
  public function after() {

    $dal = new DAL();

    $sql = "SELECT path, name FROM mainmenu " . 
           "WHERE rank > " .
           "(SELECT MM.rank FROM mainmenu MM WHERE MM.path = '$this->path') " .
           "ORDER BY rank";
    $items = $dal->query($sql);
  
    $menuAfter = "";
    foreach ($items as $item) {
      $menuAfter .= "
<div onclick='location.href=\"/$item->path\";' 
  style='width:100%;height:50px;background-color:#f1f1f1;cursor:pointer;border: 1px solid black;
         border-radius:5px 5px 0px 0px;border-bottom:none;'>
  <h4>$item->name</h4>
</div>
      ";
    }
    return $menuAfter;
  }
}
?>  
  
  
