aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--admin/cat_modify.php154
-rw-r--r--admin/element_set_global.php77
-rw-r--r--admin/include/functions.php545
-rw-r--r--admin/include/functions_metadata.php4
-rw-r--r--admin/maintenance.php1
-rw-r--r--admin/picture_modify.php49
-rw-r--r--admin/rating.php6
-rw-r--r--admin/site_update.php28
-rw-r--r--include/constants.php1
-rw-r--r--install/db/20-database.php91
-rw-r--r--install/db/21-database.php52
-rw-r--r--install/phpwebgallery_structure.sql13
-rw-r--r--language/en_UK.iso-8859-1/admin.lang.php4
-rw-r--r--language/fr_FR.iso-8859-1/admin.lang.php4
-rw-r--r--template/yoga/admin/cat_modify.tpl61
15 files changed, 329 insertions, 761 deletions
diff --git a/admin/cat_modify.php b/admin/cat_modify.php
index cfff0d31f..4f4617224 100644
--- a/admin/cat_modify.php
+++ b/admin/cat_modify.php
@@ -114,104 +114,50 @@ else if (isset($_POST['submitAdd']))
array_push($page['infos'], $output_create['info']);
// Link the new category to the current category
- $query = '
-INSERT
- INTO '.CATEGORIES_LINK_TABLE.'
- (source, destination)
- VALUES
- ('.$_GET['cat_id'].', '.$output_create['id'].')
-;';
- pwg_query($query);
+ associate_categories_to_categories(
+ array($_GET['cat_id']),
+ array($output_create['id'])
+ );
- check_links(array($output_create['id']));
- update_category(array($output_create['id']));
- }
-}
-else if (isset($_POST['destination_trueify'])
- and isset($_POST['destination_false'])
- and count($_POST['destination_false']))
-{
- $datas = array();
-
- foreach ($_POST['destination_false'] as $category_id)
- {
+ // information
array_push(
- $datas,
- array(
- 'source' => $_GET['cat_id'],
- 'destination' => $category_id,
+ $page['infos'],
+ sprintf(
+ l10n('Category elements associated to the following categories: %s'),
+ '<ul><li>'
+ .get_cat_display_name_from_id($output_create['id'])
+ .'</li></ul>'
)
);
}
-
- mass_inserts(
- CATEGORIES_LINK_TABLE,
- array('source', 'destination'),
- $datas
- );
-
- check_links($_POST['destination_false']);
- update_category(
- $_POST['destination_false'],
- true // recursive update
- );
}
-else if (isset($_POST['destination_falsify'])
- and isset($_POST['destination_true'])
- and count($_POST['destination_true']))
+else if (isset($_POST['submitDestinations'])
+ and isset($_POST['destinations'])
+ and count($_POST['destinations']) > 0)
{
- foreach ($_POST['destination_true'] as $destination)
- {
- delete_sources($destination, array($_GET['cat_id']));
- }
-
- update_category(
- $_POST['destination_true'],
- true // recursive update
+ associate_categories_to_categories(
+ array($_GET['cat_id']),
+ $_POST['destinations']
);
-}
-else if (isset($_POST['source_trueify'])
- and isset($_POST['source_false'])
- and count($_POST['source_false']))
-{
- $datas = array();
-
- foreach ($_POST['source_false'] as $category_id)
+
+ $category_names = array();
+ foreach ($_POST['destinations'] as $category_id)
{
array_push(
- $datas,
- array(
- 'source' => $category_id,
- 'destination' => $_GET['cat_id'],
- )
+ $category_names,
+ get_cat_display_name_from_id($category_id)
);
}
-
- mass_inserts(
- CATEGORIES_LINK_TABLE,
- array('source', 'destination'),
- $datas
- );
- check_links(array($_GET['cat_id']));
- update_category(
- array($_GET['cat_id']),
- true // recursive update
- );
-}
-else if (isset($_POST['source_falsify'])
- and isset($_POST['source_true'])
- and count($_POST['source_true']))
-{
- delete_sources($_GET['cat_id'], $_POST['source_true']);
-
- update_category(
- array($_GET['cat_id']),
- true // recursive update
+ array_push(
+ $page['infos'],
+ sprintf(
+ l10n('Category elements associated to the following categories: %s'),
+ '<ul><li>'.implode('</li><li>', $category_names).'</li></ul>'
+ )
);
}
-
$query = '
SELECT *
FROM '.CATEGORIES_TABLE.'
@@ -381,7 +327,7 @@ SELECT tn_ext,path
}
}
-if (!$category['is_virtual']) //!empty($category['dir']))
+if (!$category['is_virtual'])
{
$template->assign_block_vars(
'storage',
@@ -469,47 +415,17 @@ display_select_cat_wrapper(
// destination categories
$query = '
-SELECT DISTINCT id, name, uppercats, global_rank
- FROM '.CATEGORIES_TABLE.'
- INNER JOIN '.CATEGORIES_LINK_TABLE.' ON destination = id
- WHERE source = '.$_GET['cat_id'].'
-;';
-display_select_cat_wrapper($query, array(), 'destination_option_true');
-
-// non destination categories
-$destinations = array_merge(
- array($_GET['cat_id']),
- array_from_query($query, 'id')
- );
-
-$query = '
-SELECT DISTINCT id, name, uppercats, global_rank
- FROM '.CATEGORIES_TABLE.'
- WHERE id NOT IN ('.implode(',', $destinations).')
-;';
-display_select_cat_wrapper($query, array(), 'destination_option_false');
-
-// source categories
-$query = '
-SELECT DISTINCT id, name, uppercats, global_rank
+SELECT id,name,uppercats,global_rank
FROM '.CATEGORIES_TABLE.'
- INNER JOIN '.CATEGORIES_LINK_TABLE.' ON source = id
- WHERE destination = '.$_GET['cat_id'].'
+ WHERE id != '.$category['id'].'
;';
-display_select_cat_wrapper($query, array(), 'source_option_true');
-// non source categories
-$sources = array_merge(
- array($_GET['cat_id']),
- array_from_query($query, 'id')
+display_select_cat_wrapper(
+ $query,
+ array(),
+ 'category_option_destination'
);
-$query = '
-SELECT DISTINCT id, name, uppercats, global_rank
- FROM '.CATEGORIES_TABLE.'
- WHERE id NOT IN ('.implode(',', $sources).')
-;';
-display_select_cat_wrapper($query, array(), 'source_option_false');
//----------------------------------------------------------- sending html code
$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
diff --git a/admin/element_set_global.php b/admin/element_set_global.php
index 22ea2df13..041cbe0cf 100644
--- a/admin/element_set_global.php
+++ b/admin/element_set_global.php
@@ -95,80 +95,35 @@ DELETE
if ($_POST['associate'] != 0 and count($collection) > 0)
{
- $datas = array();
-
- $query = '
-SELECT image_id
- FROM '.IMAGE_CATEGORY_TABLE.'
- WHERE category_id = '.$_POST['associate'].'
-;';
- $associated = array_from_query($query, 'image_id');
-
- $associable = array_diff($collection, $associated);
-
- if (count($associable) != 0)
- {
- foreach ($associable as $item)
- {
- array_push(
- $datas,
- array(
- 'category_id' => $_POST['associate'],
- 'image_id' => $item
- )
- );
- }
-
- mass_inserts(
- IMAGE_CATEGORY_TABLE,
- array('image_id', 'category_id'),
- $datas
- );
-
- check_links();
- update_category(array($_POST['associate']));
- }
+ associate_images_to_categories(
+ $collection,
+ array($_POST['associate'])
+ );
}
if ($_POST['dissociate'] != 0 and count($collection) > 0)
{
- // First, we must identify which elements in the collection are really
- // virtually associated with the category
+ // physical links must not be broken, so we must first retrieve image_id
+ // which create virtual links with the category to "dissociate from".
$query = '
-SELECT image_id
+SELECT id
FROM '.IMAGE_CATEGORY_TABLE.'
+ INNER JOIN '.IMAGES_TABLE.' ON image_id = id
WHERE category_id = '.$_POST['dissociate'].'
- AND image_id IN ('.implode(',', $collection).')
- AND is_storage = \'false\'
+ AND id IN ('.implode(',', $collection).')
+ AND category_id != storage_category_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']);
+ $dissociables = array_from_query($query, 'id');
- $associated_categories = array_merge(
- array($_POST['dissociate']),
- $destinations_of[ $_POST['dissociate'] ]
- );
-
- // Eventually, deletion of associations
$query = '
DELETE
FROM '.IMAGE_CATEGORY_TABLE.'
- WHERE category_id IN ('.implode(',', $associated_categories).'
- AND image_id IN ('.implode(',', $associated_images).')
+ WHERE category_id = '.$_POST['dissociate'].'
+ AND image_id IN ('.implode(',', $dissociables).')
';
pwg_query($query);
-
- // 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);
+
+ update_category($_POST['dissociate']);
}
$datas = array();
@@ -318,7 +273,7 @@ SELECT DISTINCT(category_id) AS id, c.name, uppercats, global_rank
WHERE ic.image_id IN ('.implode(',', $page['cat_elements_id']).')
AND ic.category_id = c.id
AND ic.image_id = i.id
- AND ic.is_storage = \'false\'
+ AND ic.category_id != i.storage_category_id
;';
display_select_cat_wrapper($query, array(), $blockname, true);
}
diff --git a/admin/include/functions.php b/admin/include/functions.php
index 3a8c6b506..f9435b1f1 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -152,22 +152,16 @@ function delete_categories($ids)
// destruction of all the related elements
$query = '
-SELECT image_id
- FROM '.IMAGE_CATEGORY_TABLE.'
- WHERE is_storage = \'true\'
- AND category_id IN ('.
- wordwrap(
- implode(', ', $ids),
- 80,
- "\n"
- ).
- ')
+SELECT id
+ FROM '.IMAGES_TABLE.'
+ WHERE storage_category_id IN (
+'.wordwrap(implode(', ', $ids), 80, "\n").')
;';
$result = pwg_query($query);
$element_ids = array();
while ($row = mysql_fetch_array($result))
{
- array_push($element_ids, $row['image_id']);
+ array_push($element_ids, $row['id']);
}
delete_elements($element_ids);
@@ -194,37 +188,6 @@ DELETE FROM '.GROUP_ACCESS_TABLE.'
;';
pwg_query($query);
- // source/destination links deletion
- $query = '
-SELECT destination, source
- FROM '.CATEGORIES_LINK_TABLE.'
- WHERE source IN ('.implode(',', $ids).')
- OR destination IN ('.implode(',', $ids).')
-;';
- $result = pwg_query($query);
-
- $sources_of = array();
-
- while ($row = mysql_fetch_array($result))
- {
- if (!isset($sources_of[ $row['destination'] ]))
- {
- $sources_of[ $row['destination'] ] = array();
- }
-
- array_push(
- $sources_of[ $row['destination'] ],
- $row['source']
- );
- }
-
- foreach ($sources_of as $destination => $sources)
- {
- delete_sources($destination, $sources);
- }
-
- update_category();
-
// destruction of the category
$query = '
DELETE FROM '.CATEGORIES_TABLE.'
@@ -441,15 +404,14 @@ SELECT id
SELECT category_id,
COUNT(image_id) AS nb_images,
MAX(date_available) AS date_last
- FROM '.IMAGES_TABLE.'
- INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id
+ FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id
WHERE category_id IN ('.wordwrap(implode(', ', $cat_ids), 80, "\n").')
GROUP BY category_id
;';
$result = pwg_query($query);
$datas = array();
$query_ids = array();
- while ($row = mysql_fetch_array($result))
+ while ( $row = mysql_fetch_array( $result ) )
{
array_push($query_ids, $row['category_id']);
@@ -466,23 +428,12 @@ SELECT category_id,
// is returned but the update must be done !
foreach (array_diff($cat_ids, $query_ids) as $id)
{
- array_push(
- $datas,
- array(
- 'id' => $id,
- 'nb_images' => 0,
- )
- );
+ array_push($datas, array('id' => $id, 'nb_images' => 0));
}
- mass_updates(
- CATEGORIES_TABLE,
- array(
- 'primary' => array('id'),
- 'update' => array('date_last', 'nb_images')
- ),
- $datas
- );
+ $fields = array('primary' => array('id'),
+ 'update' => array('date_last', 'nb_images'));
+ mass_updates(CATEGORIES_TABLE, $fields, $datas);
// representative pictures
if (count($cat_ids) > 0)
@@ -1357,42 +1308,19 @@ SELECT id, id_uppercat
*/
function update_path()
{
- $images_of = array();
-
$query = '
-SELECT category_id, image_id
- FROM '.IMAGE_CATEGORY_TABLE.'
- WHERE is_storage = \'true\'
+SELECT DISTINCT(storage_category_id)
+ FROM '.IMAGES_TABLE.'
;';
- $result = pwg_query($query);
- while ($row = mysql_fetch_array($result))
- {
- if (!isset($images_of[ $row['category_id'] ]))
- {
- $images_of[ $row['category_id'] ] = array();
- }
+ $cat_ids = array_from_query($query, 'storage_category_id');
+ $fulldirs = get_fulldirs($cat_ids);
- array_push(
- $images_of[ $row['category_id'] ],
- $row['image_id']
- );
- }
-
- $fulldirs = get_fulldirs(
- array_keys($images_of)
- );
-
- foreach ($images_of as $cat_id => $image_ids)
+ foreach ($cat_ids as $cat_id)
{
$query = '
UPDATE '.IMAGES_TABLE.'
SET path = CONCAT(\''.$fulldirs[$cat_id].'\',\'/\',file)
- WHERE id IN ('.
- wordwrap(
- implode(', ', $image_ids),
- 80,
- "\n").
- ')
+ WHERE storage_category_id = '.$cat_id.'
;';
pwg_query($query);
}
@@ -1613,371 +1541,6 @@ DELETE FROM '.$table.'
}
/**
- * Returns all destinations of a list of source categories. This function
- * solves transitivity.
- *
- * @param mixed array of category ids, empty for all categories
- */
-function get_destinations($categories = 'all')
-{
- $query = '
-SELECT source, destination
- FROM '.CATEGORIES_LINK_TABLE.'
-';
- $result = pwg_query($query);
-
- $destinations_of = array();
-
- while ($row = mysql_fetch_array($result))
- {
- if (!isset($destinations_of[ $row['source'] ]))
- {
- $destinations_of[ $row['source'] ] = array();
- }
-
- array_push(
- $destinations_of[ $row['source'] ],
- $row['destination']
- );
- }
-
- // transitivity resolution: if " => " means "source of", if A=>B=>C
- // implies A=>B and A=>C. So A has 2 destinations: B and C.
- do
- {
- // let's suppose we only need a single turn
- $need_new_turn = false;
-
- foreach ($destinations_of as $source => $destinations)
- {
- foreach ($destinations as $destination)
- {
- // does the current destination has destinations itself?
- if (isset($destinations_of[$destination]))
- {
- // are there destinations of current destination not already among
- // destinations of the current source? (advise: take a piece of
- // paper and draw a schema). The source itself must not be counted
- // as a destination, thus avoiding cyclic links.
- $missing_destinations = array_diff(
- $destinations_of[$destination],
- $destinations,
- array($source) // no cyclic link
- );
-
- if (count($missing_destinations) > 0)
- {
- $destinations_of[$source] = array_unique(
- array_merge(
- $destinations,
- $missing_destinations
- )
- );
-
- // a category has a least one new destination, we have to check
- // one more time that it doesn't generate more destinations
- $need_new_turn = true;
- }
- }
- }
- }
- } while ($need_new_turn);
-
- if (is_array($categories))
- {
- $filtered_destinations_of = array();
-
- // Even if there is no destinations for the requested categories, we
- // return empty arrays
- foreach ($categories as $category)
- {
- $filtered_destinations_of[$category] = array();
- }
-
- foreach ($destinations_of as $source => $destinations)
- {
- if (in_array($source, $categories))
- {
- $filtered_destinations_of[$source] = $destinations;
- }
- }
-
- return $filtered_destinations_of;
- }
- else
- {
- return $destinations_of;
- }
-}
-
-/**
- * Returns all sources of a list of destination categories. This function
- * solves transitivity.
- *
- * @param mixed array of category ids, empty for all categories
- */
-function get_sources($categories = 'all')
-{
- $destinations_of = get_destinations();
-
- $sources_of = array();
-
- foreach ($destinations_of as $source => $destinations)
- {
- foreach ($destinations as $destination)
- {
- if (!isset($sources_of[$destination]))
- {
- $sources_of[$destination] = array();
- }
-
- array_push($sources_of[$destination], $source);
- }
- }
-
- // eventually, filter
- if (is_array($categories))
- {
- $filtered_sources_of = array();
-
- // Even if there is no sources for the requested categories, we return
- // empty arrays
- foreach ($categories as $category)
- {
- $filtered_sources_of[$category] = array();
- }
-
- foreach ($sources_of as $destination => $sources)
- {
- if (in_array($destination, $categories))
- {
- $filtered_sources_of[$destination] = $sources;
- }
- }
-
- return $filtered_sources_of;
- }
- else
- {
- return $sources_of;
- }
-}
-
-/**
- * Checks categories links are respected for a given list of destinations.
- *
- * Checking categories links means that each destination must be associated
- * to the images of its sources.
- *
- * @param mixed source category ids
- */
-function check_links($destinations = 'all')
-{
- $sources_of = get_sources($destinations);
-
- if (empty($sources_of))
- {
- return true;
- }
-
- // we need to search images of all sources and destinations
- $images_of = array();
-
- foreach ($sources_of as $destination => $sources)
- {
- $images_of[$destination] = array();
-
- foreach ($sources as $source)
- {
- $images_of[$source] = array();
- }
- }
-
- $query = '
-SELECT image_id, category_id
- FROM '.IMAGE_CATEGORY_TABLE.'
- WHERE category_id IN ('.
- implode(',', array_keys($images_of)).
- ')
-;';
- $result = pwg_query($query);
-
- while ($row = mysql_fetch_array($result))
- {
- array_push(
- $images_of[ $row['category_id'] ],
- $row['image_id']
- );
- }
-
- $inserts = array();
-
- foreach ($sources_of as $destination => $sources)
- {
- // merge all images from the sources of this destination
- $sources_images = array();
-
- foreach ($sources as $source)
- {
- $sources_images = array_merge(
- $sources_images,
- $images_of[$source]
- );
- }
-
- $sources_images = array_unique($sources_images);
-
- // are there images among the sources that are not linked to the
- // destination?
- $missing_images = array_diff(
- $sources_images,
- $images_of[$destination]
- );
-
- // if we find missing images (missing links in reality), we prepare the
- // final mass_inserts
- if (count($missing_images) > 0)
- {
- foreach ($missing_images as $missing_image)
- {
- array_push(
- $inserts,
- array(
- 'category_id' => $destination,
- 'image_id' => $missing_image,
- )
- );
- }
- }
- }
-
- if (count($inserts) > 0)
- {
- mass_inserts(
- IMAGE_CATEGORY_TABLE,
- array_keys($inserts[0]),
- $inserts
- );
- }
-}
-
-/**
- * Based on categories links, delete image_category links on destinations.
- *
- * The rule is the following: if an image belong to the category and to the
- * source, we suppose it comes from the source. If the source/destination
- * link is broken, we delete the image/category link if the only origin of
- * the link was the broken categories link.
- *
- * Example: "=>" means "source of". Between brackets the associated images.
- *
- * A (1,2,9) => \
- * |=> C (1,2,3,4,5,9) => D (1,2,3,4,5,6,9)
- * B (3,4,9) => /
- *
- * In category C, we suppose (1,2) come from A, (3,4) from B, 9 from A or B
- * and 5 was manually added. In category D, 6 was added manually.
- *
- * If we break A=>C, C and D loose (1,2) but not 9 because it can come from
- * B. If we break C=>D, D loose (3,4,5,9) but not 6 because it was
- * associated manually to 9.
- *
- * Warning: only virtual links can be removed, physical links are protected.
- *
- * @param int destination
- * @param array sources
- */
-function delete_sources($destination, $sources)
-{
- // if no sources to unlink, we stop with OK status
- if (count($sources) == 0)
- {
- return true;
- }
-
- $query = '
-DELETE
- FROM '.CATEGORIES_LINK_TABLE.'
- WHERE destination = '.$destination.'
- AND source IN ('.implode(',', $sources).')
-;';
- pwg_query($query);
-
- // The strategy is the following:
- //
- // * first we brutally delete the image/category associations on
- // destinations categories for all images belonging to sources.
- //
- // * then we check_links on destinations to rebuild missing image/category
- // associations.
-
- // what are the images associated to the sources to unlink
- $query = '
-SELECT image_id
- FROM '.IMAGE_CATEGORY_TABLE.'
- WHERE category_id IN ('.
- implode(',', $sources).
- ')
-;';
- $sources_images = array_unique(
- array_from_query($query, 'image_id')
- );
-
- if (count($sources_images) == 0)
- {
- return true;
- }
-
- // retrieve all direct and indirect destinations of the current
- // destination
- $destinations_of = get_destinations(array($destination));
-
- $destinations = array_merge(
- array($destination),
- $destinations_of[$destination]
- );
-
- // unlink sources images from destinations
- $query = '
-DELETE
- FROM '.IMAGE_CATEGORY_TABLE.'
- WHERE category_id IN ('.implode(',', $destinations).')
- AND image_id IN ('.implode(',', $sources_images).')
- AND is_storage = \'false\'
-;';
- pwg_query($query);
-
- // if the representative thumbnail of destinations was a picture from
- // $sources_images, we request a new random representant
- $query = '
-SELECT id, representative_picture_id
- FROM '.CATEGORIES_TABLE.'
- WHERE id IN ('.implode(',', $destinations).')
-;';
- $result = pwg_query($query);
-
- $request_random = array();
-
- while ($row = mysql_fetch_array($result))
- {
- if (isset($row['representative_picture_id']))
- {
- if (in_array($row['representative_picture_id'], $sources_images))
- {
- array_push($request_random, $row['id']);
- }
- }
- }
-
- set_random_representant($request_random);
-
- // eventually, we check_links to rebuild missing associations
- check_links($destinations);
-
- return true;
-}
-
-/**
* create a virtual category
*
* @param string category name
@@ -2299,4 +1862,78 @@ function do_maintenance_all_tables()
pwg_query($query);
}
+
+/**
+ * Associate a list of images to a list of categories.
+ *
+ * The function will not duplicate links
+ *
+ * @param array images
+ * @param array categories
+ * @return void
+ */
+function associate_images_to_categories($images, $categories)
+{
+ if (count($images) == 0
+ or count($categories) == 0)
+ {
+ return false;
+ }
+
+ $query = '
+DELETE
+ FROM '.IMAGE_CATEGORY_TABLE.'
+ WHERE image_id IN ('.implode(',', $images).')
+ AND category_id IN ('.implode(',', $categories).')
+;';
+ pwg_query($query);
+
+ $inserts = array();
+ foreach ($categories as $category_id)
+ {
+ foreach ($images as $image_id)
+ {
+ array_push(
+ $inserts,
+ array(
+ 'image_id' => $image_id,
+ 'category_id' => $category_id,
+ )
+ );
+ }
+ }
+
+ mass_inserts(
+ IMAGE_CATEGORY_TABLE,
+ array_keys($inserts[0]),
+ $inserts
+ );
+
+ update_category($categories);
+}
+
+/**
+ * Associate images associated to a list of source categories to a list of
+ * destination categories.
+ *
+ * @param array sources
+ * @param array destinations
+ * @return void
+ */
+function associate_categories_to_categories($sources, $destinations)
+{
+ if (count($sources) == 0)
+ {
+ return false;
+ }
+
+ $query = '
+SELECT image_id
+ FROM '.IMAGE_CATEGORY_TABLE.'
+ WHERE category_id IN ('.implode(',', $sources).')
+;';
+ $images = array_from_query($query, 'image_id');
+
+ associate_images_to_categories($images, $destinations);
+}
?>
diff --git a/admin/include/functions_metadata.php b/admin/include/functions_metadata.php
index 21897c2cd..d4324a763 100644
--- a/admin/include/functions_metadata.php
+++ b/admin/include/functions_metadata.php
@@ -246,9 +246,7 @@ SELECT id
$query = '
SELECT id, path
FROM '.IMAGES_TABLE.'
- INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id
- WHERE is_storage = \'true\'
- AND category_id IN ('.implode(',', $cat_ids).')';
+ WHERE storage_category_id IN ('.implode(',', $cat_ids).')';
if ($only_new)
{
$query.= '
diff --git a/admin/maintenance.php b/admin/maintenance.php
index de6c2a4a1..2fa60696c 100644
--- a/admin/maintenance.php
+++ b/admin/maintenance.php
@@ -47,7 +47,6 @@ switch ($action)
{
case 'categories' :
{
- check_links();
update_uppercats();
update_category('all');
ordering();
diff --git a/admin/picture_modify.php b/admin/picture_modify.php
index 83bf09a23..ac7310ddd 100644
--- a/admin/picture_modify.php
+++ b/admin/picture_modify.php
@@ -121,56 +121,23 @@ if (isset($_POST['associate'])
and isset($_POST['cat_dissociated'])
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
- )
- );
- }
-
- mass_inserts(
- IMAGE_CATEGORY_TABLE,
- array('image_id', 'category_id'),
- $datas
+ associate_images_to_categories(
+ array($_GET['image_id']),
+ $_POST['cat_dissociated']
);
-
- check_links();
- update_category($_POST['cat_dissociated']);
}
// dissociate the element from categories (but not from its storage category)
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(',', $associated_categories).')
- AND is_storage = \'false\'
+ AND category_id IN ('.implode(',', $_POST['cat_associated']).')
';
pwg_query($query);
-
- check_links();
+
update_category($_POST['cat_associated']);
}
// elect the element to represent the given categories
@@ -201,13 +168,11 @@ if (isset($_POST['dismiss'])
$query = '
SELECT *
FROM '.IMAGES_TABLE.'
- INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id
WHERE id = '.$_GET['image_id'].'
- AND is_storage = \'true\'
;';
$row = mysql_fetch_array(pwg_query($query));
-$storage_category_id = $row['category_id'];
+$storage_category_id = $row['storage_category_id'];
$image_file = $row['file'];
// tags
@@ -396,7 +361,7 @@ SELECT id,name,uppercats,global_rank
FROM '.CATEGORIES_TABLE.'
INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id
WHERE image_id = '.$_GET['image_id'].'
- AND is_storage = \'false\'
+ AND id != '.$storage_category_id.'
;';
display_select_cat_wrapper($query, array(), 'associated_option');
diff --git a/admin/rating.php b/admin/rating.php
index 76b4aa865..86f95205a 100644
--- a/admin/rating.php
+++ b/admin/rating.php
@@ -182,16 +182,14 @@ SELECT i.id,
i.file,
i.tn_ext,
i.average_rate,
+ i.storage_category_id,
MAX(r.date) AS recently_rated,
COUNT(r.rate) AS nb_rates,
SUM(r.rate) AS sum_rates,
- ROUND(STD(r.rate),2) AS std_rates,
- ic.category_id AS storage_category_id
+ ROUND(STD(r.rate),2) AS std_rates
FROM '.RATE_TABLE.' AS r
LEFT JOIN '.IMAGES_TABLE.' AS i ON r.element_id = i.id
- INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.image_id = i.id
WHERE 1 = 1 ' . $display_filter . '
- AND ic.is_storage = \'true\'
GROUP BY r.element_id
ORDER BY ' . $available_order_by[$order_by_index][1] .'
LIMIT '.$start.','.$elements_per_page.'
diff --git a/admin/site_update.php b/admin/site_update.php
index c7c31106c..3562046ae 100644
--- a/admin/site_update.php
+++ b/admin/site_update.php
@@ -368,15 +368,12 @@ if (isset($_POST['submit']) and $_POST['sync'] == 'files'
$query = '
SELECT id, path
FROM '.IMAGES_TABLE.'
- INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id
- WHERE is_storage = \'true\'
- AND category_id IN ('.
- wordwrap(
+ WHERE storage_category_id IN ('
+ .wordwrap(
implode(', ', $cat_ids),
80,
"\n"
- ).
- ')
+ ).')
;';
$result = pwg_query($query);
while ($row = mysql_fetch_array($result))
@@ -458,6 +455,7 @@ SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id
? $fs[$path]['has_high']
: null,
'path' => $path,
+ 'storage_category_id' => $db_fulldirs[$dirname],
);
array_push(
@@ -469,8 +467,7 @@ SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id
$insert_links,
array(
'image_id' => $insert{'id'},
- 'category_id' => $db_fulldirs[$dirname],
- 'is_storage' => 'true',
+ 'category_id' => $insert['storage_category_id'],
)
);
array_push(
@@ -508,6 +505,7 @@ SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id
'representative_ext' => isset($fs[$path]['representative_ext'])
? $fs[$path]['representative_ext']
: null,
+ 'storage_category_id' => $db_fulldirs[$dirname],
);
array_push(
@@ -519,8 +517,7 @@ SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id
$insert_links,
array(
'image_id' => $insert{'id'},
- 'category_id' => $db_fulldirs[$dirname],
- 'is_storage' => 'true',
+ 'category_id' => $insert['storage_category_id'],
)
);
@@ -552,7 +549,7 @@ SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id
mass_inserts(
IMAGE_CATEGORY_TABLE,
array(
- 'image_id','category_id', 'is_storage',
+ 'image_id','category_id',
),
$insert_links
);
@@ -609,9 +606,7 @@ SELECT id,file,storage_category_id,infos
$query = '
SELECT id
FROM '.IMAGES_TABLE.'
- INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id
- WHERE is_storage = \'true\'
- AND category_id = '.$row['storage_category_id'].'
+ WHERE storage_category_id = '.$row['storage_category_id'].'
AND file = \''.$row['file'].'\'
;';
list($data['id']) = mysql_fetch_array(pwg_query($query));
@@ -659,11 +654,6 @@ if (isset($_POST['submit'])
if (!$simulate)
{
$start = get_moment();
- check_links('all');
- echo '<!-- check_links(all) : ';
- echo get_elapsed_time($start,get_moment());
- echo ' -->'."\n";
- $start = get_moment();
update_category('all');
echo '<!-- update_category(all) : ';
echo get_elapsed_time($start,get_moment());
diff --git a/include/constants.php b/include/constants.php
index 02b352cc3..73e46355f 100644
--- a/include/constants.php
+++ b/include/constants.php
@@ -69,7 +69,6 @@ define('CADDIE_TABLE', $prefixeTable.'caddie');
define('UPGRADE_TABLE', $prefixeTable.'upgrade');
define('SEARCH_TABLE', $prefixeTable.'search');
define('USER_MAIL_NOTIFICATION_TABLE', $prefixeTable.'user_mail_notification');
-define('CATEGORIES_LINK_TABLE', $prefixeTable.'categories_link');
define('TAGS_TABLE', $prefixeTable.'tags');
define('IMAGE_TAG_TABLE', $prefixeTable.'image_tag');
?>
diff --git a/install/db/20-database.php b/install/db/20-database.php
new file mode 100644
index 000000000..5dba69168
--- /dev/null
+++ b/install/db/20-database.php
@@ -0,0 +1,91 @@
+<?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 =
+ '#image_category.is_storage replaced by #image.storage_category_id';
+
+// +-----------------------------------------------------------------------+
+// | New column |
+// +-----------------------------------------------------------------------+
+
+$query = '
+ALTER TABLE '.PREFIX_TABLE.'images
+ ADD storage_category_id smallint(5) unsigned default NULL
+;';
+pwg_query($query);
+
+$query = '
+SELECT category_id, image_id
+ FROM '.PREFIX_TABLE.'image_category
+ WHERE is_storage = \'true\'
+;';
+$result = pwg_query($query);
+
+$datas = array();
+while ($row = mysql_fetch_array($result))
+{
+ array_push(
+ $datas,
+ array(
+ 'id' => $row['image_id'],
+ 'storage_category_id' => $row['category_id'],
+ )
+ );
+}
+mass_updates(
+ PREFIX_TABLE.'images',
+ array(
+ 'primary' => array('id'),
+ 'update' => array('storage_category_id'),
+ ),
+ $datas
+ );
+
+// +-----------------------------------------------------------------------+
+// | Delete obsolete column |
+// +-----------------------------------------------------------------------+
+
+$query = '
+ALTER TABLE '.PREFIX_TABLE.'image_category DROP COLUMN is_storage
+;';
+pwg_query($query);
+
+// +-----------------------------------------------------------------------+
+// | End notification |
+// +-----------------------------------------------------------------------+
+
+echo
+"\n"
+.'Column '.PREFIX_TABLE.'image_category'
+.' replaced by '.PREFIX_TABLE.'images.storage_category_id'."\n"
+;
+?>
diff --git a/install/db/21-database.php b/install/db/21-database.php
new file mode 100644
index 000000000..cfd08c692
--- /dev/null
+++ b/install/db/21-database.php
@@ -0,0 +1,52 @@
+<?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 = 'drop table #categories_link';
+
+// +-----------------------------------------------------------------------+
+// | New column |
+// +-----------------------------------------------------------------------+
+
+$query = '
+DROP TABLE '.PREFIX_TABLE.'categories_link
+;';
+pwg_query($query);
+
+// +-----------------------------------------------------------------------+
+// | End notification |
+// +-----------------------------------------------------------------------+
+
+echo
+"\n"
+.'Table '.PREFIX_TABLE.'categories_link dropped'."\n"
+;
+?>
diff --git a/install/phpwebgallery_structure.sql b/install/phpwebgallery_structure.sql
index db614f40d..253157e79 100644
--- a/install/phpwebgallery_structure.sql
+++ b/install/phpwebgallery_structure.sql
@@ -42,17 +42,6 @@ CREATE TABLE `phpwebgallery_categories` (
) TYPE=MyISAM;
--
--- Table structure for table `phpwebgallery_categories_link`
---
-
-DROP TABLE IF EXISTS `phpwebgallery_categories_link`;
-CREATE TABLE `phpwebgallery_categories_link` (
- `source` smallint(5) unsigned NOT NULL default '0',
- `destination` smallint(5) unsigned NOT NULL default '0',
- PRIMARY KEY (`source`,`destination`)
-) TYPE=MyISAM;
-
---
-- Table structure for table `phpwebgallery_comments`
--
@@ -138,7 +127,6 @@ DROP TABLE IF EXISTS `phpwebgallery_image_category`;
CREATE TABLE `phpwebgallery_image_category` (
`image_id` mediumint(8) unsigned NOT NULL default '0',
`category_id` smallint(5) unsigned NOT NULL default '0',
- `is_storage` enum('true','false') default 'false',
PRIMARY KEY (`image_id`,`category_id`),
KEY `image_category_i1` (`image_id`),
KEY `image_category_i2` (`category_id`)
@@ -178,6 +166,7 @@ CREATE TABLE `phpwebgallery_images` (
`average_rate` float(5,2) unsigned default NULL,
`has_high` enum('true') default NULL,
`path` varchar(255) NOT NULL default '',
+ `storage_category_id` smallint(5) unsigned default NULL,
PRIMARY KEY (`id`),
KEY `images_i2` (`date_available`),
KEY `images_i3` (`average_rate`),
diff --git a/language/en_UK.iso-8859-1/admin.lang.php b/language/en_UK.iso-8859-1/admin.lang.php
index 73cc386c2..47145569b 100644
--- a/language/en_UK.iso-8859-1/admin.lang.php
+++ b/language/en_UK.iso-8859-1/admin.lang.php
@@ -54,6 +54,7 @@ $lang['Caddie'] = 'Caddie';
$lang['Categories authorized thanks to group associations'] = 'Categories authorized thanks to group associations';
$lang['Categories manual order was saved'] = 'Categories manual order was saved';
$lang['Categories ordered alphanumerically'] = 'Categories ordered alphanumerically';
+$lang['Category elements associated to the following categories: %s'] = 'Category elements associated to the following categories: %s';
$lang['Check for upgrade failed for unknown reasons.'] = 'Check for upgrade failed for unknown reasons.';
$lang['Check for upgrade'] = 'Check for upgrade';
$lang['Comments for all'] = 'Comments for all';
@@ -90,6 +91,8 @@ $lang['History'] = 'History';
$lang['Informations'] = 'Informations';
$lang['Interface theme'] = 'Interface theme';
$lang['Language'] = 'Language';
+$lang['Link all category elements to a new category'] = 'Link all category elements to a new category';
+$lang['Link all category elements to some existing categories'] = 'Link all category elements to some existing categories';
$lang['Linked categories'] = 'Linked categories';
$lang['Lock gallery'] = 'Lock gallery';
$lang['Maintenance'] = 'Maintenance';
@@ -164,6 +167,7 @@ $lang['Validate'] = 'Validate';
$lang['Validation'] = 'Validation';
$lang['Virtual categories movement'] = 'Virtual categories movement';
$lang['Virtual categories to move'] = 'Virtual categories to move';
+$lang['Virtual category name'] = 'Virtual category name';
$lang['Webmaster cannot be deleted'] = 'Webmaster cannot be deleted';
$lang['Yes'] = 'Yes';
$lang['You are running on development sources, no check possible.'] = 'You are running on development sources, no check possible.';
diff --git a/language/fr_FR.iso-8859-1/admin.lang.php b/language/fr_FR.iso-8859-1/admin.lang.php
index 114f1b07f..3f32119ec 100644
--- a/language/fr_FR.iso-8859-1/admin.lang.php
+++ b/language/fr_FR.iso-8859-1/admin.lang.php
@@ -55,6 +55,7 @@ $lang['Caddie'] = 'Panier';
$lang['Categories authorized thanks to group associations'] = 'Catégories accessibles grâce à l\'appartenance aux groupes';
$lang['Categories manual order was saved'] = 'L\'ordre manuel des catégories a été sauvegardé';
$lang['Categories ordered alphanumerically'] = 'Catégories ordonnées alphabético-numériquement';
+$lang['Category elements associated to the following categories: %s'] = 'Les éléments de la catégorie ont été associés aux catégories suivantes : %s';
$lang['Check for upgrade failed for unknown reasons.'] = 'La vérification de la dernière version sur le serveur a échouée pour une raison inconnue.';
$lang['Check for upgrade'] = 'Dernière version ?';
$lang['Comments for all'] = 'Commentaires utilisateur pour tous';
@@ -91,6 +92,8 @@ $lang['History'] = 'Historique';
$lang['Informations'] = 'Informations';
$lang['Interface theme'] = 'Theme de l\'interface';
$lang['Language'] = 'Langue';
+$lang['Link all category elements to a new category'] = 'Associer tous les éléments de la catégorie à une nouvelle catégorie';
+$lang['Link all category elements to some existing categories'] = 'Associer tous les éléments de la catégorie à des catégories existantes';
$lang['Linked categories'] = 'Catégories associées';
$lang['Lock gallery'] = 'Verrouiller la galerie';
$lang['Maintenance'] = 'Maintenance';
@@ -165,6 +168,7 @@ $lang['Validate'] = 'Valider';
$lang['Validation'] = 'Validation';
$lang['Virtual categories movement'] = 'Déplacement de catégories virtuelles';
$lang['Virtual categories to move'] = 'Catégories virtuelles à déplacer';
+$lang['Virtual category name'] = 'Nom de la catégorie virtuelle';
$lang['Webmaster cannot be deleted'] = 'Le webmestre ne peut pas être supprimé';
$lang['Yes'] = 'Oui';
$lang['You are running on development sources, no check possible.'] = 'Vous travaillez avec les sources de développement, impossible de vérifier la dernière version.';
diff --git a/template/yoga/admin/cat_modify.tpl b/template/yoga/admin/cat_modify.tpl
index 8101e7ffa..3212d190e 100644
--- a/template/yoga/admin/cat_modify.tpl
+++ b/template/yoga/admin/cat_modify.tpl
@@ -140,16 +140,16 @@
<form action="{F_ACTION}" method="POST" id="links">
<fieldset>
- <legend>{lang:Create a destination category}</legend>
+ <legend>{lang:Link all category elements to a new category}</legend>
<table>
<tr>
- <td>{lang:virtual category name}</td>
+ <td>{lang:Virtual category name}</td>
<td><input type="text" name="virtual_name"></td>
</tr>
<tr>
- <td>{lang:parent category}</td>
+ <td>{lang:Parent category}</td>
<td>
<select class="categoryList" name="parent">
<!-- BEGIN category_option_parent -->
@@ -160,7 +160,7 @@
</tr>
</table>
- <p style="text-align:center;">
+ <p>
<input type="submit" value="{lang:Submit}" name="submitAdd" {TAG_INPUT_ENABLED}/>
<input type="reset" value="{lang:Reset}" name="reset" />
</p>
@@ -168,55 +168,26 @@
</fieldset>
<fieldset>
- <legend>{lang:Source/destination links}</legend>
+ <legend>{lang:Link all category elements to some existing categories}</legend>
- <table class="doubleSelect">
+ <table>
<tr>
+ <td>{lang:Categories}</td>
<td>
- <h3>{lang:Destination categories}</h3>
- <select class="categoryList" name="destination_true[]" multiple="multiple" size="30">
- <!-- BEGIN destination_option_true -->
- <option {destination_option_true.SELECTED} value="{destination_option_true.VALUE}">{destination_option_true.OPTION}</option>
- <!-- END destination_option_true -->
- </select>
- <p><input type="submit" value="&raquo;" name="destination_falsify" style="font-size:15px;" {TAG_INPUT_ENABLED}/></p>
- </td>
-
- <td>
- <h3>{lang:Non destination categories}</h3>
- <select class="categoryList" name="destination_false[]" multiple="multiple" size="30">
- <!-- BEGIN destination_option_false -->
- <option {destination_option_false.SELECTED} value="{destination_option_false.VALUE}">{destination_option_false.OPTION}</option>
- <!-- END destination_option_false -->
+ <select class="categoryList" name="destinations[]" multiple="multiple" size="5">
+ <!-- BEGIN category_option_destination -->
+ <option {category_option_destination.SELECTED} value="{category_option_destination.VALUE}">{category_option_destination.OPTION}</option>
+ <!-- END category_option_destination -->
</select>
- <p><input type="submit" value="&laquo;" name="destination_trueify" style="font-size:15px;" {TAG_INPUT_ENABLED}/></p>
</td>
</tr>
</table>
- <table class="doubleSelect">
- <tr>
- <td>
- <h3>{lang:Source categories}</h3>
- <select class="categoryList" name="source_true[]" multiple="multiple" size="30">
- <!-- BEGIN source_option_true -->
- <option {source_option_true.SELECTED} value="{source_option_true.VALUE}">{source_option_true.OPTION}</option>
- <!-- END source_option_true -->
- </select>
- <p><input type="submit" value="&raquo;" name="source_falsify" style="font-size:15px;" {TAG_INPUT_ENABLED}/></p>
- </td>
+ <p>
+ <input type="submit" value="{lang:Submit}" name="submitDestinations" {TAG_INPUT_ENABLED}/>
+ <input type="reset" value="{lang:Reset}" name="reset" />
+ </p>
- <td>
- <h3>{lang:Non source categories}</h3>
- <select class="categoryList" name="source_false[]" multiple="multiple" size="30">
- <!-- BEGIN source_option_false -->
- <option {source_option_false.SELECTED} value="{source_option_false.VALUE}">{source_option_false.OPTION}</option>
- <!-- END source_option_false -->
- </select>
- <p><input type="submit" value="&laquo;" name="source_trueify" style="font-size:15px;" {TAG_INPUT_ENABLED}/></p>
- </td>
- </tr>
- </table>
-
</fieldset>
+
</form>