<?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.'screen.php';
require_once 'classes'.DIRECTORY_SEPARATOR.'systembuttonbar.php';
require_once 'classes'.DIRECTORY_SEPARATOR.'helpers.php';
  
/**
 * Customize screen
 *
 * @package Showkase
 */
class SiteSetupScreen extends Screen
{
 /**
  * @var string overrides some of head content in Screen
  */
  public $customHeadHtml = '
    <script src="scripts/formchange.js"></script>
';
 
 /**
  * constructor
  */
  public function __construct()
  {
      parent::__construct('Showkase – link', 'siteconfig', 'admin setup');
      $this->config = SkConfig::getInstance();
      $bb = new SystemButtonbar();
      $this->subNavHtml = $bb->getHtml();
  }
 /**
  * get html for link screen
  *
  * @access public
  * @return string html
  * @param array context
  */
  public function getContentHtml($context)
  {
    $contentPath = $this->config->getDocRootRelativeContentPath();
    $host = Helpers::getHost();
    $setupUrl = ' http://'.str_replace('\\', '/', $host.$contentPath);
    if ($this->config->siteIsSetup()) {
        $statusText = 'Your Web Site is Set Up';
        $cancelButton = '<li><button type="button" onclick="window.location=\'index.php\';" class="btn btn-danger">Cancel</button></li>';
        $confirm = 'onclick="return window.confirm(\'Set up site?\')"';
        $prompt = <<<EOD
    <p>Your web site address is {$setupUrl}</p>
    <p>Click the ‘Setup’ button to update the setup or change the setup path.</p>
EOD;
    } else {
        $confirm = '';
        $cancelButton = '';
        $statusText = 'Your Web Site is Not Set Up';
        $prompt = <<<EOD
    <p>Your web site address will be {$setupUrl}</p>
    <p>Showkase has entered the installation path for this address in the box below – there is usually no need to change it.</p>
    <p>Click the ‘Setup’ button to install or update.</p>
EOD;
    } 
    $html = <<<EOD
<form class="changecheck" action = "index.php?cmd=setup" id="setupform" method="post">
  <div class="subhead">
    <div class="hgroup">
      <h2>{$statusText}</h2>
    </div>
    <ul class="buttons">
      {$cancelButton}
      <li>
        <input type="hidden" name="setupSubmit" value="true" >
        <input type="hidden" name="token" value="{$context['token']}">
        <button type="submit" class="btn btn-success formbutton" {$confirm}>Setup</button></li>
    </ul>
  </div>
  <div class="prompt">
    {$prompt}
  </div>
  <fieldset>
    <div class="clearfix">
      <label for="form-contentpath" class="" title="">Path to your web site folder</label>
      <div class="input"><input type="text" class="text" name="contentPath" id="form-contentpath" tabindex="2" value="{$contentPath}" /></div>
    </div>   
  </fieldset>
</form>
EOD;
    return $html;
  }
}