- bug fixed : in admin/cat_list, next_rank cant' be calculted and query to

count sub-categories per sub-categories became false if no sub-categories

- virtual association come back in admin/infos_images (not only in
  admin/picture_modify)

- check_favorites function in admin section becomes check_user_favorites in
  public section : favorites are checked when user tries to display his
  favorites. Function was optimized.

- in function update_category, wrap of long queries due to many categories
  to update at the same time

- typo fixed in description of paginate_pages_around configuration parameter

- bug fixed in new navigation bar : no separation pipe was displayed between
  next and last when the page displayed was the last

- sessions.expiration changed of type from int to datetime (a lot easier to
  read)

- sessions.ip removed : IP address is no longer used to verify session

- $lang['cat_options'] was missing in en_UK.iso-8859-1

- typo fixed in language/en_UK.iso-8859-1/admin.lang.php on
  editcat_lock_info language item


git-svn-id: http://piwigo.org/svn/trunk@647 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
plegall 2004-12-18 22:05:30 +00:00
parent 775e9ee74c
commit f0e9cd804a
13 changed files with 110 additions and 125 deletions

View file

@ -327,9 +327,18 @@ if (isset($_GET['parent_id']))
$form_action.= '&parent_id='.$_GET['parent_id'];
}
if (count($categories) > 0)
{
$next_rank = max(array_keys($categories)) + 1;
}
else
{
$next_rank = 1;
}
$template->assign_vars(array(
'CATEGORIES_NAV'=>$navigation,
'NEXT_RANK'=>max(array_keys($categories))+1,
'NEXT_RANK'=>$next_rank,
'F_ACTION'=>$form_action,
'L_ADD_VIRTUAL'=>$lang['cat_add'],
@ -367,21 +376,26 @@ if (count($infos) != 0)
// | Categories display |
// +-----------------------------------------------------------------------+
$ranks = array();
foreach ($categories as $category)
{
$ranks[$category['id']] = $category['rank'];
}
$query = '
if (count($categories) > 0)
{
foreach ($categories as $category)
{
$ranks[$category['id']] = $category['rank'];
}
$query = '
SELECT id_uppercat, COUNT(*) AS nb_subcats
FROM '. CATEGORIES_TABLE.'
WHERE id_uppercat IN ('.implode(',', array_keys($ranks)).')
GROUP BY id_uppercat
;';
$result = pwg_query($query);
while ($row = mysql_fetch_array($result))
{
$categories[$ranks[$row['id_uppercat']]]['nb_subcats'] = $row['nb_subcats'];
$result = pwg_query($query);
while ($row = mysql_fetch_array($result))
{
$categories[$ranks[$row['id_uppercat']]]['nb_subcats']
= $row['nb_subcats'];
}
}
foreach ($categories as $category)

View file

@ -391,55 +391,6 @@ function delete_group( $group_id )
pwg_query( $query );
}
// The check_favorites function deletes all the favorites of a user if he is
// not allowed to see them (the category or an upper category is restricted
// or invisible)
function check_favorites( $user_id )
{
$query = 'SELECT status,forbidden_categories';
$query.= ' FROM '.USERS_TABLE;
$query.= ' WHERE id = '.$user_id;
$query.= ';';
$row = mysql_fetch_array( pwg_query( $query ) );
$status = $row['status'];
// retrieving all the restricted categories for this user
if ( isset( $row['forbidden_categories'] ) )
$restricted_cat = explode( ',', $row['forbidden_categories'] );
else
$restricted_cat = array();
// retrieving all the favorites for this user and comparing their
// categories to the restricted categories
$query = 'SELECT image_id FROM '.FAVORITES_TABLE;
$query.= ' WHERE user_id = '.$user_id;
$query.= ';';
$result = pwg_query ( $query );
while ( $row = mysql_fetch_array( $result ) )
{
// for each picture, we have to check all the categories it belongs
// to. Indeed if a picture belongs to category_1 and category_2 and that
// category_2 is not restricted to the user, he can have the picture as
// favorite.
$query = 'SELECT DISTINCT(category_id) as category_id';
$query.= ' FROM '.PREFIX_TABLE.'image_category';
$query.= ' WHERE image_id = '.$row['image_id'];
$query.= ';';
$picture_result = pwg_query( $query );
$picture_cat = array();
while ( $picture_row = mysql_fetch_array( $picture_result ) )
{
array_push( $picture_cat, $picture_row['category_id'] );
}
if ( count( array_diff( $picture_cat, $restricted_cat ) ) == 0 )
{
$query = 'DELETE FROM '.FAVORITES_TABLE;
$query.= ' WHERE image_id = '.$row['image_id'];
$query.= ' AND user_id = '.$user_id;
$query.= ';';
pwg_query( $query );
}
}
}
/**
* updates calculated informations about a set of categories : date_last and
* nb_images. It also verifies that the representative picture is really
@ -479,7 +430,7 @@ SELECT id
else
{
$query.= '
WHERE id IN ('.implode(',', $ids).')';
WHERE id IN ('.wordwrap(implode(', ', $ids), 80, "\n").')';
}
}
$query.= '
@ -502,7 +453,7 @@ 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
WHERE category_id IN ('.implode(',', $cat_ids).')
WHERE category_id IN ('.wordwrap(implode(', ', $cat_ids), 80, "\n").')
GROUP BY category_id
;';
$result = pwg_query($query);
@ -542,7 +493,7 @@ SELECT id
FROM '.CATEGORIES_TABLE.' LEFT JOIN '.IMAGE_CATEGORY_TABLE.'
ON id = category_id AND representative_picture_id = image_id
WHERE representative_picture_id IS NOT NULL
AND id IN ('.implode(',', $cat_ids).')
AND id IN ('.wordwrap(implode(', ', $cat_ids), 80, "\n").')
AND category_id IS NULL
;';
$result = pwg_query($query);

View file

@ -60,8 +60,6 @@ if (isset($page['cat']))
}
}
$associate = false;
$query = 'SELECT id,file FROM '.IMAGES_TABLE;
$query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id';
$query.= ' WHERE category_id = '.$page['cat'];
@ -111,18 +109,21 @@ if (isset($page['cat']))
pwg_query($query);
}
// add link to another category
if (isset($_POST['check-'.$row['id']]) and count($errors) == 0)
if (isset($_POST['check-'.$row['id']])
and isset($_POST['associate'])
and $_POST['associate'] != '')
{
$query = 'INSERT INTO '.IMAGE_CATEGORY_TABLE;
$query.= ' (image_id,category_id) VALUES';
$query.= ' ('.$row['id'].','.$_POST['associate'].')';
$query.= ';';
pwg_query($query);
$associate = true;
}
}
if (isset($_POST['associate'])) update_category($_POST['associate']);
if ($associate) synchronize_all_users();
if (isset($_POST['associate']) and $_POST['associate'] != '')
{
update_category(array($_POST['associate']));
}
// +-----------------------------------------------------------------------+
// | update general options |
// +-----------------------------------------------------------------------+
@ -336,27 +337,14 @@ SELECT *
}
// Virtualy associate a picture to a category
//
// We only show a List Of Values if the number of categories is less than
// $conf['max_LOV_categories']
$query = 'SELECT COUNT(id) AS nb_total_categories';
$query.= ' FROM '.CATEGORIES_TABLE.';';
$row = mysql_fetch_array(pwg_query($query));
if ($row['nb_total_categories'] < $conf['max_LOV_categories'])
{
/*$vtp->addSession($sub, 'associate_LOV');
$page['plain_structure'] = get_plain_structure(true);
$structure = create_structure('', array());
display_categories($structure, '&nbsp;');
$vtp->closeSession($sub, 'associate_LOV');*/
}
// else, we only display a small text field, we suppose the administrator
// knows the id of its category
else
{
//$vtp->addSession($sub, 'associate_text');
//$vtp->closeSession($sub, 'associate_text');
}
$query = '
SELECT id,name,uppercats,global_rank
FROM '.CATEGORIES_TABLE.'
;';
display_select_cat_wrapper($query,
array(),
'associate_option',
true);
}
//----------------------------------------------------------- sending html code
$template->assign_var_from_handle('ADMIN_CONTENT', 'infos_images');

View file

@ -190,7 +190,7 @@ $conf['newcat_default_status'] = 'public';
// to the sub level
$conf['level_separator'] = ' / ';
// paginate_pages_around : on paginate navigation bar, on many pages display
// before and after the current page ?
// paginate_pages_around : on paginate navigation bar, how many pages
// display before and after the current page ?
$conf['paginate_pages_around'] = 2;
?>

View file

@ -561,6 +561,8 @@ SELECT COUNT(DISTINCT(id)) AS nb_total_images
// favorites displaying
else if ( $page['cat'] == 'fav' )
{
check_user_favorites();
$page['title'] = $lang['favorites'];
$page['where'] = ', '.FAVORITES_TABLE.' AS fav';

View file

@ -158,11 +158,12 @@ function create_navigation_bar($url, $nb_element, $start,
{
$navbar.= $lang['next_page'];
}
$navbar.= ' | ';
// link to last page ?
if ($cur_page != $maximum)
{
$temp_start = ($maximum - 1) * $nb_element_page;
$navbar.= ' | ';
$navbar.= '<a href="';
$navbar.= add_session_id($url.'&amp;start='.$temp_start);
$navbar.= '" class="'.$link_class.'">'.$lang['last_page'];

View file

@ -86,16 +86,16 @@ SELECT id
}
}
// 3. inserting session in database
$expiration = $session_length + time();
$query = '
INSERT INTO '.SESSIONS_TABLE.'
(id,user_id,expiration,ip)
(id,user_id,expiration)
VALUES
(\''.$generated_id.'\','.$userid.','.$expiration.',
\''.$_SERVER['REMOTE_ADDR'].'\')
(\''.$generated_id.'\','.$userid.',
ADDDATE(NOW(), INTERVAL '.$session_length.' SECOND))
;';
pwg_query($query);
$expiration = $session_length + time();
setcookie('id', $generated_id, $expiration, cookie_path());
return $generated_id;

View file

@ -237,4 +237,43 @@ function getuserdata($user)
$result = pwg_query($sql);
return ( $row = mysql_fetch_array($result) ) ? $row : false;
}
/*
* deletes favorites of the current user if he's not allowed to see them
*
* @return void
*/
function check_user_favorites()
{
global $user;
if ($user['forbidden_categories'] == '')
{
return;
}
$query = '
SELECT f.image_id
FROM '.FAVORITES_TABLE.' AS f INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic
ON f.image_id = ic.image_id
WHERE f.user_id = '.$user['id'].'
AND ic.category_id IN ('.$user['forbidden_categories'].')
;';
$result = pwg_query($query);
$elements = array();
while ($row = mysql_fetch_array($result))
{
array_push($elements, $row['image_id']);
}
if (count($elements) > 0)
{
$query = '
DELETE FROM '.FAVORITES_TABLE.'
WHERE image_id IN ('.implode(',', $elements).')
AND user_id = '.$user['id'].'
;';
pwg_query($query);
}
}
?>

View file

@ -59,7 +59,7 @@ if (isset($session_id)
{
$page['session_id'] = $session_id;
$query = '
SELECT user_id,expiration,ip
SELECT user_id,expiration,NOW() AS now
FROM '.SESSIONS_TABLE.'
WHERE id = \''.$page['session_id'].'\'
;';
@ -67,22 +67,15 @@ SELECT user_id,expiration,ip
if (mysql_num_rows($result) > 0)
{
$row = mysql_fetch_array($result);
if (!$user['has_cookie'])
if (strnatcmp($row['expiration'], $row['now']) < 0)
{
if ($row['expiration'] < time())
{
// deletion of the session from the database,
// because it is out-of-date
$delete_query = 'DELETE FROM '.SESSIONS_TABLE;
$delete_query.= " WHERE id = '".$page['session_id']."'";
$delete_query.= ';';
pwg_query($delete_query);
}
else if ($_SERVER['REMOTE_ADDR'] == $row['ip'])
{
$query_user .= ' WHERE id = '.$row['user_id'];
$query_done = true;
}
// deletion of the session from the database, because it is
// out-of-date
$delete_query = '
DELETE FROM '.SESSIONS_TABLE.'
WHERE id = \''.$page['session_id'].'\'
;';
pwg_query($delete_query);
}
else
{

View file

@ -78,8 +78,7 @@ column:element_id table:rate type:mediumint
column:rate table:rate type:tinyint nullable:N length:2 signed:N
column:id table:sessions type:varchar nullable:N length:255 binary:Y
column:user_id table:sessions type:smallint nullable:N length:5 signed:N
column:expiration table:sessions type:int nullable:N length:10 signed:N
column:ip table:sessions type:varchar nullable:N length:255 binary:N
column:expiration table:sessions type:datetime nullable:N
column:id table:sites type:tinyint nullable:N length:4 signed:Y
column:galleries_url table:sites type:varchar nullable:N length:255 binary:N
column:user_id table:user_access type:smallint nullable:N length:5 signed:N
@ -119,7 +118,6 @@ PK:favorites_pk table:favorites column:image_id
PK:group_access_pk table:group_access column:group_id
PK:group_access_pk table:group_access column:cat_id
PK:groups_pk table:groups column:id
PK:history_pk table:history column:date
PK:image_category_pk table:image_category column:image_id
PK:image_category_pk table:image_category column:category_id
PK:images_pk table:images column:id
@ -135,6 +133,7 @@ PK:users_pk table:users column:id
PK:waiting_pk table:waiting column:id
index:categories_i2 table:categories column:id_uppercat
index:history_i1 table:history column:date
index:image_category_i1 table:image_category column:image_id
index:image_category_i2 table:image_category column:category_id
index:images_i2 table:images column:date_available

View file

@ -170,8 +170,7 @@ DROP TABLE IF EXISTS phpwebgallery_sessions;
CREATE TABLE phpwebgallery_sessions (
id varchar(255) binary NOT NULL default '',
user_id smallint(5) unsigned NOT NULL default '0',
expiration int(10) unsigned NOT NULL default '0',
ip varchar(255) NOT NULL default '',
expiration datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (id)
) TYPE=MyISAM;

View file

@ -87,6 +87,7 @@ $lang['remote_site_local_update'] = 'read local listing.xml and update';
// Categories
$lang['cat_security'] = 'Public / Private';
$lang['cat_options'] = 'Category options';
$lang['cat_add'] = 'Add a virtual category';
$lang['cat_virtual'] = 'Virtual category';
$lang['cat_public'] = 'Public category';
@ -95,7 +96,7 @@ $lang['cat_image_info'] = 'Images info';
$lang['editcat_status'] = 'Status';
$lang['editcat_confirm'] = 'Category informations updated successfully.';
$lang['editcat_perm'] = 'To set permissions for this category, click';
$lang['editcat_lock_info'] = 'The category and its sub-categories will temporary been disabled for maintenance.'
$lang['editcat_lock_info'] = 'The category and its sub-categories will temporary been disabled for maintenance.';
$lang['editcat_uploadable'] = 'Authorize upload';
$lang['editcat_uploadable_info'] = 'Authorize users to upload files';
$lang['editcat_commentable_info'] = 'Authorize users to comment elements of this category';

View file

@ -78,15 +78,13 @@
<!-- END picture -->
<tr>
<td colspan="7">
<img src="./template/default/admin/images/arrow_select.gif" alt="&lt;" />
<img src="./template/default/admin/images/arrow_select.gif" alt="&uarr;" />
{L_INFOS_ASSOCIATE}
<!-- BEGIN associate_LOV -->
<select name="associate">
<!-- BEGIN associate_cat -->
<option value="{#value}">{#content}</option>
<!-- END associate_cat -->
<select style="width:400px" name="associate" size="1">
<!-- BEGIN associate_option -->
<option {associate_option.SELECTED} value="{associate_option.VALUE}">{associate_option.OPTION}</option>
<!-- END category_option -->
</select>
<!-- END associate_LOV -->
</td>
</tr>
<tr>