<?php
  
  class page
  {
      var $parts = array();
      var $currentCategory;
      var $topCategory;
      var $cLocation;
      var $adminCategory;
      
      function __construct()
      {
          global $config;
          $checkSubDirectories = explode('/', $config->subDirectories);
          $theSplit = explode('?', $_SERVER['REQUEST_URI']);
          $this->cLocation = $theSplit[0];
          $tempParts = explode('/', $this->cLocation);
          for ($x = 0; $x <= count($tempParts); $x++)
          {
              if (!empty($tempParts[$x]) && $tempParts[$x][0] != '?')
              {
                  if (!in_array($tempParts[$x], $checkSubDirectories))
                  {
                      $this->parts[] = $tempParts[$x];
                      $this->currentCategory = $tempParts[$x];
                  }
                  else
                  {
                      unset($checkSubDirectories[$x]);
                  }
              }
          }
          $this->topCategory = $this->parts[0];
          
          if ($this->topCategory == $config->atemplate)
            $this->adminCategory = $this->parts[1];
          if (empty($this->currentCategory))
            $this->currentCategory = 'home';
          if (empty($this->topCategory))
            $this->topCategory = 'home';
      }
      
      function getPart()
      {
          if (isset($this->parts[0]))
          {
              $gotPart = $this->parts[0];
              $this->removePart();
              return $gotPart;
          }
      }
      
      function removePart()
      {
          return array_shift($this->parts);
      }
      
      function getTitle($split = '&rsaquo;&rsaquo;')
      {
          global $config, $pages, $functions;
          $pathDisplay = $config->pageTitle;
          $path = $config->subDirectories . '/';
          foreach ($this->parts as $part)
          {
              $partTitle = $pages->getShortname($part, 'title');
              if (empty($partTitle))
              {
                  $partTitle = $part;
              }
              if ($partTitle[0] != '?' && !is_numeric($partTitle))
              {
                  $pathDisplay .= ' ' . $split . ' ' . $functions->clearUnders(ucfirst($partTitle)) . ' ';
              }
              $path .= $part . '/';
          }
          
          return $pathDisplay;
      }
	  function getMyTitle($pagename)
	{
	global $db,$conn;
	 $getRecord = $db->query("SELECT * FROM pages WHERE shortname = '{$pagename}'");
	$rowRecord = $db->next_record($getRecord);
	return $rowRecord['title'];
	} 
  }
?>
