1 | <?php |
---|
2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | global $template, $conf, $page, $pwg_loaded_plugins; |
---|
5 | |
---|
6 | // check input parameters |
---|
7 | $_GET['verif_key'] = $_GET['action'].$_GET['email'].(isset($_GET['id'])?$_GET['id']:null); |
---|
8 | |
---|
9 | if ( |
---|
10 | empty($_GET['action']) or empty($_GET['email']) or empty($_GET['key']) |
---|
11 | or decrypt_value($_GET['key'], $conf['secret_key']) !== $_GET['verif_key'] |
---|
12 | ) |
---|
13 | { |
---|
14 | $_GET['action'] = null; |
---|
15 | } |
---|
16 | else |
---|
17 | { |
---|
18 | // unsubscribe all |
---|
19 | if ( isset($_POST['unsubscribe_all']) and isset($_POST['unsubscribe_all_check']) ) |
---|
20 | { |
---|
21 | $query = ' |
---|
22 | DELETE FROM '.SUBSCRIBE_TO_TABLE.' |
---|
23 | WHERE email = "'.$_GET['email'].'" |
---|
24 | ;'; |
---|
25 | pwg_query($query); |
---|
26 | } |
---|
27 | |
---|
28 | // bulk action |
---|
29 | if (isset($_POST['apply_bulk'])) |
---|
30 | { |
---|
31 | foreach ($_POST['selected'] as $id) |
---|
32 | { |
---|
33 | switch ($_POST['action']) |
---|
34 | { |
---|
35 | case 'unsubscribe': |
---|
36 | un_subscribe_to_comments($_GET['email'], $id); |
---|
37 | break; |
---|
38 | case 'validate': |
---|
39 | validate_subscriptions($_GET['email'], $id); |
---|
40 | break; |
---|
41 | } |
---|
42 | } |
---|
43 | } |
---|
44 | |
---|
45 | // unsubscribe from manage page |
---|
46 | if (isset($_GET['unsubscribe'])) |
---|
47 | { |
---|
48 | if (un_subscribe_to_comments($_GET['email'], $_GET['unsubscribe'])) |
---|
49 | { |
---|
50 | array_push($page['infos'], l10n('Successfully unsubscribed your email address from receiving notifications.')); |
---|
51 | } |
---|
52 | else |
---|
53 | { |
---|
54 | array_push($page['errors'], l10n('Not found.')); |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | // validate from manage page |
---|
59 | if (isset($_GET['validate'])) |
---|
60 | { |
---|
61 | if (validate_subscriptions($_GET['email'], $_GET['validate'])) |
---|
62 | { |
---|
63 | array_push($page['infos'], l10n('Your subscribtion has been validated, thanks you.')); |
---|
64 | } |
---|
65 | else |
---|
66 | { |
---|
67 | array_push($page['infos'], l10n('Already validated.')); |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | $template->assign('MANAGE_LINK', make_stc_url('manage', $_GET['email'])); |
---|
72 | } |
---|
73 | |
---|
74 | |
---|
75 | switch ($_GET['action']) |
---|
76 | { |
---|
77 | /* validate */ |
---|
78 | case 'validate': |
---|
79 | { |
---|
80 | $query = ' |
---|
81 | SELECT |
---|
82 | type, |
---|
83 | element_id |
---|
84 | FROM '.SUBSCRIBE_TO_TABLE.' |
---|
85 | WHERE |
---|
86 | email = "'.$_GET['email'].'" |
---|
87 | AND id = '.$_GET['id'].' |
---|
88 | ;'; |
---|
89 | $result = pwg_query($query); |
---|
90 | |
---|
91 | if (!pwg_db_num_rows($result)) |
---|
92 | { |
---|
93 | array_push($page['errors'], l10n('Not found.')); |
---|
94 | } |
---|
95 | else |
---|
96 | { |
---|
97 | if (validate_subscriptions($_GET['email'], $_GET['id'])) |
---|
98 | { |
---|
99 | array_push($page['infos'], l10n('Your subscribtion has been validated, thanks you.')); |
---|
100 | } |
---|
101 | else |
---|
102 | { |
---|
103 | array_push($page['infos'], l10n('Already validated.')); |
---|
104 | } |
---|
105 | |
---|
106 | list($type, $element_id) = pwg_db_fetch_row($result); |
---|
107 | |
---|
108 | switch ($type) |
---|
109 | { |
---|
110 | case 'image': |
---|
111 | $element = get_picture_infos($element_id, false); |
---|
112 | break; |
---|
113 | case 'album-images': |
---|
114 | case 'album': |
---|
115 | $element = get_category_infos($element_id, false); |
---|
116 | break; |
---|
117 | default: |
---|
118 | $element = null; |
---|
119 | } |
---|
120 | |
---|
121 | $template->assign(array( |
---|
122 | 'type' => $type, |
---|
123 | 'element' => $element, |
---|
124 | )); |
---|
125 | } |
---|
126 | |
---|
127 | $template->assign('IN_VALIDATE', true); |
---|
128 | break; |
---|
129 | } |
---|
130 | |
---|
131 | /* unsubscribe */ |
---|
132 | case 'unsubscribe': |
---|
133 | { |
---|
134 | $query = ' |
---|
135 | SELECT |
---|
136 | type, |
---|
137 | element_id |
---|
138 | FROM '.SUBSCRIBE_TO_TABLE.' |
---|
139 | WHERE |
---|
140 | email = "'.$_GET['email'].'" |
---|
141 | AND id = '.$_GET['id'].' |
---|
142 | ;'; |
---|
143 | $result = pwg_query($query); |
---|
144 | |
---|
145 | if (!pwg_db_num_rows($result)) |
---|
146 | { |
---|
147 | array_push($page['errors'], l10n('Not found.')); |
---|
148 | } |
---|
149 | else |
---|
150 | { |
---|
151 | if (un_subscribe_to_comments($_GET['email'], $_GET['id'])) |
---|
152 | { |
---|
153 | array_push($page['infos'], l10n('Successfully unsubscribed your email address from receiving notifications.')); |
---|
154 | } |
---|
155 | else |
---|
156 | { |
---|
157 | array_push($page['errors'], l10n('Not found.')); |
---|
158 | } |
---|
159 | |
---|
160 | list($type, $element_id) = pwg_db_fetch_row($result); |
---|
161 | |
---|
162 | switch ($type) |
---|
163 | { |
---|
164 | case 'image': |
---|
165 | $element = get_picture_infos($element_id); |
---|
166 | break; |
---|
167 | case 'album-images': |
---|
168 | case 'album': |
---|
169 | $element = get_category_infos($element_id); |
---|
170 | break; |
---|
171 | default: |
---|
172 | $element = null; |
---|
173 | } |
---|
174 | |
---|
175 | $template->assign(array( |
---|
176 | 'type' => $type, |
---|
177 | 'element' => $element, |
---|
178 | )); |
---|
179 | } |
---|
180 | |
---|
181 | $template->assign('IN_UNSUBSCRIBE', true); |
---|
182 | break; |
---|
183 | } |
---|
184 | |
---|
185 | /* manage */ |
---|
186 | case 'manage': |
---|
187 | { |
---|
188 | $query = ' |
---|
189 | SELECT * |
---|
190 | FROM '.SUBSCRIBE_TO_TABLE.' |
---|
191 | WHERE email = "'.$_GET['email'].'" |
---|
192 | ORDER BY registration_date DESC |
---|
193 | ;'; |
---|
194 | $result = pwg_query($query); |
---|
195 | |
---|
196 | if (pwg_db_num_rows($result)) |
---|
197 | { |
---|
198 | while ($subscription = pwg_db_fetch_assoc($result)) |
---|
199 | { |
---|
200 | $subscription['registration_date'] = format_date($subscription['registration_date'], true); |
---|
201 | |
---|
202 | switch ($subscription['type']) |
---|
203 | { |
---|
204 | case 'image': |
---|
205 | $subscription['infos'] = get_picture_infos($subscription['element_id']); |
---|
206 | break; |
---|
207 | case 'album-images': |
---|
208 | case 'album': |
---|
209 | $subscription['infos'] = get_category_infos($subscription['element_id']); |
---|
210 | break; |
---|
211 | default: |
---|
212 | $subscription['infos'] = null; |
---|
213 | $template->append('global_subscriptions', $subscription); |
---|
214 | continue(2); |
---|
215 | } |
---|
216 | |
---|
217 | $template->append('subscriptions', $subscription); |
---|
218 | } |
---|
219 | } |
---|
220 | else |
---|
221 | { |
---|
222 | array_push($page['infos'], l10n('You are not subscribed to any comment.')); |
---|
223 | } |
---|
224 | break; |
---|
225 | } |
---|
226 | |
---|
227 | default: |
---|
228 | { |
---|
229 | set_status_header(403); |
---|
230 | array_push($page['errors'], l10n('Bad query')); |
---|
231 | } |
---|
232 | } |
---|
233 | |
---|
234 | if (isset($pwg_loaded_plugins['Comments_on_Albums'])) |
---|
235 | { |
---|
236 | $template->assign('COA_ACTIVATED', true); |
---|
237 | } |
---|
238 | |
---|
239 | $template->assign(array( |
---|
240 | 'TITLE' => l10n('Subscriptions of').' <i>'.$_GET['email'].'</i>', |
---|
241 | 'SUBSCRIBE_TO_PATH' => SUBSCRIBE_TO_PATH, |
---|
242 | 'SUBSCRIBE_TO_ABS_PATH' => realpath(SUBSCRIBE_TO_PATH).'/', |
---|
243 | )); |
---|
244 | |
---|
245 | $template->set_filenames(array('index'=> dirname(__FILE__).'/../template/subscribtions_page.tpl')); |
---|
246 | |
---|
247 | ?> |
---|