source: trunk/include/category_subcats.inc.php @ 966

Last change on this file since 966 was 809, checked in by plg, 19 years ago
  • new : maintenance screen in administration. There you can update categories informations (number of images, date of the last added element), update images informations (path, average rate), purge obsolete sessions, purge history.
  • new : ability to have random representative for categories. This configuration parameter is set to false by default.
  • new : ability to set an element as representative of a category without belonging to the category. Thus, administrator can choose representative even for empty categories.
  • improvement : semantically superior design for category edition screen by regrouping fields in fieldsets. The improved screen contains action buttons as in category list screen.
  • new : ability to move a virtual category (ie change its parent category).
  • bug fixed : the sync_users function checks all user children tables (access, cache, group association).
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.1 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2005-08-13 23:09:54 +0000 (Sat, 13 Aug 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 809 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28/**
29 * This file is included by category.php to show thumbnails for a category
30 * that have only subcategories
31 *
32 */
33
34$query = '
35SELECT id, name, date_last, representative_picture_id
36  FROM '.CATEGORIES_TABLE.'
37  WHERE id_uppercat ';
38if (!isset($page['cat']) or !is_numeric($page['cat']))
39{
40  $query.= 'is NULL';
41}
42else
43{
44  $query.= '= '.$page['cat'];
45}
46  $query.= '
47    AND id NOT IN ('.$user['forbidden_categories'].')
48  ORDER BY rank
49;';
50$result = pwg_query($query);
51
52// $conf['allow_random_representative']
53
54$cat_thumbnails = array();
55
56while ($row = mysql_fetch_array($result))
57{
58  if (isset($row['representative_picture_id'])
59      and is_numeric($row['representative_picture_id']))
60  {
61    // if a representative picture is set, it has priority
62    $image_id = $row['representative_picture_id'];
63  }
64  else if ($conf['allow_random_representative'])
65  {
66    // searching a random representant among elements in sub-categories
67    $query = '
68SELECT image_id
69  FROM '.CATEGORIES_TABLE.' AS c INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic
70    ON ic.category_id = c.id
71  WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\'
72    AND c.id NOT IN ('.$user['forbidden_categories'].')
73  ORDER BY RAND()
74  LIMIT 0,1
75;';
76    $subresult = pwg_query($query);
77    if (mysql_num_rows($result) > 0)
78    {
79      list($image_id) = mysql_fetch_row($subresult);
80    }
81  }
82  else
83  {
84    // searching a random representant among representant of sub-categories
85    $query = '
86SELECT representative_picture_id
87  FROM '.CATEGORIES_TABLE.'
88  WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\'
89    AND id NOT IN ('.$user['forbidden_categories'].')
90    AND representative_picture_id IS NOT NULL
91  ORDER BY RAND()
92  LIMIT 0,1
93;';
94    $subresult = pwg_query($query);
95    if (mysql_num_rows($subresult) > 0)
96    {
97      list($image_id) = mysql_fetch_row($subresult);
98    }
99  }
100
101  if (isset($image_id))
102  {
103    array_push(
104      $cat_thumbnails,
105      array(
106        'category' => $row['id'],
107        'picture' => $image_id,
108        'name' => $row['name'],
109        'date_last' => @$row['date_last']
110        )
111      );
112  }
113
114  unset($image_id);
115}
116
117if (count($cat_thumbnails) > 0)
118{
119  $images = array();
120 
121  foreach ($cat_thumbnails as $item)
122  {
123    $images[$item['picture']] = '';
124  }
125
126  $query = '
127SELECT id, path, tn_ext
128  FROM '.IMAGES_TABLE.'
129  WHERE id IN ('.implode(',', array_keys($images)).')
130;';
131  $result = pwg_query($query);
132  while ($row = mysql_fetch_array($result))
133  {
134    $images[$row['id']] = get_thumbnail_src($row['path'], @$row['tn_ext']);
135  }
136
137  $template->assign_block_vars('thumbnails', array());
138  // first line
139  $template->assign_block_vars('thumbnails.line', array());
140  // current row displayed
141  $row_number = 0;
142 
143  foreach ($cat_thumbnails as $item)
144  {
145    $url_link = PHPWG_ROOT_PATH.'category.php?cat='.$row['id'];
146
147    $template->assign_block_vars(
148      'thumbnails.line.thumbnail',
149      array(
150        'IMAGE' => $images[$item['picture']],
151        'IMAGE_ALT' => $item['name'],
152        'IMAGE_TITLE' => $lang['hint_category'],
153        'IMAGE_TS' => get_icon(@$item['date_last']),
154        'U_IMG_LINK' =>
155          add_session_id(PHPWG_ROOT_PATH.'category.php?cat='.$item['category'])
156        )
157      );
158   
159    $template->assign_block_vars(
160      'thumbnails.line.thumbnail.category_name',
161      array(
162        'NAME' => $item['name']
163        )
164      );
165   
166    // create a new line ?
167    if (++$row_number == $user['nb_image_line'])
168    {
169      $template->assign_block_vars('thumbnails.line', array());
170      $row_number = 0;
171    }
172  }
173}
174?>
Note: See TracBrowser for help on using the repository browser.