function cw_patch_store_phase_result()
{
    global $patch_phase_results_file, $phase_result;
    $patch_phase_results_file =& cw_session_register("patch_phase_results_file");
    $patch_phase_results_file = cw_patch_store_in_tmp($phase_result);
    if ($patch_phase_results_file !== false) {
        cw_session_save();
        cw_html_location("index.php?target=patch&mode=result", 0);
    } else {
        cw_session_unregister("patch_phase_results_file");
        die("Upgrade/patch process cannot continue:<br />There is a problem saving temporaly data at your server. Please check permissions and/or amount of free space in your TEMP directory.<br /><br /><a href=\"patch.php\">Click here to return</a>");
    }
}
    db_query("UPDATE {$tables['config']} SET value='" . time() . "' WHERE name='db_backup_date'");
    if ($destination == "file") {
        fclose($fd);
        chmod($sqldump_file, 0666);
        $top_message['content'] = cw_get_langvar_by_name("msg_adm_db_backup_success") . " '{$sqldump_file}'";
        echo "<hr />" . cw_get_langvar_by_name("lbl_done", false, false, true) . ".";
        ?>
<script type="text/javascript">
<!--
loaded = true;
-->
</script>
<?php 
        cw_flush();
        cw_log_flag('log_database', 'DATABASE', $log_prefix . cw_get_langvar_by_name("msg_adm_db_backup_success", false, false, true));
        cw_html_location("index.php?target=db_backup", 10);
    } else {
        cw_log_flag('log_database', 'DATABASE', $log_prefix . cw_get_langvar_by_name("lbl_done", false, false, true));
    }
    exit;
}
#
# Restore database code
#
if ($REQUEST_METHOD == "POST" && $action == "restore" && empty($_POST['local_file']) && $_FILES['userfile']['error']) {
    $upload_error_codes = array();
    $upload_error_codes[1] = "The uploaded file exceeds the upload_max_filesize directive in php.ini";
    $upload_error_codes[2] = "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form.";
    $upload_error_codes[3] = "The uploaded file was only partially uploaded.";
    $upload_error_codes[4] = "No file was uploaded.";
    $top_message['content'] = cw_get_langvar_by_name("msg_adm_err_file_upload") . " [" . $_FILES['userfile']['error'] . ": " . $upload_error_codes[$_FILES['userfile']['error']] . "]";
                    $recipients[] = $v['email'];
                }
            }
        }
    }
}
// Cleanup or translate anonymous emails
foreach ($recipients as $k => $v) {
    if (cw_is_anonymous($v)) {
        if (defined('NEWS_SEND_TO_ANONYMOUS') && constant('NEWS_SEND_TO_ANONYMOUS')) {
            $recipients[$k] = cw_real_mail_address($v);
        } else {
            unset($recipients[$k]);
        }
    }
}
$recipients = array_unique($recipients);
if (count($recipients) > 0) {
    cw_call('cw_spam', array($message, $recipients, $list_lng, $list_id));
    if (!$do_not_update_status) {
        db_query("UPDATE {$tables['newsletter']} SET status = 'S', send_date = '" . time() . "' WHERE news_id = '{$message['news_id']}'");
    }
}
if (!empty($limit) && count($recipients) > 0) {
    $news_send_data[$messageid]['lastpos'] += count($recipients);
    if ($news_send_data[$messageid]['lastpos'] >= $news_send_data[$messageid]['count']) {
        cw_unset($news_send_data, $messageid);
        return;
    }
    cw_html_location("index.php?target={$target}&mode=messages&list_id={$list_id}&messageid={$messageid}&action=send_continue", $config['news']['news_sleep_interval']);
}