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


class WochentagAPI
{
  
  public $hiddenstr = '';
  public $stringop;

  
  public $wochentage;
  
  public $html;

  
  public function __construct()
  {
    $this->stringop = new StringOperations();
    $this->wochentage = array('w0' => 'Montag',
                                    'w1' => 'Dienstag',
                                    'w2' => 'Mittwoch',
                                    'w3' => 'Donnerstag',
                                    'w4' => 'Freitag',
                                    'w5' => 'Samstag',
                                    'w6' => 'Sonntag');
    $this->html = new HTMLOperations();
  }

  
  public function getForm4Wochentage()
  {
    
    
    $urlnav = new URLParameterNavigation();
    $urlnav->implodeSettings();
    $actionurl = $this->stringop->getHttpWithoutParams($this->stringop->getURLwithParams(true))
        . '?urlparameter=' . $urlnav->getStreamWith(array(), array());
    $sys_zeitraum = '';
    $sys_zeitraum .= "<form action='" . CleanOperations::cleanStringForHtml($actionurl) . "' method=\"post\">";
    $sys_zeitraum .= $this->getList4Wochentage();
    $sys_zeitraum .= $this->html->CreateInputTag(
      'wochentageFilter',
      'hidden',
      '',
      '',
      $this->hiddenstr
    );

    return $sys_zeitraum;
  }

  
  public function getList4Wochentage()
  {
    
    $wk = new DBWorkWarenkorbWochentagFilter();
    $wkids = $wk->getEntriesIDSerialized();

    $hiddenstr = 'wochentageFiltern';
    $retour = "\n " . '<ul class = "wochentage">' . "\n";
    
    foreach ($this->wochentage as $key => $val) {
      
      $wochentag_checked = in_array($key, $wkids);

      $retour .= "\n " . '<li class = "wochentage">' . "\n"
                 . $this->html->CreateInputTag(
                   'wochentag' . StringOperations::substr($key, 1),
                   'checkbox',
                   '',
                   '',
                   $key,
                   '',
                   $wochentag_checked
                 );

      $retour .= CleanOperations::cleanStringForHtml($val);
      $retour .= "</li>\n";
    }
    $retour .= "</ul>\n";

    $this->hiddenstr .= $hiddenstr;

    return $retour;
  }

  
}