source: trunk/admin/element_set_ranks.php @ 13013

Revision 13013, 9.5 KB checked in by plg, 8 years ago (diff)

feature 2561: redesign on album administration screen.

  • only one form on the screen and several tabs
  • simpler URL pattern : page=album-123-properties / page=album-123-sort_order / page=album-123-permissions
  • action to associate all photos of an album to another (new) virtual album was removed. This can be easily done with the new Batch Manager
  • notification by email on an album still has to be moved on a new dedicated tab
  • action icons (jump to album, manage photos, manage sub-albums, delete album...) replaced by plain text links
  • 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  $image_order = null;
108  if (!empty($_POST['image_order_choice'])
109      && in_array($_POST['image_order_choice'], $image_order_choices))
110  {
111    $image_order_choice = $_POST['image_order_choice'];
112  }
113
114  if ($image_order_choice=='user_define')
115  {
116    for ($i=1; $i<=3; $i++)
117    {
118      if ( !empty($_POST['order_field_'.$i]) )
119      {
120        if (! empty($image_order) )
121        {
122          $image_order .= ',';
123        }
124        $image_order .= $_POST['order_field_'.$i];
125        if ($_POST['order_direction_'.$i]=='DESC')
126        {
127          $image_order .= ' DESC';
128        }
129      }
130    }
131  }
132  elseif ($image_order_choice=='rank')
133  {
134    $image_order = 'rank';
135  }
136  $query = '
137UPDATE '.CATEGORIES_TABLE.' SET image_order=\''.$image_order.'\'
138  WHERE id='.$page['category_id'];
139  pwg_query($query);
140
141  if (isset($_POST['image_order_subcats']))
142  {
143    $cat_info = get_cat_info($page['category_id']);
144
145    $query = '
146UPDATE '.CATEGORIES_TABLE.'
147  SET image_order = '.(isset($image_order) ? '\''.$image_order.'\'' : 'NULL').'
148  WHERE uppercats LIKE \''.$cat_info['uppercats'].',%\'';
149    pwg_query($query);
150  }
151
152  array_push($page['infos'], l10n('Your configuration settings are saved'));
153}
154
155// +-----------------------------------------------------------------------+
156// |                             template init                             |
157// +-----------------------------------------------------------------------+
158$template->set_filenames(
159  array('element_set_ranks' => 'element_set_ranks.tpl')
160  );
161
162$base_url = get_root_url().'admin.php';
163
164$query = '
165SELECT *
166  FROM '.CATEGORIES_TABLE.'
167  WHERE id = '.$page['category_id'].'
168;';
169$category = pwg_db_fetch_assoc(pwg_query($query));
170
171if ($category['image_order']=='rank')
172{
173  $image_order_choice = 'rank';
174}
175elseif ($category['image_order']!='')
176{
177  $image_order_choice = 'user_define';
178}
179
180// Navigation path
181$navigation = get_cat_display_name_cache(
182  $category['uppercats'],
183  get_root_url().'admin.php?page=album-'
184  );
185
186$template->assign(
187  array(
188    'CATEGORIES_NAV' => $navigation,
189    'F_ACTION' => $base_url.get_query_string_diff(array()),
190   )
191 );
192
193// +-----------------------------------------------------------------------+
194// |                              thumbnails                               |
195// +-----------------------------------------------------------------------+
196
197$query = '
198SELECT
199    id,
200    file,
201    path,
202    representative_ext,
203    width, height,
204    name,
205    rank
206  FROM '.IMAGES_TABLE.'
207    JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id
208  WHERE category_id = '.$page['category_id'].'
209  ORDER BY rank
210;';
211$result = pwg_query($query);
212if (pwg_db_num_rows($result) > 0)
213{
214        // template thumbnail initialization
215        $current_rank = 1;
216        $thumbnail_info=array();
217        $clipping=array();
218  $derivativeParams = ImageStdParams::get_by_type(IMG_SQUARE);
219        while ($row = pwg_db_fetch_assoc($result))
220        {
221    $derivative = new DerivativeImage($derivativeParams, new SrcImage($row));
222
223                $thumbnail_size = $derivative->get_size();
224                if ( !empty( $row['name'] ) )
225                {
226                        $thumbnail_name = $row['name'];
227                }
228                else
229                {
230                        $file_wo_ext = get_filename_wo_extension($row['file']);
231                        $thumbnail_name = str_replace('_', ' ', $file_wo_ext);
232                }
233                $thumbnail_info[] = array(
234                        'name'  => $thumbnail_name,
235                        'width' => $thumbnail_size[0],
236                        'height'        => $thumbnail_size[1],
237                        'id'    => $row['id'],
238                        'tn_src'        => $derivative->get_url(),
239                        'rank'  => $current_rank * 10,
240                        );
241                if ($thumbnail_size[0]<=128 and $thumbnail_size[1]<=128)
242                {
243                        $clipping[]= min($thumbnail_size[0],$thumbnail_size[1]);
244                }
245                else
246                {
247                        $clipping[]= min($thumbnail_size[0]*0.75,$thumbnail_size[1]*0.75);
248                }
249                $current_rank++;
250        }
251        $clipping=array_sum($clipping)/count($clipping);
252        foreach ($thumbnail_info as $thumbnails_info)
253        {
254                $thumbnail_x_center = $thumbnails_info['width']/2;
255                $thumbnail_y_center = $thumbnails_info['height']/2;
256                $template->append(
257                        'thumbnails',
258                        array(
259                                'ID' => $thumbnails_info['id'],
260                                'NAME' => $thumbnails_info['name'],
261                                'TN_SRC' => $thumbnails_info['tn_src'],
262                                'RANK' => $thumbnails_info['rank'],
263                                'CLIPING' => round($clipping),
264                                'CLIPING_li' => round($clipping+8),
265                                'CLIP_TOP' => round($thumbnail_y_center - $clipping/2),
266                                'CLIP_RIGHT' => round($thumbnail_x_center + $clipping/2),
267                                'CLIP_BOTTOM' => round($thumbnail_y_center + $clipping/2),
268                                'CLIP_LEFT' => round($thumbnail_x_center - $clipping/2)
269                                )
270                        );
271        }
272}
273// image order management
274$sort_fields = array(
275  '' => '',
276  'date_creation' => l10n('Creation date'),
277  'date_available' => l10n('Post date'),
278  'rating_score' => l10n('Rating score'),
279  'hit' => l10n('Most visited'),
280  'file' => l10n('File name'),
281  'name' => l10n('Photo name'),
282  'id' => 'Id',
283  'rank' => l10n('Rank'),
284  );
285
286$sort_directions = array(
287  'ASC' => l10n('ascending'),
288  'DESC' => l10n('descending'),
289  );
290
291$template->assign('image_order_field_options', $sort_fields);
292$template->assign('image_order_direction_options', $sort_directions);
293
294$matches = array();
295if ( !empty( $category['image_order'] ) )
296{
297  preg_match_all('/([a-z_]+) *(?:(asc|desc)(?:ending)?)? *(?:, *|$)/i',
298    $category['image_order'], $matches);
299}
300
301for ($i=0; $i<3; $i++) // 3 fields
302{
303  $tpl_image_order_select = array(
304      'ID' => $i+1,
305      'FIELD' => array(''),
306      'DIRECTION' => array('ASC'),
307    );
308
309  if ( isset($matches[1][$i]) )
310  {
311    $tpl_image_order_select['FIELD'] = array($matches[1][$i]);
312  }
313
314  if (isset($matches[2][$i]) and strcasecmp($matches[2][$i],'DESC')==0)
315  {
316    $tpl_image_order_select['DIRECTION'] = array('DESC');
317  }
318  $template->append( 'image_orders', $tpl_image_order_select);
319}
320
321$template->assign('image_order_choice', $image_order_choice);
322
323
324// +-----------------------------------------------------------------------+
325// |                          sending html code                            |
326// +-----------------------------------------------------------------------+
327
328$template->assign_var_from_handle('ADMIN_CONTENT', 'element_set_ranks');
329?>
Note: See TracBrowser for help on using the repository browser.