aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--admin.php1
-rw-r--r--admin/cat_modify.php5
-rw-r--r--admin/cat_move.php117
-rw-r--r--admin/include/functions.php135
-rw-r--r--doc/ChangeLog5
-rw-r--r--language/en_UK.iso-8859-1/admin.lang.php6
-rw-r--r--language/fr_FR.iso-8859-1/admin.lang.php6
-rw-r--r--template/yoga/admin.tpl1
-rw-r--r--template/yoga/admin/cat_move.tpl40
9 files changed, 271 insertions, 45 deletions
diff --git a/admin.php b/admin.php
index 552be51e8..7b81cad91 100644
--- a/admin.php
+++ b/admin.php
@@ -73,6 +73,7 @@ $template->assign_vars(
'U_CONFIG_COMMENTS'=>add_session_id($conf_link.'comments' ),
'U_CONFIG_DISPLAY'=>add_session_id($conf_link.'default' ),
'U_CATEGORIES'=>add_session_id($link_start.'cat_list' ),
+ 'U_MOVE'=>add_session_id($link_start.'cat_move' ),
'U_CAT_UPLOAD'=>add_session_id($opt_link.'upload'),
'U_CAT_COMMENTS'=>add_session_id($opt_link.'comments'),
'U_CAT_VISIBLE'=>add_session_id($opt_link.'visible'),
diff --git a/admin/cat_modify.php b/admin/cat_modify.php
index 18aff772f..0d82c13d4 100644
--- a/admin/cat_modify.php
+++ b/admin/cat_modify.php
@@ -67,7 +67,10 @@ if (isset($_POST['submit']))
if (isset($_POST['parent']))
{
- move_category($_GET['cat_id'], $_POST['parent']);
+ move_categories(
+ array($_GET['cat_id']),
+ $_POST['parent']
+ );
}
array_push($page['infos'], $lang['editcat_confirm']);
diff --git a/admin/cat_move.php b/admin/cat_move.php
new file mode 100644
index 000000000..7760b6494
--- /dev/null
+++ b/admin/cat_move.php
@@ -0,0 +1,117 @@
+<?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$
+// | last modifier : $Author$
+// | revision : $Revision$
+// +-----------------------------------------------------------------------+
+// | 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/isadmin.inc.php');
+
+// +-----------------------------------------------------------------------+
+// | functions |
+// +-----------------------------------------------------------------------+
+
+
+// +-----------------------------------------------------------------------+
+// | categories movement |
+// +-----------------------------------------------------------------------+
+
+if (isset($_POST['submit']))
+{
+ if (count($_POST['selection']) > 0)
+ {
+ // TODO: tests
+ move_categories($_POST['selection'], $_POST['parent']);
+ }
+ else
+ {
+ array_push(
+ $page['errors'],
+ l10n('Select at least one category')
+ );
+ }
+}
+
+// +-----------------------------------------------------------------------+
+// | template initialization |
+// +-----------------------------------------------------------------------+
+
+$template->set_filenames(
+ array(
+ 'cat_move' => 'admin/cat_move.tpl'
+ )
+ );
+
+$template->assign_vars(
+ array(
+ 'F_ACTION' => add_session_id(PHPWG_ROOT_PATH.'admin.php?page=cat_move'),
+ )
+ );
+
+// +-----------------------------------------------------------------------+
+// | Categories display |
+// +-----------------------------------------------------------------------+
+
+$query = '
+SELECT id,name,uppercats,global_rank
+ FROM '.CATEGORIES_TABLE.'
+ WHERE dir IS NULL
+;';
+
+display_select_cat_wrapper(
+ $query,
+ array(),
+ 'category_option_selection'
+ );
+
+$blockname = 'category_option_parent';
+
+$template->assign_block_vars(
+ $blockname,
+ array(
+ 'VALUE'=> 0,
+ 'OPTION' => '------------'
+ )
+ );
+
+$query = '
+SELECT id,name,uppercats,global_rank
+ FROM '.CATEGORIES_TABLE.'
+;';
+
+display_select_cat_wrapper(
+ $query,
+ array(),
+ $blockname
+ );
+
+// +-----------------------------------------------------------------------+
+// | sending html code |
+// +-----------------------------------------------------------------------+
+
+$template->assign_var_from_handle('ADMIN_CONTENT', 'cat_move');
+?>
diff --git a/admin/include/functions.php b/admin/include/functions.php
index 2b7abb094..56c1bf761 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -1337,36 +1337,78 @@ SELECT element_id,
}
/**
- * change the parent category of the given category. The category is
+ * change the parent category of the given categories. The categories are
* supposed virtual.
*
- * @param int category identifier
+ * @param array category identifiers
* @param int parent category identifier
* @return void
*/
-function move_category($category_id, $new_parent = -1)
+function move_categories($category_ids, $new_parent = -1)
{
- // verifies if the move is necessary
- $query = '
-SELECT id_uppercat, status
- FROM '.CATEGORIES_TABLE.'
- WHERE id = '.$category_id.'
-;';
- list($old_parent, $status) = mysql_fetch_row(pwg_query($query));
+ global $page;
+
+ if (count($category_ids) == 0)
+ {
+ return;
+ }
- $old_parent = empty($old_parent) ? 'NULL' : $old_parent;
$new_parent = $new_parent < 1 ? 'NULL' : $new_parent;
- if ($new_parent == $old_parent)
+ $categories = array();
+
+ $query = '
+SELECT id, id_uppercat, status, uppercats
+ FROM '.CATEGORIES_TABLE.'
+ WHERE id IN ('.implode(',', $category_ids).')
+;';
+ $result = pwg_query($query);
+ while ($row = mysql_fetch_array($result))
{
- // no need to move !
- return;
+ $categories[$row['id']] =
+ array(
+ 'parent' => empty($row['id_uppercat']) ? 'NULL' : $row['id_uppercat'],
+ 'status' => $row['status'],
+ 'uppercats' => $row['uppercats']
+ );
}
+ // is the movement possible? The movement is impossible if you try to move
+ // a category in a sub-category or itself
+ if ('NULL' != $new_parent)
+ {
+ $query = '
+SELECT uppercats
+ FROM '.CATEGORIES_TABLE.'
+ WHERE id = '.$new_parent.'
+;';
+ list($new_parent_uppercats) = mysql_fetch_row(pwg_query($query));
+
+ foreach ($categories as $category)
+ {
+ // technically, you can't move a category with uppercats 12,125,13,14
+ // into a new parent category with uppercats 12,125,13,14,24
+ if (preg_match('/^'.$category['uppercats'].'/', $new_parent_uppercats))
+ {
+ array_push(
+ $page['errors'],
+ l10n('You cannot move a category in its own sub category')
+ );
+ return;
+ }
+ }
+ }
+
+ $tables =
+ array(
+ USER_ACCESS_TABLE => 'user_id',
+ GROUP_ACCESS_TABLE => 'group_id'
+ );
+
$query = '
UPDATE '.CATEGORIES_TABLE.'
SET id_uppercat = '.$new_parent.'
- WHERE id = '.$category_id.'
+ WHERE id IN ('.implode(',', $category_ids).')
;';
pwg_query($query);
@@ -1391,54 +1433,59 @@ SELECT status
if ('private' == $parent_status)
{
- switch ($status)
+ foreach ($categories as $cat_id => $category)
{
- case 'public' :
- {
- set_cat_status(array($category_id), 'private');
- break;
- }
- case 'private' :
+ switch ($category['status'])
{
- $subcats = get_subcat_ids(array($category_id));
-
- $tables =
- array(
- USER_ACCESS_TABLE => 'user_id',
- GROUP_ACCESS_TABLE => 'group_id'
- );
-
- foreach ($tables as $table => $field)
+ case 'public' :
{
- $query = '
+ set_cat_status(array($cat_id), 'private');
+ break;
+ }
+ case 'private' :
+ {
+ $subcats = get_subcat_ids(array($cat_id));
+
+ foreach ($tables as $table => $field)
+ {
+ $query = '
SELECT '.$field.'
FROM '.$table.'
- WHERE category_id = '.$category_id.'
+ WHERE cat_id = '.$cat_id.'
;';
- $category_access = array_from_query($query, $field);
+ $category_access = array_from_query($query, $field);
- $query = '
+ $query = '
SELECT '.$field.'
FROM '.$table.'
- WHERE category_id = '.$new_parent.'
+ WHERE cat_id = '.$new_parent.'
;';
- $parent_access = array_from_query($query, $field);
+ $parent_access = array_from_query($query, $field);
- $to_delete = array_diff($parent_access, $category_access);
+ $to_delete = array_diff($parent_access, $category_access);
- if (count($to_delete) > 0)
- {
- $query = '
+ if (count($to_delete) > 0)
+ {
+ $query = '
DELETE FROM '.$table.'
WHERE '.$field.' IN ('.implode(',', $to_delete).')
- AND category_id IN ('.implode(',', $subcats).')
+ AND cat_id IN ('.implode(',', $subcats).')
;';
- pwg_query($query);
+ pwg_query($query);
+ }
}
+ break;
}
- break;
}
}
}
+
+ array_push(
+ $page['infos'],
+ sprintf(
+ l10n('%d categories moved'),
+ count($categories)
+ )
+ );
}
?>
diff --git a/doc/ChangeLog b/doc/ChangeLog
index f07cfe18e..c0d8133c8 100644
--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -1,3 +1,8 @@
+2005-10-08 Pierrick LE GALL
+
+ * new: mass virtual categories movement manager in
+ Administration>Categories>Move screen.
+
2005-10-05 Pierrick LE GALL
* bug 160 fixed: (part one of the bug) hard coded column name of
diff --git a/language/en_UK.iso-8859-1/admin.lang.php b/language/en_UK.iso-8859-1/admin.lang.php
index acfed6d0e..8876fe5d0 100644
--- a/language/en_UK.iso-8859-1/admin.lang.php
+++ b/language/en_UK.iso-8859-1/admin.lang.php
@@ -26,6 +26,7 @@
// +-----------------------------------------------------------------------+
$lang['%d categories including %d physical and %d virtual'] = '%d categories including %d physical and %d virtual';
+$lang['%d categories moved'] = '%d categories moved';
$lang['%d comments'] = '%d comments';
$lang['%d elements'] = '%d elements';
$lang['%d groups'] = '%d groups';
@@ -82,8 +83,10 @@ $lang['Maximum height of the pictures'] = 'Maximum height of the pictures';
$lang['Maximum width of the pictures'] = 'Maximum width of the pictures';
$lang['Members'] = 'Members';
$lang['Metadata synchronized from file'] = 'Metadata synchronized from file';
+$lang['Move categories'] = 'Move categories';
$lang['Move'] = 'Move';
$lang['Name'] = 'Name';
+$lang['New parent category'] = 'New parent category';
$lang['No'] = 'No';
$lang['Number of comments per page'] = 'Number of comments per page';
$lang['Number of images per row'] = 'Number of images per row';
@@ -129,10 +132,13 @@ $lang['Users'] = 'Users';
$lang['Validate All'] = 'Validate All';
$lang['Validate'] = 'Validate';
$lang['Validation'] = 'Validation';
+$lang['Virtual categories movement'] = 'Virtual categories movement';
+$lang['Virtual categories to move'] = 'Virtual categories to move';
$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.';
$lang['You are running the latest version of PhpWebGallery.'] = 'You are running the latest version of PhpWebGallery.';
+$lang['You cannot move a category in its own sub category'] = 'You cannot move a category in its own sub category';
$lang['You need to confirm deletion'] = 'You need to confirm deletion';
$lang['actions'] = 'actions';
$lang['all'] = 'all';
diff --git a/language/fr_FR.iso-8859-1/admin.lang.php b/language/fr_FR.iso-8859-1/admin.lang.php
index 71197ab5c..8f85f9039 100644
--- a/language/fr_FR.iso-8859-1/admin.lang.php
+++ b/language/fr_FR.iso-8859-1/admin.lang.php
@@ -26,6 +26,7 @@
// +-----------------------------------------------------------------------+
$lang['%d categories including %d physical and %d virtual'] = '%d catégories dont %d physiques et %d virtuelles';
+$lang['%d categories moved'] = '%d catégories déplacées';
$lang['%d comments'] = '%d commentaires utilisateur';
$lang['%d elements'] = '%d éléments';
$lang['%d groups'] = '%d groupes';
@@ -82,8 +83,10 @@ $lang['Maximum height of the pictures'] = 'Hauteur maximum des images';
$lang['Maximum width of the pictures'] = 'Largeur maximum des images';
$lang['Members'] = 'Membres';
$lang['Metadata synchronized from file'] = 'Meta-données synchronisées à partir du fichier';
+$lang['Move categories'] = 'Déplacer les catégories';
$lang['Move'] = 'Déplacer';
$lang['Name'] = 'Nom';
+$lang['New parent category'] = 'Nouvelle catégorie parente';
$lang['No'] = 'Non';
$lang['Number of comments per page'] = 'Nombre de commentaires utilisateur par page';
$lang['Number of images per row'] = 'Nombre de miniatures par ligne';
@@ -129,10 +132,13 @@ $lang['Users'] = 'Utilisateurs';
$lang['Validate All'] = 'Tout valider';
$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['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.';
$lang['You are running the latest version of PhpWebGallery.'] = 'Vous utilisez la dernière version de PhpWebGallery.';
+$lang['You cannot move a category in its own sub category'] = 'Vous ne pouvez pas déplacer une catégorie dans sa propre sous-catégorie';
$lang['You need to confirm deletion'] = 'Vous devez confirmer la suppression';
$lang['actions'] = 'actions';
$lang['all'] = 'tout';
diff --git a/template/yoga/admin.tpl b/template/yoga/admin.tpl
index 70c0f2042..b16859c98 100644
--- a/template/yoga/admin.tpl
+++ b/template/yoga/admin.tpl
@@ -33,6 +33,7 @@
<dd>
<ul>
<li><a href="{U_CATEGORIES}">{lang:manage}</a></li>
+ <li><a href="{U_MOVE}">{lang:Move}</a></li>
<li><a href="{U_CAT_UPLOAD}">{lang:upload}</a></li>
<li><a href="{U_CAT_COMMENTS}">{lang:comments}</a></li>
<li><a href="{U_CAT_VISIBLE}">{lang:lock}</a></li>
diff --git a/template/yoga/admin/cat_move.tpl b/template/yoga/admin/cat_move.tpl
new file mode 100644
index 000000000..eb6ccde36
--- /dev/null
+++ b/template/yoga/admin/cat_move.tpl
@@ -0,0 +1,40 @@
+<!-- $Id$ -->
+<div class="titrePage">
+ <ul class="categoryActions">
+ <li><a href="{U_HELP}" onclick="popuphelp(this.href); return false;" title="{lang:Help}"><img src="template/yoga/theme/help.png" alt="(?)"></a></li>
+ </ul>
+ <h2>{lang:Move categories}</h2>
+</div>
+
+<form method="post" action="{F_ACTION}">
+ <fieldset>
+ <legend>{lang:Virtual categories movement}</legend>
+
+ <label>
+ {lang:Virtual categories to move}
+
+ <select class="categoryList" name="selection[]" multiple="multiple" size="30">
+ <!-- BEGIN category_option_selection -->
+ <option {category_option_selection.SELECTED} value="{category_option_selection.VALUE}">{category_option_selection.OPTION}</option>
+ <!-- END category_option_selection -->
+ </select>
+ </label>
+
+ <label>
+ {lang:New parent category}
+
+ <select class="categoryList" name="parent">
+ <!-- BEGIN category_option_parent -->
+ <option {category_option_parent.SELECTED} value="{category_option_parent.VALUE}">{category_option_parent.OPTION}</option>
+ <!-- END category_option_parent -->
+ </select>
+ </label>
+
+ </fieldset>
+
+ <p>
+ <input type="submit" name="submit" value="{lang:Submit}">
+ <input type="reset" name="reset" value="{lang:Reset}">
+ </p>
+
+</form>