source: trunk/admin/cat_modify.php @ 225

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

Modifying ../template in ./template since admin.php has moved to the PhpWebGallery root directory

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.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 225 2003-11-02 11:18:25Z 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  if ( $_POST['status'] != $row['status'] )
45  {
46    // deletion of all access for groups concerning this category
47    $query = 'DELETE';
48    $query.= ' FROM '.PREFIX_TABLE.'group_access';
49    $query.= ' WHERE cat_id = '.$_GET['cat'];
50    mysql_query( $query );
51    // deletion of all access for users concerning this category
52    $query = 'DELETE';
53    $query.= ' FROM '.PREFIX_TABLE.'user_access';
54    $query.= ' WHERE cat_id = '.$_GET['cat'];
55    mysql_query( $query );
56  }
57 
58  $query = 'UPDATE '.PREFIX_TABLE.'categories';
59
60  $query.= ' SET name = ';
61  if ( $_POST['name'] == '' )
62    $query.= 'NULL';
63  else
64    $query.= "'".htmlentities( $_POST['name'], ENT_QUOTES)."'";
65
66  $query.= ', comment = ';
67  if ( $_POST['comment'] == '' )
68    $query.= 'NULL';
69  else
70    $query.= "'".htmlentities( $_POST['comment'], ENT_QUOTES )."'";
71
72  $query.= ", status = '".$_POST['status']."'";
73  $query.= ", visible = '".$_POST['visible']."'";
74
75  if ( isset( $_POST['uploadable'] ) )
76    $query.= ", uploadable = '".$_POST['uploadable']."'";
77
78  if ( isset( $_POST['associate'] ) )
79  {
80    $query.= ', id_uppercat = ';
81    if ( $_POST['associate'] == -1 ) $query.= 'NULL';
82    else                             $query.= $_POST['associate'];
83  }
84  $query.= ' WHERE id = '.$_GET['cat'];
85  $query.= ';';
86  mysql_query( $query );
87
88  // checking users favorites
89  $query = 'SELECT id';
90  $query.= ' FROM '.PREFIX_TABLE.'users';
91  $query.= ';';
92  $result = mysql_query( $query );
93  while ( $row = mysql_fetch_array( $result ) )
94  {
95    check_favorites( $row['id'] );
96  }
97
98  $vtp->addSession( $sub, 'confirmation' );
99  $url = add_session_id( './admin.php?page=cat_list' );
100  $vtp->setVar( $sub, 'confirmation.back_url', $url );
101  $vtp->closeSession( $sub, 'confirmation' );
102}
103//------------------------------------------------------------------------ form
104$form_action = './admin.php?page=cat_modify&amp;cat='.$_GET['cat'];
105$vtp->setVar( $sub, 'form_action', add_session_id( $form_action ) );
106
107$query = 'SELECT a.id,name,dir,status,comment,uploadable';
108$query.= ',id_uppercat,site_id,galleries_url,visible';
109$query.= ' FROM '.PREFIX_TABLE.'categories as a, '.PREFIX_TABLE.'sites as b';
110$query.= ' WHERE a.id = '.$_GET['cat'];
111$query.= ' AND a.site_id = b.id';
112$query.= ';';
113$row = mysql_fetch_array( mysql_query( $query ) );
114$result = get_cat_info( $row['id'] );
115// cat name
116$cat_name = get_cat_display_name( $result['name'], ' - ', '' );
117$vtp->setVar( $sub, 'cat:name', $cat_name );
118// cat dir
119if ( $row['dir'] != '' )
120{
121  $vtp->addSession( $sub, 'storage' );
122  $vtp->setVar( $sub, 'storage.dir', $row['dir'] );
123  $vtp->closeSession( $sub, 'storage' );
124}
125else
126{
127  $vtp->addSession( $sub, 'virtual' );
128  $vtp->closeSession( $sub, 'virtual' );
129}
130// remote site ?
131if ( $row['site_id'] != 1 )
132{
133  $vtp->addSession( $sub, 'server' );
134  $vtp->setVar( $sub, 'server.url', $row['galleries_url'] );
135  $vtp->closeSession( $sub, 'server' );
136}
137$vtp->setVar( $sub, 'name',    $row['name'] );
138$vtp->setVar( $sub, 'comment', $row['comment'] );
139// status : public, private...
140$options = get_enums( PREFIX_TABLE.'categories', 'status' );
141foreach ( $options as $option  ) {
142  $vtp->addSession( $sub, 'status_option' );
143  $vtp->setVar( $sub, 'status_option.option', $lang[$option] );
144  $vtp->setVar( $sub, 'status_option.value', $option );
145  if ( $option == $row['status'] )
146  {
147    $vtp->setVar( $sub, 'status_option.checked', ' checked="checked"' ); 
148  }
149  $vtp->closeSession( $sub, 'status_option' );
150}
151// visible : true or false
152$vtp->addSession( $sub, 'visible_option' );
153$vtp->setVar( $sub, 'visible_option.value', 'true' );
154$vtp->setVar( $sub, 'visible_option.option', $lang['yes'] );
155$checked = '';
156if ( $row['visible'] == 'true' )
157{
158  $checked = ' checked="checked"';
159}
160$vtp->setVar( $sub, 'visible_option.checked', $checked );
161$vtp->closeSession( $sub, 'visible_option' );
162$vtp->addSession( $sub, 'visible_option' );
163$vtp->setVar( $sub, 'visible_option.value', 'false' );
164$vtp->setVar( $sub, 'visible_option.option', $lang['no'] );
165$checked = '';
166if ( $row['visible'] == 'false' )
167{
168  $checked = ' checked="checked"';
169}
170$vtp->setVar( $sub, 'visible_option.checked', $checked );
171$vtp->closeSession( $sub, 'visible_option' );
172// uploadable : true or false
173// a category can be uploadable if :
174//  1. upload is authorized
175//  2. category is not virtual
176//  3. category is on the main site
177if ( $conf['upload_available'] and $row['dir'] != '' and $row['site_id'] == 1 )
178{
179  $vtp->addSession( $sub, 'uploadable' );
180  $vtp->addSession( $sub, 'uploadable_option' );
181  $vtp->setVar( $sub, 'uploadable_option.value', 'true' );
182  $vtp->setVar( $sub, 'uploadable_option.option', $lang['yes'] );
183  $checked = '';
184  if ( $row['uploadable'] == 'true' )
185  {
186    $checked = ' checked="checked"';
187  }
188  $vtp->setVar( $sub, 'uploadable_option.checked', $checked );
189  $vtp->closeSession( $sub, 'uploadable_option' );
190  $vtp->addSession( $sub, 'uploadable_option' );
191  $vtp->setVar( $sub, 'uploadable_option.value', 'false' );
192  $vtp->setVar( $sub, 'uploadable_option.option', $lang['no'] );
193  $checked = '';
194  if ( $row['uploadable'] == 'false' )
195  {
196    $checked = ' checked="checked"';
197  }
198  $vtp->setVar( $sub, 'uploadable_option.checked', $checked );
199  $vtp->closeSession( $sub, 'uploadable_option' );
200  $vtp->closeSession( $sub, 'uploadable' );
201}
202// can the parent category be changed ? (is the category virtual ?)
203if ( $row['dir'] == '' )
204{
205  $vtp->addSession( $sub, 'parent' );
206  $vtp->addSession( $sub, 'associate_cat' );
207  $vtp->setVar( $sub, 'associate_cat.value', '-1' );
208  $vtp->setVar( $sub, 'associate_cat.content', '' );
209  $vtp->closeSession( $sub, 'associate_cat' );
210  $structure = create_structure( '', array() );
211  display_categories( $structure, '&nbsp;', $row['id_uppercat'], $row['id'] );
212  $vtp->closeSession( $sub, 'parent' );
213}
214//----------------------------------------------------------- sending html code
215$vtp->Parse( $handle , 'sub', $sub );
216?>
Note: See TracBrowser for help on using the repository browser.