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





class RaumanzeigeMobilePageContainer extends DefaultMobilePageContainer{
  public function __construct($pTitle){
    parent::__construct($pTitle);
    $raumanzeigePage = new RaumanzeigeMobilePage();
    $raumanzeigePage->body->content = $raumanzeigePage->getMobileHtml();

    $this->navBarLinks = $this->getMobileToolLinks($raumanzeigePage);
    $this->addPage($raumanzeigePage);

    $raumanzeigePage->addHomeButtonToHeader();
    $raumanzeigePage->addLogoutButtonToHeader();
    $raumanzeigePage->addNavBarToHeader();
  }
}


class RaumanzeigeMobilePage extends DefaultMobilePage {

  public function __construct(){
    parent::__construct(348, TOOL_MOB_RAUMANZEIGE, 'Was findet wo statt');
    $this->dbwork = new DBWorkKurseTage();
    $this->fetchData();
  }

  public function fetchData() {
    parent::fetchData();
    
    
    if(isset($this->urlParameter['dir'])){
      $blaetterForward = $this->urlParameter['dir'];
    } else {
      $blaetterForward = true;
    }     
    
    $this->dbwork->orderby = 'zeit_beg';
    $this->dbwork->orderbyasc = ($this->toolSettings->sortktasc === "1");

    if(isset($this->urlParameter['uhrzeitVon'])){
      $this->dbwork->fromobject->zeit_beg  = $this->urlParameter['uhrzeitVon'];
    }
    if(isset($this->urlParameter['uhrzeitBis'])) {
      $this->dbwork->toobject->zeit_ende  = $this->urlParameter['uhrzeitBis'];
    }    
    if(isset($this->urlParameter['datum'])) {
      $this->dbwork->fromobject->datum = $this->urlParameter['datum'];
      $this->dbwork->toobject->datum   = $this->urlParameter['datum'];
    }
    if(isset($this->urlParameter['aussenstelle'])) {
      $this->dbwork->fromobject->kurs->aussenst = $this->urlParameter['aussenstelle'];
    }
    if(isset($this->urlParameter['kursort'])) {
      $this->dbwork->fromobject->kurs->ort = $this->urlParameter['kursort'];
    }
    if(isset($this->urlParameter['fachbereich'])) {
      $this->dbwork->fromobject->kurs->fachbereich  = $this->urlParameter['fachbereich'];
      $this->dbwork->toobject->kurs->fachbereich    = $this->urlParameter['fachbereich'];
    }
    if(isset($this->urlParameter['knr_von'])) {
      $this->dbwork->fromobject->kurs->id = $this->urlParameter['knr_von'];
    }
    if(isset($this->urlParameter['knr_bis'])) {
      $this->dbwork->toobject->kurs->id = $this->urlParameter['knr_bis'];
    }    

    $this->getColorKtStatus();

    $this->dbwork->fromobject->ausfall = $this->toolSettings->ktstatus;
    $this->dbwork->toobject->ausfall   = $this->toolSettings->ktstatus;

    
    $blaetterId = isset($this->urlParameter['blid']) ? $this->urlParameter['blid'] : '';
    if (empty($blaetterId)){
      
      $firstKt = NULL;
    } else {
      
      $firstKt = $this->dbwork->getKurstag($blaetterId);
    }

    
    $limit = $this->toolSettings->kurstageproseite ? $this->toolSettings->kurstageproseite : 20;
    $this->data = $this->dbwork->getKurstageLimit($firstKt,$limit,$blaetterForward);
    $this->dataCount = count($this->data);
  }

  function getMobileHtml(){      
    $retour = '<ul data-role="listview" data-theme="'.DEFAULT_MOBILE_THEME.'" data-filter="true">'."\n";
    $retour .= $this->getFilterHtml();
  	
  	$retour .= ' <li data-role="list-divider">'."\n";
    $retour .= '  <div align="center" class="listDateHeaderDiv">'."\n";
    $retour .= '   <a href="index.php' . $this->getUrlParamsPrevDay();
    $retour .= '" data-role="button" data-icon="arrow-l" data-iconpos="notext" data-inline="true" data-ajax="false" style="float:left;">Tag zurück</a>'."\n";
    $retour .= '   <a href="index.php' . $this->getUrlParamsNextDay();
    $retour .= '" data-role="button" data-icon="arrow-r" data-iconpos="notext" data-inline="true" data-ajax="false" style="float:right;">Tag vor</a>'."\n";
    $retour .= '<h1 class="raumAnzListDateHeader">' . DateTimeOperations::getWeekDay($this->urlParameter['datum']).', '.$this->urlParameter['datum'] . '</h1>';
    $retour .= '  </div>'."\n";
    $retour .= ' </li>'."\n";

    if($this->isPrevPage()){
      $retour .= '<li data-icon="false"><a href="index.php' . $this->getUrlParamsPrevPage() . '" data-ajax="false">';
      $retour .= '<span class="raumAnzListEarlierButton">früher...</span></a></li>';
    }

    $retour .= $this->getListHTML();

    if($this->isNextPage()){
      $retour .= '<li data-icon="false"><a href="index.php' . $this->getUrlParamsNextPage();
      $retour .= '" data-ajax="false"><span class="raumAnzListLaterButton">später...</span></a></li>';
    }

    $retour .= '</ul>'."\n";
    return $retour;
  }
}

?>