source: trunk/admin/element_set_unit.php @ 5955

Last change on this file since 5955 was 5955, checked in by nikrou, 10 years ago

Feature 1156 fixed : add privacy level to photo bulk manager in unit mode

  • Property svn:eol-style set to LF
File size: 8.0 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2010 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 * Management of elements set. Elements can belong to a category or to the
26 * user caddie.
27 *
28 */
29
30if (!defined('PHPWG_ROOT_PATH'))
31{
32  die('Hacking attempt!');
33}
34
35include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
36
37// +-----------------------------------------------------------------------+
38// | Check Access and exit when user status is not ok                      |
39// +-----------------------------------------------------------------------+
40check_status(ACCESS_ADMINISTRATOR);
41
42trigger_action('loc_begin_element_set_unit');
43
44// +-----------------------------------------------------------------------+
45// |                        unit mode form submission                      |
46// +-----------------------------------------------------------------------+
47
48if (isset($_POST['submit']))
49{
50  $collection = explode(',', $_POST['element_ids']);
51
52  $datas = array();
53
54  $query = '
55SELECT id, date_creation
56  FROM '.IMAGES_TABLE.'
57  WHERE id IN ('.implode(',', $collection).')
58;';
59  $result = pwg_query($query);
60
61  while ($row = pwg_db_fetch_assoc($result))
62  {
63    $data = array();
64
65    $data['id'] = $row['id'];
66    $data['name'] = $_POST['name-'.$row['id']];
67    $data['author'] = $_POST['author-'.$row['id']];
68    $data['level'] = $_POST['level-'.$row['id']];
69
70    foreach (array('name', 'author', 'level') as $field)
71    {
72      if (!empty($_POST[$field.'-'.$row['id']]))
73      {
74        $data[$field] = strip_tags($_POST[$field.'-'.$row['id']]);
75      }
76    }
77
78    if ($conf['allow_html_descriptions'])
79    {
80      $data['comment'] = @$_POST['description-'.$row['id']];
81    }
82    else
83    {
84      $data['comment'] = strip_tags(@$_POST['description-'.$row['id']]);
85    }
86
87    if (isset($_POST['date_creation_action-'.$row['id']]))
88    {
89      if ('set' == $_POST['date_creation_action-'.$row['id']])
90      {
91        $data['date_creation'] =
92          $_POST['date_creation_year-'.$row['id']]
93            .'-'.$_POST['date_creation_month-'.$row['id']]
94            .'-'.$_POST['date_creation_day-'.$row['id']];
95      }
96      else if ('unset' == $_POST['date_creation_action-'.$row['id']])
97      {
98        $data['date_creation'] = '';
99      }
100    }
101    else
102    {
103      $data['date_creation'] = $row['date_creation'];
104    }
105
106    array_push($datas, $data);
107
108    // tags management
109    if (isset($_POST[ 'tags-'.$row['id'] ]))
110    {
111      $tag_ids = get_fckb_tag_ids($_POST[ 'tags-'.$row['id'] ]);
112      set_tags($tag_ids, $row['id']);
113    }
114  }
115
116  mass_updates(
117    IMAGES_TABLE,
118    array(
119      'primary' => array('id'),
120      'update' => array('name','author','level','comment','date_creation')
121      ),
122    $datas
123    );
124
125  array_push($page['infos'], l10n('Picture informations updated'));
126}
127
128// +-----------------------------------------------------------------------+
129// |                             template init                             |
130// +-----------------------------------------------------------------------+
131
132$template->set_filenames(
133  array('element_set_unit' => 'element_set_unit.tpl'));
134
135$base_url = PHPWG_ROOT_PATH.'admin.php';
136
137$month_list = $lang['month'];
138$month_list[0]='------------';
139ksort($month_list);
140
141$tpl_options = array();
142foreach ($conf['available_permission_levels'] as $level)
143{
144  $tpl_options[$level] = l10n( sprintf('Level %d', $level) );
145}
146
147$template->assign(
148  array(
149    'CATEGORIES_NAV'=>$page['title'],
150    'U_ELEMENTS_PAGE'
151    =>$base_url.get_query_string_diff(array('display','start')),
152    'U_GLOBAL_MODE'
153    =>
154    $base_url
155    .get_query_string_diff(array('mode','display'))
156    .'&amp;mode=global',
157    'F_ACTION'=>$base_url.get_query_string_diff(array()),   
158    'month_list' => $month_list,
159    'level_options' => $tpl_options
160    )
161  );
162
163// +-----------------------------------------------------------------------+
164// |                        global mode thumbnails                         |
165// +-----------------------------------------------------------------------+
166
167// how many items to display on this page
168if (!empty($_GET['display']))
169{
170  if ('all' == $_GET['display'])
171  {
172    $page['nb_images'] = count($page['cat_elements_id']);
173  }
174  else
175  {
176    $page['nb_images'] = intval($_GET['display']);
177  }
178}
179else
180{
181  $page['nb_images'] = 5;
182}
183
184
185
186if (count($page['cat_elements_id']) > 0)
187{
188  $nav_bar = create_navigation_bar(
189    $base_url.get_query_string_diff(array('start')),
190    count($page['cat_elements_id']),
191    $page['start'],
192    $page['nb_images']
193    );
194  $template->assign(array('navbar' => $nav_bar));
195
196  // tags
197  $all_tags = get_all_tags();
198
199  $element_ids = array();
200
201  $query = '
202SELECT id,path,tn_ext,name,date_creation,comment,author,level,file
203  FROM '.IMAGES_TABLE.'
204  WHERE id IN ('.implode(',', $page['cat_elements_id']).')
205  '.$conf['order_by'].'
206  LIMIT '.$page['nb_images'].' OFFSET '.$page['start'].'
207;';
208  $result = pwg_query($query);
209
210  while ($row = pwg_db_fetch_assoc($result))
211  {
212    array_push($element_ids, $row['id']);
213
214    $src = get_thumbnail_url($row);
215
216    // creation date
217    if (!empty($row['date_creation']))
218    {
219      list($year,$month,$day) = explode('-', $row['date_creation']);
220    }
221    else
222    {
223      list($year,$month,$day) = array('',0,0);
224    }
225
226    $query = '
227SELECT
228    tag_id,
229    name AS tag_name
230  FROM '.IMAGE_TAG_TABLE.' AS it
231    JOIN '.TAGS_TABLE.' AS t ON t.id = it.tag_id
232  WHERE image_id = '.$row['id'].'
233;';
234    $tag_selection = get_fckb_taglist($query);
235
236    $template->append(
237      'elements',
238      array(
239        'ID' => $row['id'],
240        'TN_SRC' => $src,
241        'LEGEND' => !empty($row['name']) ?
242            $row['name'] : get_name_from_file($row['file']),
243        'U_EDIT' =>
244            PHPWG_ROOT_PATH.'admin.php?page=picture_modify'.
245            '&amp;image_id='.$row['id'],
246        'NAME' => !empty($row['name'])?$row['name']:'',
247        'AUTHOR' => !empty($row['author'])?$row['author']:'',
248        'LEVEL' => !empty($row['level'])?$row['level']:'',
249        'DESCRIPTION' => !empty($row['comment'])?$row['comment']:'',
250        'DATE_CREATION_YEAR' => $year,
251        'DATE_CREATION_MONTH' => (int)$month,
252        'DATE_CREATION_DAY' => (int)$day,
253        'TAGS' => $tag_selection,
254        )
255      );
256  }
257
258  $template->assign('ELEMENT_IDS', implode(',', $element_ids));
259}
260
261trigger_action('loc_end_element_set_unit');
262
263// +-----------------------------------------------------------------------+
264// |                           sending html code                           |
265// +-----------------------------------------------------------------------+
266
267$template->assign_var_from_handle('ADMIN_CONTENT', 'element_set_unit');
268?>
Note: See TracBrowser for help on using the repository browser.