plugins/admin/ThemeManager.php
author Dan
Tue, 26 Feb 2008 19:51:43 -0500
changeset 463 0857911fb7f1
parent 433 c892b2013d3e
child 465 fe8b8c9b54e8
permissions -rw-r--r--
Fixed some bugs with $paths->getParam() and $paths->get_pageid_from_url() when slashes are in the namespace prefix. Result of testing on Windows Vista + Apache 2.2. Using TortoiseHG
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
433
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
     1
<?php
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
     2
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
     3
/*
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
     4
 * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
     5
 * Version 1.1.2 (Caoineag alpha 2)
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
     6
 * Copyright (C) 2006-2007 Dan Fuhry
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
     7
 *
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
     8
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
     9
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    10
 *
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    11
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    12
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    13
 */
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    14
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    15
function page_Admin_ThemeManager()
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    16
{
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    17
  global $db, $session, $paths, $template, $plugins; // Common objects
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    18
  global $lang;
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    19
  if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    20
  {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    21
    $login_link = makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    22
    echo '<h3>' . $lang->get('adm_err_not_auth_title') . '</h3>';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    23
    echo '<p>' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '</p>';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    24
    return;
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    25
  }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    26
  
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    27
  $system_themes = array('admin', 'printable');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    28
  
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    29
  // Obtain the list of themes (both available and already installed) and the styles available for each
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    30
  $dh = @opendir(ENANO_ROOT . '/themes');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    31
  if ( !$dh )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    32
    die('Couldn\'t open themes directory');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    33
  $themes = array();
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    34
  while ( $dr = @readdir($dh) )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    35
  {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    36
    if ( $dr == '.' || $dr == '..' )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    37
      continue;
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    38
    if ( !is_dir(ENANO_ROOT . "/themes/$dr") )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    39
      continue;
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    40
    if ( !file_exists(ENANO_ROOT . "/themes/$dr/theme.cfg") || !is_dir(ENANO_ROOT . "/themes/$dr/css") )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    41
      continue;
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    42
    $cdh = @opendir(ENANO_ROOT . "/themes/$dr/css");
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    43
    if ( !$cdh )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    44
      continue;
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    45
    
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    46
    require(ENANO_ROOT . "/themes/$dr/theme.cfg");
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    47
    global $theme;
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    48
    
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    49
    $themes[$dr] = array(
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    50
        'css' => array(),
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    51
        'theme_name' => $theme['theme_name']
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    52
      );
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    53
    while ( $cdr = @readdir($cdh) )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    54
    {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    55
      if ( $cdr == '.' || $cdr == '..' )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    56
        continue;
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    57
      if ( preg_match('/\.css$/i', $cdr) )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    58
        $themes[$dr]['css'][] = substr($cdr, 0, -4);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    59
    }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    60
  }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    61
  
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    62
  // Decide which themes are not installed
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    63
  $installable = array_flip(array_keys($themes));
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    64
  // FIXME: sanitize directory names or check with preg_match()
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    65
  $where_clause = 'theme_id = \'' . implode('\' OR theme_id = \'', array_flip($installable)) . '\'';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    66
  $q = $db->sql_query('SELECT theme_id, theme_name, enabled FROM ' . table_prefix . "themes WHERE $where_clause;");
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    67
  if ( !$q )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    68
    $db->_die();
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    69
  
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    70
  while ( $row = $db->fetchrow() )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    71
  {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    72
    $tid =& $row['theme_id'];
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    73
    unset($installable[$tid]);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    74
    $themes[$tid]['theme_name'] = $row['theme_name'];
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    75
    $themes[$tid]['enabled'] = ( $row['enabled'] == 1 );
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    76
  }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    77
  
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    78
  foreach ( $system_themes as $st )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    79
  {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    80
    unset($installable[$st]);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    81
  }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    82
  
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    83
  $installable = array_flip($installable);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    84
  
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    85
  // AJAX code
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    86
  if ( $paths->getParam(0) === 'action.json' )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    87
  {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    88
    return ajaxServlet_Admin_ThemeManager($themes);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    89
  }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    90
  
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    91
  // List installed themes
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    92
  ?>
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    93
  <div style="float: right;">
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    94
    <a href="#" id="systheme_toggler" onclick="ajaxToggleSystemThemes(); return false;"><?php echo $lang->get('acptm_btn_system_themes_show'); ?></a>
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    95
  </div>
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    96
  <?php
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    97
  echo '<h3>' . $lang->get('acptm_heading_edit_themes') . '</h3>';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    98
  echo '<div id="theme_list_edit">';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
    99
  foreach ( $themes as $theme_id => $theme_data )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   100
  {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   101
    if ( in_array($theme_id, $installable) )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   102
      continue;
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   103
    if ( file_exists(ENANO_ROOT . "/themes/$theme_id/preview.png") )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   104
    {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   105
      $preview_path = scriptPath . "/themes/$theme_id/preview.png";
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   106
    }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   107
    else
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   108
    {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   109
      $preview_path = scriptPath . "/images/themepreview.png";
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   110
    }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   111
    $d = ( @$theme_data['enabled'] ) ? '' : ' themebutton_theme_disabled';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   112
    $st = ( in_array($theme_id, $system_themes) ) ? ' themebutton_theme_system' : '';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   113
    echo '<div class="themebutton' . $st . '' . $d . '" id="themebtn_edit_' . $theme_id . '" style="background-image: url(' . $preview_path . ');">';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   114
    if ( in_array($theme_id, $system_themes) )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   115
    {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   116
      echo   '<a class="tb-inner" href="#" onclick="return false;">
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   117
                ' . $lang->get('acptm_btn_theme_system') . '
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   118
                <span class="themename">' . htmlspecialchars($theme_data['theme_name']) . '</span>
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   119
              </a>';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   120
    }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   121
    else
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   122
    {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   123
      echo   '<a class="tb-inner" href="#" onclick="ajaxEditTheme(\'' . $theme_id . '\'); return false;">
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   124
                ' . $lang->get('acptm_btn_theme_edit') . '
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   125
                <span class="themename">' . htmlspecialchars($theme_data['theme_name']) . '</span>
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   126
              </a>';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   127
    }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   128
    echo '</div>';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   129
  }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   130
  echo '</div>';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   131
  echo '<span class="menuclear"></span>';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   132
  
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   133
  if ( count($installable) > 0 )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   134
  {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   135
    echo '<h3>' . $lang->get('acptm_heading_install_themes') . '</h3>';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   136
  
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   137
    echo '<div id="theme_list_install">';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   138
    foreach ( $installable as $i => $theme_id )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   139
    {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   140
      if ( file_exists(ENANO_ROOT . "/themes/$theme_id/preview.png") )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   141
      {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   142
        $preview_path = scriptPath . "/themes/$theme_id/preview.png";
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   143
      }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   144
      else
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   145
      {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   146
        $preview_path = scriptPath . "/images/themepreview.png";
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   147
      }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   148
      echo '<div class="themebutton" id="themebtn_install_' . $theme_id . '" enano:themename="' . htmlspecialchars($themes[$theme_id]['theme_name']) . '" style="background-image: url(' . $preview_path . ');">';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   149
      echo   '<a class="tb-inner" href="#" onclick="ajaxInstallTheme(\'' . $theme_id . '\'); return false;">
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   150
                ' . $lang->get('acptm_btn_theme_install') . '
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   151
                <span class="themename">' . htmlspecialchars($themes[$theme_id]['theme_name']) . '</span>
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   152
              </a>';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   153
      echo '</div>';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   154
    }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   155
    echo '</div>';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   156
    echo '<span class="menuclear"></span>';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   157
  }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   158
}
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   159
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   160
function ajaxServlet_Admin_ThemeManager(&$themes)
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   161
{
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   162
  global $db, $session, $paths, $template, $plugins; // Common objects
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   163
  global $lang;
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   164
  if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   165
  {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   166
    $login_link = makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   167
    echo '<h3>' . $lang->get('adm_err_not_auth_title') . '</h3>';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   168
    echo '<p>' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '</p>';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   169
    return;
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   170
  }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   171
  
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   172
  if ( !isset($_POST['r']) )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   173
    return false;
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   174
  
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   175
  try
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   176
  {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   177
    $request = enano_json_decode($_POST['r']);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   178
  }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   179
  catch ( Exception $e )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   180
  {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   181
    die('Exception in JSON parser, probably invalid input.');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   182
  }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   183
  
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   184
  if ( !isset($request['mode']) )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   185
  {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   186
    die('No mode specified in JSON request.');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   187
  }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   188
  
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   189
  switch ( $request['mode'] )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   190
  {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   191
    case 'fetch_theme':
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   192
      $theme_id = $db->escape($request['theme_id']);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   193
      if ( empty($theme_id) )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   194
        die('Invalid theme_id');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   195
      
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   196
      $q = $db->sql_query("SELECT theme_id, theme_name, default_style, enabled, group_policy, group_list FROM " . table_prefix . "themes WHERE theme_id = '$theme_id';");
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   197
      if ( !$q )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   198
        $db->die_json();
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   199
      
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   200
      if ( $db->numrows() < 1 )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   201
        die('BUG: no theme with that theme_id installed.');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   202
      
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   203
      $row = $db->fetchrow();
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   204
      $row['enabled'] = ( $row['enabled'] == 1 );
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   205
      $row['css'] = @$themes[$theme_id]['css'];
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   206
      $row['default_style'] = preg_replace('/\.css$/', '', $row['default_style']);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   207
      $row['is_default'] = ( getConfig('theme_default') === $theme_id );
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   208
      $row['group_list'] = ( empty($row['group_list']) ) ? array() : enano_json_decode($row['group_list']);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   209
      
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   210
      // Build a list of group names
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   211
      $row['group_names'] = array();
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   212
      foreach ( $row['group_list'] as $group_id )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   213
      {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   214
        $row['group_names'][$group_id] = '';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   215
      }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   216
      if ( count($row['group_names']) > 0 )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   217
      {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   218
        $idlist = 'group_id = ' . implode(' OR group_id = ', array_keys($row['group_names']));
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   219
        $q = $db->sql_query('SELECT group_id, group_name FROM ' . table_prefix . "groups WHERE $idlist;");
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   220
        if ( !$q )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   221
          $db->die_json();
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   222
        while ( $gr = $db->fetchrow_num() )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   223
        {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   224
          list($group_id, $group_name) = $gr;
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   225
          $row['group_names'][$group_id] = $group_name;
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   226
        }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   227
      }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   228
      
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   229
      echo enano_json_encode($row);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   230
      break;
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   231
  }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   232
}
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   233
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   234
function page_Admin_ThemeManagerOld() 
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   235
{
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   236
  global $db, $session, $paths, $template, $plugins; // Common objects
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   237
  global $lang;
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   238
  if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   239
  {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   240
    $login_link = makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   241
    echo '<h3>' . $lang->get('adm_err_not_auth_title') . '</h3>';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   242
    echo '<p>' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '</p>';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   243
    return;
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   244
  }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   245
  
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   246
  
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   247
  // Get the list of styles in the themes/ dir
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   248
  $h = opendir('./themes');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   249
  $l = Array();
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   250
  if(!$h) die('Error opening directory "./themes" for reading.');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   251
  while(false !== ($n = readdir($h))) {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   252
    if($n != '.' && $n != '..' && is_dir('./themes/'.$n))
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   253
      $l[] = $n;
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   254
  }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   255
  closedir($h);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   256
  echo('
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   257
  <h3>Theme Management</h3>
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   258
   <p>Install, uninstall, and manage Enano themes.</p>
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   259
  ');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   260
  if(isset($_POST['disenable'])) {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   261
    $q = 'SELECT enabled FROM '.table_prefix.'themes WHERE theme_id=\'' . $db->escape($_POST['theme_id']) . '\'';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   262
    $s = $db->sql_query($q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   263
    if(!$s) die('Error selecting enabled/disabled state value: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   264
    $r = $db->fetchrow_num($s);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   265
    $db->free_result();
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   266
    if($r[0] == 1) $e = 0;
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   267
    else $e = 1;
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   268
    $s=true;
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   269
    if($e==0)
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   270
    {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   271
      $c = $db->sql_query('SELECT * FROM '.table_prefix.'themes WHERE enabled=1');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   272
      if(!$c) $db->_die('The backup check for having at least on theme enabled failed.');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   273
      if($db->numrows() <= 1) { echo '<div class="warning-box">You cannot disable the last remaining theme.</div>'; $s=false; }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   274
    }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   275
    $db->free_result();
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   276
    if($s) {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   277
    $q = 'UPDATE '.table_prefix.'themes SET enabled='.$e.' WHERE theme_id=\'' . $db->escape($_POST['theme_id']) . '\'';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   278
    $a = $db->sql_query($q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   279
    if(!$a) die('Error updating enabled/disabled state value: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   280
    else echo('<div class="info-box">The theme "'.$_POST['theme_id'].'" has been  '. ( ( $e == '1' ) ? 'enabled' : 'disabled' ).'.</div>');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   281
    }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   282
  }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   283
  elseif(isset($_POST['edit'])) {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   284
    
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   285
    $dir = './themes/'.$_POST['theme_id'].'/css/';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   286
    $list = Array();
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   287
    // Open a known directory, and proceed to read its contents
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   288
    if (is_dir($dir)) {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   289
      if ($dh = opendir($dir)) {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   290
        while (($file = readdir($dh)) !== false) {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   291
          if(preg_match('#^(.*?)\.css$#is', $file) && $file != '_printable.css') {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   292
            $list[$file] = capitalize_first_letter(substr($file, 0, strlen($file)-4));
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   293
          }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   294
        }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   295
        closedir($dh);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   296
      }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   297
    }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   298
    $lk = array_keys($list);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   299
    
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   300
    $q = 'SELECT theme_name,default_style FROM '.table_prefix.'themes WHERE theme_id=\''.$db->escape($_POST['theme_id']).'\'';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   301
    $s = $db->sql_query($q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   302
    if(!$s) die('Error selecting name value: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   303
    $r = $db->fetchrow_num($s);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   304
    $db->free_result();
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   305
    acp_start_form();
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   306
    echo('<div class="question-box">
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   307
          Theme name displayed to users: <input type="text" name="name" value="'.$r[0].'" /><br /><br />
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   308
          Default stylesheet: <select name="defaultcss">');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   309
    foreach ($lk as $l)
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   310
    {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   311
      if($r[1] == $l) $v = ' selected="selected"';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   312
      else $v = '';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   313
      echo "<option value='{$l}'$v>{$list[$l]}</option>";
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   314
    }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   315
    echo('</select><br /><br />
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   316
          <input type="submit" name="editsave" value="OK" /><input type="hidden" name="theme_id" value="'.$_POST['theme_id'].'" />
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   317
          </div>');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   318
    echo('</form>');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   319
  }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   320
  elseif(isset($_POST['editsave'])) {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   321
    $q = 'UPDATE '.table_prefix.'themes SET theme_name=\'' . $db->escape($_POST['name']) . '\',default_style=\''.$db->escape($_POST['defaultcss']).'\' WHERE theme_id=\'' . $db->escape($_POST['theme_id']) . '\'';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   322
    $s = $db->sql_query($q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   323
    if(!$s) die('Error updating name value: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   324
    else echo('<div class="info-box">Theme data updated.</div>');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   325
  }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   326
  elseif(isset($_POST['up'])) {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   327
    // If there is only one theme or if the selected theme is already at the top, do nothing
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   328
    $q = 'SELECT theme_order FROM '.table_prefix.'themes ORDER BY theme_order;';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   329
    $s = $db->sql_query($q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   330
    if(!$s) die('Error selecting order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   331
    $q = 'SELECT theme_order FROM '.table_prefix.'themes WHERE theme_id=\''.$db->escape($_POST['theme_id']).'\'';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   332
    $sn = $db->sql_query($q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   333
    if(!$sn) die('Error selecting order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   334
    $r = $db->fetchrow_num($sn);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   335
    if( /* check for only one theme... */ $db->numrows($s) < 2 || $r[0] == 1 /* ...and check if this theme is already at the top */ ) { echo('<div class="warning-box">This theme is already at the top of the list, or there is only one theme installed.</div>'); } else {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   336
      // Get the order IDs of the selected theme and the theme before it
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   337
      $q = 'SELECT theme_order FROM '.table_prefix.'themes WHERE theme_id=\'' . $db->escape($_POST['theme_id']) . '\'';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   338
      $s = $db->sql_query($q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   339
      if(!$s) die('Error selecting order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   340
      $r = $db->fetchrow_num($s);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   341
      $r = $r[0];
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   342
      $rb = $r - 1;
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   343
      // Thank God for jEdit's rectangular selection and the ablity to edit multiple lines at the same time ;)
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   344
      $q = 'UPDATE '.table_prefix.'themes SET theme_order=0 WHERE theme_order='.$rb.'';      /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   345
      $q = 'UPDATE '.table_prefix.'themes SET theme_order='.$rb.' WHERE theme_order='.$r.''; /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   346
      $q = 'UPDATE '.table_prefix.'themes SET theme_order='.$r.' WHERE theme_order=0';       /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   347
      echo('<div class="info-box">Theme moved up.</div>');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   348
    }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   349
    $db->free_result($s);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   350
    $db->free_result($sn);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   351
  }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   352
  elseif(isset($_POST['down'])) {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   353
    // If there is only one theme or if the selected theme is already at the top, do nothing
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   354
    $q = 'SELECT theme_order FROM '.table_prefix.'themes ORDER BY theme_order;';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   355
    $s = $db->sql_query($q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   356
    if(!$s) die('Error selecting order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   357
    $r = $db->fetchrow_num($s);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   358
    if( /* check for only one theme... */ $db->numrows($s) < 2 || $r[0] == $db->numrows($s) /* ...and check if this theme is already at the bottom */ ) { echo('<div class="warning-box">This theme is already at the bottom of the list, or there is only one theme installed.</div>'); } else {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   359
      // Get the order IDs of the selected theme and the theme before it
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   360
      $q = 'SELECT theme_order FROM '.table_prefix.'themes WHERE theme_id=\''.$db->escape($_POST['theme_id']).'\'';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   361
      $s = $db->sql_query($q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   362
      if(!$s) die('Error selecting order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   363
      $r = $db->fetchrow_num($s);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   364
      $r = $r[0];
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   365
      $rb = $r + 1;
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   366
      // Thank God for jEdit's rectangular selection and the ablity to edit multiple lines at the same time ;)
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   367
      $q = 'UPDATE '.table_prefix.'themes SET theme_order=0 WHERE theme_order='.$rb.'';      /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   368
      $q = 'UPDATE '.table_prefix.'themes SET theme_order='.$rb.' WHERE theme_order='.$r.''; /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   369
      $q = 'UPDATE '.table_prefix.'themes SET theme_order='.$r.' WHERE theme_order=0';       /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   370
      echo('<div class="info-box">Theme moved down.</div>');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   371
    }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   372
  }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   373
  else if(isset($_POST['uninstall'])) 
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   374
  {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   375
    $q = 'SELECT * FROM '.table_prefix.'themes;';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   376
    $s = $db->sql_query($q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   377
    if ( !$s )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   378
    {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   379
      die('Error getting theme count: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   380
    }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   381
    $n = $db->numrows($s);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   382
    $db->free_result();
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   383
    
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   384
    if ( $_POST['theme_id'] == 'oxygen' )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   385
    {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   386
      echo '<div class="error-box">The Oxygen theme is used by Enano for installation, upgrades, and error messages, and cannot be uninstalled.</div>';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   387
    }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   388
    else
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   389
    {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   390
      if($n < 2)
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   391
      {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   392
        echo '<div class="error-box">The theme could not be uninstalled because it is the only theme left.</div>';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   393
      }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   394
      else
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   395
      {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   396
        $q = 'DELETE FROM '.table_prefix.'themes WHERE theme_id=\''.$db->escape($_POST['theme_id']).'\' LIMIT 1;';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   397
        $s = $db->sql_query($q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   398
        if ( !$s )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   399
        {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   400
          die('Error deleting theme data: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   401
        }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   402
        else
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   403
        {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   404
          echo('<div class="info-box">Theme uninstalled.</div>');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   405
        }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   406
      }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   407
    }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   408
  }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   409
  elseif(isset($_POST['install'])) {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   410
    $q = 'SELECT theme_id FROM '.table_prefix.'themes;';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   411
    $s = $db->sql_query($q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   412
    if(!$s) die('Error getting theme count: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   413
    $n = $db->numrows($s);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   414
    $n++;
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   415
    $theme_id = $_POST['theme_id'];
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   416
    $theme = Array();
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   417
    include('./themes/'.$theme_id.'/theme.cfg');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   418
    if ( !isset($theme['theme_id']) )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   419
    {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   420
      echo '<div class="error-box">Could not load theme.cfg (theme metadata file)</div>';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   421
    }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   422
    else
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   423
    {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   424
      $default_style = false;
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   425
      if ( $dh = opendir('./themes/' . $theme_id . '/css') )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   426
      {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   427
        while ( $file = readdir($dh) )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   428
        {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   429
          if ( $file != '_printable.css' && preg_match('/\.css$/i', $file) )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   430
          {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   431
            $default_style = $file;
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   432
            break;
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   433
          }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   434
        }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   435
        closedir($dh);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   436
      }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   437
      else
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   438
      {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   439
        die('The /css subdirectory could not be located in the theme\'s directory');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   440
      }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   441
      
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   442
      if ( $default_style )
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   443
      {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   444
        $q = 'INSERT INTO '.table_prefix.'themes(theme_id,theme_name,theme_order,enabled,default_style) VALUES(\''.$db->escape($theme['theme_id']).'\', \''.$db->escape($theme['theme_name']).'\', '.$n.', 1, \'' . $db->escape($default_style) . '\')';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   445
        $s = $db->sql_query($q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   446
        if(!$s) die('Error inserting theme data: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   447
        else echo('<div class="info-box">Theme "'.$theme['theme_name'].'" installed.</div>');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   448
      }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   449
      else
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   450
      {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   451
        echo '<div class="error-box">Could not determine the default style for the theme.</div>';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   452
      }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   453
    }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   454
  }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   455
  echo('
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   456
  <h3>Currently installed themes</h3>
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   457
    <form action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post">
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   458
    <p>
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   459
      <select name="theme_id">
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   460
        ');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   461
        $q = 'SELECT theme_id,theme_name,enabled FROM '.table_prefix.'themes ORDER BY theme_order';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   462
        $s = $db->sql_query($q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   463
        if(!$s) die('Error selecting theme data: '.$db->get_error().'<br /><u>Attempted SQL:</u><br />'.$q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   464
        while ( $r = $db->fetchrow_num($s) ) {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   465
          if($r[2] < 1) $r[1] .= ' (disabled)';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   466
          echo('<option value="'.$r[0].'">'.$r[1].'</option>');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   467
        }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   468
        $db->free_result();
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   469
        echo('
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   470
        </select> <input type="submit" name="disenable" value="Enable/Disable" /> <input type="submit" name="edit" value="Change settings" /> <input type="submit" name="up" value="Move up" /> <input type="submit" name="down" value="Move down" /> <input type="submit" name="uninstall" value="Uninstall" style="color: #DD3300; font-weight: bold;" />
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   471
      </p>
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   472
    </form>
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   473
    <h3>Install a new theme</h3>
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   474
  ');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   475
    $theme = Array();
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   476
    $obb = '';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   477
    for($i=0;$i<sizeof($l);$i++) {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   478
      if(is_file('./themes/'.$l[$i].'/theme.cfg') && file_exists('./themes/'.$l[$i].'/theme.cfg')) {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   479
        include('./themes/'.$l[$i].'/theme.cfg');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   480
        $q = 'SELECT * FROM '.table_prefix.'themes WHERE theme_id=\''.$theme['theme_id'].'\'';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   481
        $s = $db->sql_query($q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   482
        if(!$s) die('Error selecting list of currently installed themes: '.$db->get_error().'<br /><u>Attempted SQL:</u><br />'.$q);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   483
        if($db->numrows($s) < 1) {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   484
          $obb .= '<option value="'.$theme['theme_id'].'">'.$theme['theme_name'].'</option>';
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   485
        }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   486
        $db->free_result();
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   487
      }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   488
    }
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   489
    if($obb != '') {
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   490
      echo('<form action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post"><p>');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   491
      echo('<select name="theme_id">');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   492
      echo($obb);
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   493
      echo('</select>');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   494
      echo('
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   495
      <input type="submit" name="install" value="Install this theme" />
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   496
      </p></form>');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   497
    } else echo('<p>All themes are currently installed.</p>');
c892b2013d3e Can't believe I forgot to add ThemeManager.php.
Dan
parents:
diff changeset
   498
}