/home/coolpkct/www/websites/cake3.cool.rocks/admin/classes/screen.php
<?php
/**
 * Part of Showkase web site management package
 *
 * @package Showkase
 * @author Jack Hardie {@link http://www.jhardie.com}
 * @copyright Copyright (c) 2012, SimpleViewer Inc.
 */
defined('SK_ACCESS')||die('<h1>403: Forbidden</h1>'); 
require_once 'classes'.DIRECTORY_SEPARATOR.'buttonbar.php';
require_once 'classes'.DIRECTORY_SEPARATOR.'primarybuttonbar.php';
require_once 'classes'.DIRECTORY_SEPARATOR.'pageset.php';
 
/**
 * Creates html headers and footers including css.
 *
 * @package Showkase
 */
abstract class Screen
{
  /**
   * @var object site instance of SkConfig
   */
   protected $config;
   
  /**
   * @var string contains text for html <title></title> tags
   */
   protected $title;
  /**
   * @var string id for body tag
   */
   protected $bodyId;
   
  /**
   * @var string class for body tag. Used to differentiate viewers
   */
   protected $bodyClass;
  /**
   * @var string screen specific html to be added to the bottom of the <head> element
   */
   protected $customHeadHtml = '';
   
  /**
   * @var second level nav under tabs html
   */
   protected $subNavHtml = '';
   
  /**
   * @var object page set
   */
   protected $pageSet;
   
  /**
   * @var array page preferences
   */
   protected $pagePrefs;
  /**
   * Constructs Screen
   *
   * @access public
   * @return void
   * @param string content for html title tag
   * @param string body id
   * @param string body class
   */
  public function __construct($htmlTitle, $bodyId='', $bodyClass='allpages')
  {
    $this->config = SkConfig::getInstance();
    $this->title = $htmlTitle;
    $this->bodyId = $bodyId;
    $this->bodyClass = $bodyClass;
    $this->pageSet = new PageSet();
    $this->pagePrefs = $this->pageSet->getPagesPrefs();
  }
   
  /**
   * Enforces interface for method to return html specific to page type
   *
   * @param array
   * @return string
   */
   abstract public function getContentHtml($context);
  /**
   * Return complete html for screen
   * Overriden in LibraryBrowseImagesScreen and ErrorScreen
   *
   * @return string
   * @param array context
   */
   public function getHtml($context)
   {
     // get html before error messages are collated
     $htmlHead = $this->getHtmlHead();
     $contentHtml = $this->getContentHtml($context);
     $footer = $this->getFooter();
     $uncaughtErrorMessages = ob_get_clean();
     $messages = '';
     try
     {
       $messages = Board::getMessages();
       $this->bodyClass = $this->config->siteIsSetup() ? $this->bodyClass : $this->bodyClass.' notsetup';
     }
     catch (Exception $e)
     {
       $messages = '
  <ul class="messages unstyled">
    <li class="warning">'.$e->getMessage().'</li>
  </ul>';
     }
     if (!empty($uncaughtErrorMessages))
     {
       $messages.= '<div class="error">'.$uncaughtErrorMessages.'</div>';
     }
     $html = $htmlHead;
     $html .= $this->getScreenHeader($context, $messages);
     $html .= $contentHtml;
     $html .= $footer;
     return $html;
   }
   
  /**
   * Returns string containing html header, css styles and screen heading
   *
   * @return string
   */  
  public function getHtmlHead()
  {
    $header = <<<EOD
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>{$this->title}</title>
  <link href="css/bootstrap.min.css" rel="stylesheet" media="all" />
  <link href="css/all.css" rel="stylesheet" media="all" />
  <!--[if lt IE 9]>
    <script src="scripts/html5shiv.js"></script>
  <![endif]-->
  <script src="scripts/jquery/jquery-min.js"></script>
  <script src="scripts/bootstrap/bootstrap.min.js"></script>
  <script src="scripts/allscreens.js"></script>
  {$this->customHeadHtml}
  <link href="css/custom.css" rel="stylesheet" media="all" />
  <link rel="shortcut icon" href="img/favicon.ico" type="image/x-icon">
</head>
EOD;
  return $header;
}
 /**
  * Returns string containing navigation
  *
  * @return string
  * @param array context
  * @param string eror messages and notices html
  */
  public function getScreenHeader(array $context, $messages)
  {
      $tokenQuery = isset($context['token'])
          ? '&token='.$context['token']
          : '';
      $pagesData = $this->pageSet->getPagesData();
      $bb = new PrimaryButtonbar();
      $primaryNav = $bb->getHtml();
      $rebuildLink = count($pagesData) > 0
      ?      '<a class="enabled" target="preview" href="index.php?cmd=publish'.$tokenQuery.'" title="Rebuild and save all web pages">Publish</a>'
      :      '<a class="disabled" title="Rebuild and save all web pages">Publish</a>';    
    $navigation = <<<EOD
  <body id="{$this->bodyId}" class="{$this->bodyClass}">
  	<div id="wrapper">
      <div id="header">
        <div class="nav externalnav">
          <ul class="externalnav">
            <li><a href="index.php?cmd=logout" title="log out of Showkase">Log-out</a>  |  </li>
            <li><a href="http://showkase.net/support/" target="_blank" title="on-line documentation">Help</a></li>
          </ul>
        </div>
        <div class="nav primarynav">
          <ul class="controls">
            <li class="republish {$this->pagePrefs['publishing']} first last">{$rebuildLink}</li>
          </ul>
          {$primaryNav}
      </div>
      <br class="clearboth" />
      <div class="messages">
  	    {$messages}
  	  </div>
      <div class="nav subnav">
      {$this->subNavHtml}
      </div>
      </div>
      <div id="content">
  
EOD;
    return $navigation;
  }
  /**
   * Returns string containing footer and closing html tags
   *
   * @return string
   */  
  public function getFooter()
  {
    $title = SK_TITLE; 
    $build = SK_BUILD;
    $footer = <<<EOD
  </div>
  <div id="footer">
    <p id="copyright">{$title} | Build: {$build} | <a href="http://www.showkase.net/terms/">Terms of Use</a> | © 2014 SimpleViewer Inc. All rights reserved.</p>
    <br class="clearboth" />
  </div>
  </div>
</body>
</html>
EOD;
  return $footer;
  }
  
  /**
   * Return html for customize screen fields
   *
   * @param array of field objects
   * @param integer tab index
   * @return string
   */
  protected function getFieldsHtml(array $sections, &$tab=0)
  {
      $html = '';
      foreach ($sections as $section=>$fields) {
          $html .= '
    <fieldset>
      <legend>'.$section.'</legend>
';
          foreach ($fields as $name=>$field) {
              $html .= $field->getHtml($tab);
          }
          $html .= '
    </fieldset>  
';
      }
      return $html;
  }
  
 /**
  * Returns html for colorjack color picker
  *
  * @return string
  */
  public function getColorjackHtml()
  {
    $html = <<<EOD
<div id="plugin" class="selectfree">
 <div id="plugHEX" onmousedown="stop=0; setTimeout('stop=1',100);">F1FFCC</div>
 <!-- Note change of function name from toggle to avoid namespace conflict -->
 <div id="plugCLOSE" onmousedown="toggleDisplay('plugin')">X</div><br />
 <div id="SV" onmousedown="HSVslide('SVslide','plugin',event)" title="Saturation + Value">
  <div id="SVslide" style="TOP: -4px; LEFT: -4px;"><br /></div>
 </div>
 <form id="H" onmousedown="HSVslide('Hslide','plugin',event)" title="Hue">
  <div id="Hslide" style="TOP: -7px; LEFT: -8px;"><br /></div>
  <div id="Hmodel"></div>
 </form>
 <!--[if lte IE 6.5]><iframe></iframe><![endif]-->
</div>
EOD;
    return $html;
  }
}