2003-05-09 14:42:42 +02:00
|
|
|
<?php
|
2004-02-12 00:20:38 +01:00
|
|
|
// +-----------------------------------------------------------------------+
|
2004-11-06 22:12:59 +01:00
|
|
|
// | PhpWebGallery - a PHP based picture gallery |
|
|
|
|
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
|
2005-01-08 00:10:51 +01:00
|
|
|
// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
|
2004-02-12 00:20:38 +01:00
|
|
|
// +-----------------------------------------------------------------------+
|
2004-11-06 22:12:59 +01:00
|
|
|
// | branch : BSF (Best So Far)
|
2004-02-12 00:20:38 +01:00
|
|
|
// | 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. |
|
|
|
|
// +-----------------------------------------------------------------------+
|
2004-02-02 01:55:18 +01:00
|
|
|
|
2004-10-24 20:56:09 +02:00
|
|
|
if (!defined('PHPWG_ROOT_PATH'))
|
2004-03-26 18:08:09 +01:00
|
|
|
{
|
2004-10-24 20:56:09 +02:00
|
|
|
die('Hacking attempt!');
|
2004-03-26 18:08:09 +01:00
|
|
|
}
|
2006-03-09 23:46:28 +01:00
|
|
|
|
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
|
|
|
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | Check Access and exit when user status is not ok |
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
check_status(ACCESS_ADMINISTRATOR);
|
2005-06-30 23:00:07 +02:00
|
|
|
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | functions |
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
|
|
|
|
/**
|
|
|
|
* save the rank depending on given categories order
|
|
|
|
*
|
|
|
|
* The list of ordered categories id is supposed to be in the same parent
|
|
|
|
* category
|
|
|
|
*
|
|
|
|
* @param array categories
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function save_categories_order($categories)
|
|
|
|
{
|
|
|
|
$current_rank = 0;
|
|
|
|
$datas = array();
|
|
|
|
foreach ($categories as $id)
|
|
|
|
{
|
|
|
|
array_push($datas, array('id' => $id, 'rank' => ++$current_rank));
|
|
|
|
}
|
|
|
|
$fields = array('primary' => array('id'), 'update' => array('rank'));
|
|
|
|
mass_updates(CATEGORIES_TABLE, $fields, $datas);
|
|
|
|
|
|
|
|
update_global_rank(@$_GET['parent_id']);
|
|
|
|
}
|
|
|
|
|
2004-10-24 20:56:09 +02:00
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | initialization |
|
|
|
|
// +-----------------------------------------------------------------------+
|
2005-08-19 19:00:20 +02:00
|
|
|
|
2004-10-24 20:56:09 +02:00
|
|
|
$categories = array();
|
2005-08-19 19:00:20 +02:00
|
|
|
|
|
|
|
$base_url = PHPWG_ROOT_PATH.'admin.php?page=cat_list';
|
2006-01-15 14:45:42 +01:00
|
|
|
$navigation = '<a class="" href="'.$base_url.'">';
|
2005-08-19 19:00:20 +02:00
|
|
|
$navigation.= $lang['home'];
|
|
|
|
$navigation.= '</a>';
|
|
|
|
|
2004-10-24 20:56:09 +02:00
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | virtual categories management |
|
|
|
|
// +-----------------------------------------------------------------------+
|
2006-03-27 23:19:31 +02:00
|
|
|
// request to delete a virtual category / not for an adviser
|
|
|
|
if (isset($_GET['delete']) and is_numeric($_GET['delete']) and !is_adviser())
|
2004-03-26 18:08:09 +01:00
|
|
|
{
|
2004-12-27 15:30:49 +01:00
|
|
|
delete_categories(array($_GET['delete']));
|
2005-06-11 16:10:04 +02:00
|
|
|
array_push($page['infos'], $lang['cat_virtual_deleted']);
|
2004-12-27 15:30:49 +01:00
|
|
|
ordering();
|
|
|
|
update_global_rank();
|
2004-03-26 18:08:09 +01:00
|
|
|
}
|
2004-11-13 14:43:53 +01:00
|
|
|
// request to add a virtual category
|
2005-06-30 23:00:07 +02:00
|
|
|
else if (isset($_POST['submitAdd']))
|
2003-09-07 12:14:33 +02:00
|
|
|
{
|
2006-03-05 00:31:46 +01:00
|
|
|
$output_create = create_virtual_category(
|
|
|
|
$_POST['virtual_name'],
|
|
|
|
@$_GET['parent_id']
|
|
|
|
);
|
|
|
|
|
|
|
|
if (isset($output_create['error']))
|
2004-10-24 20:56:09 +02:00
|
|
|
{
|
2006-03-05 00:31:46 +01:00
|
|
|
array_push($page['errors'], $output_create['error']);
|
2004-10-24 20:56:09 +02:00
|
|
|
}
|
2006-03-05 00:31:46 +01:00
|
|
|
else
|
2003-09-07 12:14:33 +02:00
|
|
|
{
|
2006-03-05 00:31:46 +01:00
|
|
|
array_push($page['infos'], $output_create['info']);
|
2003-09-07 12:14:33 +02:00
|
|
|
}
|
|
|
|
}
|
2006-03-07 00:28:51 +01:00
|
|
|
// save manual category ordering
|
2005-06-30 23:00:07 +02:00
|
|
|
else if (isset($_POST['submitOrder']))
|
|
|
|
{
|
|
|
|
asort($_POST['catOrd'], SORT_NUMERIC);
|
|
|
|
save_categories_order(array_keys($_POST['catOrd']));
|
2006-03-07 00:28:51 +01:00
|
|
|
|
|
|
|
array_push(
|
|
|
|
$page['infos'],
|
|
|
|
l10n('Categories manual order was saved')
|
|
|
|
);
|
2005-06-30 23:00:07 +02:00
|
|
|
}
|
2006-03-07 00:28:51 +01:00
|
|
|
// sort categories alpha-numerically
|
|
|
|
else if (isset($_POST['submitOrderAlphaNum']))
|
|
|
|
{
|
|
|
|
$query = '
|
|
|
|
SELECT id, name
|
|
|
|
FROM '.CATEGORIES_TABLE.'
|
|
|
|
WHERE id_uppercat '.
|
|
|
|
(!isset($_GET['parent_id']) ? 'IS NULL' : '= '.$_GET['parent_id']).'
|
|
|
|
;';
|
|
|
|
$result = pwg_query($query);
|
|
|
|
while ($row = mysql_fetch_assoc($result))
|
|
|
|
{
|
2006-04-20 23:39:12 +02:00
|
|
|
$categories[ $row['id'] ] = strtolower($row['name']);
|
2006-03-07 00:28:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
asort($categories, SORT_REGULAR);
|
|
|
|
save_categories_order(array_keys($categories));
|
|
|
|
|
|
|
|
array_push(
|
|
|
|
$page['infos'],
|
|
|
|
l10n('Categories ordered alphanumerically')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2004-10-24 20:56:09 +02:00
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | Cache management |
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
$query = '
|
|
|
|
SELECT *
|
|
|
|
FROM '.CATEGORIES_TABLE;
|
|
|
|
if (!isset($_GET['parent_id']))
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
2004-10-24 20:56:09 +02:00
|
|
|
$query.= '
|
|
|
|
WHERE id_uppercat IS NULL';
|
2003-05-09 14:42:42 +02:00
|
|
|
}
|
2004-03-26 18:08:09 +01:00
|
|
|
else
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
2004-10-24 20:56:09 +02:00
|
|
|
$query.= '
|
|
|
|
WHERE id_uppercat = '.$_GET['parent_id'];
|
2003-05-09 14:42:42 +02:00
|
|
|
}
|
2004-10-24 20:56:09 +02:00
|
|
|
$query.= '
|
|
|
|
ORDER BY rank ASC
|
|
|
|
;';
|
2004-10-30 17:42:29 +02:00
|
|
|
$result = pwg_query($query);
|
2004-10-24 20:56:09 +02:00
|
|
|
while ($row = mysql_fetch_assoc($result))
|
2003-09-07 12:14:33 +02:00
|
|
|
{
|
2004-10-24 20:56:09 +02:00
|
|
|
$categories[$row['rank']] = $row;
|
2004-12-12 22:06:39 +01:00
|
|
|
$categories[$row['rank']]['nb_subcats'] = 0;
|
2003-09-07 12:14:33 +02:00
|
|
|
}
|
2005-08-19 19:00:20 +02:00
|
|
|
|
2004-10-24 20:56:09 +02:00
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | Navigation path |
|
|
|
|
// +-----------------------------------------------------------------------+
|
2005-08-19 19:00:20 +02:00
|
|
|
|
2004-03-26 18:08:09 +01:00
|
|
|
if (isset($_GET['parent_id']))
|
2003-09-07 12:14:33 +02:00
|
|
|
{
|
2004-12-12 22:06:39 +01:00
|
|
|
$navigation.= $conf['level_separator'];
|
2004-10-24 20:56:09 +02:00
|
|
|
|
2004-03-26 18:08:09 +01:00
|
|
|
$current_category = get_cat_info($_GET['parent_id']);
|
2006-04-06 04:23:54 +02:00
|
|
|
|
2006-03-05 00:31:46 +01:00
|
|
|
$navigation.= get_cat_display_name(
|
|
|
|
$current_category['name'],
|
|
|
|
$base_url.'&parent_id=',
|
|
|
|
false
|
|
|
|
);
|
2003-09-07 12:14:33 +02:00
|
|
|
}
|
2004-10-24 20:56:09 +02:00
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | template initialization |
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
$template->set_filenames(array('categories'=>'admin/cat_list.tpl'));
|
2004-03-26 18:08:09 +01:00
|
|
|
|
- on picture.php, related categories under the element are displayed in
global_rank order
- when adding a new virtual category, initializes its global_rank
- bug fixed : in admin/cat_list, false next rank
- in admin/cat_modify, complete directory is calculated only if category is
not virtual
- admin/picture_modify rewritten : graphically nearer to admin/cat_modify,
virtual associations are back
- update_category partially rewritten : take an array of categories in
parameter, becomes optionnaly recursive, use the set_random_representant
function, set a random representant for categories with elements and no
representant
- bug fixed : on a search results screen, elements belonging to more than 1
category were shown more than once
- bug fixed : in admin/cat_modify, changing a value in a textefield and
hitting enter was setting a new random representant
git-svn-id: http://piwigo.org/svn/trunk@635 68402e56-0260-453c-a942-63ccdbb3a9ee
2004-12-05 22:28:40 +01:00
|
|
|
$form_action = PHPWG_ROOT_PATH.'admin.php?page=cat_list';
|
|
|
|
if (isset($_GET['parent_id']))
|
|
|
|
{
|
|
|
|
$form_action.= '&parent_id='.$_GET['parent_id'];
|
|
|
|
}
|
|
|
|
|
2004-03-26 18:08:09 +01:00
|
|
|
$template->assign_vars(array(
|
|
|
|
'CATEGORIES_NAV'=>$navigation,
|
2006-01-15 14:45:42 +01:00
|
|
|
'F_ACTION'=>$form_action,
|
2006-04-06 04:23:54 +02:00
|
|
|
|
2004-03-26 18:08:09 +01:00
|
|
|
'L_ADD_VIRTUAL'=>$lang['cat_add'],
|
|
|
|
'L_SUBMIT'=>$lang['submit'],
|
|
|
|
'L_STORAGE'=>$lang['storage'],
|
|
|
|
'L_NB_IMG'=>$lang['pictures'],
|
2004-11-25 17:44:41 +01:00
|
|
|
'L_MOVE_UP'=>$lang['up'],
|
2004-03-26 18:08:09 +01:00
|
|
|
'L_EDIT'=>$lang['edit'],
|
2004-10-24 20:56:09 +02:00
|
|
|
'L_DELETE'=>$lang['delete'],
|
|
|
|
));
|
2006-04-06 04:23:54 +02:00
|
|
|
|
2004-10-24 20:56:09 +02:00
|
|
|
$tpl = array('cat_first','cat_last');
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | Categories display |
|
|
|
|
// +-----------------------------------------------------------------------+
|
2004-12-18 23:05:30 +01:00
|
|
|
|
2005-06-30 23:00:07 +02:00
|
|
|
$categories = array();
|
|
|
|
|
|
|
|
$query = '
|
|
|
|
SELECT id, name, dir, rank, nb_images, status
|
|
|
|
FROM '.CATEGORIES_TABLE;
|
|
|
|
if (!isset($_GET['parent_id']))
|
2004-12-12 22:06:39 +01:00
|
|
|
{
|
2005-06-30 23:00:07 +02:00
|
|
|
$query.= '
|
|
|
|
WHERE id_uppercat IS NULL';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$query.= '
|
|
|
|
WHERE id_uppercat = '.$_GET['parent_id'];
|
|
|
|
}
|
|
|
|
$query.= '
|
|
|
|
ORDER BY rank ASC
|
|
|
|
;';
|
|
|
|
$result = pwg_query($query);
|
|
|
|
while ($row = mysql_fetch_array($result))
|
|
|
|
{
|
|
|
|
$categories[$row['id']] = $row;
|
|
|
|
// by default, let's consider there is no sub-categories. This will be
|
|
|
|
// calculated after.
|
|
|
|
$categories[$row['id']]['nb_subcats'] = 0;
|
|
|
|
}
|
2004-12-12 22:06:39 +01:00
|
|
|
|
2005-06-30 23:00:07 +02:00
|
|
|
if (count($categories) > 0)
|
|
|
|
{
|
2004-12-18 23:05:30 +01:00
|
|
|
$query = '
|
2004-12-12 22:06:39 +01:00
|
|
|
SELECT id_uppercat, COUNT(*) AS nb_subcats
|
|
|
|
FROM '. CATEGORIES_TABLE.'
|
2005-06-30 23:00:07 +02:00
|
|
|
WHERE id_uppercat IN ('.implode(',', array_keys($categories)).')
|
2004-12-12 22:06:39 +01:00
|
|
|
GROUP BY id_uppercat
|
|
|
|
;';
|
2004-12-18 23:05:30 +01:00
|
|
|
$result = pwg_query($query);
|
|
|
|
while ($row = mysql_fetch_array($result))
|
|
|
|
{
|
2005-06-30 23:00:07 +02:00
|
|
|
$categories[$row['id_uppercat']]['nb_subcats'] = $row['nb_subcats'];
|
2004-12-18 23:05:30 +01:00
|
|
|
}
|
2006-06-13 22:39:49 +02:00
|
|
|
|
|
|
|
$template->assign_block_vars('categories', array());
|
2004-12-12 22:06:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($categories as $category)
|
2004-10-24 20:56:09 +02:00
|
|
|
{
|
2005-12-03 18:33:38 +01:00
|
|
|
// TODO : not used anymore ?
|
|
|
|
//$images_folder = PHPWG_ROOT_PATH.'template/';
|
|
|
|
//$images_folder.= $user['template'].'/admin/images';
|
2006-04-06 04:23:54 +02:00
|
|
|
|
2004-10-24 20:56:09 +02:00
|
|
|
$base_url = PHPWG_ROOT_PATH.'admin.php?page=';
|
|
|
|
$cat_list_url = $base_url.'cat_list';
|
2006-04-06 04:23:54 +02:00
|
|
|
|
2004-10-24 20:56:09 +02:00
|
|
|
$self_url = $cat_list_url;
|
2004-03-26 18:08:09 +01:00
|
|
|
if (isset($_GET['parent_id']))
|
2004-10-24 20:56:09 +02:00
|
|
|
{
|
|
|
|
$self_url.= '&parent_id='.$_GET['parent_id'];
|
|
|
|
}
|
2004-03-26 18:08:09 +01:00
|
|
|
|
2004-10-24 20:56:09 +02:00
|
|
|
$template->assign_block_vars(
|
2006-06-13 22:39:49 +02:00
|
|
|
'categories.category',
|
2004-10-24 20:56:09 +02:00
|
|
|
array(
|
2006-03-15 23:44:35 +01:00
|
|
|
'NAME' => $category['name'],
|
|
|
|
'ID' => $category['id'],
|
|
|
|
'RANK' => $category['rank']*10,
|
2005-06-30 23:00:07 +02:00
|
|
|
|
2006-03-15 23:44:35 +01:00
|
|
|
'U_JUMPTO' => make_index_url(
|
|
|
|
array(
|
|
|
|
'category' => $category['id'],
|
2006-04-06 04:23:54 +02:00
|
|
|
'cat_name' => $category['name'],
|
2006-03-15 23:44:35 +01:00
|
|
|
)
|
|
|
|
),
|
2006-04-06 04:23:54 +02:00
|
|
|
|
|
|
|
'U_CHILDREN' => $cat_list_url.'&parent_id='.$category['id'],
|
2006-03-15 23:44:35 +01:00
|
|
|
'U_EDIT' => $base_url.'cat_modify&cat_id='.$category['id'],
|
2005-06-30 23:00:07 +02:00
|
|
|
)
|
|
|
|
);
|
2006-04-06 04:23:54 +02:00
|
|
|
|
2005-06-30 23:00:07 +02:00
|
|
|
if (empty($category['dir']))
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
2005-06-30 23:00:07 +02:00
|
|
|
$template->assign_block_vars(
|
2006-06-13 22:39:49 +02:00
|
|
|
'categories.category.delete',
|
2005-06-30 23:00:07 +02:00
|
|
|
array(
|
2006-01-15 14:45:42 +01:00
|
|
|
'URL'=>$self_url.'&delete='.$category['id']
|
2005-06-30 23:00:07 +02:00
|
|
|
)
|
|
|
|
);
|
2007-01-25 08:26:28 +01:00
|
|
|
$template->assign_block_vars(
|
|
|
|
'categories.category.virtual',
|
|
|
|
array(
|
|
|
|
'CLASS' => 'virtual_cat',
|
|
|
|
)
|
|
|
|
);
|
2003-05-09 14:42:42 +02:00
|
|
|
}
|
2006-04-06 04:23:54 +02:00
|
|
|
|
2004-10-24 20:56:09 +02:00
|
|
|
if ($category['nb_images'] > 0)
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
2005-06-30 23:00:07 +02:00
|
|
|
$template->assign_block_vars(
|
2006-06-13 22:39:49 +02:00
|
|
|
'categories.category.elements',
|
2005-06-30 23:00:07 +02:00
|
|
|
array(
|
2006-01-15 14:45:42 +01:00
|
|
|
'URL'=>$base_url.'element_set&cat='.$category['id']
|
2005-06-30 23:00:07 +02:00
|
|
|
)
|
|
|
|
);
|
2004-03-26 18:08:09 +01:00
|
|
|
}
|
2005-06-30 23:00:07 +02:00
|
|
|
|
|
|
|
if ('private' == $category['status'])
|
2004-03-26 18:08:09 +01:00
|
|
|
{
|
2005-06-30 23:00:07 +02:00
|
|
|
$template->assign_block_vars(
|
2006-08-09 14:34:55 +02:00
|
|
|
'categories.category.permissions',
|
2005-06-30 23:00:07 +02:00
|
|
|
array(
|
2006-01-15 14:45:42 +01:00
|
|
|
'URL'=>$base_url.'cat_perm&cat='.$category['id']
|
2005-06-30 23:00:07 +02:00
|
|
|
)
|
|
|
|
);
|
2003-05-09 14:42:42 +02:00
|
|
|
}
|
|
|
|
}
|
2007-01-18 22:10:39 +01:00
|
|
|
// Add a link to Page bottom only if needed (10 or more categories)
|
2007-01-19 07:50:46 +01:00
|
|
|
if ( isset($category['rank']) and $category['rank'] > 9 )
|
2007-01-18 22:10:39 +01:00
|
|
|
{
|
|
|
|
$template->assign_block_vars('eop_link', array('ICON'=>'Displayed'));
|
|
|
|
}
|
2004-10-24 20:56:09 +02:00
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | sending html code |
|
|
|
|
// +-----------------------------------------------------------------------+
|
2004-03-26 18:08:09 +01:00
|
|
|
$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
|
2004-02-12 00:20:38 +01:00
|
|
|
?>
|