<?php
/**
 * @copyright Tomasz Niewiero (Algorism.pl)
 */
 
    class UI{
        
        public $use_path;
        public $dir;
        static $instance , $i;
        
        /**
         * 
         */
        public function __construct(){
            
            $this -> dir = 'ui';
            $this -> use_path = $this -> dir . (file_exists($this->dir . core::$instance->m) ? core::$instance->m : 'dashboard') . '/';
            
            self::$instance = $this;
            self::$i = $this;
            
        }
        
        /**
         * Użycie modułu względem wywołanej funkcji
         * @param void
         * @return void
         */
        public function useThis(){
            
            if( file_exists( 'ui/' . core::$i->m . '/' . core::$instance->f . '.php' ) ){
                require_once 'ui/' . core::$i->m . '/' . core::$instance->f . '.php';
            } else core::page404();
            
            
        }
        
        public static function menu(){
            
            if( user::$i->mode == 'user' )
            {
                
                $DashboardMenu['index.php?mode=user'] = 'Nowy proces';
                $DashboardMenu['index.php?mode=user&function=history'] = 'Procesy decyzyjne';
                $DashboardMenu['index.php?mode=user&function=game'] = 'Zagraj';

                
            } 
            elseif( user::$i->mode == 'therapist' )
            {
                $DashboardMenu['index.php?mode=therapist'] = 'Decydenci';
                $DashboardMenu['index.php?mode=therapist&function=history'] = 'Procesy decyzyjne';
            } 
            else 
            {
                $DashboardMenu = array();
            }
            
            $html .= '<div class="DashboardMenu">';
            $html .= '<div class="DashboardMenuLabel">';
                $html .= '<ul>';
            
            foreach( $DashboardMenu as $Href => $Anchor ){
                

                
                $current = ( ( 'dashboard/' . core::$i->function ) == strtolower( $Href ) ) ? ' class="current"' : '';
                $html .= '<li><a href="' . $Href . '"'.$current.'>' . $Anchor . '</a></li>';
                
                
                
            }
            
                $html .= '</ul>';
            $html .= '</div>';
            $html .= '</div>';
            
                return $html;
        }
        
        /**
         * Włącz (wyświetl) moduł
         * @return void
         */
        public function on(){
            global $tpl;
            if( isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){
                js::$i->setJSON('html',$tpl->fetch('ui/' . core::$i->m . '/' . core::$instance->f . '.tpl'));
            } else {
                page::$instance->val( $tpl->fetch( 'ui/' . core::$i->m . '/' . core::$instance->f . '.tpl' ) );
            }
        }
        
        
    }



?>