1 | <?php |
---|
2 | /*************************************************************************** |
---|
3 | * infos_images.php * |
---|
4 | * ------------------ * |
---|
5 | * application : PhpWebGallery 1.3 * |
---|
6 | * author : Pierrick LE GALL <pierrick@z0rglub.com> * |
---|
7 | * * |
---|
8 | ***************************************************************************/ |
---|
9 | |
---|
10 | /*************************************************************************** |
---|
11 | * * |
---|
12 | * This program is free software; you can redistribute it and/or modify * |
---|
13 | * it under the terms of the GNU General Public License as published by * |
---|
14 | * the Free Software Foundation; * |
---|
15 | * * |
---|
16 | ***************************************************************************/ |
---|
17 | |
---|
18 | include_once( './include/isadmin.inc.php' ); |
---|
19 | include_once( '../template/'.$user['template'].'/htmlfunctions.inc.php' ); |
---|
20 | //------------------------------------------------------------------- functions |
---|
21 | function check_date_format( $date ) |
---|
22 | { |
---|
23 | // date arrives at this format : DD/MM/YYYY |
---|
24 | // checkdate ( int month, int day, int year) |
---|
25 | $tab_date = explode( '/', $date ); |
---|
26 | return checkdate ( $tab_date[1], $tab_date[0], $tab_date[2]); |
---|
27 | } |
---|
28 | |
---|
29 | function date_convert( $date ) |
---|
30 | { |
---|
31 | // date arrives at this format : DD/MM/YYYY |
---|
32 | // It must be transformed in YYYY-MM-DD |
---|
33 | $tab_date = explode( '/', $date ); |
---|
34 | return $tab_date[2].'-'.$tab_date[1].'-'.$tab_date[0]; |
---|
35 | } |
---|
36 | |
---|
37 | function date_convert_back( $date ) |
---|
38 | { |
---|
39 | // date arrives at this format : YYYY-MM-DD |
---|
40 | // It must be transformed in DD/MM/YYYY |
---|
41 | if ( $date != '' ) |
---|
42 | { |
---|
43 | $tab_date = explode( '-', $date ); |
---|
44 | return $tab_date[2].'/'.$tab_date[1].'/'.$tab_date[0]; |
---|
45 | } |
---|
46 | else |
---|
47 | { |
---|
48 | return ''; |
---|
49 | } |
---|
50 | } |
---|
51 | //-------------------------------------------------------------- initialization |
---|
52 | check_cat_id( $_GET['cat_id'] ); |
---|
53 | |
---|
54 | if ( isset( $page['cat'] ) ) |
---|
55 | { |
---|
56 | //--------------------------------------------------- update individual options |
---|
57 | $query = 'SELECT id,file'; |
---|
58 | $query.= ' FROM '.PREFIX_TABLE.'images'; |
---|
59 | $query.= ' WHERE cat_id = '.$page['cat']; |
---|
60 | $query.= ';'; |
---|
61 | $result = mysql_query( $query ); |
---|
62 | $i = 1; |
---|
63 | while ( $row = mysql_fetch_array( $result ) ) |
---|
64 | { |
---|
65 | $name = 'name-'.$row['id']; |
---|
66 | $author = 'author-'.$row['id']; |
---|
67 | $comment = 'comment-'.$row['id']; |
---|
68 | $date_creation = 'date_creation-'.$row['id']; |
---|
69 | if ( isset( $_POST[$name] ) ) |
---|
70 | { |
---|
71 | $query = 'UPDATE '.PREFIX_TABLE.'images'; |
---|
72 | if ( $_POST[$name] == '' ) |
---|
73 | { |
---|
74 | $query.= ' SET name = NULL'; |
---|
75 | } |
---|
76 | else |
---|
77 | { |
---|
78 | $query.= " SET name = '".htmlentities( $_POST[$name], ENT_QUOTES )."'"; |
---|
79 | } |
---|
80 | if ( $_POST[$author] == '' ) |
---|
81 | { |
---|
82 | $query.= ', author = NULL'; |
---|
83 | } |
---|
84 | else |
---|
85 | { |
---|
86 | $query.= ", author = '".htmlentities($_POST[$author],ENT_QUOTES)."'"; |
---|
87 | } |
---|
88 | if ( $_POST[$comment] == '' ) |
---|
89 | { |
---|
90 | $query.= ', comment = NULL'; |
---|
91 | } |
---|
92 | else |
---|
93 | { |
---|
94 | $query.= ", comment = '".htmlentities($_POST[$comment],ENT_QUOTES)."'"; |
---|
95 | } |
---|
96 | if ( check_date_format( $_POST[$date_creation] ) ) |
---|
97 | { |
---|
98 | $date = date_convert( $_POST[$date_creation] ); |
---|
99 | $query.= ", date_creation = '".$date."'"; |
---|
100 | } |
---|
101 | else if ( $_POST[$date_creation] == '' ) |
---|
102 | { |
---|
103 | $query.= ', date_creation = NULL'; |
---|
104 | } |
---|
105 | $query.= ' WHERE id = '.$row['id']; |
---|
106 | $query.= ';'; |
---|
107 | mysql_query( $query ); |
---|
108 | } |
---|
109 | } |
---|
110 | //------------------------------------------------------ update general options |
---|
111 | if ( $_POST['use_common_author'] == 1 ) |
---|
112 | { |
---|
113 | $query = 'UPDATE '.PREFIX_TABLE.'images'; |
---|
114 | if ( $_POST['author_cat'] == '' ) |
---|
115 | { |
---|
116 | $query.= ' SET author = NULL'; |
---|
117 | } |
---|
118 | else |
---|
119 | { |
---|
120 | $query.= ' SET author = '; |
---|
121 | $query.= "'".htmlentities( $_POST['author_cat'], ENT_QUOTES )."'"; |
---|
122 | } |
---|
123 | $query.= ' WHERE cat_id = '.$page['cat']; |
---|
124 | $query.= ';'; |
---|
125 | mysql_query( $query ); |
---|
126 | } |
---|
127 | if ( $_POST['use_common_date_creation'] == 1 ) |
---|
128 | { |
---|
129 | if ( check_date_format( $_POST['date_creation_cat'] ) ) |
---|
130 | { |
---|
131 | $date = date_convert( $_POST['date_creation_cat'] ); |
---|
132 | $query = 'UPDATE '.PREFIX_TABLE.'images'; |
---|
133 | if ( $_POST['date_creation_cat'] == '' ) |
---|
134 | { |
---|
135 | $query.= ' SET date_creation = NULL'; |
---|
136 | } |
---|
137 | else |
---|
138 | { |
---|
139 | $query.= " SET date_creation = '".$date."'"; |
---|
140 | } |
---|
141 | $query.= ' WHERE cat_id = '.$page['cat']; |
---|
142 | $query.= ';'; |
---|
143 | mysql_query( $query ); |
---|
144 | } |
---|
145 | else |
---|
146 | { |
---|
147 | echo $lang['err_date']; |
---|
148 | } |
---|
149 | } |
---|
150 | //--------------------------------------------------------- form initialization |
---|
151 | $page['nb_image_page'] = 5; |
---|
152 | |
---|
153 | if( !isset( $_GET['start'] ) |
---|
154 | or !is_numeric( $_GET['start'] ) |
---|
155 | or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) ) |
---|
156 | { |
---|
157 | $page['start'] = 0; |
---|
158 | } |
---|
159 | else |
---|
160 | { |
---|
161 | $page['start'] = $_GET['start']; |
---|
162 | } |
---|
163 | |
---|
164 | if ( is_numeric( $_GET['num'] ) and $_GET['num'] >= 0 ) |
---|
165 | { |
---|
166 | $page['start'] = |
---|
167 | floor( $_GET['num'] / $page['nb_image_page'] ) * $page['nb_image_page']; |
---|
168 | } |
---|
169 | // retrieving category information |
---|
170 | $result = get_cat_info( $page['cat'] ); |
---|
171 | $cat['local_dir'] = $result['local_dir']; |
---|
172 | $cat['dir'] = $result['dir']; |
---|
173 | $cat['name'] = $result['name']; |
---|
174 | $cat['site_id'] = $result['site_id']; |
---|
175 | $cat['nb_images'] = $result['nb_images']; |
---|
176 | //----------------------------------------------------- template initialization |
---|
177 | $sub = $vtp->Open('../template/'.$user['template'].'/admin/infos_image.vtp'); |
---|
178 | $tpl = array( 'infoimage_general','author','infoimage_useforall','submit', |
---|
179 | 'infoimage_creation_date','infoimage_detailed','thumbnail', |
---|
180 | 'infoimage_title','infoimage_comment', |
---|
181 | 'infoimage_creation_date' ); |
---|
182 | templatize_array( $tpl, 'lang', $sub ); |
---|
183 | //------------------------------------------------------------------------ form |
---|
184 | $url = './admin.php?page=infos_images&cat_id='.$page['cat']; |
---|
185 | $url.= '&start='.$page['start']; |
---|
186 | $vtp->setVar( $sub, 'form_action', add_session_id( $url ) ); |
---|
187 | $page['navigation_bar'] = create_navigation_bar( |
---|
188 | $url, $cat['nb_images'],$page['start'], $page['nb_image_page'], '' ); |
---|
189 | $vtp->setVar( $sub, 'navigation_bar', $page['navigation_bar'] ); |
---|
190 | $cat_name = get_cat_display_name( $cat['name'], ' - ', 'font-style:italic;'); |
---|
191 | $vtp->setVar( $sub, 'cat_name', $cat_name ); |
---|
192 | |
---|
193 | $query = 'SELECT id,file,comment,author,tn_ext,name,date_creation'; |
---|
194 | $query.= ' FROM '.PREFIX_TABLE.'images'; |
---|
195 | $query.= ' WHERE cat_id = '.$page['cat']; |
---|
196 | $query.= $conf['order_by']; |
---|
197 | $query.= ' LIMIT '.$page['start'].','.$page['nb_image_page']; |
---|
198 | $query.= ';'; |
---|
199 | $result = mysql_query( $query ); |
---|
200 | while ( $row = mysql_fetch_array( $result ) ) |
---|
201 | { |
---|
202 | $vtp->addSession( $sub, 'picture' ); |
---|
203 | $vtp->setVar( $sub, 'picture.id', $row['id'] ); |
---|
204 | $vtp->setVar( $sub, 'picture.filename', $row['file'] ); |
---|
205 | $vtp->setVar( $sub, 'picture.name', $row['name'] ); |
---|
206 | $vtp->setVar( $sub, 'picture.author', $row['author'] ); |
---|
207 | $vtp->setVar( $sub, 'picture.comment', $row['comment'] ); |
---|
208 | $vtp->setVar( $sub, 'picture.date_creation', |
---|
209 | date_convert_back( $row['date_creation'] ) ); |
---|
210 | $file = get_filename_wo_extension( $row['file'] ); |
---|
211 | $vtp->setVar( $sub, 'picture.default_name', $file ); |
---|
212 | // creating url to thumbnail |
---|
213 | if ( $cat['site_id'] == 1 ) |
---|
214 | { |
---|
215 | $thumbnail_url = '../galleries/'.$cat['local_dir'].'/'; |
---|
216 | } |
---|
217 | else |
---|
218 | { |
---|
219 | $thumbnail_url = $cat['dir']; |
---|
220 | } |
---|
221 | $thumbnail_url.= 'thumbnail/'; |
---|
222 | $thumbnail_url.= $conf['prefix_thumbnail'].$file.".".$row['tn_ext']; |
---|
223 | $vtp->setVar( $sub, 'picture.thumbnail_url', $thumbnail_url ); |
---|
224 | $url = '../picture.php?cat='.$_GET['cat_id'].'&image_id='.$row['id']; |
---|
225 | $vtp->setVar( $sub, 'picture.url', add_session_id( $url ) ); |
---|
226 | $vtp->closeSession( $sub, 'picture' ); |
---|
227 | } |
---|
228 | } |
---|
229 | //----------------------------------------------------------- sending html code |
---|
230 | $vtp->Parse( $handle , 'sub', $sub ); |
---|
231 | ?> |
---|