[8414] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[8414] | 4 | // +-----------------------------------------------------------------------+ |
---|
[26461] | 5 | // | Copyright(C) 2008-2014 Piwigo Team http://piwigo.org | |
---|
[8414] | 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 | |
---|
| 30 | if (!defined('PHPWG_ROOT_PATH')) |
---|
| 31 | { |
---|
| 32 | die('Hacking attempt!'); |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 36 | |
---|
| 37 | // +-----------------------------------------------------------------------+ |
---|
| 38 | // | Check Access and exit when user status is not ok | |
---|
| 39 | // +-----------------------------------------------------------------------+ |
---|
| 40 | check_status(ACCESS_ADMINISTRATOR); |
---|
| 41 | |
---|
| 42 | trigger_action('loc_begin_element_set_unit'); |
---|
| 43 | |
---|
| 44 | // +-----------------------------------------------------------------------+ |
---|
| 45 | // | unit mode form submission | |
---|
| 46 | // +-----------------------------------------------------------------------+ |
---|
| 47 | |
---|
| 48 | if (isset($_POST['submit'])) |
---|
| 49 | { |
---|
| 50 | $collection = explode(',', $_POST['element_ids']); |
---|
| 51 | |
---|
| 52 | $datas = array(); |
---|
| 53 | |
---|
| 54 | $query = ' |
---|
| 55 | SELECT 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 | if ($conf['allow_html_descriptions']) |
---|
| 71 | { |
---|
| 72 | $data['comment'] = @$_POST['description-'.$row['id']]; |
---|
| 73 | } |
---|
| 74 | else |
---|
| 75 | { |
---|
| 76 | $data['comment'] = strip_tags(@$_POST['description-'.$row['id']]); |
---|
| 77 | } |
---|
| 78 | |
---|
[28497] | 79 | if (!empty($_POST['date_creation-'.$row['id']])) |
---|
[8414] | 80 | { |
---|
[28500] | 81 | $data['date_creation'] = $_POST['date_creation-'.$row['id']]; |
---|
[8414] | 82 | } |
---|
| 83 | else |
---|
| 84 | { |
---|
[28497] | 85 | $data['date_creation'] = null; |
---|
[8414] | 86 | } |
---|
| 87 | |
---|
[25018] | 88 | $datas[] = $data; |
---|
[8414] | 89 | |
---|
| 90 | // tags management |
---|
[11220] | 91 | $tag_ids = array(); |
---|
| 92 | if (!empty($_POST[ 'tags-'.$row['id'] ])) |
---|
[8414] | 93 | { |
---|
[11039] | 94 | $tag_ids = get_tag_ids($_POST[ 'tags-'.$row['id'] ]); |
---|
[8414] | 95 | } |
---|
[11192] | 96 | set_tags($tag_ids, $row['id']); |
---|
[8414] | 97 | } |
---|
| 98 | |
---|
| 99 | mass_updates( |
---|
| 100 | IMAGES_TABLE, |
---|
| 101 | array( |
---|
| 102 | 'primary' => array('id'), |
---|
| 103 | 'update' => array('name','author','level','comment','date_creation') |
---|
| 104 | ), |
---|
| 105 | $datas |
---|
| 106 | ); |
---|
| 107 | |
---|
[25018] | 108 | $page['infos'][] = l10n('Photo informations updated'); |
---|
[28490] | 109 | invalidate_user_cache(); |
---|
[8414] | 110 | } |
---|
| 111 | |
---|
| 112 | // +-----------------------------------------------------------------------+ |
---|
| 113 | // | template init | |
---|
| 114 | // +-----------------------------------------------------------------------+ |
---|
| 115 | |
---|
| 116 | $template->set_filenames( |
---|
| 117 | array('batch_manager_unit' => 'batch_manager_unit.tpl')); |
---|
| 118 | |
---|
| 119 | $base_url = PHPWG_ROOT_PATH.'admin.php'; |
---|
| 120 | |
---|
| 121 | $template->assign( |
---|
| 122 | array( |
---|
| 123 | 'U_ELEMENTS_PAGE' => $base_url.get_query_string_diff(array('display','start')), |
---|
[28497] | 124 | 'F_ACTION' => $base_url.get_query_string_diff(array()), |
---|
[8414] | 125 | 'level_options' => get_privacy_level_options(), |
---|
| 126 | ) |
---|
| 127 | ); |
---|
| 128 | |
---|
| 129 | // +-----------------------------------------------------------------------+ |
---|
| 130 | // | global mode thumbnails | |
---|
| 131 | // +-----------------------------------------------------------------------+ |
---|
| 132 | |
---|
| 133 | // how many items to display on this page |
---|
| 134 | if (!empty($_GET['display'])) |
---|
| 135 | { |
---|
| 136 | if ('all' == $_GET['display']) |
---|
| 137 | { |
---|
| 138 | $page['nb_images'] = count($page['cat_elements_id']); |
---|
| 139 | } |
---|
| 140 | else |
---|
| 141 | { |
---|
| 142 | $page['nb_images'] = intval($_GET['display']); |
---|
| 143 | } |
---|
| 144 | } |
---|
| 145 | else |
---|
| 146 | { |
---|
| 147 | $page['nb_images'] = 5; |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | |
---|
| 151 | |
---|
| 152 | if (count($page['cat_elements_id']) > 0) |
---|
| 153 | { |
---|
| 154 | $nav_bar = create_navigation_bar( |
---|
| 155 | $base_url.get_query_string_diff(array('start')), |
---|
| 156 | count($page['cat_elements_id']), |
---|
| 157 | $page['start'], |
---|
| 158 | $page['nb_images'] |
---|
| 159 | ); |
---|
| 160 | $template->assign(array('navbar' => $nav_bar)); |
---|
| 161 | |
---|
| 162 | $element_ids = array(); |
---|
| 163 | |
---|
| 164 | $is_category = false; |
---|
| 165 | if (isset($_SESSION['bulk_manager_filter']['category']) |
---|
| 166 | and !isset($_SESSION['bulk_manager_filter']['category_recursive'])) |
---|
| 167 | { |
---|
| 168 | $is_category = true; |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | if (isset($_SESSION['bulk_manager_filter']['prefilter']) |
---|
| 172 | and 'duplicates' == $_SESSION['bulk_manager_filter']['prefilter']) |
---|
| 173 | { |
---|
| 174 | $conf['order_by'] = ' ORDER BY file, id'; |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | |
---|
| 178 | $query = ' |
---|
[17856] | 179 | SELECT * |
---|
[8414] | 180 | FROM '.IMAGES_TABLE; |
---|
[28490] | 181 | |
---|
[8414] | 182 | if ($is_category) |
---|
| 183 | { |
---|
| 184 | $category_info = get_cat_info($_SESSION['bulk_manager_filter']['category']); |
---|
[28490] | 185 | |
---|
[8414] | 186 | $conf['order_by'] = $conf['order_by_inside_category']; |
---|
| 187 | if (!empty($category_info['image_order'])) |
---|
| 188 | { |
---|
| 189 | $conf['order_by'] = ' ORDER BY '.$category_info['image_order']; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | $query.= ' |
---|
| 193 | JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id'; |
---|
| 194 | } |
---|
| 195 | |
---|
| 196 | $query.= ' |
---|
| 197 | WHERE id IN ('.implode(',', $page['cat_elements_id']).')'; |
---|
| 198 | |
---|
| 199 | if ($is_category) |
---|
| 200 | { |
---|
| 201 | $query.= ' |
---|
| 202 | AND category_id = '.$_SESSION['bulk_manager_filter']['category']; |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | $query.= ' |
---|
| 206 | '.$conf['order_by'].' |
---|
| 207 | LIMIT '.$page['nb_images'].' OFFSET '.$page['start'].' |
---|
| 208 | ;'; |
---|
| 209 | $result = pwg_query($query); |
---|
| 210 | |
---|
| 211 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 212 | { |
---|
[25018] | 213 | $element_ids[] = $row['id']; |
---|
[8414] | 214 | |
---|
[16280] | 215 | $src_image = new SrcImage($row); |
---|
[8414] | 216 | |
---|
| 217 | $query = ' |
---|
| 218 | SELECT |
---|
[11853] | 219 | id, |
---|
| 220 | name |
---|
[8414] | 221 | FROM '.IMAGE_TAG_TABLE.' AS it |
---|
| 222 | JOIN '.TAGS_TABLE.' AS t ON t.id = it.tag_id |
---|
| 223 | WHERE image_id = '.$row['id'].' |
---|
| 224 | ;'; |
---|
[11039] | 225 | $tag_selection = get_taglist($query); |
---|
[8414] | 226 | |
---|
[13457] | 227 | $legend = render_element_name($row); |
---|
| 228 | if ($legend != get_name_from_file($row['file'])) |
---|
| 229 | { |
---|
| 230 | $legend.= ' ('.$row['file'].')'; |
---|
| 231 | } |
---|
| 232 | |
---|
[8414] | 233 | $template->append( |
---|
[17856] | 234 | 'elements', array_merge($row, |
---|
[8414] | 235 | array( |
---|
| 236 | 'ID' => $row['id'], |
---|
[16280] | 237 | 'TN_SRC' => DerivativeImage::url(IMG_THUMB, $src_image), |
---|
| 238 | 'FILE_SRC' => DerivativeImage::url(IMG_LARGE, $src_image), |
---|
[13457] | 239 | 'LEGEND' => $legend, |
---|
[13077] | 240 | 'U_EDIT' => get_root_url().'admin.php?page=photo-'.$row['id'], |
---|
[17856] | 241 | 'NAME' => htmlspecialchars(@$row['name']), |
---|
| 242 | 'AUTHOR' => htmlspecialchars(@$row['author']), |
---|
[8414] | 243 | 'LEVEL' => !empty($row['level'])?$row['level']:'0', |
---|
[17856] | 244 | 'DESCRIPTION' => htmlspecialchars(@$row['comment']), |
---|
[28500] | 245 | 'DATE_CREATION' => $row['date_creation'], |
---|
[8414] | 246 | 'TAGS' => $tag_selection, |
---|
| 247 | ) |
---|
[17856] | 248 | )); |
---|
[8414] | 249 | } |
---|
| 250 | |
---|
[28532] | 251 | $template->assign(array( |
---|
| 252 | 'ELEMENT_IDS' => implode(',', $element_ids), |
---|
| 253 | 'CACHE_KEYS' => get_admin_client_cache_keys(array('tags')), |
---|
| 254 | )); |
---|
[8414] | 255 | } |
---|
| 256 | |
---|
| 257 | trigger_action('loc_end_element_set_unit'); |
---|
| 258 | |
---|
| 259 | // +-----------------------------------------------------------------------+ |
---|
| 260 | // | sending html code | |
---|
| 261 | // +-----------------------------------------------------------------------+ |
---|
| 262 | |
---|
| 263 | $template->assign_var_from_handle('ADMIN_CONTENT', 'batch_manager_unit'); |
---|
| 264 | ?> |
---|