<?php
/*
[UCenter Home] (C) 2007-2008 Comsenz Inc.
$Id: cp.php 12352 2009-06-11 06:59:06Z liguode $
*/
//ͨÓÃÎļþ
include_once('./common.php');
include_once(S_ROOT.'./source/function_cp.php');
include_once(S_ROOT.'./source/function_magic.php');
$mid = empty($_GET['mid'])?'':trim($_GET['mid']);
$op = empty($_GET['op'])?'use':$_GET['op'];
$id = empty($_GET['id'])?0:intval($_GET['id']);
$idtype = empty($_GET['idtype'])?'':trim($_GET['idtype']);
//ȨÏÞÅжÏ
if(empty($_SGLOBAL['supe_uid'])) {
showmessage('to_login', 'do.php?ac='.$_SCONFIG['login_action']);
}
//Õ¾µã¹Ø±Õ
checkclose();
//MID¼ì²é
if(empty($mid)) {
showmessage('unknown_magic');
}
//»ñÈ¡¿Õ¼äÐÅÏ¢
$space = getspace($_SGLOBAL['supe_uid']);
if(empty($space)) {
showmessage('space_does_not_exist');
}
//»ñµÃµÀ¾ß
$magic = magic_get($mid);
//ÊÇ·ñÓµÓиõÀ¾ß
$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname("usermagic")." WHERE uid='$_SGLOBAL[supe_uid]' AND mid='$mid'");
$usermagic = $_SGLOBAL['db']->fetch_array($query);
if(empty($usermagic['count'])) {
$op = 'buy';
}
//Ìá½»¹ºÂò
$frombuy = false;
if(submitcheck('buysubmit')) {
//»ñµÃµÀ¾ßÐÅÏ¢
$results = magic_buy_get($magic);
extract($results);
//¹ºÂòµÀ¾ß
magic_buy_post($magic, $magicstore, $coupon);
$op = 'use';
$frombuy = true;//±ê¼ÇÊǹºÂòºóÁ¢¼´Ê¹ÓÃ
$usermagic['count'] += $_POST['buynum'];
}
//¹ºÂòµÀ¾ß
if($op == 'buy') {
//»ñµÃµÀ¾ßÐÅÏ¢
$results = magic_buy_get($magic);
extract($results);
//ijЩµÀ¾ßÐèÒª´«µÝµÄ¸½¼ÓÐÅÏ¢
$extra = '';
if($mid == 'doodle') {
$extra = "&showid=$_GET[showid]&target=$_GET[target]&from=$_GET[from]";
}
include_once template('cp_magic');
exit();
}
//¼ì²éÔÚʹÓÃÖÜÆÚÄÚµÄʹÓôÎÊý
if($magic['useperoid'] > 0) {
$time = $_SGLOBAL['timestamp'] - $magic['useperoid'];
$count = $_SGLOBAL['db']->result($_SGLOBAL['db']->query("SELECT COUNT(*) FROM ".tname('magicuselog')." WHERE uid='$_SGLOBAL[supe_uid]' AND mid='$mid' AND dateline > '$time'"), 0);
if($count >= $magic['usecount']) {
//È¡ÖÜÆÚÄÚ×îÔçʹÓõÄÒ»Ìõ¼Ç¼£¬¼ÆËãÏ´ÎʹÓÃʱ¼ä
$query = $_SGLOBAL['db']->query('SELECT * FROM '.tname('magicuselog')." WHERE uid='$_SGLOBAL[supe_uid]' AND mid='$mid' AND dateline > '$time' ORDER BY dateline LIMIT 1");
$value = $_SGLOBAL['db']->fetch_array($query);
$nexttime = sgmdate('m-d H:i:s', $value['dateline'] + $magic['useperoid']);
showmessage('magic_usecount_limit', '', '', array($nexttime));
}
}
include_once(S_ROOT.'./source/magic_'.$mid.'.php');
include_once template('magic_'.$mid);
?>