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

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

change layout of form (use colorbox for standalone) + cleaning of subscriptions page

File size: 6.0 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
22if (!empty($_GET['action']))
23{
24  // unsubscribe all
25  if (isset($_POST['unsubscribe_all']) and isset($_POST['unsubscribe_all_check']))
26  {
27    $query = '
28DELETE FROM '.SUBSCRIBE_TO_TABLE.'
29  WHERE email = "'.$_GET['email'].'"
30;';
31    pwg_query($query);
32  }
33
34  // bulk action
35  else if (isset($_POST['apply_bulk']) and !empty($_POST['selected']))
36  {
37    switch ($_POST['action'])
38    {
39      case 'unsubscribe':
40        un_subscribe_to_comments($_GET['email'], $_POST['selected']);
41        break;
42      case 'validate':
43        validate_subscriptions($_GET['email'], $_POST['selected']);
44        break;
45    }
46  }
47
48  // unsubscribe from manage page
49  else if (isset($_GET['unsubscribe']))
50  {
51    if (un_subscribe_to_comments($_GET['email'], $_GET['unsubscribe']))
52    {
53      $page['infos'][] = l10n('Successfully unsubscribed your email address from receiving notifications.');
54    }
55    else
56    {
57      $page['errors'][] = l10n('Not found.');
58    }
59  }
60
61  // validate from manage page
62  else if (isset($_GET['validate']))
63  {
64    if (validate_subscriptions($_GET['email'], $_GET['validate']))
65    {
66      $page['infos'][] = l10n('Your subscription has been validated, thanks you.');
67    }
68    else
69    {
70      $page['infos'][] = l10n('Already validated.');
71    }
72  }
73
74  $self_url = make_stc_url('manage', $_GET['email']);
75  $template->assign('U_MANAGE_SUBSCRIPTIONS', $self_url);
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('STC', 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('STC', 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        $subscription['U_UNSUB'] = add_url_params($self_url, array('unsubscribe'=>$subscription['id']));
205        if ($subscription['validated']=='false')
206        {
207          $subscription['U_VALIDATE'] = add_url_params($self_url, array('validate'=>$subscription['id']));
208        }
209
210        switch ($subscription['type'])
211        {
212          case 'image':
213            $subscription['infos'] = get_picture_infos($subscription['element_id']);
214            break;
215          case 'album-images':
216          case 'album':
217            $subscription['infos'] = get_category_infos($subscription['element_id'], true, $user['id']);
218            break;
219          default:
220            $subscription['infos'] = null;
221            $template->append('global_subscriptions', $subscription);
222            continue(2);
223        }
224
225        $template->append('subscriptions', $subscription);
226      }
227    }
228    else
229    {
230      $page['infos'][] = l10n('You are not subscribed to any comment.');
231    }
232    break;
233  }
234
235  default:
236  {
237    set_status_header(403);
238    $page['errors'][] = l10n('Bad query');
239  }
240}
241
242
243$template->assign(array(
244  'SUBSCRIBE_TO_PATH' => SUBSCRIBE_TO_PATH,
245  'SUBSCRIBE_TO_ABS_PATH' => realpath(SUBSCRIBE_TO_PATH).'/',
246  'COA_ACTIVATED' => defined('COA_ID'),
247  ));
248
249if (!empty($_GET['email']))
250{
251  $template->concat('TITLE', $conf['level_separator'] . l10n('Subscriptions of %s', '<i>'.$_GET['email'].'</i>'));
252}
253
254$template->set_filename('subscribe_to_comments', realpath(SUBSCRIBE_TO_PATH . 'template/subscriptions_page.tpl'));
255$template->assign_var_from_handle('CONTENT', 'subscribe_to_comments');
Note: See TracBrowser for help on using the repository browser.