favfun.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. //--------------- 收藏夹函数 ---------------
  3. //增加收藏
  4. function AddFava($id,$classid,$cid,$from){
  5. global $empire,$level_r,$class_r,$dbtbpre;
  6. //是否登陆
  7. $user_r=islogin();
  8. $id=(int)$id;
  9. $cid=(int)$cid;
  10. $classid=(int)$classid;
  11. if(empty($id)||empty($classid))
  12. {
  13. printerror("ErrorUrl","history.go(-1)",1);
  14. }
  15. //表不存在
  16. if(empty($class_r[$classid][tbname]))
  17. {
  18. printerror("ErrorUrl","history.go(-1)",1);
  19. }
  20. $num=$empire->gettotal("select count(*) as total from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where id='$id' and classid='$classid'");
  21. if(empty($num))
  22. {printerror("ErrorUrl","history.go(-1)",1);}
  23. //是否已收藏
  24. $newsnum=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsfava where id='$id' and classid='$classid' and userid='$user_r[userid]'");
  25. if($newsnum)
  26. {
  27. printerror("ReFava","history.go(-1)",1);
  28. }
  29. $favanum=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsfava where userid='$user_r[userid]'");
  30. $groupid=$user_r[groupid];
  31. if($level_r[$groupid][favanum]<=$favanum)
  32. {
  33. printerror("MoreFava","history.go(-1)",1);
  34. }
  35. $favatime=date("Y-m-d H:i:s");
  36. $sql=$empire->query("insert into {$dbtbpre}enewsfava(id,favatime,userid,username,classid,cid) values('$id','$favatime','$user_r[userid]','$user_r[username]','$classid','$cid');");
  37. if($sql)
  38. {
  39. printerror("AddFavaSuccess",RepPostStrUrl($from),1);
  40. }
  41. else
  42. {
  43. printerror("DbError","history.go(-1)",1);
  44. }
  45. }
  46. //批量删除收藏
  47. function DelFava_All($favaid){
  48. global $empire,$dbtbpre;
  49. //是否登陆
  50. $user_r=islogin();
  51. $count=count($favaid);
  52. if(empty($count))
  53. {printerror("NotDelFavaid","history.go(-1)",1);}
  54. for($i=0;$i<$count;$i++)
  55. {
  56. $add.="favaid='".intval($favaid[$i])."' or ";
  57. }
  58. $add=substr($add,0,strlen($add)-4);
  59. $sql=$empire->query("delete from {$dbtbpre}enewsfava where (".$add.") and userid='$user_r[userid]'");
  60. if($sql)
  61. {printerror("DelFavaSuccess","../member/fava/",1);}
  62. else
  63. {printerror("DbError","history.go(-1)",1);}
  64. }
  65. //删除单个收藏夹
  66. function DelFava($favaid){
  67. global $empire,$dbtbpre;
  68. //是否登陆
  69. $user_r=islogin();
  70. $favaid=(int)$favaid;
  71. if(empty($favaid))
  72. {printerror("NotDelFavaid","history.go(-1)",1);}
  73. $sql=$empire->query("delete from {$dbtbpre}enewsfava where favaid='$favaid' and userid='$user_r[userid]'");
  74. if($sql)
  75. {printerror("DelFavaSuccess","../member/fava/",1);}
  76. else
  77. {printerror("DbError","history.go(-1)",1);}
  78. }
  79. //增加收藏夹分类
  80. function AddFavaClass($add){
  81. global $empire,$dbtbpre;
  82. if(!trim($add[cname]))
  83. {
  84. printerror('EmptyFavaClassname','history.go(-1)',1);
  85. }
  86. //是否登陆
  87. $user_r=islogin();
  88. $add[cname]=dgdb_tosave($add[cname]);
  89. $sql=$empire->query("insert into {$dbtbpre}enewsfavaclass(cname,userid) values('$add[cname]','$user_r[userid]');");
  90. if($sql)
  91. {
  92. printerror('AddFavaClassSuccess','../member/fava/FavaClass/',1);
  93. }
  94. else
  95. {
  96. printerror('DbError','history.go(-1)',1);
  97. }
  98. }
  99. //修改收藏夹分类
  100. function EditFavaClass($add){
  101. global $empire,$dbtbpre;
  102. $add[cid]=(int)$add[cid];
  103. if(!trim($add[cname])||!$add[cid])
  104. {
  105. printerror('EmptyFavaClassname','history.go(-1)',1);
  106. }
  107. //是否登陆
  108. $user_r=islogin();
  109. $add[cname]=dgdb_tosave($add[cname]);
  110. $sql=$empire->query("update {$dbtbpre}enewsfavaclass set cname='$add[cname]' where cid='$add[cid]' and userid='$user_r[userid]'");
  111. if($sql)
  112. {
  113. printerror('EditFavaClassSuccess','../member/fava/FavaClass/',1);
  114. }
  115. else
  116. {
  117. printerror('DbError','history.go(-1)',1);
  118. }
  119. }
  120. //删除收藏夹分类
  121. function DelFavaClass($cid){
  122. global $empire,$dbtbpre;
  123. $cid=(int)$cid;
  124. if(!$cid)
  125. {
  126. printerror('EmptyFavaClassid','history.go(-1)',1);
  127. }
  128. //是否登陆
  129. $user_r=islogin();
  130. $sql=$empire->query("delete from {$dbtbpre}enewsfavaclass where cid='$cid' and userid='$user_r[userid]'");
  131. if($sql)
  132. {
  133. printerror('DelFavaClassSuccess','../member/fava/FavaClass/',1);
  134. }
  135. else
  136. {
  137. printerror('DbError','history.go(-1)',1);
  138. }
  139. }
  140. //返回收藏夹分类
  141. function ReturnFavaclass($userid,$cid){
  142. global $empire,$dbtbpre;
  143. $userid=(int)$userid;
  144. $sql=$empire->query("select cid,cname from {$dbtbpre}enewsfavaclass where userid='$userid' order by cid");
  145. $select='';
  146. while($r=$empire->fetch($sql))
  147. {
  148. if($r[cid]==$cid)
  149. {$selected=' selected';}
  150. else
  151. {$selected='';}
  152. $select.='<option value="'.$r[cid].'"'.$selected.'>'.$r[cname].'</option>';
  153. }
  154. return $select;
  155. }
  156. //批量转移收藏
  157. function MoveFava_All($favaid,$cid){
  158. global $empire,$dbtbpre;
  159. //是否登陆
  160. $user_r=islogin();
  161. $cid=(int)$cid;
  162. if(!$cid)
  163. {printerror("NotChangeMoveCid","history.go(-1)",1);}
  164. $count=count($favaid);
  165. if(empty($count))
  166. {printerror("NotMoveFavaid","history.go(-1)",1);}
  167. for($i=0;$i<$count;$i++)
  168. {
  169. $add.="favaid='".intval($favaid[$i])."' or ";
  170. }
  171. $add=substr($add,0,strlen($add)-4);
  172. $sql=$empire->query("update {$dbtbpre}enewsfava set cid=$cid where (".$add.") and userid='$user_r[userid]'");
  173. if($sql)
  174. {printerror("MoveFavaSuccess","../member/fava/",1);}
  175. else
  176. {printerror("DbError","history.go(-1)",1);}
  177. }
  178. ?>