<?php

  /*

      sidebar.inc

      Sidebar of the system once logged in. [Commented]

      Changelog:
        2005-07-02 arne_sf: Replaced all instances of column name 'user' for table tbl_UserSites with 'userid'
          
      ## PAGE CONTAINS HANDYANDY MYSQL MODS ##
      ## Copyright (C) 2005 Andy Deakin (handyandy.org.uk) ##

      ----

      Copyright (C) 2003  Central Manchester CLC
      Copyright (C) 2003  David Thorne (davethorne@gmail.com)

      This program is free software; you can redistribute it and/or
      modify it under the terms of the GNU General Public License
      as published by the Free Software Foundation version 2.

      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU General Public License for more details.

      You should have received a copy of the GNU General Public License
      along with this program; if not, write to the Free Software
      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

  */

  // Includes
  require_once 'system/db.php';
  require_once 'system/lang.php';
  require_once 'system/security.php';
  require_once 'system/user_preferences.php';
 
  if ($_SESSION['_usertype'] == '') { ThrowOut(); }

  // Language selection
  set_text_domain("sidebar");

  if ($_SESSION['_id'] == '') TimeOut();
  if ($_SESSION['_domain'] == '' && $_SESSION['_usertype'] != 'Root') ThrowOut();

  // If there are no domans set up, then make sure that is what is to be done next...
  if ($_SESSION['_domain'] == '') {

?>

<div class="header">
  <div class="headerright"><?php echo gettext("You will have to create a domain...");?></div>
</div>

<div class="sidebar">
  <div class="menu">
    <div class="menutitle"><?php echo gettext("Admin");?></div>
    <div class="menugroup">
<?php
    if ($_SESSION['_usertype'] == 'Root') {
?>
      <div class="menuitem">&gt; <a href="domains.php?act=nodomains"><?php echo gettext("Domains");?></a></div>
<?php
    }
?>
    </div>
    <div class="menutitle"><?php echo gettext("My Account");?></div>
    <div class="menugroup">
      <div class="menuitem">&gt; <a href="details.php"><?php echo gettext("My Details");?></a></div>
      <div class="menuitem">&gt; <a href="index.php"><?php echo gettext("Logout");?></a></div>
    </div>
  </div>
  <p><?php printf(gettext("User <span style=\"color:#000000\">%s</span> logged in."),$_SESSION['_username']); ?></p>

</div>

<div class="maingroup">

<?php
  } else {

    // Normal sidebar starts here
    // Draw title bar with the name of the domain and the name of the user

?>

<!-- Here starts the sidebar, the main navigational tool of the system -->

<div class="header">
  <div class="headerleft">&nbsp;<?php echo $_SESSION['_domainname']?></div>
   <div class="headerright">&nbsp;<?php echo gettext("for")?> <?php echo $_SESSION['_name']?></div>
</div>

<map title="Navigation bar" id="navbar">
<div class="sidebar">
  <div class="menu">
<?php

    // Now conditionally show the sidebar menu, with all the standard links that would
    // be needed to allow normal operation.
    if ($_SESSION['_usertype'] != 'Root') {
?>
    <div class="menutitle"><?php echo gettext("Issues");?></div>
    <div class="menugroup">
      <div class="menuitem">&gt; <a href="newissue.php" accesskey="n"><?php echo gettext("New Issue");?></a></div>
      <div class="menuitem">&gt; <a href="myissues.php" accesskey="m"><?php echo gettext("My Issues");?></a></div>
<?php
      if ($_SESSION['_usertype'] != 'Client') {
?>
      <div class="menuitem">&gt; <a href="unassignedissues.php" accesskey="u"><?php echo gettext("Unassigned Issues");?></a></div>
      <div class="menuitem">&gt; <a href="mysitesissues.php" accesskey="s"><?php echo gettext("My Sites' Issues");?></a></div>
<?php
      }
?>
      <div class="menuitem">&gt; <a href="find.php" accesskey="f"><?php echo gettext("Find Issue");?></a></div>
    </div>
    <div class="menutitle"><?php echo gettext("Knowledge");?></div>
    <div class="menugroup">
      <div class="menuitem">&gt; <a href="search.php"><?php echo gettext("Search");?></a></div>
      <div class="menuitem">&gt; <a href="recent.php"><?php echo gettext("Recent");?></a></div>
    </div>
<?php
    }
    if ($_SESSION['_usertype'] != 'Client') {
      if ($_SESSION['_usertype'] != 'Root') {
?>
    <div class="menutitle"><?php echo gettext("Statistics");?></div>
    <div class="menugroup">
      <div class="menuitem">&gt; <a href="summary.php" accesskey="y"><?php echo gettext("Summary");?></a></div>
      <div class="menuitem">&gt; <a href="reports.php"><?php echo gettext("Reports");?></a></div>
    </div>
<?php
      }
?>
<?php
      // Don't display admin section if it would be empty otherwise
      if (!(($_SESSION['_usertype'] == 'Support Agent' ||
             $_SESSION['_usertype'] == 'Site Contact') ||
             $_SESSION['_restricted'] == '1')) {
?>
    <div class="menutitle"><?php echo gettext("Admin");?></div>
    <div class="menugroup">
<?php
        if ($_SESSION['_usertype'] == 'Root') {
?>
      <div class="menuitem">&gt; <a href="domains.php"><?php echo gettext("Domains");?></a></div>
<?php
        }
        if ($_SESSION['_usertype'] != 'Client' && $_SESSION['_restricted']!='1') {
?>
      <div class="menuitem">&gt; <a href="sitesandusers.php"><?php echo gettext("Sites and Users");?></a></div>
      <div class="menuitem">&gt; <a href="assets.php"><?php echo gettext("Assets");?></a></div>
<?php
        }
        if ($_SESSION['_usertype'] == 'Domain Administrator' || $_SESSION['_usertype'] == 'Root') {
?>
      <div class="menuitem">&gt; <a href="problemcategories.php"><?php echo gettext("Problem Categories");?></a></div>
      <div class="menuitem">&gt; <a href="levels.php"><?php echo gettext("Levels");?></a></div>
      <div class="menuitem">&gt; <a href="priorities.php"><?php echo gettext("Priorities");?></a></div>
      <div class="menuitem">&gt; <a href="statuses.php"><?php echo gettext("Statuses");?></a></div>
      <div class="menuitem">&gt; <a href="publicnotice.php"><?php echo gettext("Public Notice");?></a></div>
<?php
        }
        if ($_SESSION['_usertype'] == 'Root') {
?>
      <div class="menuitem">&gt; <a href="publicnotice.php?global=true"><?php echo gettext("Front Page Notice");?></a></div>
      <div class="menuitem">&gt; <a href="managenews.php"><?php echo gettext("Front Page News");?></a></div>
      <div class="menuitem">&gt; <a href="links.php"><?php echo gettext("Front Page Sidebar");?></a></div>
      <div class="menuitem">&gt; <a href="frontpagepara.php"><?php echo gettext("Front Page Text");?></a></div>
      <div class="menuitem">&gt; <a href="globalpreferences.php"><?php echo gettext("Global Preferences");?></a></div>
<?php
        }
?>
    </div>
<?php
      }
    }
?>
    <div class="menutitle"><?php echo gettext("My Account");?></div>
    <div class="menugroup">
<?php
    if ($_SESSION['_restricted'] != '1') {
?>
      <div class="menuitem">&gt; <a href="details.php" accesskey="d"><?php echo gettext("My Details");?></a></div>
<?php
      if ($_SESSION['_usertype'] != 'Root') {
?>
      <div class="menuitem">&gt; <a href="preferences.php" accesskey="p"><?php echo gettext("My Preferences");?></a></div>
<?php
      }

      // Domain wide preferences
      if ($_SESSION['_usertype'] != 'Client' &&
          $_SESSION['_usertype'] != 'Site Contact' &&
          $_SESSION['_usertype'] != 'Support Agent' &&
          $_SESSION['_usertype'] != 'Administrator') {
?>
      <div class="menuitem">&gt; <a href="preferences.php?type=domain"><?php echo gettext("Domain Preferences");?></a></div>
<?php
      }

      if ($_SESSION['_usertype'] == 'Root') {
?>
      <div class="menuitem">&gt; <a href="preferences.php?type=default"><?php echo gettext("Preference defaults");?></a></div>
<?php
      }
    }
?>
      <div class="menuitem">&gt; <a href="logout.php" accesskey="x"><?php echo gettext("Logout");?></a></div>
    </div>
<?php
    // Conditionally show the other domains this user has access to and invite them to
    // jump straight to them.
    $accept = '';
    if ($_SESSION['_usertype'] == 'Root') {
      // Show all domains except the current one for the root user
      $sql = "SELECT * FROM tbl_Domains WHERE id<>$_SESSION[_domain] AND id>0 AND active=1";
      $accept = 'root';
    } else {
      // Show all of this user's domains except the current one
    ## $sql = "SELECT DISTINCT vw_Users.domain AS id,tbl_Domains.domain FROM vw_Users,tbl_Domains,vw_Sites WHERE vw_Users.domain=tbl_Domains.id AND tbl_Domains.active=1 AND vw_Users.id=$_SESSION[_id] AND tbl_Domains.id<>$_SESSION[_domain] AND vw_Sites.domain=vw_Users.domain AND vw_Sites.\"user\"=vw_Users.id";
      $sql = "SELECT DISTINCT tbl_Sites.domain as id, tbl_Domains.domain
              FROM tbl_Sites,tbl_Domains,tbl_UserSites
              WHERE tbl_UserSites.userid=$_SESSION[_id]
                AND tbl_Sites.id=tbl_UserSites.site
                AND tbl_Sites.domain != $_SESSION[_domain]
                AND tbl_Domains.id=tbl_Sites.domain";
    }
    $domainsRS = db_recordset($sql);
    if (count($domainsRS) > 0) {
      // If there are indeed other domains available then show them, otherwise don't
      // even show this menu item. Submitting this form passes execution back to the
      // login.php page and tells it to change the domain.
?>
    <div class="menutitle"><?php echo gettext("My Domains")?></div>
    <div class="menulogingroup">
      <form name="login" id="login" method="post" class="login" action="login.php">
        <input type="hidden" name="act" value="accept<?php echo $accept?>" />
        <select name="domain">
<?php
      foreach ($domainsRS as $record) {
        print "          <option value=\"$record[id]\">$record[domain]</option>\n";
      }
?>
        </select>
        <div class="loginbutton"><input type="submit"
            value="<?php echo gettext("Jump To");?>" /></div>
      </form>
    </div>
<?php
    }
?>
  </div>

  <p><?php printf(gettext("User <span style=\"color:#000000\">%s</span> logged in."),$_SESSION['_username']);?></p>

</div>
</map>

<?php
    // Check for a public notice for this current domain and display it if present
    $noticeRS = db_recordset("SELECT content FROM tbl_News WHERE frontpagepara=3 and domain_id=$_SESSION[_domain] and lang='".$language."'");
    if ($noticeRS[0][content] != '') {
?>

<!-- Here starts the public notice of this domain -->

<div class="maingroup">
  <div class="notice">
    <h2><?php echo gettext("Important Notice")?></h2>
    <p><?php echo nl2br($noticeRS[0][content])?></p>
  </div>
</div>

<?php
    }
?>

<!-- Here starts the main section of the page -->

<div class="maingroup">
<?php
  }
?>
