Example #1
0
function admincp_master()
{
    global $X7CHATVERSION, $x7p, $x7s, $print, $db, $txt, $x7c, $prefix, $X7CHAT_CONFIG, $g_default_settings;
    $head = $txt[37];
    $body = "<h2 style=\"text-align: center;\">Pannello di amministrazione</h2>";
    // Set these so it doesn't complain, all admins have access to these pages
    $x7c->permissions["admin_main"] = 1;
    $x7c->permissions["admin_news"] = 1;
    $x7c->permissions["admin_help"] = 1;
    // Look for the CP page we are on, if not set then make it main
    if (!isset($_GET['cp_page'])) {
        $_GET['cp_page'] = "main";
    }
    // Check permissions
    $check_page = $_GET['cp_page'];
    if ($check_page == "groupmanager") {
        $check_page = "groups";
    }
    if ($x7c->permissions["admin_{$check_page}"] == 0) {
        $_GET['cp_page'] = "ad2";
    }
    if ($x7c->permissions['admin_access'] == 0) {
        $_GET['cp_page'] = "ad";
    }
    // Figure out which page this is
    if ($_GET['cp_page'] == "settings") {
        $head = $txt[139];
        if (isset($_GET['update_settings'])) {
            // Update the settings for some section
            $txt[343] = eregi_replace("<a>", "<a href=\"./index.php?act=adminpanel&cp_page=settings\">", $txt[343]);
            if ($_GET['settings_page'] == "general") {
                // Update the settings page for the general settings
                // Check for unset values (this is a bug in some browers)
                if (!isset($_POST['disable_chat'])) {
                    $_POST['disable_chat'] = 0;
                }
                if (!isset($_POST['allow_reg'])) {
                    $_POST['allow_reg'] = 0;
                }
                if (!isset($_POST['allow_guests'])) {
                    $_POST['allow_guests'] = 0;
                }
                if (!isset($_POST['disable_sounds'])) {
                    $_POST['disable_sounds'] = 0;
                }
                if (!isset($_POST['log_bandwidth'])) {
                    $_POST['log_bandwidth'] = 0;
                }
                if (!isset($_POST['req_activation'])) {
                    $_POST['req_activation'] = 0;
                }
                // Preparse these to cuz we need to convert seconds to miliseconds
                $_POST['min_refresh'] = $_POST['min_refresh'] * 1000;
                $_POST['max_refresh'] = $_POST['max_refresh'] * 1000;
                // Check for problems with the submitted data
                if ($_POST['min_refresh'] > $_POST['max_refresh']) {
                    $error = $txt[344];
                }
                if (!isset($error)) {
                    // Do the actual updates right now, when I say now I mean NOW
                    // Yes this section wrecks hell on your MySql server but hopefully you don't need to update your settings to often
                    update_setting("disable_chat", $_POST['disable_chat']);
                    update_setting("allow_reg", $_POST['allow_reg']);
                    update_setting("allow_guests", $_POST['allow_guests']);
                    update_setting("disable_sounds", $_POST['disable_sounds']);
                    update_setting("site_name", $_POST['site_name']);
                    update_setting("admin_email", $_POST['admin_email']);
                    update_setting("logout_page", $_POST['logout_page']);
                    update_setting("default_lang", $_POST['default_lang']);
                    update_setting("default_skin", $_POST['default_skin']);
                    update_setting("maxchars_status", $_POST['maxchars_status']);
                    update_setting("maxchars_msg", $_POST['maxchars_msg']);
                    update_setting("max_offline_msgs", $_POST['max_offline_msgs']);
                    update_setting("min_refresh", $_POST['min_refresh']);
                    update_setting("max_refresh", $_POST['max_refresh']);
                    update_setting("cookie_time", $_POST['cookie_time']);
                    update_setting("log_bandwidth", $_POST['log_bandwidth']);
                    update_setting("maxchars_username", $_POST['maxchars_username']);
                    update_setting("banner_link", $_POST['banner_link']);
                    update_setting("single_room_mode", $_POST['single_room_mode']);
                    update_setting("req_activation", $_POST['req_activation']);
                    // Check activation stuff
                    if ($_POST['req_activation'] == 0) {
                        // Update existing accounts so they do not require activation
                        $db->doQuery("UPDATE {$prefix}users SET activated='1'");
                    }
                    $body = $txt[343];
                } else {
                    $body = $error . "<Br><Br><div align=\"center\"><a href=\"javascript: history.back()\">{$txt['77']}</a></div>";
                }
            } elseif ($_GET['settings_page'] == "logs") {
                // Convert these values from Kilobytes to bytes
                $_POST['max_log_user'] *= 1024;
                $_POST['max_log_room'] *= 1024;
                if (!isset($_POST['enable_logging'])) {
                    $_POST['enable_logging'] = 0;
                }
                // Update the settings
                update_setting("max_log_user", $_POST['max_log_user']);
                update_setting("max_log_room", $_POST['max_log_room']);
                update_setting("logs_path", $_POST['logs_path']);
                update_setting("enable_logging", $_POST['enable_logging']);
                $body = $txt[343];
            } elseif ($_GET['settings_page'] == "user_agreement") {
                // Update the user agreement
                $_POST['user_agreement'] = eregi_replace("\n", "<Br>", $_POST['user_agreement']);
                $_POST['user_agreement'] = eregi_replace("&lt;", "<", $_POST['user_agreement']);
                $_POST['user_agreement'] = eregi_replace("&gt;", ">", $_POST['user_agreement']);
                $_POST['user_agreement'] = eregi_replace("&quot;", "\"", $_POST['user_agreement']);
                update_setting("user_agreement", $_POST['user_agreement']);
                $body = $txt[343];
            } elseif ($_GET['settings_page'] == "timedate") {
                // Update the settings
                update_setting("date_format", $_POST['date_format']);
                update_setting("date_format_full", $_POST['date_format_full']);
                update_setting("date_format_date", $_POST['date_format_date']);
                update_setting("time_offset_hours", $_POST['time_offset_hours']);
                update_setting("time_offset_mins", $_POST['time_offset_mins']);
                $body = $txt[343];
            } elseif ($_GET['settings_page'] == "exptime") {
                // Pre-parse, convert these times from hours to seconds
                $_POST['expire_messages'] = round($_POST['expire_messages'] * 60, 0);
                $_POST['expire_rooms'] = round($_POST['expire_rooms'] * 60, 0);
                $_POST['expire_guests'] = round($_POST['expire_guests'] * 60, 0);
                if ($_POST['online_time'] <= 0) {
                    $_POST['online_time'] = 30;
                }
                update_setting("online_time", $_POST['online_time']);
                update_setting("expire_messages", $_POST['expire_messages']);
                update_setting("expire_rooms", $_POST['expire_rooms']);
                update_setting("expire_guests", $_POST['expire_guests']);
                $body = $txt[343];
            } elseif ($_GET['settings_page'] == "styles") {
                // uncheck these checkboxs if not checked
                if (!isset($_POST['enable_roombgs'])) {
                    $_POST['enable_roombgs'] = 0;
                }
                if (!isset($_POST['enable_roomlogo'])) {
                    $_POST['enable_roomlogo'] = 0;
                }
                if (!isset($_POST['disable_smiles'])) {
                    $_POST['disable_smiles'] = 0;
                }
                if (!isset($_POST['disable_styles'])) {
                    $_POST['disable_styles'] = 0;
                }
                if (!isset($_POST['disable_autolinking'])) {
                    $_POST['disable_autolinking'] = 0;
                }
                // parse comma spaces
                $_POST['style_allowed_fonts'] = eregi_replace(" ,", ",", $_POST['style_allowed_fonts']);
                $_POST['style_allowed_fonts'] = eregi_replace(", ", ",", $_POST['style_allowed_fonts']);
                // Update the styles section
                update_setting("banner_url", $_POST['banner_url']);
                update_setting("background_image", $_POST['background_image']);
                update_setting("enable_roombgs", $_POST['enable_roombgs']);
                update_setting("enable_roomlogo", $_POST['enable_roomlogo']);
                update_setting("default_font", $_POST['default_font']);
                update_setting("default_color", $_POST['default_color']);
                update_setting("default_size", $_POST['default_size']);
                update_setting("style_min_size", $_POST['style_min_size']);
                update_setting("style_max_size", $_POST['style_max_size']);
                update_setting("disable_smiles", $_POST['disable_smiles']);
                update_setting("disable_styles", $_POST['disable_styles']);
                update_setting("disable_autolinking", $_POST['disable_autolinking']);
                update_setting("system_message_color", $_POST['system_message_color']);
                update_setting("style_allowed_fonts", $_POST['style_allowed_fonts']);
                $body = $txt[343];
            } elseif ($_GET['settings_page'] == "avatars") {
                // Convert from kilobytes to bytes
                $_POST['avatar_max_size'] *= 1024;
                // Check for unchecked checkboxes
                if (!isset($_POST['enable_avatar_uploads'])) {
                    $_POST['enable_avatar_uploads'] = 0;
                }
                if (!isset($_POST['resize_smaller_avatars'])) {
                    $_POST['resize_smaller_avatars'] = 0;
                }
                update_setting("enable_avatar_uploads", $_POST['enable_avatar_uploads']);
                update_setting("resize_smaller_avatars", $_POST['resize_smaller_avatars']);
                update_setting("avatar_max_size", $_POST['avatar_max_size']);
                update_setting("avatar_size_px", $_POST['avatar_size_px']);
                update_setting("uploads_path", $_POST['uploads_path']);
                update_setting("uploads_url", $_POST['uploads_url']);
                $body = $txt[343];
            } elseif ($_GET['settings_page'] == "loginpage") {
                // Check Check boxes
                if (!isset($_POST['enable_passreminder'])) {
                    $_POST['enable_passreminder'] = 0;
                }
                // Adjust this wierd little setting again
                // Update settings
                update_setting("news", $_POST['news']);
                update_setting("floating_text", $_POST['floating_text']);
                $body = $txt[343];
            } elseif ($_GET['settings_page'] == "advanced") {
                if (!isset($_POST['disable_gd'])) {
                    $_POST['disable_gd'] = 0;
                }
                update_setting("disable_gd", $_POST['disable_gd']);
                $body = $txt[343];
            } elseif ($_GET['settings_page'] == "support") {
                // Clean up the values a little
                $_POST['support_personel'] = eregi_replace("; ", ";", $_POST['support_personel']);
                $_POST['support_personel'] = eregi_replace(" ;", ";", $_POST['support_personel']);
                update_setting("support_personel", $_POST['support_personel']);
                update_setting("support_image_online", $_POST['support_image_online']);
                update_setting("support_image_offline", $_POST['support_image_offline']);
                update_setting("support_message", $_POST['support_message']);
                $body = $txt[343];
            }
        } elseif (isset($_GET['settings_page'])) {
            // Display the settings form
            // Get default values for settings
            // The reason we have to do this here is because values for this admin and the system default may be different
            $query = $db->DoQuery("SELECT * FROM {$prefix}settings");
            while ($row = $db->Do_Fetch_Row($query)) {
                $def_settings[$row[1]] = $row[2];
            }
            if ($_GET['settings_page'] == "general") {
                // Get the default values for check boxes
                $checkboxs[] = "disable_chat";
                $checkboxs[] = "allow_reg";
                $checkboxs[] = "allow_guests";
                $checkboxs[] = "disable_sounds";
                $checkboxs[] = "log_bandwidth";
                foreach ($checkboxs as $key => $val) {
                    if ($def_settings[$val] == 1) {
                        $def[$val] = " CHECKED=\"true\"";
                    } else {
                        $def[$val] = "";
                    }
                }
                // Get defaults for lang and skin
                $lng_dir = dir("./lang");
                $skin_dir = dir("./themes");
                $def['default_lang'] = "";
                $def['default_skin'] = "";
                while ($option = $lng_dir->read()) {
                    if ($option != "." && $option != ".." && $option != "index.html") {
                        $option = eregi_replace("\\.php", "", $option);
                        if ($option == $def_settings['default_lang']) {
                            $slcted = " SELECTED=\"true\"";
                        } else {
                            $slcted = "";
                        }
                        $def['default_lang'] .= "<option value=\"{$option}\"{$slcted}>{$option}</option>";
                    }
                }
                while ($option = $skin_dir->read()) {
                    if ($option != "." && $option != ".." && @is_file("./themes/{$option}/theme.info")) {
                        if ($option == $def_settings['default_skin']) {
                            $slcted = " SELECTED=\"true\"";
                        } else {
                            $slcted = "";
                        }
                        include "./themes/{$option}/theme.info";
                        $def['default_skin'] .= "<option value=\"{$option}\"{$slcted}>{$name}</option>";
                    }
                }
                if ($def_settings['single_room_mode'] == "") {
                    $def['single_room_mode'] = "<option value=\"\" SELECTED>{$txt['591']}</option>";
                } else {
                    $def['single_room_mode'] = "<option value=\"\">{$txt['591']}</option>";
                }
                $query = $db->DoQuery("SELECT * FROM {$prefix}rooms");
                while ($row = $db->Do_Fetch_Row($query)) {
                    if ($def_settings['single_room_mode'] == $row[1]) {
                        $def['single_room_mode'] .= "<option value=\"{$row['1']}\" SELECTED>{$row['1']}</option>";
                    } else {
                        $def['single_room_mode'] .= "<option value=\"{$row['1']}\">{$row['1']}</option>";
                    }
                }
                // Default values for these two fields since we need to convert milisconds to seconds
                $def['min_refresh'] = $def_settings['min_refresh'] / 1000;
                $def['max_refresh'] = $def_settings['max_refresh'] / 1000;
                if ($def_settings['req_activation'] == 1) {
                    $def['req_activation'] = " checked=\"true\"";
                } else {
                    $def['req_activation'] = "";
                }
                $body = "<Br>\n\t\t\t\t\t<form action=\"./index.php?act=adminpanel&cp_page=settings&settings_page=general&update_settings=1\" method=\"POST\">\n\t\t\t\t\t<table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\">\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['329']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"checkbox\" name=\"disable_chat\"{$def['disable_chat']} value=\"1\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['330']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"checkbox\" name=\"allow_reg\"{$def['allow_reg']} value=\"1\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['331']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"checkbox\" name=\"allow_guests\"{$def['allow_guests']} value=\"1\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['468']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"checkbox\" name=\"log_bandwidth\"{$def['log_bandwidth']} value=\"1\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['207']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"checkbox\" name=\"disable_sounds\"{$def['disable_sounds']} value=\"1\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['332']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"site_name\" value=\"{$def_settings['site_name']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['333']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"admin_email\" value=\"{$def_settings['admin_email']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['334']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"logout_page\" value=\"{$def_settings['logout_page']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['335']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"maxchars_status\" value=\"{$def_settings['maxchars_status']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['551']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"banner_link\" value=\"{$def_settings['banner_link']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['515']}*: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"maxchars_username\" value=\"{$def_settings['maxchars_username']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['336']}*: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"maxchars_msg\" value=\"{$def_settings['maxchars_msg']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['337']}*: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"max_offline_msgs\" value=\"{$def_settings['max_offline_msgs']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['338']}* ({$txt['351']}): </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"min_refresh\" value=\"{$def['min_refresh']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['339']}* ({$txt['351']}): </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"max_refresh\" value=\"{$def['max_refresh']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['341']}: </td>\n\t\t\t\t\t<td width=\"100\">\n\t\t\t\t\t<select name=\"default_lang\" class=\"text_input\">\n\t\t\t\t\t{$def['default_lang']}\n\t\t\t\t\t</select>\n\t\t\t\t\t</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['342']}: </td>\n\t\t\t\t\t<td width=\"100\">\n\t\t\t\t\t<select name=\"default_skin\" class=\"text_input\">\n\t\t\t\t\t{$def['default_skin']}\n\t\t\t\t\t</select>\n\t\t\t\t\t</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['357']} ({$txt['351']}): </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"cookie_time\" value=\"{$def_settings['cookie_time']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['590']}<b>**</b>: </td>\n\t\t\t\t\t<td width=\"100\"><select class=\"text_input\" name=\"single_room_mode\">{$def['single_room_mode']}</select></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['616']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"checkbox\" class=\"text_input\" value=\"1\" name=\"req_activation\"{$def['req_activation']}></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"200\" colspan=\"2\"><div align=\"center\"><input type=\"submit\" class=\"button\" value=\"{$txt['187']}\"></div></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"200\" colspan=\"2\"><b>* {$txt['340']}</b><Br><Br><b>** {$txt['593']}</b></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t\t</form>";
            } elseif ($_GET['settings_page'] == "user_agreement") {
                // The user agreement page
                $agreement = eregi_replace("<br>", "\n", $x7c->settings['user_agreement']);
                $body = "<Br><div align=\"center\">{$txt['518']}<Br><Br>\n\t\t\t\t\t<form action=\"./index.php?act=adminpanel&cp_page=settings&settings_page=user_agreement&update_settings=1\" method=\"POST\">\n\t\t\t\t\t<textarea cols=\"35\" rows=\"15\" name=\"user_agreement\" class=\"text_input\">{$agreement}</textarea>\n\t\t\t\t\t<br>\n\t\t\t\t\t<input type=\"submit\" value=\"{$txt['187']}\" class=\"button\">\n\t\t\t\t\t</form></div>";
            } elseif ($_GET['settings_page'] == "logs") {
                // Get defaults
                if ($def_settings['enable_logging'] == 1) {
                    $def['enable_logging'] = "checked=\"true\"";
                } else {
                    $def['enable_logging'] = "";
                }
                // Convert these from bytes to kilobytes
                $def['max_log_user'] = $def_settings['max_log_user'] / 1024;
                $def['max_log_room'] = $def_settings['max_log_room'] / 1024;
                $body = "<Br>\n\t\t\t\t\t<form action=\"./index.php?act=adminpanel&cp_page=settings&settings_page=logs&update_settings=1\" method=\"POST\">\n\t\t\t\t\t<table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\">\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['244']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"checkbox\" name=\"enable_logging\"{$def['enable_logging']} value=\"1\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['345']}**: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"logs_path\" value=\"{$def_settings['logs_path']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['346']}*: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"max_log_room\" value=\"{$def['max_log_room']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['347']}*: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"max_log_user\" value=\"{$def['max_log_user']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"200\" colspan=\"2\"><div align=\"center\"><input type=\"submit\" class=\"button\" value=\"{$txt['187']}\"></div></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"200\" colspan=\"2\"><b>* {$txt['340']}</b><Br><b>** {$txt['522']}</b></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t\t</form>";
            } elseif ($_GET['settings_page'] == "timedate") {
                $thelp = $print->help_button("time_date");
                $body = "<Br>\n\t\t\t\t\t<form action=\"./index.php?act=adminpanel&cp_page=settings&settings_page=timedate&update_settings=1\" method=\"POST\">\n\t\t\t\t\t<table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\">\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['348']}: {$thelp}</td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"date_format\" value=\"{$def_settings['date_format']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['349']}: {$thelp}</td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"date_format_date\" value=\"{$def_settings['date_format_date']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['350']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"date_format_full\" value=\"{$def_settings['date_format_full']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['201']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"time_offset_hours\" value=\"{$def_settings['time_offset_hours']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['202']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"time_offset_mins\" value=\"{$def_settings['time_offset_mins']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"200\" colspan=\"2\"><div align=\"center\"><input type=\"submit\" class=\"button\" value=\"{$txt['187']}\"></div></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t\t</form>";
            } elseif ($_GET['settings_page'] == "exptime") {
                // Convert default values from miliseconds to second
                $def['expire_messages'] = $def_settings['expire_messages'] / 60;
                $def['expire_rooms'] = $def_settings['expire_rooms'] / 60;
                $def['expire_guests'] = $def_settings['expire_guests'] / 60;
                $body = "<Br>\n\t\t\t\t\t<form action=\"./index.php?act=adminpanel&cp_page=settings&settings_page=exptime&update_settings=1\" method=\"POST\">\n\t\t\t\t\t<table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\">\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['352']} ({$txt['351']}): </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"online_time\" value=\"{$def_settings['online_time']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['353']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"expire_messages\" value=\"{$def['expire_messages']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['354']}* ({$txt['356']}): </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"expire_rooms\" value=\"{$def['expire_rooms']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['355']}* ({$txt['356']}): </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"expire_guests\" value=\"{$def['expire_guests']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"200\" colspan=\"2\"><div align=\"center\"><input type=\"submit\" class=\"button\" value=\"{$txt['187']}\"></div></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"200\" colspan=\"2\"><b>* {$txt['340']}</b></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t\t</form>";
            } elseif ($_GET['settings_page'] == "styles") {
                // Calculate default check box values
                $checkboxs[] = "enable_roombgs";
                $checkboxs[] = "enable_roomlogo";
                $checkboxs[] = "disable_smiles";
                $checkboxs[] = "disable_styles";
                $checkboxs[] = "disable_autolinking";
                foreach ($checkboxs as $key => $val) {
                    if ($def_settings[$val] == 1) {
                        $def[$val] = " CHECKED=\"true\"";
                    } else {
                        $def[$val] = "";
                    }
                }
                $body = "<Br>\n\t\t\t\t\t<form action=\"./index.php?act=adminpanel&cp_page=settings&settings_page=styles&update_settings=1\" name=\"settings_form\" method=\"POST\">\n\t\t\t\t\t<table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\">\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['324']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"banner_url\" value=\"{$def_settings['banner_url']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['358']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"background_image\" value=\"{$def_settings['background_image']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['359']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"checkbox\" name=\"enable_roombgs\"{$def['enable_roombgs']} value=\"1\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['360']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"checkbox\" name=\"enable_roomlogo\"{$def['enable_roomlogo']} value=\"1\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['361']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"default_font\" style=\"font-family: {$def_settings['default_font']};\" value=\"{$def_settings['default_font']}\" onChange=\"this.style.fontFamily=this.value\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['362']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"default_size\" value=\"{$def_settings['default_size']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['363']}: &nbsp;&nbsp;<img src=\"./colors.png\" width=\"15\" height=\"15\" onClick=\"javascript: window.open('./index.php?act=sm_window&page=colors&toform=settings_form&tofield=default_color','','location=no,menubar=no,resizable=no,status=no,toolbar=no,scrollbars=yes,width={$x7c->settings['tweak_window_small_width']},height={$x7c->settings['tweak_window_small_height']}');\"></td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"default_color\" value=\"{$def_settings['default_color']}\" style=\"color: {$def_settings['default_color']};\" onChange=\"this.style.color=this.value\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['364']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"style_min_size\" value=\"{$def_settings['style_min_size']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['365']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"style_max_size\" value=\"{$def_settings['style_max_size']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['366']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"checkbox\" name=\"disable_smiles\"{$def['disable_smiles']} value=\"1\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['367']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"checkbox\" name=\"disable_styles\"{$def['disable_styles']} value=\"1\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['368']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"checkbox\" name=\"disable_autolinking\"{$def['disable_autolinking']} value=\"1\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['369']}: &nbsp;&nbsp;<img src=\"./colors.png\" width=\"15\" height=\"15\" onClick=\"javascript: window.open('./index.php?act=sm_window&page=colors&toform=settings_form&tofield=system_message_color','','location=no,menubar=no,resizable=no,status=no,toolbar=no,scrollbars=yes,width={$x7c->settings['tweak_window_small_width']},height={$x7c->settings['tweak_window_small_height']}');\"></td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"system_message_color\" value=\"{$def_settings['system_message_color']}\" style=\"color: {$def_settings['system_message_color']};\" onChange=\"this.style.color=this.value\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['370']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"style_allowed_fonts\" value=\"{$def_settings['style_allowed_fonts']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"200\" colspan=\"2\"><div align=\"center\"><input type=\"submit\" class=\"button\" value=\"{$txt['187']}\"></div></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"200\" colspan=\"2\"><b>* {$txt['371']}</b></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t\t</form>";
            } elseif ($_GET['settings_page'] == "avatars") {
                // Get Default checkbox values
                if ($def_settings['enable_avatar_uploads'] == 1) {
                    $def['enable_avatar_uploads'] = " checked=\"true\"";
                } else {
                    $def['enable_avatar_uploads'] = "";
                }
                if ($def_settings['resize_smaller_avatars'] == 1) {
                    $def['resize_smaller_avatars'] = " checked=\"true\"";
                } else {
                    $def['resize_smaller_avatars'] = "";
                }
                // Convert from bytes to kilobytes
                $def['avatar_max_size'] = $def_settings['avatar_max_size'] / 1024;
                $body = "<Br>\n\t\t\t\t\t<form action=\"./index.php?act=adminpanel&cp_page=settings&settings_page=avatars&update_settings=1\" method=\"POST\">\n\t\t\t\t\t<table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\">\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['372']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"checkbox\" name=\"enable_avatar_uploads\"{$def['enable_avatar_uploads']} value=\"1\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['373']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"checkbox\" name=\"resize_smaller_avatars\"{$def['resize_smaller_avatars']} value=\"1\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['374']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"avatar_max_size\" value=\"{$def['avatar_max_size']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['375']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"avatar_size_px\" value=\"{$def_settings['avatar_size_px']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['376']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"uploads_path\" value=\"{$def_settings['uploads_path']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['377']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"uploads_url\" value=\"{$def_settings['uploads_url']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"200\" colspan=\"2\"><div align=\"center\"><input type=\"submit\" class=\"button\" value=\"{$txt['187']}\"></div></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t\t</form>";
            } elseif ($_GET['settings_page'] == "loginpage") {
                // Calculate default check box values
                $body = "<Br>\n\t\t\t\t\t<form action=\"./index.php?act=adminpanel&cp_page=settings&settings_page=loginpage&update_settings=1\" method=\"POST\">\n\t\t\t\t\t<table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\">\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['262']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"news\" value=\"{$def_settings['news']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">Testo in mappa: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"floating_text\" value=\"{$def_settings['floating_text']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['380']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"checkbox\" name=\"enable_passreminder\"{$def['enable_passreminder']} value=\"1\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"200\" colspan=\"2\"><div align=\"center\"><input type=\"submit\" class=\"button\" value=\"{$txt['187']}\"></div></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t\t</form>";
            } elseif ($_GET['settings_page'] == "advanced") {
                // Default values
                if ($def_settings['disable_gd'] == 1) {
                    $def['disable_gd'] = " checked=\"true\"";
                } else {
                    $def['disable_gd'] = "";
                }
                $body = "<Br>{$txt['385']}<Br><Br>\n\t\t\t\t\t<form action=\"./index.php?act=adminpanel&cp_page=settings&settings_page=advanced&update_settings=1\" method=\"POST\">\n\t\t\t\t\t<table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\">\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"100\">{$txt['384']}: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"checkbox\" name=\"disable_gd\"{$def['disable_gd']} value=\"1\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"200\" colspan=\"2\"><div align=\"center\"><input type=\"submit\" class=\"button\" value=\"{$txt['187']}\"></div></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t\t</form>";
            }
        } else {
            // Display the many catagories of settings
            $body = "\n\t\t\t\t<div align=\"center\">{$txt['321']}\n\t\t\t\t<br><Br>\n\t\t\t\t<a href=\"./index.php?act=adminpanel&cp_page=settings&settings_page=general\">[{$txt['218']}]</a><br><br>\n\t\t\t\t<a href=\"./index.php?act=adminpanel&cp_page=settings&settings_page=logs\">[{$txt['240']}]</a><br><br>\n\t\t\t\t<a href=\"./index.php?act=adminpanel&cp_page=settings&settings_page=timedate\">[{$txt['322']}]</a><br><br>\n\t\t\t\t<a href=\"./index.php?act=adminpanel&cp_page=settings&settings_page=exptime\">[{$txt['323']}]</a><br><br>\n\t\t\t\t<a href=\"./index.php?act=adminpanel&cp_page=settings&settings_page=styles\">[{$txt['325']}]</a><br><br>\n\t\t\t\t<a href=\"./index.php?act=adminpanel&cp_page=settings&settings_page=avatars\">[{$txt['326']}]</a><br><br>\n\t\t\t\t<a href=\"./index.php?act=adminpanel&cp_page=settings&settings_page=loginpage\">[{$txt['327']}]</a><br><br>\n\t\t\t\t<a href=\"./index.php?act=adminpanel&cp_page=settings&settings_page=user_agreement\">[{$txt['517']}]</a><br><br>\n\t\t\t\t<a href=\"./index.php?act=adminpanel&cp_page=settings&settings_page=support\">[{$txt['599']}]</a><br><br>\n\t\t\t\t<a href=\"./index.php?act=adminpanel&cp_page=settings&settings_page=advanced\">[{$txt['328']}]</a><br><br>\n\t\t\t\t</div>";
        }
    } elseif ($_GET['cp_page'] == "groupmanager") {
        // This is the user group control page
        $head = $txt[309];
        $body = "";
        if (isset($_POST['create'])) {
            // Create a group
            if ($_POST['create'] != "") {
                $db->DoQuery("INSERT INTO {$prefix}permissions (id,usergroup) VALUES('0','{$_POST['create']}')");
                // Edit the settings for this group
                $_GET['edit'] = $_POST['create'];
            }
        }
        if (isset($_GET['edit'])) {
            // Edit a groups permissions
            // Get defaults
            $query = $db->DoQuery("SELECT * FROM {$prefix}permissions WHERE usergroup='{$_GET['edit']}'");
            $row = $db->Do_Fetch_Row($query);
            $row[2] == 1 ? $def['make_rooms'] = " checked=\"true\"" : ($def['make_rooms'] = "");
            $row[3] == 1 ? $def['make_proom'] = " checked=\"true\"" : ($def['make_proom'] = "");
            $row[4] == 1 ? $def['make_nexp'] = " checked=\"true\"" : ($def['make_nexp'] = "");
            $row[5] == 1 ? $def['make_mod'] = " checked=\"true\"" : ($def['make_mod'] = "");
            $row[6] == 1 ? $def['viewip'] = " checked=\"true\"" : ($def['viewip'] = "");
            $row[7] == 1 ? $def['kick'] = " checked=\"true\"" : ($def['kick'] = "");
            $row[8] == 1 ? $def['ban_kick_imm'] = " checked=\"true\"" : ($def['ban_kick_imm'] = "");
            $row[9] == 1 ? $def['AOP_all'] = " checked=\"true\"" : ($def['AOP_all'] = "");
            $row[10] == 1 ? $def['AV_all'] = " checked=\"true\"" : ($def['AV_all'] = "");
            $row[11] == 1 ? $def['view_hidden_emails'] = " checked=\"true\"" : ($def['view_hidden_emails'] = "");
            $row[12] == 1 ? $def['use_keywords'] = " checked=\"true\"" : ($def['use_keywords'] = "");
            $row[13] == 1 ? $def['access_room_logs'] = " checked=\"true\"" : ($def['access_room_logs'] = "");
            $row[14] == 1 ? $def['log_pms'] = " checked=\"true\"" : ($def['log_pms'] = "");
            $row[15] == 1 ? $def['set_background'] = " checked=\"true\"" : ($def['set_background'] = "");
            $row[16] == 1 ? $def['set_logo'] = " checked=\"true\"" : ($def['set_logo'] = "");
            $row[17] == 1 ? $def['make_admins'] = " checked=\"true\"" : ($def['make_admins'] = "");
            $row[18] == 1 ? $def['server_msg'] = " checked=\"true\"" : ($def['server_msg'] = "");
            $row[19] == 1 ? $def['can_mdeop'] = " checked=\"true\"" : ($def['can_mdeop'] = "");
            $row[20] == 1 ? $def['can_mkick'] = " checked=\"true\"" : ($def['can_mkick'] = "");
            $row[21] == 1 ? $def['admin_settings'] = " checked=\"true\"" : ($def['admin_settings'] = "");
            $row[22] == 1 ? $def['admin_themes'] = " checked=\"true\"" : ($def['admin_themes'] = "");
            $row[23] == 1 ? $def['admin_filter'] = " checked=\"true\"" : ($def['admin_filter'] = "");
            $row[24] == 1 ? $def['admin_groups'] = " checked=\"true\"" : ($def['admin_groups'] = "");
            $row[25] == 1 ? $def['admin_users'] = " checked=\"true\"" : ($def['admin_users'] = "");
            $row[26] == 1 ? $def['admin_ban'] = " checked=\"true\"" : ($def['admin_ban'] = "");
            $row[27] == 1 ? $def['admin_bandwidth'] = " checked=\"true\"" : ($def['admin_bandwidth'] = "");
            $row[28] == 1 ? $def['admin_logs'] = " checked=\"true\"" : ($def['admin_logs'] = "");
            $row[29] == 1 ? $def['admin_events'] = " checked=\"true\"" : ($def['admin_events'] = "");
            $row[30] == 1 ? $def['admin_mail'] = " checked=\"true\"" : ($def['admin_mail'] = "");
            $row[31] == 1 ? $def['admin_mods'] = " checked=\"true\"" : ($def['admin_mods'] = "");
            $row[32] == 1 ? $def['admin_smilies'] = " checked=\"true\"" : ($def['admin_smilies'] = "");
            $row[33] == 1 ? $def['admin_rooms'] = " checked=\"true\"" : ($def['admin_rooms'] = "");
            $row[34] == 1 ? $def['access_disabled'] = " checked=\"true\"" : ($def['access_disabled'] = "");
            $row[35] == 1 ? $def['b_invisible'] = " checked=\"true\"" : ($def['b_invisible'] = "");
            $row[36] == 1 ? $def['c_invisible'] = " checked=\"true\"" : ($def['c_invisible'] = "");
            $row[37] == 1 ? $def['admin_keywords'] = " checked=\"true\"" : ($def['admin_keywords'] = "");
            $row[38] == 1 ? $def['access_pw_rooms'] = " checked=\"true\"" : ($def['access_pw_rooms'] = "");
            $row[39] == 1 ? $def['admin_panic'] = " checked=\"true\"" : ($def['admin_panic'] = "");
            $row[40] == 1 ? $def['admin_alarms'] = " checked=\"true\"" : ($def['admin_alarms'] = "");
            $row[41] == 1 ? $def['admin_objects'] = " checked=\"true\"" : ($def['admin_objects'] = "");
            $row[43] == 1 ? $def['sheet_modify'] = " checked=\"true\"" : ($def['sheet_modify'] = "");
            $row[44] == 1 ? $def['write_master'] = " checked=\"true\"" : ($def['write_master'] = "");
            $row[45] == 1 ? $def['gremios'] = " checked=\"true\"" : ($def['gremios'] = "");
            $row[46] == 1 ? $def['admin_abilities'] = " checked=\"true\"" : ($def['admin_abilities'] = "");
            $row[47] == 1 ? $def['admin_money'] = " checked=\"true\"" : ($def['admin_money'] = "");
            $row[48] == 1 ? $def['admin_hints'] = " checked=\"true\"" : ($def['admin_hints'] = "");
            $body = "{$txt['424']}<Br><Br><table border=\"0\" cellspacing=\"0\" cellpadding=\"4\" align=\"center\">\n\t\t\t\t<form action=\"index.php?act=adminpanel&cp_page=groupmanager&update={$_GET['edit']}\" method=\"post\">\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['422']}</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"make_rooms\" value=\"1\"{$def['make_rooms']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['423']}</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"make_proom\" value=\"1\"{$def['make_proom']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['425']}*</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"make_nexp\" value=\"1\"{$def['make_nexp']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['426']}*</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"make_mod\" value=\"1\"{$def['make_mod']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['427']}*</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"viewip\" value=\"1\"{$def['viewip']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['428']}*</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"kick\" value=\"1\"{$def['kick']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['429']}</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"ban_kick_imm\" value=\"1\"{$def['ban_kick_imm']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['430']}</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"AOP_all\" value=\"1\"{$def['AOP_all']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['431']}</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"AV_all\" value=\"1\"{$def['AV_all']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['432']}</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"view_hidden_emails\" value=\"1\"{$def['view_hidden_emails']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['433']}*</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"use_keywords\" value=\"1\"{$def['use_keywords']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['434']}*</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"access_room_logs\" value=\"1\"{$def['access_room_logs']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['435']}</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"log_pms\" value=\"1\"{$def['log_pms']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['436']}**</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"set_background\" value=\"1\"{$def['set_background']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['437']}**</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"set_logo\" value=\"1\"{$def['set_logo']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['438']}</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"make_admins\" value=\"1\"{$def['make_admins']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['439']}</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"server_msg\" value=\"1\"{$def['server_msg']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['440']}*</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"can_mdeop\" value=\"1\"{$def['can_mdeop']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['441']}*</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"can_mkick\" value=\"1\"{$def['can_mkick']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['442']}</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"admin_settings\" value=\"1\"{$def['admin_settings']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['443']}</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"admin_themes\" value=\"1\"{$def['admin_themes']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['444']}</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"admin_filter\" value=\"1\"{$def['admin_filter']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['445']}</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"admin_groups\" value=\"1\"{$def['admin_groups']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['446']}</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"admin_users\" value=\"1\"{$def['admin_users']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['447']}</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"admin_ban\" value=\"1\"{$def['admin_ban']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['448']}</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"admin_bandwidth\" value=\"1\"{$def['admin_bandwidth']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['449']}</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"admin_logs\" value=\"1\"{$def['admin_logs']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['457']}</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"admin_events\" value=\"1\"{$def['admin_events']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['450']}</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"admin_mail\" value=\"1\"{$def['admin_mail']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['451']}</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"admin_mods\" value=\"1\"{$def['admin_mods']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['452']}</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"admin_smilies\" value=\"1\"{$def['admin_smilies']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['453']}</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"admin_rooms\" value=\"1\"{$def['admin_rooms']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['577']}</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"admin_keywords\" value=\"1\"{$def['admin_keywords']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['454']}</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"access_disabled\" value=\"1\"{$def['access_disabled']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['505']}</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"b_invisible\" value=\"1\"{$def['b_invisible']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['506']}</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"c_invisible\" value=\"1\"{$def['c_invisible']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">{$txt['602']}</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"access_pw_rooms\" value=\"1\"{$def['access_pw_rooms']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">Amministra l'oscurit&agrave;</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"admin_panic\" value=\"1\"{$def['admin_panic']}></td>\n\t\t\t\t</tr>\t\t\t\t\t\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">Amministra gli allarmi</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"admin_alarms\" value=\"1\"{$def['admin_alarms']}></td>\n\t\t\t\t</tr>\t\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">Amministra gli oggetti</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"admin_objects\" value=\"1\"{$def['admin_objects']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">Amministra i soldi</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"admin_money\" value=\"1\"{$def['admin_money']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">Puo' modificare le schede</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"sheet_modify\" value=\"1\"{$def['sheet_modify']}></td>\n\t\t\t\t</tr>\t\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">Puo' scrivere in modo master</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"write_master\" value=\"1\"{$def['write_master']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">Amministra le abilit&agrave;</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"admin_abilities\" value=\"1\"{$def['admin_abilities']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">Amministra gli hint del master</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"admin_hints\" value=\"1\"{$def['admin_hints']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">E' una gremios?</td>\n\t\t\t\t<td width=\"50\"><input type=\"checkbox\" name=\"gremios\" value=\"1\"{$def['gremios']}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"120\">Logo</td>\n\t\t\t\t<td width=\"50\"><input type=\"text\" name=\"logo\" value=\"{$row['42']}\"></td>\n\t\t\t\t</tr>\n\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"170\" colspan=\"2\"><div align=\"center\"><input type=\"submit\" class=\"button\" value=\"{$txt['187']}\"></div></td>\n\t\t\t\t</tr>\n\t\t\t\t</table><Br><Br>\n\t\t\t\t<b>*</b>: {$txt['455']}<br><Br>\n\t\t\t\t<b>**</b>: {$txt['456']}<br><Br>";
        } elseif (isset($_GET['view'])) {
            // View members in a group
            // Get defaults for changing it
            $query = $db->DoQuery("SELECT usergroup FROM {$prefix}permissions");
            $change_ops = "";
            while ($row = $db->Do_Fetch_Row($query)) {
                $change_ops .= "<option value=\"{$row['0']}\">{$row['0']}</option>";
            }
            $query = $db->DoQuery("SELECT username FROM {$prefix}groups WHERE usergroup='{$_GET['view']}'");
            // This is the javascript for the check all uncheck all boxes
            $body .= "{$txt['418']}<Br><br>";
            while ($row = $db->Do_Fetch_Row($query)) {
                $body .= "&nbsp;&nbsp;<b>{$row['0']}</b><Br>";
            }
            $body .= "<br><a href=\"index.php?act=adminpanel&cp_page=groupmanager\">{$txt['77']}</a></div>";
        } else {
            if (isset($_GET['update'])) {
                // Update a group
                // Check for checkboxs
                !isset($_POST['make_rooms']) ? $_POST['make_rooms'] = 0 : "";
                !isset($_POST['make_proom']) ? $_POST['make_proom'] = 0 : "";
                !isset($_POST['make_nexp']) ? $_POST['make_nexp'] = 0 : "";
                !isset($_POST['make_mod']) ? $_POST['make_mod'] = 0 : "";
                !isset($_POST['viewip']) ? $_POST['viewip'] = 0 : "";
                !isset($_POST['kick']) ? $_POST['kick'] = 0 : "";
                !isset($_POST['ban_kick_imm']) ? $_POST['ban_kick_imm'] = 0 : "";
                !isset($_POST['AOP_all']) ? $_POST['AOP_all'] = 0 : "";
                !isset($_POST['AV_all']) ? $_POST['AV_all'] = 0 : "";
                !isset($_POST['view_hidden_emails']) ? $_POST['view_hidden_emails'] = 0 : "";
                !isset($_POST['use_keywords']) ? $_POST['use_keywords'] = 0 : "";
                !isset($_POST['access_room_logs']) ? $_POST['access_room_logs'] = 0 : "";
                !isset($_POST['log_pms']) ? $_POST['log_pms'] = 0 : "";
                !isset($_POST['set_background']) ? $_POST['set_background'] = 0 : "";
                !isset($_POST['set_logo']) ? $_POST['set_logo'] = 0 : "";
                !isset($_POST['make_admins']) ? $_POST['make_admins'] = 0 : "";
                !isset($_POST['server_msg']) ? $_POST['server_msg'] = 0 : "";
                !isset($_POST['can_mdeop']) ? $_POST['can_mdeop'] = 0 : "";
                !isset($_POST['can_mkick']) ? $_POST['can_mkick'] = 0 : "";
                !isset($_POST['admin_settings']) ? $_POST['admin_settings'] = 0 : "";
                !isset($_POST['admin_themes']) ? $_POST['admin_themes'] = 0 : "";
                !isset($_POST['admin_filter']) ? $_POST['admin_filter'] = 0 : "";
                !isset($_POST['admin_groups']) ? $_POST['admin_groups'] = 0 : "";
                !isset($_POST['admin_users']) ? $_POST['admin_users'] = 0 : "";
                !isset($_POST['admin_ban']) ? $_POST['admin_ban'] = 0 : "";
                !isset($_POST['admin_bandwidth']) ? $_POST['admin_bandwidth'] = 0 : "";
                !isset($_POST['admin_logs']) ? $_POST['admin_logs'] = 0 : "";
                !isset($_POST['admin_events']) ? $_POST['admin_events'] = 0 : "";
                !isset($_POST['admin_mail']) ? $_POST['admin_mail'] = 0 : "";
                !isset($_POST['admin_mods']) ? $_POST['admin_mods'] = 0 : "";
                !isset($_POST['admin_smilies']) ? $_POST['admin_smilies'] = 0 : "";
                !isset($_POST['admin_rooms']) ? $_POST['admin_rooms'] = 0 : "";
                !isset($_POST['access_disabled']) ? $_POST['access_disabled'] = 0 : "";
                !isset($_POST['b_invisible']) ? $_POST['b_invisible'] = 0 : "";
                !isset($_POST['c_invisible']) ? $_POST['c_invisible'] = 0 : "";
                !isset($_POST['admin_keywords']) ? $_POST['admin_keywords'] = 0 : "";
                !isset($_POST['access_pw_rooms']) ? $_POST['access_pw_rooms'] = 0 : "";
                !isset($_POST['admin_panic']) ? $_POST['admin_panic'] = 0 : "";
                !isset($_POST['admin_alarms']) ? $_POST['admin_alarms'] = 0 : "";
                !isset($_POST['admin_objects']) ? $_POST['admin_objects'] = 0 : "";
                !isset($_POST['admin_money']) ? $_POST['admin_money'] = 0 : "";
                !isset($_POST['sheet_modify']) ? $_POST['sheet_modify'] = 0 : "";
                !isset($_POST['logo']) ? $_POST['logo'] = 0 : "";
                !isset($_POST['write_master']) ? $_POST['write_master'] = 0 : "";
                !isset($_POST['gremios']) ? $_POST['gremios'] = 0 : "";
                !isset($_POST['admin_abilities']) ? $_POST['admin_abilities'] = 0 : "";
                !isset($_POST['admin_hints']) ? $_POST['admin_hints'] = 0 : "";
                // Save the settings
                $db->DoQuery("UPDATE {$prefix}permissions \n\t\t\t\t\t\tSET make_rooms='{$_POST['make_rooms']}',\n\t\t\t\t\t\tmake_proom='{$_POST['make_proom']}',\n\t\t\t\t\t\tmake_nexp='{$_POST['make_nexp']}',\n\t\t\t\t\t\tmake_mod='{$_POST['make_mod']}',\n\t\t\t\t\t\tviewip='{$_POST['viewip']}',\n\t\t\t\t\t\tkick='{$_POST['kick']}',\n\t\t\t\t\t\tban_kick_imm='{$_POST['ban_kick_imm']}',\n\t\t\t\t\t\tAOP_all='{$_POST['AOP_all']}',\n\t\t\t\t\t\tAV_all='{$_POST['AV_all']}',\n\t\t\t\t\t\tview_hidden_emails='{$_POST['view_hidden_emails']}',\n\t\t\t\t\t\tuse_keywords='{$_POST['use_keywords']}',\n\t\t\t\t\t\taccess_room_logs='{$_POST['access_room_logs']}',\n\t\t\t\t\t\tlog_pms='{$_POST['log_pms']}',\n\t\t\t\t\t\tset_background='{$_POST['set_background']}',\n\t\t\t\t\t\tset_logo='{$_POST['set_logo']}',\n\t\t\t\t\t\tmake_admins='{$_POST['make_admins']}',\n\t\t\t\t\t\tserver_msg='{$_POST['server_msg']}',can_mdeop='{$_POST['can_mdeop']}',\n\t\t\t\t\t\tcan_mkick='{$_POST['can_mkick']}',\n\t\t\t\t\t\tadmin_settings='{$_POST['admin_settings']}',\n\t\t\t\t\t\tadmin_themes='{$_POST['admin_themes']}',\n\t\t\t\t\t\tadmin_filter='{$_POST['admin_filter']}',\n\t\t\t\t\t\tadmin_groups='{$_POST['admin_groups']}',\n\t\t\t\t\t\tadmin_users='{$_POST['admin_users']}',\n\t\t\t\t\t\tadmin_ban='{$_POST['admin_ban']}',\n\t\t\t\t\t\tadmin_bandwidth='{$_POST['admin_bandwidth']}',\n\t\t\t\t\t\tadmin_logs='{$_POST['admin_logs']}',\n\t\t\t\t\t\tadmin_events='{$_POST['admin_events']}',\n\t\t\t\t\t\tadmin_mail='{$_POST['admin_mail']}',\n\t\t\t\t\t\tadmin_mods='{$_POST['admin_mods']}',\n\t\t\t\t\t\tadmin_smilies='{$_POST['admin_smilies']}',\n\t\t\t\t\t\tadmin_rooms='{$_POST['admin_rooms']}',\n\t\t\t\t\t\taccess_disabled='{$_POST['access_disabled']}',\n\t\t\t\t\t\tb_invisible='{$_POST['b_invisible']}',\n\t\t\t\t\t\tc_invisible={$_POST['c_invisible']},\n\t\t\t\t\t\tadmin_keywords='{$_POST['admin_keywords']}',\n\t\t\t\t\t\taccess_pw_rooms='{$_POST['access_pw_rooms']}', \n\t\t\t\t\t\tadmin_panic='{$_POST['admin_panic']}', \n\t\t\t\t\t\tadmin_alarms='{$_POST['admin_alarms']}', \n\t\t\t\t\t\tadmin_objects='{$_POST['admin_objects']}', \n\t\t\t\t\t\tlogo='{$_POST['logo']}', \n\t\t\t\t\t\tsheet_modify='{$_POST['sheet_modify']}', \n\t\t\t\t\t\twrite_master='{$_POST['write_master']}', \n\t\t\t\t\t\tgremios='{$_POST['gremios']}', \n\t\t\t\t\t\tadmin_abilities='{$_POST['admin_abilities']}', \n\t\t\t\t\t\tadmin_hints='{$_POST['admin_hints']}', \n\t\t\t\t\t\tadmin_money='{$_POST['admin_money']}' \n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tWHERE usergroup='{$_GET['update']}'");
                // Tell user they have been updated
                $body .= "{$txt['458']}<Br><br>";
            } elseif (isset($_GET['delete'])) {
                // Delete a group
                // Make sure the group is empty
                $query = $db->DoQuery("SELECT * FROM {$prefix}groups WHERE usergroup='{$_GET['delete']}'");
                $row = $db->Do_Fetch_Row($query);
                $query = $db->DoQuery("SELECT * FROM {$prefix}ability WHERE corp='{$_GET['delete']}'");
                $row2 = $db->Do_Fetch_Row($query);
                if ($row[0] != "") {
                    $body .= "{$txt['420']}<Br><Br>";
                } elseif ($row2[0] != "") {
                    $body .= "Rimuovere tutte le abilita' di gremios prima di cancellare<Br><Br>";
                } else {
                    $db->DoQuery("DELETE FROM {$prefix}permissions WHERE usergroup='{$_GET['delete']}'");
                    $body .= "{$txt['421']}<Br><Br>";
                }
            } elseif (isset($_POST['new_g'])) {
                // Change user's groups
                $body .= "{$txt['415']}<Br><Br>";
                foreach ($_POST as $key => $val) {
                    if (eregi("^ug_", $key) && $val == 1) {
                        $key = eregi_replace("^ug_", "", $key);
                        $gif_query = $db->DoQuery("SELECT logo FROM {$prefix}permissions WHERE usergroup='{$_POST['new_g']}'");
                        $row = $db->Do_Fetch_Assoc($gif_query);
                        $gif = $row['logo'];
                        include_once './lib/sheet_lib.php';
                        join_corp($key, $_POST['new_g']);
                    }
                }
            } elseif (isset($_GET['defaults'])) {
                // Edit the default groups
                // Update the database
                update_setting("usergroup_admin", $_POST['admin']);
                update_setting("usergroup_guest", $_POST['guest']);
                update_setting("usergroup_default", $_POST['member']);
                $body .= "{$txt['412']}<Br><Br>";
                // Update member accounts so their user groups are correct
                //$db->DoQuery("UPDATE {$prefix}users SET user_group='_1' WHERE user_group='{$x7c->settings['usergroup_admin']}' WHERE username<>'$x7s->username'");
                //$db->DoQuery("UPDATE {$prefix}users SET user_group='_2' WHERE user_group='{$x7c->settings['usergroup_guest']}' WHERE username<>'$x7s->username'");
                //$db->DoQuery("UPDATE {$prefix}users SET user_group='_3' WHERE user_group='{$x7c->settings['usergroup_default']}' WHERE username<>'$x7s->username'");
                //$db->DoQuery("UPDATE {$prefix}users SET user_group='{$_POST['admin']}' WHERE user_group='_1' WHERE username<>'$x7s->username'");
                //$db->DoQuery("UPDATE {$prefix}users SET user_group='{$_POST['guest']}' WHERE user_group='_2' WHERE username<>'$x7s->username'");
                //$db->DoQuery("UPDATE {$prefix}users SET user_group='{$_POST['member']}' WHERE user_group='_3' WHERE username<>'$x7s->username'");
                // Update these values quickly so that the change is shown
                $x7c->settings['usergroup_admin'] = $_POST['admin'];
                $x7c->settings['usergroup_guest'] = $_POST['guest'];
                $x7c->settings['usergroup_default'] = $_POST['member'];
            }
            // Get default group values
            $query = $db->DoQuery("SELECT usergroup FROM {$prefix}permissions");
            $group_options['admin'] = "";
            $group_options['member'] = "";
            $group_options['guest'] = "";
            while ($row = $db->Do_Fetch_Row($query)) {
                if ($x7c->settings['usergroup_admin'] == $row[0]) {
                    $group_options['admin'] .= "<option value=\"{$row['0']}\" selected=\"true\">{$row['0']}</option>";
                } else {
                    $group_options['admin'] .= "<option value=\"{$row['0']}\">{$row['0']}</option>";
                }
                if ($x7c->settings['usergroup_guest'] == $row[0]) {
                    $group_options['guest'] .= "<option value=\"{$row['0']}\" selected=\"true\">{$row['0']}</option>";
                } else {
                    $group_options['guest'] .= "<option value=\"{$row['0']}\">{$row['0']}</option>";
                }
                if ($x7c->settings['usergroup_default'] == $row[0]) {
                    $group_options['member'] .= "<option value=\"{$row['0']}\" selected=\"true\">{$row['0']}</option>";
                } else {
                    $group_options['member'] .= "<option value=\"{$row['0']}\">{$row['0']}</option>";
                }
                $groups[] = $row[0];
            }
            // Display groups and settings edit form
            /*$body .= "<div align=\"center\">
            			<b>$txt[408]</b><br>
            			<form action=\"index.php?act=adminpanel&cp_page=groupmanager&defaults=1\" method=\"post\">
            			<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
            			<tr>
            			<td width=\"100\">$txt[409]: </td>
            			<td width=\"100\"><select name=\"member\" class=\"text_input\">{$group_options['member']}</select></td>
            			</tr>
            			<tr>
            			<td width=\"100\">$txt[410]: </td>
            			<td width=\"100\"><select name=\"guest\" class=\"text_input\">{$group_options['guest']}</select></td>
            			</tr>
            			<tr>
            			<td width=\"100\">$txt[411]: </td>
            			<td width=\"100\"><select name=\"admin\" class=\"text_input\">{$group_options['admin']}</select></td>
            			</tr>
            			<tr>
            			<td width=\"200\" colspan=\"2\"><div align=\"center\"><input type=\"submit\" class=\"button\" value=\"$txt[187]\"></div></td>
            			</tr>
            			</table>
            			</form><Br><Br>
            			<table width=\"95%\" align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"col_header\">
            			<tr>
            			<td height=\"25\">&nbsp;$txt[123]</td>
            			<td width=\"33%\" height=\"25\">$txt[86]</td>
            			</tr>
            			</table>
            			<table width=\"95%\" align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"inside_table\">";
            		*/
            $body .= "<div align=\"center\">\n\t\t\t\t<table width=\"95%\" align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"col_header\">\n\t\t\t\t<tr>\n\t\t\t\t<td height=\"25\">&nbsp;{$txt['123']}</td>\n\t\t\t\t<td width=\"33%\" height=\"25\">{$txt['86']}</td>\n\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t\t<table width=\"95%\" align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"inside_table\">";
            // Display a table of groups with actions
            foreach ($groups as $key => $group) {
                $body .= "<Tr>\n\t\t\t\t\t<td>&nbsp;{$group}</td>\n\t\t\t\t\t<td width=\"33%\">\n\t\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=groupmanager&view={$group}\">[{$txt['413']}]</a>\n\t\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=groupmanager&delete={$group}\">[{$txt['175']}]</a>\n\t\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=groupmanager&edit={$group}\">[{$txt['139']}]</a>\n\t\t\t\t\t</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr><td colspan=\"2\"><hr></tr>\n\t\t\t\t\t";
            }
            $body .= "</table><Br><br>\n\t\t\t\t<form action=\"index.php?act=adminpanel&cp_page=groupmanager\" method=\"post\">\n\t\t\t\t{$txt['414']}: <input type=\"text\" class=\"text_input\" name=\"create\">\n\t\t\t\t<input type=\"submit\" class=\"button\" value=\"{$txt['63']}\">\n\t\t\t\t</form></div>";
        }
    } elseif ($_GET['cp_page'] == "objects") {
        include_once './lib/shop_lib.php';
        global $shopper, $money_name;
        $head = "Amministrazione oggetti";
        $navigator = '';
        $body = '';
        $error = '';
        if (isset($_GET['sell'])) {
            if ($_POST['sell_copies'] < 0) {
                $error = "Errore: il numero di copie deve essere positivo";
            } else {
                if (!$x7c->permissions["admin_panic"]) {
                    // Only masters can change the shop
                    $error = "Errore: operazione non permessa";
                } else {
                    get_obj_name_and_uses($_POST['id'], $obj_name, $dummy);
                    $cur_avail = get_obj_availability($obj_name);
                    $delta_avail = $_POST['sell_copies'] - $cur_avail;
                    $value = calculate_obj_value($_POST['id'], $shopper);
                    if ($value <= 0 || $obj_name == $money_name) {
                        $error = "Errore: l'oggetto non ha valore";
                    } else {
                        if ($delta_avail < 0) {
                            $delta_avail = -$delta_avail;
                            $db->DoQuery("DELETE FROM {$prefix}objects\n\t\t\t\t\t\t\t\tWHERE name = '{$obj_name}'\n\t\t\t\t\t\t\t\tAND owner = '{$shopper}'\n\t\t\t\t\t\t\t\tLIMIT {$delta_avail}");
                        } else {
                            if ($delta_avail > 0) {
                                $query = $db->DoQuery("SELECT * \n\t\t\t\t\t\t\t\tFROM {$prefix}objects WHERE id='{$_POST['id']}'");
                                $row = $db->Do_Fetch_Assoc($query);
                                if (!$row || $row['id'] == '') {
                                    $error = "Oggetto non esistente";
                                } else {
                                    for ($i = 0; $i < $delta_avail; $i++) {
                                        $db->DoQuery("INSERT INTO {$prefix}objects\n\t\t\t\t\t\t\t\t\t\t(name,description,uses,\n\t\t\t\t\t\t\t\t\t\t image_url,owner,equipped,size,category,base_value,\n\t\t\t\t\t\t\t\t\t\t visible_uses, expire_span, shop_return,random_img)\n\t\t\t\t\t\t\t\t\t\tVALUES('{$row['name']}','{$row['description']}','{$row['uses']}',\n\t\t\t\t\t\t\t\t\t\t\t'{$row['image_url']}','{$shopper}','1','{$row['size']}',\n\t\t\t\t\t\t\t\t\t\t\t'{$row['category']}',{$row['base_value']},'{$row['visible_uses']}',\n\t\t\t\t\t\t\t\t\t\t\t'{$row['expire_span']}','{$row['shop_return']}',\n\t\t\t\t\t\t\t\t\t\t\t'{$row['random_img']}')");
                                    }
                                }
                            }
                        }
                        $error = "Nuove copie in vendita: {$_POST['sell_copies']}";
                    }
                }
            }
        }
        if (isset($_GET['assign'])) {
            if (!isset($_POST['owner']) || !isset($_POST['id']) || !isset($_POST['qty'])) {
                die("Bad form");
            }
            if (!is_numeric($_POST['qty'])) {
                $error = "Quantita' da assegnare non valida";
            }
            get_obj_name_and_uses($_POST['id'], $obj_name, $dummy);
            if ($obj_name == $money_name) {
                $error = "Non puoi assegnare soldi da questo pannello";
            }
            include_once './lib/sheet_lib.php';
            if ($error == '') {
                for ($i = 0; $i < $_POST['qty']; $i++) {
                    $error .= assign_object($_POST['id'], $_POST['owner'], true);
                }
            }
        }
        if (isset($_GET['modify'])) {
            if (!isset($_POST['name']) || !isset($_POST['id']) || !isset($_POST['description']) || !isset($_POST['uses']) || !isset($_POST['image_url']) || !isset($_POST['size']) || !isset($_POST['base_value']) || !isset($_POST['category']) || !isset($_POST['expire_span'])) {
                die("Bad form");
            }
            $_POST['name'] = trim($_POST['name']);
            $visible_uses = false;
            if (isset($_POST['visible_uses'])) {
                $visible_uses = true;
            }
            $shop_return = false;
            if (isset($_POST['shop_return'])) {
                $shop_return = true;
            }
            $category = $_POST['category'];
            if ($_POST['category'] == "_new_" && isset($_POST['new_category'])) {
                $category = $_POST['new_category'];
            }
            if ($_POST['id'] != -1) {
                $old_name = '';
                get_obj_name_and_uses($_POST['id'], $old_name, $uses);
                $query_old_size = $db->DoQuery("SELECT size FROM {$prefix}objects\n\t\t\t\t\t\tWHERE id='{$_POST['id']}'");
                $row_old_size = $db->Do_Fetch_Assoc($query_old_size);
                $db->DoQuery("UPDATE {$prefix}objects \n\t\t\t\t\t\tSET name='{$_POST['name']}',\n\t\t\t\t\t\t\tdescription='{$_POST['description']}',\n\t\t\t\t\t\t\tuses='{$_POST['uses']}',\n\t\t\t\t\t\t\timage_url='{$_POST['image_url']}',\n\t\t\t\t\t\t\tsize='{$_POST['size']}',\n\t\t\t\t\t\t\tbase_value='{$_POST['base_value']}',\n\t\t\t\t\t\t\tcategory='{$category}',\n\t\t\t\t\t\t\tvisible_uses='{$visible_uses}',\n\t\t\t\t\t\t\texpire_span='{$_POST['expire_span']}',\n\t\t\t\t\t\t\tshop_return = '{$shop_return}',\n\t\t\t\t\t\t\trandom_img = '{$_POST['random_img']}'\n\t\t\t\t\t\tWHERE id='{$_POST['id']}'");
                // Update not sold copies
                $db->DoQuery("UPDATE {$prefix}objects \n\t\t\t\t\t\tSET name='{$_POST['name']}',\n\t\t\t\t\t\t\tdescription='{$_POST['description']}',\n\t\t\t\t\t\t\tuses='{$_POST['uses']}',\n\t\t\t\t\t\t\timage_url='{$_POST['image_url']}',\n\t\t\t\t\t\t\tsize='{$_POST['size']}',\n\t\t\t\t\t\t\tbase_value='{$_POST['base_value']}',\n\t\t\t\t\t\t\tcategory='{$category}',\n\t\t\t\t\t\t\tvisible_uses='{$visible_uses}',\n\t\t\t\t\t\t\texpire_span='{$_POST['expire_span']}',\n\t\t\t\t\t\t\tshop_return = '{$shop_return}',\n\t\t\t\t\t\t\trandom_img = '{$_POST['random_img']}'\n\t\t\t\t\t\tWHERE name='{$old_name}' AND owner='{$shopper}'");
                // Sync existing objects
                // we do not sync uses
                if (isset($_POST['sync']) && $_POST['sync'] == 1) {
                    $db->DoQuery("UPDATE {$prefix}objects \n\t\t\t\t\t\t\tSET name = '{$_POST['name']}',\n\t\t\t\t\t\t\t\tdescription='{$_POST['description']}',\n\t\t\t\t\t\t\t\timage_url='{$_POST['image_url']}',\n\t\t\t\t\t\t\t\tsize='{$_POST['size']}',\n\t\t\t\t\t\t\t\tbase_value='{$_POST['base_value']}',\n\t\t\t\t\t\t\t\tcategory='{$category}',\n\t\t\t\t\t\t\t\tvisible_uses='{$visible_uses}',\n\t\t\t\t\t\t\t\texpire_span='{$_POST['expire_span']}',\n\t\t\t\t\t\t\t\tshop_return = '{$shop_return}',\n\t\t\t\t\t\t\t\trandom_img = '{$_POST['random_img']}'\n\t\t\t\t\t\t\tWHERE name='{$old_name}'");
                    $query_count_obj = $db->DoQuery("SELECT count(*) AS cnt\n\t\t\t\t\t\t\tFROM {$prefix}objects\n\t\t\t\t\t\t\tWHERE name='{$_POST['name']}'");
                    $row_count_obj = $db->Do_Fetch_Assoc($query_count_obj);
                    $error = "Modifica eseguita e sincronizzati {$row_count_obj['cnt']}\n\t\t\t\t\t\toggetti esistenti.";
                    if ($row_old_size && $row_old_size['size'] != $_POST['size']) {
                        if ($row_old_size['size'] >= 0) {
                            // Disequip the object if it had a positive value
                            $query_user_sync = $db->DoQuery("SELECT count(*) AS total\n\t\t\t\t\t\t\t\t\tFROM {$prefix}objects \n\t\t\t\t\t\t\t\t\tWHERE name='{$_POST['name']}'\n\t\t\t\t\t\t\t\t\tAND equipped = 1\n\t\t\t\t\t\t\t\t\tAND owner <> ''\n\t\t\t\t\t\t\t\t\tAND owner <> '{$shopper}'");
                            $db->DoQuery("UPDATE {$prefix}objects \n\t\t\t\t\t\t\t\t\tSET equipped = 0\n\t\t\t\t\t\t\t\t\tWHERE name='{$_POST['name']}'\n\t\t\t\t\t\t\t\t\tAND equipped = 1\n\t\t\t\t\t\t\t\t\tAND owner <> ''\n\t\t\t\t\t\t\t\t\tAND owner <> '{$shopper}'");
                            $row_user_sync = $db->Do_Fetch_Assoc($query_user_sync);
                            $error .= "<br>A {$row_user_sync['total']} utenti e' stato \n\t\t\t\t\t\t\t\tdisequipaggiato\tl'oggetto.";
                        } else {
                            // Disequip everything if the object had a negative value
                            $query_user_sync = $db->DoQuery("SELECT owner\n\t\t\t\t\t\t\t\t\tFROM {$prefix}objects \n\t\t\t\t\t\t\t\t\tWHERE equipped = 1\n\t\t\t\t\t\t\t\t\tAND name='{$_POST['name']}'\n\t\t\t\t\t\t\t\t\tAND owner <> ''\n\t\t\t\t\t\t\t\t\tAND owner <> '{$shopper}'");
                            $disequipped = 0;
                            while ($row_user_sync = $db->Do_Fetch_Assoc($query_user_sync)) {
                                if ($row_user_sync['owner'] != "" && $row_user_sync['owner'] != $shopper) {
                                    $db->DoQuery("UPDATE {$prefix}objects \n\t\t\t\t\t\t\t\t\t\t\tSET equipped = 0\n\t\t\t\t\t\t\t\t\t\t\tWHERE owner = '{$row_user_sync['owner']}'");
                                    $disequipped++;
                                }
                            }
                            $error .= "<br>A {$row_user_sync['total']} utenti e' stato \n\t\t\t\t\t\t\t\tdisequipaggiato tutto";
                        }
                    }
                }
            } else {
                $query_duplicate = $db->DoQuery("\n\t\t\t\t\tSELECT count(*) AS cnt FROM {$prefix}objects\n\t\t\t\t\t\tWHERE name='{$_POST['name']}' AND owner = ''");
                $row = $db->Do_Fetch_Assoc($query_duplicate);
                if ($row['cnt'] > 0) {
                    $error = "Oggetto gia' esistente";
                } else {
                    $db->DoQuery("INSERT INTO {$prefix}objects \n\t\t\t\t\t\t(name, description, uses, image_url,\n\t\t\t\t\t\t equipped, size, base_value, category, visible_uses, expire_span, \n\t\t\t\t\t\t shop_return,random_img)\n\t\t\t\t\t\tVALUES(\n\t\t\t\t\t\t\t'{$_POST['name']}',\t'{$_POST['description']}',\n\t\t\t\t\t\t\t'{$_POST['uses']}',\t'{$_POST['image_url']}',\n\t\t\t\t\t\t\t'1','{$_POST['size']}', '{$_POST['base_value']}', '{$category}', \n\t\t\t\t\t\t\t'{$visible_uses}', '{$_POST['expire_span']}', '{$shop_return}',\n\t\t\t\t\t\t\t'{$_POST['random_img']}'\n\t\t\t\t\t\t\t)");
                }
            }
            if (!isset($error) || $error == "") {
                $error = "Modifica eseguita con successo";
            }
        }
        if (isset($_GET['delete'])) {
            $name = '';
            get_obj_name_and_uses($_GET['delete'], $name, $uses);
            $db->DoQuery("DELETE FROM {$prefix}objects WHERE id='{$_GET['delete']}'");
            $db->DoQuery("DELETE FROM {$prefix}objects WHERE name='{$name}'\n\t\t\t\t\tAND owner='{$shopper}'");
            $error = "Oggetto eliminato";
        }
        if (isset($_GET['proom'])) {
            if (isset($_POST['owner']) && $_POST['owner'] != '') {
                $query = $db->DoQuery("SELECT username \n\t\t\t\t\t\tFROM {$prefix}users WHERE username='******'owner']}'");
                $row = $db->Do_Fetch_Assoc($query);
                if ($row == null || $row['username'] != $_POST['owner']) {
                    $body .= "Errore, utente {$_POST['owner']} non esistente";
                } else {
                    $query_rooms = $db->DoQuery("SELECT count(*) AS cnt\n\t\t\t\t\t\t\tFROM {$prefix}rooms WHERE name='{$_POST['owner']}'");
                    $query_obj_master = $db->DoQuery("SELECT count(*) AS cnt\n\t\t\t\t\t\t\tFROM {$prefix}objects WHERE name='masterkey_{$_POST['owner']}' \n\t\t\t\t\t\t\tAND owner=''");
                    $query_obj_user = $db->DoQuery("SELECT count(*) AS cnt\n\t\t\t\t\t\t\tFROM {$prefix}objects \n\t\t\t\t\t\t\tWHERE name='masterkey_{$_POST['owner']}' AND owner='{$_POST['owner']}'");
                    $row_rooms = $db->Do_Fetch_Assoc($query_rooms);
                    $row_obj_master = $db->Do_Fetch_Assoc($query_obj_master);
                    $row_obj_user = $db->Do_Fetch_Assoc($query_obj_user);
                    if ($row_rooms['cnt'] == 0) {
                        //Room creation
                        $db->DoQuery("INSERT INTO {$prefix}rooms\n\t\t\t\t\t\t\t\t(name, type, maxusers, logged, logo, long_name)\n\t\t\t\t\t\t\t\tVALUES ('{$_POST['owner']}', '2', '1000', '1',\n\t\t\t\t\t\t\t\t\t'./graphic/private_room.jpg','Stanza di {$_POST['owner']}')");
                        $body .= "Stanza creata con successo<br>";
                    } else {
                        $body .= "Stanza gi&agrave; presente<br>";
                    }
                    if ($row_obj_master['cnt'] == 0) {
                        //Copy of the key for the master
                        $db->DoQuery("INSERT INTO {$prefix}objects\n\t\t\t\t\t\t\t\t(name, description, uses, image_url, equipped, size, \n\t\t\t\t\t\t\t\t visible_uses)\n\t\t\t\t\t\t\t\tVALUES ('masterkey_{$_POST['owner']}',\n\t\t\t\t\t\t\t\t\t'Chiave della stanza di {$_POST['owner']}', '-1',\n\t\t\t\t\t\t\t\t\t'./graphic/private_key.jpg','1','0','1')");
                        $body .= "Copia master della chiave creata con successo<br>";
                    } else {
                        $body .= "Copia master della chiave gi&agrave; presente<br>";
                    }
                    if ($row_obj_user['cnt'] == 0) {
                        //Cooy of the key for the owner
                        $db->DoQuery("INSERT INTO {$prefix}objects\n\t\t\t\t\t\t\t\t(name, description, uses, image_url, owner, equipped, size,\n\t\t\t\t\t\t\t\t visible_uses)\n\t\t\t\t\t\t\t\tVALUES ('masterkey_{$_POST['owner']}',\n\t\t\t\t\t\t\t\t\t'Chiave della stanza di {$_POST['owner']}', '-1',\n\t\t\t\t\t\t\t\t\t'./graphic/private_key.jpg','{$_POST['owner']}','1','0', '1')");
                        $body .= "Copia utente della chiave creata con successo<br>";
                        include_once './lib/alarms.php';
                        object_assignement($_POST['owner'], "Chiave della stanza di {$_POST['owner']}");
                    } else {
                        $body .= "Copia utente della chiave master gi&agrave; presente<br>";
                    }
                }
                $body .= "<br><br><a href=\"index.php?act=adminpanel&cp_page=objects\">\n\t\t\t\t\t[Torna agli oggetti]</a>";
            } else {
                $body .= "\n\t\t\t\t\t<form action=\"index.php?act=adminpanel&cp_page=objects&proom=1\"\n\t\t\t\t\tmethod=\"post\">\n\t\t\t\t\t<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td>Nome del proprietario:</td>\n\t\t\t\t\t<td><input type=\"text\" name=\"owner\" class=\"text_input\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td><input type=\"submit\" class=\"button\" value=\"Vai\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t\t</form>\n\t\t\t\t\t";
            }
        }
        if (isset($_GET['edit'])) {
            $new_object = true;
            if ($_GET['edit'] != -1) {
                $new_object = false;
                $query = $db->DoQuery("SELECT * FROM {$prefix}objects \n\t\t\t\t\t\tWHERE id='{$_GET['edit']}'");
                $row = $db->Do_Fetch_Assoc($query);
                if (!$row) {
                    die("Error; should not die here");
                }
                if ($row['owner'] == $shopper) {
                    $query = $db->DoQuery("SELECT * FROM {$prefix}objects \n\t\t\t\t\t\t\tWHERE name='{$row['name']}' AND owner = ''");
                    $row = $db->Do_Fetch_Assoc($query);
                    if (!$row) {
                        die("Error; should not die here");
                    }
                }
            } else {
                $row['name'] = '';
                $row['owner'] = '';
                $row['description'] = '';
                $row['uses'] = -1;
                $row['image_url'] = '';
                $row['id'] = -1;
                $row['size'] = 0;
                $row['base_value'] = -1;
                $row['category'] = '';
                $row['visible_uses'] = '';
                $row['expire_span'] = '-1';
                $row['shop_return'] = '0';
                $row['random_img'] = '';
            }
            $minuscolo = "";
            $piccolo = "";
            $c_piccolo = "";
            $medio = "";
            $c_medio = "";
            $grande = "";
            $c_grande = "";
            $visible_uses_checked = '';
            $shop_return_checked = '';
            if ($row['visible_uses']) {
                $visible_uses_checked = "checked";
            }
            if ($row['shop_return']) {
                $shop_return_checked = "checked";
            }
            switch ($row['size']) {
                case 0:
                    $minuscolo = "selected";
                    break;
                case 1:
                    $piccolo = "selected";
                    break;
                case 2:
                    $medio = "selected";
                    break;
                case 5:
                    $grande = "selected";
                    break;
                case -1:
                    $c_piccolo = "selected";
                    break;
                case -2:
                    $c_medio = "selected";
                    break;
                case -5:
                    $c_grande = "selected";
                    break;
            }
            $query_cat = $db->DoQuery("SELECT DISTINCT category \n\t\t\t\t\tFROM {$prefix}objects\n\t\t\t\t\tORDER BY category");
            $category_form = '<select class="button" name="category"
				onChange="javascript: category_select(this);">
				<option value="">Seleziona la categoria</option>';
            while ($row_category = $db->Do_Fetch_Assoc($query_cat)) {
                if ($row_category['category']) {
                    $selected = "";
                    if ($row_category['category'] == $row['category']) {
                        $selected = "selected";
                    }
                    $category_form .= '<option value="' . $row_category['category'] . '" 
						' . $selected . '>' . $row_category['category'] . '</option>';
                }
            }
            $category_form .= '<option value="_new_">-Crea nuova categoria-</option>
				</select>';
            $name_type = "text";
            if ($row['name'] == $money_name) {
                $name_type = "hidden";
            }
            $submit_value = "Crea oggetto";
            $sync_button = '';
            if (!$new_object) {
                $submit_value = "Modifica oggetto";
                $sync_button = "<td><input type=\"button\" class=\"button\" \n\t\t\t\tvalue=\"Modifica e sincronizza\" onClick=\"sync_request();\"></td></tr>\n\t\t\t\t<tr><td>&nbsp;</td><td>\n\t\t\t\t<br>Con questo tasto le modifiche dell'oggetto vengono \n\t\t\t\t<br>riflesse anche alle copie gia' assegnate.\n\t\t\t\t<br>Gli usi rimanenti non vengono mai riassegnati.\n\t\t\t\t<br>Tutti gli oggetti modificati vengono disequipaggiati.</td>\n\t\t\t\t</td>";
            }
            $body .= "\n\t\t\t\t<script language=\"javascript\" type=\"text/javascript\">\n\t\t\t\t  function sync_request() {\n\t\t\t\t\t\tdocument.getElementById('sync_field').value = 1;\n\t\t\t\t\t\tdocument.forms.main_form.submit();\n\t\t\t\t\t}\n\t\t\t\t\tfunction category_select(elem) {\n\t\t\t\t\t\tif (elem.options[elem.selectedIndex].value == '_new_'){\n\t\t\t\t\t\t\tdocument.getElementById('new_category').style.visibility = \n\t\t\t\t\t\t\t\t'visible';\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tdocument.getElementById('new_category').style.visibility =\n\t\t\t\t\t\t\t\t'hidden';\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t</script>\n\t\t\t\t<form action=\"index.php?act=adminpanel&cp_page=objects&modify=1\"\n\t\t\t\tmethod=\"post\" name=\"main_form\">\n\t\t\t\t<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n\t\t\t\t<input type=\"hidden\" name=\"id\" value=\"{$row['id']}\">\n\t\t\t\t<tr>\n\t\t\t\t<td>Nome:</td>\n\t\t\t\t<td><input type=\"{$name_type}\" name=\"name\" class=\"text_input\"\n\t\t\t\tvalue=\"{$row['name']}\"></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td>Descrizione:</td>\n\t\t\t\t<td><textarea cols=\"30\" rows=\"10\" type=\"text\" name=\"description\"\n\t\t\t\tclass=\"text_input\">{$row['description']}</textarea></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td>\n\t\t\t  Cartella per immagine random:\n\t\t\t\t</td>\n\t\t\t\t<td>\n\t\t\t\t<input type=\"text\" name=\"random_img\" class=\"text_input\"\n\t\t\t\tvalue=\"{$row['random_img']}\">\n\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td>Usi (-1 per usi infiniti):</td>\n\t\t\t\t<td><input type=\"text\" name=\"uses\" class=\"text_input\"\n\t\t\t\tvalue=\"{$row['uses']}\"></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td>Gli usi rimasti sono visibili?\n\t\t\t\t</td>\n\t\t\t\t<td><input type=\"checkbox\" class=\"text_input\" name=\"visible_uses\" {$visible_uses_checked}>\n\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td>Scadenza in minuti (-1: no scadenza)\n\t\t\t\t</td>\n\t\t\t\t<td><input type=\"text\" class=\"text_input\" name=\"expire_span\" \n\t\t\t\tvalue=\"{$row['expire_span']}\">\n\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td>Torna in vendita dopo la scadenza?\n\t\t\t\t</td>\n\t\t\t\t<td><input type=\"checkbox\" class=\"text_input\" name=\"shop_return\" {$shop_return_checked}>\n\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td>URL immagine:</td>\n\t\t\t\t<td><input type=\"text\" name=\"image_url\" class=\"text_input\"\n\t\t\t\tvalue=\"{$row['image_url']}\"\n\t\t\t\tonChange=\"javascript: document.getElementById('objImg').src=this.value;\"></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td>Preview:</td>\n\t\t\t\t<td><img id=\"objImg\" src=\"{$row['image_url']}\"></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr><td><a onClick=\"" . popup_open($x7c->settings['tweak_window_large_width'], $x7c->settings['tweak_window_large_height'], 'index.php?act=images', 'Images', "yes") . ";\">[Carica immagine]</a></td></tr>\n\t\t\t\t<tr>\n\t\t\t\t<td>Dimesione:</td>\n\t\t\t\t<td><select class=\"button\" name=\"size\">\n\t\t\t\t<option value=\"0\" {$minuscolo}>Minuscolo</option>\n\t\t\t\t<option value=\"1\" {$piccolo}>Piccolo</option>\n\t\t\t\t<option value=\"2\" {$medio}>Medio</option>\n\t\t\t\t<option value=\"5\" {$grande}>Grande</option>\n\t\t\t\t<option value=\"-1\" {$c_piccolo}>Capienza Piccola</option>\n\t\t\t\t<option value=\"-2\" {$c_medio}>Capienza Media</option>\n\t\t\t\t<option value=\"-5\" {$c_grande}>Capienza Grande</option>\n\t\t\t\t</select>\n\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td>\n\t\t\t\tValore base di vendita:\n\t\t\t\t</td>\n\t\t\t\t<td>\n\t\t\t\t<input type=\"text\" name=\"base_value\" class=\"text_input\"\n\t\t\t\tvalue=\"{$row['base_value']}\">\n\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td>Categoria</td>\n\t\t\t\t<td>{$category_form}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr id=\"new_category\" style=\"visibility: hidden;\">\n\t\t\t\t<td>Nuova categoria:</td>\n\t\t\t\t<td><input type=\"text\" class=\"text_input\" name=\"new_category\">\n\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<input id=\"sync_field\" type=\"hidden\" name=\"sync\" value=\"0\">\n\t\t\t\t<td><input type=\"submit\" class=\"button\" value=\"{$submit_value}\"></td>\n\t\t\t\t{$sync_button}\n\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t\t";
            $body .= "</form>";
            if ($_GET['edit'] != -1) {
                if ($row['name'] != $money_name) {
                    $body .= "\n\t\t\t\t\t\t<form action=\"index.php?act=adminpanel&cp_page=objects&assign=1\"\n\t\t\t\t\t\tmethod=\"post\">\n\t\t\t\t\t\t<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n\t\t\t\t\t\t<input type=\"hidden\" name=\"id\" value=\"{$row['id']}\">\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t<hr>\n\t\t\t\t\t\t<td>Assegna a:</td>\n\t\t\t\t\t\t<td><input type=\"text\" name=\"owner\" class=\"text_input\"></td>\n\t\t\t\t\t\t<td>Quantita'</td>\n\t\t\t\t\t\t<td><input type=\"text\" size=\"5\" name=\"qty\"\n\t\t\t\t\t\t       class=\"text_input\" value=\"1\"></td>\n\t\t\t\t\t\t<td><input type=\"submit\" class=\"button\" value=\"Assegna\"></div>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>\n\t\n\t\t\t\t\t\t</table>\n\t\t\t\t\t</form>";
                    $availability = get_obj_availability($row['name']);
                    if ($x7c->permissions["admin_panic"]) {
                        $body .= "<form action=\"index.php?act=adminpanel&cp_page=objects&sell=1\"\n\t\t\t\t\t\t\tmethod=\"post\">\n\t\t\t\t\t\t\t<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n\t\t\t\t\t\t\t<input type=\"hidden\" name=\"id\" value=\"{$row['id']}\">\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<hr>\n\t\t\t\t\t\t\t<td>Copie in negozio:</td>\n\t\t\t\t\t\t\t<td><input type=\"text\" name=\"sell_copies\" class=\"text_input\"\n\t\t\t\t\t\t\tvalue=\"{$availability}\"></td>\n\t\t\t\t\t\t\t<td><input type=\"submit\" class=\"button\"\n\t\t\t\t\t\t\tvalue=\"Metti in vendita\"></div></td>\n\t\t\t\t\t\t\t</tr>\n\t\n\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t\t</form>";
                    }
                }
            }
        } else {
            if (!isset($_GET['proom'])) {
                $letter = 'AND name LIKE \'a%\'';
                if (isset($_GET['letter'])) {
                    $letter = "AND name LIKE '" . $_GET['letter'] . "%'";
                }
                if (isset($_POST['letter'])) {
                    $letter = "AND name LIKE '%" . $_POST['letter'] . "%'";
                }
                if (isset($_GET['category'])) {
                    $letter = "AND category LIKE '{$_GET['category']}'";
                }
                if (!isset($_POST['selling'])) {
                    $query = $db->DoQuery("SELECT * FROM {$prefix}objects \n\t\t\t\t\t\tWHERE owner='' {$letter} ORDER BY category, name");
                } else {
                    $query = $db->DoQuery("SELECT * FROM {$prefix}objects \n\t\t\t\t\t\tWHERE owner='{$shopper}' {$letter}\n\t\t\t\t\t\tAND name <> '{$money_name}'\n\t\t\t\t\t\tGROUP BY name\n\t\t\t\t\t\tORDER BY category, name");
                }
                $body = "<b style=\"color: orange;\">{$error}</b><br><br>";
                $body .= "<div align=\"center\"><input type=\"submit\"\n\t\t\t\tvalue=\"Crea nuovo oggetto\" class=\"button\"\n\t\t\t\tonClick=\"javascript: window.location.href='index.php?act=adminpanel&cp_page=objects&edit=-1'\"> &nbsp;\n\t\t\t\t<input type=\"submit\" value=\"Crea stanza privata\" class=\"button\"\n\t\t\t\tonClick=\"javascript: window.location.href='index.php?act=adminpanel&cp_page=objects&proom=1'\"></div>";
                $sell_checked = isset($_POST['selling']) ? "checked" : "";
                $body .= "<div align=\"center\"><br><b>Cerca oggetto</b></div><Br>\n\t\t\t\t<form action=\"index.php?act=adminpanel&cp_page=objects\"\n\t\t\t\tmethod=\"post\" name=\"quicke\">\n\t\t\t\t<table align=\"center\" border=\"0\" cellspacing=\"0\"\n\t\t\t\tcellpadding=\"0\">\n\t\t\t\t<tr>\n\t\t\t\t<td>Nome oggetto:</td>\n\t\t\t\t<td><input type=\"text\" name=\"letter\" class=\"text_input\"></td>\n\t\t\t\t<td><div align=\"center\"><input type=\"submit\" value=\"Cerca\"\n\t\t\t\tclass=\"button\"></div></td>\n\t\t\t\t<td>\n\t\t\t\t<input type=\"checkbox\" name=\"selling\" {$sell_checked}>\n\t\t\t\tOggetti in vendita</input>\n\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t\t</form>";
                $body .= " <p style=\"text-align: center;\">\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=objects&letter=a\">[a]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=objects&letter=b\">[b]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=objects&letter=c\">[c]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=objects&letter=d\">[d]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=objects&letter=e\">[e]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=objects&letter=f\">[f]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=objects&letter=g\">[g]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=objects&letter=h\">[h]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=objects&letter=i\">[i]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=objects&letter=j\">[j]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=objects&letter=k\">[k]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=objects&letter=l\">[l]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=objects&letter=m\">[m]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=objects&letter=n\">[n]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=objects&letter=o\">[o]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=objects&letter=p\">[p]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=objects&letter=q\">[q]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=objects&letter=r\">[r]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=objects&letter=s\">[s]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=objects&letter=t\">[t]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=objects&letter=u\">[u]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=objects&letter=v\">[v]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=objects&letter=w\">[w]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=objects&letter=x\">[x]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=objects&letter=y\">[y]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=objects&letter=z\">[z]</a>\n\t\t\t\t</p>\n\t\t\t\t";
                $query_category = $db->DoQuery("SELECT DISTINCT category\n\t\t\t\t\tFROM {$prefix}objects ORDER BY category");
                $body .= " <p style=\"text-align: center;\">";
                $count = 0;
                while ($row_category = $db->Do_Fetch_Assoc($query_category)) {
                    $count++;
                    $long_name = $row_category['category'];
                    if (!$row_category['category']) {
                        $long_name = "Senza categoria";
                    }
                    $body .= "<a href=\"index.php?act=adminpanel&cp_page=objects&category=" . $row_category['category'] . "\">[{$long_name}]</a>";
                    if ($count % 5 == 0) {
                        $body .= "<br>";
                    }
                }
                $body .= "</p>";
                $body .= '<table width="100%">
				<tr><td><b>Nome oggetto:</b></td><td style="width=10%"><b>Azioni</b>
				</td></tr>
				<tr><td colspan=2><hr></td></tr>';
                if (isset($_GET['letter']) || isset($_POST['letter']) || isset($_GET['category'])) {
                    while ($row = $db->Do_Fetch_Assoc($query)) {
                        $size = "";
                        switch ($row['size']) {
                            case 0:
                                $size = "(minuscolo)";
                                break;
                            case 1:
                                $size = "(piccolo)";
                                break;
                            case 2:
                                $size = "(medio)";
                                break;
                            case 5:
                                $size = "(grande)";
                                break;
                            case -1:
                                $size = "(capienza piccola)";
                                break;
                            case -2:
                                $size = "(capienza media)";
                                break;
                            case -5:
                                $size = "(capienza grande)";
                                break;
                            default:
                                $size = "(IMPOSSIBLE SIZE)";
                        }
                        $category = '';
                        if ($row['category']) {
                            $category = $row['category'] . ": ";
                        }
                        $body .= "<tr><td>\n\t\t\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=objects&edit={$row['id']}\">\n\t\t\t\t\t\t{$category}{$row['name']}</a> {$size}</td>";
                        if ($row['name'] != $money_name) {
                            $body .= "<td style=\"width=10%\">\n\t\t\t\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=objects&delete={$row['id']}\">\n\t\t\t\t\t\t\t[Cancella]</a></td>";
                        }
                        $body .= "</tr><tr><td colspan=2><hr></td></tr>";
                    }
                }
                $body .= '</table>';
            }
        }
    } elseif ($_GET['cp_page'] == "money") {
        include_once './lib/shop_lib.php';
        global $shopper, $base_money;
        $head = "Gestione economia";
        $body = "";
        $error = "";
        if (isset($_GET['emit']) && isset($_POST['amount'])) {
            if ($_POST['amount'] < 0) {
                $emit_value = -$_POST['amount'];
                $shopper_money = get_total_user_money($shopper);
                if ($shopper_money < $emit_value) {
                    $error = "Non puoi ritirare piu' moneta delle attuali riserve";
                } else {
                    remove_money($emit_value, $shopper);
                    $error = "Moneta ritirata con successo: {$emit_value}";
                }
            } else {
                assign_money($_POST['amount'], $shopper);
                $error = "Moneta emessa con successo: {$_POST['amount']}";
            }
        }
        if (isset($_GET['pay']) && isset($_POST['amount'])) {
            $amount = $_POST['amount'];
            if ($amount < 0) {
                $error = "Valore negativo non permesso";
            }
            if (isset($_POST['username']) && $_POST['username']) {
                if ($_POST['username'] == '__all__') {
                    $recent = time() - 3600 * 24 * 60;
                    # Two months
                    $query = $db->DoQuery("SELECT username FROM {$prefix}users\n\t\t\t\t\t\t\tWHERE time > {$recent} ORDER BY username");
                    $error = '';
                    while ($row = $db->Do_Fetch_Assoc($query)) {
                        $error .= $row['username'] . '<br>';
                        pay($amount, $shopper, $row['username']);
                    }
                } else {
                    $query = $db->DoQuery("SELECT username FROM {$prefix}users\n\t\t\t\t\t\t\tWHERE username='******'username']}'");
                    $row_usr = $db->Do_Fetch_Assoc($query);
                    if (!$row_usr) {
                        $error = "Utente non esistente";
                    }
                }
            }
            // Parameters are ok
            if (!$error) {
                $error = pay($amount, $shopper, $_POST['username']);
            }
        }
        $body = "<b style=\"color: orange;\">{$error}</b><br><br>";
        $body .= "<table width=50%>";
        $total_money = get_total_money();
        $body .= "<tr><td><b style=\"color: yellow;\">\n\t\t\tTotale moneta:</b></td><td align=\"right\">{$total_money}</b></td></tr>";
        $shopper_money = get_total_user_money($shopper);
        $body .= "<tr><td><b style=\"color: blue;\">\n\t\t\tRiserve:</b></td><td align=\"right\"> {$shopper_money}</b></td></tr>";
        $users_money = $total_money - $shopper_money;
        $body .= "<tr><td><b style=\"color: green;\">\n\t\t\tMoneta in circolo:</b></td><td align=\"right\">{$users_money}</td></tr>";
        $infl_factor = 100 * ($total_money / $base_money - 1);
        $body .= "<tr><td><b style=\"color: maroon;\">\n\t\t\tInflazione:</b></td><td align=\"right\">{$infl_factor}%</td></tr>";
        $body .= "</table>";
        $body .= "<table width=50%>";
        $body .= '<form action="./index.php?act=adminpanel&cp_page=money&emit"
				method="post">
				<tr>
				<td>Emetti moneta:</td>
				<td><input type="text" name="amount" class="text_input"></td>
				<td><div align="center"><input type="submit" value="Emetti"
				class="button"></div></td>
				</tr>
				<tr><td colspan=3>
				Puoi immettere un valore negativo per ritirare della moneta.
				<p><b>ATTENZIONE! Emettere o ritirare moneta modifica l\'inflazione
				e dunque i costi di tutti gli oggetti</b></p>
				</td></tr>
				</form>';
        $body .= '<form action="./index.php?act=adminpanel&cp_page=money&pay"
				method="post">
				<tr><td>&nbsp;</td></tr>
				<tr><td>&nbsp;</td></tr>
				<tr>
				<td>Paga giocatore:</td>
				<td><input type="text" name="username" class="text_input"></td>
				</tr>
				<tr>
				<td>Ammontare:</td>
				<td><input type="text" name="amount" class="text_input"></td>
				<td><div align="center"><input type="submit" value="Paga"
				class="button"></div></td>
				</tr>
				<tr><td colspan=3>
				<b>I soldi verranno prelevati dalle riserve.</b>
				</td></tr>
				</form>';
        $body .= '<form action="./index.php?act=adminpanel&cp_page=money&pay"
				method="post">
				<tr><td>&nbsp;</td></tr>
				<tr><td>&nbsp;</td></tr>
				<tr>
				<td>Paga tutti (verrano pagati solo i giocatori che si sono collegati 
						nei due mesi precedenti):</td>
				<td><input type="hidden" name="username" value="__all__">
				<input type="text" name="amount" class="text_input"></td>
				<td><div align="center"><input type="submit" value="Paga"
				class="button"></div></td>
				</tr>
				<tr><td colspan=3>
				<b>I soldi verranno prelevati dalle riserve.</b>
				</td></tr>
				</form>';
        $body .= "</table>";
    } elseif ($_GET['cp_page'] == "users") {
        $head = $txt[310];
        if (isset($_GET['delete'])) {
            // Check for confirmation
            if (!isset($_GET['confirm'])) {
                // Request confirmation
                $body = "<div align=\"center\">{$txt['461']}<Br>\n\t\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=users&delete={$_GET['delete']}&confirm=yes\">{$txt['392']}</a> | \n\t\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=users\">{$txt['393']}</a>\n\t\t\t\t\t</div>";
            } else {
                // Do the delete
                include_once './lib/cleanup.php';
                delete_user($_GET["delete"]);
                $body = "<div align=\"center\">{$txt['462']}<Br><a href=\"index.php?act=adminpanel&cp_page=users\">{$txt['77']}</a></div>";
            }
        } elseif (isset($_GET['edit'])) {
            // Display the form for editing the user
            // Get defaults
            $def = new profile_info($_GET['edit']);
            if ($def->profile['id'] == "") {
                // Nonexistant user
                $body = "<div align=\"center\">{$txt['463']}<Br><a href=\"index.php?act=adminpanel&cp_page=users\">{$txt['77']}</a></div>";
            } else {
                // Get the default user group
                $base_group_options = "";
                $possible_groups = array('Umano', 'NeoUmano', 'NephEl', 'ElBeth');
                foreach ($possible_groups as $cur_p_group) {
                    if ($cur_p_group == $def->profile['base_group']) {
                        $base_group_options .= "<input type=\"radio\" name=\"basegroup\" value=\"{$cur_p_group}\" checked>{$cur_p_group}<br>";
                    } else {
                        $base_group_options .= "<input type=\"radio\" name=\"basegroup\" value=\"{$cur_p_group}\">{$cur_p_group}<br>";
                    }
                }
                $query = $db->DoQuery("SELECT usergroup FROM {$prefix}permissions \n\t\t\t\t\t\tWHERE gremios=0 ORDER BY usergroup");
                $group_options = "";
                while ($row = $db->Do_Fetch_Row($query)) {
                    if (in_array($row[0], $def->profile['usergroup'])) {
                        $group_options .= "<input type=\"checkbox\" name=\"{$row['0']}\" value=\"{$row['0']}\" checked>{$row['0']}<br>";
                    } else {
                        $group_options .= "<input type=\"checkbox\" name=\"{$row['0']}\" value=\"{$row['0']}\">{$row['0']}<br>";
                    }
                }
                $query = $db->DoQuery("SELECT usergroup FROM {$prefix}permissions \n\t\t\t\t\t\tWHERE gremios=1 ORDER BY usergroup");
                while ($row = $db->Do_Fetch_Row($query)) {
                    if (in_array($row[0], $def->profile['usergroup'])) {
                        $group_options .= "<input type=\"radio\" name=\"gremios\" value=\"{$row['0']}\" checked>{$row['0']}<br>";
                    } else {
                        $group_options .= "<input type=\"radio\" name=\"gremios\" value=\"{$row['0']}\">{$row['0']}<br>";
                    }
                }
                $body = "<Br>\n\t\t\t\t\t<form action=\"index.php?act=adminpanel&cp_page=users&update={$_GET['edit']}\" method=\"post\" name=\"profileform\">\n\t\t\t\t\t<table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"60\">{$txt['2']}:</td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" name=\"username\" class=\"text_input\" value=\"{$def->profile['username']}\"></td>\n\t\t\t\t\t</tr>\n\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"60\">{$txt['3']}:</td>\n\t\t\t\t\t<td width=\"100\"><input type=\"password\" name=\"pass1\" class=\"text_input\"></td>\n\t\t\t\t\t</tr>\n\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"60\">{$txt['21']}:</td>\n\t\t\t\t\t<td width=\"100\"><input type=\"password\" name=\"pass2\" class=\"text_input\"></td>\n\t\t\t\t\t</tr>\n\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"60\">{$txt['20']}:</td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" name=\"email\" class=\"text_input\" value=\"{$def->profile['email']}\"></td>\n\t\t\t\t\t</tr>\n\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"60\">{$txt['31']}:</td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" name=\"rname\" class=\"text_input\" value=\"{$def->profile['name']}\"></td>\n\t\t\t\t\t</tr>\n\n\t\t\t\t\t<!--\n\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"60\">{$txt['121']}:</td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" name=\"location\" class=\"text_input\" value=\"{$def->profile['location']}\"></td>\n\t\t\t\t\t</tr>\n\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"60\">{$txt['122']}:</td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" name=\"hobbies\" class=\"text_input\" value=\"{$def->profile['hobbies']}\"></td>\n\t\t\t\t\t</tr>\n\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"60\">{$txt['186']}:</td>\n\t\t\t\t\t<td width=\"100\">\n\t\t\t\t\t<select name=\"gender\" class=\"text_input\">\n\t\t\t\t\t<option value=\"0\" ";
                $body .= $def->profile['gender'] == 0 ? "selected=true" : "";
                $body .= ">{$txt['191']}</option>\n\t\t\t\t\t<option value=\"1\" ";
                $body .= $def->profile['gender'] == 1 ? "selected=true" : "";
                $body .= ">{$txt['189']}</option>\n\t\t\t\t\t<option value=\"2\" ";
                $body .= $def->profile['gender'] == 2 ? "selected=true" : "";
                $body .= ">{$txt['190']}</option>\n\n\t\t\t\t\t</select>\n\t\t\t\t\t</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t-->\n\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"60\">Avatar: </td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" name=\"avatar\" class=\"text_input\" value=\"{$def->profile['avatar']}\"></td>\n\t\t\t\t\t</tr>\n\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"60\">Gif gremios:</td>\n\t\t\t\t\t<td width=\"100\"><input type=\"text\" class=\"text_input\" name=\"bio\" cols=\"18\" value=\"{$def->profile['bio']}\"></td>\n\t\t\t\t\t</tr>\n\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td>Override group gif</td><td><input type=\"checkbox\" name=\"override\" value=\"1\"></td>\n\t\t\t\t\t</tr>\n\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"60\">Gruppo base: </td>\n\t\t\t\t\t<td width=\"100\">{$base_group_options}</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"60\"><hr></td>\n\t\t\t\t\t<td width=\"100\"><hr></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"60\">{$txt['309']}: </td>\n\t\t\t\t\t<td width=\"100\">{$group_options}</td>\n\t\t\t\t\t</tr>\n\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td>Congelato:</td><td><input type=\"checkbox\" name=\"frozen\" value=\"1\" ";
                $body .= $def->profile['frozen'] == 1 ? "checked" : "";
                $body .= "></td>\n\t\t\t\t\t</tr>\n\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td width=\"160\" colspan=\"2\"><div align=\"center\"><input type=\"submit\" value=\"{$txt['187']}\" class=\"button\"></div></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t</table><Br>";
            }
        } elseif (isset($_GET['update'])) {
            // Update the user
            // Check passwords first
            if ($_POST['pass1'] != $_POST['pass2']) {
                $body = "<div align=\"center\">{$txt['26']}<Br><a href=\"javascript: history.back();\">{$txt['77']}</a></div>";
            } else {
                // Update is 100% ok to do, passwords match and user exists
                // Check to see if pass was blank, if so then don't change it
                if ($_POST['pass1'] != "") {
                    // Change their password
                    change_pass($_GET['update'], $_POST['pass1']);
                }
                $frozen = 0;
                if (isset($_POST['frozen'])) {
                    $frozen = 1;
                }
                $time = time();
                $ok = true;
                if ($_GET['update'] != $_POST['username']) {
                    $u_query = $db->DoQuery("SELECT count(*) AS cnt FROM {$prefix}users WHERE username='******'username']}'");
                    $row = $db->Do_Fetch_Assoc($u_query);
                    if ($row['cnt'] > 0) {
                        $body = "<div align=\"center\">Errore: Nome utente gia' in uso<Br><a href=\"index.php?act=adminpanel&cp_page=users\">{$txt['77']}</a></div>";
                        $ok = false;
                    }
                }
                if ($ok) {
                    $error_group = "";
                    include_once './lib/sheet_lib.php';
                    $base_group = get_base_group($_GET['update']);
                    $db->DoQuery("UPDATE {$prefix}users SET time='{$time}',\n\t\t\t\t\t\t\tuser_group='{$base_group}', \n\t\t\t\t\t\t\temail='{$_POST['email']}',avatar='{$_POST['avatar']}',\n\t\t\t\t\t\t\tname='{$_POST['rname']}',bio='{$_POST['bio']}',\n\t\t\t\t\t\t\tusername='******'username']}', m_invisible = '0', \n\t\t\t\t\t\t\tfrozen='{$frozen}', base_group='{$_POST['basegroup']}'\n\t\t\t\t\t\t\tWHERE username='******'update']}'");
                    $db->DoQuery("DELETE FROM {$prefix}groups WHERE username='******'update']}'");
                    $error_group .= join_corp($_GET['update'], $base_group);
                    $query_group = $db->DoQuery("SELECT usergroup FROM {$prefix}permissions");
                    while ($row_g = $db->Do_Fetch_Assoc($query_group)) {
                        if (isset($_POST[$row_g['usergroup']])) {
                            $error_group .= join_corp($_GET['update'], $row_g['usergroup']);
                        }
                    }
                    if (isset($_POST['gremios'])) {
                        $error_group .= join_corp($_GET['update'], $_POST['gremios']);
                    }
                    if (isset($_POST['override'])) {
                        $db->DoQuery("UPDATE {$prefix}users SET bio='{$_POST['bio']}' WHERE username='******'update']}'");
                    }
                    $db->DoQuery("UPDATE {$prefix}bandwidth SET user='******'username']}' WHERE user='******'update']}'");
                    $db->DoQuery("UPDATE {$prefix}userability SET username='******'username']}' WHERE username='******'update']}'");
                    $db->DoQuery("UPDATE {$prefix}usercharact SET username='******'username']}' WHERE username='******'update']}'");
                    $db->DoQuery("UPDATE {$prefix}objects SET owner='{$_POST['username']}' WHERE owner='{$_GET['update']}'");
                    $db->DoQuery("UPDATE {$prefix}boardmsg SET user='******'username']}' WHERE user='******'update']}'");
                    $db->DoQuery("UPDATE {$prefix}boardunread SET user='******'username']}' WHERE user='******'update']}'");
                    $db->DoQuery("UPDATE {$prefix}messages SET user='******'username']}' WHERE user='******'update']}'");
                    $body = "<div align=\"center\">{$error_group}<br>{$txt['464']}<Br><a href=\"index.php?act=adminpanel&cp_page=users\">{$txt['77']}</a></div>";
                }
            }
        } else {
            // Display all users
            $body = "<Br><div align=\"center\"><b>{$txt['460']}</b></div><Br>\n\t\t\t\t<form action=\"index.php?act=adminpanel&cp_page=users\" method=\"post\" name=\"quicke\">\n\t\t\t\t<table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n\t\t\t\t<tr>\n\t\t\t\t<td>{$txt['2']}: </td>\n\t\t\t\t<td><input type=\"text\" name=\"user\" class=\"text_input\"></td>\n\t\t\t\t<td><div align=\"center\"><input type=\"submit\" value=\"Cerca\" class=\"button\"></div></td>\n\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t\t</form>\n\t\t\t\t<Br>";
            $body .= " <p style=\"text-align: center;\">\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=users&letter=a\">[a]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=users&letter=b\">[b]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=users&letter=c\">[c]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=users&letter=d\">[d]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=users&letter=e\">[e]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=users&letter=f\">[f]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=users&letter=g\">[g]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=users&letter=h\">[h]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=users&letter=i\">[i]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=users&letter=j\">[j]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=users&letter=k\">[k]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=users&letter=l\">[l]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=users&letter=m\">[m]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=users&letter=n\">[n]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=users&letter=o\">[o]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=users&letter=p\">[p]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=users&letter=q\">[q]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=users&letter=r\">[r]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=users&letter=s\">[s]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=users&letter=t\">[t]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=users&letter=u\">[u]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=users&letter=v\">[v]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=users&letter=w\">[w]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=users&letter=x\">[x]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=users&letter=y\">[y]</a>\n\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=users&letter=z\">[z]</a>\n\t\t\t\t</p>\n\t\t\t\t";
            $body .= "\t\t<table width=\"95%\" align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"col_header\">\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"33%\" height=\"25\">&nbsp;{$txt['2']}</td>\n\t\t\t\t<td width=\"33%\" height=\"25\">{$txt['123']}</td>\n\t\t\t\t<td height=\"25\">{$txt['86']}</td>\n\t\t\t\t</tr>\n\t\t\t\t</table>";
            $search = '';
            if (isset($_GET['letter'])) {
                $search = "{$_GET['letter']}%";
            }
            if (isset($_POST['user'])) {
                $search = "%{$_POST['user']}%";
            }
            $body .= "<table width=\"95%\" align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"inside_table\">";
            // Pages
            $query = $db->DoQuery("SELECT * FROM {$prefix}users WHERE username LIKE '{$search}' ORDER BY username ASC");
            while ($row = $db->Do_Fetch_Row($query)) {
                $query_g = $db->DoQuery("SELECT usergroup FROM {$prefix}groups WHERE username='******'1']}' ORDER BY usergroup");
                $gr = "";
                while ($row_g = $db->Do_Fetch_Assoc($query_g)) {
                    $gr .= $row_g['usergroup'] . "; ";
                }
                $body .= "<tr>\n\t\t\t\t\t<td width=\"33%\" ><a href=\"#\" onClick=\"javascript: hndl=window.open('index.php?act=sheet&pg={$row[1]}','sheet_other','width=500,height=680, toolbar=no, status=yes, location=no, menubar=no, resizable=no, status=yes'); hndl.focus();\">{$row['1']}</a></td>\n\t\t\t\t\t<td width=\"33%\">{$gr}</td>\n\t\t\t\t\t<td><a href=\"index.php?act=adminpanel&cp_page=users&edit={$row['1']}\">[{$txt['459']}]</a> <a href=\"index.php?act=adminpanel&cp_page=users&delete={$row['1']}\">[{$txt['175']}]</a></td>\n\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr><td colspan=\"3\"><hr></td></tr>";
            }
            $body .= "</table>";
        }
    } elseif ($_GET['cp_page'] == "rooms") {
        // Manage rooms, allow for editing, deleteing, but not renaming
        $head = $txt[311];
        if (isset($_GET['delete'])) {
            // They want to delete a room, make sure that is ok
            if (!isset($_GET['confirm'])) {
                // Make it so admins can't delete a room being used by single-room mode
                if ($x7c->settings['single_room_mode'] != $_GET['delete']) {
                    $body = "<div align=\"center\">{$txt['465']}<Br>\n\t\t\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=rooms&delete={$_GET['delete']}&confirm=yes\">{$txt['392']}</a> | \n\t\t\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=rooms\">{$txt['393']}</a>\n\t\t\t\t\t\t</div>";
                } else {
                    $body = "{$txt['594']}<Br><Br><a href=\"index.php?act=adminpanel&cp_page=rooms\">{$txt['77']}</a>";
                }
            } else {
                // Ok, delete the room
                $body = "<div align=\"center\">{$txt['466']}<Br><a href=\"index.php?act=adminpanel&cp_page=rooms\">{$txt['77']}</a></div>";
                // Get the room id
                $query = $db->DoQuery("SELECT id FROM {$prefix}rooms WHERE name='{$_GET['delete']}'");
                $row = $db->Do_Fetch_Row($query);
                $id = $row[0];
                // Delete the room
                $db->DoQuery("DELETE FROM {$prefix}rooms WHERE name='{$_GET['delete']}'");
                // Delete room messages
                $db->DoQuery("DELETE FROM {$prefix}messages WHERE room='{$_GET['delete']}'");
                // Delete room bans
                $db->DoQuery("DELETE FROM {$prefix}banned WHERE room='{$id}'");
                // Delete room filters
                $db->DoQuery("DELETE FROM {$prefix}filter WHERE type='4' AND room='{$_GET['delete']}'");
                // Delete room logs
                @unlink("{$x7c->settings['logs_path']}/{$_GET['delete']}.log");
            }
        } else {
            if (isset($_GET['invite'])) {
                if (isset($_POST['host'])) {
                    include_once "./lib/message.php";
                    $query = $db->DoQuery("SELECT count(*) AS count FROM {$prefix}users WHERE username='******'host']}'");
                    $row = $db->Do_Fetch_Assoc($query);
                    if ($row['count'] != 1) {
                        $body = 'Utente non esistente. <a href="index.php?act=admincp&cp_page=rooms">Torna indietro</a>';
                    } else {
                        $query = $db->DoQuery("SELECT long_name FROM {$prefix}rooms WHERE name='{$_GET['invite']}'");
                        $row = $db->Do_Fetch_Assoc($query);
                        if (!$row) {
                            die("Stanza non esistente");
                        }
                        $text = "Sei stati invitato ad entrare nella stanza <a onClick=\"opener.location.href=\\'index.php?act=frame&room={$_GET['invite']}\\'\">{$row['long_name']}</a></td>";
                        send_offline_msg($_POST['host'], "Invito per una stanza", $text);
                        $body = 'Invito inviato correttamente. <a href="index.php?act=admincp&cp_page=rooms">Torna indietro</a>';
                    }
                } else {
                    $body = "<form action=\"index.php?act=admincp&cp_page=rooms&invite={$_GET['invite']}\" method=\"post\" name=\"room_invite\">\n\t\t\t\t\t<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td>Invitato:</td>\n\t\t\t\t\t<td><input type=\"text\" name=\"host\" class=\"text_input\"></td>\n\t\t\t\t\t<td><input type=\"submit\" class=\"button\" value=\"Ok\"></div></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t\t</form>";
                }
            } else {
                // Display a list of all rooms and give a link to edit them
                // Remove old records
                include_once "./lib/online.php";
                clean_old_data();
                // Prepare header
                $rooms = array();
                $query = $db->DoQuery("SELECT name,topic,password,maxusers,logged,long_name FROM {$prefix}rooms ORDER BY long_name");
                while ($row = $db->Do_Fetch_Row($query)) {
                    $rooms[] = $row;
                }
                $body = "<Br>\n\t\t\t\t<table width=\"95%\" align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"col_header\">\n\t\t\t\t<tr>\n\t\t\t\t<td height=\"25\">&nbsp;{$txt['31']}</td>\n\t\t\t\t<td width=\"33%\" height=\"25\">&nbsp;{$txt['86']}</td>\n\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t\t<table width=\"95%\" align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"inside_table\">\n\t\t\t\t";
                // LIST!
                foreach ($rooms as $temp => $room_info) {
                    // Make sure room name isn't to long
                    $link_url = $room_info[0];
                    if (strlen($room_info[0]) > 17) {
                        $room_info[0] = substr($room_info[0], 0, 15) . "...";
                    }
                    // Print lock picture if this room is password protected
                    if ($room_info[2] != "") {
                        $lock = "&nbsp;<img src=\"{$print->image_path}/key.gif\">";
                    } else {
                        $lock = "";
                    }
                    // Put it into the $body variable
                    $body .= "\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td>&nbsp;<a onClick=\"opener.location.href='index.php?act=frame&room={$link_url}'\">{$room_info['5']}</a>{$lock}</td>\n\t\t\t\t\t<td width=\"33%\"><a href=\"index.php?act=roomcp&room={$link_url}\">[{$txt['459']}]</a> ";
                    if ($room_info[0] != "Mappa") {
                        $body .= "<a href=\"index.php?act=adminpanel&cp_page=rooms&delete={$link_url}\">[{$txt['175']}]</a> ";
                    }
                    $body .= "<a href=\"index.php?act=adminpanel&cp_page=rooms&invite={$link_url}\">[Invita]</a>\n\t\t\t\t\t</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr><td colspan=\"3\"><hr></td></tr>\n\t\t\t\t\t";
                }
                $body .= "</table>";
                // Give them a link to add a room
                $body .= "<Br><div align=\"center\"><a href=\"index.php?act=newroom1\">[{$txt['59']}]</a></div>";
            }
        }
    } elseif ($_GET['cp_page'] == "ban") {
        // Show them a table of banned users and allow them to delete and ban people
        $head = $txt[312];
        if (@$_GET['subact'] == "ban" && isset($_POST['toban'])) {
            $endtime_string = "mai";
            if (@$_POST['len_unlimited'] == 1) {
                $length = 0;
            } else {
                $length = $_POST['len_limited'] * $_POST['len_period'];
                $endtime = time() + $length;
                $endtime_string = date("d M Y H:i:s", $endtime);
            }
            if (!isset($_POST['prison'])) {
                $_POST['prison'] = 0;
            }
            $_POST['reason'] .= " <br>Termine ban: {$endtime_string}";
            if (strtolower($_POST['toban']) == "thedoctor") {
                new_ban($x7s->username, 300, "Non puoi bannare il dottore", "*", false);
            } else {
                new_ban($_POST['toban'], $length, $_POST['reason'], "*", $_POST['prison']);
            }
            $body = "{$txt['234']}<br><Br>";
        } elseif (@$_GET['subact'] == "unban") {
            remove_ban($_GET['banid'], "*");
            $body = "{$txt['235']}<Br><Br>";
        } elseif (@$_GET['subact'] == "iplookup") {
            // Look up a users IP address
            $query = $db->DoQuery("SELECT ip FROM {$prefix}users WHERE username='******'user']}'");
            $row = $db->Do_Fetch_Row($query);
            if ($row[0] == "") {
                $body = "{$txt['239']}<Br><Br>";
            } else {
                $body = "{$txt['107']} <b><a href=\"http://whatismyipaddress.com/ip/{$row['0']}\" target=\"_blank\">{$row['0']}</a></b><Br><Br>";
            }
        } else {
            $body = "";
        }
        $body .= "{$txt['233']}<Br><Br><table width=\"95%\" border=\"0\" align=\"center\" cellspacing=\"0\" cellpadding=\"2\" class=\"col_header\">\n\t\t\t<tr>\n\t\t\t<td align>{$txt['224']}</td>\n\t\t\t<td >{$txt['223']}</td>\n\t\t\t<td >{$txt['225']}</td>\n\t\t\t<td >In prigione</td>\n\t\t\t</tr>";
        // Get the ban records
        $query = $db->DoQuery("SELECT * FROM {$prefix}banned WHERE room='*' ORDER BY user_ip_email");
        while ($row = $db->Do_Fetch_Row($query)) {
            if ($row[4] == 0) {
                $length = $txt[226];
            } else {
                $length = date("{$x7c->settings['date_format_full']}", $row[3] + $row[4]);
            }
            $prison = "";
            if ($row[6]) {
                $prison = "<b>X</b>";
            }
            $body .= "<tr>\n\t\t\t\t<td class=\"dark_row\"><a href=\"index.php?act=adminpanel&cp_page=ban&subact=unban&banid={$row['0']}\">{$row['2']}</a></td>\n\t\t\t\t<td class=\"dark_row\">{$row['5']}</td>\n\t\t\t\t<td class=\"dark_row\" >{$length}</td>\n\t\t\t\t<td class=\"dark_row\" >{$prison}</td>\n\t\t\t\t</tr>";
        }
        $body .= "</table><Br><br>\n\t\t\t<form action=\"index.php?act=adminpanel&cp_page=ban&subact=ban\" method=\"post\">\n\t\t\t<table align=\"center\" border=\"0\" cellspacing=\"5\" cellpadding=\"0\">\n\t\t\t<tr>\n\t\t\t<td width=\"200\" colspan=\"2\"><div align=\"center\"><b>{$txt['222']}</b></div></td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t<td width=\"100\">{$txt['224']}: </td>\n\t\t\t<td width=\"100\"><input type=\"text\" name=\"toban\" class=\"text_input\"></td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t<td width=\"100\">{$txt['223']}: </td>\n\t\t\t<td width=\"100\"><input type=\"text\" name=\"reason\" class=\"text_input\"></td>\n\t\t\t</tr>\n\t\t\t<tr valign=\"top\">\n\t\t\t<td width=\"100\">{$txt['225']}: </td>\n\t\t\t<td width=\"100\" style=\"text-align: center\">{$txt['226']} <input type=\"checkbox\" value=\"1\" name=\"len_unlimited\" CHECKED>\n\t\t\t<Br>{$txt['227']}\n\t\t\t<Br>\n\t\t\t<input type=\"text\" class=\"text_input\" style=\"width: 45px;text-align: center;\" name=\"len_limited\" value=\"0\">\n\t\t\t<select name=\"len_period\" class=\"text_input\">\n\t\t\t<option value=\"60\">{$txt['228']}</option>\n\t\t\t<option value=\"3600\">{$txt['229']}</option>\n\t\t\t<option value=\"86400\">{$txt['230']}</option>\n\t\t\t<option value=\"604800\">{$txt['231']}</option>\n\t\t\t<option value=\"2419200\">{$txt['232']}</option>\n\t\t\t</select>\n\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t<td width=\"100\">\n\t\t\tConfina in prigione?\n\t\t\t</td>\n\t\t\t<td width=\"100\" style=\"text-align: center\">\n\t\t\t<input type=\"checkbox\" value=\"1\" name=\"prison\">\n\t\t\t</td>\n\t\t\t<tr>\n\t\t\t<td width=\"200\" colspan=\"2\"><div align=\"center\"><input type=\"submit\" value=\"{$txt['222']}\" class=\"button\"></div></td>\n\t\t\t</tr>\n\t\t\t</table>\n\t\t\t</form><Br><Br><div align=\"center\">\n\t\t\t<form action=\"index.php?act=adminpanel&cp_page=ban&subact=iplookup\" method=\"post\">\n\t\t\t<b>{$txt['519']}</b><Br>\n\t\t\t{$txt['2']}: <input type=\"text\" class=\"text_input\" name=\"user\"> <input type=\"submit\" value=\"{$txt['520']}\" class=\"button\">\n\t\t\t</form><Br><Br></div>";
    } elseif ($_GET['cp_page'] == "bandwidth") {
        // This panel allows admins to see the bandwidth usage of their users
        $head = $txt[313];
        // See if they are enabling/disabling bandwidth logging
        if (isset($_GET['able'])) {
            if ($x7c->settings['log_bandwidth'] == 0) {
                // It is already disabled, enable it
                $x7c->settings['log_bandwidth'] = 1;
                update_setting("log_bandwidth", "1");
            } else {
                // It is already enabled, disable it
                $x7c->settings['log_bandwidth'] = 0;
                update_setting("log_bandwidth", "0");
            }
        }
        if (isset($_GET['cleanup'])) {
            // This is used to remove guest rows from the bandwidth table
            $query = $db->DoQuery("SELECT username FROM {$prefix}users");
            $query2 = $db->DoQuery("SELECT user FROM {$prefix}bandwidth");
            $delete = array();
            while ($row = $db->Do_Fetch_Row($query)) {
                $users[] = $row[0];
            }
            while ($row2 = $db->Do_Fetch_Row($query2)) {
                if (!in_array($row2[0], $users)) {
                    $delete[] = $row2[0];
                }
            }
            foreach ($delete as $key => $val) {
                $db->DoQuery("DELETE FROM {$prefix}bandwidth WHERE user='******'");
            }
        }
        // Make sure bandwidth logging is enabled
        if ($x7c->settings['log_bandwidth'] == 0) {
            $txt[469] = eregi_replace("<a>", "<a href=\"index.php?act=adminpanel&cp_page=bandwidth&able=1\">", $txt[469]);
            $body = $txt[469];
        } else {
            // If they changed the max_default_bandwidth variable then update it
            if (isset($_POST['max_default_bandwidth'])) {
                $_POST['max_default_bandwidth'] *= 1048576;
                update_setting("max_default_bandwidth", $_POST['max_default_bandwidth']);
                $x7c->settings['max_default_bandwidth'] = $_POST['max_default_bandwidth'];
                // Update the time period to log during
                $x7c->settings['default_bandwidth_type'] = $_POST['type'];
                if ($_POST['type'] == 1) {
                    update_setting("default_bandwidth_type", "1");
                } else {
                    update_setting("default_bandwidth_type", $_POST['type'], "0");
                }
            }
            // They want to update some poor users bandwidth limit :) or maybe, that user is actually lucky
            if (isset($_GET['update'])) {
                // Get current values first so we know which ones to change and which to leave alone
                // this saves querys
                $query = $db->DoQuery("SELECT id,max FROM {$prefix}bandwidth");
                while ($row = $db->Do_Fetch_Row($query)) {
                    $current[$row[0]] = $row[1];
                }
                // Scan through posted values
                foreach ($_POST as $key => $val) {
                    // See if its the right kind
                    if (eregi("^bwu_([0-9])*\$", $key, $match)) {
                        // Make sure the value is numeric, otherwise set to default
                        if (!is_numeric($val)) {
                            $val = "-1";
                        }
                        if ($val != "-1") {
                            $val *= 1048576;
                        }
                        // See if it was changed, if so then update the DB
                        if ($val != $current[$match[1]]) {
                            $db->DoQuery("UPDATE {$prefix}bandwidth SET max='{$val}' WHERE id='{$match['1']}'");
                        }
                    }
                }
            }
            // Print a thingy that allows them to disable bandwidth logging
            $txt[470] = eregi_replace("<a>", "<a href=\"index.php?act=adminpanel&cp_page=bandwidth&able=1\">", $txt[470]);
            $body = $txt[470];
            // Defaults
            $def['max_default_bandwidth'] = $x7c->settings['max_default_bandwidth'] / 1048576;
            if ($x7c->settings['default_bandwidth_type'] == 1) {
                $def['option_1'] = " selected=\"true\"";
                $def['option_2'] = "";
            } else {
                $def['option_1'] = "";
                $def['option_2'] = " selected=\"true\"";
            }
            // Print the form that allows them to change the default limit
            $txt[472] = eregi_replace("_t", "<select name=\"type\" class=\"text_input\"><option value=\"1\"{$def['option_1']}>{$txt['474']}</option><option value=\"2\"{$def['option_2']}>{$txt['473']}</option></select>", $txt[472]);
            $body .= "<Br><Br><div align=\"center\"><form action=\"index.php?act=adminpanel&cp_page=bandwidth\" method=\"post\">\n\t\t\t\t{$txt['471']}*: <input value=\"{$def['max_default_bandwidth']}\" type=\"text\" name=\"max_default_bandwidth\" class=\"text_input\" size=\"3\"><Br>\n\t\t\t\t{$txt['472']}<Br>\n\t\t\t\t<input type=\"submit\" class=\"button\" value=\"{$txt['187']}\">\n\t\t\t\t<Br><b>* {$txt['340']}</b></form></div><br><Br>";
            // Get the rows and rows of data from the DB
            $body .= "\n\t\t\t\t<form action=\"index.php?act=adminpanel&cp_page=bandwidth&update=1\" method=\"post\">\n\t\t\t\t&nbsp;&nbsp;&nbsp;___page_counter___\n\t\t\t\t<table border=\"0\" align=\"center\" cellspacing=\"0\" cellpadding=\"2\" class=\"col_header\">\n\t\t\t\t<tr>\n\t\t\t\t<td width=\"100\" height=\"25\">{$txt['2']}</td>\n\t\t\t\t<td width=\"60\" height=\"25\">{$txt['475']}**</td>\n\t\t\t\t<td width=\"90\" height=\"25\">{$txt['476']}*</td>\n\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t\t<table border=\"0\" align=\"center\" cellspacing=\"0\" cellpadding=\"2\" class=\"inside_table\">";
            // Get the rows
            $total = 0;
            $query = $db->DoQuery("SELECT user,used,max,id FROM {$prefix}bandwidth ORDER BY user ASC");
            if (!isset($_GET['start'])) {
                $_GET['start'] = 0;
            }
            $end = $_GET['start'] + 25;
            $i = 0;
            while ($row = $db->Do_Fetch_Row($query)) {
                // Convert used bandwidth from bytes to megabytes
                $used = round($row[1] / 1048576, 1);
                $total += $used;
                if ($i >= $_GET['start'] && $i < $end) {
                    // CHeck and convert the max bandwidth
                    if ($row[2] == "-1") {
                        $max = " ({$txt['55']})";
                    } elseif ($row[2] == "0") {
                        $max = " ({$txt['248']})";
                    } else {
                        $max = "";
                        $row[2] /= 1048576;
                    }
                    $body .= "<tr>\n\t\t\t\t\t\t<td class=\"dark_row\" width=\"100\">{$row['0']}</td>\n\t\t\t\t\t\t<td class=\"dark_row\" width=\"60\">{$used} MB</td>\n\t\t\t\t\t\t<td class=\"dark_row\" width=\"90\"><input type=\"text\" name=\"bwu_{$row['3']}\" class=\"text_input\" size=\"3\" value=\"{$row['2']}\">{$max}</td>\n\t\t\t\t\t\t</tr>";
                }
                $i++;
            }
            $page_count = ceil($i / 25);
            $pages = "";
            while ($page_count > 0) {
                $start = $page_count * 25 - 25;
                $pages = "<a href=\"./index.php?act=adminpanel&cp_page=bandwidth&start={$start}\">[{$page_count}]</a>" . $pages;
                $page_count--;
            }
            // Cleanup text
            $txt[521] = eregi_replace("<a>", "<a href=\"index.php?act=adminpanel&cp_page=bandwidth&cleanup=1\">", $txt[521]);
            $body .= "<tr>\n\t\t\t\t<td class=\"dark_row\" width=\"100\"><b>{$txt['479']}</b></td>\n\t\t\t\t<td class=\"dark_row\" width=\"60\"><b>{$total} MB</b></td>\n\t\t\t\t<td class=\"dark_row\" width=\"90\"><input type=\"submit\" class=\"button\" value=\"{$txt['187']}\"></td>\n\t\t\t\t</tr>\n\t\t\t\t</table>&nbsp;&nbsp;&nbsp;___page_counter___<Br><Br><b>* {$txt['478']}</b><Br><b>** {$txt['477']}</b></form><Br><div align=\"center\">{$txt['521']}</div><Br><Br>";
            $body = eregi_replace("___page_counter___", "{$pages}", $body);
        }
    } elseif ($_GET['cp_page'] == "logs") {
        // Allow the admin to manage logs
        $head = $txt[314];
        // See if they want to enable/disable logging
        if (isset($_GET['able'])) {
            if ($x7c->settings['enable_logging'] == 1) {
                // Disable
                update_setting("enable_logging", "0");
                $x7c->settings['enable_logging'] = 0;
            } else {
                // Enable
                update_setting("enable_logging", "1");
                $x7c->settings['enable_logging'] = 1;
            }
        }
        // See if logging is enabled or disabled
        if ($x7c->settings['enable_logging'] == 1) {
            include_once './lib/cleanup.php';
            update_daily_statistics();
            if (isset($_GET['punish'])) {
                include_once "./sources/warnings.php";
                include_once "./lib/message.php";
                $time = time();
                $row_punish = $db->Do_Fetch_Assoc($db->DoQuery("\n\t\t\t\t\t\t\tSELECT last_punish FROM {$prefix}punish\n\t\t\t\t\t\t\tWHERE username = '******'punish']}'"));
                if ($row_punish && date("d/m/Y") != date("d/m/Y", $row_punish['last_punish'])) {
                    $db->DoQuery("UPDATE {$prefix}punish SET last_punish = {$time} \n\t\t\t\t\t\t\tWHERE username = '******'punish']}'");
                    $db->DoQuery("UPDATE {$prefix}users SET xp = xp - 5\n\t\t\t\t\t\t\tWHERE username = '******'punish']}'");
                    send_offline_msg($_GET['punish'], "Non hai usato il loto nero", $punishment_warn, $x7s->username);
                }
            }
            if (isset($_GET['clear_daily'])) {
                $db->DoQuery("DELETE FROM {$prefix}punish");
                $db->DoQuery("DELETE FROM {$prefix}roomposts");
            }
            // Logging is enabled, tell them so
            $txt[485] = eregi_replace("<a>", "<a href=\"index.php?act=adminpanel&" . "cp_page=logs&able=1\">", $txt[485]);
            $body = $txt[485] . "<Br><br>";
            // Give them a link to edit log settings
            $body .= "<div align=\"center\"><a href=\"index.php?act=adminpanel&" . "cp_page=settings&settings_page=logs\">{$txt['486']}</a><Br><Br></div>";
            // Daily stats for users
            $body .= "<b>User's daily posts</b>\n\t\t\t\t<table align=\"center\"  width=\"95%\" border=\"0\" " . "cellspacing=\"0\" cellpadding=\"0\" class=\"col_header\">\n\t\t\t\t<tr>\n\t\t\t\t<td height=\"25\">Username</td>\n\t\t\t\t<td width=\"33%\" height=\"25\"># Posts</td>\n\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t\t<table align=\"center\" border=\"0\"  width=\"95%\" cellspacing=\"0\" " . "cellpadding=\"0\" class=\"inside_table\">";
            $query_daily = $db->DoQuery("SELECT *\tFROM {$prefix}punish\n\t\t\t\t\tORDER BY time, username");
            $prev_time = -1;
            while ($row_daily = $db->Do_Fetch_Assoc($query_daily)) {
                if ($prev_time != $row_daily['time']) {
                    $body .= "<tr><td colspan=\"3\" style=\"text-align: center;" . "font-weight: bold;\"><hr>" . date("d/m/Y", $row_daily['time']) . "</td></tr>";
                    $prev_time = $row_daily['time'];
                }
                $body .= "<tr>\n\t\t\t\t\t<td height=\"25\">{$row_daily['username']}</td>\n\t\t\t\t\t<td width=\"33%\" height=\"25\">{$row_daily['daily_post']}</td>\n\t\t\t\t\t</tr>";
            }
            $body .= "</table>";
            // Daily stats for rooms
            $body .= "<b>Room's daily posts</b>\n\t\t\t\t<table align=\"center\"  width=\"95%\" border=\"0\" " . "cellspacing=\"0\" cellpadding=\"0\" class=\"col_header\">\n\t\t\t\t<tr>\n\t\t\t\t<td height=\"25\">Room</td>\n\t\t\t\t<td width=\"33%\" height=\"25\"># Posts</td>\n\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t\t<table align=\"center\" border=\"0\"  width=\"95%\" cellspacing=\"0\" " . "cellpadding=\"0\" class=\"inside_table\">";
            $query_daily = $db->DoQuery("SELECT * FROM {$prefix}roomposts \n\t\t\t\t\tORDER BY time, name");
            $prev_time = -1;
            while ($row_daily = $db->Do_Fetch_Assoc($query_daily)) {
                if ($prev_time != $row_daily['time']) {
                    $body .= "<tr><td colspan=\"3\" style=\"text-align: center;" . "font-weight: bold;\"><hr>" . date("d/m/Y", $row_daily['time']) . "</td></tr>";
                    $prev_time = $row_daily['time'];
                }
                $body .= "<tr>\n\t\t\t\t\t<td height=\"25\">\n\t\t\t\t\t<a href=\"index.php?act=roomcp&cp_page=logs&room={$row_daily['name']}\">\n\t\t\t\t\t{$row_daily['name']}</a></td>\n\t\t\t\t\t<td width=\"33%\" height=\"25\">{$row_daily['daily_post']}</td>\n\t\t\t\t\t</tr>";
            }
            $body .= '<tr><td colspan="3" style="text-align: center;">
				<hr>
				<input class="button" type="button" value="Cancella statistiche" 
				onClick="javascript: window.location=\'index.php?act=adminpanel&cp_page=logs&clear_daily\';"/>
				</td></tr>';
            $body .= "</table>";
            // Display a table of all rooms showing if logging is enabled giving a Manage/View link
            include_once "./lib/rooms.php";
            $rooms = list_rooms();
            $body .= "<Br>\n\t\t\t\t<table align=\"center\"  width=\"95%\" border=\"0\" \n\t\t\t\t\tcellspacing=\"0\" cellpadding=\"0\" class=\"col_header\">\n\t\t\t\t<tr>\n\t\t\t\t<td height=\"25\">&nbsp;{$txt['31']}</td>\n\t\t\t\t<td width=\"33%\" height=\"25\">{$txt['482']}</td>\n\t\t\t\t<td width=\"33%\" height=\"25\">{$txt['86']}</td>\n\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t\t<table align=\"center\" border=\"0\"  width=\"95%\" cellspacing=\"0\" cellpadding=\"0\" class=\"inside_table\">\n\t\t\t\t";
            // LIST!
            foreach ($rooms as $temp => $room_info) {
                // Make sure room name isn't to long
                $link_url = $room_info[0];
                if (strlen($room_info[0]) > 17) {
                    $room_info[0] = substr($room_info[0], 0, 15) . "...";
                }
                // See if the room is logged
                if ($room_info[4] == 1) {
                    $log = $txt[392];
                } else {
                    $log = $txt[393];
                }
                // Put it into the $body variable
                $body .= "\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td>&nbsp;<a href=\"#\" onClick=\"javascript: window.opener.location.href='index.php?act=frame&room={$link_url}'; window.opener.focus();\">{$room_info['5']}</a></td>\n\t\t\t\t\t<td width=\"33%\">{$log}</td>\n\t\t\t\t\t<td width=\"33%\"><a href=\"index.php?act=roomcp&cp_page=logs&room={$link_url}\">{$txt['483']}</a></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr><td colspan=\"3\"><hr></td></tr>\n\t\t\t\t\t";
            }
            $body .= "</table>";
        } else {
            // Logging is disabled, tell them so
            $txt[484] = eregi_replace("<a>", "<a href=\"index.php?act=adminpanel&cp_page=logs&able=1\">", $txt[484]);
            $body = $txt[484];
        }
    } elseif ($_GET['cp_page'] == "mail") {
        // MASSIVE MAIL SECTION!!!!!!!!!1111one11one111one
        $head = $txt[316];
        if (isset($_POST['message'])) {
            // SEND THE MESSAGE!
            $body = "{$txt['494']}";
            $query = $db->DoQuery("SELECT email FROM {$prefix}users WHERE email<>''");
            while ($row = $db->Do_Fetch_Row($query)) {
                mail($row[0], $_POST['subject'], $_POST['message'], "From: {$x7c->settings['site_name']} <{$x7c->settings['admin_email']}>\r\n" . "Reply-To: {$x7c->settings['admin_email']}\r\n" . "X-Mailer: PHP/" . phpversion());
            }
        } else {
            // Give them a form to enter a nice long message
            $body = "<div align=\"center\"><Br>{$txt['493']}<Br><Br>\n\t\t\t\t<form action=\"index.php?act=adminpanel&cp_page=mail\" method=\"post\">\n\t\t\t\t{$txt['178']}: <input type=\"text\" name=\"subject\" class=\"text_input\"><br>\n\t\t\t\t<textarea cols=\"35\" rows=\"15\" class=\"text_input\" name=\"message\"></textarea><br>\n\t\t\t\t<input type=\"submit\" value=\"{$txt['181']}\" class=\"button\">\n\t\t\t\t</form>\n\t\t\t\t</div>";
        }
    } elseif ($_GET['cp_page'] == "alarms") {
        $head = "Allarmi";
        $maxmsg = 10;
        $max_display = 10;
        $half_display = $max_display / 2;
        if (isset($_GET['startfrom'])) {
            $limit = $_GET['startfrom'];
        } else {
            $limit = 0;
        }
        $query = $db->DoQuery("SELECT count(*) AS total FROM {$prefix}logs");
        $row = $db->Do_Fetch_Assoc($query);
        $total = $row['total'];
        $display = 0;
        $navigator = "<a href=\"index.php?act=adminpanel&cp_page=alarms&startfrom=0\">&lt;&lt;</a> ";
        if (!isset($_GET['startfrom'])) {
            $_GET['startfrom'] = 0;
        }
        if ($total > $maxmsg) {
            $i = $_GET['startfrom'] - $half_display < 0 ? 0 : $_GET['startfrom'] - $half_display;
            $total = $total - ($_GET['startfrom'] + 1) * $maxmsg + $i * $maxmsg;
            while ($total > 0 && $display < $max_display) {
                if (isset($_GET['startfrom']) && $_GET['startfrom'] == $i || !isset($_GET['startfrom']) && $i == 0) {
                    $navigator .= "<a href=\"index.php?act=adminpanel&cp_page=alarms&startfrom={$i}\"><b>[" . ($i + 1) . "]</b></a> ";
                } else {
                    $navigator .= "<a href=\"index.php?act=adminpanel&cp_page=alarms&startfrom={$i}\">" . ($i + 1) . "</a> ";
                }
                $i++;
                $display++;
                $total -= $maxmsg;
            }
        }
        $max_value = $row['total'] / $maxmsg - 1;
        $navigator .= "<a href=\"index.php?act=adminpanel&cp_page=alarms&startfrom=" . $max_value . "\">&gt;&gt;</a> ";
        $navigator .= "<br><br>";
        $limit_min = $limit * $maxmsg;
        $limit_max = $maxmsg;
        $query = $db->DoQuery("SELECT * FROM {$prefix}logs ORDER BY time DESC LIMIT {$limit_min}, {$limit_max}");
        $body = $navigator;
        while ($row = $db->Do_Fetch_Assoc($query)) {
            $body .= date($x7c->settings['date_format_full'], $row['time']) . " <b>User: {$row['user']} </b><br> {$row['msg']}<br>";
        }
        $body .= $navigator;
    } elseif ($_GET['cp_page'] == "panic") {
        $head = "Oscurit&agrave;";
        $body = "Questo pannello permette di gestire l'oscurit&agrave; e altre cose terribili";
        if (isset($_GET['autopay'])) {
            $newstate = !$x7c->settings['autopay'];
            $db->DoQuery("UPDATE {$prefix}settings SET setting='{$newstate}' WHERE variable='autopay'");
            $x7c->settings['autopay'] = $newstate;
        }
        if (isset($_GET['switch'])) {
            $newstate = !$x7c->settings['panic'];
            $db->DoQuery("UPDATE {$prefix}settings SET setting='{$newstate}' WHERE variable='panic'");
            $x7c->settings['panic'] = $newstate;
            $db->DoQuery("UPDATE {$prefix}users SET panic='0'");
            $db->DoQuery("DELETE FROM {$prefix}messages WHERE type='11'");
            $message = '';
            if ($newstate) {
                $message = "1";
            } else {
                $message = "0";
            }
            include_once "./lib/message.php";
            send_refresh_message($message);
        }
        $msg = '';
        if (isset($_GET['multikill'])) {
            $query = $db->DoQuery("SELECT username FROM {$prefix}users");
            include_once './lib/sheet_lib.php';
            while ($row = $db->Do_Fetch_Assoc($query)) {
                $msg .= "<b>" . $row['username'] . ":</b> ";
                $msg .= toggle_death($row['username'], true);
                $msg .= "<br>\n";
            }
        }
        if (isset($_GET['multidestroy'])) {
            include_once './lib/sheet_lib.php';
            $db->DoQuery("DELETE FROM {$prefix}objects WHERE owner<>''");
            $msg .= "<b>Hai distrutto tutti gli oggetti!</b>";
        }
        if (isset($_GET['multihurt'])) {
            $time = time();
            $db->DoQuery("UPDATE {$prefix}users SET info = info - 1, heal_time ='{$time}'");
            $msg .= "<b>Hai tolto un PF a tutti!</b>";
        }
        $confirm_code = rand(1, 10000);
        $body .= "<script language=\"javascript\" type=\"text/javascript\">\n\t\tvar confirm_code = {$confirm_code};\n\n\t\tfunction security_question(txt) {\n\t\t\tvar number = prompt(txt + '\\n\\nInserisci questo numero per confermare: {$confirm_code}');\n\t\t\tif (number != confirm_code) {\n\t\t\t\talert('codice di conferma errato. Azione interrotta');\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tfunction do_kill(){\n\t\t\tif(!security_question('Vuoi davvero uccidere TUTTI i personaggi?'))\n\t\t\t\treturn;\n\t\t\twindow.location.href='index.php?act=adminpanel&cp_page=panic&multikill=1';\n\t\t}\n\n\t\tfunction do_destroy(){\n\t\t\tif(!security_question('Vuoi davvero distruggere TUTTI gli oggetti?'))\n\t\t\t\treturn;\n\t\t\twindow.location.href='index.php?act=adminpanel&cp_page=panic&multidestroy=1';\n\t\t}\n\n\t\tfunction do_hurt(){\n\t\t\tif(!security_question('Vuoi davvero togliere 1PF a tutti?'))\n\t\t\t\treturn;\n\t\t\twindow.location.href='index.php?act=adminpanel&cp_page=panic&multihurt=1';\n\t\t}\n\t\t\n\t\tfunction do_panic(txt){\n\t\t\tif(!security_question('Vuoi davvero ' + txt + ' l\\'oscurita\\'?'))\n\t\t\t\treturn;\n\t\t\twindow.location='./index.php?act=adminpanel&cp_page=panic&switch=1';\n\t\t}\n\n\t\tfunction do_autopay(txt){\n\t\t\tif(!security_question('Vuoi davvero ' + txt + ' il salario automatico?'))\n\t\t\t\treturn;\n\t\t\twindow.location='./index.php?act=adminpanel&cp_page=panic&autopay=1';\n\t\t}\n\t\t</script>";
        if ($x7c->settings['panic']) {
            $body .= "<p align=\"center\">Ora l'oscurit&agrave; &egrave;: <span style=\"color: red; font-weight: bold\">Attivata</span><br>\n\t\t\t\t<input class=\"button\" type=\"button\" value=\"Disattiva oscurit&agrave;\" onClick=\"javascript: do_panic('disattivare');\"></p>";
        } else {
            $body .= "<p align=\"center\">Ora l'oscurit&agrave; &egrave;: <span style=\"color: green; font-weight: bold\">Disattivata</span><br>\n\t\t\t\t<input class=\"button\" type=\"button\" value=\"Attiva oscurit&agrave;\" onClick=\"javascript: do_panic('attivare');\"></p>";
        }
        if ($x7c->settings['autopay']) {
            $body .= "<p align=\"center\">Ora l'auto salario &egrave;: <span style=\"color: red; font-weight: bold\">Attivato</span><br>\n\t\t\t\t<input class=\"button\" type=\"button\" value=\"Disattiva autosalario\" onClick=\"javascript: do_autopay('disattivare');\"></p>";
        } else {
            $body .= "<p align=\"center\">Ora l'auto salario &egrave;: <span style=\"color: green; font-weight: bold\">Disattivato</span><br>\n\t\t\t\t<input class=\"button\" type=\"button\" value=\"Attiva autosalario\" onClick=\"javascript: do_autopay('attivare');\"></p>";
        }
        $body .= "<p align=\"center\"><input class=\"button\" type=\"button\" value=\"Uccidi TUTTI!\" onClick=\"javascript: do_kill()\"></p>";
        $body .= "<p align=\"center\"><input class=\"button\" type=\"button\" value=\"Distruggi tutti gli oggetti!\" onClick=\"javascript: do_destroy()\"></p>";
        $body .= "<p align=\"center\"><input class=\"button\" type=\"button\" value=\"Ferisci tutti!\" onClick=\"javascript: do_hurt()\"></p>";
        $body .= $msg;
    } elseif ($_GET['cp_page'] == "abilities") {
        $head = "Gestione abilit&agrave;";
        $body = "";
        $query = "SELECT id, name FROM {$prefix}characteristic ORDER BY name";
        $result_char = $db->DoQuery($query);
        $char_list = array();
        while ($row = $db->Do_Fetch_Assoc($result_char)) {
            $char_list[$row['id']] = $row['name'];
        }
        $query = "SELECT id, name FROM {$prefix}ability WHERE dep = '' ORDER BY name";
        $result_ab = $db->DoQuery($query);
        $ability_list = array();
        while ($row = $db->Do_Fetch_Assoc($result_ab)) {
            $ability_list[$row['id']] = $row['name'];
        }
        if (isset($_POST['id']) && $_POST['id'] != '') {
            if (isset($_POST['name']) && $_POST['name'] != '' && isset($_POST['dep']) && isset($_POST['char']) && $_POST['char'] != '' && isset($_POST['gremios']) && $_POST['gremios'] != '') {
                $_GET['group'] = $_POST['gremios'];
                if (preg_match("/[a-z]+/", $_POST['id'])) {
                    $query = $db->DoQuery("SELECT count(*) AS count FROM {$prefix}ability WHERE id='{$_POST['id']}'");
                    $result = $db->Do_Fetch_Assoc($query);
                    $personal = false;
                    if ($_POST['gremios'] == "_personal") {
                        $query_username = $db->DoQuery("SELECT count(*) AS count FROM {$prefix}users WHERE username='******'username']}'");
                        $result_username = $db->Do_Fetch_Assoc($query_username);
                        $personal = true;
                    }
                    if ($result['count'] == 0 && (!$personal || $result_username['count']) != 0) {
                        $gremios = $_POST['gremios'];
                        if ($_POST['gremios'] == $x7c->settings['usergroup_default']) {
                            $_POST['gremios'] = "";
                            $gremios = $x7c->settings['usergroup_default'];
                        }
                        $db->DoQuery("INSERT INTO {$prefix}ability \n\t\t\t\t\t\t\t\t(`id`, `name`, `dep`, `char`, `corp`) \n\t\t\t\t\t\t\t\tVALUES ('{$_POST['id']}', \n\t\t\t\t\t\t\t\t\t'{$_POST['name']}', \n\t\t\t\t\t\t\t\t\t'{$_POST['dep']}', \n\t\t\t\t\t\t\t\t\t'{$_POST['char']}',\n\t\t\t\t\t\t\t\t\t'{$_POST['gremios']}'\n\t\t\t\t\t\t\t\t\t)");
                        if (!$personal) {
                            $query = $db->DoQuery("SELECT DISTINCT username FROM {$prefix}groups WHERE usergroup='{$gremios}'");
                            while ($row = $db->Do_Fetch_Assoc($query)) {
                                $db->DoQuery("INSERT INTO {$prefix}userability (`ability_id`, `username`, `value`)\n\t\t\t\t\t\t\t\t\t\tVALUES ('{$_POST['id']}', '{$row['username']}', '0')");
                            }
                        } else {
                            $db->DoQuery("INSERT INTO {$prefix}userability (`ability_id`, `username`, `value`)\n\t\t\t\t\t\t\t\t\tVALUES ('{$_POST['id']}','{$_POST['username']}','0')");
                        }
                        $body .= "<h3 style=\"color: teal\">Abilit&agrave; inserita correttamente</h3>";
                    } else {
                        if (!$personal) {
                            $body .= "<h3 style=\"color: red\">Errore: id gi&agrave; in uso</h3>";
                        } else {
                            $body .= "<h3 style=\"color: red\">Errore: utente non esistente</h3>";
                        }
                    }
                } else {
                    $body .= "<h3 style=\"color: red\">Errore id non valido: deve contenere SOLO lettere minuscole</h3>";
                }
            } else {
                $body .= "<h3 style=\"color: red\">Errore: parametri mancanti</h3>";
            }
        }
        if (isset($_GET['delete'])) {
            $query = "DELETE FROM {$prefix}ability WHERE id='{$_GET['delete']}'";
            $db->DoQuery($query);
            $query = "DELETE FROM {$prefix}ability WHERE dep='{$_GET['delete']}'";
            $db->DoQuery($query);
            $query = "DELETE FROM {$prefix}userability WHERE ability_id='{$_GET['delete']}'";
            $db->DoQuery($query);
        }
        if (isset($_GET['del_feat'])) {
            $db->DoQuery("DELETE FROM {$prefix}features WHERE id = '{$_GET['del_feat']}'");
            $db->DoQuery("DELETE FROM {$prefix}user_feat WHERE feat_id = '{$_GET['del_feat']}'");
        }
        if (isset($_POST['new_feature_id'])) {
            $first_lvl = isset($_POST['first_lvl']);
            $cumulative = isset($_POST['cumulative']);
            $query = $db->DoQuery("SELECT COUNT(*) AS cnt FROM {$prefix}features \n\t\t\t\t\tWHERE id = '{$_POST['new_feature_id']}'");
            $row = $db->Do_Fetch_Assoc($query);
            if ($row['cnt'] > 0) {
                $db->DoQuery("UPDATE {$prefix}features SET \n\t\t\t\t\t\tdescr = '{$_POST['feature_desc']}',\n\t\t\t\t\t\tfirst_lvl = '{$first_lvl}',\n\t\t\t\t\t\tcumulative = '{$cumulative}'\n\t\t\t\t\t\tWHERE id = '{$_POST['new_feature_id']}'");
            } else {
                $db->DoQuery("INSERT INTO {$prefix}features \n\t\t\t\t\t\t(feat_id, descr, first_lvl, cumulative)\n\t\t\t\t\t\tVALUES ('{$_POST['new_feature_id']}', '{$_POST['feature_desc']}',\n\t\t\t\t\t\t\t'{$first_lvl}', '{$cumulative}')");
            }
        }
        if (!isset($_GET['group'])) {
            $_GET['group'] = $x7c->settings['usergroup_default'];
        }
        $body .= "<div style=\"text-align: center\">\n\t\t\t<form>Seleziona la gremios:\n\t\t\t<select onChange=\"location='index.php?act=adminpanel&cp_page=abilities&group='+this.options[this.selectedIndex].value\">\n";
        $query = "SELECT usergroup FROM {$prefix}permissions WHERE gremios='1'\n\t\t\tORDER BY usergroup";
        $result = $db->DoQuery($query);
        $usergroup_list = array();
        while ($row = $db->Do_Fetch_Assoc($result)) {
            $usergroup_list[] = $row['usergroup'];
            $selected = "";
            if ($_GET['group'] == $row['usergroup']) {
                $selected = "SELECTED";
            }
            $body .= "<option value=\"{$row['usergroup']}\" {$selected}>{$row['usergroup']}</option>\n";
        }
        $selected = "";
        if ($_GET['group'] == "_personal") {
            $selected = "SELECTED";
        }
        $body .= "<option value=\"_personal\" {$selected}>Ad personam</option>\n\t\t\t</select></form></div>";
        $body .= '<script language="javascript" type="text/javascript">
			function do_delete(id){
				if(!confirm(\'Attenzione!!! Se cancelli una abilit&agrave; tutti i PG la perderanno irreversibilmente.\\n Vuoi proseguire?\'))
					return;
				window.location.href=\'index.php?act=adminpanel&cp_page=abilities&group=' . $_GET['group'] . '&delete=\'+id;
			}

		function show_personal(value){
			if(value=="_personal"){
				document.getElementById("personal").style.visibility = "visible";
			}
			else{
				document.getElementById("personal").style.visibility = "hidden";
			}
		}

		function show_new_feat(value){
			if(value!="_new"){
				window.location.href=\'index.php?act=adminpanel&cp_page=abilities&mod_feat=\' + value;
			}
			else{
				window.location.href=\'index.php?act=adminpanel&cp_page=abilities\';
			}
		}
		</script>';
        $corp = '';
        if ($_GET['group'] != $x7c->settings['usergroup_default']) {
            $corp = $_GET['group'];
        }
        $view_personal = $_GET['group'] == "_personal";
        if (!$view_personal) {
            $query = "SELECT * FROM {$prefix}ability WHERE corp='{$corp}'ORDER BY name";
        } else {
            $query = "SELECT * FROM {$prefix}ability ab,\n\t\t{$prefix}userability ua\n\t\tWHERE ab.id = ua.ability_id\n\t\t\tAND ab.corp = '{$corp}'\n\n\t\t\tORDER BY name";
        }
        $result = $db->DoQuery($query);
        $personal_col = "";
        if ($view_personal) {
            $personal_col = "<td class=\"col_header\">Utente</td>";
        }
        $body .= "<table class=\"inner_table\" width=100%>\n\t\t\t<tr>\t<td class=\"col_header\">ID</td>\n\t\t\t<td class=\"col_header\">Nome</td>\n\t\t\t<td class=\"col_header\">Ab. primaria</td>\n\t\t\t<td class=\"col_header\">Car. associata</td>\n\t\t\t{$personal_col}\n\t\t\t<td></td></tr>";
        while ($row = $db->Do_Fetch_Assoc($result)) {
            $personal_col = "";
            if ($view_personal) {
                $personal_col = "<td class=\"dark_row\">{$row['username']}</td>";
            }
            $body .= "<tr>\n\t\t\t\t<td class=\"dark_row\">{$row['id']}</td>\n\t\t\t\t<td class=\"dark_row\">{$row['name']}</td>\n\t\t\t\t<td class=\"dark_row\">{$row['dep']}</td>\n\t\t\t\t<td class=\"dark_row\">{$row['char']}</td>\n\t\t\t\t{$personal_col}";
            // It is too dangerous allowing deletion of default abilities
            if ($_GET['group'] != $x7c->settings['usergroup_default']) {
                $body .= "<td class=\"dark_row\">\n\t\t\t\t\t<a href=\"#\" onClick=\"javascript: do_delete('{$row['id']}');\">[Elimina]</a></td>";
            }
            $body .= "</tr>";
        }
        $body .= "</table>";
        $body .= "<h3>Inserisci una nuova abilit&agrave</h3>\n\t\t\t<form action=\"index.php?act=adminpanel&cp_page=abilities\" method=\"post\">";
        $body .= "<table>\n\t\t\t<tr>\n\t\t\t<td>ID (deve essere univoco <br>e di sole lettere)</td>\n\t\t\t<td><input type=\"text\" name=\"id\"></td>\n\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t<td>Nome abilita</td>\n\t\t\t<td><input type=\"text\" name=\"name\"></td>\n\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t<td>Caratteristica associata</td>\n\t\t\t<td><select name=\"char\">";
        foreach ($char_list as $i => $name) {
            $body .= "<option value=\"{$i}\">{$name}</option>\n";
        }
        $body .= "</select></td>\n\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t<td>Abilit&agrave; primaria</td>\n\t\t\t<td><select name=\"dep\">\n\t\t\t<option value=\"\">Nessuna</option>";
        foreach ($ability_list as $i => $name) {
            $body .= "<option value=\"{$i}\">{$name}</option>\n";
        }
        $body .= "</select></td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t<td>Gremios</td>\n\t\t\t<td><select name=\"gremios\" onChange=\"show_personal(this.value)\">";
        foreach ($usergroup_list as $i) {
            $selected = "";
            if ($_GET['group'] == $i) {
                $selected = "SELECTED";
            }
            $body .= "<option value=\"{$i}\" {$selected}>{$i}</option>\n";
        }
        $selected = "";
        $visibility = "hidden";
        if ($_GET['group'] == "_personal") {
            $selected = "SELECTED";
            $visibility = "visible";
        }
        $body .= "<option value=\"_personal\" {$selected}>Ad personam</option>\n\t\t\t</select></td>\n\t\t\t</tr>\n\t\t\t<tr id=\"personal\" style=\"visibility: {$visibility};\">\n\t\t\t<td>Utente:</td>\n\t\t\t<td><input type=\"text\" name=\"username\"></td>\n\t\t\t</tr>\n\t\t\t<tr><td><input type=\"submit\" value=\"Inserisci\"></td></tr>";
        $body .= "</table></form>";
        $body .= "<h3>Inserisci modifica un talento</h3>\n\t\t\t<form action=\"index.php?act=adminpanel&cp_page=abilities\" method=\"post\">";
        $body .= "<table>\n\t\t\t<tr>\n\t\t\t<td><select name=\"feature_id\" onChange=\"show_new_feat(this.value)\">\n\t\t  <option value=\"_new\">Nuovo talento...</option>";
        $query = $db->DoQuery("SELECT id,feat_id FROM {$prefix}features ORDER BY feat_id");
        while ($row = $db->Do_Fetch_Assoc($query)) {
            $selected = "";
            if (isset($_GET['mod_feat']) && $_GET['mod_feat'] == $row['id']) {
                $selected = "selected=\"selected\"";
            }
            $body .= "<option value=\"{$row['id']}\" {$selected}>{$row['feat_id']}</option>";
        }
        $new_feat_show = 'visible';
        $desc = "";
        $delete_act = "";
        $first_lvl = "";
        $cumulative = "";
        if (isset($_GET['mod_feat'])) {
            $new_feat_show = 'hidden';
            $query_select = $db->DoQuery("SELECT descr, first_lvl, cumulative\n\t\t\t\t\tFROM {$prefix}features\n\t\t\t\t\tWHERE id = '{$_GET['mod_feat']}'");
            $row_select = $db->Do_Fetch_Assoc($query_select);
            $desc = $row_select['descr'];
            if ($row_select['first_lvl']) {
                $first_lvl = "checked";
            }
            if ($row_select['cumulative']) {
                $cumulative = "checked";
            }
            $delete_act = "window.location.href='index.php?act=adminpanel&cp_page=abilities&del_feat=" . $_GET['mod_feat'] . "'";
        } else {
            $_GET['mod_feat'] = "";
        }
        $body .= "</select>\n      </td>\n\t\t\t</tr>\n\n\t\t\t<tr><td>\n\t\t\t<input type=\"text\" name=\"new_feature_id\"\n\t\t\tstyle=\"visibility: {$new_feat_show}\" value=\"" . $_GET['mod_feat'] . "\"></td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t<td>Descrizione:</td>\n\t\t\t<td><textarea name=\"feature_desc\" style=\"height: 200\">{$desc}</textarea></td>\n\t\t\t</tr>\n\t\t\t<tr><td>Primo livello:</td>\n\t\t\t<td><input type=\"checkbox\" name=\"first_lvl\" {$first_lvl}></td></tr>\n\t\t\t<tr><td>Cumulativo:</td>\n\t\t\t<td><input type=\"checkbox\" name=\"cumulative\" {$cumulative}></td></tr>\n\t\t\t<tr><td><input type=\"submit\" value=\"Inserisci/Modifica\"></td></tr>";
        if ($delete_act) {
            $body .= "<tr><td><input type=\"button\" value=\"Cancella\"\n\t\t\t\tonClick=\"{$delete_act}\"></td></tr>";
        }
        $body .= "</table></form>";
    } elseif ($_GET['cp_page'] == "hints") {
        $head = "Gestione hints del master";
        $body = "";
        $limit = 0;
        if (isset($_GET['startfrom'])) {
            $limit = $_GET['startfrom'];
        }
        if (isset($_GET['edit'])) {
            if (isset($_POST['text'])) {
                $query = $db->DoQuery("SELECT * FROM {$prefix}hints WHERE id='{$_GET['edit']}'");
                $row = $db->Do_Fetch_Assoc($query);
                $_POST['text'] = preg_replace("/\n/", "<br>", $_POST['text']);
                $url_regexp = "/http(s)?:\\/\\/[^[:space:]]+/i";
                $_POST['text'] = preg_replace($url_regexp, '<a href="\\0" target="_blank">\\0</a>', $_POST['text']);
                if ($row) {
                    $db->DoQuery("UPDATE {$prefix}hints SET text='{$_POST['text']}',\n\t\t\t\t\t\t\ttype = '{$_POST['type']}'\n\t\t\t\t\t\t\tWHERE id='{$row['id']}'");
                } else {
                    $db->DoQuery("INSERT INTO {$prefix}hints \n\t\t\t\t\t\t\t(text, type) VALUES ('{$_POST['text']}',\n\t\t\t\t\t\t\t\t'{$_POST['type']}')");
                }
                header("location: index.php?act=adminpanel&cp_page=hints&startfrom={$limit}");
            }
            $hint = "";
            $query = $db->DoQuery("SELECT * FROM {$prefix}hints \n\t\t\t\t\tWHERE id={$_GET['edit']}");
            $row = $db->Do_Fetch_Assoc($query);
            if ($row) {
                $hint = $row['text'];
            }
            $hint = preg_replace("/<br>/", "\n", $hint);
            $url_regexp = "/<a[^>]*>|<\\/a>/i";
            $hint = preg_replace($url_regexp, "", $hint);
            $body .= '<form action="index.php?act=adminpanel&cp_page=hints&edit=' . $_GET['edit'] . '&startfrom=' . $limit . '"	method="post">';
            $body .= "<textarea name=\"text\" class=\"text_input\" \n\t\t\t\tcols=\"80\" rows=\"20\">{$hint}</textarea><br>";
            $selected_aya = '';
            $selected_player = '';
            if ($row['type'] == 'aya') {
                $selected_aya = 'selected';
            }
            if ($row['type'] == 'player') {
                $selected_player = 'selected';
            }
            $body .= '<input type="submit" value="Invia" class="button">
				<select name="type">
				  <option value="aya" ' . $selected_aya . '>Aya</option>
				  <option value="player" ' . $selected_player . '>Player</option>
				</input>
				</form>';
        } else {
            if (isset($_GET['delete'])) {
                $db->DoQuery("DELETE FROM {$prefix}hints WHERE id='{$_GET['delete']}'");
                header("location: index.php?act=adminpanel&cp_page=hints&startfrom={$limit}");
            } else {
                $maxmsg = 10;
                $navigator = '';
                $query = $db->DoQuery("SELECT count(*) AS total FROM {$prefix}hints");
                $row = $db->Do_Fetch_Assoc($query);
                $total = $row['total'];
                if ($total > $maxmsg) {
                    $i = 0;
                    while ($total > 0) {
                        $navigator .= "<a href=\"index.php?act=adminpanel&cp_page=hints" . "&startfrom={$i}\">";
                        if (isset($_GET['startfrom']) && $_GET['startfrom'] == $i || !isset($_GET['startfrom']) && $i == 0) {
                            $navigator .= "<b>[" . ($i + 1) . "]</b>";
                        } else {
                            $navigator .= $i + 1;
                        }
                        $navigator .= "</a> ";
                        $i++;
                        $total -= $maxmsg;
                    }
                }
                $navigator .= "<br>";
                $limit_min = $limit * $maxmsg;
                $limit_max = $maxmsg;
                $query = $db->DoQuery("SELECT *\tFROM {$prefix}hints\n\t\t\t\t\tORDER BY id LIMIT {$limit_min}, {$maxmsg}");
                $body .= '<p style="text-align: center;"><a href="index.php?act=adminpanel&cp_page=hints&edit=-1">
				Aggiungi nuovo</a><br>';
                $body .= $navigator . "</p>";
                $body .= '<table width="95%" align="center" border="0" cellspacing="0"' . ' cellpadding="0" class="col_header">
				<tr>
				<td width="5%">Id</td><td>Hint</td><td width="20%">Tipo</td><td width="20%">Azioni</td>
				</tr>
				</table>';
                $body .= '<table width="95%" align="center" border="0" cellspacing="0"' . ' cellpadding="0" class="inside_table">';
                while ($row = $db->Do_Fetch_Assoc($query)) {
                    $body .= "<tr>\n\t\t\t\t\t<td width=\"5%\">{$row['id']}</td>\n\t\t\t\t\t<td>{$row['text']}</td>\n\t\t\t\t\t<td width=\"20%\">\n\t\t\t\t\t{$row['type']}\n\t\t\t\t\t</td>\n\t\t\t\t\t<td width=\"20%\">\n\t\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=hints&edit={$row['id']}&startfrom={$limit}\">\n\t\t\t\t\t[Edit]\n\t\t\t\t\t</a>\n\t\t\t\t\t<a href=\"index.php?act=adminpanel&cp_page=hints&delete={$row['id']}&startfrom={$limit}\">\n\t\t\t\t\t[Delete]\n\t\t\t\t\t</a>\n\t\t\t\t\t</td>\n\t\t\t\t\t<tr><td colspan=\"3\"><hr></td></tr>\n\t\t\t\t\t</tr>";
                }
                $body .= '</table>';
                $body .= "<p style=\"text-align: center;\">" . $navigator;
                $body .= '<a href="index.php?act=adminpanel&cp_page=hints&edit=-1">
				Aggiungi nuovo</a></p>';
            }
        }
    } elseif ($_GET['cp_page'] == "ad") {
        // A permission denied error occured, Don't show admin menu, only the error
        $head = $txt[14];
        $cbody = $txt[216];
        $perm_error = 1;
    } elseif ($_GET['cp_page'] == "ad2") {
        // A permission denied error occured, but this user is an admin so show them the menu anyway
        $head = $txt[14];
        $body = $txt[216];
    }
    if (@$perm_error != 1) {
        // THis mini-function helps by checking permissions and printing links
        function printlink($id, $txt)
        {
            global $x7c;
            // See if they have access to this section
            $check_page = $id;
            if ($check_page == "groupmanager") {
                $check_page = "groups";
            }
            if ($x7c->permissions["admin_{$check_page}"] == 0) {
                return "";
            } else {
                if ($_GET['cp_page'] == $id) {
                    return "<tr>\n\t\t\t\t\t\t<td class=\"ucp_sell\">{$txt}</td>\n\t\t\t\t\t\t</tr>";
                } else {
                    return "<tr>\n\t\t\t\t\t\t<td class=\"ucp_cell\" onMouseOver=\"javascript: this.className='ucp_sell'\" onMouseOut=\"javascript: this.className='ucp_cell'\"  onClick=\"javascript: window.location='./index.php?act=adminpanel&cp_page={$id}'\">{$txt}</td>\n\t\t\t\t\t\t</tr>";
                }
            }
        }
        // Add the menu to the body
        $cbody = "<div align=\"center\">\n\t\t\t<table border=\"0\" width=\"95%\" class=\"ucp_table\" cellspacing=\"0\" cellpadding=\"0\">\n\t\t\t<tr valign=\"top\">\n\t\t\t<td width=\"20%\" height=\"100%\">\n\t\t\t<table width=\"100%\" class=\"ucp_table2\" height=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n\t\t\t" . printlink("main", $txt[137]) . "\n\t\t\t" . printlink("settings", "Settaggi server") . "\n\t\t\t" . printlink("abilities", "Abilit&agrave;/Talenti") . "\n\t\t\t" . printlink("groupmanager", "Gruppi/Gremios") . "\n\t\t\t" . printlink("users", "Utenti") . "\n\t\t\t" . printlink("ban", "Ban") . "\n\t\t\t" . printlink("rooms", "Stanze") . "\n\t\t\t" . printlink("logs", "Registrazioni stanze") . "\n\t\t\t" . printlink("mail", $txt[316]) . "\n\t\t\t" . printlink("panic", "Oscurit&agrave;, multi-kill") . "\n\t\t\t" . printlink("alarms", "Allarmi") . "\n\t\t\t" . printlink("objects", "Oggetti") . "\n\t\t\t" . printlink("money", "Soldi") . "\n\t\t\t" . printlink("hints", "Hint del master") . "\n\t\t\t<tr valign=\"top\">\n\t\t\t<td class=\"ucp_cell\" style=\"cursor: default;\" height=\"100%\"><Br><a href=\"#\" onClick=\"javascript: window.close();\">[{$txt['133']}]</a><Br><Br></td>\n\t\t\t</tr>\n\t\t\t</table>\n\t\t\t</td>\n\t\t\t<Td width=\"5\" class=\"ucp_divider\">&nbsp;</td>\n\t\t\t<td class=\"ucp_bodycell\">{$body}</td>\n\t\t\t</tr>\n\t\t\t</table>\n\t\t\t</div>";
    }
    $print->normal_window($head, $print->ss_ucp . $cbody);
}
Example #2
0
function roomcp_master()
{
    global $x7p, $x7s, $print, $db, $txt, $x7c, $prefix;
    // Check permissions to make sure they have access to the Room Control Panel
    if ($x7c->permissions['room_operator'] == 0) {
        $print->normal_window($txt[215], "++" . $txt[216]);
        return "";
    }
    $head = $txt[41];
    $body = $txt[217];
    if (!isset($_GET['cp_page'])) {
        $_GET['cp_page'] = "main";
    }
    if ($_GET['cp_page'] == "main") {
        // The main CP -- hmm, duh
        // Nothing needs done here
        $body = "<a href=\"index.php?act=admincp\">Vai al pannello di amministrazione generale</a>";
    } elseif ($_GET['cp_page'] == "settings") {
        $head = $txt[218];
        if ($x7c->permissions['make_rooms'] == 0) {
            $body = "--" . $txt[216];
            return;
        }
        if (!isset($_POST['topic'])) {
            // Some quick defaults
            if ($x7c->room_data['moderated'] == 1) {
                $def['moderated'] = " CHECKED";
            } else {
                $def['moderated'] = "";
            }
            if ($x7c->room_data['time'] == 0) {
                $def['neverexpire'] = " CHECKED";
            } else {
                $def['neverexpire'] = "";
            }
            if ($x7c->room_data['panic_free'] == 1) {
                $def['panic_free'] = " CHECKED";
            } else {
                $def['panic_free'] = "";
            }
            if ($x7c->room_data['hunt'] == 1) {
                $def['hunt'] = " CHECKED";
            } else {
                $def['hunt'] = "";
            }
            $body = "<Br><Br><form action=\"index.php?act=roomcp&cp_page=settings&room={$_GET['room']}\" method=\"post\">\n\t\t\t\t<table width=\"100%\" align=\"center\" border=\"0\" cellspacing=\"5\" cellpadding=\"0\">\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td width=\"33%\">Descrizione:</td>\n \t\t\t\t\t\t<td ><textarea class=\"text_input\" name=\"topic\" style=\"width: 100%; height: 200px\">{$x7c->room_data['topic']}</textarea></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t\t<input type=\"hidden\" class=\"text_input\" style=\"width: 100%;\" name=\"greeting\" value=\"{$x7c->room_data['greeting_raw']}\" autocomplete=\"off\">\n\t\t\t\t\t\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>{$txt['3']}:</td>\n\t\t\t\t\t\t<td><input type=\"password\" class=\"text_input\" style=\"width: 100%;\"  name=\"password\" autocomplete=\"off\" value=\"{$x7c->room_data['password']}\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>{$txt['67']}:</td>\n\t\t\t\t\t\t<td><input type=\"text\" class=\"text_input\" style=\"width: 100%;\" name=\"max_users\" value=\"{$x7c->room_data['maxusers']}\"></td>\n\t\t\t\t\t</tr>\n                                        <td>Nome lungo:</td>\n\t\t\t\t\t\t\t\t<td width=\"100\"><input type=\"text\" style=\"width: 100%;\" class=\"text_input\" name=\"long_name\" value=\"{$x7c->room_data['long_name']}\"></td>\n\t\t\t\t\t";
            if ($x7c->permissions['set_background'] == 1 && $x7c->settings['enable_roombgs'] == 1) {
                $body .= "<tr>\n\t\t\t\t\t\t\t\t<td>Immagine per la descrizione:</font></td>\n\t\t\t\t\t\t\t\t<td><input type=\"text\" class=\"text_input\" style=\"width: 100%;\"  name=\"rm_bg\" value=\"{$x7c->room_data['background']}\"></td>\n\t\t\t\t\t\t\t</tr>";
            }
            if ($x7c->permissions['set_logo'] == 1 && $x7c->settings['enable_roomlogo'] == 1) {
                $body .= "<tr>\n\t\t\t\t\t\t\t\t<td>Immagine polaroid:</td>\n\t\t\t\t\t\t\t\t<td><input type=\"text\" class=\"text_input\" style=\"width: 100%;\"  name=\"image_url\" value=\"{$x7c->room_data['logo']}\"></td>\n\t\t\t\t\t\t\t\t<tr><td>&nbsp;</td><td><a onClick=\"javascript: window.open('index.php?act=images&subdir=polaroid','Images','location=no,menubar=no,resizable=yes,status=no,toolbar=no,scrollbars=yes,width={$x7c->settings['tweak_window_large_width']},height={$x7c->settings['tweak_window_large_height']}');\">[Carica immagine]</a></td></tr>\n\t\t\t\t\t\t\t</tr>";
            }
            if ($x7c->room_data['type'] == 1) {
                $def['public'] = " selected=true";
                $def['private'] = "";
            } else {
                $def['public'] = "";
                $def['private'] = " selected=true";
            }
            $type_options = "<option value=\"1\"{$def['public']}>{$txt['68']}</option>";
            if ($x7c->permissions['make_proom'] != 0) {
                $type_options .= "<option value=\"2\"{$def['private']}>{$txt['69']}</option>";
            }
            $body .= "<tr>\n\t\t\t\t\t\t\t<td>{$txt['64']}:</td>\n\t\t\t\t\t\t\t<td><select class=\"text_input\" style=\"width: 100px;\" name=\"room_type\">{$type_options}</select></td>\n\t\t\t\t\t\t</tr>";
            $body .= "<tr>\n\t\t\t\t\t\t\t\t<td>Non &egrave; affetta dal panico:</td>\n\t\t\t\t\t\t\t\t<td><input type=\"checkbox\" name=\"panic_free\" value=\"1\"{$def['panic_free']}></td>\n\t\t\t\t\t\t</tr>";
            $body .= "<tr>\n\t\t\t\t\t\t\t\t<td>Stanza hunt (random avatar):</td>\n\t\t\t\t\t\t\t\t<td><input type=\"checkbox\" name=\"hunt\" value=\"1\"{$def['hunt']}></td>\n\t\t\t\t\t\t</tr>";
            $body .= "<tr>\n\t\t\t\t\t\t\t<td colspan=\"2\"><Br><div align=\"center\"><input type=\"submit\" class=\"text_input\" value=\"{$txt['187']}\"></div></td>\n\t\t\t\t\t\t</tr></form></table>";
        } else {
            // Update actual settings, print ok message
            include_once "./lib/rooms.php";
            // Check some values
            if ($_POST['max_users'] == "" || $_POST['max_users'] < 3) {
                $_POST['max_users'] = "3";
            }
            if (@$_POST['moderated'] == "" || $x7c->permissions['make_mod'] == 0) {
                $_POST['moderated'] = 0;
            }
            if ($x7c->permissions['make_proom'] == 0 || $_POST['room_type'] != 1 && $_POST['room_type'] != 2) {
                $_POST['room_type'] = 1;
            }
            if ($x7c->permissions['set_background'] == 0 || $x7c->settings['enable_roombgs'] == 0 || !isset($_POST['rm_bg'])) {
                $_POST['rm_bg'] = $x7c->room_data['background'];
            }
            if ($x7c->permissions['set_logo'] == 0 || $x7c->settings['enable_roomlogo'] == 0 || !isset($_POST['image_url'])) {
                $_POST['image_url'] = $x7c->room_data['logo'];
            }
            if (!isset($_POST['panic_free'])) {
                $_POST['panic_free'] = 0;
            }
            if (!isset($_POST['hunt'])) {
                $_POST['hunt'] = 0;
            }
            //We enable html formatting for the topic field
            $_POST['topic'] = preg_replace("/&lt;/i", "<", $_POST['topic']);
            $_POST['topic'] = preg_replace("/&gt;/i", ">", $_POST['topic']);
            $_POST['topic'] = preg_replace("/&quot;/i", "\"", $_POST['topic']);
            // Order `em up
            $new_settings[] = $_POST['room_type'];
            $new_settings[] = $_POST['moderated'];
            $new_settings[] = $_POST['topic'];
            $new_settings[] = $_POST['greeting'];
            $new_settings[] = $_POST['password'];
            $new_settings[] = $_POST['max_users'];
            $new_settings[] = $_POST['rm_bg'];
            $new_settings[] = $_POST['image_url'];
            $new_settings[] = $_POST['panic_free'];
            $new_settings[] = $_POST['long_name'];
            $new_settings[] = $_POST['hunt'];
            mass_change_roomsettings($_GET['room'], $new_settings);
            $body = $txt[210];
        }
    } elseif ($_GET['cp_page'] == "blocklist") {
        $head = $txt[141];
        if (@$_GET['subact'] == "ban" && isset($_POST['toban'])) {
            if (@$_POST['len_unlimited'] == 1) {
                $length = 0;
            } else {
                $length = $_POST['len_limited'] * $_POST['len_period'];
            }
            new_ban($_POST['toban'], $length, $_POST['reason'], $x7c->room_data['id']);
            $body = "{$txt['234']}<br><Br>";
        } elseif (@$_GET['subact'] == "unban") {
            remove_ban($_GET['banid'], $x7c->room_data['id']);
            $body = "{$txt['235']}<Br><Br>";
        } else {
            $body = "";
        }
        $body .= "{$txt['233']}<Br><Br><table border=\"0\" align=\"center\" cellspacing=\"0\" cellpadding=\"2\" class=\"col_header\">\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td width=\"100\">{$txt['224']}</td>\n\t\t\t\t\t\t\t<td width=\"110\">{$txt['223']}</td>\n\t\t\t\t\t\t\t<td width=\"50\">{$txt['225']}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t</table>\n\t\t\t\t\t\t<table border=\"0\" align=\"center\" cellspacing=\"0\" cellpadding=\"2\" class=\"inside_table\">";
        // Get the ban records
        $query = $db->DoQuery("SELECT * FROM {$prefix}banned WHERE room='{$x7c->room_data['id']}'");
        while ($row = $db->Do_Fetch_Row($query)) {
            if ($row[4] == 0) {
                $length = $txt[226];
            } else {
                $length = date("{$x7c->settings['date_format_full']}", $row[3] + $row[4]);
            }
            $body .= "<tr>\n\t\t\t\t\t\t\t\t<td width=\"100\" class=\"dark_row\"><a href=\"index.php?act=roomcp&cp_page=blocklist&subact=unban&banid={$row['0']}&room={$_GET['room']}\">{$row['2']}</a></td>\n\t\t\t\t\t\t\t\t<td width=\"110\" class=\"dark_row\">{$row['5']}</td>\n\t\t\t\t\t\t\t\t<td width=\"50\" class=\"dark_row\" style=\"text-align: center\">{$length}</td>\n\t\t\t\t\t\t\t</tr>";
        }
        $body .= "</table><Br><br>\n\t\t\t\t\t<form action=\"index.php?act=roomcp&cp_page=blocklist&subact=ban&room={$_GET['room']}\" method=\"post\">\n\t\t\t\t\t\t<table align=\"center\" border=\"0\" cellspacing=\"5\" cellpadding=\"0\">\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td width=\"200\" colspan=\"2\"><div align=\"center\"><b>{$txt['222']}</b></div></td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td width=\"100\">{$txt['224']}: </td>\n\t\t\t\t\t\t\t\t<td width=\"100\"><input type=\"text\" name=\"toban\" class=\"text_input\"></td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td width=\"100\">{$txt['223']}: </td>\n\t\t\t\t\t\t\t\t<td width=\"100\"><input type=\"text\" name=\"reason\" class=\"text_input\"></td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr valign=\"top\">\n\t\t\t\t\t\t\t\t<td width=\"100\">{$txt['225']}: </td>\n\t\t\t\t\t\t\t\t<td width=\"100\" style=\"text-align: center\">{$txt['226']} <input type=\"checkbox\" value=\"1\" name=\"len_unlimited\" CHECKED>\n\t\t\t\t\t\t\t\t\t<Br>{$txt['227']}\n\t\t\t\t\t\t\t\t\t<Br>\n\t\t\t\t\t\t\t\t\t<input type=\"text\" class=\"text_input\" style=\"width: 45px;text-align: center;\" name=\"len_limited\" value=\"0\">\n\t\t\t\t\t\t\t\t\t<select name=\"len_period\" class=\"text_input\">\n\t\t\t\t\t\t\t\t\t\t<option value=\"60\">{$txt['228']}</option>\n\t\t\t\t\t\t\t\t\t\t<option value=\"3600\">{$txt['229']}</option>\n\t\t\t\t\t\t\t\t\t\t<option value=\"86400\">{$txt['230']}</option>\n\t\t\t\t\t\t\t\t\t\t<option value=\"604800\">{$txt['231']}</option>\n\t\t\t\t\t\t\t\t\t\t<option value=\"2419200\">{$txt['232']}</option>\n\t\t\t\t\t\t\t\t\t</select>\n\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td width=\"200\" colspan=\"2\"><div align=\"center\"><input type=\"submit\" value=\"{$txt['222']}\" class=\"button\"></div></td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t</table>\n\t\t\t\t\t</form>";
    } elseif ($_GET['cp_page'] == "ops") {
        $head = $txt[219];
        // Include the necessary librarys for this
        include_once "./lib/usercontrol.php";
        if (isset($_POST['add'])) {
            // Give them operator status
            $body = $txt[105] . "<Br><Br>";
            $uco = new user_control($_POST['add']);
            if ($uco->user_info->profile['id'] != "") {
                $uco->give_ops();
                $x7c->room_data['ops'] .= ";" . $uco->user_info->profile['id'];
            } else {
                $body = $txt[239] . "<Br><Br>";
            }
        } elseif (isset($_GET['revoke'])) {
            // Take away their operator status
            $body = $txt[106] . "<br><br>";
            $uco = new user_control($_GET['revoke']);
            $uco->take_ops();
            // Clear it so it isn't displayed again
            $ops = explode(";", $x7c->room_data['ops']);
            $ops_id = array_search($uco->user_info->profile['id'], $ops);
            unset($ops[$ops_id]);
            $x7c->room_data['ops'] = implode(";", $ops);
        } else {
            $body = "";
        }
        // Make a listing of all operators in this room
        $body .= $txt[236] . "<Br>";
        $ops = explode(";", $x7c->room_data['ops']);
        foreach ($ops as $key => $val) {
            $username = get_user_by_id($val);
            $body .= "<Br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"index.php?act=roomcp&cp_page=ops&room={$_GET['room']}&revoke={$username}\">{$username}</a>";
        }
        $body .= "<Br><Br><form action=\"index.php?act=roomcp&cp_page=ops&room={$_GET['room']}\" method=\"post\">\n\t\t\t{$txt['94']}: <input type=\"text\" name=\"add\" class=\"text_input\"> <input type=\"submit\" class=\"button\" value=\"{$txt['94']}\">\n\t\t\t</form><Br><Br>";
    } elseif ($_GET['cp_page'] == "voices") {
        $head = $txt[220];
        // Include the necessary librarys for this
        include_once "./lib/usercontrol.php";
        if (isset($_POST['add'])) {
            // Give them a voice
            $body = $txt[113] . "<Br><Br>";
            $uco = new user_control($_POST['add']);
            if ($uco->user_info->profile['id'] != "") {
                $uco->voice();
                $x7c->room_data['voiced'] .= ";" . $uco->user_info->profile['id'];
            } else {
                $body = $txt[239] . "<Br><Br>";
            }
        } elseif (isset($_GET['revoke'])) {
            // Take their voice
            $body = $txt[114] . "<br><br>";
            $uco = new user_control($_GET['revoke']);
            $uco->unvoice();
            // Clear it so it isn't displayed again
            $voice = explode(";", $x7c->room_data['voiced']);
            $voice_id = array_search($uco->user_info->profile['id'], $voice);
            unset($voice[$voice_id]);
            $x7c->room_data['voiced'] = implode(";", $voice);
        } else {
            $body = "";
        }
        // Make a listing of all voiced users in this room
        $body .= $txt[237] . "<Br>";
        $voice = explode(";", $x7c->room_data['voiced']);
        foreach ($voice as $key => $val) {
            if ($val > 0) {
                $username = get_user_by_id($val);
                $body .= "<Br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"index.php?act=roomcp&cp_page=voices&room={$_GET['room']}&revoke={$username}\">{$username}</a>";
            }
        }
        $body .= "<Br><Br><form action=\"index.php?act=roomcp&cp_page=voices&room={$_GET['room']}\" method=\"post\">\n\t\t\t{$txt['99']}: <input type=\"text\" name=\"add\" class=\"text_input\"> <input type=\"submit\" class=\"button\" value=\"{$txt['99']}\">\n\t\t\t</form><Br><Br>";
    } elseif ($_GET['cp_page'] == "mutes") {
        $head = $txt[221];
        // Include the necessary librarys for this
        include_once "./lib/usercontrol.php";
        if (isset($_POST['add'])) {
            // Mute them
            $body = $txt[111] . "<Br><Br>";
            $uco = new user_control($_POST['add']);
            if ($uco->user_info->profile['id'] != "") {
                $uco->mute();
                $x7c->room_data['voiced'] .= ";-" . $uco->user_info->profile['id'];
            } else {
                $body = $txt[239] . "<Br><Br>";
            }
        } elseif (isset($_GET['revoke'])) {
            // Make them on longer muted
            $body = $txt[112] . "<br><br>";
            $uco = new user_control($_GET['revoke']);
            $uco->unmute();
            // Clear it so it isn't displayed again
            $mute = explode(";", $x7c->room_data['voiced']);
            $mute_id = array_search("-{$uco->user_info->profile['id']}", $mute);
            unset($mute[$mute_id]);
            $x7c->room_data['voiced'] = implode(";", $mute);
        } else {
            $body = "";
        }
        // Make a listing of all operators in this room
        $body .= $txt[238] . "<Br>";
        $mute = explode(";", $x7c->room_data['voiced']);
        foreach ($mute as $key => $val) {
            if ($val < 0) {
                $val = $val * -1;
                $username = get_user_by_id($val);
                $body .= "<Br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"index.php?act=roomcp&cp_page=mutes&room={$_GET['room']}&revoke={$username}\">{$username}</a>";
            }
        }
        $body .= "<Br><Br><form action=\"index.php?act=roomcp&cp_page=mutes&room={$_GET['room']}\" method=\"post\">\n\t\t\t{$txt['93']}: <input type=\"text\" name=\"add\" class=\"text_input\"> <input type=\"submit\" class=\"button\" value=\"{$txt['93']}\">\n\t\t\t</form><Br><Br>";
    } elseif ($_GET['cp_page'] == "logs") {
        $head = $txt[240];
        if ($x7c->permissions['access_room_logs'] == 0) {
            $body = "--" . $txt[216];
        } else {
            include_once "./lib/logs.php";
            $log = new logs(1, $_GET['room']);
            if (isset($_GET['subact'])) {
                if ($_GET['subact'] == 'enable') {
                    // Enable logging
                    include_once "./lib/rooms.php";
                    change_roomsetting($_GET['room'], "logged", 1);
                    $x7c->room_data['logged'] = 1;
                } elseif ($_GET['subact'] == 'disable') {
                    // Disable logging
                    include_once "./lib/rooms.php";
                    change_roomsetting($_GET['room'], "logged", 0);
                    $x7c->room_data['logged'] = 0;
                } elseif ($_GET['subact'] == 'clear') {
                    // Clear the log
                    $log->clear();
                    $log->log_size = 0;
                }
            }
            if ($x7c->room_data['logged'] == 1) {
                $body = "{$txt['242']}.  <a href=\"index.php?act=roomcp&cp_page=logs&subact=disable&room={$_GET['room']}\">[{$txt['245']}]</a><Br><Br>";
            } else {
                $body = "{$txt['243']}.  <a href=\"index.php?act=roomcp&cp_page=logs&subact=enable&room={$_GET['room']}\">[{$txt['244']}]</a><Br><Br>";
            }
            // Display file size information
            if ($x7c->settings['max_log_room'] != 0) {
                $percent1 = round($log->log_size / $x7c->settings['max_log_room'], 2) * 100;
                $percent1 .= "%";
                $percent2 = 100 - $percent1 . "%";
                $fs1 = round($log->log_size / 1024, 2);
                $fs2 = round(($x7c->settings['max_log_room'] - $log->log_size) / 1024, 2);
            } else {
                $percent1 = $txt[248];
                $percent2 = $txt[248];
                $fs1 = round($log->log_size / 1024, 2);
                $fs2 = "({$txt['248']})";
            }
            $txt[246] = eregi_replace("_p", "{$percent1}", $txt[246]);
            $txt[247] = eregi_replace("_p", "{$percent2}", $txt[247]);
            $txt[246] = eregi_replace("_s", "{$fs1}", $txt[246]);
            $txt[247] = eregi_replace("_s", "{$fs2}", $txt[247]);
            $body .= "{$txt['246']}<Br>{$txt['247']}<Br><Br>";
            // If logging is enabled then show the log
            if ($x7c->room_data['logged'] == 1) {
                // Get the log contents
                $contents = $log->get_log_contents_per_date();
                // Calculate the pages display
                $selected_date = "";
                if (isset($_POST['date'])) {
                    $selected_date = "value=\"{$_POST['date']}\"";
                }
                $pages = '<script language="javascript" type="text/javascript" src="lib/datetimepicker.js" ></script>
					<script language="javascript" type="text/javascript">
						function jump_to_date(date_str) {
							document.getElementById(\'demo1\').value = date_str;
							document.forms[0].submit();

						}
					</script>
					<form id="dateform" name="dateform1" action="index.php?act=roomcp&cp_page=logs&room=' . $_GET['room'] . '" method="post">
						<input type="Text" name="date" id="demo1" maxlength="15" size="15" ' . $selected_date . '><a href="javascript:NewCal(\'demo1\',\'ddmmyyyy\',false,24)"><img src="graphic/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>
					</form>
					';
                $body .= "<Br>{$pages}<hr>";
                include_once "./lib/message.php";
                $body .= '<div style="background: black; color: white;">';
                $header = false;
                $count = 0;
                foreach ($contents as $linenum => $entry) {
                    // Get date and sender
                    $count++;
                    $message = "";
                    $match = "";
                    if (preg_match("/^(.+?);\\[(.+?)\\]/", $entry, $match)) {
                        $entry = preg_replace("/^(.+?);\\[(.+?)\\]/", "", $entry);
                        $date = date($x7c->settings['date_format_full'], $match[1]);
                        $sender = $match[2];
                        // Get message
                        $message = $entry;
                    } else {
                        $message = "<b>Warning: wrong log format </b>" . $entry;
                    }
                    if (!$header) {
                        if ($match) {
                            $date_short = date("j/n/Y", $match[1]);
                            $body .= "<a href=\"#\" onClick=\"javascript: jump_to_date('{$date_short}');\"> &lt;&lt;&lt; {$date_short}</a><br><br>";
                        }
                        $header = true;
                    } else {
                        if ($count == sizeof($contents)) {
                            if ($match) {
                                $date_short = date("j/n/Y", $match[1]);
                                $body .= "<a href=\"#\" onClick=\"javascript: jump_to_date('{$date_short}');\">{$date_short} &gt;&gt;&gt;</a><br><br>";
                            }
                        } else {
                            $body .= "<b>{$sender}</b>[{$date}]: {$message}<br><br>";
                        }
                    }
                }
                $body .= "</div><hr>{$pages}<Br><Br>";
            }
        }
    }
    // THis mini-function determines what the active section link is
    function whatsmyclass($id)
    {
        $x = $_GET['cp_page'];
        if ($x == $id) {
            return " class=\"ucp_sell\"";
        } else {
            return " class=\"ucp_cell\" onMouseOver=\"javascript: this.className='ucp_sell'\" onMouseOut=\"javascript: this.className='ucp_cell'\"  onClick=\"javascript: window.location='./index.php?act=roomcp&cp_page={$id}&room={$_GET['room']}'\"";
        }
    }
    // Add the menu to the body
    $cbody = "<div align=\"center\">\n\t\t\t<table border=\"0\" width=\"95%\" class=\"ucp_table\" cellspacing=\"0\" cellpadding=\"0\">\n\t\t\t\t<tr valign=\"top\">\n\t\t\t\t\t<td width=\"20%\" height=\"100%\">\n\t\t\t\t\t\t<table class=\"ucp_table2\" height=\"100%\" border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td width=\"100%\"" . whatsmyclass("main") . ">{$txt['137']}</td>\n\t\t\t\t\t\t\t</tr>";
    if ($x7c->permissions['make_rooms'] == 1) {
        $cbody .= "\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td width=\"100%\"" . whatsmyclass("settings") . ">{$txt['218']}</td>\n\t\t\t\t\t\t\t</tr>";
    }
    if ($x7c->permissions['access_room_logs'] == 1) {
        $cbody .= "\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td width=\"100%\"" . whatsmyclass("logs") . ">{$txt['240']}</td>\n\t\t\t\t\t\t\t\t</tr>";
    }
    $cbody .= "<tr valign=\"top\">\n\t\t\t\t\t\t\t\t<td width=\"100%\" class=\"ucp_cell\" style=\"cursor: default;\" height=\"100%\"><Br>";
    //if($x7c->settings['single_room_mode'] == "")
    //	$cbody .= 					"<a href=\"./index.php\">[$txt[29]]</a><Br>";
    $cbody .= "<a href=\"#\" onClick=\"javascript: window.close();\">[{$txt['133']}]</a><Br><Br>\n\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t</tr>";
    $cbody .= "</table>\n\t\t\t\t\t</td>\n\t\t\t\t\t<Td width=\"5\" class=\"ucp_divider\">&nbsp;</td>\n\t\t\t\t\t<td class=\"ucp_bodycell\">{$body}</td>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t\t</div>";
    $print->normal_window($head, $print->ss_ucp . $cbody);
}