<?php
/**
* @author moufer<moufer@163.com>
* @copyright www.modoer.com
* @version $Id ac_exchange.php 1 2008-08-15 08:57 $
*/
!defined('IN_MUDDER') && exit('Access Denied');

if(!$user->isLogin) {
    $forward = $php_reuri ? $host_url.$php_reuri : $_config['siteurl'];
    location($_config['siteurl'].'member/login.php?forward='.rawurlencode($forward));
}

(!is_numeric($giftid) || $giftid < 0) && redirect('无效的礼品编号。',NULL);
$gift = $db->get_one("SELECT * FROM {$dbpre}gifts WHERE giftid='$giftid'");
!$gift && redirect('礼品不存在，或已删除。',NULL);
!$gift['available'] && redirect('此礼品当前已停止兑换，您可以选择其他礼品进行兑换。');
($gift['num'] <= 0) && redirect('此礼品当前已缺货，您可以选择其他礼品进行兑换。');
($user->coin < $gift['price']) && redirect('您的积分不足，无法兑换此礼品，请继续加油。');

$gift['thumb'] = unserialize($gift['thumb']);
$gift['picture'] = unserialize($gift['picture']);

$subtitle = '礼品兑换';
$tplname = 'exchange_apply';
require_once MUDDER_ROOT.'header.php';
require_once template($tplname);
footer();
?>