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