Changeset 575 for trunk/admin/picture_modify.php
- Timestamp:
- Oct 23, 2004, 11:58:28 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/picture_modify.php
r509 r575 26 26 // +-----------------------------------------------------------------------+ 27 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 28 if(!defined("PHPWG_ROOT_PATH")) 29 { 30 die ("Hacking attempt!"); 31 } 32 include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php'); 34 33 //--------------------------------------------------------- update informations 35 34 $errors = array(); 36 35 // first, we verify whether there is a mistake on the given creation date 37 if ( isset( $_POST['date_creation'] ) and !empty($_POST['date_creation'])) 38 { 39 if ( !check_date_format( $_POST['date_creation'] ) ) 40 array_push( $errors, $lang['err_date'] ); 41 } 42 if ( isset( $_POST['submit'] ) ) 36 if (isset($_POST['date_creation']) and !empty($_POST['date_creation'])) 37 { 38 if (!check_date_format($_POST['date_creation'])) 39 { 40 array_push($errors, $lang['err_date']); 41 } 42 } 43 if (isset($_POST['submit'])) 43 44 { 44 45 $query = 'UPDATE '.IMAGES_TABLE.' SET name = '; 45 if ( $_POST['name'] == '')46 if ($_POST['name'] == '') 46 47 $query.= 'NULL'; 47 48 else 48 $query.= "'".htmlentities( $_POST['name'], ENT_QUOTES)."'";49 $query.= "'".htmlentities($_POST['name'], ENT_QUOTES)."'"; 49 50 50 51 $query.= ', author = '; 51 if ( $_POST['author'] == '')52 if ($_POST['author'] == '') 52 53 $query.= 'NULL'; 53 54 else … … 55 56 56 57 $query.= ', comment = '; 57 if ( $_POST['comment'] == '')58 if ($_POST['comment'] == '') 58 59 $query.= 'NULL'; 59 60 else … … 61 62 62 63 $query.= ', date_creation = '; 63 if ( check_date_format( $_POST['date_creation'] ))64 $query.= "'".date_convert( $_POST['date_creation'])."'";65 else if ( $_POST['date_creation'] == '')64 if (check_date_format($_POST['date_creation'])) 65 $query.= "'".date_convert($_POST['date_creation'])."'"; 66 else if ($_POST['date_creation'] == '') 66 67 $query.= 'NULL'; 67 68 68 69 $query.= ', keywords = '; 69 $keywords_array = get_keywords( $_POST['keywords']);70 if ( count( $keywords_array ) == 0)70 $keywords_array = get_keywords($_POST['keywords']); 71 if (count($keywords_array) == 0) 71 72 $query.= 'NULL'; 72 73 else 73 74 { 74 75 $query.= "'"; 75 foreach ( $keywords_array as $i => $keyword) {76 if ( $i > 0) $query.= ',';76 foreach ($keywords_array as $i => $keyword) { 77 if ($i > 0) $query.= ','; 77 78 $query.= $keyword; 78 79 } … … 82 83 $query.= ' WHERE id = '.$_GET['image_id']; 83 84 $query.= ';'; 84 mysql_query( $query);85 mysql_query($query); 85 86 // make the picture representative of a category ? 86 $query = 'SELECT DISTINCT(category_id) as category_id'; 87 $query.= ',representative_picture_id'; 88 $query.= ' FROM '.IMAGE_CATEGORY_TABLE.' AS ic'; 89 $query.= ', '.CATEGORIES_TABLE.' AS c'; 90 $query.= ' WHERE c.id = ic.category_id'; 91 $query.= ' AND image_id = '.$_GET['image_id']; 92 $query.= ';'; 93 $result = mysql_query( $query ); 94 while ( $row = mysql_fetch_array( $result ) ) 87 $query = ' 88 SELECT DISTINCT(category_id) as category_id,representative_picture_id 89 FROM '.IMAGE_CATEGORY_TABLE.' AS ic, '.CATEGORIES_TABLE.' AS c 90 WHERE c.id = ic.category_id 91 AND image_id = '.$_GET['image_id'].' 92 ;'; 93 $result = mysql_query($query); 94 while ($row = mysql_fetch_array($result)) 95 95 { 96 96 // if the user ask the picture to be the representative picture of its 97 97 // category, the category is updated in the database (without wondering 98 98 // if this picture was already the representative one) 99 if ( isset($_POST['representative-'.$row['category_id']]))99 if (isset($_POST['representative-'.$row['category_id']])) 100 100 { 101 101 $query = 'UPDATE '.CATEGORIES_TABLE; … … 103 103 $query.= ' WHERE id = '.$row['category_id']; 104 104 $query.= ';'; 105 mysql_query( $query);105 mysql_query($query); 106 106 } 107 107 // if the user ask this picture to be not any more the representative, 108 108 // we have to set the representative_picture_id of this category to NULL 109 else if ( isset( $row['representative_picture_id'] ) 110 and $row['representative_picture_id'] == $_GET['image_id'] ) 111 { 112 $query = 'UPDATE '.CATEGORIES_TABLE; 113 $query.= ' SET representative_picture_id = NULL'; 114 $query.= ' WHERE id = '.$row['category_id']; 115 $query.= ';'; 116 mysql_query( $query ); 109 else if (isset($row['representative_picture_id']) 110 and $row['representative_picture_id'] == $_GET['image_id']) 111 { 112 $query = ' 113 UPDATE '.CATEGORIES_TABLE.' 114 SET representative_picture_id = NULL 115 WHERE id = '.$row['category_id'].' 116 ;'; 117 mysql_query($query); 117 118 } 118 119 } 119 120 $associate_or_dissociate = false; 120 121 // associate with a new category ? 121 if ( $_POST['associate'] != '-1' and $_POST['associate'] != '')122 if ($_POST['associate'] != '-1' and $_POST['associate'] != '') 122 123 { 123 124 // does the uppercat id exists in the database ? 124 if ( !is_numeric( $_POST['associate'] ))125 { 126 array_push( $errors, $lang['cat_unknown_id']);125 if (!is_numeric($_POST['associate'])) 126 { 127 array_push($errors, $lang['cat_unknown_id']); 127 128 } 128 129 else 129 130 { 130 $query = 'SELECT id FROM '.CATEGORIES_TABLE; 131 $query.= ' WHERE id = '.$_POST['associate']; 132 $query.= ';'; 133 if ( mysql_num_rows( mysql_query( $query ) ) == 0 ) 134 array_push( $errors, $lang['cat_unknown_id'] ); 135 } 136 } 137 if ( $_POST['associate'] != '-1' 131 $query = ' 132 SELECT id 133 FROM '.CATEGORIES_TABLE.' 134 WHERE id = '.$_POST['associate'].' 135 ;'; 136 if (mysql_num_rows(mysql_query($query)) == 0) 137 array_push($errors, $lang['cat_unknown_id']); 138 } 139 } 140 if ($_POST['associate'] != '-1' 138 141 and $_POST['associate'] != '' 139 and count( $errors ) == 0 ) 140 { 141 $query = 'INSERT INTO '.IMAGE_CATEGORY_TABLE; 142 $query.= ' (category_id,image_id) VALUES '; 143 $query.= '('.$_POST['associate'].','.$_GET['image_id'].')'; 144 $query.= ';'; 145 mysql_query( $query); 142 and count($errors) == 0) 143 { 144 $query = ' 145 INSERT INTO '.IMAGE_CATEGORY_TABLE.' 146 (category_id,image_id) 147 VALUES 148 ('.$_POST['associate'].','.$_GET['image_id'].') 149 ;'; 150 mysql_query($query); 146 151 $associate_or_dissociate = true; 147 update_category( $_POST['associate']);152 update_category($_POST['associate']); 148 153 } 149 154 // dissociate any category ? 150 155 // retrieving all the linked categories 151 $query = 'SELECT DISTINCT(category_id) as category_id FROM '.IMAGE_CATEGORY_TABLE; 152 $query.= ' WHERE image_id = '.$_GET['image_id']; 153 $query.= ';'; 154 $result = mysql_query( $query ); 155 while ( $row = mysql_fetch_array( $result ) ) 156 { 157 if ( isset($_POST['dissociate-'.$row['category_id']]) ) 158 { 159 $query = 'DELETE FROM '.IMAGE_CATEGORY_TABLE; 160 $query.= ' WHERE image_id = '.$_GET['image_id']; 161 $query.= ' AND category_id = '.$row['category_id']; 162 $query.= ';'; 163 mysql_query( $query ); 156 $query = ' 157 SELECT DISTINCT(category_id) as category_id 158 FROM '.IMAGE_CATEGORY_TABLE.' 159 WHERE image_id = '.$_GET['image_id'].' 160 ;'; 161 $result = mysql_query($query); 162 while ($row = mysql_fetch_array($result)) 163 { 164 if (isset($_POST['dissociate-'.$row['category_id']])) 165 { 166 $query = ' 167 DELETE FROM '.IMAGE_CATEGORY_TABLE.' 168 WHERE image_id = '.$_GET['image_id'].' 169 AND category_id = '.$row['category_id'].' 170 ;'; 171 mysql_query($query); 164 172 $associate_or_dissociate = true; 165 update_category( $row['category_id']);166 } 167 } 168 if ( $associate_or_dissociate)173 update_category($row['category_id']); 174 } 175 } 176 if ($associate_or_dissociate) 169 177 { 170 178 synchronize_all_users(); … … 173 181 174 182 // retrieving direct information about picture 175 $query = 'SELECT * FROM '.IMAGES_TABLE; 176 $query.= ' WHERE id = '.$_GET['image_id']; 177 $query.= ';'; 178 $row = mysql_fetch_array( mysql_query( $query ) ); 179 180 $title = empty($row['name'])?str_replace( '_',' ',get_filename_wo_extension($row['file']) ):$row['name']; 183 $query = ' 184 SELECT * 185 FROM '.IMAGES_TABLE.' 186 WHERE id = '.$_GET['image_id'].' 187 ;'; 188 $row = mysql_fetch_array(mysql_query($query)); 189 190 // some fields are nullable in the images table 191 $nullables = array('name','author','keywords','date_creation','comment'); 192 foreach ($nullables as $field) 193 { 194 if (!isset($row[$field])) 195 { 196 $row[$field] = ''; 197 } 198 } 199 200 if (empty($row['name'])) 201 { 202 $title = str_replace('_', ' ',get_filename_wo_extension($row['file'])); 203 } 204 else 205 { 206 $title = $row['name']; 207 } 181 208 // Navigation path 182 209 $current_category = get_cat_info($row['storage_category_id']); 183 210 $dir_path = get_cat_display_name($current_category['name'], '->', ''); 184 211 185 $thumbnail_url = get_complete_dir( $row['storage_category_id']);186 $file_wo_ext = get_filename_wo_extension( $row['file']);212 $thumbnail_url = get_complete_dir($row['storage_category_id']); 213 $file_wo_ext = get_filename_wo_extension($row['file']); 187 214 $thumbnail_url.= '/thumbnail/'; 188 215 $thumbnail_url.= $conf['prefix_thumbnail'].$file_wo_ext.'.'.$row['tn_ext']; … … 193 220 194 221 // retrieving all the linked categories 195 $query = 'SELECT DISTINCT(category_id) as category_id,status,visible'; 196 $query.= ',representative_picture_id'; 197 $query.= ' FROM '.IMAGE_CATEGORY_TABLE.','.CATEGORIES_TABLE; 198 $query.= ' WHERE image_id = '.$_GET['image_id']; 199 $query.= ' AND category_id = id;'; 200 $result = mysql_query( $query ); 222 $query = ' 223 SELECT DISTINCT(category_id) AS category_id,status,visible 224 ,representative_picture_id 225 FROM '.IMAGE_CATEGORY_TABLE.','.CATEGORIES_TABLE.' 226 WHERE image_id = '.$_GET['image_id'].' 227 AND category_id = id 228 ;'; 229 $result = mysql_query($query); 201 230 $categories = ''; 202 while ( $cat_row = mysql_fetch_array( $result ))203 { 204 $cat_infos = get_cat_info( $cat_row['category_id']);205 $cat_name = get_cat_display_name( $cat_infos['name'], ' > ', '');231 while ($cat_row = mysql_fetch_array($result)) 232 { 233 $cat_infos = get_cat_info($cat_row['category_id']); 234 $cat_name = get_cat_display_name($cat_infos['name'], ' > ', ''); 206 235 $categories.='<option value="'.$cat_row['category_id'].'">'.$cat_name.'</option>'; 207 236 } 208 237 209 238 //----------------------------------------------------- template initialization 210 $template->set_filenames( array('picture_modify'=>'admin/picture_modify.tpl'));239 $template->set_filenames(array('picture_modify'=>'admin/picture_modify.tpl')); 211 240 $template->assign_vars(array( 212 241 'TITLE_IMG'=>$title, … … 214 243 'FILE_IMG'=>$row['file'], 215 244 'TN_URL_IMG'=>$thumbnail_url, 216 'URL_IMG'=>add_session_id( $url_img ), 245 'URL_IMG'=>add_session_id($url_img), 246 'DEFAULT_NAME_IMG'=>str_replace('_',' ',get_filename_wo_extension($row['file'])), 247 'FILE_IMG'=>$row['file'], 217 248 'NAME_IMG'=>isset($_POST['name'])?$_POST['name']:$row['name'], 218 'DEFAULT_NAME_IMG'=>str_replace( '_',' ',get_filename_wo_extension($row['file']) ),219 'FILE_IMG'=>$row['file'],220 249 'SIZE_IMG'=>$row['width'].' * '.$row['height'], 221 250 'FILESIZE_IMG'=>$row['filesize'].' KB', … … 243 272 244 273 'F_ACTION'=>add_session_id(PHPWG_ROOT_PATH.'admin.php?'.$_SERVER['QUERY_STRING']) 245 274 )); 246 275 247 276 //-------------------------------------------------------------- errors display 248 if ( sizeof( $errors ) != 0)277 if (sizeof($errors) != 0) 249 278 { 250 279 $template->assign_block_vars('errors',array()); 251 for ( $i = 0; $i < sizeof( $errors ); $i++)280 for ($i = 0; $i < sizeof($errors); $i++) 252 281 { 253 282 $template->assign_block_vars('errors.error',array('ERROR'=>$errors[$i])); … … 257 286 // if there are linked category other than the storage category, we show 258 287 // propose the dissociate text 259 if ( mysql_num_rows( $result ) > 0)260 { 261 //$vtp->addSession( $sub, 'dissociate');262 //$vtp->closeSession( $sub, 'dissociate');288 if (mysql_num_rows($result) > 0) 289 { 290 //$vtp->addSession($sub, 'dissociate'); 291 //$vtp->closeSession($sub, 'dissociate'); 263 292 } 264 293 // associate to another category ? … … 268 297 $query = 'SELECT COUNT(id) AS nb_total_categories'; 269 298 $query.= ' FROM '.CATEGORIES_TABLE.';'; 270 $row = mysql_fetch_array( mysql_query( $query ));271 if ( $row['nb_total_categories'] < $conf['max_LOV_categories'])299 $row = mysql_fetch_array(mysql_query($query)); 300 if ($row['nb_total_categories'] < $conf['max_LOV_categories']) 272 301 { 273 302 $template->assign_block_vars('associate_LOV',array()); 274 303 $template->assign_block_vars('associate_LOV.associate_cat',array( 275 304 )); 276 /*$vtp->addSession( $sub, 'associate_LOV');277 $vtp->addSession( $sub, 'associate_cat');278 $vtp->setVar( $sub, 'associate_cat.value', '-1');279 $vtp->setVar( $sub, 'associate_cat.content', '');280 $vtp->closeSession( $sub, 'associate_cat');281 $page['plain_structure'] = get_plain_structure( true);282 $structure = create_structure( '', array());283 display_categories( $structure, ' ');284 $vtp->closeSession( $sub, 'associate_LOV');*/305 /*$vtp->addSession($sub, 'associate_LOV'); 306 $vtp->addSession($sub, 'associate_cat'); 307 $vtp->setVar($sub, 'associate_cat.value', '-1'); 308 $vtp->setVar($sub, 'associate_cat.content', ''); 309 $vtp->closeSession($sub, 'associate_cat'); 310 $page['plain_structure'] = get_plain_structure(true); 311 $structure = create_structure('', array()); 312 display_categories($structure, ' '); 313 $vtp->closeSession($sub, 'associate_LOV');*/ 285 314 } 286 315
Note: See TracChangeset
for help on using the changeset viewer.