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-09-20 21:10:17 +0000 (Mon, 20 Sep 2004) $ |
---|
10 | // | last modifier : $Author: z0rglub $ |
---|
11 | // | revision : $Revision: 530 $ |
---|
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 | |
---|
28 | if( !defined("PHPWG_ROOT_PATH") ) |
---|
29 | { |
---|
30 | die ("Hacking attempt!"); |
---|
31 | } |
---|
32 | include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php' ); |
---|
33 | |
---|
34 | //---------------------------------------------------------------- verification |
---|
35 | if ( !isset( $_GET['cat_id'] ) || !is_numeric( $_GET['cat_id'] ) ) |
---|
36 | { |
---|
37 | $_GET['cat_id'] = '-1'; |
---|
38 | } |
---|
39 | |
---|
40 | $template->set_filenames( array('categories'=>'admin/cat_modify.tpl') ); |
---|
41 | |
---|
42 | //--------------------------------------------------------- form criteria check |
---|
43 | if ( isset( $_POST['submit'] ) ) |
---|
44 | { |
---|
45 | // if new status is different from previous one, deletion of all related |
---|
46 | // links for access rights |
---|
47 | $query = 'SELECT status'; |
---|
48 | $query.= ' FROM '.CATEGORIES_TABLE; |
---|
49 | $query.= ' WHERE id = '.$_GET['cat_id']; |
---|
50 | $query.= ';'; |
---|
51 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
52 | |
---|
53 | $query = 'UPDATE '.CATEGORIES_TABLE; |
---|
54 | $query.= ' SET name = '; |
---|
55 | if ( empty($_POST['name'])) |
---|
56 | $query.= 'NULL'; |
---|
57 | else |
---|
58 | $query.= "'".htmlentities( $_POST['name'], ENT_QUOTES)."'"; |
---|
59 | |
---|
60 | $query.= ', comment = '; |
---|
61 | if ( empty($_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 | if ( isset( $_POST['uploadable'] ) ) |
---|
69 | $query.= ", uploadable = '".$_POST['uploadable']."'"; |
---|
70 | |
---|
71 | if ( isset( $_POST['associate'] ) ) |
---|
72 | { |
---|
73 | $query.= ', id_uppercat = '; |
---|
74 | if ( $_POST['associate'] == -1 or $_POST['associate'] == '' ) |
---|
75 | $query.= 'NULL'; |
---|
76 | else |
---|
77 | $query.= $_POST['associate']; |
---|
78 | } |
---|
79 | $query.= ' WHERE id = '.$_GET['cat_id']; |
---|
80 | $query.= ';'; |
---|
81 | mysql_query( $query ); |
---|
82 | |
---|
83 | if ( $_POST['status'] != $row['status'] ) |
---|
84 | { |
---|
85 | // deletion of all access for groups concerning this category |
---|
86 | $query = 'DELETE'; |
---|
87 | $query.= ' FROM '.GROUP_ACCESS_TABLE; |
---|
88 | $query.= ' WHERE cat_id = '.$_GET['cat_id']; |
---|
89 | mysql_query( $query ); |
---|
90 | // deletion of all access for users concerning this category |
---|
91 | $query = 'DELETE'; |
---|
92 | $query.= ' FROM '.USER_ACCESS_TABLE; |
---|
93 | $query.= ' WHERE cat_id = '.$_GET['cat_id']; |
---|
94 | mysql_query( $query ); |
---|
95 | } |
---|
96 | |
---|
97 | // checking users favorites |
---|
98 | $query = 'SELECT id'; |
---|
99 | $query.= ' FROM '.USERS_TABLE; |
---|
100 | $query.= ';'; |
---|
101 | $result = mysql_query( $query ); |
---|
102 | while ( $row = mysql_fetch_array( $result ) ) |
---|
103 | { |
---|
104 | check_favorites( $row['id'] ); |
---|
105 | } |
---|
106 | $template->assign_block_vars('confirmation' ,array()); |
---|
107 | } |
---|
108 | |
---|
109 | $query = 'SELECT a.*, b.*'; |
---|
110 | $query.= ' FROM '.CATEGORIES_TABLE.' as a, '.SITES_TABLE.' as b'; |
---|
111 | $query.= ' WHERE a.id = '.$_GET['cat_id']; |
---|
112 | $query.= ' AND a.site_id = b.id'; |
---|
113 | $query.= ';'; |
---|
114 | $category = mysql_fetch_array( mysql_query( $query ) ); |
---|
115 | // nullable fields |
---|
116 | foreach (array('comment','dir') as $nullable) |
---|
117 | { |
---|
118 | if (!isset($category[$nullable])) |
---|
119 | { |
---|
120 | $category[$nullable] = ''; |
---|
121 | } |
---|
122 | } |
---|
123 | |
---|
124 | // Navigation path |
---|
125 | $current_category = get_cat_info($_GET['cat_id']); |
---|
126 | $url = PHPWG_ROOT_PATH.'admin.php?page=cat_list&parent_id='; |
---|
127 | $navigation = '<a class="" href="'.add_session_id(PHPWG_ROOT_PATH.'admin.php?page=cat_list').'">'; |
---|
128 | $navigation.= $lang['gallery_index'].'</a>->'; |
---|
129 | $navigation.= get_cat_display_name($current_category['name'], '->', $url); |
---|
130 | |
---|
131 | $form_action = PHPWG_ROOT_PATH.'admin.php?page=cat_modify&cat_id='.$_GET['cat_id']; |
---|
132 | $access = ($category['status']=='public')?'ACCESS_FREE':'ACCESS_RESTRICTED'; |
---|
133 | $lock = ($category['visible']=='true')?'UNLOCKED':'LOCKED'; |
---|
134 | |
---|
135 | //----------------------------------------------------- template initialization |
---|
136 | $template->assign_vars(array( |
---|
137 | 'CATEGORIES_NAV'=>$navigation, |
---|
138 | 'CAT_NAME'=>$category['name'], |
---|
139 | 'CAT_COMMENT'=>$category['comment'], |
---|
140 | 'CATEGORY_DIR'=>$category['dir'], |
---|
141 | 'SITE_URL'=>$category['galleries_url'], |
---|
142 | |
---|
143 | $access=>'checked="checked"', |
---|
144 | $lock=>'checked="checked"', |
---|
145 | |
---|
146 | 'L_EDIT_CONFIRM'=>$lang['editcat_confirm'], |
---|
147 | 'L_EDIT_NAME'=>$lang['description'], |
---|
148 | 'L_STORAGE'=>$lang['storage'], |
---|
149 | 'L_EDIT_COMMENT'=>$lang['comment'], |
---|
150 | 'L_EDIT_STATUS'=>$lang['conf_access'], |
---|
151 | 'L_EDIT_STATUS_INFO'=>$lang['cat_access_info'], |
---|
152 | 'L_ACCESS_FREE'=>$lang['free'], |
---|
153 | 'L_ACCESS_RESTRICTED'=>$lang['restricted'], |
---|
154 | 'L_EDIT_LOCK'=>$lang['cat_lock'], |
---|
155 | 'L_EDIT_LOCK_INFO'=>$lang['cat_lock_info'], |
---|
156 | 'L_YES'=>$lang['yes'], |
---|
157 | 'L_NO'=>$lang['no'], |
---|
158 | 'L_SUBMIT'=>$lang['submit'], |
---|
159 | |
---|
160 | 'F_ACTION'=>add_session_id($form_action) |
---|
161 | )); |
---|
162 | |
---|
163 | if ( !empty($category['dir'])) |
---|
164 | { |
---|
165 | $template->assign_block_vars('storage' ,array()); |
---|
166 | } |
---|
167 | |
---|
168 | if ( $category['site_id'] != 1 ) |
---|
169 | { |
---|
170 | $template->assign_block_vars('storage' ,array()); |
---|
171 | } |
---|
172 | |
---|
173 | /* |
---|
174 | // can the parent category be changed ? (is the category virtual ?) |
---|
175 | if ( $row['dir'] == '' ) |
---|
176 | { |
---|
177 | $vtp->addSession( $sub, 'parent' ); |
---|
178 | // We only show a List Of Values if the number of categories is less than |
---|
179 | // $conf['max_LOV_categories'] |
---|
180 | $query = 'SELECT COUNT(id) AS nb_total_categories'; |
---|
181 | $query.= ' FROM '.CATEGORIES_TABLE; |
---|
182 | $query.= ';'; |
---|
183 | $countrow = mysql_fetch_array( mysql_query( $query ) ); |
---|
184 | if ( $countrow['nb_total_categories'] < $conf['max_LOV_categories'] ) |
---|
185 | { |
---|
186 | $vtp->addSession( $sub, 'associate_LOV' ); |
---|
187 | $vtp->addSession( $sub, 'associate_cat' ); |
---|
188 | $vtp->setVar( $sub, 'associate_cat.value', '-1' ); |
---|
189 | $vtp->setVar( $sub, 'associate_cat.content', '' ); |
---|
190 | $vtp->closeSession( $sub, 'associate_cat' ); |
---|
191 | $page['plain_structure'] = get_plain_structure( true ); |
---|
192 | $structure = create_structure( '', array() ); |
---|
193 | display_categories( $structure, ' ', $row['id_uppercat'],$row['id'] ); |
---|
194 | $vtp->closeSession( $sub, 'associate_LOV' ); |
---|
195 | } |
---|
196 | // else, we only display a small text field, we suppose the administrator |
---|
197 | // knows the id of its category |
---|
198 | else |
---|
199 | { |
---|
200 | $vtp->addSession( $sub, 'associate_text' ); |
---|
201 | $vtp->setVar( $sub, 'associate_text.value', $row['id_uppercat'] ); |
---|
202 | $vtp->closeSession( $sub, 'associate_text' ); |
---|
203 | } |
---|
204 | $vtp->closeSession( $sub, 'parent' ); |
---|
205 | } |
---|
206 | */ |
---|
207 | //----------------------------------------------------------- sending html code |
---|
208 | $template->assign_var_from_handle('ADMIN_CONTENT', 'categories'); |
---|
209 | ?> |
---|