source: branches/branch-1_7/admin/permalinks.php @ 2458

Last change on this file since 2458 was 2120, checked in by rvelices, 17 years ago

merge rev 2119 from trunk

  • bug 755: admin permalinks page - fix category field sort
  • web service functions: 1 fix and 3 optimizations
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
RevLine 
[1866]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 2120 2007-10-03 23:38:37Z rvelices $
7// | last update   : $Date: 2007-10-03 23:38:37 +0000 (Wed, 03 Oct 2007) $
8// | last modifier : $Author: rvelices $
9// | revision      : $Revision: 2120 $
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
[1873]26function parse_sort_variables(
27    $sortable_by, $default_field,
28    $get_param, $get_rejects,
[1974]29    $template_var,
30    $anchor = '' )
[1873]31{
32  global $template;
[2120]33
[1873]34  $url_components = parse_url( $_SERVER['REQUEST_URI'] );
35
36  $base_url = $url_components['path'];
[2120]37
[1873]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;
[2120]54    $disp = '&dArr;'; // TODO: an small image is better
55
[1873]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      }
[2120]62      elseif (isset($default_field) and !isset($_GET[$get_param]) )
63      {
64        array_push($ret, $field);
65        $disp = '<em>'.$disp.'</em>';
66      }
[1873]67    }
68    else
69    {
70      array_push($ret, $field);
[2120]71      $disp = '<em>'.$disp.'</em>';
[1873]72    }
73    if ( isset($template_var) )
74    {
75      $template->assign_var( $template_var.strtoupper($field),
[1974]76            '<a href="'.$url.$anchor.'" title="'.l10n('Sort order').'">'.$disp.'</a>'
[1873]77         );
78    }
79  }
80  return $ret;
81}
82
[1866]83if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
84
85include_once(PHPWG_ROOT_PATH.'admin/include/functions_permalinks.php');
86
87$selected_cat = array();
[1974]88if ( isset($_POST['set_permalink']) and $_POST['cat_id']>0 and !is_adviser() )
[1866]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}
[1974]97elseif ( isset($_GET['delete_permanent']) and !is_adviser() )
[1866]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
[1873]108
[1866]109$template->set_filename('permalinks', 'admin/permalinks.tpl' );
110
111$query = '
[2120]112SELECT
113  id,
[1866]114  CONCAT(id, " - ", name, IF(permalink IS NULL, "", " &radic;") ) AS name,
[2120]115  uppercats, global_rank
[1866]116FROM '.CATEGORIES_TABLE;
117
118display_select_cat_wrapper( $query, $selected_cat, 'categories', false );
119
[1873]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
[1866]128$query = '
[1873]129SELECT id, permalink, uppercats, global_rank
[1866]130  FROM '.CATEGORIES_TABLE.'
[1873]131  WHERE permalink IS NOT NULL
132';
[2120]133if ( $sort_by[0]=='id' or $sort_by[0]=='permalink' )
[1873]134{
135  $query .= ' ORDER BY '.$sort_by[0];
136}
137$categories=array();
[1866]138$result=pwg_query($query);
139while ( $row=mysql_fetch_assoc($result) )
140{
[1873]141  $row['name'] = get_cat_display_name_cache( $row['uppercats'] );
142  $categories[] = $row;
[1866]143}
144
[2120]145if ( $sort_by[0]=='name')
[1873]146{
147  usort($categories, 'global_rank_compare');
148}
149foreach ($categories as $cat)
150{
151  $template->assign_block_vars( 'permalink', $cat );
152}
153
154
155// --- generate display of old permalinks --------------------------------------
156
157$sort_by = parse_sort_variables(
158    array('cat_id','permalink','date_deleted','last_hit','hit'), null,
159    'dpsf',
160    array('delete_permanent'),
[1974]161    'SORT_OLD_', '#old_permalinks' );
[1873]162
[1866]163$url_del_base = get_root_url().'admin.php?page=permalinks';
164$query = 'SELECT * FROM '.OLD_PERMALINKS_TABLE;
[1873]165if ( count($sort_by) )
166{
167  $query .= ' ORDER BY '.$sort_by[0];
168}
[1866]169$result = pwg_query($query);
170while ( $row=mysql_fetch_assoc($result) )
171{
[1873]172  $row['name'] = get_cat_display_name_cache($row['cat_id']);
[1866]173  $row['U_DELETE'] =
174      add_url_params(
175        $url_del_base,
176        array( 'delete_permanent'=> $row['permalink'] )
177      );
178  $template->assign_block_vars( 'deleted_permalink', $row );
179}
180
181$template->assign_var('U_HELP', get_root_url().'popuphelp.php?page=permalinks');
182
183$template->assign_var_from_handle('ADMIN_CONTENT', 'permalinks');
184?>
Note: See TracBrowser for help on using the repository browser.