2003-05-09 14:42:42 +02:00
|
|
|
<?php
|
2004-02-12 00:20:38 +01:00
|
|
|
// +-----------------------------------------------------------------------+
|
2011-01-18 01:02:52 +01:00
|
|
|
// | Piwigo - a PHP based photo gallery |
|
2008-04-05 00:57:23 +02:00
|
|
|
// +-----------------------------------------------------------------------+
|
2012-01-17 23:48:36 +01:00
|
|
|
// | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org |
|
2008-04-05 00:57:23 +02:00
|
|
|
// | 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 |
|
2004-02-12 00:20:38 +01:00
|
|
|
// | 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
|
|
|
|
2010-04-21 14:51:48 +02:00
|
|
|
trigger_action('loc_begin_cat_list');
|
|
|
|
|
2010-03-19 23:25:39 +01:00
|
|
|
if (!empty($_POST) or isset($_GET['delete']))
|
|
|
|
{
|
|
|
|
check_pwg_token();
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2010-07-23 23:33:56 +02:00
|
|
|
$current_rank_for_id_uppercat = array();
|
2005-06-30 23:00:07 +02:00
|
|
|
$current_rank = 0;
|
2010-07-23 23:33:56 +02:00
|
|
|
|
2005-06-30 23:00:07 +02:00
|
|
|
$datas = array();
|
2010-07-23 23:33:56 +02:00
|
|
|
foreach ($categories as $category)
|
2005-06-30 23:00:07 +02:00
|
|
|
{
|
2010-07-23 23:33:56 +02:00
|
|
|
if (is_array($category))
|
|
|
|
{
|
|
|
|
$id = $category['id'];
|
|
|
|
$id_uppercat = $category['id_uppercat'];
|
|
|
|
|
|
|
|
if (!isset($current_rank_for_id_uppercat[$id_uppercat]))
|
|
|
|
{
|
|
|
|
$current_rank_for_id_uppercat[$id_uppercat] = 0;
|
|
|
|
}
|
|
|
|
$current_rank = ++$current_rank_for_id_uppercat[$id_uppercat];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$id = $category;
|
|
|
|
$current_rank++;
|
|
|
|
}
|
|
|
|
|
|
|
|
array_push($datas, array('id' => $id, 'rank' => $current_rank));
|
2005-06-30 23:00:07 +02:00
|
|
|
}
|
|
|
|
$fields = array('primary' => array('id'), 'update' => array('rank'));
|
|
|
|
mass_updates(CATEGORIES_TABLE, $fields, $datas);
|
|
|
|
|
2008-04-21 00:20:20 +02:00
|
|
|
update_global_rank();
|
2005-06-30 23:00:07 +02:00
|
|
|
}
|
|
|
|
|
2004-10-24 20:56:09 +02:00
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | initialization |
|
|
|
|
// +-----------------------------------------------------------------------+
|
2005-08-19 19:00:20 +02:00
|
|
|
|
2010-03-19 23:25:39 +01:00
|
|
|
check_input_parameter('parent_id', $_GET, false, PATTERN_ID);
|
|
|
|
|
2004-10-24 20:56:09 +02:00
|
|
|
$categories = array();
|
2005-08-19 19:00:20 +02:00
|
|
|
|
2008-04-21 00:20:20 +02:00
|
|
|
$base_url = get_root_url().'admin.php?page=cat_list';
|
|
|
|
$navigation = '<a href="'.$base_url.'">';
|
2010-03-02 15:54:22 +01:00
|
|
|
$navigation.= l10n('Home');
|
2005-08-19 19:00:20 +02:00
|
|
|
$navigation.= '</a>';
|
|
|
|
|
2012-02-20 20:28:43 +01:00
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | tabs |
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
|
|
|
|
$page['tab'] = 'list';
|
|
|
|
include(PHPWG_ROOT_PATH.'admin/include/albums_tab.inc.php');
|
|
|
|
|
2004-10-24 20:56:09 +02:00
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | virtual categories management |
|
|
|
|
// +-----------------------------------------------------------------------+
|
2010-12-14 15:36:20 +01:00
|
|
|
// request to delete a virtual category
|
2010-12-14 14:47:24 +01:00
|
|
|
if (isset($_GET['delete']) and is_numeric($_GET['delete']))
|
2004-03-26 18:08:09 +01:00
|
|
|
{
|
2004-12-27 15:30:49 +01:00
|
|
|
delete_categories(array($_GET['delete']));
|
2010-12-17 01:11:56 +01:00
|
|
|
$_SESSION['page_infos'] = array(l10n('Virtual album deleted'));
|
2004-12-27 15:30:49 +01:00
|
|
|
update_global_rank();
|
2010-12-17 01:11:56 +01:00
|
|
|
|
|
|
|
$redirect_url = get_root_url().'admin.php?page=cat_list';
|
|
|
|
if (isset($_GET['parent_id']))
|
|
|
|
{
|
|
|
|
$redirect_url.= '&parent_id='.$_GET['parent_id'];
|
|
|
|
}
|
|
|
|
redirect($redirect_url);
|
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
|
2012-02-20 20:28:43 +01:00
|
|
|
else if (isset($_POST['submitManualOrder']))
|
2005-06-30 23:00:07 +02:00
|
|
|
{
|
2012-02-20 20:28:43 +01:00
|
|
|
asort($_POST['catOrd'], SORT_NUMERIC);
|
|
|
|
save_categories_order(array_keys($_POST['catOrd']));
|
2006-03-07 00:28:51 +01:00
|
|
|
|
2012-02-20 20:28:43 +01:00
|
|
|
array_push(
|
|
|
|
$page['infos'],
|
|
|
|
l10n('Album manual order was saved')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else if (isset($_POST['submitAutoOrder']))
|
|
|
|
{
|
|
|
|
$query = '
|
2010-07-23 23:33:56 +02:00
|
|
|
SELECT id
|
2006-03-07 00:28:51 +01:00
|
|
|
FROM '.CATEGORIES_TABLE.'
|
|
|
|
WHERE id_uppercat '.
|
|
|
|
(!isset($_GET['parent_id']) ? 'IS NULL' : '= '.$_GET['parent_id']).'
|
|
|
|
;';
|
2012-02-20 20:28:43 +01:00
|
|
|
$category_ids = array_from_query($query, 'id');
|
2010-07-23 23:33:56 +02:00
|
|
|
|
2012-02-20 20:28:43 +01:00
|
|
|
if (isset($_POST['recursive']))
|
|
|
|
{
|
|
|
|
$category_ids = get_subcat_ids($category_ids);
|
|
|
|
}
|
2010-07-23 23:33:56 +02:00
|
|
|
|
2012-02-20 20:28:43 +01:00
|
|
|
$categories = array();
|
|
|
|
$names = array();
|
|
|
|
$id_uppercats = array();
|
|
|
|
|
|
|
|
$query = '
|
2010-07-23 23:33:56 +02:00
|
|
|
SELECT id, name, id_uppercat
|
2010-03-07 22:09:26 +01:00
|
|
|
FROM '.CATEGORIES_TABLE.'
|
2010-07-23 23:33:56 +02:00
|
|
|
WHERE id IN ('.implode(',', $category_ids).')
|
2010-03-07 22:09:26 +01:00
|
|
|
;';
|
2012-02-20 20:28:43 +01:00
|
|
|
$result = pwg_query($query);
|
|
|
|
while ($row = pwg_db_fetch_assoc($result))
|
|
|
|
{
|
|
|
|
array_push(
|
|
|
|
$categories,
|
|
|
|
array(
|
|
|
|
'id' => $row['id'],
|
|
|
|
'id_uppercat' => $row['id_uppercat'],
|
|
|
|
)
|
2010-07-23 23:33:56 +02:00
|
|
|
);
|
|
|
|
array_push(
|
2012-02-20 20:28:43 +01:00
|
|
|
$names,
|
|
|
|
$row['name']
|
2010-07-23 23:33:56 +02:00
|
|
|
);
|
2010-03-07 22:09:26 +01:00
|
|
|
}
|
2012-02-20 20:28:43 +01:00
|
|
|
|
|
|
|
array_multisort(
|
|
|
|
$names,
|
|
|
|
SORT_REGULAR,
|
|
|
|
'asc' == $_POST['ascdesc'] ? SORT_ASC : SORT_DESC,
|
|
|
|
$categories
|
|
|
|
);
|
|
|
|
save_categories_order($categories);
|
|
|
|
|
|
|
|
array_push(
|
|
|
|
$page['infos'],
|
|
|
|
l10n('Albums automatically sorted')
|
|
|
|
);
|
2010-03-07 22:09:26 +01:00
|
|
|
}
|
2006-03-07 00:28:51 +01: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
|
|
|
|
2007-02-27 02:56:16 +01:00
|
|
|
$navigation.= get_cat_display_name_from_id(
|
|
|
|
$_GET['parent_id'],
|
2006-03-05 00:31:46 +01:00
|
|
|
$base_url.'&parent_id=',
|
|
|
|
false
|
|
|
|
);
|
2003-09-07 12:14:33 +02:00
|
|
|
}
|
2004-10-24 20:56:09 +02:00
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | template initialization |
|
|
|
|
// +-----------------------------------------------------------------------+
|
2008-09-14 09:16:15 +02:00
|
|
|
$template->set_filename('categories', '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'];
|
|
|
|
}
|
|
|
|
|
2008-02-28 03:41:48 +01:00
|
|
|
$template->assign(array(
|
2004-03-26 18:08:09 +01:00
|
|
|
'CATEGORIES_NAV'=>$navigation,
|
2006-01-15 14:45:42 +01:00
|
|
|
'F_ACTION'=>$form_action,
|
2010-03-19 23:25:39 +01:00
|
|
|
'PWG_TOKEN' => get_pwg_token(),
|
2004-10-24 20:56:09 +02:00
|
|
|
));
|
2006-04-06 04:23:54 +02:00
|
|
|
|
2004-10-24 20:56:09 +02:00
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | Categories display |
|
|
|
|
// +-----------------------------------------------------------------------+
|
2004-12-18 23:05:30 +01:00
|
|
|
|
2005-06-30 23:00:07 +02:00
|
|
|
$categories = array();
|
|
|
|
|
|
|
|
$query = '
|
2008-05-01 03:12:34 +02:00
|
|
|
SELECT id, name, permalink, dir, rank, status
|
2005-06-30 23:00:07 +02:00
|
|
|
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
|
|
|
|
;';
|
2008-05-01 03:12:34 +02:00
|
|
|
$categories = hash_from_query($query, 'id');
|
2004-12-12 22:06:39 +01:00
|
|
|
|
2008-05-01 03:12:34 +02:00
|
|
|
// get the categories containing images directly
|
|
|
|
$categories_with_images = array();
|
|
|
|
if ( count($categories) )
|
2005-06-30 23:00:07 +02:00
|
|
|
{
|
2004-12-18 23:05:30 +01:00
|
|
|
$query = '
|
2008-05-01 03:12:34 +02:00
|
|
|
SELECT DISTINCT category_id
|
|
|
|
FROM '.IMAGE_CATEGORY_TABLE.'
|
|
|
|
WHERE category_id IN ('.implode(',', array_keys($categories)).')';
|
|
|
|
$categories_with_images = array_flip( array_from_query($query, 'category_id') );
|
2004-12-12 22:06:39 +01:00
|
|
|
}
|
|
|
|
|
2008-02-28 03:41:48 +01:00
|
|
|
$template->assign('categories', array());
|
2008-05-01 03:12:34 +02:00
|
|
|
$base_url = get_root_url().'admin.php?page=';
|
2004-12-12 22:06:39 +01:00
|
|
|
foreach ($categories as $category)
|
2004-10-24 20:56:09 +02:00
|
|
|
{
|
|
|
|
$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
|
|
|
|
2008-02-28 03:41:48 +01:00
|
|
|
$tpl_cat =
|
2004-10-24 20:56:09 +02:00
|
|
|
array(
|
2008-07-12 16:57:24 +02:00
|
|
|
'NAME' =>
|
|
|
|
trigger_event(
|
|
|
|
'render_category_name',
|
|
|
|
$category['name'],
|
|
|
|
'admin_cat_list'
|
|
|
|
),
|
2006-03-15 23:44:35 +01:00
|
|
|
'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(
|
2007-02-27 02:56:16 +01:00
|
|
|
'category' => $category
|
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'],
|
2012-02-02 00:03:35 +01:00
|
|
|
'U_EDIT' => $base_url.'album-'.$category['id'],
|
2008-04-21 00:20:20 +02:00
|
|
|
|
2008-02-28 03:41:48 +01:00
|
|
|
'IS_VIRTUAL' => empty($category['dir'])
|
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
|
|
|
{
|
2008-02-28 03:41:48 +01:00
|
|
|
$tpl_cat['U_DELETE'] = $self_url.'&delete='.$category['id'];
|
2010-03-19 23:25:39 +01:00
|
|
|
$tpl_cat['U_DELETE'].= '&pwg_token='.get_pwg_token();
|
2003-05-09 14:42:42 +02:00
|
|
|
}
|
2011-05-25 11:18:32 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if ($conf['enable_synchronization'])
|
|
|
|
{
|
|
|
|
$tpl_cat['U_SYNC'] = $base_url.'site_update&site=1&cat_id='.$category['id'];
|
|
|
|
}
|
|
|
|
}
|
2006-04-06 04:23:54 +02:00
|
|
|
|
2008-05-01 03:12:34 +02:00
|
|
|
if ( array_key_exists($category['id'], $categories_with_images) )
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
2008-02-28 03:41:48 +01:00
|
|
|
$tpl_cat['U_MANAGE_ELEMENTS']=
|
2010-12-31 16:19:11 +01:00
|
|
|
$base_url.'batch_manager&cat='.$category['id'];
|
2004-03-26 18:08:09 +01:00
|
|
|
}
|
2005-06-30 23:00:07 +02:00
|
|
|
|
2008-02-28 03:41:48 +01:00
|
|
|
$template->append('categories', $tpl_cat);
|
2007-01-18 22:10:39 +01:00
|
|
|
}
|
2010-04-21 14:51:48 +02:00
|
|
|
|
|
|
|
trigger_action('loc_end_cat_list');
|
|
|
|
|
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
|
|
|
?>
|