aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/SwiftThemeCreator/theme_creator.php
blob: 9d70286401a3155d738751e8cbb9694eb3a34ff4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
<?php
// +-----------------------------------------------------------------------+
// | Piwigo - a PHP based picture gallery                                  |
// +-----------------------------------------------------------------------+
// | Copyright(C) 2008      Piwigo Team                  http://piwigo.org |
// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
// +-----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify  |
// | it under the terms of the GNU General Public License as published by  |
// | the Free Software Foundation                                          |
// |                                                                       |
// | This program is distributed in the hope that it will be useful, but   |
// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
// | General Public License for more details.                              |
// |                                                                       |
// | You should have received a copy of the GNU General Public License     |
// | along with this program; if not, write to the Free Software           |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA.                                                                  |
// +-----------------------------------------------------------------------+

/* TODO: Revoir le lien du menu de l'admin */
if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
if (!defined('IN_ADMIN') or !IN_ADMIN) die('Hacking attempt!');
define('STC_PATH', PHPWG_PLUGINS_PATH.'SwiftThemeCreator/');
define('STC_INTERNAL_VERSION', '1.40'); 
/*
 * stc_hex2rgb convert any string to array of RGB values
 */
function stc_hex2rgb($color)
{
  if ($color[0] == '#') $color = substr($color, 1);
  if (strlen($color) == 6)
    list($r, $g, $b) = array($color[0].$color[1],
                             $color[2].$color[3],
                             $color[4].$color[5]);
  else {
    $color .= $color . $color . '000';
    list($r, $g, $b) = array($color[0].$color[0],
                             $color[1].$color[1], 
                             $color[2].$color[2]);
  }
  return array(hexdec($r), hexdec($g), hexdec($b));
}
/*
 * lighten returns array of x% of lighter RGB values
 */
function lighten( $r, $g, $b, $percent)
{
  $r = min(round($r+(($percent*(255-$r))/100)),255);
  $g = min(round($g+(($percent*(255-$g))/100)),255);
  $b = min(round($b+(($percent*(255-$b))/100)),255);
  return sprintf('#%02X%02X%02X', $r, $g, $b);
}
/*
 * darken returns array of x% of darker RGB values
 */
function darken( $r, $g, $b, $percent)
{
  $r = max(round($r-(($percent*$r)/100)),0);
  $g = max(round($g-(($percent*$g)/100)),0);
  $b = max(round($b-(($percent*$b)/100)),0);
  return sprintf('#%02X%02X%02X', $r, $g, $b);
}
/*
 * stc_newfile create a new file
 */
function stc_newfile( $filename, $data )
{
  $fp = @fopen($filename, 'w');
  if ($fp) {
    $ret = fwrite($fp, $data); 
    @fclose($fp);
    return $ret;
  }
  return false;
}
/*
 * Default values 
 */
function init_main(&$main)
{
  global $available_templates;
  $main = array(
    STC_INTERNAL_VERSION => true, /* $main version */
    'template_sel' => 0, 
    'newtpl' => 'yoga',
    'newtheme' => '',
    'simulate' => true,
    'colorize' => false,
    'brightness' => false,
    'contrast' => false,
    'new_theme' => '',
    'color1' => '#111111',
    'color' => array('#111111', '#EEEEEE', '#FF7700', '#FF3333', '#FF3363', ),
    'templatedir' => PHPWG_ROOT_PATH . 'plugins/SwiftThemeCreator/simul',
    'color1' => '#111111',
    'color2' => '#EEEEEE',
    'color3' => '#FF7700',
    'color4' => '#FF3333',
    'color5' => '#FF3363',
    'background' => 'fixed',
    'picture_url' => PHPWG_ROOT_PATH . 'plugins/SwiftThemeCreator/sample.jpg',
    'picture_width' => 2048,
    'picture_height' => 100,
    'background_mode' => 'as',
    'src_category' => 0,
    'category' => 'header',
    'phase' => 'Kernel init',
    'subphase' => 'New version',
  );    
} 

$errors = array();
$infos = array();

// +-----------------------------------------------------------------------+
// |                            Kernel init                                |
// +-----------------------------------------------------------------------+
if (!isset($swift_theme_creator)) $swift_theme_creator = new ThemeCreator();
$swift_theme_creator->reload();
$main = $swift_theme_creator->theme_config;

/* 
 * Find templates
 */
$available_templates = array();
$template_dir = PHPWG_ROOT_PATH.'template';
foreach (get_dirs($template_dir) as $dir)
{ array_push($available_templates, $dir);
}
/* 
 * $main is reloaded but does template still exist?
 * Does the fixed background still exist? Category? ...
 */
if (!isset($main[STC_INTERNAL_VERSION])) init_main($main);
$flip = array_flip($available_templates);
$main['template_sel'] = (isset($flip[$main['newtpl']])) ?
    $flip[$main['newtpl']] : 0; /* Deleted ? First available */
$main['subphase'] = 'Find category';
$query = 'SELECT id,name,uppercats,global_rank
  FROM ' . CATEGORIES_TABLE . ';';
display_select_cat_wrapper($query,array(),'src_category');
$available_cat = $template->get_template_vars('src_category');
$flip = array_flip($available_cat);
$main['src_category'] = (isset($flip[$main['category']])) ?
    $flip[$main['category']] : max($flip); /* Deleted ? Most recent */

    
// +-----------------------------------------------------------------------+
// |                            $_POST controls                            |
// +-----------------------------------------------------------------------+
$main['phase'] = 'POST controls';
if (!isset($_POST['reset']))
{
  $main['simulate'] = isset($_POST['simulate']);
  if (!isset($_POST['submit'])) $main['simulate'] = true;
  /* 
   * Template controls
   */
  $main['subphase'] = 'template controls';
  if (isset($_POST['template'])) $main['template_sel'] = $_POST['template'];
  $main['newtpl'] = $available_templates[$main['template_sel']];
  if ($main['newtpl'] != 'yoga')
    array_push($infos, l10n('Unpredictable results could be observed with ' 
        . 'this template. Preview is based on yoga template only.')); 

  /* 
   * Theme controls
   */
  $main['subphase'] = 'theme controls';
  if (isset($_POST['new_theme'])) $main['newtheme'] = strip_tags($_POST['new_theme']);
  if ($main['newtheme'] == '') $main['simulate'] = true; /* Empty = Simulate */
  $cleaning = true; /* Delete files on failure */
  if ( !$main['simulate'] and !preg_match('/^[a-z0-9-_]{1,8}$/', $main['newtheme']) )
    array_push($errors, l10n('Invalid theme name: 1 to 8 lowercase'
      . ' alphanumeric characters including "-" and "_".')); 
  if ($main['simulate']) { /* $main['templatedir'] != $template_dir (Smarty) */
    $main['templatedir'] = PHPWG_ROOT_PATH . 'plugins/SwiftThemeCreator/simul';
    $themedir = $main['templatedir'];
    $cleaning = false; /* No delete with simulate */ 
  } else { 
    $main['templatedir'] = PHPWG_ROOT_PATH . 'template/' . $main['newtpl']; 
    $themedir = $main['templatedir'] . '/theme/' . $main['newtheme'];
  }

  /* 
   * Directories controls
   */
  $main['subphase'] = 'directories controls';
  if (is_dir( $themedir ) and !$main['simulate']) {
    array_push($errors, '['.$themedir.'] : '.l10n('Invalid theme: This' 
         . ' theme exists already (no override available).')); 
    $cleaning = false; /* No delete on existing theme */
  } elseif ( !is_writable($main['templatedir']) )
    array_push($errors, '['.$main['templatedir'].'] : '.l10n('no_write_access'));

  /* 
   * Colors controls
   */
  $main['subphase'] = 'colors controls';
  if (isset($_POST['color1'])) 
    $main['color'] = array(
      $_POST['color1'], $_POST['color2'], $_POST['color3'], $_POST['color4'], 
      $_POST['color5']);
  $main['color1'] = $main['color'][0];
  $main['color2'] = $main['color'][1];
  $main['color3'] = $main['color'][2];
  $main['color4'] = $main['color'][3];
  $main['color5'] = $main['color'][4];
  $colors = $main['color1'] . $main['color2']
          . $main['color3'] . $main['color4'] . $main['color5'];
  if ( !preg_match('/^(#?([A-Fa-f0-9]{3}|[A-Fa-f0-9]{6})){5}$/', $colors) ) 
    array_push($errors, l10n('Invalid color code: 3 or 6 hexadecimal characters,' 
          . ' preceded or not by "#"')); 
  
  /* 
   * Background and text difference control
   */
  $main['subphase'] = 'text difference controls';
  list($r,$g,$b) = stc_hex2rgb($main['color'][0]);
  list($r2,$g2,$b2) = stc_hex2rgb($main['color'][1]);
  $dif = abs( ( (($r*299)+($g*587)+($b*114)) / 1000 )
          - ( (( $r2*299)+($g2*587)+($b2*114)) / 1000 ) );
  if ( $dif < 65 )
    array_push($errors, l10n('Insufficient brightness difference between ' 
          . 'text and background. dif=') . $dif); 
  $dif = (max($r, $r2) - min($r, $r2)) 
     + (max($g, $g2) - min($g, $g2)) + (max($b, $b2) - min($b, $b2));
  if ( $dif < 200 )
    array_push($errors, l10n('Insufficient colour difference between ' 
          . 'text and background. dif=') . $dif); 

  /* 
   * Background and Internal links difference control
   */
  $main['subphase'] = 'links difference controls';
  if (false)
  {
    list($r,$g,$b) = stc_hex2rgb($main['color'][0]);
    list($r2,$g2,$b2) = stc_hex2rgb($main['color'][2]);
    $dif = abs( ( (($r*299)+($g*587)+($b*114)) / 1000 )
            - ( (($r2*299)+($g2*587)+($b2*114)) / 1000 ));
    if ( $dif < 65 )
      array_push($errors, l10n('Insufficient brightness difference between ' 
            . 'Internal links and background. dif=') . $dif); 
    $dif = (max($r, $r2) - min($r, $r2)) 
       + (max($g, $g2) - min($g, $g2)) + (max($b, $b2) - min($b, $b2));
    if ( $dif < 200 )
      array_push($errors, l10n('Insufficient colour difference between ' 
            . 'Internal links and background. dif=') . $dif); 
  }

  /* 
   * Header background controls
   */
  $main['subphase'] = 'fixed background controls'; 
  if (isset($_POST['picture_url'])) $main['picture_url'] = $_POST['picture_url'];
  if (isset($_POST['background_mode'])) 
      $main['background_mode'] = $_POST['background_mode'];  
  if (isset($_POST['background'])) $main['background'] = $_POST['background'];
  // Fixed
  if ( $main['background'] == 'fixed') {
    if ( is_dir($main['picture_url'])
        or !is_file($main['picture_url']) )
      array_push($errors, l10n('Header picture is not found, check its path and name.')); 
    $extension = substr($main['picture_url'],strrpos($main['picture_url'],'.')+1);
    if (!in_array($extension, array('jpg','jpeg','png')))
      array_push($errors, l10n('Compliant extensions are .jpg, .jpeg or .png.')); 
  }
  $main['subphase'] = 'random background controls';
  if (isset($_POST['src_category'])) 
    $main['src_category'] = (int) $_POST['src_category'];
  $main['category'] = $available_cat[$main['src_category']];

  /*
   * Width and Height limits control
   */
  $main['subphase'] = 'width and height controls'; 
  if ($main['background'] != 'off' 
    and isset($_POST['picture_width'])
    and isset($_POST['picture_height']))
  { 
    if( !(ctype_digit($_POST['picture_width']) 
      and $_POST['picture_width'] > 11 
      and $_POST['picture_width'] < 4097 ) )
      array_push($errors, '['.$_POST['picture_width'].'] : ' 
            . l10n('incorrect width value [12-4096].')); 
    else $main['picture_width'] = $_POST['picture_width'];
    if ( !(ctype_digit($_POST['picture_height'])
      and $_POST['picture_height'] > 11 
      and $_POST['picture_height'] < 201 ) )
      array_push($errors, '['.$_POST['picture_height'].'] : '
            . l10n('incorrect width value [12-200].')); 
    else $main['picture_height'] = $_POST['picture_height'];
  }     

  /*
   * Generate missing colors values
   */
  $main['subphase'] = 'complementary colors';
  list($r,$g,$b) = stc_hex2rgb($main['color'][0]);
  if ((( (($r+1)/256)*(($g+1)/256)*(($b+1)/256) ) * 1000 ) < 125 )
       $main['color6'] = lighten( $r, $g, $b, 10);
  else $main['color6'] = darken( $r, $g, $b, 10);
  list($r,$g,$b) = stc_hex2rgb($main['color'][4]);
  if ((( (($r+1)/256)*(($g+1)/256)*(($b+1)/256) ) * 1000 ) < 125 )
       $main['color7'] = lighten( $r, $g, $b, 10);
  else $main['color7'] = darken( $r, $g, $b, 10);
  $main['colorize'] = isset($_POST['colorize']) ? true : false;
  $main['brightness'] = isset($_POST['brightness']) ? true : false;
  $main['contrast'] = isset($_POST['contrast']) ? true : false;
}

// +-----------------------------------------------------------------------+
// |                            Build files                                |
// +-----------------------------------------------------------------------+
$main['phase'] = 'Files building';
if (!function_exists('imagecreatetruecolor') or !function_exists('imagefilter')) {
  array_push($errors, l10n('Some Php Graphic resources are missing.' 
        . ' Sorry for the inconvenience, but Swift Theme Creator couldn\'t work in such case.')); 
  array_push($infos, l10n('This plugin requires PHP 5.2.5 or later' 
        . ' and compiled against graphic library GD 2.0.1 or later.'));
  array_push($infos, l10n('On this server, PHP is:'). phpversion());
  if (function_exists('gd_info')) {
    $GD = gd_info();            
    array_push($infos, l10n('and graphic library is:').$GD['GD Version']);
  }
  else array_push($infos, l10n('graphic library version is not available.'));
  $main['background'] = 'off';
}
if ((isset($_POST['submit']) or $main['simulate'] ) and (!is_adviser()))
{
  /*
   * Go ahead
   */
  $main['subphase'] = 'Mkdir control';
  if (count($errors) == 0) {
    umask(0000);
    @mkdir($themedir, 0705);
    if (!is_dir(  $themedir ))
        array_push($errors,
          l10n('Theme directory creation failure: ' 
          . 'it can\'t be created (for now en attendant la suite 8-) ).'));
    else {
      $main['ldelim'] = '{ldelim}';
      /*
       * Build themeconf.inc.php
       **/
      $main['subphase'] = 'Build themeconf';
      $plugin_tpl = new Template();
      $plugin_tpl->set_filenames(array('themeconf'=>
      STC_PATH . 'themeconf.inc.tpl'));
      $plugin_tpl->assign('main',$main);
      $main['themeconf_inc_php'] = $plugin_tpl->parse('themeconf', true);
      $rfs = stc_newfile( $themedir . '/themeconf.inc.php', 
        $main['themeconf_inc_php'] );
      /*
       * Build mail-css.tpl
       **/  
      $main['subphase'] = 'Build mail-css';
      $plugin_tpl->set_filenames(array('mailcss'=>
      STC_PATH . 'mail-css.tpl2'));
      $plugin_tpl->assign('main',$main);
      $main['mail-css.tpl'] = $plugin_tpl->parse('mailcss', true);  
      $rfs = $rfs && stc_newfile( $themedir . '/mail-css.tpl', 
        $main['mail-css.tpl'] );
      /*
       * Build theme.css
       **/
      $main['subphase'] = 'Build theme';
      $plugin_tpl->set_filenames(array('theme'=> STC_PATH . 'theme.tpl'));
      $plugin_tpl->assign('main',$main);
      $main['theme.css'] = $plugin_tpl->parse('theme', true);  
      $rfs = $rfs && stc_newfile( $themedir . '/theme.css', $main['theme.css'] );
      $internal = stc_hex2rgb($main['color'][2]);
      list($r,$g,$b) = $internal;
      $background = stc_hex2rgb($main['color'][0]);
      list($r2,$g2,$b2) = $background;
      $delta = floor(((array_sum($internal)/3) - (array_sum($background)/3))/5.1);
      /* Brightness is half of difference between colors of internal lnks and bkground */
      /* but if color range is 0-255, resulting brightness range is between -50 and 50 */
      if ($delta > 0) { /* Colorize need a darker color on a dark background */
         $r = floor($r / 5);
         $g = floor($g / 5);
         $b = floor($b / 5);
      }
      if (isset($_POST['background']) and $_POST['background'] == 'random')
      {
        $main['subphase'] = 'Pick random for a pic';
        $main['random'] = mt_rand(12, 4096);
        $result = pwg_query('
        SELECT i.path
          FROM '.CATEGORIES_TABLE.' c, 
               '.IMAGES_TABLE.' i, 
               '.IMAGE_CATEGORY_TABLE.' ic
         WHERE c.status=\'public\'
           AND c.id = ic.category_id
           AND c.id = ' . $main['src_category'] . '
           AND ic.category_id = ' . $main['src_category'] . '
           AND ic.image_id = i.id
         ORDER BY RAND(' . $main['random'] . ')
         LIMIT 0,1');
        if($result) list($main['pic_path']) = mysql_fetch_array($result);
        else $main['pic_path'] = 
             PHPWG_ROOT_PATH . 'plugins/SwiftThemeCreator/simul/header.jpg';
        $main['pic_ext'] = substr($main['pic_path'],strrpos($main['pic_path'],'.')+1);
        if ($main['pic_ext']=='png')
          $img = imagecreatefrompng($main['pic_path']);
        elseif (in_array($main['pic_ext'],array('jpg','jpeg'))) 
                $img = imagecreatefromjpeg($main['pic_path']);
        else $img = imagecreatefromjpeg(PHPWG_ROOT_PATH 
                     . 'plugins/SwiftThemeCreator/simul/header.jpg');
        imagejpeg( $img, $themedir . '/header.jpg', 90 );
        imagedestroy ($img);
      }
      if (isset($_POST['background']) and $_POST['background'] == 'fixed')
      {
        $main['subphase'] = 'Fixed background';
        $hdr = imagecreatetruecolor ($main['picture_width'], $main['picture_height']);
        imagecolorset ( $hdr, 0, $r2, $g2, $b2 );
        if ($extension == 'png') $img = imagecreatefrompng($main['picture_url']);
        else $img = imagecreatefromjpeg($main['picture_url']);
        imagecopymerge ( $hdr, $img, 0, 0, 0, 0, $main['picture_width'], $main['picture_height'], 60 );
        imagedestroy ($img);
        if ($main['colorize']) imagefilter($hdr, IMG_FILTER_COLORIZE, $r, $g, $b);
        if ($main['brightness']) imagefilter($hdr, IMG_FILTER_BRIGHTNESS, $delta);
        if ($main['contrast']) imagefilter($hdr, IMG_FILTER_CONTRAST, 20);
        imagejpeg( $hdr, $themedir . '/header.jpg', 90 );
          imagedestroy ($hdr);
      }
      /*
       * Build background image for titrePage or definition list (in #menubar)
       **/
      $main['subphase'] = 'Headbars background'; 
      $hdr = imagecreatetruecolor (1, 38);
      imagecolorset ( $hdr, 0, $r2, $g2, $b2 );
      $img = imagecreatefrompng(STC_PATH . '/titrePage-bg.png');
      imagecopymerge ( $hdr, $img, 0, 0, 0, 0, 1, 38, 60 );
      imagedestroy ($img);
      if ($main['colorize']) imagefilter($hdr, IMG_FILTER_COLORIZE, $r, $g, $b);
      if ($main['brightness']) imagefilter($hdr, IMG_FILTER_BRIGHTNESS, $delta);
      if ($main['contrast']) imagefilter($hdr, IMG_FILTER_CONTRAST, 20);
      imagepng( $hdr, $themedir . '/stc.png', 9 );
      imagedestroy ($hdr);

      /*
       * Errors and cleaning or Congratulations
       **/
      $main['phase'] = 'Congratulation';
      $main['subphase'] = 'cleaning';
      if ($rfs == false) {
        array_push($errors,
          l10n('Theme files creation failure: theme should be deleted.'));
        if ($cleaning) {
          @unlink( $themedir . '/header.jpg' );
          @unlink( $themedir . '/stc.png' );
          @unlink( $themedir . '/themeconf.inc.php' );
          @unlink( $themedir . '/mail-css.tpl' );
          @unlink( $themedir . '/theme.css' );
          @rmdir( $themedir );
        }
      }
      elseif (!$main['simulate']) {
        array_push($infos,
       '['.$main['newtpl'] . '/' . $main['newtheme'].'] : '
       .l10n('Congratulation! You have got(/ten) a new available theme.')); 
        @copy( $themedir . '/header.jpg', PHPWG_ROOT_PATH . 'plugins/SwiftThemeCreator/simul/header.jpg');
        @copy( $themedir . '/stc.png', PHPWG_ROOT_PATH . 'plugins/SwiftThemeCreator/simul/stc.png');
        @copy( $themedir . '/themeconf.inc.php', PHPWG_ROOT_PATH . 'plugins/SwiftThemeCreator/simul/themeconf.inc.php');
        @copy( $themedir . '/mail-css.tpl', PHPWG_ROOT_PATH . 'plugins/SwiftThemeCreator/simul/mail-css.tpl');
        @copy( $themedir . '/theme.css', PHPWG_ROOT_PATH . 'plugins/SwiftThemeCreator/simul/theme.css');
      }
    }
  }

  // TODO       ********   theSwiftHeader itself   *********
  
  $swift_theme_creator->save_theme_config();  
}

// +-----------------------------------------------------------------------+
// |                            reset values
// +-----------------------------------------------------------------------+
if (isset($_POST['reset']) and (!is_adviser())) {
  $main = array();
  init_main($main);
  $swift_theme_creator->theme_config = $main;
  $swift_theme_creator->save_theme_config();  
  redirect( get_admin_plugin_menu_link(dirname(__FILE__).'/theme_creator.php'));
}

// Don't forget to re-read because some statements are superfluous
 
// +-----------------------------------------------------------------------+
// |                            template initialization
// +-----------------------------------------------------------------------+
$template->set_filenames(array(
    'plugin_admin_content' => dirname(__FILE__) . '/theme_creator.tpl'));
$template->append('head_elements',
   '<script type="text/javascript" 
        src="./plugins/SwiftThemeCreator/farbtastic/farbtastic.js"></script>
<link rel="stylesheet" type="text/css"
      href="./plugins/SwiftThemeCreator/farbtastic/farbtastic.css" />
<style type="text/css" media="screen">
.colorwell { border: 3px double #F30; width: 6em; 
  text-align: center; cursor: pointer; }
body .colorwell-selected { border: 3px double #F36; font-weight: bold; }
.radio { margin: 0 10px 0 50px; }
</style>'
    );
$template->assign('radio_options',
 array(
  'true' => l10n('Yes'),
  'false' => l10n('No')));
$template->assign('template_options', $available_templates);
$template->assign('background_options',
  array(
    'off' => l10n('No'),
    'random' => l10n('24H Random'),
    'fixed' => l10n('Fixed URL'),
  ));
$template->assign('background_mode_options',
  array(
    'as' => l10n('As is'),
    'crop' => l10n('Truncated'),
    'sized' => l10n('Resized'),
  ));
if (count($errors) != 0) $template->assign('errors', $errors);
if (count($infos) != 0) $template->assign('infos', $infos);
/* Restore Main values */
$template->assign('main', $main);
$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
$swift_theme_creator->theme_config = $main;
$swift_theme_creator->save_theme_config();
?>