source: extensions/NBM_Subscriber/main.inc.php @ 32840

Last change on this file since 32840 was 23028, checked in by Eric, 11 years ago

Next version is 2.5.3:
Bug fixed - On new user registration, user should submit his NBM choice twice in his profile page for it to be considered

  • Property svn:eol-style set to LF
File size: 3.7 KB
Line 
1<?php
2/*
3Plugin Name: NBM Subscriber
4Version: auto
5Description: Permet aux visiteurs inscrits de gérer eux-même leur abonnement à la notification par mail (NBM) - Allows registered visitors to manage their own subscription to the notification by mail (NBM)
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=397
7Author: Eric
8Author URI: http://www.infernoweb.net
9*/
10
11if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
12if (!defined('NBMS_PATH')) define('NBMS_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
13
14include_once (NBMS_PATH.'include/functions.inc.php');
15
16load_language('plugin.lang', NBMS_PATH);
17
18
19/* Plugin admin */
20add_event_handler('get_admin_plugin_menu_links', 'NBMS_admin_menu');
21
22function NBMS_admin_menu($menu)
23{
24// +-----------------------------------------------------------------------+
25// |                      Getting plugin name                              |
26// +-----------------------------------------------------------------------+
27  $plugin =  NBMSInfos(NBMS_PATH);
28  $name = $plugin['name'];
29 
30  array_push($menu,
31    array(
32      'NAME' => $name,
33      'URL' => get_root_url().'admin.php?page=plugin-'.basename(NBMS_PATH)
34    )
35  );
36
37  return $menu;
38}
39
40
41/* Saving from profile with added data */
42add_event_handler('save_profile_from_post', 'NBMS_Save_Profile');
43
44function NBMS_Save_Profile()
45{
46  global $conf, $user;
47 
48  include_once(PHPWG_ROOT_PATH.'admin/include/functions_notification_by_mail.inc.php');
49 
50  $query = '
51SELECT *
52FROM '.USER_MAIL_NOTIFICATION_TABLE.'
53WHERE user_id = \''.$user['id'].'\'
54';
55
56  $count = pwg_db_num_rows(pwg_query($query));
57
58  if ($count == 0)
59  {
60    $inserts = array();
61    $check_key_list = array();
62
63    // Calculate key
64    $nbm_user['check_key'] = find_available_check_key();
65
66    // Save key
67    array_push($check_key_list, $nbm_user['check_key']);
68
69    // Insert new nbm_users
70    array_push
71    (
72      $inserts,
73        array
74        (
75          'user_id' => $user['id'],
76          'check_key' => $nbm_user['check_key'],
77          'enabled' => $_POST['NBM_Subscription']
78        )
79    );
80
81    mass_inserts(USER_MAIL_NOTIFICATION_TABLE, array('user_id', 'check_key', 'enabled'), $inserts);
82  }
83  elseif ($count != 0 and !empty($_POST['NBM_Subscription']) && in_array($_POST['NBM_Subscription'], array('true', 'false')))
84  {
85    $query = '
86UPDATE '.USER_MAIL_NOTIFICATION_TABLE.'
87  SET enabled = \''.$_POST['NBM_Subscription'].'\'
88  WHERE user_id = \''.$user['id'].'\';';
89
90    pwg_query($query); 
91  }
92}
93
94/* Adding NBMS in profile page */
95add_event_handler('load_profile_in_template', 'NBMS_Load_Profile');
96
97function NBMS_Load_Profile()
98{
99  global $conf, $user, $template, $lang;
100
101  $query = '
102  SELECT enabled
103    FROM '.USER_MAIL_NOTIFICATION_TABLE.'
104    WHERE user_id = \''.$user['id'].'\'
105  ;';
106 
107  $data = pwg_db_fetch_assoc(pwg_query($query));
108 
109  $values = $data['enabled'];
110 
111  if (is_null($values))
112    $values = 'false';
113
114  $template->assign('radio_options',
115    array(
116      'true' => l10n('Yes'),
117      'false'=> l10n('No')
118    )
119  );
120
121  $template->assign(
122    array(
123      'NBMS'=>$values
124    )
125  );
126     
127  $template->set_prefilter('profile_content', 'NBMS_prefilter');
128}
129
130/* Original template modification */
131function NBMS_prefilter($content, &$smarty)
132{
133  global $template, $lang;
134 
135  load_language('plugin.lang', NBMS_PATH);
136 
137  $search = '<p class="bottomButtons">';
138     
139  $addon = '
140  <fieldset>
141    <legend>{\'NBMS_Section\'|@translate}</legend>
142      <ul>
143        <li>
144          <span class="property">{\'NBMS_Text\'|@translate}</span>
145          {html_radios name=\'NBM_Subscription\' options=$radio_options selected=$NBMS}
146        </li>
147      </ul>
148  </fieldset>
149';
150 
151  $replacement = $addon.$search;
152
153  return str_replace($search, $replacement, $content);
154}
155?>
Note: See TracBrowser for help on using the repository browser.