<?
	include("include/common.php");
	if(!$loggedin){
		ob_start();
		header("Location: login.php");
	}
	include("include/header.php");
	include("include/accmenu.php");
?>
	<h3>Create Gallery</h3>
	<table width="85%" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr>
		<td>
<?	if( $step == 2){	?>
<?
		$sql = "INSERT INTO gallery SET name='".$_POST['gname']."',user='".$myuid."'";
		$res = mysql_query($sql);
		$gid = mysql_insert_id();
		if (is_array( $_POST['img'] )){
			foreach( $_POST['img'] AS $aimg ){
				mysql_query( "INSERT INTO gitem SET gid='$gid',image='$aimg'" );
			}
		}
		echo "Your Gallery has been created";
?>
<?	}else{	?>
		<form method="POST">
		<input type='hidden' name='gname' value='<?=$_POST['gname']?>'>
		<input type='hidden' name='step' value='2'>
<?
		$sql = "SELECT * FROM images WHERE user='$myuid'";
		$qr1 = mysql_query($sql);
		$rowcount = mysql_num_rows($qr1);
		$i = 1;
		$domCount = 0;
		while( $a = mysql_fetch_object($qr1) ){
			$filen = $siteurl."/".str_replace('./', '', $att_path)."/".$a->filename;
			$filen = str_replace('http://','%%',$filen);
			$filen = str_replace('//','/',$filen);
			$filen = str_replace('%%','http://',$filen);
			if( file_exists($att_path."/".$a->filename)	){
				echo "<a href='$filen' target='_new'><img src='$filen' width=100 height=100 border=0></a><br>";
			}else{
				echo "no image found<br>";
			}
			echo "<input type='checkbox' name='img[]' value='".$a->id."'>Select This Image<br>";
		}
?>
		<br><br>
		<div align=right>
			<input type='submit' value='continue'>
		</div>
		</form>
<?	}	?>
		</td>
	</tr>
	</table>
<?	include("include/footer.php");	?>