Ignore:
Timestamp:
Feb 25, 2011, 12:22:52 AM (13 years ago)
Author:
plg
Message:

Rewritten version of Community plugin :

  • user upload (web form on gallery side)
  • precise permission manage (who, where, with moderation or not, ability to create sub-albums)
  • email notification to administrators when photos are uploaded

Requires Piwigo 2.2.0RC3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/community/admin.php

    r3673 r9372  
    33// | Piwigo - a PHP based picture gallery                                  |
    44// +-----------------------------------------------------------------------+
    5 // | Copyright(C) 2009      Pierrick LE GALL             http://piwigo.org |
     5// | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
     6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
     7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
    68// +-----------------------------------------------------------------------+
    79// | This program is free software; you can redistribute it and/or modify  |
     
    2628
    2729include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
     30include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
     31
    2832load_language('plugin.lang', COMMUNITY_PATH);
    2933
    30 $conf['community_permission_levels'] = array(1,2);
    31 $admin_base_url = get_root_url().'admin.php?page=plugin&section=community%2Fadmin.php';
     34define('COMMUNITY_BASE_URL', get_root_url().'admin.php?page=plugin-community');
    3235
    3336// +-----------------------------------------------------------------------+
    3437// | Check Access and exit when user status is not ok                      |
    3538// +-----------------------------------------------------------------------+
     39
    3640check_status(ACCESS_ADMINISTRATOR);
    3741
    3842// +-----------------------------------------------------------------------+
    39 // |                               functions                               |
     43// | Tabs                                                                  |
    4044// +-----------------------------------------------------------------------+
    4145
    42 function get_permission_level_label($level)
     46$tabs = array(
     47  array(
     48    'code' => 'permissions',
     49    'label' => l10n('Upload Permissions'),
     50    ),
     51  array(
     52    'code' => 'pendings',
     53    'label' => l10n('Pending Photos'),
     54    ),
     55  );
     56
     57$tab_codes = array_map(
     58  create_function('$a', 'return $a["code"];'),
     59  $tabs
     60  );
     61
     62if (isset($_GET['tab']) and in_array($_GET['tab'], $tab_codes))
    4363{
    44   return '('.$level.') '.l10n( sprintf('Community level %d', $level) );
     64  $page['tab'] = $_GET['tab'];
     65}
     66else
     67{
     68  $page['tab'] = $tabs[0]['code'];
    4569}
    4670
    47 // +-----------------------------------------------------------------------+
    48 // |                            add permissions                            |
    49 // +-----------------------------------------------------------------------+
    50 
    51 if (isset($_POST['submit_add']) and !is_adviser())
     71$tabsheet = new tabsheet();
     72foreach ($tabs as $tab)
    5273{
    53   if (!is_numeric($_POST['user_options']))
    54   {
    55     array_push($page['errors'], 'invalid user');
    56   }
    57   if (!is_numeric($_POST['permission_level_options']))
    58   {
    59     array_push($page['errors'], 'invalid permission level');
    60   }
    61 
    62   if (count($page['errors']) == 0)
    63   {
    64     $query = '
    65 SELECT
    66     '.$conf['user_fields']['username'].' AS username
    67   FROM '.USERS_TABLE.'
    68   WHERE '.$conf['user_fields']['id'].' = '.$_POST['user_options'].'
    69 ;';
    70     list($username) = mysql_fetch_row(pwg_query($query));
    71     // remove any existing permission for this user
    72     $query = '
    73 DELETE
    74   FROM '.COMMUNITY_TABLE.'
    75   WHERE user_id = '.$_POST['user_options'].'
    76 ;';
    77     pwg_query($query);
    78 
    79     // creating the permission
    80     $query = '
    81 INSERT INTO '.COMMUNITY_TABLE.'
    82   (user_id, permission_level)
    83   VALUES
    84   ('.$_POST['user_options'].', '.$_POST['permission_level_options'].')
    85 ;';
    86     pwg_query($query);
    87 
    88     array_push(
    89       $page['infos'],
    90       sprintf(
    91         l10n('community permissions "%s" added/updated for "%s"'),
    92         get_permission_level_label($_POST['permission_level_options']),
    93         $username
    94         )
    95       );
    96   }
    97 
     74  $tabsheet->add(
     75    $tab['code'],
     76    $tab['label'],
     77    COMMUNITY_BASE_URL.'-'.$tab['code']
     78    );
    9879}
    99 
    100 // +-----------------------------------------------------------------------+
    101 // |                           remove permissions                          |
    102 // +-----------------------------------------------------------------------+
    103 
    104 if (isset($_GET['delete']) and !is_adviser())
    105 {
    106   if (is_numeric($_GET['delete']))
    107   {
    108     $query = '
    109 SELECT
    110     community.user_id,
    111     community.permission_level,
    112     u.'.$conf['user_fields']['username'].' AS username
    113   FROM '.COMMUNITY_TABLE.' AS community
    114     INNER JOIN '.USERS_TABLE.' AS u
    115       ON u.'.$conf['user_fields']['id'].' = community.user_id
    116   WHERE community.user_id = '.$_GET['delete'].'
    117 ;';
    118     $result = pwg_query($query);
    119     if (mysql_num_rows($result) == 0)
    120     {
    121       array_push($page['errors'], 'this user has no community permission yet');
    122     }
    123 
    124     if (count($page['errors']) == 0)
    125     {
    126       list($user_id, $permission_level, $username) = mysql_fetch_row($result);
    127 
    128       $query = '
    129 DELETE
    130   FROM '.COMMUNITY_TABLE.'
    131   WHERE user_id = '.$user_id.'
    132 ;';
    133       pwg_query($query);
    134 
    135       array_push(
    136         $page['infos'],
    137         sprintf(
    138           l10n('community permissions "%s" removed for "%s"'),
    139           get_permission_level_label($permission_level),
    140           $username
    141         )
    142       );
    143     }
    144   }
    145 }
     80$tabsheet->select($page['tab']);
     81$tabsheet->assign();
    14682
    14783// +-----------------------------------------------------------------------+
     
    15187$template->set_filenames(
    15288  array(
    153     'plugin_admin_content' => dirname(__FILE__).'/admin.tpl'
     89    'photos_add' => 'photos_add_'.$page['tab'].'.tpl'
    15490    )
    15591  );
    15692
    157 $template->assign(
    158     array(
    159       'F_ADD_ACTION'=> $admin_base_url,
    160     )
    161   );
    162 
    163 
    164 // user options
    165 $query = '
    166 SELECT
    167     u.'.$conf['user_fields']['id'].' AS id,
    168     u.'.$conf['user_fields']['username'].' AS username
    169   FROM '.USERS_TABLE.' AS u
    170     INNER JOIN '.USER_INFOS_TABLE.' AS ui
    171       ON u.'.$conf['user_fields']['id'].' = ui.user_id
    172   WHERE ui.status = "normal"
    173   ORDER BY username
    174 ;';
    175 $user_options = array();
    176 $result = pwg_query($query);
    177 while ($row = mysql_fetch_assoc($result))
    178 {
    179   $user_options[ $row['id'] ] = $row['username'];
    180 }
    181 $template->assign(
    182     array(
    183       'user_options'=> $user_options,
    184     )
    185   );
    186 
    187  
    188 // permission level options
    189 $permission_level_options = array();
    190 foreach ($conf['community_permission_levels'] as $level)
    191 {
    192   $permission_level_options[$level] = get_permission_level_label($level);
    193 }
    194 $template->assign(
    195     array(
    196       'permission_level_options'=> $permission_level_options,
    197     )
    198   );
    199 
    200 // user with community permissions
    201 $query = '
    202 SELECT
    203     community.user_id,
    204     community.permission_level,
    205     u.'.$conf['user_fields']['username'].' AS username
    206   FROM '.COMMUNITY_TABLE.' AS community
    207     INNER JOIN '.USERS_TABLE.' AS u
    208       ON u.'.$conf['user_fields']['id'].' = community.user_id
    209   ORDER BY username
    210 ;';
    211 $result = pwg_query($query);
    212 
    213 while ($row = mysql_fetch_assoc($result))
    214 {
    215   $template->append(
    216     'users',
    217     array(
    218       'NAME' => $row['username'],
    219       'PERMISSION_LEVEL' => get_permission_level_label($row['permission_level']),
    220       'U_DELETE' => $admin_base_url.'&delete='.$row['user_id']
    221       )
    222     );
    223 }
    224 
    22593// +-----------------------------------------------------------------------+
    226 // |                           sending html code                           |
     94// |                             Load the tab                              |
    22795// +-----------------------------------------------------------------------+
    22896
    229 $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
     97include(COMMUNITY_PATH.'admin_'.$page['tab'].'.php');
    23098?>
Note: See TracChangeset for help on using the changeset viewer.