Ignore:
Timestamp:
Apr 9, 2010, 9:47:29 PM (14 years ago)
Author:
plg
Message:

feature 1591: smarter default categories in upload form. We use the most
recently added photo as reference.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/photos_add_direct.php

    r5742 r5743  
    380380}
    381381
     382// categories
     383//
     384// we need to know the category in which the last photo was added
     385$selected_category = array();
     386$selected_parent = array();
     387
     388$query = '
     389SELECT
     390    category_id,
     391    id_uppercat
     392  FROM '.IMAGES_TABLE.' AS i
     393    JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON image_id = i.id
     394    JOIN '.CATEGORIES_TABLE.' AS c ON category_id = c.id
     395  ORDER BY i.id DESC
     396  LIMIT 1
     397;';
     398$result = pwg_query($query);
     399if (pwg_db_num_rows($result) > 0)
     400{
     401  $row = pwg_db_fetch_assoc($result);
     402 
     403  $selected_category = array($row['category_id']);
     404
     405  if (!empty($row['id_uppercat']))
     406  {
     407    $selected_parent = array($row['id_uppercat']);
     408  }
     409}
     410
     411// existing category
    382412$query = '
    383413SELECT id,name,uppercats,global_rank
     
    387417display_select_cat_wrapper(
    388418  $query,
    389   array(),
     419  $selected_category,
    390420  'category_options'
    391421  );
     422
     423// new category
     424display_select_cat_wrapper(
     425  $query,
     426  $selected_parent,
     427  'category_parent_options'
     428  );
     429
    392430
    393431// image level options
Note: See TracChangeset for help on using the changeset viewer.