function.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. require_once "../path.php";
  3. require_once "../public/_pdo.php";
  4. require_once '../public/function.php';
  5. require_once '../ucenter/function.php';
  6. require_once '../channal/function.php';
  7. require_once '../doc/function.php';
  8. /*
  9. 获取某用户的可见的协作资源
  10. $res_type 见readme.md#资源类型 -1全部类型资源
  11. */
  12. function share_res_list_get($userid,$res_type=-1){
  13. # 找我加入的群
  14. $dbhGroup = new PDO(_FILE_DB_GROUP_, "", "");
  15. $dbhGroup->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  16. $query = "SELECT group_id from group_member where user_id = ? limit 0,100";
  17. $stmtGroup = $dbhGroup->prepare($query);
  18. $stmtGroup->execute(array($userid));
  19. $my_group = $stmtGroup->fetchAll(PDO::FETCH_ASSOC);
  20. $userList = array();
  21. $userList[] = $userid;
  22. foreach ($my_group as $key => $value) {
  23. # code...
  24. $userList[]=$value["group_id"];
  25. }
  26. $place_holders = implode(',', array_fill(0, count($userList), '?'));
  27. $Fetch=array();
  28. $PDO = new PDO(_FILE_DB_USER_SHARE_, "", "");
  29. $PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  30. if($res_type==-1){
  31. $query = "SELECT res_id,res_type,power FROM share_cooperator WHERE is_deleted=0 AND cooperator_id IN ($place_holders) group by res_id ";
  32. $stmt = $PDO->prepare($query);
  33. $stmt->execute($userList);
  34. $Fetch =$stmt->fetchAll(PDO::FETCH_ASSOC);
  35. }
  36. else{
  37. $userList[]=$res_type;
  38. $query = "SELECT res_id,res_type,power FROM share_cooperator WHERE is_deleted=0 AND cooperator_id IN ($place_holders) AND res_type = ? group by res_id";
  39. $stmt = $PDO->prepare($query);
  40. $stmt->execute($userList);
  41. $Fetch =$stmt->fetchAll(PDO::FETCH_ASSOC);
  42. }
  43. $channel = new Channal();
  44. foreach ($Fetch as $key => $res) {
  45. # 获取资源标题 和所有者
  46. switch ($res["res_type"]) {
  47. case 1:
  48. # pcs 文档
  49. $Fetch[$key]["res_title"]=pcs_get_title($res["res_id"]);
  50. break;
  51. case 2:
  52. # channel
  53. $channelInfo = $channel->getChannal($res["res_id"]);
  54. if($channelInfo){
  55. $Fetch[$key]["res_title"]=$channelInfo["name"];
  56. $Fetch[$key]["res_owner_id"]=$channelInfo["owner"];
  57. }
  58. else{
  59. $Fetch[$key]["res_title"]="_unkown_";
  60. $Fetch[$key]["res_owner_id"]="_unkown_";
  61. }
  62. break;
  63. case 3:
  64. # code...
  65. break;
  66. case 4:
  67. # code...
  68. break;
  69. case 5:
  70. # code...
  71. break;
  72. default:
  73. # code...
  74. break;
  75. }
  76. }
  77. return $Fetch;
  78. }
  79. //对某个共享资源的权限
  80. function share_get_res_power($userid,$res_id){
  81. # 找我加入的群
  82. $dbhGroup = new PDO(_FILE_DB_GROUP_, "", "");
  83. $dbhGroup->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  84. $query = "SELECT group_id from group_member where user_id = ? limit 0,100";
  85. $stmtGroup = $dbhGroup->prepare($query);
  86. $stmtGroup->execute(array($userid));
  87. $my_group = $stmtGroup->fetchAll(PDO::FETCH_ASSOC);
  88. $userList = array();
  89. $userList[] = $userid;
  90. foreach ($my_group as $key => $value) {
  91. # code...
  92. $userList[]=$value["group_id"];
  93. }
  94. $place_holders = implode(',', array_fill(0, count($userList), '?'));
  95. $Fetch=array();
  96. $PDO = new PDO(_FILE_DB_USER_SHARE_, "", "");
  97. $PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  98. $userList[]=$res_id;
  99. $query = "SELECT power FROM share_cooperator WHERE is_deleted=0 AND cooperator_id IN ($place_holders) AND res_id = ? ";
  100. $stmt = $PDO->prepare($query);
  101. $stmt->execute($userList);
  102. $Fetch =$stmt->fetchAll(PDO::FETCH_ASSOC);
  103. $power=0;
  104. foreach ($Fetch as $key => $value) {
  105. # code...
  106. if((int)$value["power"]>$power){
  107. $power = $value["power"];
  108. }
  109. }
  110. return $power;
  111. }
  112. ?>