Optimised a bunch of code, removed circular references
[specialops2.git] / theme.php
blobb38d758f3c5ba1b2c0093314e4972b7150bc2359
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 $tmp = $DB->query('SELECT `themeid`, `theme_name` FROM `themes` ORDER BY `theme_name` ASC');
13 while ( $row = $tmp->fetch_row() )
14 $premade_themes->add_item($row[0], $row[1]);
16 $user_themes = new form_select('user_theme', 2);
17 $tmp = $DB->query('SELECT `userid`, `alias` FROM `users` WHERE `theme` = 0 ORDER BY `alias` ASC');
18 while ( $row = $tmp->fetch_row() )
19 $user_themes->add_item($row[0], $row[1]);
21 if ( isset($_POST['submit']) ) {
22 try {
23 switch ( $_POST['themetype'] ) {
24 case 'premade' :
25 $premade_themes->check_value($_POST['premade_theme']);
26 $premade_themes->default = $user->theme = intval($_POST['premade_theme']);
28 if ( isset($_POST['importpre']) ) {
29 list($f) = $DB->query('SELECT `css_file` FROM `themes`
30 WHERE `themeid` = '.intval($_POST['premade_theme']))->fetch_row();
31 file_put_contents('css/u'.$user->userid.'.css', file_get_contents('css/'.$f));
33 break;
35 case 'import' :
36 $user_themes->check_value($_POST['user_theme']);
37 file_put_contents('css/u'.$user->userid.'.css', 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', $_POST['user_css']);
46 $user->userheader();
47 echo '<div class="notice">',_('Settings have been saved.'),'</div>';
48 } catch ( Exception $e ) {
49 $user->userheader();
50 echo '<div class="error">',$e->getMessage(),'</div>';
52 } else
53 $user->userheader();
55 if ( file_exists('css/u'.$user->userid.'.css') )
56 $css_textbox = file_get_contents('css/u'.$user->userid.'.css');
57 else
58 $css_textbox = '';
60 $a = 1;
62 echo '<form method="post" action="',$_SERVER['PHP_SELF'],'">
63 <table id="theme">
64 <thead>
65 <tr>
66 <th scope="col">',_('Theme Type'),'</th>
67 <th scope="col">',_('Detailed Settings'),'</th>
68 </tr>
69 </thead>
71 <tbody>
72 <tr class="content c',(++$a&1),'">
73 <td><label><input type="radio" name="themetype" value="premade"',( $user->theme > 0 ? ' checked="checked"' : '' ),'/> ',_('Premade'),'</label></td>
74 <td><label>',_('Select theme: '),$premade_themes->display(),
75 ' </label><br/>
76 <label><input type="checkbox" name="importpre"/> ',_('Set this as your custom theme (will overwrite anything currently there)'),'</label></td>
77 </tr>
78 <tr class="content c',(++$a&1),'">
79 <td><label><input type="radio" name="themetype" value="import"/> ',_('Import user theme'),'</label></td>
80 <td><label>',_('User name: '),$user_themes->display(),
81 ' </label></td>
82 </tr>
83 <tr class="content c',(++$a&1),'">
84 <td><label><input type="radio" name="themetype" value="custom"',( $user->theme == 0 ? ' checked="checked"' : '' ),'/> ',_('Custom CSS'),'</label></td>
85 <td><label>CSS:<br/><textarea rows="20" cols="60" name="user_css" id="user_css">',$css_textbox,'</textarea></label></td>
86 </tr>
87 </tbody>
88 </table>
90 <button type="submit" name="submit" value="save" accesskey="s">',_('Save Settings'),' (S)</button>
91 </form>';
93 $page->pagefooter();