/home/coolpkct/www/websites/cake3.cool.rocks/admin/classes/pagesscreen.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.'screen.php';
require_once 'classes'.DIRECTORY_SEPARATOR.'helpers.php';
 
/**
 * Pages screen
 *
 * @package Showkase
 */
class PagesScreen extends Screen
{
  /**
   * Returns list of pages as html table
   * @access public
   * @return string html table
   * @param array context
  */
  function getContentHtml($context)
  {
    $weights = array();
    $pageIndices = array();
    $parents = array();
    $sorted = array();
    $siteTitle = $context['siteTitle'];
    $pagesData = $this->pageSet->getPagesData();
    foreach ($pagesData as $key=>$pageData)
    {
      $weights[] = isset($pageData['navWeight']) ? $pageData['navWeight'] : 0;
      $pageIndices[$pageData['pageRef']] = $key;
    }
    unset($key, $pageData);
    array_multisort($weights, $pagesData);
    foreach ($pagesData as $key=>$pageData)
    {
      if (!isset($pageData['parentPage']) || $pageData['parentPage'] == 0)
      {
        $parents[$key] = $pageData;
      }
    }
    unset($key, $pageData);
    foreach ($parents as $parentKey=>$parentData)
    {
      $sorted[] = $parentData;
      foreach ($pagesData as $key=>$pageData)
      {
        if (isset($pageData['parentPage']) && $pageData['parentPage'] == $parentData['pageRef'])
        {
          $sorted[] = $pageData;
        }
      }
      unset ($key, $pageData);
    }
    unset($parentKey, $parentData);
    $pagesData = $sorted;
    $pagesPrefs = $this->pageSet->getPagesPrefs();
    //$newPagePref = isset($pagesPrefs['newPagePref']) ? $pagesPrefs['newPagePref'] : '';
    $newPageOptions = '';
    $submitDisabled = '';
    $newPageHtml = '';
    foreach ($context['pageTypes'] as $type=>$pageTypeData)
    {
      if (isset($pageTypeData['exposed']) && strtolower($pageTypeData['exposed']) == 'false') continue;
      $newPageHtml .= '
      <tr>
        <td>'.$pageTypeData['name'].'</td>
        <td class="commit"><a href="index.php?cmd=newpage&amp;type='.$type.'&amp;token='.$context['token'].'">Create</a></td>
      </tr>
';
    }
    unset($type, $pageTypeData);
    if ($newPageHtml == '')
    {
      $newPageHtml = '
      <tr>
        <td>No plugins available</td>
      </tr>
';
    }
    $html = <<<EOD
    <div id="newpage" class="modal hide fade">
      <div class="modal-header">
        <a class="btn btn-danger close" data-dismiss="modal" href="#">Cancel</a>
        <h3>Create new web page</h3>
      </div>
      <div class="modal-body">
        <table class="showkase-actions">
          {$newPageHtml}
        </table>
      </div>
    </div>
	  <div class="subhead">
	    <div class="hgroup">
        <h2>{$siteTitle}</h2>
      </div>
      <ul class="buttons unstyled">
        <li><button type="button" class="btn btn-success" data-toggle="modal" data-target="#newpage" data-backdrop="true" title="Create new page for your web site"><span>New&nbsp;Page</span></button></li>
      </ul>
    </div>
    <br class="clearboth">
EOD;
    if (count($pagesData) == 0)
    {
      $html .= '<p class="info">You have no web pages</p>';
      return $html;
    }
    $html .= '
    <table id="pageset" class="showkase-actions">
      <thead>
        <tr>
          <th scope="col">Name</th>
          <th scope="col">Type</th>
          <th scope="col" colspan="2">Actions</th>
        </tr>
      </thead>
      <tbody>';
    foreach ($pagesData as $key=>$pageData)
    {
      $pageRef = $pageData['pageRef'];
      $pageUrl = str_replace('\\', '/', $pageData['path']);
      $groupClass = ($pageData['parentPage'] > 0) ? 'child' : '';
      $navName = htmlspecialchars($pageData['navName'], ENT_QUOTES, 'UTF-8');
      $navShowClass = 'nav-show-false'; 
      if (
          strtolower($pageData['navShow']) == 'true'
          || (
              $pageData['isGallery']
              && strtolower($pageData['indexShow']) == 'true'
          )
      ) {
          $navShowClass = 'nav-show-true';
      }
      $supported = isset($pageData['supported']) && strtolower($pageData['supported']) == 'false'
          ? 'false'
          : 'true';
      $supportedClass = 'supported-'.$supported;
      $remPrompt = "'Move ".$navName." to trash folder?'";
      $pageIndex = $pageIndices[$pageData['pageRef']];
      $navNameHtml = $supported == 'true'
          ? '<a href="'.$pageUrl.'" target="preview" title="View page">'.$navName.'</a>'
          : $navName;
      $html .= '
      <tr>
        <td class="name '.$groupClass.' '.$navShowClass.' '.$supportedClass.'">
          <div class="truncate">
            '.$navNameHtml.'
          </div>
        </td>
        <td class="pagetype '.$supportedClass.'">'.$context['pageTypes'][$pageData['pageType']]['name'].'</td>
        <td class="edit"><a href="index.php?cmd=pagecustomize&amp;pageIndex='.$pageIndex.'" title="Customize web page">Edit</a></td>
        <td class="trash"><a href="index.php?cmd=trash&amp;pageIndex='.$pageIndex.'&amp;token='.$context['token'].'" onclick="return window.confirm('.$remPrompt.')" title="Move page to trash folder">Trash</a></td>
      </tr>';
    }
    $html .= '
    </tbody>
    </table>'; 
    return $html;    
  }
}