function ManageLabels() { global $txt, $context, $db_prefix, $ID_MEMBER, $scripturl, $func; // Build the link tree elements... $context['linktree'][] = array('url' => $scripturl . '?action=pm;sa=manlabels', 'name' => $txt['pm_manage_labels']); $context['page_title'] = $txt['pm_manage_labels']; $context['sub_template'] = 'labels'; $the_labels = array(); // Add all existing labels to the array to save, slashing them as necessary... foreach ($context['labels'] as $label) { if ($label['id'] != -1) { $the_labels[$label['id']] = addslashes($label['name']); } } if (isset($_GET['sesc'])) { // This will be for updating messages. $message_changes = array(); $new_labels = array(); // Adding a new label? if (isset($_POST['add'])) { $_POST['label'] = strtr($func['htmlspecialchars'](trim($_POST['label'])), array(',' => ',')); if ($func['strlen']($_POST['label']) > 30) { $_POST['label'] = $func['substr']($_POST['label'], 0, 30); } if ($_POST['label'] != '') { $the_labels[] = $_POST['label']; } } elseif (isset($_POST['delete'], $_POST['delete_label'])) { $i = 0; foreach ($the_labels as $id => $name) { if (isset($_POST['delete_label'][$id])) { unset($the_labels[$id]); $message_changes[$id] = true; } else { $new_labels[$id] = $i++; } } } elseif (isset($_POST['save']) && !empty($_POST['label_name'])) { $i = 0; foreach ($the_labels as $id => $name) { if ($id == -1) { continue; } elseif (isset($_POST['label_name'][$id])) { $_POST['label_name'][$id] = trim(strtr($func['htmlspecialchars']($_POST['label_name'][$id]), array(',' => ','))); if ($func['strlen']($_POST['label_name'][$id]) > 30) { $_POST['label_name'][$id] = $func['substr']($_POST['label_name'][$id], 0, 30); } if ($_POST['label_name'][$id] != '') { $the_labels[(int) $id] = $_POST['label_name'][$id]; $new_labels[$id] = $i++; } else { unset($the_labels[(int) $id]); $message_changes[(int) $id] = true; } } else { $new_labels[$id] = $i++; } } } // Save the label status. updateMemberData($ID_MEMBER, array('messageLabels' => "'" . implode(',', $the_labels) . "'")); // Update all the messages currently with any label changes in them! if (!empty($message_changes)) { $searchArray = array_keys($message_changes); if (!empty($new_labels)) { for ($i = max($searchArray) + 1, $n = max(array_keys($new_labels)); $i <= $n; $i++) { $searchArray[] = $i; } } // Now find the messages to change. $request = db_query("\n\t\t\t\tSELECT ID_PM, labels\n\t\t\t\tFROM {$db_prefix}pm_recipients\n\t\t\t\tWHERE FIND_IN_SET('" . implode("', labels) OR FIND_IN_SET('", $searchArray) . "', labels)\n\t\t\t\t\tAND ID_MEMBER = {$ID_MEMBER}", __FILE__, __LINE__); while ($row = mysql_fetch_assoc($request)) { // Do the long task of updating them... $toChange = explode(',', $row['labels']); foreach ($toChange as $key => $value) { if (in_array($value, $searchArray)) { if (isset($new_labels[$value])) { $toChange[$key] = $new_labels[$value]; } else { unset($toChange[$key]); } } } if (empty($toChange)) { $toChange[] = '-1'; } // Update the message. db_query("\n\t\t\t\t\tUPDATE {$db_prefix}pm_recipients\n\t\t\t\t\tSET labels = '" . implode(',', array_unique($toChange)) . "'\n\t\t\t\t\tWHERE ID_PM = {$row['ID_PM']}\n\t\t\t\t\t\tAND ID_MEMBER = {$ID_MEMBER}\n\t\t\t\t\tLIMIT 1", __FILE__, __LINE__); } mysql_free_result($request); } // To make the changes appear right away, redirect. redirectExit('action=pm;sa=manlabels'); } }
function deleteAccount2($profile_vars, $post_errors, $memID) { global $user_info, $sourcedir, $context, $cur_profile, $modSettings, $smcFunc; // Try get more time... @set_time_limit(600); // !!! Add a way to delete pms as well? if (!$context['user']['is_owner']) { isAllowedTo('profile_remove_any'); } elseif (!allowedTo('profile_remove_any')) { isAllowedTo('profile_remove_own'); } checkSession(); $old_profile =& $cur_profile; // Too often, people remove/delete their own only account. if (in_array(1, explode(',', $old_profile['additional_groups'])) || $old_profile['id_group'] == 1) { // Are you allowed to administrate the forum, as they are? isAllowedTo('admin_forum'); $request = $smcFunc['db_query']('', ' SELECT id_member FROM {db_prefix}members WHERE (id_group = {int:admin_group} OR FIND_IN_SET({int:admin_group}, additional_groups) != 0) AND id_member != {int:selected_member} LIMIT 1', array('admin_group' => 1, 'selected_member' => $memID)); list($another) = $smcFunc['db_fetch_row']($request); $smcFunc['db_free_result']($request); if (empty($another)) { fatal_lang_error('at_least_one_admin', 'critical'); } } // This file is needed for the deleteMembers function. require_once $sourcedir . '/Subs-Members.php'; // Do you have permission to delete others profiles, or is that your profile you wanna delete? if ($memID != $user_info['id']) { isAllowedTo('profile_remove_any'); // Now, have you been naughty and need your posts deleting? // !!! Should this check board permissions? if ($_POST['remove_type'] != 'none' && allowedTo('moderate_forum')) { // Include RemoveTopics - essential for this type of work! require_once $sourcedir . '/RemoveTopic.php'; // First off we delete any topics the member has started - if they wanted topics being done. if ($_POST['remove_type'] == 'topics') { // Fetch all topics started by this user within the time period. $request = $smcFunc['db_query']('', ' SELECT t.id_topic FROM {db_prefix}topics AS t WHERE t.id_member_started = {int:selected_member}', array('selected_member' => $memID)); $topicIDs = array(); while ($row = $smcFunc['db_fetch_assoc']($request)) { $topicIDs[] = $row['id_topic']; } $smcFunc['db_free_result']($request); // Actually remove the topics. // !!! This needs to check permissions, but we'll let it slide for now because of moderate_forum already being had. removeTopics($topicIDs); } // Now delete the remaining messages. $request = $smcFunc['db_query']('', ' SELECT m.id_msg FROM {db_prefix}messages AS m INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic AND t.id_first_msg != m.id_msg) WHERE m.id_member = {int:selected_member}', array('selected_member' => $memID)); // This could take a while... but ya know it's gonna be worth it in the end. while ($row = $smcFunc['db_fetch_assoc']($request)) { if (function_exists('apache_reset_timeout')) { @apache_reset_timeout(); } removeMessage($row['id_msg']); } $smcFunc['db_free_result']($request); } // Only delete this poor members account if they are actually being booted out of camp. if (isset($_POST['deleteAccount'])) { deleteMembers($memID); } } elseif (empty($post_errors) && !empty($modSettings['approveAccountDeletion']) && !allowedTo('moderate_forum')) { // Setup their account for deletion ;) updateMemberData($memID, array('is_activated' => 4)); // Another account needs approval... updateSettings(array('unapprovedMembers' => true), true); } elseif (empty($post_errors)) { deleteMembers($memID); require_once $sourcedir . '/LogInOut.php'; LogOut(true); redirectExit(); } }
function ConvertUtf8() { global $scripturl, $context, $txt, $language, $db_prefix, $db_character_set; global $modSettings, $user_info, $sourcedir; // Show me your badge! isAllowedTo('admin_forum'); // The character sets used in SMF's language files with their db equivalent. $charsets = array('big5' => 'big5', 'gbk' => 'gbk', 'ISO-8859-1' => 'latin1', 'ISO-8859-2' => 'latin2', 'ISO-8859-9' => 'latin5', 'tis-620' => 'tis620', 'UTF-8' => 'utf8', 'windows-1251' => 'cp1251', 'windows-1253' => 'utf8', 'windows-1255' => 'utf8', 'windows-1256' => 'cp1256'); // Get a list of character sets supported by your MySQL server. $request = db_query("\n\t\tSHOW CHARACTER SET", __FILE__, __LINE__); $db_charsets = array(); while ($row = mysql_fetch_assoc($request)) { $db_charsets[] = $row['Charset']; } // Character sets supported by both MySQL and SMF's language files. $charsets = array_intersect($charsets, $db_charsets); // This is for the first screen telling backups is good. if (!isset($_POST['proceed'])) { adminIndex('maintain_forum'); // Character set conversions are only supported as of MySQL 4.1.2. if (version_compare('4.1.2', preg_replace('~\\-.+?$~', '', mysql_get_server_info())) > 0) { fatal_lang_error('utf8_db_version_too_low'); } // Use the messages.body column as indicator for the database charset. $request = db_query("\n\t\t\tSHOW FULL COLUMNS\n\t\t\tFROM {$db_prefix}messages\n\t\t\tLIKE 'body'", __FILE__, __LINE__); $column_info = mysql_fetch_assoc($request); mysql_free_result($request); // A collation looks like latin1_swedish. We only need the character set. list($context['database_charset']) = explode('_', $column_info['Collation']); $context['database_charset'] = in_array($context['database_charset'], $charsets) ? array_search($context['database_charset'], $charsets) : $context['database_charset']; // No need to convert to UTF-8 if it already is. if ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8') { fatal_lang_error('utf8_already_utf8'); } // Grab the character set from the default language file. loadLanguage('index', $language, true); $context['charset_detected'] = $txt['lang_character_set']; $context['charset_about_detected'] = sprintf($txt['utf8_detected_charset'], $language, $context['charset_detected']); // Go back to your own language. loadLanguage('index', $user_info['language'], true); // Show a warning if the character set seems not to be supported. if (!isset($charsets[strtr(strtolower($context['charset_detected']), array('utf' => 'UTF', 'iso' => 'ISO'))])) { $context['charset_warning'] = sprintf($txt['utf8_charset_not_supported'], $txt['lang_character_set']); // Default to ISO-8859-1. $context['charset_detected'] = 'ISO-8859-1'; } $context['charset_list'] = array_keys($charsets); $context['page_title'] = $txt['utf8_title']; $context['sub_template'] = 'convert_utf8'; return; } // After this point we're starting the conversion. But first: session check. checkSession(); // Translation table for the character sets not native for MySQL. $translation_tables = array('windows-1255' => array('0x81' => '\'\'', '0x8A' => '\'\'', '0x8C' => '\'\'', '0x8D' => '\'\'', '0x8E' => '\'\'', '0x8F' => '\'\'', '0x90' => '\'\'', '0x9A' => '\'\'', '0x9C' => '\'\'', '0x9D' => '\'\'', '0x9E' => '\'\'', '0x9F' => '\'\'', '0xCA' => '\'\'', '0xD9' => '\'\'', '0xDA' => '\'\'', '0xDB' => '\'\'', '0xDC' => '\'\'', '0xDD' => '\'\'', '0xDE' => '\'\'', '0xDF' => '\'\'', '0xFB' => '\'\'', '0xFC' => '\'\'', '0xFF' => '\'\'', '0xC2' => '0xFF', '0x80' => '0xFC', '0xE2' => '0xFB', '0xA0' => '0xC2A0', '0xA1' => '0xC2A1', '0xA2' => '0xC2A2', '0xA3' => '0xC2A3', '0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7', '0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB', '0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE', '0xAF' => '0xC2AF', '0xB0' => '0xC2B0', '0xB1' => '0xC2B1', '0xB2' => '0xC2B2', '0xB3' => '0xC2B3', '0xB4' => '0xC2B4', '0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7', '0xB8' => '0xC2B8', '0xB9' => '0xC2B9', '0xBB' => '0xC2BB', '0xBC' => '0xC2BC', '0xBD' => '0xC2BD', '0xBE' => '0xC2BE', '0xBF' => '0xC2BF', '0xD7' => '0xD7B3', '0xD1' => '0xD781', '0xD4' => '0xD7B0', '0xD5' => '0xD7B1', '0xD6' => '0xD7B2', '0xE0' => '0xD790', '0xEA' => '0xD79A', '0xEC' => '0xD79C', '0xED' => '0xD79D', '0xEE' => '0xD79E', '0xEF' => '0xD79F', '0xF0' => '0xD7A0', '0xF1' => '0xD7A1', '0xF2' => '0xD7A2', '0xF3' => '0xD7A3', '0xF5' => '0xD7A5', '0xF6' => '0xD7A6', '0xF7' => '0xD7A7', '0xF8' => '0xD7A8', '0xF9' => '0xD7A9', '0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6', '0x86' => '0xE280A0', '0x87' => '0xE280A1', '0x89' => '0xE280B0', '0x8B' => '0xE280B9', '0x93' => '0xE2809C', '0x94' => '0xE2809D', '0x95' => '0xE280A2', '0x97' => '0xE28094', '0x99' => '0xE284A2', '0xC0' => '0xD6B0', '0xC1' => '0xD6B1', '0xC3' => '0xD6B3', '0xC4' => '0xD6B4', '0xC5' => '0xD6B5', '0xC6' => '0xD6B6', '0xC7' => '0xD6B7', '0xC8' => '0xD6B8', '0xC9' => '0xD6B9', '0xCB' => '0xD6BB', '0xCC' => '0xD6BC', '0xCD' => '0xD6BD', '0xCE' => '0xD6BE', '0xCF' => '0xD6BF', '0xD0' => '0xD780', '0xD2' => '0xD782', '0xE3' => '0xD793', '0xE4' => '0xD794', '0xE5' => '0xD795', '0xE7' => '0xD797', '0xE9' => '0xD799', '0xFD' => '0xE2808E', '0xFE' => '0xE2808F', '0x92' => '0xE28099', '0x83' => '0xC692', '0xD3' => '0xD783', '0x88' => '0xCB86', '0x98' => '0xCB9C', '0x91' => '0xE28098', '0x96' => '0xE28093', '0xBA' => '0xC3B7', '0x9B' => '0xE280BA', '0xAA' => '0xC397', '0xA4' => '0xE282AA', '0xE1' => '0xD791', '0xE6' => '0xD796', '0xE8' => '0xD798', '0xEB' => '0xD79B', '0xF4' => '0xD7A4', '0xFA' => '0xD7AA', '0xFF' => '0xD6B2', '0xFC' => '0xE282AC', '0xFB' => '0xD792'), 'windows-1253' => array('0x81' => "''", '0x88' => "''", '0x8A' => "''", '0x8C' => "''", '0x8D' => "''", '0x8E' => "''", '0x8F' => "''", '0x90' => "''", '0x98' => "''", '0x9A' => "''", '0x9C' => "''", '0x9D' => "''", '0x9E' => "''", '0x9F' => "''", '0xAA' => "''", '0xD2' => "''", '0xFF' => "''", '0xCE' => '0xCE9E', '0xB8' => '0xCE88', '0xBA' => '0xCE8A', '0xBC' => '0xCE8C', '0xBE' => '0xCE8E', '0xBF' => '0xCE8F', '0xC0' => '0xCE90', '0xC8' => '0xCE98', '0xCA' => '0xCE9A', '0xCC' => '0xCE9C', '0xCD' => '0xCE9D', '0xCF' => '0xCE9F', '0xDA' => '0xCEAA', '0xE8' => '0xCEB8', '0xEA' => '0xCEBA', '0xEC' => '0xCEBC', '0xEE' => '0xCEBE', '0xEF' => '0xCEBF', '0xC2' => '0xFF', '0xBD' => '0xC2BD', '0xED' => '0xCEBD', '0xB2' => '0xC2B2', '0xA0' => '0xC2A0', '0xA3' => '0xC2A3', '0xA4' => '0xC2A4', '0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7', '0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB', '0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE', '0xB0' => '0xC2B0', '0xB1' => '0xC2B1', '0xB3' => '0xC2B3', '0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7', '0xBB' => '0xC2BB', '0xE2' => '0xCEB2', '0x80' => '0xD2', '0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6', '0x86' => '0xE280A0', '0xA1' => '0xCE85', '0xA2' => '0xCE86', '0x87' => '0xE280A1', '0x89' => '0xE280B0', '0xB9' => '0xCE89', '0x8B' => '0xE280B9', '0x91' => '0xE28098', '0x99' => '0xE284A2', '0x92' => '0xE28099', '0x93' => '0xE2809C', '0x94' => '0xE2809D', '0x95' => '0xE280A2', '0x96' => '0xE28093', '0x97' => '0xE28094', '0x9B' => '0xE280BA', '0xAF' => '0xE28095', '0xB4' => '0xCE84', '0xC1' => '0xCE91', '0xC3' => '0xCE93', '0xC4' => '0xCE94', '0xC5' => '0xCE95', '0xC6' => '0xCE96', '0x83' => '0xC692', '0xC7' => '0xCE97', '0xC9' => '0xCE99', '0xCB' => '0xCE9B', '0xD0' => '0xCEA0', '0xD1' => '0xCEA1', '0xD3' => '0xCEA3', '0xD4' => '0xCEA4', '0xD5' => '0xCEA5', '0xD6' => '0xCEA6', '0xD7' => '0xCEA7', '0xD8' => '0xCEA8', '0xD9' => '0xCEA9', '0xDB' => '0xCEAB', '0xDC' => '0xCEAC', '0xDD' => '0xCEAD', '0xDE' => '0xCEAE', '0xDF' => '0xCEAF', '0xE0' => '0xCEB0', '0xE1' => '0xCEB1', '0xE3' => '0xCEB3', '0xE4' => '0xCEB4', '0xE5' => '0xCEB5', '0xE6' => '0xCEB6', '0xE7' => '0xCEB7', '0xE9' => '0xCEB9', '0xEB' => '0xCEBB', '0xF0' => '0xCF80', '0xF1' => '0xCF81', '0xF2' => '0xCF82', '0xF3' => '0xCF83', '0xF4' => '0xCF84', '0xF5' => '0xCF85', '0xF6' => '0xCF86', '0xF7' => '0xCF87', '0xF8' => '0xCF88', '0xF9' => '0xCF89', '0xFA' => '0xCF8A', '0xFB' => '0xCF8B', '0xFC' => '0xCF8C', '0xFD' => '0xCF8D', '0xFE' => '0xCF8E', '0xFF' => '0xCE92', '0xD2' => '0xE282AC')); // Make some preparations. if (isset($translation_tables[$_POST['src_charset']])) { $replace = '%field%'; foreach ($translation_tables[$_POST['src_charset']] as $from => $to) { $replace = "REPLACE({$replace}, {$from}, {$to})"; } } // Grab a list of tables. if (preg_match('~^`(.+?)`\\.(.+?)$~', $db_prefix, $match) === 1) { $queryTables = db_query("\n\t\t\tSHOW TABLE STATUS\n\t\t\tFROM `" . strtr($match[1], array('`' => '')) . "`\n\t\t\tLIKE '" . str_replace('_', '\\_', $match[2]) . "%'", __FILE__, __LINE__); } else { $queryTables = db_query("\n\t\t\tSHOW TABLE STATUS\n\t\t\tLIKE '" . str_replace('_', '\\_', $db_prefix) . "%'", __FILE__, __LINE__); } while ($table_info = mysql_fetch_assoc($queryTables)) { // Just to make sure it doesn't time out. if (function_exists('apache_reset_timeout')) { apache_reset_timeout(); } $table_charsets = array(); // Loop through each column. $queryColumns = db_query("\n\t\t\tSHOW FULL COLUMNS \n\t\t\tFROM {$table_info['Name']}", __FILE__, __LINE__); while ($column_info = mysql_fetch_assoc($queryColumns)) { // Only text'ish columns have a character set and need converting. if (strpos($column_info['Type'], 'text') !== false || strpos($column_info['Type'], 'char') !== false) { $collation = empty($column_info['Collation']) || $column_info['Collation'] === 'NULL' ? $table_info['Collation'] : $column_info['Collation']; if (!empty($collation) && $collation !== 'NULL') { list($charset) = explode('_', $collation); if (!isset($table_charsets[$charset])) { $table_charsets[$charset] = array(); } $table_charsets[$charset][] = $column_info; } } } mysql_free_result($queryColumns); // Only change the column if the data doesn't match the current charset. if (count($table_charsets) === 1 && key($table_charsets) !== $charsets[$_POST['src_charset']] || count($table_charsets) > 1) { $updates_blob = ''; $updates_text = ''; foreach ($table_charsets as $charset => $columns) { if ($charset !== $charsets[$_POST['src_charset']]) { foreach ($columns as $column) { $updates_blob .= "\n\t\t\t\t\t\t\tCHANGE COLUMN {$column['Field']} {$column['Field']} " . strtr($column['Type'], array('text' => 'blob', 'char' => 'binary')) . ($column['Null'] === 'YES' ? ' NULL' : ' NOT NULL') . (strpos($column['Type'], 'char') === false ? '' : " default '{$column['Default']}'") . ','; $updates_text .= "\n\t\t\t\t\t\t\tCHANGE COLUMN {$column['Field']} {$column['Field']} {$column['Type']} CHARACTER SET " . $charsets[$_POST['src_charset']] . ($column['Null'] === 'YES' ? '' : ' NOT NULL') . (strpos($column['Type'], 'char') === false ? '' : " default '{$column['Default']}'") . ','; } } } // Change the columns to binary form. db_query("\n\t\t\t\tALTER TABLE {$table_info['Name']}" . substr($updates_blob, 0, -1), __FILE__, __LINE__); // Convert the character set if MySQL has no native support for it. if (isset($translation_tables[$_POST['src_charset']])) { $update = ''; foreach ($table_charsets as $charset => $columns) { foreach ($columns as $column) { $update .= "\n\t\t\t\t\t\t\t{$column['Field']} = " . strtr($replace, array('%field%' => $column['Field'])) . ','; } } db_query("\n\t\t\t\t\tUPDATE {$table_info['Name']}\n\t\t\t\t\tSET " . substr($update, 0, -1), __FILE__, __LINE__); } // Change the columns back, but with the proper character set. db_query("\n\t\t\t\tALTER TABLE {$table_info['Name']}" . substr($updates_text, 0, -1), __FILE__, __LINE__); } // Now do the actual conversion (if still needed). if ($charsets[$_POST['src_charset']] !== 'utf8') { db_query("\n\t\t\t\tALTER TABLE {$table_info['Name']}\n\t\t\t\tCONVERT TO CHARACTER SET utf8", __FILE__, __LINE__); } } mysql_free_result($queryTables); // Let the settings know we have a new character set. updateSettings(array('global_character_set' => 'UTF-8')); updateSettingsFile(array('db_character_set' => '\'utf8\'')); // The conversion might have messed up some serialized strings. Fix them! require_once $sourcedir . '/Subs-Charset.php'; fix_serialized_columns(); redirectExit('action=maintain'); }