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






class FormularSight extends NormaldetailsSight
{
  public $searchformaction = '#'; 
  public $searchlink = '#';
  public $objcalendar;
  public $dbwss;
  public $datamodul;

  
  public function initiate()
  {
    NormalSight::initiate();
    $this->dbwss = new DBWorkSightsSettings();
  }

  
  public function getTable()
  {
    $str = "<form name='Normaldetailsight' action='" . CleanOperations::cleanStringForHtml($this->searchformaction) . "' method='POST'>";
    $str .= NormaldetailsSight::getTable();
    $str .= '<table>'
            . '  <tr>'
            . "    <td valign='top'>"
            . "      <input type='image' src='layout/button_search.gif'></form>"
            . '    </td>'
            . "    <td valign='top' align='right'>"
            . "      <form action='" . CleanOperations::cleanStringForHtml($this->searchformaction) . "&delSearchSession=true' method='POST'>"
            . "        <input type='image' src='layout/button_clear_search.gif'>"
            . '      </form>'
                . '    </td>'
              . '  </tr>'
            . '</table>';

    return $str;
  }

  
  public function getTableRow($rowindex = -1)
  {
    $str = NormaldetailsSight::getTableRow($rowindex);
    $str = $this->dbwss->stringop->cutWidthof($str);

    return str_replace('<td', '<td nowrap ', $str);
  }

  
  public function createSight()
  { 
    $this->clear();
    
    $this->getColumns(false);
    $this->getData();
    
    if (isset($_REQUEST['showSearch'])) {
      SessionOperations::setVarValueWTIntern('sshowSearch', $_REQUEST['showSearch']);
    }
    if (SessionOperations::getVarValueWTIntern('sshowSearch') == 'true') {
      $this->sight .= $this->getHeader();
      $this->sight .= "<div class='suchformext'><a class='suchformext' href='" . CleanOperations::cleanStringForHtml($this->searchlink) . "&showSearch=false&delSearchSession=true'>
                       <img src='layout/button_searchclose.gif' border='0'></a>
                       <font class='text_main_menu'></font>";
      if (!$this->printmodus) {
        $this->sight .= $this->getBackLink($this->toolid);
      }
      $this->sight .= '</div>';
      $this->sight .= $this->getTable();
      $this->sight .= $this->getFooter();
    }

    else {
      $this->sight .= "<div class='suchformext'><a class='suchformext' href='" . CleanOperations::cleanStringForHtml($this->searchlink) . "&showSearch=true'>
                            <img src='layout/button_searchopen.gif' border='0'></a>
                            <font class='text_main_menu'></font>";
      if (!$this->printmodus) {
        
        $this->sight .= $this->getBackLink($this->toolid);
      }
      $this->sight .= '</div>';
    }

    if ($this->printmodus) {
      $this->sight = '';
    }
  }

  
  public function getBackLink($pToolid)
  {
    $toolx = new ToolX();
    $img = "<img class='zurueckrechts' border='0' src='layout/button_back_start.gif' alt='Zur&uuml;ck zur Startseite' title='Zur&uuml;ck zur Startseite' />";

    return
         "<a href='starttools.php?tool_id=" . CleanOperations::cleanInt($pToolid) . '&amp;toolsection_id=' . CleanOperations::cleanInt($toolx->getFirstToolSection($pToolid)) . "'>" . $img . "</a>\n";
  }

  
  public function getReorderedSearchRows($rows)
  {
    return $rows;
  }

  
  public function getColumns($justallowedcolumns = true)
  {
    $coldb = new DBWorkSightsSettings();
    $coldb->justallowedColumns = $justallowedcolumns;
    $coldb->justallowedColumns4User = $this->userid;
    
    $this->columnsary = $this->getReorderedSearchRows($coldb->getColumns($this->sightid));
    unset($coldb);
  }

  
  public function getData()
  {
    
    $this->dataary = $this->getReorderedSearchRows($this->dbwss->getColumns($this->sightid));

    if (isset($_REQUEST['delSearchSession']) && $_REQUEST['delSearchSession'] == true) { 
      for ($i = 0;$i < count($this->dataary);$i++) {
        SessionOperations::setVarValueWTIntern('ssearch_' . $this->dataary[$i]->fieldname . $this->getToolExt(), null);
      }
    }
  }

  
  public function getToolExt()
  {
    return;
  }

  
  
  public function getTableRowContent($rowindex, $colindex)
  { 
    return "<input type='text' class=\"suchformDiv_input\" size='" . CleanOperations::cleanInt($this->dataary[$colindex]->width) . "' name='search_" . CleanOperations::cleanStringForHtml($this->dataary[$colindex]->fieldname) . "' value='" . CleanOperations::cleanStringForHtml(SessionOperations::getVarValueWTIntern('ssearch_' . $this->dataary[$colindex]->fieldname . $this->getToolExt())) . "'>";
  }

  public function getFromObject()
  {
  }

  public function getToObject()
  {
  }
}