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

Last change on this file since 7239 was 6825, checked in by Eric, 14 years ago

Bug fixed on adding new users in NBM list
Adding changelog.txt.php file
Version 1.0.2 hard coded

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