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




class Menu
{
  
  public function header($pWeitereJsDateien = null, $pWeitereCssDateien = null, $pToolid = '', $pIncludeColorpickerCSS = false)
  {
    
    $str = $this->headerBegin();

    $allgSettings = AllgSettingsAPI::getAllgSettings();
    $str .= '<title>' . CleanOperations::cleanStringForHtml($allgSettings->title) . "</title>\n";
    $str .= "<link rel='stylesheet' type='text/css' href='./css/webtools.css'>\n";
    
    if ($pIncludeColorpickerCSS) {
      $str .= "<link rel='stylesheet' type='text/css' href='../jquery/plugins/colorpicker/css/colorpicker.css'>\n";
    }
    $str .= "<link rel='stylesheet' media='screen' type='text/css' href='../jquery/css/smoothness/jquery-ui-1.11.4.custom.min.css' >\n";
    $str .= '<link rel="stylesheet" media="screen" type="text/css" href="../jquery/css/contextmenu/jquery.contextmenu.css" >' . "\n";
    $str .= "<link rel='stylesheet' type='text/css' href='./css/skin.css'>\n";
    $str .= "<link rel='stylesheet' type='text/css' href='./css/webtools_legacy.css'>\n";
    if (file_exists(BASEDIR . 'webtools' . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . 'individuell.css')) {
      $str .= '<link rel="stylesheet" media="screen" type="text/css" href="./css/individuell.css" >' . "\n";
    }
    
    if (!is_null($pWeitereCssDateien)) {
      foreach ($pWeitereCssDateien as $cssDatei) {
        $str .= "<link rel='stylesheet' type='text/css' href='" . CleanOperations::cleanStringForHtml($cssDatei) . "'>\n";
      }
    }
    $str .= '<script type="text/javascript" src="../jquery/jquery-1.12.4.min.js" charset="' . CodingOperations::getEncoding4ExternalKuferToolsJsFiles() . '"></script>' . "\n";
    $str .= '<script type="text/javascript" src="../jquery/jquery-migrate-1.4.1.min.js" charset="' . CodingOperations::getEncoding4ExternalKuferToolsJsFiles() . '"></script>' . "\n";
    $str .= '<script type="text/javascript" src="../jquery/jquery-ui-1.11.4.custom.min.js" charset="' . CodingOperations::getEncoding4ExternalKuferToolsJsFiles() . '"></script>' . "\n";
    $str .= '<script type="text/javascript" src="../jquery/plugins/colorpicker/colorpicker.js" charset="' . CodingOperations::getEncoding4ExternalKuferToolsJsFiles() . '"></script>' . "\n";
    $str .= '<script type="text/javascript" src="../jquery/plugins/jquery.contextmenu.js" charset="' . CodingOperations::getEncoding4ExternalKuferToolsJsFiles() . '"></script>' . "\n";
    $str .= '<script type="text/javascript" src="../jquery/plugins/jquery-ui-timepicker-addon.min.js" charset="' . CodingOperations::getEncoding4ExternalKuferToolsJsFiles() . '"></script>' . "\n";
    
    $str .= '<script type="text/javascript" src="../jquery/plugins/jquery.inlineedit.js" charset="' . CodingOperations::getEncoding4ExternalKuferToolsJsFiles() . '"></script>' . "\n";
    $str .= '<script type="text/javascript" src="../jquery/plugins/jquery.dataTables.min.js" charset="' . CodingOperations::getEncoding4ExternalKuferToolsJsFiles() . '"></script>' . "\n";
    $str .= '<script type="text/javascript" src="js/localization.js" charset="' . CodingOperations::getEncoding4OwnKuferToolsJsFiles() . '"></script>' . "\n";
    $str .= '<script type="text/javascript" src="js/project.js" charset="' . CodingOperations::getEncoding4OwnKuferToolsJsFiles() . '"></script>' . "\n";
    $str .= '<script type="text/javascript" src="js/json2.js" charset="' . CodingOperations::getEncoding4OwnKuferToolsJsFiles() . '"></script>' . "\n";
    $str .= '<script type="text/javascript" src="js/base64.js" charset="' . CodingOperations::getEncoding4OwnKuferToolsJsFiles() . '"></script>' . "\n";
    $str .= '<script type="text/javascript" src="js/utils.js" charset="' . CodingOperations::getEncoding4OwnKuferToolsJsFiles() . '"></script>' . "\n";
    $str .= '<script type="text/javascript" src="js/klassenbuch.js" charset="' . CodingOperations::getEncoding4OwnKuferToolsJsFiles() . '"></script>' . "\n";
    
    
    $str .= '<script type="text/javascript" src="js/medienhandler.js" charset="' . CodingOperations::getEncoding4OwnKuferToolsJsFiles() . '"></script>' . "\n";
    $str .= '<script type="text/javascript" src="js/TNTool/stundenplanhandler.js" charset="' . CodingOperations::getEncoding4OwnKuferToolsJsFiles() . '"></script>' . "\n";
    $str .= '<script src="functions.js" type="text/javascript" language="javascript" charset="' . CodingOperations::getEncoding4OwnKuferToolsJsFiles() . '"></script>' . "\n";

    
    if (!is_null($pWeitereJsDateien)) {
      foreach ($pWeitereJsDateien as $jsDatei) {
        $str .= '<script type="text/javascript" src="' . CleanOperations::cleanStringForHtml($jsDatei) . '" charset="' . CodingOperations::getEncoding4OwnKuferToolsJsFiles() . '"></script>' . "\n";
      }
    }
    $str .= "<script type='text/javascript' language='javascript'>initLocalization();\n";

    if ($pToolid !== '') {
      $str .= " registerNamespace('KuferTools.ZentraleEinstellungen');\n";
      $str .= JsOperations::getDeclarationInt('KuferTools.ZentraleEinstellungen.ToolId', $pToolid);
    }
    $str .= "</script>\n";
    $str .= "</head>\n";
    echo $str;
  }

  
  public function headerBegin()
  {
    $str = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">' . "\n";
    $str .= '<html>' . "\n";
    $str .= '<head>' . "\n";
    
    $str .= '<META http-equiv="Content-Type" content="text/html; charset=' . ConstantOperations::getEncoding4Charset() . '" >' . "\n";
    $str .= '<META http-equiv="content-language" content="de">' . "\n"
            . '<META http-equiv="author" content="Kufer Software GmbH">' . "\n"
            . '<META http-equiv="content-style-type" content="text/css">' . "\n";
    $str .= '<meta http-equiv="X-UA-Compatible" content="IE=8">' . "\n";
    
      
    return $str;
  }

  
  public static function forbidden()
  {
    session_unset();
    session_destroy();
    header('Location: index.php?sessionfail=1');
    die();
  }

  
  public static function getUserLink($p_text, $p_href, $p_privileg = 2, $pNewWindow = false, $pAddNBSP = false, $pClass = '')
  {
    if ($p_privileg == 0) {
      return('');
    }
    if ($p_privileg == 1) {
      return('<a>' . $p_text . '</a>' . ($pAddNBSP ? '&nbsp;' : ''));
    }
    if ($p_privileg == 2) {
      return('<a href="' . CleanOperations::cleanStringForHtml($p_href) . '"' . ($pClass != '' ? ' class="' . CleanOperations::cleanStringForHtml($pClass) . '"' : '') . ($pNewWindow ? ' target="_blank"' : '') . '>'
          . $p_text . '</a>' . ($pAddNBSP ? '&nbsp;' : ''));
    }
  }

  
  public static function getWindowCloseLink()
  {
    return
      "<a href='#' onClick='window.close();'>"
      . "<img border='0' src='layout/button_close.gif' alt='Fenster schlie&szlig;en' "
      . "title='Fenster schlie&szlig;en' /></a>\n";
  }

  
  public static function getBackLink($link = 'javascript:history.back()')
  {
    return
      "<a href='" . CleanOperations::cleanStringForHtml($link) . "'>"
      . "<img border='0' src='layout/button_back.gif' alt='Zur&uuml;ck' "
      . "title='Zur&uuml;ck' /></a>\n";
  }

  
  public static function getOverviewLink($pToolid, $freeAddOn, $pTyp = '', $pImageClass = '', $pUserTools = false)
  {
    $toolx = new ToolX();
    $img = "<img class='buttonwMargin' src='layout/button_close_small.gif' alt='Zur&uuml;ck' title='Zur&uuml;ck' ";
    if ($pImageClass != '') {
      $img .= "class='" . CleanOperations::cleanStringForHtml($pImageClass) . "' ";
    }
    $img .= '/>';

    $toolstart = 'usertools.php';

    switch ($pTyp) {
      case 'zurueck_startseite':
        $img = "<img class='buttonwMargin' src='layout/button_back_start.gif' alt='Zur&uuml;ck zur Startseite' title='Zur&uuml;ck zur Startseite' />";
        break;
      case 'abbruch':
        $img = "<img class='buttonwMargin' class='abbruch' src='layout/button_close_small.gif' alt='Zurück' title='Zurück' />";
        break;
    }

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

  public static function getBackJS()
  {
    return
       "<a href='javascript:history.back()'>"
      . "<img class='zurueck' border='0' src='layout/button_back.gif' alt='Zur&uuml;ck' "
      . "title='Zur&uuml;ck' /></a>\n";
  }

  
  public function updateSelectedRowNrs()
  {
    
    $oldSelectedSessionIdsString = SessionOperations::getVarValueWTIntern('selnrstr_');
    
    $idsAufLetzterSeiteString = RequestOperations::getVarValue('idsAufSeite');

    
    if ($oldSelectedSessionIdsString != '') {
      $oldSelectedSessionIds = explode(':', $oldSelectedSessionIdsString);
    } else {
      $oldSelectedSessionIds = array();
    }
    if ($idsAufLetzterSeiteString != '') {
      $idsAufLetzterSeite = explode('#', $idsAufLetzterSeiteString);
    } else {
      $idsAufLetzterSeite = array();
    }

    
    
    $newSelectedSessionIds = array();
    foreach ($oldSelectedSessionIds as $selid) {
      if (!in_array($selid, $idsAufLetzterSeite)) {
        $newSelectedSessionIds[] = $selid;
      }
    }

    
    $anznrproSeite = SessionOperations::getVarValueWTIntern('anznrproSeite');
    for ($i = 0; $i < $anznrproSeite; $i++) {
      if (RequestOperations::isDefined('row' . $i)) {
        $newSelectedSessionIds[] = RequestOperations::getVarValue('row' . $i);
      }
      
    }

    return implode(':', $newSelectedSessionIds);
  }
}