aboutsummaryrefslogtreecommitdiffstats
path: root/admin/cat_modify.php
blob: ad0911a0c5324a4095ef18eecf84daf986f0d863 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?php
/***************************************************************************
 *                               cat_modify.php                            *
 *                            -------------------                          *
 *   application   : PhpWebGallery 1.3 <http://phpwebgallery.net>          *
 *   author        : Pierrick LE GALL <pierrick@z0rglub.com>               *
 *                                                                         *
 *   $Id$
 *                                                                         *
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation;                                         *
 *                                                                         *
 ***************************************************************************/

include_once( './admin/include/isadmin.inc.php' );
//----------------------------------------------------- template initialization
$sub = $vtp->Open( './template/'.$user['template'].'/admin/cat_modify.vtp' );
$tpl = array( 'remote_site','editcat_confirm','editcat_back','editcat_title1',
              'editcat_name','editcat_comment','editcat_status',
              'editcat_visible','editcat_visible_info', 'submit',
              'editcat_uploadable','cat_virtual','cat_parent' );
templatize_array( $tpl, 'lang', $sub );
//---------------------------------------------------------------- verification
if ( !is_numeric( $_GET['cat'] ) )
{
  $_GET['cat'] = '-1';
}
//--------------------------------------------------------- form criteria check
if ( isset( $_POST['submit'] ) )
{
  // if new status is different from previous one, deletion of all related
  // links for access rights
  $query = 'SELECT status';
  $query.= ' FROM '.PREFIX_TABLE.'categories';
  $query.= ' WHERE id = '.$_GET['cat'];
  $query.= ';';
  $row = mysql_fetch_array( mysql_query( $query ) );

  if ( $_POST['status'] != $row['status'] )
  {
    // deletion of all access for groups concerning this category
    $query = 'DELETE';
    $query.= ' FROM '.PREFIX_TABLE.'group_access';
    $query.= ' WHERE cat_id = '.$_GET['cat'];
    mysql_query( $query );
    // deletion of all access for users concerning this category
    $query = 'DELETE';
    $query.= ' FROM '.PREFIX_TABLE.'user_access';
    $query.= ' WHERE cat_id = '.$_GET['cat'];
    mysql_query( $query );
  }
  
  $query = 'UPDATE '.PREFIX_TABLE.'categories';

  $query.= ' SET name = ';
  if ( $_POST['name'] == '' )
    $query.= 'NULL';
  else
    $query.= "'".htmlentities( $_POST['name'], ENT_QUOTES)."'";

  $query.= ', comment = ';
  if ( $_POST['comment'] == '' )
    $query.= 'NULL';
  else
    $query.= "'".htmlentities( $_POST['comment'], ENT_QUOTES )."'";

  $query.= ", status = '".$_POST['status']."'";
  $query.= ", visible = '".$_POST['visible']."'";

  if ( isset( $_POST['uploadable'] ) )
    $query.= ", uploadable = '".$_POST['uploadable']."'";

  if ( isset( $_POST['associate'] ) )
  {
    $query.= ', id_uppercat = ';
    if ( $_POST['associate'] == -1 ) $query.= 'NULL';
    else                             $query.= $_POST['associate'];
  }
  $query.= ' WHERE id = '.$_GET['cat'];
  $query.= ';';
  mysql_query( $query );

  // checking users favorites
  $query = 'SELECT id';
  $query.= ' FROM '.PREFIX_TABLE.'users';
  $query.= ';';
  $result = mysql_query( $query );
  while ( $row = mysql_fetch_array( $result ) )
  {
    check_favorites( $row['id'] );
  }

  $vtp->addSession( $sub, 'confirmation' );
  $url = add_session_id( './admin.php?page=cat_list' );
  $vtp->setVar( $sub, 'confirmation.back_url', $url );
  $vtp->closeSession( $sub, 'confirmation' );
}
//------------------------------------------------------------------------ form
$form_action = './admin.php?page=cat_modify&amp;cat='.$_GET['cat'];
$vtp->setVar( $sub, 'form_action', add_session_id( $form_action ) );

$query = 'SELECT a.id,name,dir,status,comment,uploadable';
$query.= ',id_uppercat,site_id,galleries_url,visible';
$query.= ' FROM '.PREFIX_TABLE.'categories as a, '.PREFIX_TABLE.'sites as b';
$query.= ' WHERE a.id = '.$_GET['cat'];
$query.= ' AND a.site_id = b.id';
$query.= ';';
$row = mysql_fetch_array( mysql_query( $query ) );
$result = get_cat_info( $row['id'] );
// cat name
$cat_name = get_cat_display_name( $result['name'], ' - ', '' );
$vtp->setVar( $sub, 'cat:name', $cat_name );
// cat dir
if ( $row['dir'] != '' )
{
  $vtp->addSession( $sub, 'storage' );
  $vtp->setVar( $sub, 'storage.dir', $row['dir'] );
  $vtp->closeSession( $sub, 'storage' );
}
else
{
  $vtp->addSession( $sub, 'virtual' );
  $vtp->closeSession( $sub, 'virtual' );
}
// remote site ?
if ( $row['site_id'] != 1 )
{
  $vtp->addSession( $sub, 'server' );
  $vtp->setVar( $sub, 'server.url', $row['galleries_url'] );
  $vtp->closeSession( $sub, 'server' );
}
$vtp->setVar( $sub, 'name',    $row['name'] );
$vtp->setVar( $sub, 'comment', $row['comment'] );
// status : public, private...
$options = get_enums( PREFIX_TABLE.'categories', 'status' );
foreach ( $options as $option  ) {
  $vtp->addSession( $sub, 'status_option' );
  $vtp->setVar( $sub, 'status_option.option', $lang[$option] );
  $vtp->setVar( $sub, 'status_option.value', $option );
  if ( $option == $row['status'] )
  {
    $vtp->setVar( $sub, 'status_option.checked', ' checked="checked"' );  
  }
  $vtp->closeSession( $sub, 'status_option' );
}
// visible : true or false
$vtp->addSession( $sub, 'visible_option' );
$vtp->setVar( $sub, 'visible_option.value', 'true' );
$vtp->setVar( $sub, 'visible_option.option', $lang['yes'] );
$checked = '';
if ( $row['visible'] == 'true' )
{
  $checked = ' checked="checked"';
}
$vtp->setVar( $sub, 'visible_option.checked', $checked );
$vtp->closeSession( $sub, 'visible_option' );
$vtp->addSession( $sub, 'visible_option' );
$vtp->setVar( $sub, 'visible_option.value', 'false' );
$vtp->setVar( $sub, 'visible_option.option', $lang['no'] );
$checked = '';
if ( $row['visible'] == 'false' )
{
  $checked = ' checked="checked"';
}
$vtp->setVar( $sub, 'visible_option.checked', $checked );
$vtp->closeSession( $sub, 'visible_option' );
// uploadable : true or false
// a category can be uploadable if :
//  1. upload is authorized
//  2. category is not virtual
//  3. category is on the main site
if ( $conf['upload_available'] and $row['dir'] != '' and $row['site_id'] == 1 )
{
  $vtp->addSession( $sub, 'uploadable' );
  $vtp->addSession( $sub, 'uploadable_option' );
  $vtp->setVar( $sub, 'uploadable_option.value', 'true' );
  $vtp->setVar( $sub, 'uploadable_option.option', $lang['yes'] );
  $checked = '';
  if ( $row['uploadable'] == 'true' )
  {
    $checked = ' checked="checked"';
  }
  $vtp->setVar( $sub, 'uploadable_option.checked', $checked );
  $vtp->closeSession( $sub, 'uploadable_option' );
  $vtp->addSession( $sub, 'uploadable_option' );
  $vtp->setVar( $sub, 'uploadable_option.value', 'false' );
  $vtp->setVar( $sub, 'uploadable_option.option', $lang['no'] );
  $checked = '';
  if ( $row['uploadable'] == 'false' )
  {
    $checked = ' checked="checked"';
  }
  $vtp->setVar( $sub, 'uploadable_option.checked', $checked );
  $vtp->closeSession( $sub, 'uploadable_option' );
  $vtp->closeSession( $sub, 'uploadable' );
}
// can the parent category be changed ? (is the category virtual ?)
if ( $row['dir'] == '' )
{
  $vtp->addSession( $sub, 'parent' );
  $vtp->addSession( $sub, 'associate_cat' );
  $vtp->setVar( $sub, 'associate_cat.value', '-1' );
  $vtp->setVar( $sub, 'associate_cat.content', '' );
  $vtp->closeSession( $sub, 'associate_cat' );
  $structure = create_structure( '', array() );
  display_categories( $structure, '&nbsp;', $row['id_uppercat'], $row['id'] );
  $vtp->closeSession( $sub, 'parent' );
}
//----------------------------------------------------------- sending html code
$vtp->Parse( $handle , 'sub', $sub );
?>