Exemplo n.º 1
0
			full_page_generation('confirm_body.tpl', $lang['Confirm'], '', '');
		}
		break;

	case 'poll_delete':
		if(!$is_auth['auth_pollcreate'])
		{
			message_die(MESSAGE, sprintf($lang['Sorry_auth_delete'], $is_auth['auth_delete_type']));
		}

		$meta_content['page_title'] = $lang['Mod_CP'] . ' (' . $lang['Delete_poll'] . ')';

		if($confirm)
		{
			$topics = (isset($_POST['topic_id_list'])) ? $_POST['topic_id_list'] : array($topic_id);
			$class_mcp->topic_poll_delete($topics);

			$redirect_page = 'modcp.' . PHP_EXT . '?' . POST_FORUM_URL . '=' . $forum_id . '&sid=' . $user->data['session_id'];
			$l_redirect = sprintf($lang['Click_return_modcp'], '<a href="'. $redirect_page .'">', '</a>') . '<br /><br />'. sprintf($lang['Click_return_forum'], '<a href="'. CMS_PAGE_VIEWFORUM . '?' . POST_FORUM_URL . '=' . $forum_id . '&amp;sid=' . $user->data['session_id'] .'">', '</a>');

			$redirect_url = $redirect_page;
			meta_refresh(3, $redirect_url);

			message_die(GENERAL_MESSAGE, ((sizeof($topics) == '1') ? $lang['Mod_CP_poll_removed'] : $lang['Mod_CP_polls_removed']) . '<br /><br />'. $l_redirect);
		}
		else
		{
			if(empty($_POST['topic_id_list']) && empty($topic_id))
			{
				message_die(GENERAL_MESSAGE, $lang['None_selected']);
			}
function delete_item($old, $new = '', $topic_dest = '')
{
    global $db;
    // no changes
    if ($old == $new) {
        return;
    }
    // old type and id
    $old_type = substr($old, 0, 1);
    $old_id = intval(substr($old, 1));
    // new type and id
    $new_type = substr($new, 0, 1);
    $new_id = intval(substr($new, 1));
    if ($new_id == 0 || !in_array($new_type, array(POST_FORUM_URL, POST_CAT_URL))) {
        $new_type = POST_CAT_URL;
        $new_id = 0;
    }
    // topic dest
    $dst_type = substr($topic_dest, 0, 1);
    $dst_id = intval(substr($topic_dest, 1));
    if ($dst_id == 0 || $dst_type != POST_FORUM_URL) {
        $topic_dest = '';
    }
    // re-attach all the content to the new id
    if (!empty($new)) {
        $sql = "UPDATE " . FORUMS_TABLE . "\n\t\t\t\t\tSET main_type = '{$new_type}', parent_id = {$new_id}\n\t\t\t\t\tWHERE main_type = '{$old_type}' AND parent_id = {$old_id}";
        $db->sql_query($sql);
    }
    // topics move
    if (!empty($topic_dest) && $dst_type == POST_FORUM_URL) {
        if ($dst_type == POST_FORUM_URL && $old_type == POST_FORUM_URL) {
            // topics
            $sql = "UPDATE " . TOPICS_TABLE . " SET forum_id = {$dst_id} WHERE forum_id = {$old_id}";
            $db->sql_query($sql);
            // posts
            $sql = "UPDATE " . POSTS_TABLE . " SET forum_id = {$dst_id} WHERE forum_id = {$old_id}";
            $db->sql_query($sql);
            if (!class_exists('class_mcp')) {
                include IP_ROOT_PATH . 'includes/class_mcp.' . PHP_EXT;
            }
            if (empty($class_mcp)) {
                $class_mcp = new class_mcp();
            }
            $class_mcp->sync('forum', $dst_id);
        }
    }
    // all what is attached to a forum
    if ($old_type == POST_FORUM_URL) {
        // read current moderators for the old forum
        $sql = "SELECT ug.user_id FROM " . AUTH_ACCESS_TABLE . " a, " . USER_GROUP_TABLE . " ug\n\t\t\t\t\tWHERE a.forum_id = {$old_id}\n\t\t\t\t\t\tAND a.auth_mod = 1\n\t\t\t\t\t\tAND ug.group_id = a.group_id";
        $result = $db->sql_query($sql);
        $user_ids = array();
        while ($row = $db->sql_fetchrow($result)) {
            $user_ids[] = $row['user_id'];
        }
        $db->sql_freeresult($result);
        // remove moderator status for those ones
        if (!empty($user_ids)) {
            $old_moderators = implode(', ', $user_ids);
            // check which ones remain moderators
            $sql = "SELECT ug.user_id FROM " . AUTH_ACCESS_TABLE . " a, " . USER_GROUP_TABLE . " ug\n\t\t\t\t\t\tWHERE a.forum_id <> {$old_id}\n\t\t\t\t\t\t\tAND a.auth_mod = 1\n\t\t\t\t\t\t\tAND ug.group_id = a.group_id\n\t\t\t\t\t\t\tAND ug.user_id IN ({$old_moderators})";
            $result = $db->sql_query($sql);
            $user_ids = array();
            while ($row = $db->sql_fetchrow($result)) {
                $user_ids[] = $row['user_id'];
            }
            $new_moderators = empty($user_ids) ? '' : implode(', ', $user_ids);
            // update users status
            $sql = "UPDATE " . USERS_TABLE . "\n\t\t\t\t\t\tSET user_level = " . USER . "\n\t\t\t\t\t\tWHERE user_id IN ({$old_moderators})\n\t\t\t\t\t\t\tAND user_level NOT IN (" . JUNIOR_ADMIN . ", " . ADMIN . ")";
            $db->sql_query($sql);
            if (!empty($new_moderators)) {
                $sql = "UPDATE " . USERS_TABLE . "\n\t\t\t\t\t\t\tSET user_level = " . MOD . "\n\t\t\t\t\t\t\tWHERE user_id IN ({$new_moderators})\n\t\t\t\t\t\t\t\tAND user_level NOT IN (" . JUNIOR_ADMIN . ", " . ADMIN . ")";
                $db->sql_query($sql);
            }
        }
        // remove auth for the old forum
        $sql = "DELETE FROM " . AUTH_ACCESS_TABLE . " WHERE forum_id = {$old_id}";
        $db->sql_query($sql);
        // prune table
        $sql = "DELETE FROM " . PRUNE_TABLE . " WHERE forum_id = {$old_id}";
        $db->sql_query($sql);
        // polls
        $sql = "SELECT t.topic_id FROM " . TOPICS_TABLE . " t\n\t\t\t\t\tWHERE t.forum_id = {$old_id}";
        $result = $db->sql_query($sql);
        $topic_ids = array();
        while ($row = $db->sql_fetchrow($result)) {
            $topic_ids[] = $row['topic_id'];
        }
        if (!empty($topic_ids)) {
            if (!class_exists('class_mcp')) {
                include IP_ROOT_PATH . 'includes/class_mcp.' . PHP_EXT;
            }
            if (empty($class_mcp)) {
                $class_mcp = new class_mcp();
            }
            $class_mcp->topic_poll_delete($topic_ids);
        }
        // topics
        prune($old_id, 0, true);
        // Delete everything from forum
    }
    // delete the old one
    $sql = "DELETE FROM " . FORUMS_TABLE . " WHERE forum_id = {$old_id}";
    $db->sql_query($sql);
}