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

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

[Event Cats] bug:1432 (Event Cats help always loaded after other admin help screens ) resolved

File size: 10.9 KB
Line 
1<?php
2
3/*
4Plugin Name: Event Cats
5Version: auto
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/ext/extension_svn.php?eid=326
8Author: LucMorizur
9Author URI: 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
34// Keeps file coded in UTF-8 without BOM : é
35
36if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
37
38// pour faciliter le debug - make debug easier :o)
39//ini_set('error_reporting', E_ALL);
40//ini_set('display_errors', true);
41
42global $conf, $prefixeTable, $ec_lists;
43
44define( // -------------------------------------------------------------------
45  'EVNTCATS_INFO_VERSION', // VERSION HISTORY :
46   '1.2.1' // Improve EN translation thanks to Tosca
47// '1.2.0' // Add feature 1335, Possibility to display the 'Connection'
48//         // link in identification block menu for generic users ;
49//         // finish (yes !) english translation
50// '1.1.5' // Fix bugs 1324 and 1325
51// '1.1.4' // Improve help banner
52// '1.1.3' // Better help banner management ; finalize banner texts
53// '1.1.2' // Better help banner example : some examples
54// '1.1.1' // Better help banner example ; but still no text in it
55// '1.1.0' // First bugs (1305 and 1306) corrected ;
56           // add newly created user/group association with cat/AP (was
57           // forgotten) ; begin help banner
58// '1.0.0' // Conception version
59); // ------------------------------------------------------------------------
60define(
61  'EVNTCATS_PATH',
62   PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'
63);
64define(
65  'EVNTCATS_TABLE',
66   $prefixeTable.'event_cats'
67);
68define(
69  'ROOT_URL',
70   get_absolute_root_url()
71);
72
73include_once(EVNTCATS_PATH.'include/evntcats_main_funcs.inc.php');
74
75class event_cats {
76// Sets the administration panel of the plugin
77  function plugin_admin_menu($menu) {
78    array_push($menu,
79      array(
80        'NAME' => 'Event Cats',
81        'URL'  => get_admin_plugin_menu_link(dirname(__FILE__).
82                  '/admin/evntcats_admin.php')
83      )
84    );
85    return $menu;
86  }
87} // End class
88
89$obj = new event_cats();
90
91// Adds the translation of "duplicate" link
92load_language('duplic.lang', EVNTCATS_PATH);
93
94// Admin help management
95add_event_handler('get_popup_help_content', 'ec_popup_help_content',
96 EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
97
98function ec_popup_help_content($popup_help_content, $page) {
99  return (
100   $help_content = (is_admin() and $page == 'ec_help') ?
101    load_language('help.html', EVNTCATS_PATH, array('return' => true)) : false
102  ) ? $popup_help_content.$help_content : $popup_help_content;
103}
104
105//----------------------------------
106
107/**
108 *
109 * auto_log_user()
110 * the function uses the value of the argument "autolog" of the posted URL, as a code
111 * to know which username has to be logged in.
112 *
113 * @param no parameter
114 * @return no return value
115 */
116
117add_event_handler('init', 'auto_log_user');
118
119function auto_log_user() {
120  global $ec_lists;
121
122  $ec_ap  = NULL;
123  $ec_cat = NULL;
124  $ec_img = NULL;
125 
126  if (isset($_GET['autolog']) and (read_ec_conf('activated') == 1)) {
127    if (!is_a_guest()) {
128      $url = '';
129      foreach ($_GET as $item => $value) {
130        $url.= '&'.$item.'='.$value;
131      }
132      logout_user();
133      redirect(make_index_url().$url);
134    }
135    build_ec_lists();
136    foreach ($ec_lists['ec_table'] as $ec_entry) {
137      if ($code_exists = ($ec_entry['code'] == $_GET['autolog'])) break;
138    }
139    if ($code_exists) {
140      if (is_in($ec_entry['action'], 'ec_ok')) {
141        log_user($ec_entry['user_id'], false);
142        if (isset($_GET['ap'])) $ec_ap = $_GET['ap'];
143        if (isset($_GET['cat'])) $ec_cat = $_GET['cat'];
144        if (isset($_GET['img'])) $ec_img = $_GET['img'];
145        if ($ec_entry['forced'] == 'true') {
146          if (empty($ec_entry['arg1']) and !empty($ec_entry['arg2'])) {
147            $ec_ap = $ec_entry['arg2'];
148          }
149          elseif (!empty($ec_entry['arg1'])) {
150            $ec_cat = $ec_entry['arg1'];
151            if (!empty($ec_entry['arg2'])) $ec_img = $ec_entry['arg2'];
152          }
153        }
154        if (isset($ec_ap)) {
155          if (array_key_exists($ec_ap,$ec_lists['add_pages'])) {
156            redirect(
157             PHPWG_ROOT_PATH.'index.php?/additional_page/'.$ec_ap);
158          }
159        }
160        elseif (isset($ec_cat)) {
161          if (array_key_exists($ec_cat, $ec_lists['categories'])) {
162            if (isset($ec_img)) {
163              if (ec_image_exists($ec_cat, $ec_img)) {
164                redirect(PHPWG_ROOT_PATH.'picture.php?/'.$ec_img.'/category/'.$ec_cat);
165              }
166            }
167            redirect(PHPWG_ROOT_PATH.'index.php?/category/'.$ec_cat);
168          }
169        }
170        redirect(make_index_url());
171      }
172      else {
173        if (
174         $ec_entry['action'] == 'ec_nok' or
175         $ec_entry['action'] == 'ec_nok_ap_pb'
176        ) {
177          if ($ec_entry['action'] == 'ec_nok_ap_pb') access_denied();
178          $ec_ap = $ec_entry['arg2'];
179          if (array_key_exists($ec_ap, $ec_lists['add_pages'])) {
180            redirect(
181             PHPWG_ROOT_PATH.'index.php?/additional_page/'.$ec_ap);
182          }
183          access_denied();
184        }
185        else {
186          redirect(make_index_url());
187        }
188      }
189    }
190    else {
191      if (
192       read_ec_conf('unknown_code') == '2' and
193        array_key_exists(
194         read_ec_conf('unknown_code_ap_id'), $ec_lists['add_pages']
195        )
196       ) {
197        redirect(
198         PHPWG_ROOT_PATH.
199         'index.php?/additional_page/'.read_ec_conf('unknown_code_ap_id')
200        );
201      }
202      elseif (read_ec_conf('unknown_code') == '1' or
203       read_ec_conf('unknown_code') == '2') {
204        access_denied();
205      }
206      else {
207        redirect(make_index_url());
208      }
209    }
210  }
211}
212
213/**
214 *
215 * assign_perm_for_new_user()
216 * copies/paste groups+access+properties associations of previously connected
217 * username, to newly created username.
218 *
219 * @param no parameter
220 * @return no return value
221 */
222
223add_event_handler('register_user', 'assign_perm_for_new_user');
224
225function assign_perm_for_new_user($new_user) {
226  global $user;
227
228  if (!is_a_guest() and !is_admin()) if (
229    read_ec_conf('dup_allow') == '1' or (
230      read_ec_conf('dup_allow') == '2' and
231      dup_allowed($user['id'])
232    )
233  ) {
234    // User access
235    $result = pwg_query("
236      SELECT `cat_id`
237      FROM `".USER_ACCESS_TABLE."`
238      WHERE `user_id` = ".$user['id'].";
239    ");
240    $insert = array();
241    while ($row = mysql_fetch_assoc($result))
242     $insert[] = "(".$new_user['id'].",".$row['cat_id'].")";
243    if (!empty($insert)) pwg_query("
244      INSERT INTO `".USER_ACCESS_TABLE."`
245      VALUES ".implode(',', $insert).";
246    ");
247
248    // User groups
249    $result = pwg_query("
250      SELECT `group_id`
251      FROM `".USER_GROUP_TABLE."`
252      WHERE `user_id` = ".$user['id'].";
253    ");
254    $insert = array();
255    while ($row = mysql_fetch_assoc($result))
256     $insert[] = "(".$new_user['id'].",".$row['group_id'].")";
257    if (!empty($insert)) pwg_query("
258      INSERT INTO `".USER_GROUP_TABLE."`
259      VALUES ".implode(',', $insert).";
260    ");
261
262    // User infos
263    $result = pwg_query("
264      SELECT `level`
265      FROM `".USER_INFOS_TABLE."`
266      WHERE `user_id` = ".$user['id'].";
267    ");
268    $insert = array();
269    while ($row = mysql_fetch_assoc($result))
270     $insert[] = "(".$new_user['id'].",".$row['level'].")";
271    if (!empty($insert)) pwg_query("
272      UPDATE `".USER_INFOS_TABLE."`
273      SET `level` = ".$user['level']."
274      WHERE `user_id` = ".$new_user['id'].";
275    ");
276  }
277}
278
279/**
280 *
281 * duplicate_account_url()
282 * adds a link for duplicating the currently identified user in
283 * Identification block menu, in case the identifed user is granted to
284 * duplication. Displays also the connection link for generic users, if
285 * required in the configuration.
286 *
287 * @param no parameter
288 * @return no return value
289 */
290
291add_event_handler('blockmanager_apply', 'duplicate_account_url');
292
293function duplicate_account_url() {
294  global $lang, $template, $user;
295 
296  // Adds duplication link, if needed
297  if (!is_admin() and !is_a_guest()) if (
298    read_ec_conf('dup_allow') == '1' or (
299      read_ec_conf('dup_allow') == '2' and
300      dup_allowed($user['id'])
301    )
302  ) {
303    $template->assign('U_REGISTER', get_root_url().'register.php');
304    if (
305      read_ec_conf('duplic_display') == '1' or (
306        read_ec_conf('duplic_display') == '2' and
307        !is_generic()
308      )
309    ) {
310      $lang['Register'] = $lang['Duplicate'];
311      $lang['Create a new account'] =
312       $lang['Create a new account with same properties'];
313    }
314  }
315 
316  // Adds connection link, if needed
317  if (read_ec_conf('display_connection') == '1' and is_generic()) {
318    // Adds connection link
319    $template->assign(
320      'U_LOGIN',
321      get_root_url().'identification.php?redirect='.$_SERVER['REQUEST_URI']
322    );
323    // Removes "quick connection" fieldset (form)
324    $template->set_filenames(array(
325      'ec_no_quick_connect' =>
326      realpath(EVNTCATS_PATH.'ec_no_quick_connect.tpl')
327    ));
328    $begin = 'PLUGIN_INDEX_CONTENT_BEFORE';
329    $old_begin = $template->get_template_vars($begin);
330    $template->assign_var_from_handle($begin, 'ec_no_quick_connect');
331    $template->concat($begin, $old_begin);
332  }
333}
334
335add_event_handler(
336 'get_admin_plugin_menu_links',
337 array(&$obj, 'plugin_admin_menu')
338);
339set_plugin_data($plugin['id'], $obj);
340
341?>
Note: See TracBrowser for help on using the repository browser.