diff options
author | plegall <plg@piwigo.org> | 2004-12-18 22:05:30 +0000 |
---|---|---|
committer | plegall <plg@piwigo.org> | 2004-12-18 22:05:30 +0000 |
commit | f0e9cd804af6512529982e66f73a27fa7658c46c (patch) | |
tree | d7a2be782e859b9b4e9bdc06069122cc38c95729 | |
parent | 775e9ee74cf910f858f08b24d4b4820ea42bac85 (diff) |
- 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
Diffstat (limited to '')
-rw-r--r-- | admin/cat_list.php | 32 | ||||
-rw-r--r-- | admin/include/functions.php | 55 | ||||
-rw-r--r-- | admin/infos_images.php | 42 | ||||
-rw-r--r-- | include/config.inc.php | 4 | ||||
-rw-r--r-- | include/functions_category.inc.php | 2 | ||||
-rw-r--r-- | include/functions_html.inc.php | 3 | ||||
-rw-r--r-- | include/functions_session.inc.php | 8 | ||||
-rw-r--r-- | include/functions_user.inc.php | 39 | ||||
-rw-r--r-- | include/user.inc.php | 25 | ||||
-rw-r--r-- | install/dbscheme.txt | 5 | ||||
-rw-r--r-- | install/phpwebgallery_structure.sql | 3 | ||||
-rw-r--r-- | language/en_UK.iso-8859-1/admin.lang.php | 3 | ||||
-rw-r--r-- | template/default/admin/infos_images.tpl | 12 |
13 files changed, 109 insertions, 124 deletions
diff --git a/admin/cat_list.php b/admin/cat_list.php index d92575fe8..2f7834730 100644 --- a/admin/cat_list.php +++ b/admin/cat_list.php @@ -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) + +if (count($categories) > 0) { - $ranks[$category['id']] = $category['rank']; -} + foreach ($categories as $category) + { + $ranks[$category['id']] = $category['rank']; + } -$query = ' + $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) diff --git a/admin/include/functions.php b/admin/include/functions.php index 1191f1f6f..1e8926aee 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -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); diff --git a/admin/infos_images.php b/admin/infos_images.php index ef02c91b7..9a7ab5590 100644 --- a/admin/infos_images.php +++ b/admin/infos_images.php @@ -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, ' '); - $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'); diff --git a/include/config.inc.php b/include/config.inc.php index e5926578d..22d205fad 100644 --- a/include/config.inc.php +++ b/include/config.inc.php @@ -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; ?> diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php index 2fd502120..f08a2fa27 100644 --- a/include/functions_category.inc.php +++ b/include/functions_category.inc.php @@ -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'; diff --git a/include/functions_html.inc.php b/include/functions_html.inc.php index f1b76169f..c60abc778 100644 --- a/include/functions_html.inc.php +++ b/include/functions_html.inc.php @@ -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.'&start='.$temp_start); $navbar.= '" class="'.$link_class.'">'.$lang['last_page']; diff --git a/include/functions_session.inc.php b/include/functions_session.inc.php index aa454d3ea..bbbb739cd 100644 --- a/include/functions_session.inc.php +++ b/include/functions_session.inc.php @@ -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; diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php index 1581ff28f..c00ba2f4a 100644 --- a/include/functions_user.inc.php +++ b/include/functions_user.inc.php @@ -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); + } +} ?> diff --git a/include/user.inc.php b/include/user.inc.php index 3500ff186..eb5540f8b 100644 --- a/include/user.inc.php +++ b/include/user.inc.php @@ -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 { diff --git a/install/dbscheme.txt b/install/dbscheme.txt index 9aae6234c..8caeb48e6 100644 --- a/install/dbscheme.txt +++ b/install/dbscheme.txt @@ -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 diff --git a/install/phpwebgallery_structure.sql b/install/phpwebgallery_structure.sql index da5f45b55..4bf05af9c 100644 --- a/install/phpwebgallery_structure.sql +++ b/install/phpwebgallery_structure.sql @@ -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; diff --git a/language/en_UK.iso-8859-1/admin.lang.php b/language/en_UK.iso-8859-1/admin.lang.php index 28f60a3bb..dac80109e 100644 --- a/language/en_UK.iso-8859-1/admin.lang.php +++ b/language/en_UK.iso-8859-1/admin.lang.php @@ -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'; diff --git a/template/default/admin/infos_images.tpl b/template/default/admin/infos_images.tpl index 0d6ac2e21..33da3f8b4 100644 --- a/template/default/admin/infos_images.tpl +++ b/template/default/admin/infos_images.tpl @@ -78,15 +78,13 @@ <!-- END picture --> <tr> <td colspan="7"> - <img src="./template/default/admin/images/arrow_select.gif" alt="<" /> + <img src="./template/default/admin/images/arrow_select.gif" alt="↑" /> {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> |