<?php

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

class PageVisitenkartenUebersicht extends PageBaseWT
{
  
  private $_data;

  
  private $_statusCode;

  public function __construct($pTool, $pData, $pPageId, $pStatusCode)
  {
    parent::__construct('Visitenkarten', $pPageId, $pTool);
    $this->_data = $pData;
    $this->_statusCode = $pStatusCode;
  }

  public function getContentHeader()
  {
    return 'Visitenkarten';
  }

  
  public function getContent()
  {
    $toolsection_id = $this->id;
    $menu = new Menu();
    $result = '';

    if ($this->_statusCode === 0) {
      $result .= HTMLOperations::getSuccessBox(CleanOperations::cleanStringForHtml($this->allgSettings->successMsgDeleteVisitenkarte), '', 'in_background');
    }

    $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) {
      $result .= '<div id="confirm"></div>';
      foreach ($this->_data as $visitenkarte) {
        $builder = new SightBuilderUebersicht($this->tool->getToolId(), $toolsection_id, $visitenkarte, true);
        $evenClass = ($counter % 2 == 0) ? ' farbe_sicht_erstezeile' : '';

        $result .= '<div class="content_zeile' . $evenClass . '">';
        $result .= '<div class="steuerelemente">';

        $result .= $menu->getUserLink('<img src="images/kursdetails.gif" alt="Zu den Details" title="Visitenkartendetails">', 'usertools.php?tool_id=40&toolsection_id=496&id=' . CleanOperations::cleanInt($visitenkarte->id), 2, false, false, 'details_link');
        $result .= '<a href = "#/" id= "' . CleanOperations::cleanInt($visitenkarte->id) . '" class ="delete"> <img alt="Löschen" title="Löschen" src = "images/delete.png"  style="display:block"></a>';
        

        $result .= '<div class ="clear"></div>';
        $result .= '</div>';
        $result .= $builder->buildSight();
        $result .= '</div>' . "\n";
        $counter++;
      }
    } else { 
      $result .= $this->getNoDataMessage('Es sind keine Visitenkarten vorhanden.');
    }
    $result .= '</div>' . "\n";

    if ($this->allgSettings->buttonleite_position != BUTTONBAR_TOP) {
      $result .= $this->_getMainButtons();
    }

    return $result;
  }

  

  
  private function _getMainButtons()
  {
    $result = '<div class="main_buttons visitenkarte">';
    
    if ($this->links['newVk']) {
      $result .= '<a id="newVisitenkarte" class="button_img" href="usertools.php?tool_id=40&amp;toolsection_id=496" title="neue Visitenkarte">'
              . HTMLOperations::createButtonSpan('neue Visitenkarte', 'neue Visitenkarte', '', '', 'images/add.gif')
              . '</a>' . "\n";
    } else {
      $result .= HTMLOperations::CreateSubmitButton('images/disabled_new_vkrt.png', 'Deaktiviert', 'Diese Taste ist deaktiviert weil Sie keine Zugriffsberechtigung haben', '1') . "\n";
    }
    $result .= '</div>';

    return $result;

    
  }

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

    return array_merge($js, array('js/TNTool/webvisitenkarten.js'));
  }
}