source: tags/release-1_3_1beta/admin/cat_modify.php @ 27629

Last change on this file since 27629 was 331, checked in by z0rglub, 20 years ago
  • Php warnings correction
  • many categories management : display a simple text field for uppercat id instead of a selection box
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.0 KB
Line 
1<?php
2/***************************************************************************
3 *                               cat_modify.php                            *
4 *                            -------------------                          *
5 *   application   : PhpWebGallery 1.3 <http://phpwebgallery.net>          *
6 *   author        : Pierrick LE GALL <pierrick@z0rglub.com>               *
7 *                                                                         *
8 *   $Id: cat_modify.php 331 2004-01-30 22:47:18Z z0rglub $
9 *                                                                         *
10 ***************************************************************************/
11
12/***************************************************************************
13 *                                                                         *
14 *   This program is free software; you can redistribute it and/or modify  *
15 *   it under the terms of the GNU General Public License as published by  *
16 *   the Free Software Foundation;                                         *
17 *                                                                         *
18 ***************************************************************************/
19
20include_once( './include/isadmin.inc.php' );
21//----------------------------------------------------- template initialization
22$sub = $vtp->Open( '../template/'.$user['template'].'/admin/cat_modify.vtp' );
23$tpl = array( 'remote_site','editcat_confirm','editcat_back','editcat_title1',
24              'editcat_name','editcat_comment','editcat_status',
25              'editcat_visible','editcat_visible_info', 'submit',
26              'editcat_uploadable','cat_virtual','cat_parent' );
27templatize_array( $tpl, 'lang', $sub );
28//---------------------------------------------------------------- verification
29if ( !is_numeric( $_GET['cat'] ) )
30{
31  $_GET['cat'] = '-1';
32}
33//--------------------------------------------------------- form criteria check
34if ( isset( $_POST['submit'] ) )
35{
36  // if new status is different from previous one, deletion of all related
37  // links for access rights
38  $query = 'SELECT status';
39  $query.= ' FROM '.PREFIX_TABLE.'categories';
40  $query.= ' WHERE id = '.$_GET['cat'];
41  $query.= ';';
42  $row = mysql_fetch_array( mysql_query( $query ) );
43 
44  $query = 'UPDATE '.PREFIX_TABLE.'categories';
45
46  $query.= ' SET name = ';
47  if ( $_POST['name'] == '' )
48    $query.= 'NULL';
49  else
50    $query.= "'".htmlentities( $_POST['name'], ENT_QUOTES)."'";
51
52  $query.= ', comment = ';
53  if ( $_POST['comment'] == '' )
54    $query.= 'NULL';
55  else
56    $query.= "'".htmlentities( $_POST['comment'], ENT_QUOTES )."'";
57
58  $query.= ", status = '".$_POST['status']."'";
59  $query.= ", visible = '".$_POST['visible']."'";
60
61  if ( isset( $_POST['uploadable'] ) )
62    $query.= ", uploadable = '".$_POST['uploadable']."'";
63
64  if ( isset( $_POST['associate'] ) )
65  {
66    $query.= ', id_uppercat = ';
67    if ( $_POST['associate'] == -1 or $_POST['associate'] == '' )
68      $query.= 'NULL';
69    else
70      $query.= $_POST['associate'];
71  }
72  $query.= ' WHERE id = '.$_GET['cat'];
73  $query.= ';';
74  mysql_query( $query );
75
76  if ( $_POST['status'] != $row['status'] )
77  {
78    // deletion of all access for groups concerning this category
79    $query = 'DELETE';
80    $query.= ' FROM '.PREFIX_TABLE.'group_access';
81    $query.= ' WHERE cat_id = '.$_GET['cat'];
82    mysql_query( $query );
83    // deletion of all access for users concerning this category
84    $query = 'DELETE';
85    $query.= ' FROM '.PREFIX_TABLE.'user_access';
86    $query.= ' WHERE cat_id = '.$_GET['cat'];
87    mysql_query( $query );
88    // resynchronize all users
89    synchronize_all_users();
90  }
91
92  // checking users favorites
93  $query = 'SELECT id';
94  $query.= ' FROM '.PREFIX_TABLE.'users';
95  $query.= ';';
96  $result = mysql_query( $query );
97  while ( $row = mysql_fetch_array( $result ) )
98  {
99    check_favorites( $row['id'] );
100  }
101
102  $vtp->addSession( $sub, 'confirmation' );
103  $url = add_session_id( './admin.php?page=cat_list' );
104  $vtp->setVar( $sub, 'confirmation.back_url', $url );
105  $vtp->closeSession( $sub, 'confirmation' );
106}
107//------------------------------------------------------------------------ form
108$form_action = './admin.php?page=cat_modify&amp;cat='.$_GET['cat'];
109$vtp->setVar( $sub, 'form_action', add_session_id( $form_action ) );
110
111$query = 'SELECT a.id,name,dir,status,comment,uploadable';
112$query.= ',id_uppercat,site_id,galleries_url,visible';
113$query.= ' FROM '.PREFIX_TABLE.'categories as a, '.PREFIX_TABLE.'sites as b';
114$query.= ' WHERE a.id = '.$_GET['cat'];
115$query.= ' AND a.site_id = b.id';
116$query.= ';';
117$row = mysql_fetch_array( mysql_query( $query ) );
118
119if ( !isset( $row['dir'] ) ) $row['dir'] = '';
120if ( !isset( $row['id_uppercat'] ) ) $row['id_uppercat'] = '';
121
122$result = get_cat_info( $row['id'] );
123// cat name
124$cat_name = get_cat_display_name( $result['name'], ' - ', '' );
125$vtp->setVar( $sub, 'cat:name', $cat_name );
126// cat dir
127if ( $row['dir'] != '' )
128{
129  $vtp->addSession( $sub, 'storage' );
130  $vtp->setVar( $sub, 'storage.dir', $row['dir'] );
131  $vtp->closeSession( $sub, 'storage' );
132}
133else
134{
135  $vtp->addSession( $sub, 'virtual' );
136  $vtp->closeSession( $sub, 'virtual' );
137}
138// remote site ?
139if ( $row['site_id'] != 1 )
140{
141  $vtp->addSession( $sub, 'server' );
142  $vtp->setVar( $sub, 'server.url', $row['galleries_url'] );
143  $vtp->closeSession( $sub, 'server' );
144}
145$vtp->setVar( $sub, 'name',    $row['name'] );
146if ( !isset( $row['comment'] ) ) $row['comment'] = '';
147$vtp->setVar( $sub, 'comment', $row['comment'] );
148// status : public, private...
149$options = get_enums( PREFIX_TABLE.'categories', 'status' );
150foreach ( $options as $option  ) {
151  $vtp->addSession( $sub, 'status_option' );
152  $vtp->setVar( $sub, 'status_option.option', $lang[$option] );
153  $vtp->setVar( $sub, 'status_option.value', $option );
154  if ( $option == $row['status'] )
155  {
156    $vtp->setVar( $sub, 'status_option.checked', ' checked="checked"' ); 
157  }
158  $vtp->closeSession( $sub, 'status_option' );
159}
160// visible : true or false
161$vtp->addSession( $sub, 'visible_option' );
162$vtp->setVar( $sub, 'visible_option.value', 'true' );
163$vtp->setVar( $sub, 'visible_option.option', $lang['yes'] );
164$checked = '';
165if ( $row['visible'] == 'true' )
166{
167  $checked = ' checked="checked"';
168}
169$vtp->setVar( $sub, 'visible_option.checked', $checked );
170$vtp->closeSession( $sub, 'visible_option' );
171$vtp->addSession( $sub, 'visible_option' );
172$vtp->setVar( $sub, 'visible_option.value', 'false' );
173$vtp->setVar( $sub, 'visible_option.option', $lang['no'] );
174$checked = '';
175if ( $row['visible'] == 'false' )
176{
177  $checked = ' checked="checked"';
178}
179$vtp->setVar( $sub, 'visible_option.checked', $checked );
180$vtp->closeSession( $sub, 'visible_option' );
181// uploadable : true or false
182// a category can be uploadable if :
183//  1. upload is authorized
184//  2. category is not virtual
185//  3. category is on the main site
186if ( $conf['upload_available'] and $row['dir'] != '' and $row['site_id'] == 1 )
187{
188  $vtp->addSession( $sub, 'uploadable' );
189  $vtp->addSession( $sub, 'uploadable_option' );
190  $vtp->setVar( $sub, 'uploadable_option.value', 'true' );
191  $vtp->setVar( $sub, 'uploadable_option.option', $lang['yes'] );
192  $checked = '';
193  if ( $row['uploadable'] == 'true' )
194  {
195    $checked = ' checked="checked"';
196  }
197  $vtp->setVar( $sub, 'uploadable_option.checked', $checked );
198  $vtp->closeSession( $sub, 'uploadable_option' );
199  $vtp->addSession( $sub, 'uploadable_option' );
200  $vtp->setVar( $sub, 'uploadable_option.value', 'false' );
201  $vtp->setVar( $sub, 'uploadable_option.option', $lang['no'] );
202  $checked = '';
203  if ( $row['uploadable'] == 'false' )
204  {
205    $checked = ' checked="checked"';
206  }
207  $vtp->setVar( $sub, 'uploadable_option.checked', $checked );
208  $vtp->closeSession( $sub, 'uploadable_option' );
209  $vtp->closeSession( $sub, 'uploadable' );
210}
211// can the parent category be changed ? (is the category virtual ?)
212if ( $row['dir'] == '' )
213{
214  $vtp->addSession( $sub, 'parent' );
215  // We only show a List Of Values if the number of categories is less than
216  // $conf['max_LOV_categories']
217  $query = 'SELECT COUNT(id) AS nb_total_categories';
218  $query.= ' FROM '.PREFIX_TABLE.'categories';
219  $query.= ';';
220  $countrow = mysql_fetch_array( mysql_query( $query ) );
221  if ( $countrow['nb_total_categories'] < $conf['max_LOV_categories'] )
222  {
223    $vtp->addSession( $sub, 'associate_LOV' );
224    $vtp->addSession( $sub, 'associate_cat' );
225    $vtp->setVar( $sub, 'associate_cat.value', '-1' );
226    $vtp->setVar( $sub, 'associate_cat.content', '' );
227    $vtp->closeSession( $sub, 'associate_cat' );
228    $page['plain_structure'] = get_plain_structure( true );
229    $structure = create_structure( '', array() );
230    display_categories( $structure, '&nbsp;', $row['id_uppercat'],$row['id'] );
231    $vtp->closeSession( $sub, 'associate_LOV' );
232  }
233  // else, we only display a small text field, we suppose the administrator
234  // knows the id of its category
235  else
236  {
237    $vtp->addSession( $sub, 'associate_text' );
238    $vtp->setVar( $sub, 'associate_text.value', $row['id_uppercat'] );
239    $vtp->closeSession( $sub, 'associate_text' );
240  }
241  $vtp->closeSession( $sub, 'parent' );
242}
243//----------------------------------------------------------- sending html code
244$vtp->Parse( $handle , 'sub', $sub );
245?>
Note: See TracBrowser for help on using the repository browser.