source: trunk/admin/permalinks.php @ 2096

Last change on this file since 2096 was 1975, checked in by rvelices, 18 years ago

merge revision 1974 from branch-1_7 to trunk

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
5// +-----------------------------------------------------------------------+
6// | file          : $Id: permalinks.php 1975 2007-04-23 23:50:39Z rvelices $
7// | last update   : $Date: 2007-04-23 23:50:39 +0000 (Mon, 23 Apr 2007) $
8// | last modifier : $Author: rvelices $
9// | revision      : $Revision: 1975 $
10// +-----------------------------------------------------------------------+
11// | This program is free software; you can redistribute it and/or modify  |
12// | it under the terms of the GNU General Public License as published by  |
13// | the Free Software Foundation                                          |
14// |                                                                       |
15// | This program is distributed in the hope that it will be useful, but   |
16// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
17// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
18// | General Public License for more details.                              |
19// |                                                                       |
20// | You should have received a copy of the GNU General Public License     |
21// | along with this program; if not, write to the Free Software           |
22// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
23// | USA.                                                                  |
24// +-----------------------------------------------------------------------+
25
26function parse_sort_variables(
27    $sortable_by, $default_field,
28    $get_param, $get_rejects,
29    $template_var,
30    $anchor = '' )
31{
32  global $template;
33 
34  $url_components = parse_url( $_SERVER['REQUEST_URI'] );
35
36  $base_url = $url_components['path'];
37 
38  parse_str($url_components['query'], $vars);
39  $is_first = true;
40  foreach ($vars as $key => $value)
41  {
42    if (!in_array($key, $get_rejects) and $key!=$get_param)
43    {
44      $base_url .= $is_first ? '?' : '&amp;';
45      $is_first = false;
46      $base_url .= $key.'='.urlencode($value);
47    }
48  }
49
50  $ret = array();
51  foreach( $sortable_by as $field)
52  {
53    $url = $base_url;
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      $disp = '&dArr;'; // TODO: an small image is better
61    }
62    else
63    {
64      array_push($ret, $field);
65      $disp = '<em>&dArr;</em>'; // TODO: an small image is better
66    }
67    if ( isset($template_var) )
68    {
69      $template->assign_var( $template_var.strtoupper($field),
70            '<a href="'.$url.$anchor.'" title="'.l10n('Sort order').'">'.$disp.'</a>'
71         );
72    }
73  }
74  return $ret;
75}
76
77if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
78
79include_once(PHPWG_ROOT_PATH.'admin/include/functions_permalinks.php');
80
81$selected_cat = array();
82if ( isset($_POST['set_permalink']) and $_POST['cat_id']>0 and !is_adviser() )
83{
84  $permalink = $_POST['permalink'];
85  if ( empty($permalink) )
86    delete_cat_permalink($_POST['cat_id'], isset($_POST['save']) );
87  else
88    set_cat_permalink($_POST['cat_id'], $permalink, isset($_POST['save']) );
89  $selected_cat = array( $_POST['cat_id'] );
90}
91elseif ( isset($_GET['delete_permanent']) and !is_adviser() )
92{
93  $query = '
94DELETE FROM '.OLD_PERMALINKS_TABLE.'
95  WHERE permalink="'.$_GET['delete_permanent'].'"
96  LIMIT 1';
97  pwg_query($query);
98  if (mysql_affected_rows()==0)
99    array_push($page['errors'], 'Cannot delete the old permalink !');
100}
101
102
103$template->set_filename('permalinks', 'admin/permalinks.tpl' );
104
105$query = '
106SELECT
107  id,
108  CONCAT(id, " - ", name, IF(permalink IS NULL, "", " &radic;") ) AS name,
109  uppercats, global_rank
110FROM '.CATEGORIES_TABLE;
111
112display_select_cat_wrapper( $query, $selected_cat, 'categories', false );
113
114
115// --- generate display of active permalinks -----------------------------------
116$sort_by = parse_sort_variables(
117    array('id', 'name', 'permalink'), 'name',
118    'psf',
119    array('delete_permanent'),
120    'SORT_' );
121
122$query = '
123SELECT id, permalink, uppercats, global_rank
124  FROM '.CATEGORIES_TABLE.'
125  WHERE permalink IS NOT NULL
126';
127if ( count($sort_by) and
128      ($sort_by[0]=='id' or $sort_by[0]=='permalink')
129    )
130{
131  $query .= ' ORDER BY '.$sort_by[0];
132}
133$categories=array();
134$result=pwg_query($query);
135while ( $row=mysql_fetch_assoc($result) )
136{
137  $row['name'] = get_cat_display_name_cache( $row['uppercats'] );
138  $categories[] = $row;
139}
140
141if ( !count($sort_by) or $sort_by[0]=='name')
142{
143  usort($categories, 'global_rank_compare');
144}
145foreach ($categories as $cat)
146{
147  $template->assign_block_vars( 'permalink', $cat );
148}
149
150
151// --- generate display of old permalinks --------------------------------------
152
153$sort_by = parse_sort_variables(
154    array('cat_id','permalink','date_deleted','last_hit','hit'), null,
155    'dpsf',
156    array('delete_permanent'),
157    'SORT_OLD_', '#old_permalinks' );
158
159$url_del_base = get_root_url().'admin.php?page=permalinks';
160$query = 'SELECT * FROM '.OLD_PERMALINKS_TABLE;
161if ( count($sort_by) )
162{
163  $query .= ' ORDER BY '.$sort_by[0];
164}
165$result = pwg_query($query);
166while ( $row=mysql_fetch_assoc($result) )
167{
168  $row['name'] = get_cat_display_name_cache($row['cat_id']);
169  $row['U_DELETE'] =
170      add_url_params(
171        $url_del_base,
172        array( 'delete_permanent'=> $row['permalink'] )
173      );
174  $template->assign_block_vars( 'deleted_permalink', $row );
175}
176
177$template->assign_var('U_HELP', get_root_url().'popuphelp.php?page=permalinks');
178
179$template->assign_var_from_handle('ADMIN_CONTENT', 'permalinks');
180?>
Note: See TracBrowser for help on using the repository browser.