<?

/*
FlexCMS (http://www.flexcms.com)
Flexible, Powerful, Affordable.

Contents of this file are protected by the copyright
notice found at http://www.flexcms.com/flex/pages/copyright.html,
and its usage is subject to the terms of the licensing agreement 
available at http://www.flexcms.com/flex/pages/license.html
*/



	// ========================================================================================
	// actually Delete Existing Photo
	// ========================================================================================
	
	$PageTitle = $MsgText[3][62];
	$BrowserTitle = $MsgText[3][62];
	$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="' . $MainURL . '/options.html">'.$MsgText[0][4].'</a> > <a href="'.$MainURL.'/admin/photos.html">'.$MsgText[3][2].'</a> > '.$MsgText[3][62];
	
	if ($LoggedIn == 'y') {
		
		ReadPermissions();
		Global $Permissions;
		
		ReadFormArguments();
		Global $FormArguments;
		
		
		$query55 = "select * from `".$Settings['DBPrefix']."pg-Images` where RecordNumber='".$FormArguments['RecordNumber']."' limit 1";
		$result55 = mysql_query($query55) or die (mysql_error());
		$row55 = mysql_fetch_array($result55);
		
		$query55 = "select MinLevel,MinEditLevel from `".$Settings['DBPrefix']."pg-Galleries` where RecordNumber='".$row55['GalleryNumber']."' limit 1";
		$result55 = mysql_query($query55) or die (mysql_error());
		$row55 = mysql_fetch_array($result55);
		
		
		if ($Permissions[301] == 'y' && $row55['MinLevel'] <= $UserLevel && $row55['MinEditLevel'] <= $UserLevel) {
	
			
			
			if (count($FormArguments) > 0) {
			
			
				$query = "select * from `".$Settings['DBPrefix']."pg-Settings`";
				$result = mysql_query($query) or die (mysql_error());
				while ($row = mysql_fetch_array($result)) {
					$pgSettings[$row['Name']] = $row['Value'];
				}
				
				if ($pgSettings['StorageLocationHTTP'] == '') {
					$pgSettings['StorageLocationHTTP'] = $BaseURL.'/pg_images';
				}	
				if ($pgSettings['StorageLocationLocal'] == '') {
					$pgSettings['StorageLocationLocal'] = './pg_images';
				}
			
			
			
				$query = "select * from `".$Settings['DBPrefix']."pg-Images` where RecordNumber='".$FormArguments['RecordNumber']."' limit 1";
				$result = mysql_query($query) or die (mysql_error());
				$row = mysql_fetch_array($result);
																											
				$query5 = "delete from `".$Settings['DBPrefix']."pg-Images` where RecordNumber='".$FormArguments['RecordNumber']."' limit 1";
				$result5 = mysql_query($query5) or die (mysql_error());
				
				$query55 = "update `".$Settings['DBPrefix']."pg-Galleries` set GalleryImages=(GalleryImages-1) where RecordNumber='".$row['GalleryNumber']."'";
				$result55 = mysql_query($query55) or die (mysql_error());
	
	
				$Extensions[1] = '.gif';
				$Extensions[2] = '.jpg';
				$Extensions[3] = '.png';
			
				$ThumbExtensions[1] = '-thumb.gif';
				$ThumbExtensions[2] = '-thumb.jpg';
				$ThumbExtensions[3] = '-thumb.png';
				
				unlink($pgSettings['StorageLocationLocal'].'/'.$row['FileName'].$Extensions[$row['FileType']]);
				unlink($pgSettings['StorageLocationLocal'].'/'.$row['FileName'].$ThumbExtensions[$row['FileType']]);
				
				
				
				header('Location: ' . $MainURL . '/admin/photos.html');
				
			}
			else {
				$PageContents = $MsgText[0][98];
			}
			
		}
		else {
		
			$PageContents = $MsgText[0][97];
		
		}

	}
	else {
	
		RedirectToLogin();
	
	}
	
	

	// ========================================================================================




?>
