GroupReq-Notify.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * This taks handles notifying someone that a user has
  4. * requeted to join a group they moderate.
  5. *
  6. * Simple Machines Forum (SMF)
  7. *
  8. * @package SMF
  9. * @author Simple Machines http://www.simplemachines.org
  10. * @copyright 2014 Simple Machines and individual contributors
  11. * @license http://www.simplemachines.org/about/smf/license.php BSD
  12. *
  13. * @version SMF 2.1 Alpha 1
  14. */
  15. class GroupReq_Notify_Background extends SMF_BackgroundTask
  16. {
  17. public function execute()
  18. {
  19. global $sourcedir, $smcFunc, $language, $modSettings;
  20. // Do we have any group moderators?
  21. $request = $smcFunc['db_query']('', '
  22. SELECT id_member
  23. FROM {db_prefix}group_moderators
  24. WHERE id_group = {int:selected_group}',
  25. array(
  26. 'selected_group' => $this->_details['id_group'],
  27. )
  28. );
  29. $moderators = array();
  30. while ($row = $smcFunc['db_fetch_assoc']($request))
  31. $moderators[] = $row['id_member'];
  32. $smcFunc['db_free_result']($request);
  33. require_once($sourcedir . '/Subs-Members.php');
  34. // Make sure anyone who can moderate_membergroups gets notified as well
  35. $moderators = array_unique(array_merge($moderators, membersAllowedTo('manage_membergroups')));
  36. if (!empty($moderators))
  37. {
  38. // Figure out who wants to be alerted/emailed about this
  39. $data = array('alert' => array(), 'email' => array());
  40. require_once($sourcedir . '/Subs-Notify.php');
  41. $prefs = getNotifyPrefs($moderators, 'request_group', true);
  42. // Bitwise comparisons are fun...
  43. foreach ($moderators as $mod)
  44. {
  45. if (!empty($prefs[$mod]['request_group']))
  46. {
  47. if ($prefs[$mod]['request_group'] & 0x01)
  48. $data['alert'][] = $mod;
  49. if ($prefs[$mod]['request_group'] & 0x02)
  50. $data['email'][] = $mod;
  51. }
  52. }
  53. if (!empty($data['alert']))
  54. {
  55. $alert_rows = array();
  56. foreach($data['alert'] as $group_mod)
  57. {
  58. $alert_rows[] = array(
  59. 'alert_time' => $this->_details['time'],
  60. 'id_member' => $group_mod,
  61. 'id_member_started' => $this->_details['id_member'],
  62. 'member_name' => $this->_details['member_name'],
  63. 'content_type' => 'member',
  64. 'content_id' => 0,
  65. 'content_action' => 'group_request',
  66. 'is_read' => 0,
  67. 'extra' => serialize(array('group_name' => $this->_details['group_name'])),
  68. );
  69. }
  70. $smcFunc['db_insert']('insert', '{db_prefix}user_alerts',
  71. array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string',
  72. 'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'),
  73. $alert_rows, array()
  74. );
  75. }
  76. if (!empty($data['email']))
  77. {
  78. require_once($sourcedir . '/ScheduledTasks.php');
  79. require_once($sourcedir . '/Subs-Post.php');
  80. loadEssentialThemeData();
  81. $request = $smcFunc['db_query']('', '
  82. SELECT id_member, email_address, lngfile, member_name, mod_prefs
  83. FROM {db_prefix}members
  84. WHERE id_member IN ({array_int:moderator_list})
  85. ORDER BY lngfile',
  86. array(
  87. 'moderator_list' => $moderators,
  88. )
  89. );
  90. while ($row = $smcFunc['db_fetch_assoc']($request))
  91. {
  92. $replacements = array(
  93. 'RECPNAME' => $row['member_name'],
  94. 'APPYNAME' => $this->_details['member_name'],
  95. 'GROUPNAME' => $this->_details['group_name'],
  96. 'REASON' => $this->_details['reason'],
  97. 'MODLINK' => $scripturl . '?action=moderate;area=groups;sa=requests',
  98. );
  99. $emaildata = loadEmailTemplate('request_membership', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);
  100. sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'groupreq' . $this->_details['id_group'], false, 2);
  101. }
  102. }
  103. }
  104. return true;
  105. }
  106. }
  107. ?>