<?
session_start();
include('_db.connection.php');
include('check.access.php');
include('_public.setup.php');

if(!$img_x){
	$img_x = 5;
}
?>
<style>
	<!--
	.menuskin{
	position:absolute;
	width:165px;
	background-color:menu;
	border:2px solid black;
	font:normal 12px Verdana;
	line-height:18px;
	z-index:100;
	visibility:hidden;
	}

	.menuskin a{
	text-decoration:none;
	color:black;
	padding-left:10px;
	padding-right:10px;
	}

	#mouseoverstyle{
	background-color:highlight;
	}

	#mouseoverstyle a{
	color:white;
	}
	-->
</style>
<script language="javascript">
<!--
image1 = new Image()
image1.src = "./images/UploadingBar.gif";
//-->
</script>
<div style="position:absolute; top:350px; left:300px; display:none; filter:alpha(Opacity=85);" id="uploading">
	<table bgcolor="#eeeeee" style="border: 1px solid #000000" width="200" height="80">
		<tr>
			<td align="center"><font face="arial" style="font-size: 12;"><b>Uploading Images...</b><br><img src="./images/UploadingBar.gif"></td>
		</tr>
		<tr>
			<td align="center"><font face="arial" style="font-size: 10;">You will be redirected to another page when the images are finished uploading.</td>
		</tr>
	</table>
</div>
	<table cellpadding="0" cellspacing="0" width="780" border="0">
		<?php include("i.header.php"); ?>
		<tr>
			<td>
				<table cellpadding="0" cellspacing="0" border="0">
					<tr>
						<td valign="top">
							<!--
							**************************
							**** BEGIN BODY TABLE ****
							**************************
							-->
							<table cellpadding="0" cellspacing="0">
								<tr>
									<td><img src="./images/HeaderUploadImages.gif"></td>
								</tr>
								<tr>
									<td align="center">
										<!--
										**************************
										*** BEGIN BODY CONTENT ***
										**************************
										-->
										<script language="javascript">
										function upload() {
											if (document.imgupload.fid.value == "") {
												alert("Please Choose A Folder Before You Upload Your Images");
											}
											else{
												var agree=confirm("Uploading images may take a while depending on your connection speed!");
												if (agree) {
													document.getElementById('uploading').style.display='block';
													//child = window.open('uploading.ani.php', 'Uploading', ['HEIGHT=100', 'WIDTH=250', 'dependent']);
													document.imgupload.action = "upload.complete.php";
													document.imgupload.submit();
												}
												else {
													false
												}
											}
										}			
										</script>
										<?
											$member_result = mysql_query("SELECT * FROM members WHERE member_id = '$mid'", $db);						
											$member = mysql_fetch_object($member_result);
											
											$used_space = "0";
											$image_result = mysql_query("SELECT image_id,file_size FROM images WHERE mid = '$mid'", $db);
											$image_count = mysql_num_rows($image_result);
											while($img = mysql_fetch_object($image_result)){
												$used_space = $used_space + ($img->file_size/1000);	
											}
													if($member->custom_plan == 1){
														$space_available = $member->custom_space;
													}
													else {
														$plan_result = mysql_query("SELECT * FROM plans WHERE plan_id = '$member->plan'");
														$plan = mysql_fetch_object($plan_result);
															$space_available = $plan->space;
													}
													
													if($used_space >= $space_available){
										?>	
											<table width="530" border="0">
											<tr>
												<td align="center"><b><font face="Verdana" style="font-size: 11;"><br><br><br>You have exceeded your Disk Space limit. Please <a href="contact.php">contact us</a> to get more space.</td>
											</tr>										
										<?
										
													}
													else {
										?>
										<table width="530" border="0">
											<tr>
												<td>&nbsp;</td>
											</tr>
											<?
											$folder_result = mysql_query("SELECT * FROM folders WHERE mid = '$mid'", $db);
											$folder_count = mysql_num_rows($folder_result);
												if($folder_count > 0){
											?>
											<form ENCTYPE="multipart/form-data" name="imgupload" method="post">
											<tr>
												<td>
													<table cellpadding="0" cellspacing="0" width="100%" style="border: 1px solid #083C58">
														<tr>
															<td bgcolor="#083C58" style="padding: 10px" width="40%"><font face="Verdana" style="font-size: 11;" color="#ffffff"><i><b>Upload up to 
															<select name="mass_upload" id="mass_upload" style="font-size: 9; width:40;" onChange="location=document.imgupload.mass_upload.options[document.imgupload.mass_upload.selectedIndex].value;" value="GO">
																<option value="upload.images.php?img_x=1&cap=<? if($cap == 1){ echo "1"; } ?>" <? if($img_x == 1){ echo "selected"; } ?>>1</option>
																<option value="upload.images.php?img_x=3&cap=<? if($cap == 1){ echo "1"; } ?>" <? if($img_x == 3){ echo "selected"; } ?>>3</option>
																<option value="upload.images.php?img_x=5&cap=<? if($cap == 1){ echo "1"; } ?>" <? if($img_x == 5){ echo "selected"; } ?>>5</option>
																<option value="upload.images.php?img_x=7&cap=<? if($cap == 1){ echo "1"; } ?>" <? if($img_x == 7){ echo "selected"; } ?>>7</option>
																<option value="upload.images.php?img_x=10&cap=<? if($cap == 1){ echo "1"; } ?>" <? if($img_x == 10){ echo "selected"; } ?>>10</option>
																<option value="upload.images.php?img_x=13&cap=<? if($cap == 1){ echo "1"; } ?>" <? if($img_x == 13){ echo "selected"; } ?>>13</option>
																<option value="upload.images.php?img_x=15&cap=<? if($cap == 1){ echo "1"; } ?>" <? if($img_x == 15){ echo "selected"; } ?>>15</option>
															</select>															
															 files at a time. To enter Captions with your images <a href="upload.images.php?img_x=<? echo $img_x; ?>&cap=1"><font color="#ffffff">click here</a>.</td>
															<td bgcolor="#F8F8F8" style="padding: 10px" width="60%">
																<table cellpadding="0" cellspacing="0">
																	<tr>
																		<td colspan="2"><font face="Verdana" style="font-size: 11;" color="#083C58"><b>Select a folder to upload your images to:</td>
																	</tr>
																	<tr><td colspan="2" height="3"></td></tr>
																	<tr>
																		<td>
																		<select name="fid">
																			<option></option>
																		<?
																		while($folder = mysql_fetch_object($folder_result)){
																		?>
																			<option value="<?php echo $folder->folder_id; ?>"><?php echo $folder->name; ?></option>
																		<? } ?>
																		</select>
																		</td>
																		<td align="center"><a href="image.manager.php">Make a new folder</a></td>
																	</tr>
																</table>
															</td>
														</tr>
													</table>
												</tr>
											</tr>
											<tr><td height="3"></td></tr>
											<?
												for($i = 1; $i <= $img_x; $i++){
											?>
											<tr>
												<td style="border: 1px solid #083C58; padding: 10px" bgcolor="#F8F8F8">
													<table>
														<tr>
															<td><font face="Verdana" style="font-size: 11;" color="#083C58"><b>Image <? echo $i; ?></td>
															<td><input type="file" name="image[]" style="width: 400"></td>
														</tr>
														<? if($cap == 1){ ?>
														<tr>
															<td><font face="Verdana" style="font-size: 11;" color="#083C58"><b>Caption</td>
															<td><input type="text" name="caption[]" style="width: 400"></td>
														</tr>
														<? } ?>
													</table>
												</td>
											</tr>
											<tr>
												<td height="2"></td>
											</tr>
											<?
												}
											?>
											<tr>
												<td height="4"></td>
											</tr>
											<tr>
												<td><input type="checkbox" value="1" name="resize"><font face="Verdana" style="font-size: 11;" color="#083C58"><b> &nbsp;<font color="#ff0000">Resize Images</font></b> (Recommended: They will load quicker and use less bandwidth)</td>
											</tr>
											<tr>
												<td><hr color="#eeeeee" size="1"></td>
											</tr>
											<tr>
												<td><font face="verdana" size="2"><b>Select Image Quality</td>
											</tr>
											<tr>
												<td><input type="radio" name="quality" value="80"><font face="Verdana" style="font-size: 11;" color="#083C58"><b>High<br></b>(Uses more bandwidth, takes longer to load, excellent image quality)</td>
											</tr>
											<tr>
												<td><input type="radio" name="quality" value="65" checked><font face="Verdana" style="font-size: 11;" color="#083C58"><b>Medium</b><br>(Recommended. Uses less bandwidth, loads faster than High Quality, good image quality)</td>
											</tr>
											<tr>
												<td><input type="radio" name="quality" value="40"><font face="Verdana" style="font-size: 11;" color="#083C58"><b>Low</b><br>(Uses the least bandwidth, loads fastest, fair image quality)</td>
											</tr>
											<tr>
												<td align="right"><input onclick="upload();" type="button" value="Start Uploading"></td>
											</tr>
											</form>
											<?
												}
												else{
											?>
											<tr>
												<td>&nbsp;</td>
											</tr>
											<tr>
												<td align="center"><font face="Verdana" size="2" color="#8C8E91"><b>Before you upload images you must make a folder to store them in.</b><br></td>
											</tr>
											<tr>
												<td>&nbsp;</td>
											</tr>
											<tr>
												<td>
													<table cellpadding="0" cellspacing="0" width="100%" style="border: 1px solid #083C58">
														<form action="actions.php?pmode=make_folder" method="post">
														<input type="hidden" name="return" value="upload.images.php">
														<tr>
															<td bgcolor="#083C58" style="padding: 10px" width="50%"><font face="Verdana" style="font-size: 11;" color="#ffffff"><i><b>Create folders to keep your images organized.</td>
															<td bgcolor="#F8F8F8" style="padding: 10px" width="50%">
																<table cellpadding="0" cellspacing="0">
																	<tr>
																		<td colspan="3"><font face="Verdana" style="font-size: 11;" color="#083C58"><b>New Folder Name</td>
																	</tr>
																	<tr>
																		<td><input type="text" name="folder_name" maxlength="64" style="font-size: 10; width: 140;"></td>
																		<td>&nbsp;</td>
																		<td><input type="image" src="./images/ButtonCreate.gif"></td>
																	</tr>
																</table>
															</td>
														</tr>
														</form>
													</table>
												</td>
											</tr>
											<?
												}
											}
											?>
											<tr>
												<td>&nbsp;</td>
											</tr>
										</table>
										<!--
										**************************
										**** END BODY CONTENT ****
										**************************
										-->
									</td>
								</tr>
							</table>
							<!--
							**************************
							***** END BODY TABLE *****
							**************************
							-->
						</td>
						<td valign="top"bgcolor="#295670"><img src="./images/IndexDropShadow.gif"></td>
						<td valign="top" bgcolor="#083C58">
							<?php include("i.member.rn.php"); ?>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td background="./images/Footer.gif"><img src="./images/Footer.gif" border="0"></td>
		</tr>
		<tr>
			<td>
				<?php include("i.footer.php"); ?>
			</td>
		</tr>
	</table>

<?
mysql_close($db);
print($close);
?>