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 322 2004-01-26 23:29:52Z 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 | |
---|
20 | include_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' ); |
---|
27 | templatize_array( $tpl, 'lang', $sub ); |
---|
28 | //---------------------------------------------------------------- verification |
---|
29 | if ( !is_numeric( $_GET['cat'] ) ) |
---|
30 | { |
---|
31 | $_GET['cat'] = '-1'; |
---|
32 | } |
---|
33 | //--------------------------------------------------------- form criteria check |
---|
34 | if ( 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 ) $query.= 'NULL'; |
---|
68 | else $query.= $_POST['associate']; |
---|
69 | } |
---|
70 | $query.= ' WHERE id = '.$_GET['cat']; |
---|
71 | $query.= ';'; |
---|
72 | mysql_query( $query ); |
---|
73 | |
---|
74 | if ( $_POST['status'] != $row['status'] ) |
---|
75 | { |
---|
76 | // deletion of all access for groups concerning this category |
---|
77 | $query = 'DELETE'; |
---|
78 | $query.= ' FROM '.PREFIX_TABLE.'group_access'; |
---|
79 | $query.= ' WHERE cat_id = '.$_GET['cat']; |
---|
80 | mysql_query( $query ); |
---|
81 | // deletion of all access for users concerning this category |
---|
82 | $query = 'DELETE'; |
---|
83 | $query.= ' FROM '.PREFIX_TABLE.'user_access'; |
---|
84 | $query.= ' WHERE cat_id = '.$_GET['cat']; |
---|
85 | mysql_query( $query ); |
---|
86 | // resynchronize all users |
---|
87 | synchronize_all_users(); |
---|
88 | } |
---|
89 | |
---|
90 | // checking users favorites |
---|
91 | $query = 'SELECT id'; |
---|
92 | $query.= ' FROM '.PREFIX_TABLE.'users'; |
---|
93 | $query.= ';'; |
---|
94 | $result = mysql_query( $query ); |
---|
95 | while ( $row = mysql_fetch_array( $result ) ) |
---|
96 | { |
---|
97 | check_favorites( $row['id'] ); |
---|
98 | } |
---|
99 | |
---|
100 | $vtp->addSession( $sub, 'confirmation' ); |
---|
101 | $url = add_session_id( './admin.php?page=cat_list' ); |
---|
102 | $vtp->setVar( $sub, 'confirmation.back_url', $url ); |
---|
103 | $vtp->closeSession( $sub, 'confirmation' ); |
---|
104 | } |
---|
105 | //------------------------------------------------------------------------ form |
---|
106 | $form_action = './admin.php?page=cat_modify&cat='.$_GET['cat']; |
---|
107 | $vtp->setVar( $sub, 'form_action', add_session_id( $form_action ) ); |
---|
108 | |
---|
109 | $query = 'SELECT a.id,name,dir,status,comment,uploadable'; |
---|
110 | $query.= ',id_uppercat,site_id,galleries_url,visible'; |
---|
111 | $query.= ' FROM '.PREFIX_TABLE.'categories as a, '.PREFIX_TABLE.'sites as b'; |
---|
112 | $query.= ' WHERE a.id = '.$_GET['cat']; |
---|
113 | $query.= ' AND a.site_id = b.id'; |
---|
114 | $query.= ';'; |
---|
115 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
116 | $result = get_cat_info( $row['id'] ); |
---|
117 | // cat name |
---|
118 | $cat_name = get_cat_display_name( $result['name'], ' - ', '' ); |
---|
119 | $vtp->setVar( $sub, 'cat:name', $cat_name ); |
---|
120 | // cat dir |
---|
121 | if ( isset( $row['dir'] ) and $row['dir'] != '' ) |
---|
122 | { |
---|
123 | $vtp->addSession( $sub, 'storage' ); |
---|
124 | $vtp->setVar( $sub, 'storage.dir', $row['dir'] ); |
---|
125 | $vtp->closeSession( $sub, 'storage' ); |
---|
126 | } |
---|
127 | else |
---|
128 | { |
---|
129 | $vtp->addSession( $sub, 'virtual' ); |
---|
130 | $vtp->closeSession( $sub, 'virtual' ); |
---|
131 | } |
---|
132 | // remote site ? |
---|
133 | if ( $row['site_id'] != 1 ) |
---|
134 | { |
---|
135 | $vtp->addSession( $sub, 'server' ); |
---|
136 | $vtp->setVar( $sub, 'server.url', $row['galleries_url'] ); |
---|
137 | $vtp->closeSession( $sub, 'server' ); |
---|
138 | } |
---|
139 | $vtp->setVar( $sub, 'name', $row['name'] ); |
---|
140 | if ( !isset( $row['comment'] ) ) $row['comment'] = ''; |
---|
141 | $vtp->setVar( $sub, 'comment', $row['comment'] ); |
---|
142 | // status : public, private... |
---|
143 | $options = get_enums( PREFIX_TABLE.'categories', 'status' ); |
---|
144 | foreach ( $options as $option ) { |
---|
145 | $vtp->addSession( $sub, 'status_option' ); |
---|
146 | $vtp->setVar( $sub, 'status_option.option', $lang[$option] ); |
---|
147 | $vtp->setVar( $sub, 'status_option.value', $option ); |
---|
148 | if ( $option == $row['status'] ) |
---|
149 | { |
---|
150 | $vtp->setVar( $sub, 'status_option.checked', ' checked="checked"' ); |
---|
151 | } |
---|
152 | $vtp->closeSession( $sub, 'status_option' ); |
---|
153 | } |
---|
154 | // visible : true or false |
---|
155 | $vtp->addSession( $sub, 'visible_option' ); |
---|
156 | $vtp->setVar( $sub, 'visible_option.value', 'true' ); |
---|
157 | $vtp->setVar( $sub, 'visible_option.option', $lang['yes'] ); |
---|
158 | $checked = ''; |
---|
159 | if ( $row['visible'] == 'true' ) |
---|
160 | { |
---|
161 | $checked = ' checked="checked"'; |
---|
162 | } |
---|
163 | $vtp->setVar( $sub, 'visible_option.checked', $checked ); |
---|
164 | $vtp->closeSession( $sub, 'visible_option' ); |
---|
165 | $vtp->addSession( $sub, 'visible_option' ); |
---|
166 | $vtp->setVar( $sub, 'visible_option.value', 'false' ); |
---|
167 | $vtp->setVar( $sub, 'visible_option.option', $lang['no'] ); |
---|
168 | $checked = ''; |
---|
169 | if ( $row['visible'] == 'false' ) |
---|
170 | { |
---|
171 | $checked = ' checked="checked"'; |
---|
172 | } |
---|
173 | $vtp->setVar( $sub, 'visible_option.checked', $checked ); |
---|
174 | $vtp->closeSession( $sub, 'visible_option' ); |
---|
175 | // uploadable : true or false |
---|
176 | // a category can be uploadable if : |
---|
177 | // 1. upload is authorized |
---|
178 | // 2. category is not virtual |
---|
179 | // 3. category is on the main site |
---|
180 | if ( $conf['upload_available'] and $row['dir'] != '' and $row['site_id'] == 1 ) |
---|
181 | { |
---|
182 | $vtp->addSession( $sub, 'uploadable' ); |
---|
183 | $vtp->addSession( $sub, 'uploadable_option' ); |
---|
184 | $vtp->setVar( $sub, 'uploadable_option.value', 'true' ); |
---|
185 | $vtp->setVar( $sub, 'uploadable_option.option', $lang['yes'] ); |
---|
186 | $checked = ''; |
---|
187 | if ( $row['uploadable'] == 'true' ) |
---|
188 | { |
---|
189 | $checked = ' checked="checked"'; |
---|
190 | } |
---|
191 | $vtp->setVar( $sub, 'uploadable_option.checked', $checked ); |
---|
192 | $vtp->closeSession( $sub, 'uploadable_option' ); |
---|
193 | $vtp->addSession( $sub, 'uploadable_option' ); |
---|
194 | $vtp->setVar( $sub, 'uploadable_option.value', 'false' ); |
---|
195 | $vtp->setVar( $sub, 'uploadable_option.option', $lang['no'] ); |
---|
196 | $checked = ''; |
---|
197 | if ( $row['uploadable'] == 'false' ) |
---|
198 | { |
---|
199 | $checked = ' checked="checked"'; |
---|
200 | } |
---|
201 | $vtp->setVar( $sub, 'uploadable_option.checked', $checked ); |
---|
202 | $vtp->closeSession( $sub, 'uploadable_option' ); |
---|
203 | $vtp->closeSession( $sub, 'uploadable' ); |
---|
204 | } |
---|
205 | // can the parent category be changed ? (is the category virtual ?) |
---|
206 | if ( $row['dir'] == '' ) |
---|
207 | { |
---|
208 | $vtp->addSession( $sub, 'parent' ); |
---|
209 | $vtp->addSession( $sub, 'associate_cat' ); |
---|
210 | $vtp->setVar( $sub, 'associate_cat.value', '-1' ); |
---|
211 | $vtp->setVar( $sub, 'associate_cat.content', '' ); |
---|
212 | $vtp->closeSession( $sub, 'associate_cat' ); |
---|
213 | $structure = create_structure( '', array() ); |
---|
214 | display_categories( $structure, ' ', $row['id_uppercat'], $row['id'] ); |
---|
215 | $vtp->closeSession( $sub, 'parent' ); |
---|
216 | } |
---|
217 | //----------------------------------------------------------- sending html code |
---|
218 | $vtp->Parse( $handle , 'sub', $sub ); |
---|
219 | ?> |
---|