GroupReq-Notify.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 2013 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' => $group_id,
  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');
  42. // Bitwise comparisons are fun...
  43. foreach ($moderators as $mod)
  44. {
  45. // Do we have any defaults?
  46. if (isset($prefs[0]) && !isset($prefs[$mod]))
  47. $prefs[$mod] = $prefs[0];
  48. if (!empty($prefs[$mod]))
  49. {
  50. if ($prefs[$mod] & 0x01 == 0x01)
  51. $data['alert'][] = $mod;
  52. if ($prefs[$mod] & 0x02 == 0x02)
  53. $data['email'][] = $mod;
  54. }
  55. }
  56. if (!empty($data['alert']))
  57. {
  58. $alert_rows = array();
  59. foreach($data['alert'] as $group_mod)
  60. {
  61. $alert_rows[] = array(
  62. 'alert_time' => $this->_details['time'],
  63. 'id_member' => $group_mod,
  64. 'id_member_started' => $this->_details['id_member'],
  65. 'member_name' => $this->_details['member_name'],
  66. 'content_type' => 'member',
  67. 'content_id' => 0,
  68. 'content_action' => 'group_request',
  69. 'extra' => serialize(array('group_name' => $this->_details['group_name'])),
  70. );
  71. }
  72. $smcFunc['db_insert']('insert', '{db_prefix}user_alerts',
  73. array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string',
  74. 'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'),
  75. $alert_rows, array()
  76. );
  77. }
  78. if (!empty($data['email']))
  79. {
  80. require_once($sourcedir . '/ScheduledTasks.php');
  81. require_once($sourcedir . '/Subs-Post.php');
  82. loadEssentialThemeData();
  83. $request = $smcFunc['db_query']('', '
  84. SELECT id_member, email_address, lngfile, member_name, mod_prefs
  85. FROM {db_prefix}members
  86. WHERE id_member IN ({array_int:moderator_list})
  87. ORDER BY lngfile',
  88. array(
  89. 'moderator_list' => $moderators,
  90. )
  91. );
  92. while ($row = $smcFunc['db_fetch_assoc']($request))
  93. {
  94. $replacements = array(
  95. 'RECPNAME' => $row['member_name'],
  96. 'APPYNAME' => $this->_details['member_name'],
  97. 'GROUPNAME' => $this->_details['group_name'],
  98. 'REASON' => $this->_details['reason'],
  99. 'MODLINK' => $scripturl . '?action=moderate;area=groups;sa=requests',
  100. );
  101. $emaildata = loadEmailTemplate('request_membership', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);
  102. sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, null, false, 2);
  103. }
  104. }
  105. }
  106. return true;
  107. }
  108. }
  109. ?>