Changeset 423 for trunk/admin/include/functions.php
- Timestamp:
- May 28, 2004, 11:56:07 PM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/functions.php
r394 r423 276 276 mysql_query( $query ); 277 277 278 // destruction of the categories informations linked with the user279 $query = 'DELETE FROM '.PREFIX_TABLE.'user_category';280 $query.= ' WHERE user_id = '.$user_id;281 $query.= ';';282 mysql_query( $query );283 284 278 // destruction of the user 285 279 $query = 'DELETE FROM '.USERS_TABLE; … … 632 626 633 627 /** 634 * prepares the query to update the table user_category635 *636 * Prepares the query (global variable $values) to update table637 * user_category : for a couple (user,category) the number of sub-categories638 * and the last date of the category (all sub-categories taken into639 * account). It also calls function update_uppercats for each category. The640 * function is recursive.641 *642 * @param array $categories643 * @return void644 */645 function update_user_category( $categories )646 {647 global $page,$user_restrictions,$value_num,$values;648 649 foreach ( $categories as $category ) {650 // recursive call651 update_user_category( $category['subcats'] );652 // 1. update the table user_category653 foreach ( $user_restrictions as $user_id => $restrictions ) {654 // if the category is forbidden to this user, go to next user655 if ( in_array( $category['id'], $restrictions ) ) continue;656 657 // how many sub_categories for this user ?658 $user_subcats = array_diff(659 $page['plain_structure'][$category['id']]['direct_subcats_ids'],660 $restrictions );661 $user_nb_subcats = count( array_unique( $user_subcats ) );662 // last date of the category663 $user_all_subcats = array_unique( array_diff(664 $page['plain_structure'][$category['id']]['all_subcats_ids'],665 $restrictions ) );666 667 $query = 'SELECT MAX(date_last) AS last_date';668 $query.= ' FROM '.CATEGORIES_TABLE;669 $query.= ' WHERE id IN ('.$category['id'];670 if ( count( $user_all_subcats ) > 0 )671 $query.= ','.implode( ',', $user_all_subcats );672 $query.= ')';673 $query.= ';';674 $row = mysql_fetch_array( mysql_query( $query ) );675 676 // insert a new line in database677 if ( $value_num++ > 0 ) $values.= ', ';678 else $values.= ' ';679 $values.= '('.$user_id.",".$category['id'];680 if ( isset( $row['last_date'] ) ) $values.= ",'".$row['last_date']."'";681 else $values.= ',NULL';682 $values.= ','.$user_nb_subcats.')';683 }684 update_uppercats( $category['id'] );685 }686 }687 688 /**689 628 * updates the column categories.uppercats 690 629 * … … 799 738 800 739 /** 801 * finalizes operation for user_category table update802 *803 * This function is called by synchronization_*. It creates the804 * $page['plain_structure'] and $page['structure'], get the SQL query to805 * update user_category, clean user_category, and finally update the806 * table. The users updates depends on the global array $user_restrictions.807 *808 * @return void809 */810 function synchronize()811 {812 global $user_restrictions,$page,$values;813 814 update_user_category( $page['structure'] );815 816 // cleaning user_category table for users to update817 foreach( $user_restrictions as $user_id => $restrictions ) {818 $query = 'DELETE';819 $query.= ' FROM '.USER_CATEGORY_TABLE;820 $query.= ' WHERE user_id = '.$user_id;821 $query.= ';';822 mysql_query( $query );823 }824 825 $query = 'INSERT INTO '.USER_CATEGORY_TABLE;826 $query.= ' (user_id,category_id,date_last,nb_sub_categories) VALUES ';827 $query.= $values;828 $query.= ';';829 mysql_query( $query );830 }831 832 /**833 * synchronizes all users calculated informations834 *835 * fills global array $user_restrictions with all users and related836 * restrictions before calling synchronize.837 *838 * @return void839 */840 function synchronize_all_users()841 {842 global $user_restrictions,$page;843 844 $page['plain_structure'] = get_plain_structure();845 $page['structure'] = create_structure( '' );846 847 $user_restrictions = array();848 849 $query = 'SELECT id';850 $query.= ' FROM '.USERS_TABLE;851 $query.= ';';852 $result = mysql_query( $query );853 while ( $row = mysql_fetch_array( $result ) )854 {855 $user_restrictions[$row['id']] = update_user_restrictions( $row['id'] );856 }857 synchronize();858 }859 860 /**861 * synchronizes 1 user calculated informations862 *863 * fills global array $user_restrictions with the user id and its related864 * restrictions before calling synchronize.865 *866 * @param int $user_id867 * @return void868 */869 function synchronize_user( $user_id )870 {871 global $user_restrictions,$page;872 873 $page['plain_structure'] = get_plain_structure();874 $page['structure'] = create_structure( '' );875 876 $user_restrictions = array();877 $user_restrictions[$user_id] = update_user_restrictions( $user_id );878 synchronize();879 }880 881 /**882 * synchronizes all users (belonging to the group) calculated informations883 *884 * fills global array $user_restrictions with all users and related885 * restrictions before calling synchronize.886 *887 * @return void888 */889 function synchronize_group( $group_id )890 {891 global $user_restrictions,$page;892 893 $page['plain_structure'] = get_plain_structure();894 $page['structure'] = create_structure( '' );895 896 $user_restrictions = array();897 898 $query = 'SELECT id';899 $query.= ' FROM '.USERS_TABLE;900 $query.= ', '.USER_GROUP_TABLE;901 $query.= ' WHERE group_id = '.$group_id;902 $query.= ' AND id = user_id';903 $query.= ';';904 $result = mysql_query( $query );905 while ( $row = mysql_fetch_array( $result ) )906 {907 $user_restrictions[$row['id']] = update_user_restrictions( $row['id'] );908 }909 synchronize();910 }911 912 /**913 740 * updates the calculated data users.forbidden_categories, it includes 914 741 * sub-categories of the direct forbidden categories
Note: See TracChangeset
for help on using the changeset viewer.