source: trunk/admin/element_set_unit.php @ 5813

Last change on this file since 5813 was 5196, checked in by plg, 15 years ago

increase copyright year to 2010

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