forked from kakukeme/jms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addfriends.php
72 lines (66 loc) · 2.98 KB
/
addfriends.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
* 增加好友
*
* 增加好友,参数可以是好友的用户ID或者用户名/昵称
*
* 调用模板:无
*
* @category jieqicms
* @package system
* @copyright Copyright (c) Hangzhou Jieqi Network Technology Co.,Ltd. (http://www.jieqi.com)
* @author $Author: juny $
* @version $Id: addfriends.php 322 2009-01-13 11:28:29Z juny $
*/
define('JIEQI_MODULE_NAME', 'system');
require_once('global.php');
jieqi_checklogin();
if(empty($_REQUEST['id']) && empty($_REQUEST['username'])) jieqi_printfail(LANG_NO_USER);
include_once(JIEQI_ROOT_PATH.'/class/users.php');
$users_handler =& JieqiUsersHandler::getInstance('JieqiUsersHandler');
if(!empty($_REQUEST['id'])){
$userobj=$users_handler->get($_REQUEST['id']);
}else{
$_REQUEST['username']=trim($_REQUEST['username']);
$userobj=$users_handler->getByname($_REQUEST['username'],3);
}
if(is_object($userobj)){
jieqi_loadlang('users', JIEQI_MODULE_NAME);
include_once(JIEQI_ROOT_PATH.'/class/friends.php');
$friends_handler =& JieqiFriendsHandler::getInstance('JieqiFriendsHandler');
jieqi_getconfigs(JIEQI_MODULE_NAME, 'configs');
jieqi_getconfigs('system', 'honors');
jieqi_getconfigs(JIEQI_MODULE_NAME, 'right');
$maxfriendsnum=intval($jieqiConfigs['system']['maxfriends']); //默认好友数
$honorid=jieqi_gethonorid($_SESSION['jieqiUserScore'], $jieqiHonors);
if($honorid && isset($jieqiRight['system']['maxfriends']['honors'][$honorid]) && is_numeric($jieqiRight['system']['maxfriends']['honors'][$honorid])) $maxfriendsnum = intval($jieqiRight['system']['maxfriends']['honors'][$honorid]); //根据头衔设置的好友数
if(is_numeric($maxfriendsnum)){
$criteria=new CriteriaCompo(new Criteria('myid', $_SESSION['jieqiUserId']));
$friendsnum=$friends_handler->getCount($criteria);
if($friendsnum>=$maxfriendsnum) jieqi_printfail(sprintf($jieqiLang['system']['too_manay_friends'], $maxfriendsnum));
}
unset($criteria);
$criteria=new CriteriaCompo(new Criteria('myid', $_SESSION['jieqiUserId']));
$criteria->add(new Criteria('yourid', $userobj->getVar('uid', 'n')));
$isexist=$friends_handler->getCount($criteria);
if($isexist>0) jieqi_printfail($jieqiLang['system']['has_been_friends']);
$newFriends = $friends_handler->create();
$newFriends->setVar('adddate', JIEQI_NOW_TIME);
$newFriends->setVar('myid', $_SESSION['jieqiUserId']);
$newFriends->setVar('myname', $_SESSION['jieqiUserName']);
$newFriends->setVar('yourid', $userobj->getVar('uid', 'n'));
if(strlen($userobj->getVar('name', 'n')) > 0) $newFriends->setVar('yourname', $userobj->getVar('name', 'n'));
else $newFriends->setVar('yourname', $userobj->getVar('uname', 'n'));
$newFriends->setVar('teamid', 0);
$newFriends->setVar('team', '');
$newFriends->setVar('fset', '');
$newFriends->setVar('state', 0);
$newFriends->setVar('flag', 0);
if (!$friends_handler->insert($newFriends)) jieqi_printfail($jieqiLang['system']['add_friends_failure']);
else {
jieqi_msgwin(LANG_DO_SUCCESS, $jieqiLang['system']['add_friends_success']);
}
}else{
jieqi_printfail(LANG_NO_USER);
}
?>