<?php
/**
 * Copyright 2003 - 2004 by Gero Kohnert
 *
 *  CVS Info:  $Id: new_layout.pinc,v 1.16 2005/05/03 13:18:51 saraj Exp $
 *  $Author: saraj $
 */
global $calpath;
 $calpath = 'modules/Calendar/';
 require_once $calpath .'layout/layout_base.pinc';
/**
 * This class implements a slighly more modern  TUTOS layout
 * a headline in an table together with a another table
 * which has a left side navigation element an a big area on the right side
 *
 * @package BASE
 * @module classic_layout
 */
class layout extends layout_base {
  /**
   * initialize
   */
  function layout (&$user) {
    $this->init($user);
  }
  /**
   * initialize
   */
  function init (&$user) {
    parent::init($user);
  }
  /**
   * error output visible to user
   */
  function error($str) {
    if ( $str == "" ) return "";
    return "<span class=\"warn\">". $str ."</span><br />";
  }
  /**
   * start a data table
   */
  function DataTableStart() {
    return "<table class=\"single\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">\n";
  }
  /**
   * end a data table
   */
  function DataTableEnd() {
    return "</table>\n";
  }
  /**
   * start a overview table
   */
  function OverviewTableStart() {
    #return "<table class=\"single\" border=\"1\" cellpadding=\"3\" cellspacing=\"0\">\n";
  }
  /**
   * end a overview table
   */
  function OverviewTableEnd() {
    return "</table>\n";
  }
  /**
   * start a overview row
   */
  function OverviewRowStart($line,$title = "") {
    return "<tr title=\"". myentities($title) ."\" onmouseover=\"this.style.backgroundColor='#ffff72';\" onmouseout=\"this.style.backgroundColor=this.style.color;\" class=\"line". ($line % 2 +1) ."\">\n";
  }
  /**
   * end a overview row
   */
  function OverviewRowEnd($line) {
    return "</tr>\n";
  }
  /**
   * display icons for see, modify, delete...
   */
  function showGuiIcons($start, $end, &$myobject, &$myparentobj, $which, $desc = false) {
    global $tutos,$lang,$current_user;

    $r = "";    
    #preparing address-objects
    if ( $myobject->getType() == "address" ) {
      $SeeSprintf = sprintf($lang['AdrSeeEntryI'],$myobject->getFullName());
      $ModSprintf = sprintf($lang['AdrBModInfo'],$myobject->getFullName());
      $DelSprintf = sprintf($lang['AdrBDelInfo'],$myobject->getFullName());
      $SeeUrl  = $myobject->getURL();
      $ModUrl  = $myobject->getModURL();
      $DelUrl  = $myobject->getDelURL();
    #preparing company-objects
    } else if ( $myobject->getType() == "company" ) {
      $SeeSprintf = sprintf($lang['CompanyLinkInfo'],$myobject->getFullName());
      $ModSprintf = sprintf($lang['CompanyChgInfo'],$myobject->getFullName());
      $DelSprintf = sprintf($lang['CompanyDelInfo'],$myobject->getFullName());
      $SeeUrl  = $myobject->getURL();
      $ModUrl  = $myobject->getModURL();
      $DelUrl  = $myobject->getDelURL();
    #preparing location-objects
    } else if ( $myobject->getType() == "location" ) {
      $SeeSprintf = sprintf($lang['show'],$myobject->lname);
      $ModSprintf = sprintf($lang['ChangeLocInfo'],$myobject->lname,$myparentobj->getFullName());
      $DelSprintf = sprintf($lang['DeleteLocInfo'],$myobject->lname,$myparentobj->getFullName());
      $SeeUrl  = $myparentobj->getURL();
      if ( $myparentobj->getType() == "address" ) {
        $ModUrl  = "address_new.php?id=". $myparentobj->id ."&loc_id=". $myobject->id;
      } else if ( $myparentobj->getType() == "company" ) {
        $ModUrl  = "company_new.php?id=". $myparentobj->id ."&loc_id=". $myobject->id;
      }
      $DelUrl  = "location_del.php?ref=". $myparentobj->id ."&id=". $myobject->id;
    #preparing rate-objects
    } else if ( $myobject->getType() == "rate" ) {
      $SeeSprintf = sprintf($lang['RateInfo'],$myobject->getFullName());
      $ModSprintf = sprintf($lang['RateModInfo'],$myobject->getFullName());
      $DelSprintf = sprintf($lang['RateDelInfo'],$myobject->getFullName());
      $SeeUrl  = $myobject->getURL();
      $ModUrl  = $myobject->getModURL();
      $DelUrl  = $myobject->getDelURL();
    #preparing other objects
    } else {
      $SeeSprintf = sprintf($lang['show'],$myobject->getFullName());
      $ModSprintf = $lang['Modify'] ." ". $lang[$myobject->getType()] ." ". $myobject->getFullName();
      $DelSprintf = $lang['Delete'] ." ". $lang[$myobject->getType()] ." ". $myobject->getFullName();
      $SeeUrl  = $myobject->getURL();
      $ModUrl  = $myobject->getModURL();
      $DelUrl  = $myobject->getDelURL();
    }
    
    #building html
    if ( ($myobject->see_ok()) && (in_array("see",$which)) && ($desc == true) ) {
      $r .= "&nbsp;". menulink($SeeUrl,
           $this->theme->getImage(view,'list')."&nbsp;". $lang['show'],
           $SeeSprintf);
    } else if ( ($myobject->see_ok()) && (in_array("see",$which)) && ($desc == false) ) {
      $r .= menulink($SeeUrl,
           $this->theme->getImage(view,'list'),
           $SeeSprintf);
    }
    if ( ($myobject->mod_ok()) && (in_array("mod",$which)) && ($desc == true) ) {
      $r .= "&nbsp;". menulink($ModUrl,
           $this->theme->getImage(modify,'list')."&nbsp;". $lang['Modify'],
           $ModSprintf);
    } else if ( ($myobject->mod_ok()) && (in_array("mod",$which)) && ($desc == false) ) {
      $r .= menulink($ModUrl,
           $this->theme->getImage(modify,'list'),
           $ModSprintf);
    }
    if ( ($myobject->del_ok()) && (in_array("del",$which)) && ($desc == true) ) {
      $r .= "&nbsp;". confirmlink($DelUrl,
           $this->theme->getImage(delete,'list')."&nbsp;". $lang['Delete'],
           $DelSprintf);
    } else if ( ($myobject->del_ok()) && (in_array("del",$which)) && ($desc == false) ) {
      $r .= confirmlink($DelUrl,
           $this->theme->getImage(delete,'list'),
           $DelSprintf);
    }
    return $start.$r.$end;
  }
  /** 
   * do we support icons for edit modify del
   */
  function checkGuiIcons() {
    return true;
  }
  /**
   * start a massupdate row
   */
  function UpdateRowStart($cols) {
    $r = "<tr>\n";
    $r .= " <td align=\"right\" colspan=\"". $cols ."\">\n";
    return $r;
  }
  /**
   * end a massupdate row
   */
  function UpdateRowEnd($cols) {
    global $lang;
    $r = "";
    $r .= " </td>\n";
    $r .= " <td colspan=\"". $cols ."\">\n";
    $r .= " <input type=\"submit\" value=\"". $lang['Enter'] ."\"></td>\n";
    $r .= "</tr>\n";
    return $r;
  }
  /**
   * action form header 
   * make the javascript stuff for massupdates
   */
  function actionformStart($url) {
    global $tutos;

    $r = "";
    if ( $tutos[massupdate] == 1 ) {
      $r .= "<script type=\"text/javascript\" language=\"JavaScript\">\n";
      $r .= "<!--\n";
      $r .= "function CheckAll2() {\n";
      $r .= "  for (var i=0; i < document.forms['actionform'].elements.length; i++) {\n";
      $r .= "   var e = document.forms['actionform'].elements[i];\n";
      $r .= "   if (e.name != 'checkit')\n";
      $r .= "     e.checked = document.forms['actionform'].checkit.checked;\n";
      $r .= "  }\n";
      $r .= "}\n";
      $r .= "//-->\n";
      $r .= "</script>\n";
      $r .= "<form name=\"actionform\" method=\"GET\" action=\"". $url ."\">\n";
    }
    return $r;
  }
  function actionformEnd($url) {
    global $tutos;

    $r = "";
    if ( $tutos[massupdate] == 1 ) {
      $r .= $this->getHidden();
      hiddenFormElements();
      $r .= "</form>";
    }
    return $r;
  }
  /**
   * sortable header field in overviews
   */
  function orderheader($oname,$link,$base,$cols = 1) {
    global $tutos, $lang;

    $base =  addUrlParameter($base,"xf=".$oname,false);
    $r = "<th nowrap=\"nowrap\" colspan=\"". $cols ."\">\n";
    if ( $oname == "" ) {
      $r .= $link;
    } else {
      $l =  addUrlParameter($base,"xo=1",false);
      if ( isset ($_GET['xo']) && $_GET['xo'] == 1 &&  ($_GET['xf'] == $oname) ) {
        $r .= "(". makelink($l ,$this->theme->getImage(up,'list'),sprintf($lang['OrderBy'], $link)) .")";
      } else {
        $r .= makelink($l ,$this->theme->getImage(up,'list'),sprintf($lang['OrderBy'], $link));
      }
      if ( isset ($_GET['xo']) && ($_GET['xf'] == $oname) ) {
        $r .= "<b>". $link ."</b>";
      } else {
        $r .= $link;
      }
      $l =  addUrlParameter($base,"xo=2",false);
      if ( isset ($_GET['xo']) && $_GET['xo'] == 2  &&  ($_GET['xf'] == $oname) ) {
        $r .= "(". makelink($l ,$this->theme->getImage(down,'list'),sprintf($lang['RevOrderBy'],$link)) .")";
      } else {
        $r .= makelink($l ,$this->theme->getImage(down,'list'),sprintf($lang['RevOrderBy'],$link));
      }
    }
    $r .= "</th>\n";
    return $r;
  }
  /**
   * shows a simple field descriptor (top)
   */
  Function showfield($text,$req = 0,$label = "") {
    $r = "";
    $r .= "<td class=\"desc\" valign=\"top\">";
    if ( $label != "" ) {
      $r .= "<label for=\"". $label ."\">";
    }
    $r.= $text;
    if ( $label != "" ) {
      $r .= "</label>";
    }
    if ( $req != 0 ) {
      $r .= "<font color=\"red\">(*)</font>";
    }
    $r .= ": </td>\n";
    return $r;
  }
  /**
   * shows a simple field descriptor (center)
   */
  Function showfieldc($text,$req = 0,$label = "") {
    $r = "";
    $r .= "<td class=\"desc\">";
    if ( $label != "" ) {
      $r .= "<label for=\"". $label ."\">";
    }
    $r .= $text;
    if ( $label != "" ) {
      $r .= "</label>";
    }
    if ( $req != 0 ) {
      $r .= "<font color=\"red\">(*)</font>";
    }
    $r .= ":</td>\n";
    return $r;
  }
  /**
   * shows data
   */
  Function showdata($text,$cols = 1) {
    $r = "";
    $r .= "<td colspan=\"". $cols ."\" class=\"data\">";
    $r .= ( $text == "" ?  "&nbsp;" : $text);
    $r .= "</td>\n";
    return $r;
  }
  /**
   * get all hidden fields
   */
  Function getHidden() {
    $r = "";
    foreach ($this->hidden as $v ) {
      $r .= "<input id=\"". $v[0] ."\" type=\"hidden\" name=\"". $v[0] ."\" value=\"". $v[1] ."\">\n";
    }
    $this->hidden = array();
    return $r;
  }
  /**
   * add the default menu parts
   */
  function mainmenu() {
    global $tutos,$lang,$calpath;

    if ( ! isset($this->user->id) || ($this->user->id == -1) ) {
      return;
    }
    if ( "help.php" == basename($_SERVER['PHP_SELF']) ) {
      return;
    }
    if (! method_exists($this->user,"feature_ok") ) {
      return;
    }
    if ( $this->user->feature_ok(usecalendar,PERM_SEE) ) {
      require_once $calpath .'appointment.pinc';
      $x = array( url => "calendar.php",
                  image => $this->theme->getImage(appointment::getHtmlIcon(),'menu'),
                  text => $lang['Calendar'],
                  info => $lang['CalendarInfo'],
                  category => array("overview","app","default")
                );
      $this->addMenu($x);
    }
    if ( $this->user->feature_ok(useaddressbook,PERM_SEL) ) {
      $x = tutos_address::getSelectLink($this->user);
      $x[category][] = "default";
      if ( basename($_SERVER['PHP_SELF']) == "address_select.php" ) {
        $x[url] = "";
      }
      $this->addMenu($x);
    }
    if ( $this->user->feature_ok(usebugtracking,PERM_SEL) ) {
      loadmodule('bugtracking');
      if (class_exists('bug')) {
        $x = bug::getSelectLink($this->user,$lang['BugTrack']);
        $x[category][] = "default";
        if ( basename($_SERVER['PHP_SELF']) == "bug_select.php" ) {
          $x[url] = "";
        }
        $this->addMenu($x);
      }
    }
    if ( $this->user->feature_ok(useprojects,PERM_SEL) ) {
      require_once $calpath .'product.pinc';
      $x = product::getSelectLink($this->user,$lang['ProductMenu']);
      $x[category][] = "default";
      if ( basename($_SERVER['PHP_SELF']) == "product_select.php" ) {
        $x[url] = "";
      }
      $this->addMenu($x);
    }

    if ( $this->user->feature_ok(useteams,PERM_SEL) ) {
      $x = team::getSelectLink($this->user);
      $x[category][] = "default";
      if ( basename($_SERVER['PHP_SELF']) == "team_select.php" ) {
        $x[url] = "";
      }
      $this->addMenu($x);
    }
    $x = array( url => "mytutos.php",
                image => $this->theme->getImage(user,'menu'),
                text => $this->user->getFullName(),
                info => sprintf($lang['PersonalPageFor'],$this->user->getFullname()),
                category => array("mytutos","overview","default")
              );
    $this->addMenu($x);

    $x = array( url => "admin_show.php",
                image => $this->theme->getImage('admin','menu'),
                info => $lang['UserAdmin'],
                category => array("admin")
              );
    if ( $this->user->isAdmin() ) {
      $x[text] = $lang['UserAdmin'];
      $this->addMenu($x);
    } else if ( $tutos[demo] == 1 ) {
      $x[text] = $lang['UserAdmin'] ." (DEMO)";
      $this->addMenu($x);
    }

    build_module_links($this);

    $x = array( url => make_helplink(),
                image => $this->theme->getImage(help,'menu'),
                text => $lang['Help'],
                info => $lang['HelpInfo'],
                'key' => "?",
                category => array("help","default")
              );
    //$this->addMenu($x);

    # Logout
    $x = array( url => "logout.php",
                image => $this->theme->getImage(logout,'menu'),
                text => $lang['Logout'],
                info => $lang['LogoutInfo'],
                category => array("logout","admin","default")
              );
    $this->addMenu($x);

    # Team Stuff
    if ( ! class_exists ("url") ) {
      loadmodule("url");
    }

    if ( class_exists ("url") ) {
      if ( $this->user->feature_ok(useurl,PERM_SEE) ) {
        $ulist = array();
        foreach ( $this->user->teams as $idx => $val ) {
          url::obj_read($this->user->teams[$idx]);
          $ulist = array_merge($ulist,$this->user->teams[$idx]->list[useurl]);
        }
        if ( count($ulist) > 0 ) {
          foreach ( $ulist as $idx => $val ) {
            $x = array( url => $ulist[$idx]->getUrl() ,
                        target => "url",
                        info => $ulist[$idx]->getUrl() ,
                        category => array("extern","url")
                      );
            if (strlen($ulist[$idx]->name) > 40) {
              $x[text] = substr($ulist[$idx]->name,0,35) ."...". substr($ulist[$idx]->name,-2);
            } else {
              $x[text] = $ulist[$idx]->name;
            }
            $this->addMenu($x);
          }
        }
      }
    }
  }

  /**
   * header of a printable page
   */
  function PrintHeader($name = "") {
    $this->name = $name;
    $this->HTML_Start();
    Overlib_Header();
  }
  /**
   * foot of a printable page
   */
  function PrintFooter() {
    $this->HTML_Stop();
  }

  Function HTML_Start() {
    global $tutos,$lang;

    @ob_start();
    if ( !isset($this->name) || empty($this->name) ) {
      $this->name = "TUTOS";
    }
    Header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
#    Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    Header("Expires: -1");
    Header("Cache-Control: no-store, no-cache, must-revalidate");
    Header("Cache-Control: max_age=0 ,post-check=0, pre-check=0",false);
    Header("Pragma: no-cache");

    Header("Content-Description: a TUTOS Page" );
    Header("Content-Type: text/html;charset=". $lang['content_encoding']);
    if (!true) {
      echo "<?xml version=\"1.0\"?>\n";
      #echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";  
      $xml = true;
      $c = "/>"; 
    } else {
      #echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
      $c = ">"; 
      $xml = false;
    }
    if ( isset($tutos[lang]) && $tutos[lang] != "" ) {
      #echo "<html dir=\"ltr\" lang=\"". $tutos[lang] ."\">\n";
    } else {
      #echo "<html dir=\"ltr\">\n";
    }
    #echo "<!-- Copyright 1999 - 2004 by Gero Kohnert gokohnert@users.sourceforge.net -->\n";
    #echo "<!-- all rights reserved -->\n";
    #echo " <head>\n";
    #echo "  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=". $lang['content_encoding'] ."\"".$c."\n";
    #echo "  <meta name=\"GENERATOR\" content=\"TUTOS ". $tutos[version] ."\"".$c."\n";
    if ( isset($tutos[lang]) && $tutos[lang] != "" ) {
      #echo "  <meta name=\"language\" content=\"". $tutos[lang] ."\"".$c."\n";
    }
    #echo "  <meta http-equiv=\"Expires\" content=\"-1\"".$c."\n";
    if (is_readable(getcwd()."/".$tutos['base'] ."/html/". $this->theme->name .".css") ) {
      #echo "  <link rel=\"stylesheet\" href=\"". $tutos['base'] ."/html/". $this->theme->name .".css\" type=\"text/css\"".$c."\n";
    } else {
      #echo "\n<!-- NO THEME ". $this->theme->name ." found -->\n";
    }
    #echo "  <link rel=\"stylesheet\" href=\"". $tutos['base'] ."/html/new_layout.css\" type=\"text/css\"".$c."\n";


    $x = $_SERVER['REQUEST_URI'];
    $x = htmlentities(delUrlParameter($x,"th"));
    foreach ($tutos[themes] as $i) {
      #echo "  <link rel=\"alternate stylesheet\" title=\"TUTOS ". $i ." ". $lang['UserTheme'] ."\" href=\"". $tutos['base'] ."/html/".$i.".css\" type=\"text/css\"". $c ."\n";
      #echo "  <link rel=\"Alternate\" href=\"". addUrlParaMeter($x,"th=".$i) ."\" title=\"".  myentities($lang['UserTheme'] .": ".$i) ."\"". $c ."\n";
    }

    #echo "  <meta name=\"MSSmartTagsPreventParsing\" content=\"TRUE\"".$c."\n";
    #echo "  <link rel=\"icon\" href=\"". $tutos['base'] ."/html/tutos_small.gif\" type=\"image/gif\"". $c ."\n";
    #echo "  <link rel=\"SHORTCUT ICON\" href=\"". $tutos['base'] ."/html/tutos.ico\"". $c ."\n";
    #echo "  <link rel=\"Copyright\" href=\"". $tutos['base'] ."/html/copyright.html\" title=\"Copyright\"". $c ."\n";
    //echo "  <link rel=\"Help\" href=\"".  make_helplink() ."\" title=\"". $lang['Help']."\"".$c."\n";
    #echo "  <link rev=\"Made\" href=\"https://sourceforge.net/project/memberlist.php?group_id=8047\" hreflang=\"en\" target=\"url\" title=\"TUTOS Team\"".$c."\n";
    $x = $_SERVER['REQUEST_URI'];
    $x = htmlentities(delUrlParameter($x,"lg"));
    foreach($lang['lang'] as $i => $f) {
      #echo "  <link rel=\"Alternate\" href=\"". addUrlParaMeter($x,"lg=".$i) ."\" title=\"".  myentities($lang['UserLanguage'] .": ".$f) ."\"". $c ."\n";
    }
    #echo "  <title>TUTOS -- ". myentities($this->name) ."</title>\n";
    #echo " </head>\n";
    #echo " <body>\n";
  }



  Function HTML_Stop() {
    #echo " </body>\n";
    #echo "</html>\n";
  }
  /** 
   * print a menu 
   */
  function menuprint($class,$sep,$img) {
    $r = "";
    foreach ($this->menu as $i => $m) {
      $attr = "";
      if ( !isset($m[text])|| ($m[text] == "") ) {
        continue;
      }
      if ($img) {
        $t = (isset($m[image])?$m[image]:""). myentities($m[text]);
      } else {
        $t = myentities($m[text]);
      }
      if (isset($m['key'])) {
        $attr .= " accesskey=\"". $m['key'] ."\"";
      }
      if (isset($m['target'])) {
        $attr .= " target=\"". $m['target'] ."\"";
      }
      if ( in_array($class,$m[category]) ) {
        if ( isset($m[confirm]) && ($m[confirm] == true) ) {
          $r .= confirmlink($m[url],$t,$m[info],"",$attr) .$sep;
        } else {
          $r .= menulink($m[url],$t,$m[info],"",$attr) .$sep;
        }
        unset($this->menu[$i][text]);
      }
    }
    return $r;
  }
  /**
   * header of a "normal" page
   */
  function layout_start($name = "") {
    global $tutos,$lang,$msg;


    Overlib_Header();
    echo "<!-- layout_start -->\n";
    echo " <table id=\"maintable\" cellspacing=\"0\" border=\"0\">\n";
    echo "  <!--tr>\n";
    echo "   <td class=\"headline\" valign=\"middle\" align=\"left\">";
    if ( isset($lang['DateTimeSPHP']) ) {
      echo Date($lang['DateTimeSPHP']);
    } else {
      echo Date("d/m H:i");
    }
    echo "   </td>\n";
    echo "   <td nowrap=\"nowrap\" width=\"90%\" height=\"30px\" colspan=\"8\" align=\"center\" class=\"pagetitle\">". ($name == "" ? myentities($this->name):myentities($name)) ."</td>\n";
    echo "   <td colspan=\"1\" rowspan=\"2\" align=\"right\" valign=\"top\" class=\"pagetitle\">\n";
    if ( isset($tutos[logolink]) ) {
      //echo "   <a target=\"url\" href=\"". (ereg("^http",$tutos[logolink]) ? "":$tutos['base']."/" ) . $tutos[logolink] ."\">";
    } 
    //echo "   <img id=\"logo\" border=\"0\" src=\"". (ereg("^http",$tutos[logo]) ? "":$tutos['base']."/" ). $tutos[logo] ."\" alt=\"LOGO\" align=\"middle\" />";
    if ( isset($tutos[logolink]) ) {
      //echo "</a>";
    }
    echo "   </td>\n";
    echo "  </tr-->\n";

    echo "  <!--tr>\n";
    echo "   <td class=\"headline\" height=\"30px\" align=\"left\" nowrap=\"nowrap\">\n";
    echo $this->menuprint("mytutos","&nbsp;&nbsp;\n",true);
    echo $this->menuprint("logout","&nbsp;&nbsp;\n",true);
    echo "</td>\n";
    $help = $this->menuprint("help","&nbsp;",true);
    echo "   <td colspan=\"7\" class=\"headline\" align=\"left\" nowrap=\"nowrap\">\n";
    echo $this->menuprint("default","&nbsp;&nbsp;\n",true);
    echo "   </td>\n";
    echo "   <td colspan=\"1\" class=\"headline\" align=\"right\" nowrap=\"nowrap\">\n";
    echo $help;
    echo "   </td>\n";
    echo "  </tr-->\n";

    echo "  <tr>\n";
    if ( $this->nomenu == false ) {
      echo "   <!--td width=\"10%\" class=\"navigate\">\n";
      echo "<table width=\"100%\">\n";
      echo "<tr><td valign=\"top\" nowrap=\"nowrap\">\n";
      #echo $this->menuprint("obj","<br />\n",false);
      echo "</td></tr-->\n";

      echo "<!--tr><td valign=\"top\" nowrap=\"nowrap\">\n";
      echo $this->menuprint("view","<br />\n",false);
      echo "</td></tr-->\n";

      echo "<!-- outside navigation -->\n";
      #$this->navigate();
      echo "<!-- end of outside navigation -->\n";

      echo "<!--tr><td valign=\"top\" nowrap=\"nowrap\">\n";
      echo $this->menuprint("search","<br />\n",false);
      echo $this->menuprint("overview","<br />\n",false);
      echo "</td></tr-->\n";


   /*   $sup = $this->menuprint("support","<br />\n",false);
      if ( $sup != "" ) {
        echo "<tr><th></th></tr>\n";
        echo "<tr><td valign=\"top\" nowrap=\"nowrap\">\n";
        echo $sup;
        echo "</td></tr>\n";
      }
      $mod = $this->menuprint("module","<br />\n",false);
      if ( $mod != "" ) {
        echo "<tr><th></th></tr>\n";
        echo "<tr><td valign=\"top\" nowrap=\"nowrap\">\n";
        echo $mod;
        echo "</td></tr>\n";
      }
      $admin = $this->menuprint("admin","<br />\n",false);
      if ( $admin != "" ) {
        echo "<tr><th></th></tr>\n";
        echo "<tr><td valign=\"top\" nowrap=\"nowrap\">\n";
        echo $admin;
        echo "</td></tr>\n";
      }

      $urls =  $this->menuprint("url","<br />\n",false);

      echo "<tr><td valign=\"top\" nowrap=\"nowrap\">\n";
      foreach ($this->menu as $i => $m) {
        if ( !isset($m[text]) ) {
          continue;
        }
        if ( isset($m[confirm]) && ($m[confirm] == true) ) {
          echo confirmlink($m[url],$m[text],$m[info]) ."<br />\n";
        } else {
          echo menulink($m[url],$m[text],$m[info]) ."<br />\n";
        }
      }
      echo "</td></tr>\n";

      if ( $urls != "" ) {
        echo "<tr><th>". $lang['URL'] ."</th></tr>\n";
        echo "<tr><td valign=\"top\" nowrap=\"nowrap\">\n";
        echo $urls;
        echo "</td></tr>\n";
      }
      if ( "help.php" != basename($_SERVER['PHP_SELF']) ) {
        if (isset($_SESSION['history'])) {
          echo "<tr><th>History</th></tr>\n";
          echo "<tr><td nowrap=\"nowrap\">\n";
          foreach($_SESSION['history'] as $x) {
            echo menulink($x[url],myentities($x[text]),$x[info]) ."<br />\n";
          }
          echo "</td></tr>\n";
        }
      }
*/
      echo "<!--/table>\n";
      echo "  </td-->\n";
      echo "  <td width=\"95%\" colspan=\"9\" valign=\"top\" align=\"left\" id=\"datafield\">\n";
    } else {
      echo "  <td width=\"100%\" colspan=\"10\" valign=\"top\" align=\"left\" id=\"datafield\">\n";
    }
    # the remaining parts are put into an table field
    if ($msg != "") {
      echo "<div class=\"message\">". $this->error(StripSlashes($msg)) ."</div>";
    }
    echo "<!-- end of layout_start -->\n";
  }
  /**
   * end of a "normal" page
   */
  function layout_stop($name = "") {
    global $tutos,$lang,$g_hash;

    echo "<!-- layout_stop -->\n";
    #echo "   </td>\n";
    #echo "  </tr>\n";
    #echo "  <tr>\n";
    #echo "   <td colspan=\"10\" align=\"right\" height=\"30px\">\n";
    #echo "   <a id=\"tutosversion\"  class=\"nodeco\" href=\"". $tutos['base'] ."/html/copyright.html\" title=\"TUTOS ". $tutos[version] ;
    if ( ($tutos[debug] == 1) && function_exists('memory_get_usage') ) {
        echo " using ". memory_get_usage() ." Bytes of memory";
    }
    #echo " cacheinfo ". count($g_hash) ."/". $g_hash['hits'] ."";
    #echo "\"><font size=\"-2\"><i><b><acronym title=\"The Ultimative team organization software\">TUTOS</acronym> ". $tutos[version] ."</b></i></font></a>&nbsp;\n";
    #echo "   </td>\n";
    #echo "  </tr>\n";
    #echo " </table>\n";
    echo "<!-- end of layout_stop -->\n";
  }

  /**
   * display the screen
   */
  function display ($sch=false) {
    global $msg;

    if ( isset($_GET['mark']) && isset($_GET['action']) && ($_GET['action'] != -1) ) {
      $this->action = $this->action();
    }
    $this->mainmenu();
    $this->prepare();
    if ( $this->redirect != "" ) {
      Header("Status: 302 Moved Temporarily");
      Header("Location: ". getBaseUrl(). addSessionKey($this->redirect,true));
      return;
    }
    if ( ($this->format == "html") || ($this->format == "stat") || ($this->format == "checklist")) {
      # Start the HTML
      if(!$sch)
      $this->HTML_Start();
      $this->layout_start();
      if ($this->stop == false ) {
        $this->info();
      }
      echo $this->showContent();
      $this->layout_stop();
      $this->HTML_Stop();
    } else if ( $this->format == "paper" ) {
      $this->PrintHeader($this->name);
      if ($this->stop == false ) {
        $this->info();
      }
	if(!$sch)
      $this->PrintFooter();
    } else {
      $this->info();
    }
  }
  /**
   * navigation for lists
   * A Tablerow that gives some naviagtion links
   * link = the base link
   * cnt  = field count in the table
   * start = current start position
   * end   = current end position
   * max   = number of elements
   */
  function list_navigation($link,$cnt,$start,$end,$max,$paraname = 'start') {
    global $tutos, $lang;

    if ( ( $end == $max ) && ( $start <= 0 ) ) {
      return "";
    }

    $r  = "<tr>\n";
    $r .= " <th align=\"left\" colspan=\"". $cnt ."\">\n";
    $r .= "  <div align=\"left\">\n";
    $r .= $max ." ". $lang['AdminDBCount'] ."&nbsp;&nbsp;";

    if ($start > $tutos[maxshow]) {
      $l = addUrlParameter($link,$paraname ."=". max($start-2*$tutos[maxshow],0),true);
      $r .= "&nbsp;". menulink($l,"(". max($start+1-2*$tutos[maxshow],1) ." - ". ($start-$tutos[maxshow]) .")\n",$lang['NavBack']);
    }
    if ($start > 1) {
      $l = addUrlParameter($link,$paraname ."=". max($start-$tutos[maxshow],0),true);
      $r .= "&nbsp;". menulink($l,"(". max($start+1-$tutos[maxshow],1) ." - ". ($start) .")\n",$lang['NavBack']);
    }
    $r .= "&nbsp;<b>(". ($start + 1) ." - ". $end .")</b>\n";
    if ($end < $max) {
      $l = addUrlParameter($link,$paraname ."=". $end,true);
      $r .= "&nbsp;". menulink($l,"(". ($end+1) ." - ". min($end+$tutos[maxshow],$max) .")\n",$lang['NavNext']);
    }
    if (($end + $tutos[maxshow]) < $max) {
      $l = addUrlParameter($link,$paraname ."=". ($end+$tutos[maxshow]),true);
      $r .= "&nbsp;". menulink($l,"(". ($end+1+$tutos[maxshow]) ." - ". min($end+2*$tutos[maxshow],$max) .")\n",$lang['NavNext']);
    }

    $r .= "  </div><center>\n";
    if ( $start > 0 ) {
      $l = addUrlParameter($link,$paraname ."=0",true);
      $r .= menulink($l ,$lang['NavFirst'],$lang['NavFirst'],"","rel=\"Start\"");
    }
    $r .= "&nbsp;&nbsp;";
    if ( $start > 0 ) {
      $l = addUrlParameter($link,$paraname ."=". max($start - $tutos[maxshow],0),true);
      $r .= menulink($l ,$this->theme->getImage(left,'list') ."&nbsp;".$lang['NavBack'],$lang['NavBack'],"","rel=\"prev\"");
    }
    $r .= "&nbsp;&nbsp;&nbsp;";
    if ( $end < $max ) {
      $l = addUrlParameter($link,$paraname ."=". $end,true);
      $r .= menulink($l ,$lang['NavNext'] ."&nbsp;". $this->theme->getImage(right,'list'),$lang['NavNext'],"","rel=\"next\"");
    }
    $r .= "&nbsp;&nbsp;";
    if ( $start < ($max - $tutos[maxshow]) ) {
      $l = addUrlParameter($link, $paraname ."=-1",true);
      $r .= menulink($l ,$lang['NavLast'],$lang['NavLast']);
    }
    $r .= " </center>\n";
    $r .= " </th>\n";
    $r .= "</tr>\n";
    return $r;
  }
  /**
   * set focus to named field
   */
  function setfocus($fld) {
     return "<script type=\"text/javascript\" language=\"JavaScript\"> document.". $fld .".focus(); </script>\n";
  }
  /**
   * create a textarea with the given size and name
   */
  function textarea($name,$colspan,$maxsize,$value) {
    $r = "";
    $cols = 70;
    $rows = 10;
    if ($maxsize != -1) {
      $cols = min($cols,$maxsize);
      $rows = ceil($maxsize / $cols);
    }
    $rows = max(2,$rows);
    $rows = min(10,$rows);

    $r .= " <td colspan=\"". $colspan ."\">\n";
    if ($maxsize != -1) {
      $r .= "<script type=\"text/javascript\" language=\"JavaScript\">\n";
      $r .= "<!--\n";
      $r .= "function recount_". $name ."(x,maxlength) {\n";
      $r .= "  myval = 0+ x.". $name . ".value.length;";
      $r .= "  x.cnt_". $name .".value = myval;";
      $r .= "  if (myval > maxlength ) {";
      $r .= "    x.". $name .".value= x.". $name .".value.substring(0,maxlength);";
      $r .= "    x.cnt_". $name .".value = maxlength;";
      $r .= "  }";      
      $r .= "}\n";
      $r .= "//-->\n";
      $r .= "</script>\n";
    }
    $r .= "<textarea ";
    if ($maxsize != -1) {
      $r .="onblur=\"recount_". $name ."(this.form,". $maxsize .");\" ";
      $r .="onkeyup=\"recount_". $name ."(this.form,". $maxsize .");\" ";
      $r .="onchange=\"recount_". $name ."(this.form,". $maxsize .");\" ";
    }
    $r .= "id=\"". $name ."\" rows=\"". $rows ."\" cols=\"". $cols ."\" name=\"". $name ."\">". $value ."</textarea>\n";
    if ($maxsize != -1) {
        $r .= "<br /><font size=\"-2\">(<input size=\"3\" maxlength=\"3\" name=\"cnt_".$name."\" id=\"cnt_".$name."\" value=\"". strlen($value) ."\"> / ".$maxsize." characters)</font>";
    }
    $r .= " </td>\n";
    return $r;
  }
}
?>
