source: trunk/admin/permalinks.php @ 2223

Last change on this file since 2223 was 2223, checked in by rvelices, 17 years ago
  • migrate many templates to smarty
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 5.7 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2003-2008 PhpWebGallery Team - http://phpwebgallery.net |
5// +-----------------------------------------------------------------------+
6// | file          : $Id: permalinks.php 2223 2008-02-28 02:41:48Z rvelices $
7// | last update   : $Date: 2008-02-28 02:41:48 +0000 (Thu, 28 Feb 2008) $
8// | last modifier : $Author: rvelices $
9// | revision      : $Revision: 2223 $
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    $disp = '&dArr;'; // TODO: an small image is better
55
56    if ( $field !== @$_GET[$get_param] )
57    {
58      if ( !isset($default_field) or $default_field!=$field )
59      { // the first should be the default
60        $url = add_url_params($url, array($get_param=>$field) );
61      }
62      elseif (isset($default_field) and !isset($_GET[$get_param]) )
63      {
64        array_push($ret, $field);
65        $disp = '<em>'.$disp.'</em>';
66      }
67    }
68    else
69    {
70      array_push($ret, $field);
71      $disp = '<em>'.$disp.'</em>';
72    }
73    if ( isset($template_var) )
74    {
75      $template->assign( $template_var.strtoupper($field),
76            '<a href="'.$url.$anchor.'" title="'.l10n('Sort order').'">'.$disp.'</a>'
77         );
78    }
79  }
80  return $ret;
81}
82
83if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
84
85include_once(PHPWG_ROOT_PATH.'admin/include/functions_permalinks.php');
86
87$selected_cat = array();
88if ( isset($_POST['set_permalink']) and $_POST['cat_id']>0 and !is_adviser() )
89{
90  $permalink = $_POST['permalink'];
91  if ( empty($permalink) )
92    delete_cat_permalink($_POST['cat_id'], isset($_POST['save']) );
93  else
94    set_cat_permalink($_POST['cat_id'], $permalink, isset($_POST['save']) );
95  $selected_cat = array( $_POST['cat_id'] );
96}
97elseif ( isset($_GET['delete_permanent']) and !is_adviser() )
98{
99  $query = '
100DELETE FROM '.OLD_PERMALINKS_TABLE.'
101  WHERE permalink="'.$_GET['delete_permanent'].'"
102  LIMIT 1';
103  pwg_query($query);
104  if (mysql_affected_rows()==0)
105    array_push($page['errors'], 'Cannot delete the old permalink !');
106}
107
108
109$template->set_filename('permalinks', 'admin/permalinks.tpl' );
110
111$query = '
112SELECT
113  id,
114  CONCAT(id, " - ", name, IF(permalink IS NULL, "", " &radic;") ) AS name,
115  uppercats, global_rank
116FROM '.CATEGORIES_TABLE;
117
118display_select_cat_wrapper( $query, $selected_cat, 'categories', false );
119
120
121// --- generate display of active permalinks -----------------------------------
122$sort_by = parse_sort_variables(
123    array('id', 'name', 'permalink'), 'name',
124    'psf',
125    array('delete_permanent'),
126    'SORT_' );
127
128$query = '
129SELECT id, permalink, uppercats, global_rank
130  FROM '.CATEGORIES_TABLE.'
131  WHERE permalink IS NOT NULL
132';
133if ( $sort_by[0]=='id' or $sort_by[0]=='permalink' )
134{
135  $query .= ' ORDER BY '.$sort_by[0];
136}
137$categories=array();
138$result=pwg_query($query);
139while ( $row=mysql_fetch_assoc($result) )
140{
141  $row['name'] = get_cat_display_name_cache( $row['uppercats'] );
142  $categories[] = $row;
143}
144
145if ( $sort_by[0]=='name')
146{
147  usort($categories, 'global_rank_compare');
148}
149$template->assign( 'permalinks', $categories );
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);
166$deleted_permalinks=array();
167while ( $row=mysql_fetch_assoc($result) )
168{
169  $row['name'] = get_cat_display_name_cache($row['cat_id']);
170  $row['U_DELETE'] =
171      add_url_params(
172        $url_del_base,
173        array( 'delete_permanent'=> $row['permalink'] )
174      );
175  $deleted_permalinks[] = $row;
176}
177$template->assign('deleted_permalinks', $deleted_permalinks);
178$template->assign('U_HELP', get_root_url().'popuphelp.php?page=permalinks');
179
180$template->assign_var_from_handle('ADMIN_CONTENT', 'permalinks');
181?>
Note: See TracBrowser for help on using the repository browser.