source: extensions/Subscribe_to_comments/include/subscriptions_page.inc.php @ 26141

Last change on this file since 26141 was 26141, checked in by mistic100, 10 years ago

update language files

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