Changeset 496 for trunk/admin/include/functions.php
- Timestamp:
- Aug 26, 2004, 12:25:58 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/functions.php
r491 r496 556 556 557 557 /** 558 * Complete plain structure of the gallery559 *560 * Returns the plain structure (one level array) of the gallery. In the561 * returned array, each element is an array with jeys 'id' and562 * 'id_uppercat'. The function also fills the array $page['subcats'] which563 * associate (category_id => array of sub-categories id).564 *565 * @param bool $use_name566 * @return array567 */568 function get_plain_structure( $use_name = false )569 {570 global $page;571 572 $plain_structure = array();573 574 $query = 'SELECT id,id_uppercat';575 if ( $use_name ) $query.= ',name';576 $query.= ' FROM '.CATEGORIES_TABLE;577 $query.= ' ORDER BY id_uppercat ASC, rank ASC';578 $query.= ';';579 580 $subcats = array();581 $id_uppercat = 'NULL';582 583 $result = mysql_query( $query );584 while ( $row = mysql_fetch_array( $result ) )585 {586 $plain_structure[$row['id']]['id'] = $row['id'];587 if ( !isset( $row['id_uppercat'] ) ) $row['id_uppercat'] = 'NULL';588 $plain_structure[$row['id']]['id_uppercat'] = $row['id_uppercat'];589 if ( $use_name ) $plain_structure[$row['id']]['name'] = $row['name'];590 // subcats list591 if ( $row['id_uppercat'] != $id_uppercat )592 {593 $page['subcats'][$id_uppercat] = $subcats;594 595 $subcats = array();596 $id_uppercat = $row['id_uppercat'];597 }598 array_push( $subcats, $row['id'] );599 }600 mysql_free_result( $result );601 602 $page['subcats'][$id_uppercat] = $subcats;603 604 return $plain_structure;605 }606 607 /**608 * get N levels array representing structure under the given category609 *610 * create_structure returns the N levels array representing structure under611 * the given gategory id. It also updates the612 * $page['plain_structure'][id]['all_subcats_id'] and613 * $page['plain_structure'][id]['direct_subcats_ids'] for each sub category.614 *615 * @param int $id_uppercat616 * @return array617 */618 function create_structure( $id_uppercat )619 {620 global $page;621 622 $structure = array();623 $ids = get_subcats_ids( $id_uppercat );624 foreach ( $ids as $id ) {625 $category = $page['plain_structure'][$id];626 627 $category['subcats'] = create_structure( $id );628 629 $page['plain_structure'][$id]['all_subcats_ids'] =630 get_all_subcats_ids( $id );631 632 $page['plain_structure'][$id]['direct_subcats_ids'] =633 get_subcats_ids( $id );634 635 array_push( $structure, $category );636 }637 return $structure;638 }639 640 /**641 * returns direct sub-categories ids642 *643 * Returns an array containing all the direct sub-categories ids of the644 * given category. It uses the $page['subcats'] global array.645 *646 * @param int $id_uppercat647 * @return array648 */649 function get_subcats_ids( $id_uppercat )650 {651 global $page;652 653 if ( $id_uppercat == '' ) $id_uppercat = 'NULL';654 655 if ( isset( $page['subcats'][$id_uppercat] ) )656 return $page['subcats'][$id_uppercat];657 else658 return array();659 }660 661 /**662 * returns all sub-categories ids, not only direct ones663 *664 * Returns an array containing all the sub-categories ids of the given665 * category, not only direct ones. This function is recursive.666 *667 * @param int $category_id668 * @return array669 */670 function get_all_subcats_ids( $category_id )671 {672 $ids = array();673 674 $subcats = get_subcats_ids( $category_id );675 $ids = array_merge( $ids, $subcats );676 foreach ( $subcats as $subcat ) {677 // recursive call678 $sub_subcats = get_all_subcats_ids( $subcat );679 $ids = array_merge( $ids, $sub_subcats );680 }681 return array_unique( $ids );682 }683 684 /**685 * updates the column categories.uppercats686 *687 * @param int $category_id688 * @return void689 */690 function update_uppercats( $category_id )691 {692 global $page;693 694 $final_id = $category_id;695 $uppercats = array();696 697 array_push( $uppercats, $category_id );698 $uppercat = $page['plain_structure'][$category_id]['id_uppercat'];699 700 while ( $uppercat != 'NULL' )701 {702 array_push( $uppercats, $uppercat );703 $category_id = $page['plain_structure'][$category_id]['id_uppercat'];704 $uppercat = $page['plain_structure'][$category_id]['id_uppercat'];705 }706 707 $string_uppercats = implode( ',', array_reverse( $uppercats ) );708 $query = 'UPDATE '.CATEGORIES_TABLE;709 $query.= ' SET uppercats = '."'".$string_uppercats."'";710 $query.= ' WHERE id = '.$final_id;711 $query.= ';';712 mysql_query( $query );713 }714 715 /**716 558 * returns an array with the ids of the restricted categories for the user 717 559 *
Note: See TracChangeset
for help on using the changeset viewer.