Index: /extensions/community/admin.php
===================================================================
--- /extensions/community/admin.php	(revision 3673)
+++ /extensions/community/admin.php	(revision 3673)
@@ -0,0 +1,230 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery                                  |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2009      Pierrick LE GALL             http://piwigo.org |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+if( !defined("PHPWG_ROOT_PATH") )
+{
+  die ("Hacking attempt!");
+}
+
+include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
+load_language('plugin.lang', COMMUNITY_PATH);
+
+$conf['community_permission_levels'] = array(1,2);
+$admin_base_url = get_root_url().'admin.php?page=plugin&section=community%2Fadmin.php';
+
+// +-----------------------------------------------------------------------+
+// | Check Access and exit when user status is not ok                      |
+// +-----------------------------------------------------------------------+
+check_status(ACCESS_ADMINISTRATOR);
+
+// +-----------------------------------------------------------------------+
+// |                               functions                               |
+// +-----------------------------------------------------------------------+
+
+function get_permission_level_label($level)
+{
+  return '('.$level.') '.l10n( sprintf('Community level %d', $level) );
+}
+
+// +-----------------------------------------------------------------------+
+// |                            add permissions                            |
+// +-----------------------------------------------------------------------+
+
+if (isset($_POST['submit_add']) and !is_adviser())
+{
+  if (!is_numeric($_POST['user_options']))
+  {
+    array_push($page['errors'], 'invalid user');
+  }
+  if (!is_numeric($_POST['permission_level_options']))
+  {
+    array_push($page['errors'], 'invalid permission level');
+  }
+
+  if (count($page['errors']) == 0)
+  {
+    $query = '
+SELECT
+    '.$conf['user_fields']['username'].' AS username
+  FROM '.USERS_TABLE.'
+  WHERE '.$conf['user_fields']['id'].' = '.$_POST['user_options'].'
+;';
+    list($username) = mysql_fetch_row(pwg_query($query));
+    // remove any existing permission for this user
+    $query = '
+DELETE
+  FROM '.COMMUNITY_TABLE.'
+  WHERE user_id = '.$_POST['user_options'].'
+;';
+    pwg_query($query);
+
+    // creating the permission
+    $query = '
+INSERT INTO '.COMMUNITY_TABLE.'
+  (user_id, permission_level)
+  VALUES
+  ('.$_POST['user_options'].', '.$_POST['permission_level_options'].')
+;';
+    pwg_query($query);
+
+    array_push(
+      $page['infos'],
+      sprintf(
+        l10n('community permissions "%s" added/updated for "%s"'),
+        get_permission_level_label($_POST['permission_level_options']),
+        $username
+        )
+      );
+  }
+
+}
+
+// +-----------------------------------------------------------------------+
+// |                           remove permissions                          |
+// +-----------------------------------------------------------------------+
+
+if (isset($_GET['delete']) and !is_adviser())
+{
+  if (is_numeric($_GET['delete']))
+  {
+    $query = '
+SELECT
+    community.user_id,
+    community.permission_level,
+    u.'.$conf['user_fields']['username'].' AS username
+  FROM '.COMMUNITY_TABLE.' AS community
+    INNER JOIN '.USERS_TABLE.' AS u
+      ON u.'.$conf['user_fields']['id'].' = community.user_id
+  WHERE community.user_id = '.$_GET['delete'].'
+;';
+    $result = pwg_query($query);
+    if (mysql_num_rows($result) == 0)
+    {
+      array_push($page['errors'], 'this user has no community permission yet');
+    }
+
+    if (count($page['errors']) == 0)
+    {
+      list($user_id, $permission_level, $username) = mysql_fetch_row($result);
+
+      $query = '
+DELETE
+  FROM '.COMMUNITY_TABLE.'
+  WHERE user_id = '.$user_id.'
+;';
+      pwg_query($query);
+
+      array_push(
+        $page['infos'],
+        sprintf(
+          l10n('community permissions "%s" removed for "%s"'),
+          get_permission_level_label($permission_level),
+          $username
+        )
+      );
+    }
+  }
+}
+
+// +-----------------------------------------------------------------------+
+// |                             template init                             |
+// +-----------------------------------------------------------------------+
+
+$template->set_filenames(
+  array(
+    'plugin_admin_content' => dirname(__FILE__).'/admin.tpl'
+    )
+  );
+
+$template->assign(
+    array(
+      'F_ADD_ACTION'=> $admin_base_url,
+    )
+  );
+
+
+// user options
+$query = '
+SELECT
+    u.'.$conf['user_fields']['id'].' AS id,
+    u.'.$conf['user_fields']['username'].' AS username
+  FROM '.USERS_TABLE.' AS u
+    INNER JOIN '.USER_INFOS_TABLE.' AS ui
+      ON u.'.$conf['user_fields']['id'].' = ui.user_id
+  WHERE ui.status = "normal"
+  ORDER BY username
+;';
+$user_options = array();
+$result = pwg_query($query);
+while ($row = mysql_fetch_assoc($result))
+{
+  $user_options[ $row['id'] ] = $row['username'];
+}
+$template->assign(
+    array(
+      'user_options'=> $user_options,
+    )
+  );
+
+  
+// permission level options
+$permission_level_options = array();
+foreach ($conf['community_permission_levels'] as $level)
+{
+  $permission_level_options[$level] = get_permission_level_label($level);
+}
+$template->assign(
+    array(
+      'permission_level_options'=> $permission_level_options,
+    )
+  );
+
+// user with community permissions
+$query = '
+SELECT
+    community.user_id,
+    community.permission_level,
+    u.'.$conf['user_fields']['username'].' AS username
+  FROM '.COMMUNITY_TABLE.' AS community
+    INNER JOIN '.USERS_TABLE.' AS u
+      ON u.'.$conf['user_fields']['id'].' = community.user_id
+  ORDER BY username
+;';
+$result = pwg_query($query);
+
+while ($row = mysql_fetch_assoc($result))
+{
+  $template->append(
+    'users',
+    array(
+      'NAME' => $row['username'],
+      'PERMISSION_LEVEL' => get_permission_level_label($row['permission_level']),
+      'U_DELETE' => $admin_base_url.'&amp;delete='.$row['user_id']
+      )
+    );
+}
+
+// +-----------------------------------------------------------------------+
+// |                           sending html code                           |
+// +-----------------------------------------------------------------------+
+
+$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
+?>
Index: /extensions/community/admin.tpl
===================================================================
--- /extensions/community/admin.tpl	(revision 3673)
+++ /extensions/community/admin.tpl	(revision 3673)
@@ -0,0 +1,50 @@
+<div class="titrePage">
+  <h2>{'Community'|@translate}</h2>
+</div>
+
+<form method="post" name="add_permission" action="{$F_ADD_ACTION}" class="properties">
+  <fieldset>
+    <legend>{'Add permissions'|@translate}</legend>
+
+    <table>
+      <tr>
+        <td>{'User'|@translate}</td>
+        <td>
+          {html_options name="user_options" options=$user_options}
+        </td>
+      </tr>
+
+      <tr>
+        <td>{'Permission level'|@translate}</td>
+        <td>
+          {html_options name="permission_level_options" options=$permission_level_options}
+        </td>
+      </tr>
+    </table>
+    
+    <p>
+      <input class="submit" type="submit" name="submit_add" value="{'Add'|@translate}" {$TAG_INPUT_ENABLED}/>
+    </p>
+  </fieldset>
+</form>
+
+<table class="table2">
+  <tr class="throw">
+    <th>{'User'|@translate}</th>
+    <th>{'Permission level'|@translate}</th>
+    <th>{'Actions'|@translate}</th>
+  </tr>
+  {if not empty($users)}
+  {foreach from=$users item=user name=user_loop}
+  <tr class="{if $smarty.foreach.user_loop.index is odd}row1{else}row2{/if}">
+    <td>{$user.NAME}</td>
+    <td>{$user.PERMISSION_LEVEL}</td>
+    <td style="text-align:center;">
+      <a href="{$user.U_DELETE}" onclick="return confirm( document.getElementById('btn_delete').title + '\n\n' + '{'Are you sure?'|@translate|@escape:'javascript'}');">
+        <img src="{$ROOT_URL}{$themeconf.admin_icon_dir}/delete.png" class="button" style="border:none" id="btn_delete" alt="{'delete'|@translate}" title="{'delete'|@translate}" {$TAG_INPUT_ENABLED}/>
+      </a>
+    </td>
+  </tr>
+  {/foreach}
+  {/if}
+</table>
Index: /extensions/community/include/constants.php
===================================================================
--- /extensions/community/include/constants.php	(revision 3673)
+++ /extensions/community/include/constants.php	(revision 3673)
@@ -0,0 +1,4 @@
+<?php
+global $prefixeTable;
+define('COMMUNITY_TABLE', $prefixeTable.'community');
+?>
Index: /extensions/community/language/en_UK/plugin.lang.php
===================================================================
--- /extensions/community/language/en_UK/plugin.lang.php	(revision 3673)
+++ /extensions/community/language/en_UK/plugin.lang.php	(revision 3673)
@@ -0,0 +1,29 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery                                  |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2009      Pierrick LE GALL             http://piwigo.org |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+$lang['Community'] = 'Community';
+$lang['Add permissions'] = 'Add permissions';
+$lang['Permission level'] = 'Permission level';
+$lang['Community level 1'] = 'add photos';
+$lang['Community level 2'] = 'add photos + categories';
+$lang['community permissions "%s" added/updated for "%s"'] = 'community permissions "%s" added/updated for "%s"';
+$lang['community permissions "%s" removed for "%s"'] = 'community permissions "%s" removed for "%s"';
+?>
Index: /extensions/community/language/fr_FR/plugin.lang.php
===================================================================
--- /extensions/community/language/fr_FR/plugin.lang.php	(revision 3673)
+++ /extensions/community/language/fr_FR/plugin.lang.php	(revision 3673)
@@ -0,0 +1,29 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery                                  |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2009      Pierrick LE GALL             http://piwigo.org |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+$lang['Community'] = 'Communauté';
+$lang['Add permissions'] = 'Ajouter des permissions';
+$lang['Permission level'] = 'Niveau de permission';
+$lang['Community level 1'] = 'ajouter des photos';
+$lang['Community level 2'] = 'ajouter des photos + categories';
+$lang['community permissions "%s" added/updated for "%s"'] = 'permissions communautaires "%s" ajoutées ou mises à jour pour "%s"';
+$lang['community permissions "%s" removed for "%s"'] = 'permissions communautaires "%s" supprimées pour "%s"';
+?>
Index: /extensions/community/main.inc.php
===================================================================
--- /extensions/community/main.inc.php	(revision 3673)
+++ /extensions/community/main.inc.php	(revision 3673)
@@ -0,0 +1,91 @@
+<?php
+/*
+Plugin Name: Community
+Version: auto
+Description: Non admin users can add photos
+Plugin URI: http://piwigo.org/ext/extension_view.php?eid=303
+Author: plg
+Author URI: http://piwigo.wordpress.com
+*/
+
+if (!defined('PHPWG_ROOT_PATH'))
+{
+  die('Hacking attempt!');
+}
+
+define('COMMUNITY_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
+include_once (COMMUNITY_PATH.'/include/constants.php');
+
+/* Plugin admin */
+add_event_handler('get_admin_plugin_menu_links', 'community_admin_menu');
+
+function community_admin_menu($menu)
+{
+  array_push(
+    $menu,
+    array(
+      'NAME' => 'Community',
+      'URL'  => get_admin_plugin_menu_link(dirname(__FILE__).'/admin.php')
+      )
+    );
+
+  return $menu;
+}
+
+add_event_handler('ws_invoke_allowed', 'community_switch_user_to_admin', EVENT_HANDLER_PRIORITY_NEUTRAL, 3);
+
+function community_switch_user_to_admin($res, $methodName, $params)
+{
+  global $user;
+
+  $methods_of_permission_level[1] = array(
+    'pwg.categories.getList',
+    'pwg.tags.getAdminList',
+    'pwg.tags.add',
+    'pwg.images.exist',
+    'pwg.images.add',
+    'pwg.images.setInfo',
+    'pwg.images.addChunk',
+    );
+
+  // permission_level 2 has all methods of level 1 + others
+  $methods_of_permission_level[2] = array_merge(
+    $methods_of_permission_level[1],
+    array(
+      'pwg.categories.add',
+      'pwg.categories.setInfo',
+      )
+    );
+    
+  $query = '
+SELECT
+    permission_level
+  FROM '.COMMUNITY_TABLE.'
+  WHERE user_id = '.$user['id'].'
+;';
+  $result = pwg_query($query);
+  if (1 == mysql_num_rows($result))
+  {
+    list($permission_level) = mysql_fetch_row($result);
+
+    if (in_array($methodName, $methods_of_permission_level[$permission_level]))
+    {
+      $user['status'] = 'admin';
+    }
+  }
+
+  return $res;
+}
+
+add_event_handler('delete_user', 'community_delete_user');
+function community_delete_user($user_id)
+{
+  $query = '
+DELETE
+  FROM '.COMMUNITY_TABLE.'
+  WHERE user_id = '.$user_id.'
+;';
+  pwg_query($query);
+}
+
+?>
Index: /extensions/community/maintain.inc.php
===================================================================
--- /extensions/community/maintain.inc.php	(revision 3673)
+++ /extensions/community/maintain.inc.php	(revision 3673)
@@ -0,0 +1,27 @@
+<?php
+
+if (!defined("COMMUNITY_PATH"))
+{
+  define('COMMUNITY_PATH', PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)));
+}
+
+include_once (COMMUNITY_PATH.'/include/constants.php');
+
+function plugin_install()
+{
+  $query = "
+CREATE TABLE IF NOT EXISTS ".COMMUNITY_TABLE." (
+  user_id smallint(5) NOT NULL default '0',
+  permission_level tinyint NOT NULL default 1,
+  PRIMARY KEY  (user_id)
+)
+;";
+  pwg_query($query);
+}
+
+function plugin_uninstall()
+{
+  $query = 'DROP TABLE '.COMMUNITY_TABLE.';';
+  pwg_query($query);
+}
+?>
