my_collect_post.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. require_once "../path.php";
  3. require_once "../public/_pdo.php";
  4. require_once '../public/function.php';
  5. require_once '../collect/function.php';
  6. require_once "../ucenter/active.php";
  7. require_once "../redis/function.php";
  8. $respond=array("status"=>0,"message"=>"");
  9. if(!isset($_COOKIE["userid"])){
  10. #不登录不能新建
  11. $respond['status']=1;
  12. $respond['message']="no power create article";
  13. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  14. exit;
  15. }
  16. # 检查当前用户是否有修改权限
  17. $redis = redis_connect();
  18. $collection = new CollectInfo($redis);
  19. $power = $collection->getPower($_POST["id"]);
  20. if($power<20){
  21. $respond["status"]=1;
  22. $respond["message"]="No Power For Edit";
  23. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  24. exit;
  25. }
  26. add_edit_event(_COLLECTION_EDIT_,$_POST["id"]);
  27. PDO_Connect(_FILE_DB_USER_ARTICLE_);
  28. $query="UPDATE collect SET title = ? , subtitle = ? , summary = ?, article_list = ? , status = ? , lang = ? , receive_time= ? , modify_time= ? where id = ? ";
  29. $sth = $PDO->prepare($query);
  30. $sth->execute(array($_POST["title"] , $_POST["subtitle"] ,$_POST["summary"], $_POST["article_list"] , $_POST["status"] , $_POST["lang"] , mTime() , mTime() , $_POST["id"]));
  31. $respond=array("status"=>0,"message"=>"");
  32. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  33. $error = PDO_ErrorInfo();
  34. $respond['status']=1;
  35. $respond['message']=$error[2];
  36. }
  37. else{
  38. if($redis){
  39. $redis->del("collection://".$_POST["id"]);
  40. $redis->del("power://collection/".$_POST["id"]);
  41. }
  42. # 更新 article_list 表
  43. $query = "DELETE FROM article_list WHERE collect_id = ? ";
  44. PDO_Execute($query,array($_POST["id"]));
  45. $arrList = json_decode($_POST["article_list"]);
  46. if(count($arrList)>0){
  47. /* 开始一个事务,关闭自动提交 */
  48. $PDO->beginTransaction();
  49. $query = "INSERT INTO article_list (collect_id, article_id,level,title,children) VALUES ( ? , ?, ?, ? , ? )";
  50. $sth = $PDO->prepare($query);
  51. foreach ($arrList as $row) {
  52. $sth->execute(array($_POST["id"],$row->article,$row->level,$row->title,$row->children));
  53. if($redis){
  54. #删除article权限缓存
  55. $redis->del("power://article/".$row->article);
  56. }
  57. }
  58. $PDO->commit();
  59. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  60. /* 识别错误且回滚更改 */
  61. $PDO->rollBack();
  62. $error = PDO_ErrorInfo();
  63. $respond['status']=1;
  64. $respond['message']=$error[2];
  65. }
  66. }
  67. }
  68. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  69. ?>