Notify.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. /**
  3. * Simple Machines Forum (SMF)
  4. *
  5. * @package SMF
  6. * @author Simple Machines http://www.simplemachines.org
  7. * @copyright 2011 Simple Machines
  8. * @license http://www.simplemachines.org/about/smf/license.php BSD
  9. *
  10. * @version 2.0
  11. */
  12. if (!defined('SMF'))
  13. die('Hacking attempt...');
  14. /* This file contains just the functions that turn on and off notifications to
  15. topics or boards. The following two functions are included:
  16. void Notify()
  17. - is called to turn off/on notification for a particular topic.
  18. - must be called with a topic specified in the URL.
  19. - uses the Notify template (main sub template.) when called with no sa.
  20. - the sub action can be 'on', 'off', or nothing for what to do.
  21. - requires the mark_any_notify permission.
  22. - upon successful completion of action will direct user back to topic.
  23. - is accessed via ?action=notify.
  24. void BoardNotify()
  25. - is called to turn off/on notification for a particular board.
  26. - must be called with a board specified in the URL.
  27. - uses the Notify template. (notify_board sub template.)
  28. - only uses the template if no sub action is used. (on/off)
  29. - requires the mark_notify permission.
  30. - redirects the user back to the board after it is done.
  31. - is accessed via ?action=notifyboard.
  32. */
  33. // Turn on/off notifications...
  34. function Notify()
  35. {
  36. global $scripturl, $txt, $topic, $user_info, $context, $smcFunc;
  37. // Make sure they aren't a guest or something - guests can't really receive notifications!
  38. is_not_guest();
  39. isAllowedTo('mark_any_notify');
  40. // Make sure the topic has been specified.
  41. if (empty($topic))
  42. fatal_lang_error('not_a_topic', false);
  43. // What do we do? Better ask if they didn't say..
  44. if (empty($_GET['sa']))
  45. {
  46. // Load the template, but only if it is needed.
  47. loadTemplate('Notify');
  48. // Find out if they have notification set for this topic already.
  49. $request = $smcFunc['db_query']('', '
  50. SELECT id_member
  51. FROM {db_prefix}log_notify
  52. WHERE id_member = {int:current_member}
  53. AND id_topic = {int:current_topic}
  54. LIMIT 1',
  55. array(
  56. 'current_member' => $user_info['id'],
  57. 'current_topic' => $topic,
  58. )
  59. );
  60. $context['notification_set'] = $smcFunc['db_num_rows']($request) != 0;
  61. $smcFunc['db_free_result']($request);
  62. // Set the template variables...
  63. $context['topic_href'] = $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'];
  64. $context['start'] = $_REQUEST['start'];
  65. $context['page_title'] = $txt['notification'];
  66. return;
  67. }
  68. elseif ($_GET['sa'] == 'on')
  69. {
  70. checkSession('get');
  71. // Attempt to turn notifications on.
  72. $smcFunc['db_insert']('ignore',
  73. '{db_prefix}log_notify',
  74. array('id_member' => 'int', 'id_topic' => 'int'),
  75. array($user_info['id'], $topic),
  76. array('id_member', 'id_topic')
  77. );
  78. }
  79. else
  80. {
  81. checkSession('get');
  82. // Just turn notifications off.
  83. $smcFunc['db_query']('', '
  84. DELETE FROM {db_prefix}log_notify
  85. WHERE id_member = {int:current_member}
  86. AND id_topic = {int:current_topic}',
  87. array(
  88. 'current_member' => $user_info['id'],
  89. 'current_topic' => $topic,
  90. )
  91. );
  92. }
  93. // Send them back to the topic.
  94. redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
  95. }
  96. function BoardNotify()
  97. {
  98. global $scripturl, $txt, $board, $user_info, $context, $smcFunc;
  99. // Permissions are an important part of anything ;).
  100. is_not_guest();
  101. isAllowedTo('mark_notify');
  102. // You have to specify a board to turn notifications on!
  103. if (empty($board))
  104. fatal_lang_error('no_board', false);
  105. // No subaction: find out what to do.
  106. if (empty($_GET['sa']))
  107. {
  108. // We're gonna need the notify template...
  109. loadTemplate('Notify');
  110. // Find out if they have notification set for this topic already.
  111. $request = $smcFunc['db_query']('', '
  112. SELECT id_member
  113. FROM {db_prefix}log_notify
  114. WHERE id_member = {int:current_member}
  115. AND id_board = {int:current_board}
  116. LIMIT 1',
  117. array(
  118. 'current_board' => $board,
  119. 'current_member' => $user_info['id'],
  120. )
  121. );
  122. $context['notification_set'] = $smcFunc['db_num_rows']($request) != 0;
  123. $smcFunc['db_free_result']($request);
  124. // Set the template variables...
  125. $context['board_href'] = $scripturl . '?board=' . $board . '.' . $_REQUEST['start'];
  126. $context['start'] = $_REQUEST['start'];
  127. $context['page_title'] = $txt['notification'];
  128. $context['sub_template'] = 'notify_board';
  129. return;
  130. }
  131. // Turn the board level notification on....
  132. elseif ($_GET['sa'] == 'on')
  133. {
  134. checkSession('get');
  135. // Turn notification on. (note this just blows smoke if it's already on.)
  136. $smcFunc['db_insert']('ignore',
  137. '{db_prefix}log_notify',
  138. array('id_member' => 'int', 'id_board' => 'int'),
  139. array($user_info['id'], $board),
  140. array('id_member', 'id_board')
  141. );
  142. }
  143. // ...or off?
  144. else
  145. {
  146. checkSession('get');
  147. // Turn notification off for this board.
  148. $smcFunc['db_query']('', '
  149. DELETE FROM {db_prefix}log_notify
  150. WHERE id_member = {int:current_member}
  151. AND id_board = {int:current_board}',
  152. array(
  153. 'current_board' => $board,
  154. 'current_member' => $user_info['id'],
  155. )
  156. );
  157. }
  158. // Back to the board!
  159. redirectexit('board=' . $board . '.' . $_REQUEST['start']);
  160. }
  161. ?>