friendfun.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. //--------------- 会员好友函数 ---------------
  3. //增加好友
  4. function AddFriend($add){
  5. global $empire,$dbtbpre;
  6. //是否登陆
  7. $user_r=islogin();
  8. $fname=RepPostVar(trim($add['fname']));
  9. $add['fcid']=(int)$add['fcid'];
  10. if(!$fname)
  11. {
  12. printerror("EmptyFriend","",1);
  13. }
  14. //加自己为好友
  15. if($fname==$user_r['username'])
  16. {
  17. printerror("NotAddFriendSelf","",1);
  18. }
  19. $num=$empire->gettotal("select count(*) as total from ".eReturnMemberTable()." where ".egetmf('username')."='$fname' limit 1");
  20. if(!$num)
  21. {
  22. printerror("NotFriendUsername","",1);
  23. }
  24. //重复提交
  25. $num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewshy where fname='$fname' and userid='$user_r[userid]' limit 1");
  26. if($num)
  27. {
  28. printerror("ReAddFriend","",1);
  29. }
  30. $cid=(int)$add['cid'];
  31. $fsay=RepPostStr($add['fsay']);
  32. $sql=$empire->query("insert into {$dbtbpre}enewshy(userid,fname,cid,fsay) values('$user_r[userid]','".addslashes($fname)."',$cid,'".addslashes($fsay)."');");
  33. if($sql)
  34. {
  35. printerror("AddFriendSuccess","../member/friend/?cid=$add[fcid]",1);
  36. }
  37. else
  38. {
  39. printerror("DbError","",1);
  40. }
  41. }
  42. //修改好友
  43. function EditFriend($add){
  44. global $empire,$dbtbpre;
  45. //是否登陆
  46. $user_r=islogin();
  47. $fid=(int)$add['fid'];
  48. $fname=RepPostVar(trim($add['fname']));
  49. $add['fcid']=(int)$add['fcid'];
  50. if(!$fname||!$fid)
  51. {
  52. printerror("EmptyFriend","",1);
  53. }
  54. //加自己为好友
  55. if($fname==$user_r['username'])
  56. {
  57. printerror("NotAddFriendSelf","",1);
  58. }
  59. $num=$empire->gettotal("select count(*) as total from ".eReturnMemberTable()." where ".egetmf('username')."='$fname' limit 1");
  60. if(!$num)
  61. {
  62. printerror("NotFriendUsername","",1);
  63. }
  64. //重复提交
  65. if($fname!=$add['oldfname'])
  66. {
  67. $num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewshy where fname='$fname' and userid='$user_r[userid]' limit 1");
  68. if($num)
  69. {
  70. printerror("ReAddFriend","",1);
  71. }
  72. }
  73. $cid=(int)$add['cid'];
  74. $fsay=RepPostStr($add['fsay']);
  75. $sql=$empire->query("update {$dbtbpre}enewshy set fname='".addslashes($fname)."',cid=$cid,fsay='".addslashes($fsay)."' where fid=$fid and userid='$user_r[userid]'");
  76. if($sql)
  77. {
  78. printerror("EditFriendSuccess","../member/friend/?cid=$add[fcid]",1);
  79. }
  80. else
  81. {
  82. printerror("DbError","",1);
  83. }
  84. }
  85. //删除好友
  86. function DelFriend($add){
  87. global $empire,$dbtbpre;
  88. //是否登陆
  89. $user_r=islogin();
  90. $fid=(int)$add['fid'];
  91. $add['fcid']=(int)$add['fcid'];
  92. if(!$fid)
  93. {
  94. printerror("EmptyFriendId","",1);
  95. }
  96. $num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewshy where fid=$fid and userid='$user_r[userid]'");
  97. if(!$num)
  98. {
  99. printerror("EmptyFriendId","",1);
  100. }
  101. $sql=$empire->query("delete from {$dbtbpre}enewshy where fid=$fid and userid='$user_r[userid]'");
  102. if($sql)
  103. {
  104. printerror("DelFriendSuccess","../member/friend/?cid=$add[fcid]",1);
  105. }
  106. else
  107. {
  108. printerror("DbError","",1);
  109. }
  110. }
  111. //增加好友分类
  112. function AddFriendClass($add){
  113. global $empire,$dbtbpre;
  114. if(!trim($add[cname]))
  115. {
  116. printerror('EmptyFavaClassname','history.go(-1)',1);
  117. }
  118. //是否登陆
  119. $user_r=islogin();
  120. $add[cname]=dgdb_tosave($add[cname]);
  121. $sql=$empire->query("insert into {$dbtbpre}enewshyclass(cname,userid) values('$add[cname]','$user_r[userid]');");
  122. if($sql)
  123. {
  124. printerror('AddFavaClassSuccess','../member/friend/FriendClass/',1);
  125. }
  126. else
  127. {
  128. printerror('DbError','history.go(-1)',1);
  129. }
  130. }
  131. //修改好友分类
  132. function EditFriendClass($add){
  133. global $empire,$dbtbpre;
  134. $add[cid]=(int)$add[cid];
  135. if(!trim($add[cname])||!$add[cid])
  136. {
  137. printerror('EmptyFavaClassname','history.go(-1)',1);
  138. }
  139. //是否登陆
  140. $user_r=islogin();
  141. $add[cname]=dgdb_tosave($add[cname]);
  142. $sql=$empire->query("update {$dbtbpre}enewshyclass set cname='$add[cname]' where cid='$add[cid]' and userid='$user_r[userid]'");
  143. if($sql)
  144. {
  145. printerror('EditFavaClassSuccess','../member/friend/FriendClass/',1);
  146. }
  147. else
  148. {
  149. printerror('DbError','history.go(-1)',1);
  150. }
  151. }
  152. //删除好友分类
  153. function DelFriendClass($cid){
  154. global $empire,$dbtbpre;
  155. $cid=(int)$cid;
  156. if(!$cid)
  157. {
  158. printerror('EmptyFavaClassid','history.go(-1)',1);
  159. }
  160. //是否登陆
  161. $user_r=islogin();
  162. $sql=$empire->query("delete from {$dbtbpre}enewshyclass where cid='$cid' and userid='$user_r[userid]'");
  163. if($sql)
  164. {
  165. printerror('DelFavaClassSuccess','../member/friend/FriendClass/',1);
  166. }
  167. else
  168. {
  169. printerror('DbError','history.go(-1)',1);
  170. }
  171. }
  172. //返回好友分类
  173. function ReturnFriendclass($userid,$cid){
  174. global $empire,$dbtbpre;
  175. $userid=(int)$userid;
  176. $sql=$empire->query("select cid,cname from {$dbtbpre}enewshyclass where userid='$userid' order by cid");
  177. $select='';
  178. while($r=$empire->fetch($sql))
  179. {
  180. if($r[cid]==$cid)
  181. {$selected=' selected';}
  182. else
  183. {$selected='';}
  184. $select.='<option value="'.$r[cid].'"'.$selected.'>'.$r[cname].'</option>';
  185. }
  186. return $select;
  187. }
  188. ?>