<?php
error_reporting(0);
define('SUPPORT_URL', 'http://api.iskysoft.com/interface.php?m=' . $_GET['m']);

$email = get_gp('email');
$back_url = get_gp('back_url');
$op_type = get_gp('op_type');
$op_url = get_gp('op_url');
$mode = get_gp('mode');
$title = get_gp('title');
$firstname = get_gp('firstname');
$lastname = get_gp('lastname');
$country = get_gp('country');
$is_html = get_gp('is_html');
$type = get_gp('type');
$url .= $action_url ? '&action_url='.$action_url : '';

$is_subscribe = 'is_subscribe';
$url = SUPPORT_URL . "&email={$email}";

$url .= $title ? '&title='.$title : '';
$url .= $firstname ? '&firstname='.$firstname : '';
$url .= $lastname ? '&lastname='.$lastname : '';
$url .= $country ? '&country='.$country : '';
$url .= $is_html ? '&is_html='.$is_html : '';
$url .= $type ? '&type='.$type : '';
$action_url = get_gp('action_url');

$url .= $op_type ? '&op_type=' . $op_type . '&op_url=' . $op_url : '';
$url .= ($_GET['m'] == 'subscribe') ? "&is_subscribe={$is_subscribe}" : "";
$url .= $mode ? "&mode={$mode}" : "";

$res = file_get_contents($url);

switch($_GET['m']){
    case 'subscribe':
        if(!eregi("(submitted|failed|invalid|sorry)", $res)){
            gopage($back_url .'#'.$email);
        }
        break;
	case 'direct_subscribe':
        if(!eregi("(submitted|failed|invalid|sorry)", $res)){
            gopage($back_url .'#'.$email);
        }		
		break;
    case 'unsubscribe':
        if(eregi('didn', $res)){
            gopage($back_url.'?error');
        }elseif(!eregi("failed", $res)){
            gopage($back_url.'#'.$email);
        }
        break;
    case 'check_email':
        echo $res;
        break;
	default:
        echo $res;
        break;

}


/** 跳转页面 */
function gopage($url){
    echo '<script type="text/javascript">window.location.href="' . $url . '"</script>';
}

function get_gp($str){
    $res = $_POST[$str] ? $_POST[$str] : ($_GET[$str] ? $_GET[$str] : '');
    return $res;
}

?>