<?php

class css_header{
    private $_css;
    public $_controller;
    public $_def_css;
    
    public function __construct($css, $controller){
        $this->_css = array();
        $this->_def_css = $css;
        $this->_controller = $controller;
    }
    
    public function add($css_file, $path = ""){
        if (gettype ($css_file ) == 'array'){
            foreach($css_file as $file){
                $this->_css[] = $path.$file;
            }
            $this->_css = array_merge($this->_css, $css_file);
        }
        if (gettype ($css_file ) == 'string')
            $this->_css[] = $path.$css_file;
    }
    

    
    public function get_script_css(){
        $rtn = "";
        foreach($this->_css as $css){
            if (strpos($css, "/")!==false){
                if (file_exists ($css)){
                    $rtn .= file_get_contents($css);                    
                }
                        
            }
            else{
                if (file_exists (MAIN_APP_DIRECTORY.'/'.$this->_controller.'/css/'.$css))
                $rtn .= file_get_contents(MAIN_APP_DIRECTORY.'/'.$this->_controller.'/css/'.$css);                    
            }
        }   
        if ($rtn){
            $rtn = "<style>".$rtn."</style>";
        }
        return $rtn;
    }
    
    public function render(){
        $rtn  = "";
        
        foreach($this->_def_css as $css){
            if (file_exists ("general/css/".$css))
                $rtn .= '
                    <link rel="stylesheet" href="general/css/'.$css.'" />';
            
        }        
        foreach($this->_css as $css){
            if (strpos($css, "/")!==false){
                if (file_exists ($css)){
                    $rtn .= '
                    <link rel="stylesheet" href="'.$css.'" />';                    
                }
                        
            }
            else{
                if (file_exists (MAIN_APP_DIRECTORY.'/'.$this->_controller.'/css/'.$css))
                $rtn .= '
                    <link rel="stylesheet" href="'.MAIN_APP_DIRECTORY.'/'.$this->_controller.'/css/'.$css.'" />';
            }
        }    
        return $rtn;
    }
}


?>