Improved userlist.php from O(n^2) to O(n)
[specialops2.git] / theme.php
blob992e6837a55e5bb54e6fc17f094543edf0e2ac0c
1 <?php
2 // $Id$
4 require 'con.php';
5 $page->title = _('Theme Settings');
7 if ( ! ($user instanceof authuser) ) {
8 $page->errorfooter('login');
11 if ( isset($_POST['submit']) ) {
13 switch ( $_POST['themetype'] ) {
14 case 'premade' :
15 $user->u_theme = intval($_POST['premade_theme']);
16 if ( isset($_POST['importpre']) ) {
17 list($file) = $DB->query('SELECT `st_file` FROM `styles` WHERE `stid` = '.intval($_POST['premade_theme']))->fetch_row();
18 file_put_contents('css/u'.$user->userid.'.css', file_get_contents('css/'.$file));
20 break;
22 case 'import' :
23 if ( file_exists('css/u'.intval($_POST['user_import']).'.css') )
24 file_put_contents('css/u'.$user->userid.'.css', file_get_contents('css/u'.intval($_POST['user_import']).'.css'));
25 $user->u_theme = 0;
26 break;
28 case 'custom' :
29 $user->u_theme = 0;
30 file_put_contents('css/u'.$user->userid.'.css', $_POST['user_css']);
33 $page->pageheader();
34 echo '<div class="notice">',_('Settings have been saved.'),'</div>';
37 $user->userheader();
39 //These are only used 2 times so it's not worth making a function to do it
40 $q = $DB->query('SELECT `stid`, `st_name` FROM `styles` ORDER BY `st_name` ASC');
41 $pre_selectbox = '<select name="premade_theme">'."\n";
42 while ($row = $q->fetch_row())
43 $pre_selectbox .= '<option value="'.$row[0].'"'.( $user->u_theme == $row[0] ? ' selected="selected"' : '' ).'>'.$row[1]."</option>\n";
44 $pre_selectbox .= '</select>';
46 $q = $DB->query('SELECT `userid`, `u_name` FROM `users` WHERE `u_theme` = 0 ORDER BY `u_name` ASC');
47 $import_selectbox = '<select name="user_import">'."\n";
48 while ($row = $q->fetch_row())
49 $import_selectbox .= '<option value="'.$row[0].'">'.$row[1]."</option>\n";
50 $import_selectbox .= '</select>';
53 if ( file_exists('css/u'.$user->userid.'.css') )
54 $css_textbox = file_get_contents('css/u'.$user->userid.'.css');
55 else
56 $css_textbox = '';
58 echo '<form id="themeprefs" method="post" action="',$_SERVER['PHP_SELF'],'">
59 <fieldset class="content">
60 <ul class="formlist">
61 <li class="c0">
62 <input type="radio" id="premade" name="themetype" value="premade"',( $user->u_theme > 0 ? ' checked="checked"' : '' ),'/>
63 <label for="premade">',_('Use a premade theme:'),'</label>
64 '.$pre_selectbox.'<br/>
65 <input type="checkbox" id="importpre" name="importpre"/>
66 <label for="importpre">',_('Set this as your custom theme (will overwrite anything currently there)'),'</label>
67 </li>
68 <li class="c1">
69 <input type="radio" id="import" name="themetype" value="import"/>
70 <label for="import">',_('Import a custom theme from a user:'),'</label>
71 '.$import_selectbox.'
72 </li>
73 <li class="c0">
74 <input type="radio" id="custom" name="themetype" value="custom"',( $user->u_theme == 0 ? ' checked="checked"' : '' ),'/>
75 <label for="custom">',_('Use your own CSS:'),'</label>
76 <textarea rows="15" cols="80" name="user_css" id="user_css">'.$css_textbox.'</textarea>
77 </li>
78 </ul>
80 <button type="submit" name="submit" value="save" accesskey="s">',_('Save Settings'),' (S)</button>
81 </fieldset>
82 </form>';
84 $page->pagefooter();