<?php
/**
 * @package sichten_plan
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf 
 */




class DefaultMobilePageContainer implements IMobilePageContainer {

  public $pages;
  public $title;
  public $navBarLinks;

  public function __construct($pTitle){    
    $this->pages = array();
    $this->navBarLinks = array();
    $this->title = $pTitle;
  }

  
  public function addPage($pPage, $inNavBar = false, $pNavBarTitle = ''){
    $this->pages[] = $pPage;
    $pPage->inContainer = $this;
    if($inNavBar){
      if(empty($pNavBarTitle)){
        $this->navBarLinks[] = new MobilePageLink($pPage->title, '#' . $pPage->sightId);
      } else {
        $this->navBarLinks[] =  new MobilePageLink($pNavBarTitle, '#' . $pPage->sightId);
      }
    }
  }

  protected function getContainerHeader(){
    $retour = '<!DOCTYPE html>' . "\n";
    $retour .= '<html>' . "\n";
    $retour .= '<head>' . "\n";
    $retour .= '<meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1">' . "\n";
    $retour .= '<meta http-equiv="content-type" content="text/html; charset=' . ConstantOperations::getEncoding4Charset() . '">' . "\n";
    $retour .= '<meta http-equiv="content-language" content="de">' . "\n";
    $retour .= '<meta http-equiv="author" content="Kufer Software GmbH">' . "\n";
    $retour .= '<meta http-equiv="content-style-type" content="text/css">' . "\n";
    $retour .= $this->getCssCode();
    $retour .= $this->getJsCode();
    $retour .= '<title>' . $this->title . '</title>' . "\n";
    $retour .= '</head>' . "\n";
    $retour .= '<body>' . "\n";
    return $retour;
  }

  protected function getStandardCss(){
    return array( 'css/jquery.mobile-1.0.1.min.css');
  }

  protected function getSpecialCss(){
    return array('css/index.css',
                 'css/jquery.mobile.datebox.min.css',
     			 'css/kuferMobile.css');
  }

  protected function getStandardJs(){
    return array( '../jquery/jquery-1.6.1.js',
    
    		      '../jquery/jquery.mobile-1.0.1.js',  
    		      '../jquery/plugins/jquery.mobile.datebox.min.js',                               
                  'http://maps.google.com/maps/api/js?sensor=false'
    );
  }

  protected function getSpecialJs(){
    return array('js/kuferMobile.js');
  }

  
  protected function getMobileToolLinks($pPage) {
    $links = array();
    $userId = SessionOperations::getUserID();
    
    $mobileToolIds = array (TOOL_MOB_BEGINNKURSE, TOOL_MOB_AKTUELLES, TOOL_MOB_RAUMANZEIGE, TOOL_MOB_FEEDBACK);
    
    $mobileTitles = array(26 => TOOL_BEZ_MOB_BEGINNKURSE_MA, 27 => TOOL_BEZ_MOB_RAUMANZEIGE_MA, 28 => TOOL_BEZ_MOB_AKTUELLES_MA,
                          31 => TOOL_BEZ_MOB_FEEDBACK_DOZ);
    $firstToolSections = ConstantOperations::getFirstToolSections();
   
    foreach ($mobileToolIds as $toolId) {
      if (SecurityOperations::checkToolAccess($userId, $toolId, $firstToolSections[$toolId])) {
        
        if ($pPage->sightId === $firstToolSections[$toolId]) {
          $links[] = new MobilePageLink($mobileTitles[$toolId], '#'. $firstToolSections[$toolId], 'data-ajax="false"');
        } else {
          $links[] = new MobilePageLink($mobileTitles[$toolId], 'index.php?tool_id='.$toolId.'&toolsection_id='.$firstToolSections[$toolId].'&einstieg=1', 'data-ajax="false"');
        }
      }
    }       
    return $links;
  }
      
  public function getCssCode(){
    $result = '';
    $cssAry = $this->getStandardCss();
    $cssAry = array_merge($cssAry, $this->getSpecialCss());
    foreach ($cssAry as $value) {
      $result .= '<link rel="stylesheet" media="screen" type="text/css" href="' . $value . '" >' . "\n";
    }
    return $result;
  }

  public function getJsCode()
  {
    $retour = '';
    $jsAry = $this->getStandardJs();
    $jsAry = array_merge($jsAry, $this->getSpecialJs());
    foreach ($jsAry as $value) {
      $retour .= '<script type="text/javascript" src="' . $value . '"></script>' . "\n";
    }
    return $retour;
  }

  public function toHTML(){
    $retour = $this->getContainerHeader();

    foreach ($this->pages as $page) {
      $retour .= $page->toHTML();
    }

    $retour .= "</body>\n</html>";
    return $retour;
  }
}
?>