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 | function parse_sort_variables( |
---|
25 | $sortable_by, $default_field, |
---|
26 | $get_param, $get_rejects, |
---|
27 | $template_var, |
---|
28 | $anchor = '' ) |
---|
29 | { |
---|
30 | global $template; |
---|
31 | |
---|
32 | $url_components = parse_url( $_SERVER['REQUEST_URI'] ); |
---|
33 | |
---|
34 | $base_url = $url_components['path']; |
---|
35 | |
---|
36 | parse_str($url_components['query'], $vars); |
---|
37 | $is_first = true; |
---|
38 | foreach ($vars as $key => $value) |
---|
39 | { |
---|
40 | if (!in_array($key, $get_rejects) and $key!=$get_param) |
---|
41 | { |
---|
42 | $base_url .= $is_first ? '?' : '&'; |
---|
43 | $is_first = false; |
---|
44 | $base_url .= $key.'='.urlencode($value); |
---|
45 | } |
---|
46 | } |
---|
47 | |
---|
48 | $ret = array(); |
---|
49 | foreach( $sortable_by as $field) |
---|
50 | { |
---|
51 | $url = $base_url; |
---|
52 | $disp = '⇓'; // TODO: an small image is better |
---|
53 | |
---|
54 | if ( $field !== @$_GET[$get_param] ) |
---|
55 | { |
---|
56 | if ( !isset($default_field) or $default_field!=$field ) |
---|
57 | { // the first should be the default |
---|
58 | $url = add_url_params($url, array($get_param=>$field) ); |
---|
59 | } |
---|
60 | elseif (isset($default_field) and !isset($_GET[$get_param]) ) |
---|
61 | { |
---|
62 | array_push($ret, $field); |
---|
63 | $disp = '<em>'.$disp.'</em>'; |
---|
64 | } |
---|
65 | } |
---|
66 | else |
---|
67 | { |
---|
68 | array_push($ret, $field); |
---|
69 | $disp = '<em>'.$disp.'</em>'; |
---|
70 | } |
---|
71 | if ( isset($template_var) ) |
---|
72 | { |
---|
73 | $template->assign( $template_var.strtoupper($field), |
---|
74 | '<a href="'.$url.$anchor.'" title="'.l10n('Sort order').'">'.$disp.'</a>' |
---|
75 | ); |
---|
76 | } |
---|
77 | } |
---|
78 | return $ret; |
---|
79 | } |
---|
80 | |
---|
81 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
82 | |
---|
83 | include_once(PHPWG_ROOT_PATH.'admin/include/functions_permalinks.php'); |
---|
84 | |
---|
85 | $selected_cat = array(); |
---|
86 | if ( isset($_POST['set_permalink']) and $_POST['cat_id']>0 and !is_adviser() ) |
---|
87 | { |
---|
88 | $permalink = $_POST['permalink']; |
---|
89 | if ( empty($permalink) ) |
---|
90 | delete_cat_permalink($_POST['cat_id'], isset($_POST['save']) ); |
---|
91 | else |
---|
92 | set_cat_permalink($_POST['cat_id'], $permalink, isset($_POST['save']) ); |
---|
93 | $selected_cat = array( $_POST['cat_id'] ); |
---|
94 | } |
---|
95 | elseif ( isset($_GET['delete_permanent']) and !is_adviser() ) |
---|
96 | { |
---|
97 | $query = ' |
---|
98 | DELETE FROM '.OLD_PERMALINKS_TABLE.' |
---|
99 | WHERE permalink="'.$_GET['delete_permanent'].'" |
---|
100 | LIMIT 1'; |
---|
101 | pwg_query($query); |
---|
102 | if (mysql_affected_rows()==0) |
---|
103 | array_push($page['errors'], 'Cannot delete the old permalink !'); |
---|
104 | } |
---|
105 | |
---|
106 | |
---|
107 | $template->set_filename('permalinks', 'permalinks.tpl' ); |
---|
108 | |
---|
109 | $query = ' |
---|
110 | SELECT |
---|
111 | id, |
---|
112 | CONCAT(id, " - ", name, IF(permalink IS NULL, "", " √") ) AS name, |
---|
113 | uppercats, global_rank |
---|
114 | FROM '.CATEGORIES_TABLE; |
---|
115 | |
---|
116 | display_select_cat_wrapper( $query, $selected_cat, 'categories', false ); |
---|
117 | |
---|
118 | |
---|
119 | // --- generate display of active permalinks ----------------------------------- |
---|
120 | $sort_by = parse_sort_variables( |
---|
121 | array('id', 'name', 'permalink'), 'name', |
---|
122 | 'psf', |
---|
123 | array('delete_permanent'), |
---|
124 | 'SORT_' ); |
---|
125 | |
---|
126 | $query = ' |
---|
127 | SELECT id, permalink, uppercats, global_rank |
---|
128 | FROM '.CATEGORIES_TABLE.' |
---|
129 | WHERE permalink IS NOT NULL |
---|
130 | '; |
---|
131 | if ( $sort_by[0]=='id' or $sort_by[0]=='permalink' ) |
---|
132 | { |
---|
133 | $query .= ' ORDER BY '.$sort_by[0]; |
---|
134 | } |
---|
135 | $categories=array(); |
---|
136 | $result=pwg_query($query); |
---|
137 | while ( $row=mysql_fetch_assoc($result) ) |
---|
138 | { |
---|
139 | $row['name'] = get_cat_display_name_cache( $row['uppercats'] ); |
---|
140 | $categories[] = $row; |
---|
141 | } |
---|
142 | |
---|
143 | if ( $sort_by[0]=='name') |
---|
144 | { |
---|
145 | usort($categories, 'global_rank_compare'); |
---|
146 | } |
---|
147 | $template->assign( 'permalinks', $categories ); |
---|
148 | |
---|
149 | // --- generate display of old permalinks -------------------------------------- |
---|
150 | |
---|
151 | $sort_by = parse_sort_variables( |
---|
152 | array('cat_id','permalink','date_deleted','last_hit','hit'), null, |
---|
153 | 'dpsf', |
---|
154 | array('delete_permanent'), |
---|
155 | 'SORT_OLD_', '#old_permalinks' ); |
---|
156 | |
---|
157 | $url_del_base = get_root_url().'admin.php?page=permalinks'; |
---|
158 | $query = 'SELECT * FROM '.OLD_PERMALINKS_TABLE; |
---|
159 | if ( count($sort_by) ) |
---|
160 | { |
---|
161 | $query .= ' ORDER BY '.$sort_by[0]; |
---|
162 | } |
---|
163 | $result = pwg_query($query); |
---|
164 | $deleted_permalinks=array(); |
---|
165 | while ( $row=mysql_fetch_assoc($result) ) |
---|
166 | { |
---|
167 | $row['name'] = get_cat_display_name_cache($row['cat_id']); |
---|
168 | $row['U_DELETE'] = |
---|
169 | add_url_params( |
---|
170 | $url_del_base, |
---|
171 | array( 'delete_permanent'=> $row['permalink'] ) |
---|
172 | ); |
---|
173 | $deleted_permalinks[] = $row; |
---|
174 | } |
---|
175 | $template->assign('deleted_permalinks', $deleted_permalinks); |
---|
176 | $template->assign('U_HELP', get_root_url().'popuphelp.php?page=permalinks'); |
---|
177 | |
---|
178 | $template->assign_var_from_handle('ADMIN_CONTENT', 'permalinks'); |
---|
179 | ?> |
---|