source: trunk/admin/cat_modify.php @ 21

Last change on this file since 21 was 21, checked in by z0rglub, 21 years ago

* empty log message *

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 KB
Line 
1<?php
2/***************************************************************************
3 *                               cat_modify.php                            *
4 *                            -------------------                          *
5 *   application          : PhpWebGallery 1.3                              *
6 *   author               : Pierrick LE GALL <pierrick@z0rglub.com>        *
7 *                                                                         *
8 ***************************************************************************/
9
10/***************************************************************************
11 *                                                                         *
12 *   This program is free software; you can redistribute it and/or modify  *
13 *   it under the terms of the GNU General Public License as published by  *
14 *   the Free Software Foundation;                                         *
15 *                                                                         *
16 ***************************************************************************/
17
18include_once( './include/isadmin.inc.php' );
19//----------------------------------------------------- template initialization
20$sub = $vtp->Open( '../template/'.$user['template'].'/admin/cat_modify.vtp' );
21$tpl = array( 'remote_site','editcat_confirm','editcat_back','editcat_title1',
22              'editcat_name','editcat_comment','editcat_status',
23              'editcat_visible','editcat_status_info', 'submit' );
24templatize_array( $tpl, 'lang', $sub );
25//---------------------------------------------------------------- verification
26if ( !is_numeric( $_GET['cat'] ) )
27{
28  $_GET['cat'] = '-1';
29}
30//--------------------------------------------------------- form criteria check
31if ( isset( $_POST['submit'] ) )
32{
33  // if new status is different from previous one, deletion of all related
34  // links for access rights
35  $query = 'SELECT status';
36  $query.= ' FROM '.PREFIX_TABLE.'categories';
37  $query.= ' WHERE id = '.$_GET['cat'];
38  $query.= ';';
39  $row = mysql_fetch_array( mysql_query( $query ) );
40
41  if ( $_POST['status'] != $row['status'] )
42  {
43    // deletion of all access for groups concerning this category
44    $query = 'DELETE';
45    $query.= ' FROM '.PREFIX_TABLE.'group_access';
46    $query.= ' WHERE cat_id = '.$_GET['cat'];
47    mysql_query( $query );
48    // deletion of all access for users concerning this category
49    $query = 'DELETE';
50    $query.= ' FROM '.PREFIX_TABLE.'user_access';
51    $query.= ' WHERE cat_id = '.$_GET['cat'];
52    mysql_query( $query );
53  }
54 
55  $query = 'UPDATE '.PREFIX_TABLE.'categories';
56  if ( $_POST['name'] == '' )
57  {
58    $query.= ' SET name = NULL';
59  }
60  else
61  {
62    $query.= " SET name = '".htmlentities( $_POST['name'], ENT_QUOTES)."'";
63  }
64  if ( $_POST['comment'] == '' )
65  {
66    $query.= ', comment = NULL';
67  }
68  else
69  {
70    $query.= ", comment = '".htmlentities( $_POST['comment'], ENT_QUOTES )."'";
71  }
72  $query.= ", status = '".$_POST['status']."'";
73  $query.= ", visible = '".$_POST['visible']."'";
74  $query.= " WHERE id = '".$_GET['cat']."'";
75  $query.= ';';
76  mysql_query( $query );
77
78  $query = 'SELECT id';
79  $query.= ' FROM '.PREFIX_TABLE.'users';
80  $query.= " WHERE username != '".$conf['webmaster']."'";
81  $query.= ';';
82  $result = mysql_query( $query );
83  while ( $row = mysql_fetch_array ( $result ) )
84  {
85    check_favorites( $row['id'] );
86  }
87  $vtp->addSession( $sub, 'confirmation' );
88  $url = add_session_id( './admin.php?page=cat_list' );
89  $vtp->setVar( $sub, 'confirmation.back_url', $url );
90  $vtp->closeSession( $sub, 'confirmation' );
91}
92//------------------------------------------------------------------------ form
93$form_action = './admin.php?page=cat_modify&amp;cat='.$_GET['cat'];
94$vtp->setVar( $sub, 'form_action', add_session_id( $form_action ) );
95
96$query = 'SELECT a.id,name,dir,status,comment';
97$query.= ',id_uppercat,site_id,galleries_url,visible';
98$query.= ' FROM '.PREFIX_TABLE.'categories as a, '.PREFIX_TABLE.'sites as b';
99$query.= ' WHERE a.id = '.$_GET['cat'];
100$query.= ' AND a.site_id = b.id';
101$query.= ';';
102$row = mysql_fetch_array( mysql_query( $query ) );
103$result = get_cat_info( $row['id'] );
104// cat name
105$cat_name = get_cat_display_name( $result['name'], ' - ', '' );
106$vtp->setVar( $sub, 'cat:name', $cat_name );
107// cat dir
108$vtp->setVar( $sub, 'cat:dir', $row['dir'] );
109// remote site ?
110if ( $row['site_id'] != 1 )
111{
112  $vtp->addSession( $sub, 'server' );
113  $vtp->setVar( $sub, 'server.url', $row['galleries_url'] );
114  $vtp->closeSession( $sub, 'server' );
115}
116$vtp->setVar( $sub, 'name',    $row['name'] );
117$vtp->setVar( $sub, 'comment', $row['comment'] );
118// status : public, private...
119$options = get_enums( PREFIX_TABLE.'categories', 'status' );
120foreach ( $options as $option  ) {
121  $vtp->addSession( $sub, 'status_option' );
122  $vtp->setVar( $sub, 'status_option.option', $lang[$option] );
123  $vtp->setVar( $sub, 'status_option.value', $option );
124  if ( $option == $row['status'] )
125  {
126    $vtp->setVar( $sub, 'status_option.checked', ' checked="checked"' ); 
127  }
128  $vtp->closeSession( $sub, 'status_option' );
129}
130// visible : true or false
131$vtp->addSession( $sub, 'visible_option' );
132$vtp->setVar( $sub, 'visible_option.value', 'true' );
133$vtp->setVar( $sub, 'visible_option.option', $lang['yes'] );
134$checked = '';
135if ( $row['visible'] == 'true' )
136{
137  $checked = ' checked="checked"';
138}
139$vtp->setVar( $sub, 'visible_option.checked', $checked );
140$vtp->closeSession( $sub, 'visible_option' );
141$vtp->addSession( $sub, 'visible_option' );
142$vtp->setVar( $sub, 'visible_option.value', 'false' );
143$vtp->setVar( $sub, 'visible_option.option', $lang['no'] );
144$checked = '';
145if ( $row['visible'] == 'false' )
146{
147  $checked = ' checked="checked"';
148}
149$vtp->setVar( $sub, 'visible_option.checked', $checked );
150$vtp->closeSession( $sub, 'visible_option' );
151//----------------------------------------------------------- sending html code
152$vtp->Parse( $handle , 'sub', $sub );
153?>
Note: See TracBrowser for help on using the repository browser.