<?php
/**
 * @copyright (c) Kufer Software GmbH, Oderstraße 7, D-84453 Mühldorf
 */


class ZeitraumAPI
{
  
  public $hiddenstr = '';
  public $stringop;
  
  public $zeitbereiche;
  
  public $html;

  
  public function __construct()
  {
    $this->stringop = new StringOperations();
    $this->zeitbereiche = array('zb0' => array(0 => 'vormittags', 1 => 0, 2 => 1300),
                                    'zb1' => array(0 => 'nachmittags', 1 => 1300, 2 => 1800),
                                    'zb2' => array(0 => 'abends', 1 => 18, 2 => 0));
    $this->hiddenstr = 0;
    $this->html = new HTMLOperations();
  }

  
  public function getForm4Zeitbereiche()
  {
    
    
    $urlnav = new URLParameterNavigation();
    $urlnav->implodeSettings();
    $actionurl = $this->stringop->getHttpWithoutParams($this->stringop->getURLwithParams(true))
        . '?urlparameter=' . $urlnav->getStreamWith(array(), array());

    $sys_wochentag = '<form action="' . CleanOperations::cleanStringForHtml($actionurl) . '" method="post">';
    $sys_wochentag .= $this->getList4Zeitbereiche();
    $sys_wochentag .= $this->html->CreateInputTag(
      'noOfAdd',
      'hidden',
      '',
      '',
      $this->hiddenstr
    );

    return $sys_wochentag;
  }

  
  public function getList4Zeitbereiche()
  {
    $wk = new DBWorkWarenkorbZeitraumFilter();
    $wkids = $wk->getEntriesIDSerialized();

    $retour = "\n " . '<table class="zeitbereiche" border="0" cellpadding="3" cellspacing="0">' . "\n";

    for ($zb = 0; $zb < 3; $zb++) {
      $entry = $wk->getEntry('zb' . $zb);

      $zeitraum_checked = $entry->id != '';

      $retour .= '  <tr>' . "\n"
                         . '    <td class="zeitbereichTD4Checkbox">' . "\n"
                         . $this->html->CreateInputTag(
                           'zeitraum' . $zb,
                           'checkbox',
                           '',
                           'zeitbereichCheck',
                           'zb' . $zb,
                           '',
                           $zeitraum_checked
                         ) . "\n"
                         . '    </td>' . "\n"
                         . '    <td colspan="2" class="zeitbereichTD4Input">' . CleanOperations::cleanStringForHtml($this->zeitbereiche['zb' . $zb][0]) . '</td>' . "\n"
                         . '  </tr>' . "\n";
    }
    
    foreach ($wkids as $wkid) {
      if (StringOperations::substr($wkid, 0, 1) == 'a') {
        $tmpAry = explode('|', StringOperations::substr($wkid, 1));
        $tmpAry[1] = StringOperations::substr($tmpAry[1], 0, -2) . ':' . StringOperations::substr($tmpAry[1], -2);
        $tmpAry[2] = StringOperations::substr($tmpAry[2], 0, -2) . ':' . StringOperations::substr($tmpAry[2], -2);
        $retour .= '  <tr>' . "\n"
                   . '    <td class="zeitbereichTD4Checkbox" rowspan="2">' . "\n"
                   . $this->html->CreateInputTag(
                     'zeitraum' . $this->hiddenstr,
                     'checkbox',
                     '',
                     'zeitbereichCheckbox',
                     'zb' . $this->hiddenstr,
                     '',
                     true
                   )
                   . '    </td>' . "\n"
                   . '    <td class="zeitbereichTD4Input">von</td>' . "\n"
                   . '    <td class="zeitbereichTD4Input">bis</td>' . "\n"
                   . '  </tr>' . "\n"
                   . '  <tr>' . "\n"
                   . '    <td class="zeitbereichTD4Input">' . "\n"
                   . $this->html->CreateInputTag(
                     'zeitraum' . $this->hiddenstr . 'Beginn',
                     'text',
                     'zeitraum' . $this->hiddenstr . 'Beginn',
                     'zeitbereichInput',
                     $tmpAry[1]
                   )
                   . '    </td>' . "\n"
                   . '    <td class="zeitbereichTD4Input">' . "\n"
                   . $this->html->CreateInputTag(
                     'zeitraum' . $this->hiddenstr . 'Ende',
                     'text',
                     'zeitraum' . $this->hiddenstr . 'Ende',
                     'zeitbereichInput',
                     $tmpAry[2]
                   ) . "\n"
                   . '    </td>' . "\n"
                   . '  </tr>' . "\n";

        $this->hiddenstr++;
      }
    } 
    
    $retour .= '  <tr>' . "\n"
                   . '    <td class="zeitbereichTD4Checkbox" rowspan="2">&nbsp;</td>' . "\n"
                   . '    <td class="zeitbereichTD4Input">von</td>' . "\n"
                   . '    <td class="zeitbereichTD4Input">bis</td>' . "\n"
                   . '  </tr>' . "\n"
                   . '  <tr>' . "\n"
                   . '    <td class="zeitbereichTD4Input">' . "\n"
                   . $this->html->CreateInputTag(
                     'zeitraum' . $this->hiddenstr . 'Beginn',
                     'text',
                     'zeitraum' . $this->hiddenstr . 'Beginn',
                     'zeitbereichInput'
                   ) . "\n"
                   . '    </td>' . "\n"
                   . '    <td class="zeitbereichTD4Input">' . "\n"
                   . $this->html->CreateInputTag(
                     'zeitraum' . $this->hiddenstr . 'Ende',
                     'text',
                     'zeitraum' . $this->hiddenstr . 'Ende',
                     'zeitbereichInput'
                   ) . "\n"
                   . '    </td>' . "\n"
                   . '  </tr>' . "\n";
    $this->hiddenstr = 'no' . $this->hiddenstr;
    $retour .= "</table>\n";

    return $retour;
  }

  
}