source: trunk/admin/element_set_ranks.php @ 15659

Revision 14205, 8.6 KB checked in by flop25, 8 years ago (diff)

feature:2388
on element_set_ranks, no more clipping due to the use of the default square size

  • Property svn:eol-style set to LF
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24/**
25 * Change rank of images inside a category
26 *
27 */
28
29if (!defined('PHPWG_ROOT_PATH'))
30{
31  die('Hacking attempt!');
32}
33
34include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
35
36// +-----------------------------------------------------------------------+
37// | Check Access and exit when user status is not ok                      |
38// +-----------------------------------------------------------------------+
39check_status(ACCESS_ADMINISTRATOR);
40
41if (!isset($_GET['cat_id']) or !is_numeric($_GET['cat_id']))
42{
43  trigger_error('missing cat_id param', E_USER_ERROR);
44}
45
46$page['category_id'] = $_GET['cat_id'];
47
48// +-----------------------------------------------------------------------+
49// |                               functions                               |
50// +-----------------------------------------------------------------------+
51
52/**
53 * save the rank depending on given images order
54 *
55 * The list of ordered images id is supposed to be in the same parent
56 * category
57 *
58 * @param array categories
59 * @return void
60 */
61function save_images_order($category_id, $images)
62{
63  $current_rank = 0;
64  $datas = array();
65  foreach ($images as $id)
66  {
67    array_push(
68      $datas,
69      array(
70        'category_id' => $category_id,
71        'image_id' => $id,
72        'rank' => ++$current_rank,
73        )
74      );
75  }
76  $fields = array(
77    'primary' => array('image_id', 'category_id'),
78    'update' => array('rank')
79    );
80  mass_updates(IMAGE_CATEGORY_TABLE, $fields, $datas);
81}
82
83// +-----------------------------------------------------------------------+
84// |                       global mode form submission                     |
85// +-----------------------------------------------------------------------+
86
87$image_order_choices = array('default', 'rank', 'user_define');
88$image_order_choice = 'default';
89
90if (isset($_POST['submit']))
91{
92  if (isset($_POST['rank_of_image']))
93  {
94    asort($_POST['rank_of_image'], SORT_NUMERIC);
95
96    save_images_order(
97      $page['category_id'],
98      array_keys($_POST['rank_of_image'])
99      );
100
101    array_push(
102      $page['infos'],
103      l10n('Images manual order was saved')
104      );
105  }
106
107  if (!empty($_POST['image_order_choice'])
108      && in_array($_POST['image_order_choice'], $image_order_choices))
109  {
110    $image_order_choice = $_POST['image_order_choice'];
111  }
112
113  $image_order = null;
114  if ($image_order_choice=='user_define')
115  {
116    for ($i=0; $i<3; $i++)
117    {
118      if (!empty($_POST['image_order'][$i]))
119      {
120        if (!empty($image_order)) $image_order.= ',';
121        $image_order.= $_POST['image_order'][$i];
122      }
123    }
124  }
125  elseif ($image_order_choice=='rank')
126  {
127    $image_order = 'rank';
128  }
129  $query = '
130UPDATE '.CATEGORIES_TABLE.'
131  SET image_order=\''.$image_order.'\'
132  WHERE id='.$page['category_id'];
133  pwg_query($query);
134
135  if (isset($_POST['image_order_subcats']))
136  {
137    $cat_info = get_cat_info($page['category_id']);
138
139    $query = '
140UPDATE '.CATEGORIES_TABLE.'
141  SET image_order = '.(isset($image_order) ? '\''.$image_order.'\'' : 'NULL').'
142  WHERE uppercats LIKE \''.$cat_info['uppercats'].',%\'';
143    pwg_query($query);
144  }
145
146  array_push($page['infos'], l10n('Your configuration settings are saved'));
147}
148
149// +-----------------------------------------------------------------------+
150// |                             template init                             |
151// +-----------------------------------------------------------------------+
152$template->set_filenames(
153  array('element_set_ranks' => 'element_set_ranks.tpl')
154  );
155
156$base_url = get_root_url().'admin.php';
157
158$query = '
159SELECT *
160  FROM '.CATEGORIES_TABLE.'
161  WHERE id = '.$page['category_id'].'
162;';
163$category = pwg_db_fetch_assoc(pwg_query($query));
164
165if ($category['image_order']=='rank')
166{
167  $image_order_choice = 'rank';
168}
169elseif ($category['image_order']!='')
170{
171  $image_order_choice = 'user_define';
172}
173
174// Navigation path
175$navigation = get_cat_display_name_cache(
176  $category['uppercats'],
177  get_root_url().'admin.php?page=album-'
178  );
179
180$template->assign(
181  array(
182    'CATEGORIES_NAV' => $navigation,
183    'F_ACTION' => $base_url.get_query_string_diff(array()),
184   )
185 );
186
187// +-----------------------------------------------------------------------+
188// |                              thumbnails                               |
189// +-----------------------------------------------------------------------+
190
191$query = '
192SELECT
193    id,
194    file,
195    path,
196    representative_ext,
197    width, height, rotation,
198    name,
199    rank
200  FROM '.IMAGES_TABLE.'
201    JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id
202  WHERE category_id = '.$page['category_id'].'
203  ORDER BY rank
204;';
205$result = pwg_query($query);
206if (pwg_db_num_rows($result) > 0)
207{
208        // template thumbnail initialization
209        $current_rank = 1;
210        $thumbnail_info=array();
211        $clipping=array();
212  $derivativeParams = ImageStdParams::get_by_type(IMG_SQUARE);
213        while ($row = pwg_db_fetch_assoc($result))
214        {
215    $derivative = new DerivativeImage($derivativeParams, new SrcImage($row));
216
217                if ( !empty( $row['name'] ) )
218                {
219                        $thumbnail_name = $row['name'];
220                }
221                else
222                {
223                        $file_wo_ext = get_filename_wo_extension($row['file']);
224                        $thumbnail_name = str_replace('_', ' ', $file_wo_ext);
225                }
226                $current_rank++;
227                $template->append(
228                        'thumbnails',
229                        array(
230                                'ID' => $row['id'],
231                                'NAME' => $thumbnail_name,
232                                'TN_SRC' => $derivative->get_url(),
233                                'RANK' => $current_rank * 10,
234                                'SIZE' => $derivative->get_size(),
235                                )
236                        );
237        }
238}
239// image order management
240$sort_fields = array(
241  ''                    => '',
242  'file'                => l10n('file name, A &rarr; Z'),
243  'file DESC'           => l10n('file name, Z &rarr; A'),
244  'name'                => l10n('photo title, A &rarr; Z'),
245  'name DESC'           => l10n('photo title, Z &rarr; A'),
246  'date_creation DESC'  => l10n('date created, new &rarr; old'),
247  'date_creation'       => l10n('date created, old &rarr; new'),
248  'date_available DESC' => l10n('date posted, new &rarr; old'),
249  'date_available'      => l10n('date posted, old &rarr; new'),
250  'rating_score DESC'   => l10n('rating score, high &rarr; low'),
251  'rating_score'        => l10n('rating score, low &rarr; high'),
252  'hit DESC'            => l10n('visits, high &rarr; low'),
253  'hit'                 => l10n('visits, low &rarr; high'),
254  'id'                  => l10n('numeric identifier, 1 &rarr; 9'),
255  'id DESC'             => l10n('numeric identifier, 9 &rarr; 1'),
256  'rank'                => l10n('manual sort order'),
257  );
258
259$template->assign('image_order_options', $sort_fields);
260
261$image_order = explode(',', $category['image_order']);
262
263for ($i=0; $i<3; $i++) // 3 fields
264{
265  if ( isset($image_order[$i]) )
266  {
267    $template->append('image_order', $image_order[$i]);
268  }
269  else
270  {
271    $template->append('image_order', '');
272  }
273}
274
275$template->assign('image_order_choice', $image_order_choice);
276
277
278// +-----------------------------------------------------------------------+
279// |                          sending html code                            |
280// +-----------------------------------------------------------------------+
281
282$template->assign_var_from_handle('ADMIN_CONTENT', 'element_set_ranks');
283?>
Note: See TracBrowser for help on using the repository browser.