source: trunk/admin/cat_modify.php @ 394

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