Reduced the gfh2 background image contrast a bit since it was hard to read text with it.
[specialops2.git] / theme.php
blob0e90d9b87bc7d71e9c613c2795728f12c3a8b109
1 <?php
2 // $Id$
4 require 'con.php';
5 $page->title = 'Theme Settings';
7 if ( ! ($user instanceof authuser) )
8 $page->errorfooter('login');
10 $premade_themes = new form_select('premade_theme', 2, $user->theme);
11 $user_themes = new form_select('user_theme', 2);
13 $premade_themes->db_fill($DB->query('SELECT `themeid`, `theme_name` FROM `themes` ORDER BY `theme_name` ASC', MYSQLI_USE_RESULT));
14 $user_themes->db_fill($DB->query('SELECT `userid`, `alias` FROM `users` WHERE `theme` = 0 ORDER BY `alias` ASC', MYSQLI_USE_RESULT));
16 if ( isset($_POST['submit']) ) {
17 try {
18 switch ( $_POST['themetype'] ) {
19 case 'premade':
20 $premade_themes->check_value($_POST['premade_theme']);
21 $premade_themes->default = $user->theme = intval($_POST['premade_theme']);
23 if ( isset($_POST['importpre']) ) {
24 list($f) = $DB->query('SELECT `css_file` FROM `themes`
25 WHERE `themeid` = '.intval($_POST['premade_theme']))->fetch_row();
26 file_put_contents('css/u'.$user->userid.'.css',
27 file_get_contents('css/'.$f.'.css'));
29 break;
31 case 'import':
32 $user_themes->check_value($_POST['user_theme']);
33 file_put_contents('css/u'.$user->userid.'.css',
34 file_get_contents('css/u'.intval($_POST['user_theme']).'.css'));
35 $user->theme = 0;
36 break;
38 case 'custom':
39 $user->theme = 0;
40 file_put_contents('css/u'.$user->userid.'.css',
41 str_replace("\r\n", "\n", $_POST['user_css']));
44 $user->userheader();
45 echo '<p class="notice">Settings have been saved.</p>';
46 } catch ( Exception $e ) {
47 $user->userheader();
48 echo '<p class="error">',$e->getMessage(),'</p>';
50 } else
51 $user->userheader();
53 if ( file_exists('css/u'.$user->userid.'.css') )
54 $css_textbox = htmlspecialchars(file_get_contents('css/u'.$user->userid.'.css'));
55 else
56 $css_textbox = '';
59 <form id="theme" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
60 <fieldset class="content">
61 <legend><label><input type="radio" name="themetype" value="premade"<?php
62 echo $user->theme > 0 ? ' checked="checked"' : '' ?>/> Premade Theme</label></legend>
63 <p><label>Select theme: <?php echo $premade_themes->display() ?></label></p>
64 <p><label><input type="checkbox" name="importpre"/> Set your custom theme to this</label></p>
65 </fieldset>
66 <fieldset class="content">
67 <legend><label><input type="radio" name="themetype" value="import"/> Import from user</label></legend>
68 <p><label>User name: <?php echo $user_themes->display() ?></label></p>
69 </fieldset>
70 <fieldset class="content">
71 <legend><label><input type="radio" name="themetype" value="custom"<?php
72 echo $user->theme == 0 ? ' checked="checked"' : '' ?>/> Custom CSS</label></legend>
73 <textarea rows="20" cols="60" name="user_css" id="user_css"><?php echo $css_textbox ?></textarea>
74 </fieldset>
76 <button type="submit" name="submit" value="save" accesskey="s">Save Settings (S)</button>
77 </form>
79 <?php
80 $page->pagefooter();