1、打开u/themes/default/profile_toolcenter.htm文件
找到:
<a href="profile.php?action=toolcenter&job=sell&id=$id" class="canclesale">转让</a>
上上上上方添加如下代码:
<a href="profile.php?action=toolcenter&job=send&id=$id" class="canclesend" title="将道具赠送给你的好友">赠送他人</a>
找到:
elseif ($job == 'use')
前前前前面添加如下代码:
elseif ($job == 'send') {print <<<EOT
-->
<div class="navC mb10">
<ul id="infolist">
<li><a href="profile.php?action=toolcenter">道具交易</a></li>
<li class="current"><a href="profile.php?action=toolcenter&job=mytool">我的道具箱</a></li>
</ul>
</div>
<div class="bdB pb10 mb10 p_lr_10">
<a class="s5 b" href="profile.php?action=toolcenter&job=mytool">我拥有的</a> | <a href="profile.php?action=toolcenter&job=user&uid=$winduid">我转让的</a>
</div>
<script>
function checkForm()
{
var nums = $('nums');
var re = /^[0-9]*[1-9][0-9]*$/;
if (!re.test(nums.value))
{
alert("您输入的数字为非法数字,请输入一个大于 “0” 的“整数”");
nums.focus();
return false;
}
}
</script>
<form action="profile.php?action=toolcenter&" method="post" onsubmit="return checkForm()">
<input type="hidden" name="job" value="send" />
<input type="hidden" name="step" value="2" />
<input type="hidden" name="id" value="$id" />
<div class="toolItem">
<table width="100%" cellspacing="0" cellpadding="0" class="vt">
<tr>
<!--
EOT;
if($rt[logo]){
print <<<EOT
-->
<td rowspan="3" class="toolPic" width="20%"><img src="u/images/toolcenter/tool/$rt[logo]" /></td>
<!--
EOT;
}
print <<<EOT
-->
<th width="12%">名称:</th><td style="vertical-align:middle">$rt[name]</td>
</tr>
<tr>
<th>目标用户UID:</th><td style="vertical-align:middle"><input type="text" class="input" name="touid" value="" onblur="javascript:get_username(this.value);" /><span id="showusername"></span></td>
</tr>
<tr>
<th>赠送数量:</th><td style="vertical-align:middle"><input type="text" class="input" name="nums" value="1" id="nums"/>[{$credit->cType[$rt[creditype]]}]</td>
</tr>
</table>
</div>
<div class="tac"><span class="btn"><span><button type="submit">提交赠送</button></span></span></div>
</form>
<!--
EOT;
}
找到:
<!--
EOT;
if (!defined('AJAX')) {print <<<EOT
-->
上上上上上方添加如下代码:
<script type="text/javascript">
<!--
function get_username(n){
createXMLHttpRequest();
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("GET","profile.php?action=toolcenter&new_action=getusername&uid="+n,true);
xmlHttp.send(null);
}
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
function handleStateChange(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
document.getElementById("showusername").innerHTML = xmlHttp.responseText;
}
}
}
//-->
</script>
--------------------------------------------
2、打开u/require/profile/toolcenter.php文件,
找到:
S::gp(array('job'));
替换替换替换成如下代码:
S::gp(array('job','new_action','uid'));
找到:
if (empty($job)) {
上上上上方添加如下代码:
if($new_action == "getusername"){
@header("Content-Type:text/html; charset=$db_charset");
$username = $db->get_value("SELECT username from pw_members where uid=".pwEscape($uid));
if($username){
echo " UID对应账号:<b><a target='_blank' href='u.php?uid=".$uid."'>".$username."</a></b>";exit;
}else{
echo " <font color=red>对不起,您输入的UID对应的用户账号为空</font>";exit;
}
}
找到:
elseif ($job == 'unsell')
前前前前面添加如下代码:
elseif ($job == 'send') {
!$db_allowtrade && Showmsg('trade_close');
S::gp(array('id'));
if (empty($_POST['step'])) {
$rt = $db->get_one("SELECT u.*,t.name,t.price,t.creditype,t.logo FROM pw_usertool u LEFT JOIN pw_tools t ON t.id=u.toolid WHERE uid=".S::sqlEscape($winduid,false)." AND toolid=".S::sqlEscape($id));
!$rt && Showmsg('undefined_action');
$rt['nums'] == 0 && Showmsg('unenough_toolnum');
!$rt['creditype'] && $rt['creditype'] = 'currency';
require_once uTemplate::PrintEot('profile_toolcenter');
pwOutPut();
} else {
$rt = $db->get_one("SELECT u.*,t.name FROM pw_usertool u LEFT JOIN pw_tools t ON t.id=u.toolid WHERE uid=".S::sqlEscape($winduid)."AND toolid=".S::sqlEscape($id));
if ($rt) {
S::gp(array('nums','touid'),'P');
$nums = (int)$nums;
$touid = (int)$touid;
$nums <= 0 && Showmsg('illegal_nums');
$touid <= 0 && Showmsg('用户UID不能为空或者为0');
$rt['nums'] < $nums && Showmsg('您要赠送的道具数量大于您拥有的道具数量!');
$db->update("UPDATE pw_usertool SET nums=nums-".S::sqlEscape($nums)." WHERE uid=".S::sqlEscape($winduid)."AND toolid=".S::sqlEscape($id));
$touid_nums = $db->get_value("SELECT nums from pw_usertool where uid=".pwEscape($touid)." and toolid=".pwEscape($id));
if($touid_nums){
$db->update("UPDATE pw_usertool SET nums=nums+".S::sqlEscape($nums)." WHERE uid=".S::sqlEscape($touid)."AND toolid=".S::sqlEscape($id));
}else{
$db->update("INSERT INTO pw_usertool(uid,toolid,nums,sellstatus)values(".S::sqlEscape($touid).",".S::sqlEscape($id).",".S::sqlEscape($nums).",0)");
}
require_once(R_P.'require/tool.php');
$logdata = array(
'type' => 'send',
'nums' => $nums,
'descrip' => 'send_descrip',
'uid' => $winduid,
'username' => $windid,
'touid' => $touid,
'tousername' => $db->get_value("SELECT username from pw_members WHERE uid=".pwEscape($touid)),
'ip' => $onlineip,
'time' => $timestamp,
'toolname' => $rt['name'],
'from' => '',
);
writetoollog($logdata);
refreshto("profile.php?action=toolcenter&job=mytool",'operate_success');
} else {
Showmsg('undefined_action');
}
}
}
3、打开template/wind/lang_toollog.php文件,
找到:
'sell' => '转让',
'sell_descrip' => '{$L[username]} 转让道具: {$L[toolname]} ,数量:{$L[nums]}。',
下下下下方添加如下代码:
'send' => '赠送',
'send_descrip' => '{$L[username]} 向 {$L[tousername]} 赠送道具: {$L[toolname]} ,数量:{$L[nums]}。',
4、以上修改基本将道具赠送的功能写好了,下面就是将我的道具页面中的赠送的文字链接添加背景图片显示,这个需要美工协助将hack/toolcenter/image/listnavon.gif文件重新做下,然后控制下下面的-100px的值:
打开u/images/style.css文件
找到:
.toolbuy,.canceltran,.usetool,.canclesale{display:block; height:21px; width:74px; text-indent:-999em; overflow:hidden; background:url(toolcenter/listnavon.gif) no-repeat 0 -83px;float:right; text-align:left;}
替换替换替换成如下代码:
.toolbuy,.canceltran,.usetool,.canclesale,.canclesend{display:block; height:21px; width:74px; text-indent:-999em; overflow:hidden; background:url(toolcenter/listnavon.gif) no-repeat 0 -83px;float:right; text-align:left;}
找到:
.canclesale{width:51px; background-position:0 -212px;}
下下下下方添加如下代码:
.canclesend{width:75px; background-position:-113px top; height:23px; display:block;}