| 1 | <?php |
|---|
| 2 | // +-----------------------------------------------------------------------+ |
|---|
| 3 | // | Piwigo - a PHP based picture gallery | |
|---|
| 4 | // +-----------------------------------------------------------------------+ |
|---|
| 5 | // | Copyright(C) 2008-2009 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 | |
|---|
| 29 | if (!defined('PHPWG_ROOT_PATH')) |
|---|
| 30 | { |
|---|
| 31 | die('Hacking attempt!'); |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
|---|
| 35 | |
|---|
| 36 | // +-----------------------------------------------------------------------+ |
|---|
| 37 | // | Check Access and exit when user status is not ok | |
|---|
| 38 | // +-----------------------------------------------------------------------+ |
|---|
| 39 | check_status(ACCESS_ADMINISTRATOR); |
|---|
| 40 | |
|---|
| 41 | if (!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 | */ |
|---|
| 61 | function 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 | if (isset($_POST['submit'])) |
|---|
| 88 | { |
|---|
| 89 | asort($_POST['rank_of_image'], SORT_NUMERIC); |
|---|
| 90 | |
|---|
| 91 | save_images_order( |
|---|
| 92 | $page['category_id'], |
|---|
| 93 | array_keys($_POST['rank_of_image']) |
|---|
| 94 | ); |
|---|
| 95 | |
|---|
| 96 | array_push( |
|---|
| 97 | $page['infos'], |
|---|
| 98 | l10n('Images manual order was saved') |
|---|
| 99 | ); |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | // +-----------------------------------------------------------------------+ |
|---|
| 103 | // | template init | |
|---|
| 104 | // +-----------------------------------------------------------------------+ |
|---|
| 105 | $template->set_filenames( |
|---|
| 106 | array('element_set_ranks' => 'element_set_ranks.tpl') |
|---|
| 107 | ); |
|---|
| 108 | |
|---|
| 109 | $base_url = get_root_url().'admin.php'; |
|---|
| 110 | |
|---|
| 111 | // $form_action = $base_url.'?page=element_set_global'; |
|---|
| 112 | |
|---|
| 113 | $query = ' |
|---|
| 114 | SELECT uppercats |
|---|
| 115 | FROM '.CATEGORIES_TABLE.' |
|---|
| 116 | WHERE id = '.$page['category_id'].' |
|---|
| 117 | ;'; |
|---|
| 118 | $category = mysql_fetch_array(pwg_query($query)); |
|---|
| 119 | |
|---|
| 120 | // Navigation path |
|---|
| 121 | $navigation = get_cat_display_name_cache( |
|---|
| 122 | $category['uppercats'], |
|---|
| 123 | get_root_url().'admin.php?page=cat_modify&cat_id=' |
|---|
| 124 | ); |
|---|
| 125 | |
|---|
| 126 | $template->assign( |
|---|
| 127 | array( |
|---|
| 128 | 'CATEGORIES_NAV' => $navigation, |
|---|
| 129 | 'F_ACTION' => $base_url.get_query_string_diff(array()), |
|---|
| 130 | ) |
|---|
| 131 | ); |
|---|
| 132 | |
|---|
| 133 | // +-----------------------------------------------------------------------+ |
|---|
| 134 | // | thumbnails | |
|---|
| 135 | // +-----------------------------------------------------------------------+ |
|---|
| 136 | |
|---|
| 137 | $query = ' |
|---|
| 138 | SELECT |
|---|
| 139 | id, |
|---|
| 140 | path, |
|---|
| 141 | tn_ext, |
|---|
| 142 | rank |
|---|
| 143 | FROM '.IMAGES_TABLE.' |
|---|
| 144 | JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id |
|---|
| 145 | WHERE category_id = '.$page['category_id'].' |
|---|
| 146 | ORDER BY rank |
|---|
| 147 | ;'; |
|---|
| 148 | $result = pwg_query($query); |
|---|
| 149 | |
|---|
| 150 | // template thumbnail initialization |
|---|
| 151 | $current_rank = 1; |
|---|
| 152 | |
|---|
| 153 | while ($row = mysql_fetch_assoc($result)) |
|---|
| 154 | { |
|---|
| 155 | $src = get_thumbnail_url($row); |
|---|
| 156 | |
|---|
| 157 | $template->append( |
|---|
| 158 | 'thumbnails', |
|---|
| 159 | array( |
|---|
| 160 | 'ID' => $row['id'], |
|---|
| 161 | 'TN_SRC' => $src, |
|---|
| 162 | 'RANK' => $current_rank * 10, |
|---|
| 163 | ) |
|---|
| 164 | ); |
|---|
| 165 | |
|---|
| 166 | $current_rank++; |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | // +-----------------------------------------------------------------------+ |
|---|
| 170 | // | sending html code | |
|---|
| 171 | // +-----------------------------------------------------------------------+ |
|---|
| 172 | |
|---|
| 173 | $template->assign_var_from_handle('ADMIN_CONTENT', 'element_set_ranks'); |
|---|
| 174 | ?> |
|---|