<?php require "_header.php";?>
<?php
 	$schoolid = $_SESSION["VedantnrSchoolId"];
	$username= $_SESSION["VedantnrUserName"];
	$userpassword=$_SESSION["c_pass"];
    $user_id = $_SESSION["VedantnrUserId"];
	
	if(isset($_POST['submit'])){
		$file = basename($_FILES['image_file']['name']);
		if($file!="")
		{	
			$logofile = $_FILES['image_file']['name'];
			$tok = strtok($logofile,".");
			while($tok){
				$t=$tok;
				$tok = strtok(".");
			}
			$ext = $t;
						
			if($ext == 'jpeg' or $ext == 'JPEG' or $ext == 'jpg' or $ext == 'JPG')
			{
				$filename = "school-photo-".time().".".$ext;
				if(!is_dir("photo/school/".$schoolid."/school-photo")){
					mkdir("photo/school/".$schoolid."/school-photo",0777);
				}
				chmod("photo/school/".$schoolid."/school-photo/",0777);
				$dir = "photo/school/".$schoolid."/school-photo/".$filename;							
				copy($_FILES['image_file']['tmp_name'],$dir);					
				chmod($dir,0777);
				$file = "";
				$logofile = "";
				//start resizing 
                   if (preg_match("/(jpg|jpeg)/",$ext))	{											
				   		$objResizeImage = new ResizeImageMgmt();
						$objResizeImage->resize($dir,520,435,true,true);//name,w,h, blnfixheight
				 	}
				 //end resizing
				 ?>
                    	<script type="text/javascript" language="javascript">
							
						window.location.href='school-photo.php';
						</script>
                    <?php
			}
			else
			{															   
				echo "<script language='javascript'> alert('only (.jpg) formats are allowed');</script>"; 
			}
		}
	}
		
	if(isset($_REQUEST['act']) && $_REQUEST['act']=="del"){		
		if($_REQUEST['photo']!=''){
			if(file_exists($_REQUEST['photo'])){
				unlink($_REQUEST['photo']);
				
				
					?>
                    	<script type="text/javascript" language="javascript">
							
						window.location.href='school-photo.php';
						</script>
                    <?php
						
				}
		}
	}
?>
<br />
<form action="" method="post" name="form1" enctype="multipart/form-data">
<table border="0" align="center" width="60%">
	<tr>
    	<td colspan="5">New Image: 
			&nbsp; <input type="file" name="image_file" />
			&nbsp; <input type="submit" name="submit" value=" Upload " /> <br /><br />
		</td>
    </tr>
	<?php
        $i = 1;
        foreach (glob("photo/school/".$schoolid."/school-photo/*.jpg") as $filename) { 
            if($i==1){ ?><tr><? }
            $file = $filename;
            ?>
                <td width="20%">
                <table border="0" width="20%">
                <tr><td><a href="?photo=<?=$file?>&act=del">Delete</a></td></tr>
                <tr><td><img src='<?php echo $file; ?>' width="100" height="100" /></td></tr>
                </table>
                </td>
            <?
            $i++;
            if($i%5==1){
                $i==1;
                ?></tr><?
            }
       	}
    ?>
</table>
</form>
<?php require "_footer.php";?>