Index: /extensions/download_permissions/admin.php
===================================================================
--- /extensions/download_permissions/admin.php	(revision 29460)
+++ /extensions/download_permissions/admin.php	(revision 29460)
@@ -0,0 +1,12 @@
+<?php
+defined('DLPERMS_PATH') or die('Hacking attempt!');
+
+global $template, $page;
+load_language('plugin.lang', DLPERMS_PATH);
+
+$page['tab'] = (isset($_GET['tab'])) ? $_GET['tab'] : 'cat_options';
+
+// include page
+include(DLPERMS_PATH.$page['tab'].'.php');
+
+$template->assign_var_from_handle('ADMIN_CONTENT', 'download_permissions');
Index: /extensions/download_permissions/cat_options.php
===================================================================
--- /extensions/download_permissions/cat_options.php	(revision 29460)
+++ /extensions/download_permissions/cat_options.php	(revision 29460)
@@ -0,0 +1,136 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based photo gallery                                    |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2014 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | 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');
+include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
+
+// +-----------------------------------------------------------------------+
+// | Check Access and exit when user status is not ok                      |
+// +-----------------------------------------------------------------------+
+
+check_status(ACCESS_ADMINISTRATOR);
+
+// +-----------------------------------------------------------------------+
+// |                       modification registration                       |
+// +-----------------------------------------------------------------------+
+
+// print '<pre>';
+// print_r($_POST);
+// print '</pre>';
+if (isset($_POST['falsify'])
+    and isset($_POST['cat_true'])
+    and count($_POST['cat_true']) > 0)
+{
+  $query = '
+UPDATE '.CATEGORIES_TABLE.'
+  SET downloadable = \'false\'
+  WHERE id IN ('.implode(',', $_POST['cat_true']).')
+;';
+  pwg_query($query);
+}
+else if (isset($_POST['trueify'])
+         and isset($_POST['cat_false'])
+         and count($_POST['cat_false']) > 0)
+{
+  $query = '
+UPDATE '.CATEGORIES_TABLE.'
+  SET downloadable = \'true\'
+  WHERE id IN ('.implode(',', $_POST['cat_false']).')
+;';
+  pwg_query($query);
+}
+
+// +-----------------------------------------------------------------------+
+// |                             template init                             |
+// +-----------------------------------------------------------------------+
+
+$template->set_filenames(
+  array(
+    'double_select' => 'double_select.tpl',
+    'download_permissions' => realpath(DLPERMS_PATH . 'cat_options.tpl'),
+    )
+  );
+
+$template->assign(
+  array(
+    'F_ACTION' => '',
+   )
+ );
+
+// TabSheet
+$tabsheet = new tabsheet();
+$tabsheet->set_id('cat_options');
+$tabsheet->select('dlperms');
+$tabsheet->assign();
+
+// +-----------------------------------------------------------------------+
+// |                              form display                             |
+// +-----------------------------------------------------------------------+
+
+// for each section, categories in the multiselect field can be :
+//
+// - true : commentable for comment section
+// - false : un-commentable for comment section
+// - NA : (not applicable) for virtual categories
+//
+// for true and false status, we associates an array of category ids,
+// function display_select_categories will use the given CSS class for each
+// option
+$cats_true = array();
+$cats_false = array();
+
+$query_true = '
+SELECT id,name,uppercats,global_rank
+  FROM '.CATEGORIES_TABLE.'
+  WHERE downloadable = \'true\'
+;';
+
+$query_false = '
+SELECT id,name,uppercats,global_rank
+  FROM '.CATEGORIES_TABLE.'
+  WHERE downloadable = \'false\'
+;';
+
+$template->assign(
+  array(
+    'L_SECTION' => l10n('Authorize download on photos'),
+    'L_CAT_OPTIONS_TRUE' => l10n('Authorized'),
+    'L_CAT_OPTIONS_FALSE' => l10n('Forbidden'),
+    )
+  );
+
+display_select_cat_wrapper($query_true,array(),'category_option_true');
+display_select_cat_wrapper($query_false,array(),'category_option_false');
+
+// +-----------------------------------------------------------------------+
+// |                           sending html code                           |
+// +-----------------------------------------------------------------------+
+
+$template->assign_var_from_handle('DOUBLE_SELECT', 'double_select');
+// $template->assign_var_from_handle('ADMIN_CONTENT', 'cat_options');
+?>
Index: /extensions/download_permissions/cat_options.tpl
===================================================================
--- /extensions/download_permissions/cat_options.tpl	(revision 29460)
+++ /extensions/download_permissions/cat_options.tpl	(revision 29460)
@@ -0,0 +1,11 @@
+<div class="titrePage">
+  <h2>{'Properties'|@translate} {$TABSHEET_TITLE}</h2>
+</div>
+
+<form method="post" action="{$F_ACTION}" id="cat_options">
+  <fieldset>
+    <legend>{$L_SECTION}</legend>
+    {$DOUBLE_SELECT}
+  </fieldset>
+</form>
+
Index: /extensions/download_permissions/language/en_UK/description.txt
===================================================================
--- /extensions/download_permissions/language/en_UK/description.txt	(revision 29460)
+++ /extensions/download_permissions/language/en_UK/description.txt	(revision 29460)
@@ -0,0 +1,1 @@
+Permit photo download, filtered by album.
Index: /extensions/download_permissions/language/en_UK/plugin.lang.php
===================================================================
--- /extensions/download_permissions/language/en_UK/plugin.lang.php	(revision 29460)
+++ /extensions/download_permissions/language/en_UK/plugin.lang.php	(revision 29460)
@@ -0,0 +1,3 @@
+<?php
+$lang['Authorize download on photos'] = 'Authorize download on photos';
+?>
Index: /extensions/download_permissions/language/fr_FR/description.txt
===================================================================
--- /extensions/download_permissions/language/fr_FR/description.txt	(revision 29460)
+++ /extensions/download_permissions/language/fr_FR/description.txt	(revision 29460)
@@ -0,0 +1,1 @@
+Autoriser le téléchargement des photos, album par album.
Index: /extensions/download_permissions/language/fr_FR/plugin.lang.php
===================================================================
--- /extensions/download_permissions/language/fr_FR/plugin.lang.php	(revision 29460)
+++ /extensions/download_permissions/language/fr_FR/plugin.lang.php	(revision 29460)
@@ -0,0 +1,3 @@
+<?php
+$lang['Authorize download on photos'] = 'Autoriser le téléchargement sur les photos';
+?>
Index: /extensions/download_permissions/main.inc.php
===================================================================
--- /extensions/download_permissions/main.inc.php	(revision 29460)
+++ /extensions/download_permissions/main.inc.php	(revision 29460)
@@ -0,0 +1,105 @@
+<?php 
+/*
+Plugin Name: Download Permissions
+Version: auto
+Description: Manage download permissions, filter by album.
+Plugin URI: http://piwigo.org/ext/extension_view.php?eid=
+Author: plg
+Author URI: http://le-gall.net/pierrick
+*/
+
+defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
+
+global $prefixeTable;
+define('DLPERMS_PATH',    PHPWG_PLUGINS_PATH . 'download_permissions/');
+define('DLPERMS_ADMIN',   get_root_url() . 'admin.php?page=plugin-download_permissions');
+define('DLPERMS_VERSION', 'auto');
+
+add_event_handler('init', 'dlperms_init');
+add_event_handler('loc_begin_picture', 'dlperms_begin_picture');
+  
+if (defined('IN_ADMIN'))
+{
+  add_event_handler('tabsheet_before_select', 'dlperms_tab', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
+}
+
+/**
+ * initialization
+ */
+function dlperms_init()
+{
+  global $user;
+  
+  include_once(DLPERMS_PATH.'maintain.inc.php');
+  $maintain = new download_permissions_maintain('download_permissions');
+  $maintain->autoUpdate(DLPERMS_VERSION, 'install');
+
+  // overwrite $user['enabled_high'] depending on the current album
+  if ('action' == script_basename() and isset($_GET['id']) and is_numeric($_GET['id']))
+  {
+    if (!dlperms_is_photo_downloadable($_GET['id']))
+    {
+      $user['enabled_high'] = false;
+    }
+  }
+}
+
+/**
+ * tab on albums properties page
+ */
+function dlperms_tab($sheets, $id)
+{
+  if ($id == 'cat_options')
+  {
+    load_language('plugin.lang', DLPERMS_PATH);
+    
+    $sheets['dlperms'] = array(
+      'caption' => l10n('Download'),
+      'url' => DLPERMS_ADMIN.'-cat_options',
+      );
+  }
+  
+  return $sheets;
+}
+
+function dlperms_begin_picture()
+{
+  global $user, $page;
+
+  if (!dlperms_is_photo_downloadable($page['image_id']))
+  {
+    $user['enabled_high'] = false;
+  }
+}
+
+function dlperms_is_photo_downloadable($image_id)
+{
+  // the photo is downloadable if it belongs at least to one album that is
+  // downloadable
+
+  $query = '
+SELECT
+    COUNT(*)
+  FROM '.IMAGE_CATEGORY_TABLE.'
+    INNER JOIN '.CATEGORIES_TABLE.' ON category_id = id
+  WHERE image_id = '.$image_id.'
+    AND downloadable = \'true\'
+'.get_sql_condition_FandF
+  (
+    array
+      (
+        'forbidden_categories' => 'id',
+        'visible_categories' => 'id'
+      ),
+    'AND'
+  ).'
+;';
+  list($counter) = pwg_db_fetch_row(pwg_query($query));
+
+  if (0 == $counter)
+  {
+    return false;
+  }
+
+  return true;
+}
Index: /extensions/download_permissions/maintain.inc.php
===================================================================
--- /extensions/download_permissions/maintain.inc.php	(revision 29460)
+++ /extensions/download_permissions/maintain.inc.php	(revision 29460)
@@ -0,0 +1,42 @@
+<?php
+defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
+
+class download_permissions_maintain extends PluginMaintain
+{
+  private $installed = false;
+  
+  private $default_conf = array();
+
+  function install($plugin_version, &$errors=array())
+  {
+    global $conf, $prefixeTable;
+
+    // create categories.downloadable (true/false)
+    $result = pwg_query('SHOW COLUMNS FROM `'.CATEGORIES_TABLE.'` LIKE "downloadable";');
+    if (!pwg_db_num_rows($result))
+    {
+      pwg_query('ALTER TABLE `'.CATEGORIES_TABLE.'` ADD `downloadable` enum("true", "false") DEFAULT "true";');
+    }
+
+    $this->installed = true;
+  }
+
+  function activate($plugin_version, &$errors=array())
+  {
+    if (!$this->installed)
+    {
+      $this->install($plugin_version, $errors);
+    }
+  }
+
+  function deactivate()
+  {
+  }
+
+  function uninstall()
+  {
+    global $prefixeTable;
+    
+    pwg_query('ALTER TABLE '.CATEGORIES_TABLE.' DROP COLUMN downloadable;');
+  }
+}
