aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--admin/include/functions.php173
-rw-r--r--admin/update.php5
-rw-r--r--include/constants.php1
-rw-r--r--include/functions_category.inc.php90
-rw-r--r--include/functions_user.inc.php17
-rw-r--r--install/dbscheme.txt7
-rw-r--r--install/phpwebgallery_structure.sql13
7 files changed, 60 insertions, 246 deletions
diff --git a/admin/include/functions.php b/admin/include/functions.php
index 84b81e66f..7bc3e52eb 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -275,12 +275,6 @@ function delete_user( $user_id )
$query.= ';';
mysql_query( $query );
- // destruction of the categories informations linked with the user
- $query = 'DELETE FROM '.PREFIX_TABLE.'user_category';
- $query.= ' WHERE user_id = '.$user_id;
- $query.= ';';
- mysql_query( $query );
-
// destruction of the user
$query = 'DELETE FROM '.USERS_TABLE;
$query.= ' WHERE id = '.$user_id;
@@ -631,61 +625,6 @@ function get_all_subcats_ids( $category_id )
}
/**
- * prepares the query to update the table user_category
- *
- * Prepares the query (global variable $values) to update table
- * user_category : for a couple (user,category) the number of sub-categories
- * and the last date of the category (all sub-categories taken into
- * account). It also calls function update_uppercats for each category. The
- * function is recursive.
- *
- * @param array $categories
- * @return void
- */
-function update_user_category( $categories )
-{
- global $page,$user_restrictions,$value_num,$values;
-
- foreach ( $categories as $category ) {
- // recursive call
- update_user_category( $category['subcats'] );
- // 1. update the table user_category
- foreach ( $user_restrictions as $user_id => $restrictions ) {
- // if the category is forbidden to this user, go to next user
- if ( in_array( $category['id'], $restrictions ) ) continue;
-
- // how many sub_categories for this user ?
- $user_subcats = array_diff(
- $page['plain_structure'][$category['id']]['direct_subcats_ids'],
- $restrictions );
- $user_nb_subcats = count( array_unique( $user_subcats ) );
- // last date of the category
- $user_all_subcats = array_unique( array_diff(
- $page['plain_structure'][$category['id']]['all_subcats_ids'],
- $restrictions ) );
-
- $query = 'SELECT MAX(date_last) AS last_date';
- $query.= ' FROM '.CATEGORIES_TABLE;
- $query.= ' WHERE id IN ('.$category['id'];
- if ( count( $user_all_subcats ) > 0 )
- $query.= ','.implode( ',', $user_all_subcats );
- $query.= ')';
- $query.= ';';
- $row = mysql_fetch_array( mysql_query( $query ) );
-
- // insert a new line in database
- if ( $value_num++ > 0 ) $values.= ', ';
- else $values.= ' ';
- $values.= '('.$user_id.",".$category['id'];
- if ( isset( $row['last_date'] ) ) $values.= ",'".$row['last_date']."'";
- else $values.= ',NULL';
- $values.= ','.$user_nb_subcats.')';
- }
- update_uppercats( $category['id'] );
- }
-}
-
-/**
* updates the column categories.uppercats
*
* @param int $category_id
@@ -798,118 +737,6 @@ function get_user_restrictions( $user_id, $user_status,
}
/**
- * finalizes operation for user_category table update
- *
- * This function is called by synchronization_*. It creates the
- * $page['plain_structure'] and $page['structure'], get the SQL query to
- * update user_category, clean user_category, and finally update the
- * table. The users updates depends on the global array $user_restrictions.
- *
- * @return void
- */
-function synchronize()
-{
- global $user_restrictions,$page,$values;
-
- update_user_category( $page['structure'] );
-
- // cleaning user_category table for users to update
- foreach( $user_restrictions as $user_id => $restrictions ) {
- $query = 'DELETE';
- $query.= ' FROM '.USER_CATEGORY_TABLE;
- $query.= ' WHERE user_id = '.$user_id;
- $query.= ';';
- mysql_query( $query );
- }
-
- $query = 'INSERT INTO '.USER_CATEGORY_TABLE;
- $query.= ' (user_id,category_id,date_last,nb_sub_categories) VALUES ';
- $query.= $values;
- $query.= ';';
- mysql_query( $query );
-}
-
-/**
- * synchronizes all users calculated informations
- *
- * fills global array $user_restrictions with all users and related
- * restrictions before calling synchronize.
- *
- * @return void
- */
-function synchronize_all_users()
-{
- global $user_restrictions,$page;
-
- $page['plain_structure'] = get_plain_structure();
- $page['structure'] = create_structure( '' );
-
- $user_restrictions = array();
-
- $query = 'SELECT id';
- $query.= ' FROM '.USERS_TABLE;
- $query.= ';';
- $result = mysql_query( $query );
- while ( $row = mysql_fetch_array( $result ) )
- {
- $user_restrictions[$row['id']] = update_user_restrictions( $row['id'] );
- }
- synchronize();
-}
-
-/**
- * synchronizes 1 user calculated informations
- *
- * fills global array $user_restrictions with the user id and its related
- * restrictions before calling synchronize.
- *
- * @param int $user_id
- * @return void
- */
-function synchronize_user( $user_id )
-{
- global $user_restrictions,$page;
-
- $page['plain_structure'] = get_plain_structure();
- $page['structure'] = create_structure( '' );
-
- $user_restrictions = array();
- $user_restrictions[$user_id] = update_user_restrictions( $user_id );
- synchronize();
-}
-
-/**
- * synchronizes all users (belonging to the group) calculated informations
- *
- * fills global array $user_restrictions with all users and related
- * restrictions before calling synchronize.
- *
- * @return void
- */
-function synchronize_group( $group_id )
-{
- global $user_restrictions,$page;
-
- $page['plain_structure'] = get_plain_structure();
- $page['structure'] = create_structure( '' );
-
- $user_restrictions = array();
-
- $query = 'SELECT id';
- $query.= ' FROM '.USERS_TABLE;
- $query.= ', '.USER_GROUP_TABLE;
- $query.= ' WHERE group_id = '.$group_id;
- $query.= ' AND id = user_id';
- $query.= ';';
- $result = mysql_query( $query );
- while ( $row = mysql_fetch_array( $result ) )
- {
- $user_restrictions[$row['id']] = update_user_restrictions( $row['id'] );
- }
- synchronize();
-}
-
-/**
* updates the calculated data users.forbidden_categories, it includes
* sub-categories of the direct forbidden categories
*
diff --git a/admin/update.php b/admin/update.php
index db8790bdf..e77dd2c72 100644
--- a/admin/update.php
+++ b/admin/update.php
@@ -763,11 +763,6 @@ if ( isset( $_GET['update'] )
ordering('NULL');
$end = get_moment();
echo get_elapsed_time( $start, $end ).' for update_category( all )<br />';
-
- $start = get_moment();
- synchronize_all_users();
- $end = get_moment();
- echo get_elapsed_time( $start, $end ).' for synchronize_all_users<br />';
}
//----------------------------------------------------------- sending html code
$template->assign_var_from_handle('ADMIN_CONTENT', 'update');
diff --git a/include/constants.php b/include/constants.php
index ddc6a639d..fb647d8b3 100644
--- a/include/constants.php
+++ b/include/constants.php
@@ -51,7 +51,6 @@ define('IMAGES_TABLE', $table_prefix.'images');
define('SESSIONS_TABLE', $table_prefix.'sessions');
define('SITES_TABLE', $table_prefix.'sites');
define('USER_ACCESS_TABLE', $table_prefix.'user_access');
-define('USER_CATEGORY_TABLE', $table_prefix.'user_category');
define('USER_GROUP_TABLE', $table_prefix.'user_group');
define('USERS_TABLE', $table_prefix.'users');
define('WAITING_TABLE', $table_prefix.'waiting');
diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php
index 1a153a08d..fbeff41e9 100644
--- a/include/functions_category.inc.php
+++ b/include/functions_category.inc.php
@@ -25,6 +25,21 @@
// | USA. |
// +-----------------------------------------------------------------------+
+/**
+ * Provides functions to handle categories.
+ *
+ *
+ */
+
+/**
+ * Is the category accessible to the connected user ?
+ *
+ * Note : if the user is not authorized to see this category, page creation
+ * ends (exit command in this function)
+ *
+ * @param int category id to verify
+ * @return void
+ */
function check_restrictions( $category_id )
{
global $user,$lang;
@@ -38,10 +53,23 @@ function check_restrictions( $category_id )
}
}
-// the check_cat_id function check whether the $cat is a right parameter :
-// - $cat is numeric and corresponds to a category in the database
-// - $cat equals 'fav' (for favorites)
-// - $cat equals 'search' (when the result of a search is displayed)
+/**
+ * Checks whether the argument is a right parameter category id
+ *
+ * The argument is a right parameter if corresponds to one of these :
+ *
+ * - is numeric and corresponds to a category in the database
+ * - is equals 'fav' (for favorites)
+ * - is equals 'search' (when the result of a search is displayed)
+ * - is equals 'most_visited'
+ * - is equals 'best_rated'
+ * - is equals 'recent'
+ *
+ * The function fills the global var $page['cat'] and returns nothing
+ *
+ * @param mixed category id or special category name
+ * @return void
+ */
function check_cat_id( $cat )
{
global $page;
@@ -78,15 +106,12 @@ function get_user_plain_structure()
{
global $page,$user;
- $infos = array( 'name','id','uc.date_last','nb_images','dir','id_uppercat',
- 'rank','site_id','nb_sub_categories','uppercats');
+ $infos = array( 'name','id','date_last','nb_images','dir','id_uppercat',
+ 'rank','site_id','uppercats');
$query = 'SELECT '.implode( ',', $infos );
- $query.= ' FROM '.CATEGORIES_TABLE.' AS c';
-// $query.= ' ,'.PREFIX_TABLE.'user_category AS uc';
- $query.= ' INNER JOIN '.USER_CATEGORY_TABLE.' AS uc';
- $query.= ' ON c.id = uc.category_id';
- $query.= ' WHERE user_id = '.$user['id'];
+ $query.= ' FROM '.CATEGORIES_TABLE;
+ $query.= ' WHERE 1 = 1'; // stupid but permit using AND after it !
if ( !$user['expand'] )
{
$query.= ' AND (id_uppercat is NULL';
@@ -101,7 +126,6 @@ function get_user_plain_structure()
$query.= ' AND id NOT IN ';
$query.= '('.$user['forbidden_categories'].')';
}
-// $query.= ' AND c.id = uc.category_id';
$query.= ' ORDER BY id_uppercat ASC, rank ASC';
$query.= ';';
@@ -113,15 +137,15 @@ function get_user_plain_structure()
foreach ( $infos as $info ) {
if ( $info == 'uc.date_last')
{
- if (empty($row['date_last']))
- {
- $category['date_last']= 0;
- }
- else
- {
+ if ( empty( $row['date_last'] ) )
+ {
+ $category['date_last'] = 0;
+ }
+ else
+ {
list($year,$month,$day) = explode( '-', $row['date_last'] );
$category['date_last'] = mktime(0,0,0,$month,$day,$year);
- }
+ }
}
else if ( isset( $row[$info] ) ) $category[$info] = $row[$info];
else $category[$info] = '';
@@ -233,17 +257,23 @@ function count_user_total_images()
return $row['total'];
}
-// variables :
-// $cat['comment']
-// $cat['dir']
-// $cat['dir']
-// $cat['name'] is an array :
-// - $cat['name'][0] is the lowest cat name
-// and
-// - $cat['name'][n] is the most uppercat name findable
-// $cat['nb_images']
-// $cat['id_uppercat']
-// $cat['site_id']
+/**
+ * Retrieve informations about a category in the database
+ *
+ * Returns an array with following keys :
+ *
+ * - comment
+ * - dir : directory, might be empty for virtual categories
+ * - name : an array with indexes from 0 (lowest cat name) to n (most
+ * uppercat name findable)
+ * - nb_images
+ * - id_uppercat
+ * - site_id
+ * -
+ *
+ * @param int category id
+ * @return array
+ */
function get_cat_info( $id )
{
$infos = array( 'nb_images','id_uppercat','comment','site_id','galleries_url'
diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php
index 400e104c6..983d7e82e 100644
--- a/include/functions_user.inc.php
+++ b/include/functions_user.inc.php
@@ -153,23 +153,6 @@ function register_user( $login, $password, $password_conf,
$query.= ';';
mysql_query ( $query );
}
- // 6. has the same categories informations than guest
- $query = 'SELECT category_id,date_last,nb_sub_categories';
- $query.= ' FROM '.PREFIX_TABLE.'user_category AS uc';
- $query.= ', '.PREFIX_TABLE.'users AS u';
- $query.= " WHERE u.username = 'guest'";
- $query.= ' AND uc.user_id = u.id';
- $query.= ';';
- $result = mysql_query( $query );
- while( $row = mysql_fetch_array( $result ) )
- {
- $query = 'INSERT INTO '.PREFIX_TABLE.'user_category';
- $query.= ' (user_id,category_id,date_last,nb_sub_categories) VALUES';
- $query.= ' ('.$user_id.','.$row['category_id'];
- $query.= ",'".$row['date_last']."',".$row['nb_sub_categories'].')';
- $query.= ';';
- mysql_query ( $query );
- }
}
return $error;
}
diff --git a/install/dbscheme.txt b/install/dbscheme.txt
index 06c757949..2b9b8addd 100644
--- a/install/dbscheme.txt
+++ b/install/dbscheme.txt
@@ -11,7 +11,6 @@ table:images
table:sessions
table:sites
table:user_access
-table:user_category
table:user_group
table:users
table:waiting
@@ -75,10 +74,6 @@ column:id table:sites type:tinyint
column:galleries_url table:sites type:varchar nullable:Y length:255 binary:N
column:user_id table:user_access type:smallint nullable:Y length:5 signed:N
column:cat_id table:user_access type:smallint nullable:Y length:5 signed:N
-column:user_id table:user_category type:smallint nullable:Y length:5 signed:N
-column:category_id table:user_category type:smallint nullable:Y length:5 signed:N
-column:date_last table:user_category type:date nullable:N
-column:nb_sub_categories table:user_category type:smallint nullable:Y length:5 signed:N
column:user_id table:user_group type:smallint nullable:Y length:5 signed:N
column:group_id table:user_group type:smallint nullable:Y length:5 signed:N
column:id table:users type:smallint nullable:Y length:5 signed:N
@@ -122,8 +117,6 @@ PK:sessions_pk table:sessions column:id
PK:sites_pk table:sites column:id
PK:user_access_pk table:user_access column:user_id
PK:user_access_pk table:user_access column:cat_id
-PK:user_category_pk table:user_category column:user_id
-PK:user_category_pk table:user_category column:category_id
PK:user_group_pk table:user_group column:group_id
PK:user_group_pk table:user_group column:user_id
PK:users_pk table:users column:id
diff --git a/install/phpwebgallery_structure.sql b/install/phpwebgallery_structure.sql
index a6d28e7be..603949488 100644
--- a/install/phpwebgallery_structure.sql
+++ b/install/phpwebgallery_structure.sql
@@ -176,19 +176,6 @@ CREATE TABLE phpwebgallery_user_access (
) TYPE=MyISAM;
--
--- Table structure for table 'phpwebgallery_user_category'
---
-
-DROP TABLE IF EXISTS phpwebgallery_user_category;
-CREATE TABLE phpwebgallery_user_category (
- user_id smallint(5) unsigned NOT NULL default '0',
- category_id smallint(5) unsigned NOT NULL default '0',
- date_last date default NULL,
- nb_sub_categories smallint(5) unsigned NOT NULL default '0',
- PRIMARY KEY (user_id,category_id)
-) TYPE=MyISAM;
-
---
-- Table structure for table 'phpwebgallery_user_group'
--