source: extensions/event_cats/main.inc.php @ 4247

Last change on this file since 4247 was 4247, checked in by LucMorizur, 14 years ago

[Event Cats] Continue duplication management using cat_perm.php and cat_perm.tpl codes

File size: 9.1 KB
Line 
1<?php
2
3/*
4Plugin Name: Event Cats
5Version: 1.0.0
6Description: A single URL can be enough to be identified, and a user can duplicate his account to create a new one getting immediately the same properties. / On peut être identifié grâce à un simple URL, et on peut dupliquer son compte pour créer un nouveau compte ayant immédiatement les mêmes propriétés.
7Plugin URI: http://piwigo.org/svn/extensions/event_cats
8Author: P@t, LucMorizur
9Author URI: http://www.gauchon.fr, http://lucmorizur.free.fr
10*/
11
12// +-----------------------------------------------------------------------+
13// | Piwigo - a PHP based picture gallery                                  |
14// +-----------------------------------------------------------------------+
15// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
16// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
17// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
18// +-----------------------------------------------------------------------+
19// | This program is free software; you can redistribute it and/or modify  |
20// | it under the terms of the GNU General Public License as published by  |
21// | the Free Software Foundation                                          |
22// |                                                                       |
23// | This program is distributed in the hope that it will be useful, but   |
24// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
25// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
26// | General Public License for more details.                              |
27// |                                                                       |
28// | You should have received a copy of the GNU General Public License     |
29// | along with this program; if not, write to the Free Software           |
30// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
31// | USA.                                                                  |
32// +-----------------------------------------------------------------------+
33
34if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
35
36// pour faciliter le debug - make debug easier :o)
37//ini_set('error_reporting', E_ALL);
38//ini_set('display_errors', true);
39
40global $conf, $prefixeTable, $ec_lists, $ec_debug,
41  $ec_ap_ok;   // whether Additional Pages is installed and activated
42
43define('EVNTCATS_INFO_VERSION','1.0.0');
44define('EVNTCATS_PATH',PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)). '/');
45define('EVNTCATS_TABLE',$prefixeTable.'event_cats');
46define('ROOT_URL',get_absolute_root_url());
47
48$ec_ap_ok = defined('AP_DIR');
49
50if (!isset($ec_lists)) $ec_lists = array();
51
52include_once(EVNTCATS_PATH.'include/evntcats_main_funcs.inc.php');
53
54class event_cats {
55// Sets the administration panel of the plugin
56  function plugin_admin_menu($menu) {
57    array_push($menu,
58      array(
59        'NAME' => 'Event Cats',
60        'URL'  => get_admin_plugin_menu_link(dirname(__FILE__).
61                  '/admin/evntcats_admin.php')
62      )
63    );
64    return $menu;
65  }
66} // End class
67
68$obj = new event_cats();
69
70// Admin help management
71add_event_handler('get_popup_help_content', 'ec_popup_help_content',
72 EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
73
74function ec_popup_help_content($popup_help_content, $page) {
75  return (
76   $help_content = ($page == 'event_cats' and is_admin()) ?
77    load_language('help.html', EVNTCATS_PATH, array('return' => true)) : false
78  ) ? $popup_help_content.$help_content : $popup_help_content;
79}
80
81//----------------------------------
82
83/**
84 *
85 * auto_log_user()
86 * the function uses the value of the argument "autolog" of the posted URL, as a code
87 * to know which username has to be logged in.
88 *
89 * @param no parameter
90 * @return no return value
91 */
92
93add_event_handler('init', 'auto_log_user');
94
95function auto_log_user() {
96  global $ec_lists;
97
98  $ec_ap  = NULL;
99  $ec_cat = NULL;
100  $ec_img = NULL;
101
102  // For compatibility ; must be removed
103  if (isset($_GET['log'])) $_GET['autolog'] = $_GET['log'];
104  // For compatibility ; must be removed
105 
106  if (isset($_GET['autolog']) and (read_ec_conf('activated') == 1)) {
107    if (!is_a_guest()) {
108      $url = '';
109      foreach ($_GET as $item => $value) {
110        $url.= '&'.$item.'='.$value;
111      }
112      logout_user();
113      redirect(make_index_url().$url);
114    }
115    build_ec_lists();
116    foreach ($ec_lists['ec_table'] as $ec_entry) {
117      if ($code_exists = ($ec_entry['code'] == $_GET['autolog'])) break;
118    }
119    if ($code_exists) {
120      if (is_in($ec_entry['action'], 'ec_ok')) {
121        log_user($ec_entry['user_id'], false);
122        if (isset($_GET['ap'])) $ec_ap = $_GET['ap'];
123        if (isset($_GET['cat'])) $ec_cat = $_GET['cat'];
124        if (isset($_GET['img'])) $ec_img = $_GET['img'];
125        if ($ec_entry['forced'] == 'true') {
126          if (empty($ec_entry['arg1']) and !empty($ec_entry['arg2'])) {
127            $ec_ap = $ec_entry['arg2'];
128          }
129          elseif (!empty($ec_entry['arg1'])) {
130            $ec_cat = $ec_entry['arg1'];
131            if (!empty($ec_entry['arg2'])) $ec_img = $ec_entry['arg2'];
132          }
133        }
134        if (isset($ec_ap)) {
135          if (array_key_exists($ec_ap,$ec_lists['add_pages'])) {
136            redirect(
137             PHPWG_ROOT_PATH.'index.php?/additional_page/'.$ec_ap);
138          }
139        }
140        elseif (isset($ec_cat)) {
141          if (array_key_exists($ec_cat, $ec_lists['categories'])) {
142            if (isset($ec_img)) {
143              if (ec_image_exists($ec_cat, $ec_img)) {
144                redirect(PHPWG_ROOT_PATH.'picture.php?/'.$ec_img.'/category/'.$ec_cat);
145              }
146            }
147            redirect(PHPWG_ROOT_PATH.'index.php?/category/'.$ec_cat);
148          }
149        }
150        redirect(make_index_url());
151      }
152      else {
153        if (
154         $ec_entry['action'] == 'ec_nok' or
155         $ec_entry['action'] == 'ec_nok_ap_pb'
156        ) {
157          if ($ec_entry['action'] == 'ec_nok_ap_pb') access_denied();
158          $ec_ap = $ec_entry['arg2'];
159          if (array_key_exists($ec_ap, $ec_lists['add_pages'])) {
160            redirect(
161             PHPWG_ROOT_PATH.'index.php?/additional_page/'.$ec_ap);
162          }
163          access_denied();
164        }
165        else {
166          redirect(make_index_url());
167        }
168      }
169    }
170    else {
171      if (
172       read_ec_conf('unknown_code') == 2 and
173        array_key_exists(
174         read_ec_conf('unknown_code_ap_id'), $ec_lists['add_pages']
175        )
176       ) {
177        redirect(
178         PHPWG_ROOT_PATH.
179         'index.php?/additional_page/'.read_ec_conf('unknown_code_ap_id')
180        );
181      }
182      elseif (read_ec_conf('unknown_code') == 1 or
183       read_ec_conf('unknown_code') == 2) {
184        access_denied();
185      }
186      else {
187        redirect(make_index_url());
188      }
189    }
190  }
191}
192
193/**
194 *
195 * assign_perm_for_new_user()
196 * copies/paste groups+access+properties associations of previously connected
197 * username, to newly created username.
198 *
199 * @param no parameter
200 * @return no return value
201 */
202
203add_event_handler('register_user', 'assign_perm_for_new_user');
204
205function assign_perm_for_new_user($new_user)
206{
207  global $user;
208
209  if (!is_a_guest() and !is_admin())
210  {
211    // User access
212    $query = 'SELECT cat_id FROM '.USER_ACCESS_TABLE.' WHERE user_id = '.$user['id'].';';
213    $result = pwg_query($query);
214    $insert = array();
215    while ($row = mysql_fetch_assoc($result))
216    {
217      $insert[] = '('.$new_user['id'].','.$row['cat_id'].')';
218    }
219    if (!empty($insert))
220    {
221      pwg_query('INSERT INTO '.USER_ACCESS_TABLE.' VALUES '.implode(',', $insert).';');
222    }
223
224    // User groups
225    $query = 'SELECT group_id FROM '.USER_GROUP_TABLE.' WHERE user_id = '.$user['id'].';';
226    $result = pwg_query($query);
227    $insert = array();
228    while ($row = mysql_fetch_assoc($result))
229    {
230      $insert[] = '('.$new_user['id'].','.$row['group_id'].')';
231    }
232    if (!empty($insert))
233    {
234      pwg_query('INSERT INTO '.USER_GROUP_TABLE.' VALUES '.implode(',', $insert).';');
235    }
236
237    // User infos
238    $query = 'SELECT level FROM '.USER_INFOS_TABLE.' WHERE user_id = '.$user['id'].';';
239    $result = pwg_query($query);
240    $insert = array();
241    while ($row = mysql_fetch_assoc($result))
242    {
243      $insert[] = '('.$new_user['id'].','.$row['level'].')';
244    }
245    if (!empty($insert))
246    {
247      $query = 'UPDATE '.USER_INFOS_TABLE.' SET level = '.$user['level'].' WHERE user_id = '.$new_user['id'].';';
248      pwg_query($query);
249    }
250  }
251}
252
253/**
254 *
255 * duplicate_account_url()
256 * adds a link "Duplicate" in Identification block menu.
257 *
258 * @param no parameter
259 * @return no return value
260 */
261
262add_event_handler('blockmanager_apply', 'duplicate_account_url');
263
264function duplicate_account_url() {
265  global $lang, $template;
266 
267  if (is_admin() and read_ec_conf('reg_display') == '0')
268   change_ec_conf('reg_display', '1;'.$lang['Register']);
269  if (!is_admin() and !is_a_guest()) {
270    $template->assign( 'U_REGISTER', get_root_url().'register.php');
271    $lang['Create a new account'] = l10n('Duplicate account');
272    $lang['Register'] = l10n('Duplicate');
273  }
274}
275
276add_event_handler('get_admin_plugin_menu_links', array(&$obj, 'plugin_admin_menu') );
277set_plugin_data($plugin['id'], $obj);
278
279?>
Note: See TracBrowser for help on using the repository browser.