<?php
/**
 * Part of Showkase web site management package
 *
 * @package Showkase
 * @author Jack Hardie {@link http://www.jhardie.com}
 * @copyright Copyright (c) 2013, SimpleViewer Inc.
 */
defined('SK_ACCESS')||die('<h1>403: Forbidden</h1>');
require_once 'classes'.DIRECTORY_SEPARATOR.'sitebuttonbar.php';
require_once 'classes'.DIRECTORY_SEPARATOR.'helpers.php';
require_once 'classes'.DIRECTORY_SEPARATOR.'customizescreenhelper.php';
 
/**
 * Customize screen
 *
 * @package Showkase
 */
class ViewerCustomizeScreen extends Screen
{
    /**
     * @var string overrides some of head content in Screen
     */
    protected $customHeadHtml;
    
    /**
     * @var object viewer
     */
    private $viewer;
   
    /**
     * @var string tabs html
     */
    protected $subNavHtml;
    
    /**
     * @var object helper
     */
    private $helper;
    
    /**
     * constructor
     * @param string contains text for html <title></title> tags
     * @param string html id for body tag
     */
    public function __construct(Viewer $viewer, $classes="")
    {
        $this->viewer = $viewer;
        parent::__construct('Showkase – customize', 'viewercustomize', $classes);
        $this->helper = new CustomizeScreenHelper($viewer, $this->pageSet);
        $this->customHeadHtml = $this->helper->getCustomHeadHtml();
        $bb = new SiteButtonbar();
        $this->subNavHtml = $bb->getHtml();
    }
  
    /**
     * get html for customize screen
     *
     * @return string html
     * @param array context
     */
    public function getContentHtml($context)
    {
      $viewerName = $this->viewer->getRef();
      $headerHtml = '
        <h2>Customize '.$context['pageTypes'][$viewerName]['shortName'].'</h2>
';
      $showLink = '
      <a href="index.php?cmd=viewercustomize&viewer='.$viewerName.'&showPro=1" class="linktipper" title="Showkase will reload the page to show the Pro options. Update first if you have unsaved changes.">
        Show Pro Options <img alt="tooltip icon" src="img/comment.png">
      </a>';
      $hideLink = '
      <a href="index.php?cmd=viewercustomize&viewer='.$viewerName.'&showPro=0" class="linktipper" title="Showkase will reload the page to hide the Pro options. Update first if you have unsaved changes.">
        Hide Pro Options <img alt="tooltip icon" src="img/comment.png">
      </a>';
      $liteFields = $this->helper->getLiteFields();
      $proFields = $this->helper->getProFields();
      $tab = 0;
      $liteHtml = $this->getFieldsHtml($liteFields, $tab);
      $proHtml = '';
      if (
          !empty($context['showPro'])
          && !empty($proFields)
      ) {
          $proHtml = '
      <div class="hline"> </div>
      '
      .$this->getFieldsHtml($proFields, $tab)
      .'
      <p class="showhide">'.$hideLink.'</p>';
      }
      $formButtonHtml = $this->helper->getFormButtonHtml($context);
      $cmd = 'viewercustomize&viewer='.$this->viewer->getRef();
      $showHide = empty($context['showPro'])
          ? $showLink
          : $hideLink;
      if (empty($proFields)) {
          $showHide = '';
      }
      if (count($this->helper->getAllFields()) == 0) {
          $showHide = '';
          $liteHtml = '
          <p>There are no viewer settings in this theme.</p>
';
          $proHtml = '';
      }
      $html = $this->getColorjackHtml();   
      $html .= <<<EOD
      <form class="changecheck form-horizontal" action = "index.php?cmd={$cmd}" id="customizeform" method="post">
        <div class="subhead">
          <div class="hgroup">
            {$headerHtml}
          </div>
          {$formButtonHtml}
        </div>
        {$liteHtml}
        <p class="showhide">{$showHide}</p>
        {$proHtml}
      </form>
EOD;
      return $html;
    }
}