Advertisement
Guest User

Untitled

a guest
Aug 24th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. <?php
  2.  
  3. class adminMysql {
  4.  
  5. private static $interval;
  6. public static $config;
  7.  
  8. public static function isTriggered() {
  9. if (time() > self::$interval) {
  10. self::$interval = time() + HelpfulParrot::timer(self::$config['interval']);
  11. return true;
  12. }
  13. return false;
  14. }
  15.  
  16. public static function handle() {
  17. global $ts3, $db;
  18.  
  19. $connect = $db->prepare('SELECT * FROM adminOnTheServer');
  20. $connect->execute();
  21.  
  22. foreach ($ts3->getElement('data', $ts3->serverGroupList()) as $groups) {
  23. if (in_array($groups['sgid'], self::$config['groups'])) {
  24. foreach ($ts3->getElement('data', $ts3->serverGroupClientList($groups['sgid'], true)) as $sgClientList) {
  25. if (isset($sgClientList['cldbid'])) {
  26. $admins[] = [
  27. 'groupSgid' => $groups['sgid'],
  28. 'nick' => $sgClientList['client_nickname'],
  29. 'cldbid' => $sgClientList['cldbid'],
  30. 'cuid' => $sgClientList['client_unique_identifier'],
  31. 'groupName' => $groups['name']
  32. ];
  33. $cldbid[] = $sgClientList['cldbid'];
  34. }
  35. }
  36. }
  37. }
  38. foreach ($admins as $admin) {
  39. if ($connect->rowCount() < count($admins)) {
  40. $db->insert('adminOnTheServer', array(
  41. 'groupSgid' => $admin['groupSgid'],
  42. 'nick' => $admin['nick'],
  43. 'cldbid' => $admin['cldbid'],
  44. 'cuid' => $admin['cuid'],
  45. 'groupName' => $admin['groupName']
  46. ));
  47. } else {
  48. $update = array(
  49. 'groupSgid' => $admin['groupSgid'],
  50. 'nick' => $admin['nick'],
  51. 'groupName' => $admin['groupName'],
  52. );
  53. $db->update('adminOnTheServer', $update, "`cldbid` = '{$admin['cldbid']}'");
  54. }
  55. }
  56. $adminMsql = $connect->fetchAll(PDO::FETCH_COLUMN, 2);
  57. $adminDel = array_diff($adminMsql, $cldbid);
  58. if (!empty($adminDel)) {
  59. foreach ($adminDel as $adminRemove) {
  60. $db->delete("adminOnTheServer", "cldbid = $adminRemove", 1);
  61. }
  62. }
  63. unset($admins, $cldbid, $adminMsql);
  64. }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement