No sense in forcing small fonts on people.
[specialops2.git] / theme.php
blobdf11223cf7eab261176547d0d6f8106280ce1f04
1 <?php
2 // $Id$
4 require 'con.php';
5 $page->title = 'Theme Settings';
7 if ( ! ($user instanceof authuser) ) {
8 $page->errorfooter('login');
11 $premade_themes = new form_select('premade_theme', 2, $user->theme);
12 $user_themes = new form_select('user_theme', 2);
14 $premade_themes->db_fill($DB->query('SELECT `themeid`, `theme_name` FROM `themes` ORDER BY `theme_name` ASC',
15 MYSQLI_USE_RESULT));
16 $user_themes->db_fill($DB->query('SELECT `userid`, `alias` FROM `users` WHERE `theme` = 0 ORDER BY `alias` ASC',
17 MYSQLI_USE_RESULT));
19 if ( isset($_POST['submit']) ) {
20 try {
21 switch ( $_POST['themetype'] ) {
22 case 'premade':
23 $premade_themes->check_value($_POST['premade_theme']);
24 $premade_themes->default = $user->theme = intval($_POST['premade_theme']);
26 if ( isset($_POST['importpre']) ) {
27 list($f) = $DB->query('SELECT `css_file` FROM `themes`
28 WHERE `themeid` = '.intval($_POST['premade_theme']))->fetch_row();
29 file_put_contents('css/u'.$user->userid.'.css',
30 file_get_contents('css/'.$f));
32 break;
34 case 'import':
35 $user_themes->check_value($_POST['user_theme']);
36 file_put_contents('css/u'.$user->userid.'.css',
37 file_get_contents('css/u'.intval($_POST['user_theme']).'.css'));
38 $user->theme = 0;
39 break;
41 case 'custom':
42 $user->theme = 0;
43 file_put_contents('css/u'.$user->userid.'.css',
44 $_POST['user_css']);
47 $user->userheader();
48 echo '<p class="notice">Settings have been saved.</p>';
49 } catch ( Exception $e ) {
50 $user->userheader();
51 echo '<p class="error">',$e->getMessage(),'</p>';
53 } else
54 $user->userheader();
56 if ( file_exists('css/u'.$user->userid.'.css') )
57 $css_textbox = htmlspecialchars(file_get_contents('css/u'.$user->userid.'.css'));
58 else
59 $css_textbox = '';
61 $a = 1;
63 echo
64 '<form method="post" action="',$_SERVER['PHP_SELF'],'">
65 <table id="theme">
66 <thead>
67 <tr>
68 <th scope="col">Theme Type</th>
69 <th scope="col">Detailed Settings</th>
70 </tr>
71 </thead>
73 <tbody>
74 <tr class="content c',(++$a&1),'">
75 <td><label><input type="radio" name="themetype" value="premade"',
76 ( $user->theme > 0 ? ' checked="checked"' : '' ),'/> Premade</label></td>
77 <td><label>Select theme: ',$premade_themes->display(),
78 ' </label><br/>
79 <label><input type="checkbox" name="importpre"/> Set your custom theme to this</label></td>
80 </tr>
81 <tr class="content c',(++$a&1),'">
82 <td><label><input type="radio" name="themetype" value="import"/> Import user theme</label></td>
83 <td><label>User name: ',$user_themes->display(),
84 ' </label></td>
85 </tr>
86 <tr class="content c',(++$a&1),'">
87 <td><label><input type="radio" name="themetype" value="custom"',
88 ( $user->theme == 0 ? ' checked="checked"' : '' ),'/> Custom CSS</label></td>
89 <td><label>CSS:<br/><textarea rows="20" cols="60" name="user_css">',$css_textbox,'</textarea></label></td>
90 </tr>
91 </tbody>
92 </table>
94 <button type="submit" name="submit" value="save" accesskey="s">Save Settings (S)</button>
95 </form>';
97 $page->pagefooter();