3 /***************************************************************************
6 * copyright : (C) 2003, 2004 CyberAlien
7 * support : http://www.phpbbstyles.com
12 * project revision : 51
13 * last modified : 25 Aug 2004 11:51:47
15 ***************************************************************************/
17 /***************************************************************************
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
24 ***************************************************************************/
26 define('IN_PHPBB', 1);
27 $phpbb_root_path = "./../";
28 $no_page_header = true;
29 require($phpbb_root_path . 'extension.inc');
30 require('./pagestart.' . $phpEx);
32 // check if mod is installed
33 if(empty($template->xs_version) || $template->xs_version !== 5)
35 message_die(GENERAL_ERROR, 'eXtreme Styles mod is not installed. You forgot to upload includes/template.php');
38 define('IN_XS', true);
39 include_once('xs_include.' . $phpEx);
41 $template->assign_block_vars('nav_left',array('ITEM' => '» <a href="' . append_sid('xs_styles.'.$phpEx) . '">' . $lang['xs_default_style'] . '</a>'));
44 // set new default style
46 if(!empty($HTTP_GET_VARS['setdefault']) && !defined('DEMO_MODE'))
48 $board_config['default_style'] = intval($HTTP_GET_VARS['setdefault']);
49 $sql = "UPDATE " . CONFIG_TABLE . " SET config_value='" . $board_config['default_style'] . "' WHERE config_name='default_style'";
50 if(defined('XS_MODS_ADMIN_TEMPLATES'))
52 $sql = str_replace(' WHERE config_name', ', theme_public=\'1\' WHERE config_name', $sql);
58 // change "override" variable
60 if(isset($HTTP_GET_VARS['setoverride']) && !defined('DEMO_MODE'))
62 $board_config['override_user_style'] = intval($HTTP_GET_VARS['setoverride']);
63 $sql = "UPDATE " . CONFIG_TABLE . " SET config_value='" . $board_config['override_user_style'] . "' WHERE config_name='override_user_style'";
68 // move all users to some style
70 if(!empty($HTTP_GET_VARS['moveusers']) && !defined('DEMO_MODE'))
72 $id = intval($HTTP_GET_VARS['moveusers']);
73 $sql = "UPDATE " . USERS_TABLE . " SET user_style='" . $id . "' WHERE user_id > 0";
78 // move all users from some style
80 if(!empty($HTTP_GET_VARS['moveaway']) && !defined('DEMO_MODE'))
82 $id = intval($HTTP_GET_VARS['moveaway']);
83 $id2 = intval($HTTP_GET_VARS['movestyle']);
86 $sql = "UPDATE " . USERS_TABLE . " SET user_style='" . $id2 . "' WHERE user_style = " . $id;
90 $sql = "UPDATE " . USERS_TABLE . " SET user_style = NULL WHERE user_style = " . $id;
96 // set admin-only style (Admin Templates mod)
98 if(!empty($HTTP_GET_VARS['setadmin']) && !defined('DEMO_MODE'))
100 $id = intval($HTTP_GET_VARS['setadmin']);
101 $setadmin = empty($HTTP_GET_VARS['admin']) ? 0 : 1;
102 $sql = "UPDATE " . THEMES_TABLE . " SET theme_public='{$setadmin}' WHERE themes_id='{$id}'";
103 $db->sql_query($sql);
107 // get list of installed styles
109 $sql = 'SELECT themes_id, template_name, style_name FROM ' . THEMES_TABLE . ' ORDER BY template_name';
110 if(defined('XS_MODS_ADMIN_TEMPLATES'))
112 $sql = str_replace(', style_name', ', style_name, theme_public', $sql);
114 if(!$result = $db->sql_query($sql))
116 xs_error($lang['xs_no_style_info'], __LINE__, __FILE__);
118 $style_rowset = $db->sql_fetchrowset($result);
120 $style_override = $board_config['override_user_style'];
121 $style_default = $board_config['default_style'];
123 $style_ids = array();
125 for($i=0; $i<count($style_rowset); $i++)
127 $id = $style_rowset[$i]['themes_id'];
129 $sql = 'SELECT count(user_id) as total FROM ' . USERS_TABLE . ' WHERE user_style = ' . $id;
130 $result = $db->sql_query($sql);
137 $total = $db->sql_fetchrow($result);
138 $total = $total['total'];
139 $num_users += $total;
142 $row_class = $xs_row_class[$i % 2];
143 $template->assign_block_vars('styles', array(
144 'ROW_CLASS' => $row_class,
145 'STYLE' => $style_rowset[$i]['style_name'],
146 'TEMPLATE' => $style_rowset[$i]['template_name'],
149 'U_TOTAL' => append_sid('xs_styles.' . $phpEx . '?list=' . $id),
150 'U_DEFAULT' => append_sid('xs_styles.' . $phpEx . '?setdefault=' . $id),
151 'U_OVERRIDE' => append_sid('xs_styles.' . $phpEx . '?setoverride=' . ($style_override ? '0' : '1')),
152 'U_SWITCHALL' => append_sid('xs_styles.' . $phpEx . '?moveusers=' . $id),
157 $template->assign_block_vars('styles.users', array());
159 if($id == $style_default)
161 $template->assign_block_vars('styles.default', array());
164 $template->assign_block_vars('styles.default.override', array());
168 $template->assign_block_vars('styles.default.nooverride', array());
173 $template->assign_block_vars('styles.nodefault', array());
174 if(defined('XS_MODS_ADMIN_TEMPLATES'))
176 if($style_rowset[$i]['theme_public'])
178 $template->assign_block_vars('styles.nodefault.admin_only', array(
179 'U_CHANGE' => append_sid('xs_styles.'.$phpEx.'?setadmin='.$id.'&admin=0')
184 $template->assign_block_vars('styles.nodefault.public', array(
185 'U_CHANGE' => append_sid('xs_styles.'.$phpEx.'?setadmin='.$id.'&admin=1')
192 $template->assign_block_vars('styles.total', array());
196 $template->assign_block_vars('styles.none', array());
200 // get number of users using default style
201 $sql = 'SELECT count(user_id) as total FROM ' . USERS_TABLE . ' WHERE user_style = NULL';
202 $result = $db->sql_query($sql);
205 $total = $db->sql_fetchrow($result);
206 $num_default = $total['total'];
207 $num_users += $num_default;
210 // get number of users
211 $sql = 'SELECT count(user_id) as total FROM ' . USERS_TABLE;
212 $result = $db->sql_query($sql);
219 $total = $db->sql_fetchrow($result);
220 $total_users = $total['total'];
223 $template->assign_vars(array(
224 'U_SCRIPT' => 'xs_styles.' . $phpEx,
225 'NUM_DEFAULT' => $num_default
229 if($total_users > $num_users)
232 $sql = 'UPDATE ' . USERS_TABLE . ' SET user_style = NULL WHERE user_style NOT IN (' . implode(', ', $style_ids) . ')';
233 $db->sql_query($sql);
239 if(isset($HTTP_GET_VARS['list']))
241 $id = intval($HTTP_GET_VARS['list']);
242 $template->assign_block_vars('list_users', array());
243 $sql = "SELECT user_id, username FROM " . USERS_TABLE . " WHERE user_style='{$id}' ORDER BY username ASC";
244 if(!$result = $db->sql_query($sql))
246 xs_error('Could not get users list!', __LINE__, __FILE__);
248 $rowset = $db->sql_fetchrowset($result);
249 for($i=0; $i<count($rowset); $i++)
251 $template->assign_block_vars('list_users.user', array(
253 'ID' => $rowset[$i]['user_id'],
254 'NAME' => htmlspecialchars($rowset[$i]['username']),
260 $template->set_filenames(array('body' => XS_TPL_PATH . 'styles.tpl'));
261 $template->pparse('body');