<?php

namespace Drupal\restaurant\Controller;
use Drupal\restaurant\Controller\AppController;


class RestaurantController extends AppController
{
  public function __construct()
  {
    parent::__construct();
    $this->setPath('restaurant' . DIRECTORY_SEPARATOR . 'HtmlScripts' . DIRECTORY_SEPARATOR);
  }


  public function index()
  {
    //$this->redirect('/admin/restaurant/bookings');



    return $this->render('index.phtml');
  }

  public function help()
  {
      $path = get_restaurant_path() . DIRECTORY_SEPARATOR;


      $tableimg = str_replace($_SERVER['DOCUMENT_ROOT'], '', $path) . 'img' . DIRECTORY_SEPARATOR . 'help' . DIRECTORY_SEPARATOR . 'tables.png';
      $times = str_replace($_SERVER['DOCUMENT_ROOT'], '', $path) . 'img' . DIRECTORY_SEPARATOR . 'help' . DIRECTORY_SEPARATOR . 'times.png';

      $help =  $path . 'data' . DIRECTORY_SEPARATOR . 'help.inc.php';

      ob_start();
      require_once $help;
      $return = ob_get_clean();

      return array('#markup' => $return);
  }

  //cache_config  context.context.ajax

  public function page()
  {
    $result = $this->db->fetchAll("show tables");

    foreach ($result as $key => $val) {

      //$count = $this->db->fetchOne("select count(*) from {$val['Tables_in_drupal']}");

      if ($count) {
        echo '<h1>' . $val['Tables_in_drupal'] . '</h1>';
        echo '<p style="color: red;">' . $count . '</p>';
        echo '<br>';

        $table = $this->db->fetchAll("SELECT * FROM {$val['Tables_in_drupal']}");
        if (isset ($table['data'])) {
          unset ($table['data']);
        }
        echo '<pre>';
        print_r ($table);
        echo '</pre>';
      }


    }
    return $this->render('index.phtml');
  }
}
