/source/plugin/myrepeats/memcp.inc.php

https://github.com/sichen/hrmmdiscuz · PHP · 81 lines · 64 code · 11 blank · 6 comment · 17 complexity · fcd6ba18716043a0da02d6431f31690a MD5 · raw file

  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: memcp.inc.php 18014 2010-11-10 05:52:07Z monkey $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. if(!$_G['uid']) {
  12. showmessage('not_loggedin', NULL, array(), array('login' => 1));
  13. }
  14. $myrepeatsusergroups = (array)unserialize($_G['cache']['plugin']['myrepeats']['usergroups']);
  15. if(in_array('', $myrepeatsusergroups)) {
  16. $myrepeatsusergroups = array();
  17. }
  18. $singleprem = FALSE;
  19. $permusers = array();
  20. if(!in_array($_G['groupid'], $myrepeatsusergroups)) {
  21. $singleprem = TRUE;
  22. }
  23. $query = DB::query("SELECT * FROM ".DB::table('myrepeats')." WHERE username='$_G[username]'");
  24. while($user = DB::fetch($query)) {
  25. $permusers[] = $user['uid'];
  26. }
  27. $query = DB::query("SELECT username FROM ".DB::table('common_member')." WHERE uid IN (".dimplode($permusers).")");
  28. $permusers = array();
  29. while($user = DB::fetch($query)) {
  30. $permusers[] = $user['username'];
  31. }
  32. if(!$permusers && $singleprem) {
  33. showmessage('myrepeats:usergroup_disabled');
  34. }
  35. if($_G['gp_pluginop'] == 'add' && submitcheck('adduser')) {
  36. if($singleprem && in_array(stripslashes($_G['gp_usernamenew']), $permusers) || !$singleprem) {
  37. $usernamenew = strip_tags($_G['gp_usernamenew']);
  38. $logindata = addslashes(authcode($_G['gp_passwordnew']."\t".$_G['gp_questionidnew']."\t".$_G['gp_answernew'], 'ENCODE', $_G['config']['security']['authkey']));
  39. if(DB::result_first("SELECT COUNT(*) FROM ".DB::table('myrepeats')." WHERE uid='$_G[uid]' AND username='$usernamenew'")) {
  40. DB::query("UPDATE ".DB::table('myrepeats')." SET logindata='$logindata' WHERE uid='$_G[uid]' AND username='$usernamenew'");
  41. } else {
  42. DB::query("INSERT INTO ".DB::table('myrepeats')." (uid, username, logindata, comment) VALUES ('$_G[uid]', '$usernamenew', '$logindata', '".strip_tags($_G['gp_commentnew'])."')");
  43. }
  44. dsetcookie('mrn', '');
  45. dsetcookie('mrd', '');
  46. $usernamenew = stripslashes($usernamenew);
  47. showmessage('myrepeats:adduser_succeed', 'home.php?mod=spacecp&ac=plugin&id=myrepeats:memcp', array('usernamenew' => $usernamenew));
  48. }
  49. } elseif($_G['gp_pluginop'] == 'update' && submitcheck('updateuser')) {
  50. if(!empty($_G['gp_delete'])) {
  51. DB::query("DELETE FROM ".DB::table('myrepeats')." WHERE uid='$_G[uid]' AND username IN (".dimplode($_G['gp_delete']).")");
  52. }
  53. foreach($_G['gp_comment'] as $user => $v) {
  54. DB::query("UPDATE ".DB::table('myrepeats')." SET comment='".strip_tags($v)."' WHERE uid='$_G[uid]' AND username='$user'");
  55. }
  56. dsetcookie('mrn', '');
  57. dsetcookie('mrd', '');
  58. showmessage('myrepeats:updateuser_succeed', 'home.php?mod=spacecp&ac=plugin&id=myrepeats:memcp');
  59. }
  60. $username = empty($_G['gp_username']) ? '' : htmlspecialchars(stripslashes($_G['gp_username']));
  61. $repeatusers = array();
  62. $query = DB::query("SELECT * FROM ".DB::table('myrepeats')." WHERE uid='$_G[uid]'");
  63. while($myrepeat = DB::fetch($query)) {
  64. $myrepeat['lastswitch'] = $myrepeat['lastswitch'] ? dgmdate($myrepeat['lastswitch']) : '';
  65. $myrepeat['usernameenc'] = rawurlencode($myrepeat['username']);
  66. $myrepeat['comment'] = htmlspecialchars($myrepeat['comment']);
  67. $repeatusers[] = $myrepeat;
  68. }
  69. $_G['basescript'] = 'home';
  70. ?>