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

  





class PageDozentStornoTermine extends PageBaseWT
{
  private $_dbwkurstage;
  private $_data;
  
  private $_selectedIds;
  private $_dbwdoz;

  public function __construct($pTool, $pData, $pSelectedIds)
  {
    parent::__construct('Storno von Terminen', 1, $pTool);
    $this->_data = $pData;
    $this->_selectedIds = $pSelectedIds;
    $this->_dbwkurstage = new DBWorkKurseTageWT();
    $this->_dbwdoz = new DBWorkDozenten();
    $this->anchor = GetOperations::getVarValue('tab');
  }

  public function getContentHeader()
  {
    return ' Verlegung von Kurs ' . $this->_data->id . ' - ' . $this->_data->kurzbez;
  }

  public function getContent()
  {
    $tab = '';
    if ($this->anchor != '') {
      $tab = '&tab=' . $this->anchor;
    }
    $result = '<form action="' . CleanOperations::cleanStringForHtml($this->links['action'] . $tab) . '" method="post">';
    $result .= '<div id="formular">';
    $result .= $this->_getSonstigenFormularinhalt();
    $result .= '<h3>Betreff:</h3>';
    $result .= '<input class="betreff" name="betreff"  type="text"  value="' . CleanOperations::cleanStringForHtml($this->getBetreffValue()) . '">';
    $result .= $this->_getLabel();

    $result .= '<textarea class="terminstorno_nachrichtenarea" maxlength="1000"  id="terminstorno" name="info">' . "\n";
    $result .= $this->_getTextAreaContent();
    $result .= '</textarea>' . BR_WT;
    $result .= $this->_getLinks4Formular();
    $result .= '</div>' . "\n";
    $result .= '<form>' . "\n";

    return $result;
  }

  protected function getBetreffValue()
  {
    return 'Bitte um eine Terminverlegung für Kurs ' . $this->_data->id . ' - ' . $this->_data->kurzbez;
  }

  protected function _getSonstigenFormularinhalt()
  {
    return '';
  }

  protected function _getLabel()
  {
    return  '<h3>Ihre Nachricht:</h3>';
  }

  protected function _getLinks4Formular()
  {
    $buttons = '<div class="terminstorno">' . "\n";
    $anchor = '';
    if ($this->anchor != '') {
      $anchor = '#' . $this->anchor;
    }
    $buttons .= '<input type="image" id="sendStornoMail" name="Absenden" src="layout/button_send.gif" title="Mail zum Stornieren von Terminen absenden">' . "\n";
    $buttons .= HTMLOperations::CreateBackButton($this->links['back'] . $anchor);
    $buttons .= '</div>' . "\n";

    return $buttons;
  }

  
  protected function _getTextAreaContent()
  {
    $terminAry = array();
    $selectIdsAry = explode(':', $this->_selectedIds);
    foreach ($selectIdsAry as $ktid) {
      
      $terminAry[] = $this->_dbwkurstage->getKurstag($ktid);
    }

    $result = 'Guten Tag, ' . "\r\n" . "\r\n"
               . 'ist es m&ouml;glich, die folgenden Termine f&uuml;r den Kurs ' . CleanOperations::cleanStringForHtml($this->_data->id) . ' - ' . CleanOperations::cleanStringForHtml($this->_data->kurzbez) . ' zu '
               . 'verlegen bzw. zu stornieren?' . "\r\n" . "\r\n";

    foreach ($terminAry as $terminEntry) {
      
      $tab = "\t\t";
      if ($terminEntry->wotaglang === 'Donnerstag') {
        $tab = "\t";
      }
      $result .= '         ' . CleanOperations::cleanStringForHtml($terminEntry->wotaglang) . ',' . $tab . CleanOperations::cleanDateString($terminEntry->datum) . '   ' . CleanOperations::cleanTimeString($terminEntry->zeit_beg) . ' - ' . CleanOperations::cleanTimeString($terminEntry->zeit_ende) . "\r\n";
    }
    $login = SessionOperations::getCurrentWebToolsUser();
    $dozname = '&nbsp;';
    $teltext = '';
    $mobiltext = '';
    if ($login != null && !$login->isEmpty()) {
      if ($login->dnr > 0) {
        $dozent = $this->_dbwdoz->getDozent($login->dnr);
        if (!empty($dozent->tel->wert)) {
          $teltext = 'Tel.: ' . CleanOperations::cleanStringForHtml($dozent->tel->wert);
        }
        if (!empty($dozent->mobil->wert)) {
          $mobiltext = 'Mobil.: ' . CleanOperations::cleanStringForHtml($dozent->mobil->wert);
        }
      }
      if ($login->vorname != '') {
        $dozname = $login->vorname . ' ' . $login->name;
      } else {
        $dozname = $login->name;
      }
    }
    $result .= "\r\n" . "\r\n"
               . ' Mit freundlichen Gr&uuml;&szlig;en' . "\r\n" . "\r\n"
               . '       ' . CleanOperations::cleanStringForHtml($dozname) . ' ' . "\r\n"
               . '       ' . $teltext . ($teltext != '' ? ' ' : '') . "\r\n"
               . '       ' . $mobiltext . '' . "\r\n";

    return $result;
  }

  
  public function getJSDeclarations()
  {
    return parent::getJSDeclarations();
  }

  public function getSpecialJS()
  {
    $fileAry = array();


    $fileAry[] = '../jquery/plugins/jquery.dataTables.min.js';
    $fileAry[] = 'js/Formulare/terminstorno.js';

    return $fileAry;
  }

  
  public function getSpecialCSS()
  {
    $cssAry = parent::getSpecialCss();
    $cssAry[] = './css/doztool.css';

    return $cssAry;
  }
}