<?php
///////////////////////////////////////////////////////////////////////////////
//                                                                           //
//   Program Name         : ProPhotoHost                                     //
//   Release Version      : 1.0                                              //
//   Home Page            : http://www.prophotohost.com                      //
//   Program Author       : Jake P                                           //
//   Supplied by          : drew010                                          //
//   Nullified by         : CyKuH [WTN]                                      //
//   Distribution         : via WebForum, ForumRU and associated file dumps  //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////
session_start();
include('i.setup.php');
include('i.connection.php');
include('i.function.php');

if($mode == "upload") {
	$num_files = count($file);
	for($i = 0; $i < $num_files; $i++) {
		if($file_size[$i] != 0) {
			if($file_type[$i] != "image/pjpeg" and $file_type[$i] != "image/gif" and $file_type[$i] != "image/x-png") {
				if($page == "more") {
					header("location: ./add.image.php?mode=more&error=filetype");
					exit;
				}
				else {
					header("location: ./add.image.php?error=filetype");
					exit;
				}
				exit;
			}
		}
	}
	for($i = 0; $i < $num_files; $i++) {
		if($file_size[$i] != 0) {
			
			$size = $file_size[$i];
			$base = random(32, "");
			$original = $file_name[$i];
			
			switch($file_type[$i]) {
				case "image/pjpeg":
					$ext = "jpg";
					break;
				case "image/gif":
					$ext = "gif";
					break;
				case "image/x-png":
					$ext = "png";
					break;
			}
			
			$name = $base . "." . $ext;
			
			$image_size = getimagesize($file[$i]);
			$width = $image_size[0];
			$height = $image_size[1];
			
			copy($file[$i], "./hosted/" . $name);
			
			if($width > $height) {
				$new_width = 50/$image_size[0];
				$new_height = $image_size[1] * $new_width;
				$new_width = 50;
			}
			else {
				$new_height = 50/$image_size[1];
				$new_width = $image_size[0] * $new_height;
				$new_height = 50;
			}
			
			//print($file_type[$i]);
			//exit;
			
			switch($file_type[$i]) {
				case "image/pjpeg":
					
					$dst_img = ImageCreate($new_width, $new_height);
					$src_img = ImageCreateFromJPEG("./hosted/" . $name);
					
					imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
					
					imagejpeg($dst_img, "./hosted/thumb_" . $name, 100);
					
					break;
				case "image/x-png":
					
					$dst_img = ImageCreate($new_width, $new_height);
					$src_img = ImageCreateFromPNG("./hosted/" . $name);
					
					imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
					
					imagepng($dst_img, "./hosted/thumb_" . $name, 100);
					
					break;
			}
			
			$date = now();
			
			$sql = "INSERT INTO image (image_name,image_original,image_ext,image_size,image_width,image_height,image_caption,image_member_id,image_status,created_on,updated_on) VALUES ('$base','$original','$ext','$size','$width','$height','$caption[$i]','$session_member_id','A','$date','$date')";
			$result = mysql_query($sql);
		}
	}
	
	header("location: ./home.php");
}
?>

<html>

<head>
<title><?php print($page_title); ?></title>

<?php include('i.style.php'); ?>

<script language="javascript">
	
	function upload() {
		alert("Depending on the size of your image(s) this may take a minute.");
		document.add.action = "<?php print($PHP_SELF); ?>?mode=upload";
		document.add.submit();
	}
	
	function more() {
		document.add.action = "<?php print($PHP_SELF); ?>?mode=more";
		document.add.submit();
	}
	
	function less() {
		document.add.action = "<?php print($PHP_SELF); ?>";
		document.add.submit();
	}
	
</script>

</head>

<body <?php if($session_access == false) { ?>onload="document.login.email.focus();"<?php } ?> marginwidth="0" marginheight="0" leftmargin="0" topmargin="0" rightmargin="0">
	
	<table width="100%" cellpadding="0" cellspacing="0">
		
		<?php include('i.header.php'); ?>
		
		<tr>
			
			<td valign="top">
				
				<table cellpadding="0" cellspacing="0">
					
					<tr>
						
						<td><font face="verdana" size="1">&nbsp;&nbsp;&nbsp;</font></td>
						
					</tr>
					
				<tr>
					
					<td><font face="verdana" size="1">&nbsp;&nbsp;&nbsp;</font></td>
					
					<td valign="top">
						
						<table cellpadding="0" cellspacing="0">
							
							<?php include('i.tab.php'); ?>
							
						</table>
						
					</td>
					
					<td><font face="verdana" size="1">&nbsp;&nbsp;</font></td>
					
					<td valign="top" width="100%" height="100%">
						
						<table width="100%" height="100%" cellpadding="0" cellspacing="0">
							
							<tr>
								
								<td><font face="verdana" size="1">&nbsp;</font></td>
								
								<td width="100%" height="100%">
									
									<table width="100%" height="100%" cellpadding="0" cellspacing="0">
										
										<tr>
											
											<td><img src="./images/heading.add.image.gif"></td>
											
										</tr>
										
										<tr>
											
											<td height="8" background="images/hr.gif"></td>
											
										</tr>
										
										<tr>
											
											<td><font face="verdana" size="1">&nbsp;</font></td>
											
										</tr>
										
										<form name="add" enctype="multipart/form-data" method="post">
										<input type="hidden" name="page" value="<?php print($mode); ?>">
										
										<tr>
											
											<td>
												
												<table>
													
													<?php if($error == "filetype") { ?>
														
														<tr>
															
															<td colspan="2" align="center"><font face="verdana" size="1" color="#FF0000">Invalid filetype, please only upload <b>.jpg</b>, <b>.gif</b> or <b>.png</b> files.</font></td>
															
														</tr>
														
													<?php } else { ?>
														
														<tr>
															
															<td colspan="2" align="center"><font face="verdana" size="1">Please only upload <b>.jpg</b>, <b>.gif</b> or <b>.png</b> files.</font></td>
															
														</tr>
														
													<?php } ?>
													
													<?php
													switch($mode) {
														default:
														?>
														
														<tr>
															
															<td colspan="2">
																
																<table cellpadding="0" cellspacing="0">
																	
																	<tr>
																		
																		<td><img src="./images/image.a.gif"></td>
																		
																		<td background="./images/image.b.gif">
																			
																			<table>
																				
																				<tr>
																					
																					<td>&nbsp;</td>
																					<td><img src="./images/image.1.gif"></td>
																					<td>&nbsp;</td>
																					
																				</tr>
																				
																			</table>
																			
																		</td>
																		
																		<td background="./images/image.b.gif">
																			
																			<table>
																				
																				<tr>
																					
																					<td align="right"><font face="verdana" size="1">Caption: </font></td>
																					<td><input type="text" name="caption[]" class="form" style="width: 300px;" maxlength="128"></td>
																					
																				</tr>
																				
																				<tr>
																					
																					<td align="right"><font face="verdana" size="1">Image: </font></td>
																					<td><input type="file" name="file[]" class="form" style="width: 300px;"></td>
																					
																				</tr>
																				
																			</table>
																			
																		</td>
																		
																		<td background="./images/image.b.gif">
																			
																			<table>
																				
																				<tr>
																					
																					<td>&nbsp;</td>
																					
																				</tr>
																				
																			</table>
																			
																		</td>
																		
																		<td><img src="./images/image.c.gif"></td>
																		
																	</tr>
																	
																</table>
																
															</td>
															
														</tr>
														
														<tr>
															
															<td><input type="image" src="./images/bu.more.gif" name="more_button" onclick="more();"></td>
															<td align="right"><input type="image" src="./images/bu.add.gif" name="add_button" onclick="upload();"></td>
															
														</tr>
														
													<?php
															break;
														case "more":
													?>
														
														<tr>
															
															<td colspan="2">
																
																<table cellpadding="0" cellspacing="0">
																	
																	<tr>
																		
																		<td><img src="./images/image.a.gif"></td>
																		
																		<td background="./images/image.b.gif">
																			
																			<table>
																				
																				<tr>
																					
																					<td>&nbsp;</td>
																					<td><img src="./images/image.1.gif"></td>
																					<td>&nbsp;</td>
																					
																				</tr>
																				
																			</table>
																			
																		</td>
																		
																		<td background="./images/image.b.gif">
																			
																			<table>
																				
																				<tr>
																					
																					<td align="right"><font face="verdana" size="1">Caption: </font></td>
																					<td><input type="text" name="caption[]" class="form" style="width: 300px;" maxlength="128"></td>
																					
																				</tr>
																				
																				<tr>
																					
																					<td align="right"><font face="verdana" size="1">Image: </font></td>
																					<td><input type="file" name="file[]" class="form" style="width: 300px;"></td>
																					
																				</tr>
																				
																			</table>
																			
																		</td>
																		
																		<td background="./images/image.b.gif">
																			
																			<table>
																				
																				<tr>
																					
																					<td>&nbsp;</td>
																					
																				</tr>
																				
																			</table>
																			
																		</td>
																		
																		<td><img src="./images/image.c.gif"></td>
																		
																	</tr>
																	
																</table>
																
															</td>
															
														</tr>
														
														<tr>
															
															<td colspan="2">
																
																<table cellpadding="0" cellspacing="0">
																	
																	<tr>
																		
																		<td><img src="./images/image.a.gif"></td>
																		
																		<td background="./images/image.b.gif">
																			
																			<table>
																				
																				<tr>
																					
																					<td>&nbsp;</td>
																					<td><img src="./images/image.2.gif"></td>
																					<td>&nbsp;</td>
																					
																				</tr>
																				
																			</table>
																			
																		</td>
																		
																		<td background="./images/image.b.gif">
																			
																			<table>
																				
																				<tr>
																					
																					<td align="right"><font face="verdana" size="1">Caption: </font></td>
																					<td><input type="text" name="caption[]" class="form" style="width: 300px;" maxlength="128"></td>
																					
																				</tr>
																				
																				<tr>
																					
																					<td align="right"><font face="verdana" size="1">Image: </font></td>
																					<td><input type="file" name="file[]" class="form" style="width: 300px;"></td>
																					
																				</tr>
																				
																			</table>
																			
																		</td>
																		
																		<td background="./images/image.b.gif">
																			
																			<table>
																				
																				<tr>
																					
																					<td>&nbsp;</td>
																					
																				</tr>
																				
																			</table>
																			
																		</td>
																		
																		<td><img src="./images/image.c.gif"></td>
																		
																	</tr>
																	
																</table>
																
															</td>
															
														</tr>
														
														<tr>
															
															<td colspan="2">
																
																<table cellpadding="0" cellspacing="0">
																	
																	<tr>
																		
																		<td><img src="./images/image.a.gif"></td>
																		
																		<td background="./images/image.b.gif">
																			
																			<table>
																				
																				<tr>
																					
																					<td>&nbsp;</td>
																					<td><img src="./images/image.3.gif"></td>
																					<td>&nbsp;</td>
																					
																				</tr>
																				
																			</table>
																			
																		</td>
																		
																		<td background="./images/image.b.gif">
																			
																			<table>
																				
																				<tr>
																					
																					<td align="right"><font face="verdana" size="1">Caption: </font></td>
																					<td><input type="text" name="caption[]" class="form" style="width: 300px;" maxlength="128"></td>
																					
																				</tr>
																				
																				<tr>
																					
																					<td align="right"><font face="verdana" size="1">Image: </font></td>
																					<td><input type="file" name="file[]" class="form" style="width: 300px;"></td>
																					
																				</tr>
																				
																			</table>
																			
																		</td>
																		
																		<td background="./images/image.b.gif">
																			
																			<table>
																				
																				<tr>
																					
																					<td>&nbsp;</td>
																					
																				</tr>
																				
																			</table>
																			
																		</td>
																		
																		<td><img src="./images/image.c.gif"></td>
																		
																	</tr>
																	
																</table>
																
															</td>
															
														</tr>
														
														<tr>
															
															<td colspan="2">
																
																<table cellpadding="0" cellspacing="0">
																	
																	<tr>
																		
																		<td><img src="./images/image.a.gif"></td>
																		
																		<td background="./images/image.b.gif">
																			
																			<table>
																				
																				<tr>
																					
																					<td>&nbsp;</td>
																					<td><img src="./images/image.4.gif"></td>
																					<td>&nbsp;</td>
																					
																				</tr>
																				
																			</table>
																			
																		</td>
																		
																		<td background="./images/image.b.gif">
																			
																			<table>
																				
																				<tr>
																					
																					<td align="right"><font face="verdana" size="1">Caption: </font></td>
																					<td><input type="text" name="caption[]" class="form" style="width: 300px;" maxlength="128"></td>
																					
																				</tr>
																				
																				<tr>
																					
																					<td align="right"><font face="verdana" size="1">Image: </font></td>
																					<td><input type="file" name="file[]" class="form" style="width: 300px;"></td>
																					
																				</tr>
																				
																			</table>
																			
																		</td>
																		
																		<td background="./images/image.b.gif">
																			
																			<table>
																				
																				<tr>
																					
																					<td>&nbsp;</td>
																					
																				</tr>
																				
																			</table>
																			
																		</td>
																		
																		<td><img src="./images/image.c.gif"></td>
																		
																	</tr>
																	
																</table>
																
															</td>
															
														</tr>
														
														<tr>
															
															<td colspan="2">
																
																<table cellpadding="0" cellspacing="0">
																	
																	<tr>
																		
																		<td><img src="./images/image.a.gif"></td>
																		
																		<td background="./images/image.b.gif">
																			
																			<table>
																				
																				<tr>
																					
																					<td>&nbsp;</td>
																					<td><img src="./images/image.5.gif"></td>
																					<td>&nbsp;</td>
																					
																				</tr>
																				
																			</table>
																			
																		</td>
																		
																		<td background="./images/image.b.gif">
																			
																			<table>
																				
																				<tr>
																					
																					<td align="right"><font face="verdana" size="1">Caption: </font></td>
																					<td><input type="text" name="caption[]" class="form" style="width: 300px;" maxlength="128"></td>
																					
																				</tr>
																				
																				<tr>
																					
																					<td align="right"><font face="verdana" size="1">Image: </font></td>
																					<td><input type="file" name="file[]" class="form" style="width: 300px;"></td>
																					
																				</tr>
																				
																			</table>
																			
																		</td>
																		
																		<td background="./images/image.b.gif">
																			
																			<table>
																				
																				<tr>
																					
																					<td>&nbsp;</td>
																					
																				</tr>
																				
																			</table>
																			
																		</td>
																		
																		<td><img src="./images/image.c.gif"></td>
																		
																	</tr>
																	
																</table>
																
															</td>
															
														</tr>
														
														<tr>
															
															<td><input type="image" src="./images/bu.less.gif" name="less_button" onclick="less();"></td>
															<td align="right"><input type="image" src="./images/bu.add.gif" name="add_button" onclick="upload();"></td>
															
														</tr>
														
													<?php
															break;
													}
													?>
													
												</table>
												
											</td>
											
										</tr>
										
										</form>
										
										<tr>
											
											<td height="100%">&nbsp;</td>
											
										</tr>
										
										<tr>
											
											<td height="8" background="images/hr.gif"></td>
											
										</tr>
										
									</table>
									
								</td>
								
								<td><font face="verdana" size="1">&nbsp;</font></td>
								
							</tr>
							
						</table>
						
					</td>
					
				</tr>
				
			</table>
			
		</td>
		
	</tr>
	
	<?php include('i.footer.php'); ?>
	
	</table>
	
</body>

</html>