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


class PageMaDozentenUebersicht extends BrowseableObjectsPageBaseWT
{
  private $_data;

  private $_searchdozent;
  private $_statusMessage;
  private $_dozSuchForm;

  public function __construct($pTool, $pData, $pAnzahlAllerDozenten, $pAnzahlDozentenProSeite, $pPageId, $pStatusMessage = '', $pDozSuchForm = '')
  {
    $sprachsettings = new SprachSettingsObject();
    
    parent::__construct('Übersicht der ' . $sprachsettings->Dozent['Plural']['Genitiv'], $pPageId, $pTool, $pAnzahlAllerDozenten, $pAnzahlDozentenProSeite);
    $this->_data = $pData;
    
    
    $this->_searchdozent = (GetOperations::getVarValue('searchdozent', false) ? '&amp;searchdozent=1' : '');
    $this->_statusMessage = $pStatusMessage;
    $this->_dozSuchForm = $pDozSuchForm;
  }

  
  public function getContentHeader()
  {
    $sprachsettings = new SprachSettingsObject();

    return $sprachsettings->Dozent['Plural']['Nominativ'];
  }

  

  
  public function getContent()
  {
    $sprachsettings = new SprachSettingsObject();
    $sectionId4Reiter = 397;

    $menu = new Menu();

    $tool_id = $this->tool->getToolId();
    $toolsection_id = $this->id; 

    $allowDetails = (isset($this->links['dozentenDetails']) && $this->links['dozentenDetails'] ? 2 : 0);
    $result = '';

    if ($this->_statusMessage !== '') {
      $result .= $this->_statusMessage;
    }

    $result .= '<div id="main_content">' . "\n";

    if (!(count($this->_data) == 0 && $this->allgSettings->buttonleite_position == BUTTONBAR_BOTH)
       && ($this->allgSettings->buttonleite_position == BUTTONBAR_TOP || $this->allgSettings->buttonleite_position == BUTTONBAR_BOTH)) {
      $result .= $this->_getMainButtons();
    }

    $counter = 0;
    if (count($this->_data) > 0) {
      foreach ($this->_data as $dozent) {
        $builder = new SightBuilderUebersicht($this->tool->getToolId(), $toolsection_id, $dozent, true);
        $evenClass = ($counter % 2 == 0) ? ' farbe_sicht_erstezeile' : '';
        $result .= '<div class="content_zeile' . $evenClass . '">';
        $result .= '<div class="steuerelemente">';

        if (isset($this->links['checkboxen']) && $this->links['checkboxen']) {
          $result .= '<input type="checkbox" id="doz_' . CleanOperations::cleanInt($dozent->id) . '"  name="' . CleanOperations::cleanInt($dozent->id) . '" class="dozcheckbox markable" value="' . CleanOperations::cleanInt($dozent->id) . '">' . BR_WT;
        }

        
        $result .= $menu->getUserLink(
          '<img src="images/kursdetails.gif" alt="Zu den Details" title="' . CleanOperations::cleanStringForHtml($sprachsettings->Dozent['Plural']['Nominativ']) . 'details">',
          'usertools.php?tool_id=' . CleanOperations::cleanInt($tool_id) . '&toolsection_id=' . $sectionId4Reiter . '&dnr=' . CleanOperations::cleanInt($dozent->id) 
                                      . '&currentIndex=' . CleanOperations::cleanInt($this->currentIndex * $this->objectsPerPage + $counter + 1),
          $allowDetails,
          false
        );

        $result .= '</div>';
        $result .= $builder->buildSight();
        $result .= '</div>' . "\n";
        $counter++;
      }
    } else { 
      if ($this->_searchdozent == '') {
        
        $result .= $this->getNoDataMessageDefault(1);
      } else {
        
        $result .= $this->getNoDataMessageDefault(2);
      }
    }
    $result .= '</div>' . "\n";
    if ($this->allgSettings->buttonleite_position != BUTTONBAR_TOP) {
      $result .= $this->_getMainButtons();
    }

    $result .= $this->_dozSuchForm;

    return $result;
  }

  

  
  private function _getMainButtons()
  {
    $sprachsettings = new SprachSettingsObject();
    $result = '';
    
    if (count($this->_data) > 0) {
      $result .= '<div class="main_buttons doz">';
      

      if (isset($this->links['markieren']) && $this->links['markieren']) {
        $result .= "<input type='image' name='markieren' value='1' src='layout/button_small_markieren.gif' border='0' "
              . " title='Markieren von " . CleanOperations::cleanStringForHtml($sprachsettings->Dozent['Plural']['Akkusativ']) . "' alt='Markieren von " . CleanOperations::cleanStringForHtml($sprachsettings->Dozent['Plural']['Akkusativ']) . "' class=\"alleMarkieren\">\n";
        static $isDialogSet = false;
        if (!$isDialogSet) {
          $result .= $this->_getDialogMarkieren();
          $isDialogSet = true;
        }
      }
    }  
    

    if (isset($this->links['newDozent']) && $this->links['newDozent']) {
      $result .= '<a id="newDozent" class="button_img" href="#" title="neuer Dozent">'
                   . HTMLOperations::createButtonSpan('neuer Dozent', 'neuer Dozent', '', '', 'images/dozadd.gif')
                   . '</a>' . "\n";
    }


    

    $dozent = CleanOperations::cleanStringForHtml($sprachsettings->Dozent['Plural']['Akkusativ']);
    if (count($this->_data) > 0) {
      if (isset($this->links['print']) && $this->links['print']) {
        $result .= '<a href="javascript:window.print();" id="DruckKurse" title="' . $dozent . 'liste drucken">'
                   . '<img src="layout/button_druck_small.gif" alt="' . $dozent . 'liste drucken"></a>' . "\n";
      }
    }

    
    if (count($this->_data) > 0 || $this->_searchdozent != '') {
      if (isset($this->links['filter'])) {
        
        $imgText = '<img src="layout/button_search_small24.gif" title="Suchfilter" alt="Suchfilter">';
        $result .= $this->getLinkButton4JS($imgText, '', 'Suchfilter', $this->links['filter'], '#ui-dialog-title-dozentensuche', false, 'smallmargin_right dozSuchbutton');
      }
    }
    if (count($this->_data) > 0) {
      
      $result .= $this->getNavigaton();

      $result .= "\n" . '</div>' . "\n";
    }  

    return $result;
  }

  

  
  protected function getNoDataMessageDefault($messageType)
  {
    $sprachSettings = SettingsFactory::getSettings('SprachSettingsObject');
    switch ($messageType) {
      default:
      case 1: 
        $message = 'Es sind keine ' . $sprachSettings->Dozent['Plural']['Nominativ'] . ' vorhanden.';

        break;
      case 2: 
        $message = 'Für Ihre Filteroptionen wurden keine ' . $sprachSettings->Dozent['Plural']['Nominativ'] . ' gefunden';
        break;
    }

    return $this->getNoDataMessage($message);
  }

  
  private function _getDialogMarkieren()
  {
    $sprachsettings = new SprachSettingsObject();
    $textAlle = 'Alle ' . BR . 'markieren';
    $titleAltAlle = 'Alle ' . $sprachsettings->Dozent['Plural']['Nominativ'] . ' markieren';
    $textKeiner = 'Alle Markierungen' . BR . 'entfernen';
    $titleAltKeiner = $sprachsettings->Dozent['Plural']['Nominativ'] . ' nicht markieren';
    $textAlleDerSeite = 'Alle dieser' . BR . 'Seite markieren';
    $titleAltAlleDerSeite = $sprachsettings->Dozent['Plural']['Nominativ'] . ' dieser Seite markieren';
    $textKeinerDerSeite = ' Markierungen dieser ' . BR . 'Seite entfernen';
    $titleAltKeinerDerSeite = $sprachsettings->Dozent['Plural']['Nominativ'] . ' dieser Seite nicht markieren';

    return '<div id="dialog_markierenneu">'
              . '<div class="nowrap">'

           
              . HTMLOperations::createButtonSpan($textAlle, $titleAltAlle, 'mark', 'markall', 'images/okay.gif')
              . HTMLOperations::createButtonSpan($textKeiner, $titleAltKeiner, 'mark', 'unmarkall', 'images/abort.gif')

            . '</div>'
            . '<div class="nowrap">'
              . HTMLOperations::createButtonSpan($textAlleDerSeite, $titleAltAlleDerSeite, 'mark', 'markside', 'images/okay.gif')
              . HTMLOperations::createButtonSpan($textKeinerDerSeite, $titleAltKeinerDerSeite, 'mark', 'unmarkside', 'images/abort.gif')

            . '</div>'
          . '</div>';
  }

  

  public function getJSDeclarations()
  {
    $result = parent::getJSDeclarations();
    $result .= 'registerNamespace("KuferTools");' . "\n";
    $result .= JsOperations::getDeclarationInt('KuferTools.ToolSectionId', $this->id);
    $result .= $this->getJSForIds($this->_data);

    $sprachSettings = SettingsFactory::getSettings('SprachSettingsObject');
    $result .= JsOperations::getDeclarationJson('KuferTools.Spracheinstellungen', $sprachSettings);
    $result .= 'KuferTools.DozentenInfo;' . "\n";

    return $result;
  }

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

    return $cssAry;
  }

  public function getSpecialJS()
  {
    $fileAry = parent::getSpecialJS();


    $fileAry[] = 'js/MATool/dozinfo.js';  
    $fileAry[] = 'js/MATool/personendetails.js';

    return $fileAry;
  }
}