aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--admin/element_set_global.php43
-rw-r--r--admin/picture_modify.php37
-rw-r--r--install/db/11-database.php69
3 files changed, 133 insertions, 16 deletions
diff --git a/admin/element_set_global.php b/admin/element_set_global.php
index 7bea890ef..f2b69ca6b 100644
--- a/admin/element_set_global.php
+++ b/admin/element_set_global.php
@@ -136,32 +136,51 @@ SELECT image_id
array('image_id', 'category_id'),
$datas
);
-
+
+ check_links();
update_category(array($_POST['associate']));
}
}
if ($_POST['dissociate'] != 0 and count($collection) > 0)
{
- // physical links must not be broken, so we must first retrieve image_id
- // which create virtual links with the category to "dissociate from".
+ // First, we must identify which elements in the collection are really
+ // virtually associated with the category
$query = '
-SELECT id
- FROM '.IMAGE_CATEGORY_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON image_id = id
+SELECT image_id
+ FROM '.IMAGE_CATEGORY_TABLE.'
WHERE category_id = '.$_POST['dissociate'].'
- AND category_id != storage_category_id
- AND id IN ('.implode(',', $collection).')
+ AND image_id IN ('.implode(',', $collection).')
+ AND is_storage = \'false\'
;';
- $dissociables = array_from_query($query, 'id');
+ $associated_images = array_from_query($query, 'image_id');
+
+ // If the same element is associated to a source and its destinations,
+ // dissociating the element with the source implies dissociating the
+ // element fwith the destination.
+ $destinations_of = get_destinations($_POST['dissociate']);
+ $associated_categories = array_merge(
+ array($_POST['dissociate']),
+ $destinations_of[ $_POST['dissociate'] ]
+ );
+
+ // Eventually, deletion of associations
$query = '
-DELETE FROM '.IMAGE_CATEGORY_TABLE.'
- WHERE category_id = '.$_POST['dissociate'].'
- AND image_id IN ('.implode(',', $dissociables).')
+DELETE
+ FROM '.IMAGE_CATEGORY_TABLE.'
+ WHERE category_id IN ('.implode(',', $associated_categories).'
+ AND image_id IN ('.implode(',', $associated_images).')
';
pwg_query($query);
- update_category(array($_POST['dissociate']));
+ // check source/destination links. If category C has for sources A and
+ // B, if picture 1 was associated to A and B, the previous code lines
+ // have deleted the link between C and 1, while it should be kept due to
+ // B. Who said "complicated"?
+ check_links();
+
+ update_category($associated_categories);
}
$datas = array();
diff --git a/admin/picture_modify.php b/admin/picture_modify.php
index a4d5d8ac5..0840414a6 100644
--- a/admin/picture_modify.php
+++ b/admin/picture_modify.php
@@ -121,13 +121,25 @@ if (isset($_POST['associate'])
and count($_POST['cat_dissociated']) > 0)
{
$datas = array();
+
foreach ($_POST['cat_dissociated'] as $category_id)
{
- array_push($datas, array('image_id' => $_GET['image_id'],
- 'category_id' => $category_id));
+ array_push(
+ $datas,
+ array(
+ 'image_id' => $_GET['image_id'],
+ 'category_id' => $category_id
+ )
+ );
}
- mass_inserts(IMAGE_CATEGORY_TABLE, array('image_id', 'category_id'), $datas);
+
+ mass_inserts(
+ IMAGE_CATEGORY_TABLE,
+ array('image_id', 'category_id'),
+ $datas
+ );
+ check_links();
update_category($_POST['cat_dissociated']);
}
// dissociate the element from categories (but not from its storage category)
@@ -135,12 +147,29 @@ if (isset($_POST['dissociate'])
and isset($_POST['cat_associated'])
and count($_POST['cat_associated']) > 0)
{
+ $associated_categories = $_POST['cat_associated'];
+
+ // If the same element is associated to a source and its destinations,
+ // dissociating the element with the source implies dissociating the
+ // element fwith the destination.
+ $destinations_of = get_destinations($_POST['cat_associated']);
+ foreach ($destinations_of as $source => $destinations)
+ {
+ $associated_categories = array_merge(
+ $associated_categories,
+ $destinations
+ );
+ }
+
$query = '
DELETE FROM '.IMAGE_CATEGORY_TABLE.'
WHERE image_id = '.$_GET['image_id'].'
- AND category_id IN ('.implode(',',$_POST['cat_associated'] ).')
+ AND category_id IN ('.implode(',', $associated_categories).')
+ AND is_storage = \'false\'
';
pwg_query($query);
+
+ check_links();
update_category($_POST['cat_associated']);
}
// elect the element to represent the given categories
diff --git a/install/db/11-database.php b/install/db/11-database.php
new file mode 100644
index 000000000..bb2ea8421
--- /dev/null
+++ b/install/db/11-database.php
@@ -0,0 +1,69 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | PhpWebGallery - a PHP based picture gallery |
+// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
+// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
+// +-----------------------------------------------------------------------+
+// | branch : BSF (Best So Far)
+// | file : $RCSfile$
+// | last update : $Date: 2005-09-21 00:04:57 +0200 (mer, 21 sep 2005) $
+// | last modifier : $Author: plg $
+// | revision : $Revision: 870 $
+// +-----------------------------------------------------------------------+
+// | 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!');
+}
+
+$upgrade_description =
+ 'Table #categories_link created once again with correct prefix';
+
+// +-----------------------------------------------------------------------+
+// | Upgrade content |
+// +-----------------------------------------------------------------------+
+
+if (PREFIX_TABLE == 'phpwebgallery_')
+{
+ echo
+ "\n"
+ .'Table '.PREFIX_TABLE.'categories_link was already correctly created'
+ ."\n"
+ ;
+}
+else
+{
+ $query = '
+DROP TABLE phpwebgallery_categories_link;
+;';
+ pwg_query($query);
+
+ $query = "
+CREATE TABLE ".PREFIX_TABLE."categories_link (
+ source smallint(5) unsigned NOT NULL default '0',
+ destination smallint(5) unsigned NOT NULL default '0',
+ PRIMARY KEY (source,destination)
+) TYPE=MyISAM;";
+ pwg_query($query);
+
+ echo
+ "\n"
+ .'Table '.PREFIX_TABLE.'categories_link created'
+ ."\n"
+ ;
+}
+?>