PK

ADDRLIN : /home/anibklip/babekehospital.org/dAdmin/
FLL :
Current File : /home/anibklip/babekehospital.org/dAdmin/gallery.php

<?php
	include "include/session.php";  
	include "include/configure.php";
	
	if(isset($_POST['submit']) && $_POST['submit']=="Submit"){
		
		
		if(isset($_POST['action']) && $_POST['action']=="add"){
		
			$imageName = $_FILES["galleryImage"]["name"];
			if(!empty($imageName)) {
				if(isset($_POST['preImageName']) && $_POST['preImageName']!="" )
					@unlink("../images/".$_POST['preImageName']);
					
				$strDtMix = @date("d").substr((string)microtime(), 4, 4);
				$uploadfile = $strDtMix."_".$imageName;
				move_uploaded_file($_FILES['galleryImage']['tmp_name'], "../images/".$uploadfile);
				mysql_query("INSERT INTO gallery (galleryName,galleryImage) VALUES ('".mysql_real_escape_string($_POST['galleryName'])."','".$uploadfile."')");
			}
			header("location: gallery.php");
		
		}else if(isset($_POST['action']) && $_POST['action']=="update"){
		
			$sqlCondition = "";
			$imageName = $_FILES["galleryImage"]["name"];
			if(!empty($imageName)) {
				if(isset($_POST['preImageName']) && $_POST['preImageName']!="" )
					@unlink("../images/".$_POST['preImageName']);
					
				$strDtMix = @date("d").substr((string)microtime(), 4, 4);
				$uploadfile = $strDtMix."_".$imageName;
				move_uploaded_file($_FILES['galleryImage']['tmp_name'], "../images/".$uploadfile);
				$sqlCondition = ",galleryImage ='".$uploadfile."' ";
			}
			mysql_query("UPDATE gallery SET galleryName='". mysql_real_escape_string($_POST['galleryName'])."' ".$sqlCondition." where id='".$_POST['id']."'");	
			header("location: gallery.php?act=2");
		}
	}
	
	if(isset($_GET['act']) && $_GET['act']=="delete"){
	 	$sqlImg = mysql_query("select galleryImage from gallery where id='".$_GET['id']."'");
		$rowImg = mysql_fetch_array($sqlImg);
		@unlink("../images/".$rowImg['galleryImage']);
		mysql_query("DELETE FROM gallery WHERE id='".$_GET['id']."'");	
		header("location: gallery.php?act=1");
	}
	
	$action = "add";
	if(isset($_GET['action']) && $_GET['action']=="edit"){
		$sqlEdit = mysql_query("SELECT * FROM gallery WHERE id='".$_GET['id']."'");
		$rowsEdit = mysql_fetch_array($sqlEdit);
		extract($rowsEdit);
		$action = "update";
	} 
 	include "include/header.php"; 
?>
	<div class="openHead">Manage Gallery</div>
    <div class="middleMainContainer"> 
		<?php if(isset($_GET['action']) && $_GET['action']=="add" || $_GET['action']=="edit"){ ?>
        
        	<form method="post" action="" enctype="multipart/form-data"> 
             <table border="1" width="100%" cellpadding="5" cellspacing="0" align="center" class="formTb">
                <tr>
                    <td colspan="2" align="right"><input type="button" value="Back to List" onclick="window.location.href='<?=$siteUrl;?>gallery.php'" class="smtButton" /></td>
                </tr>
                <tr>
                    <td width="10%">Name</td>
                    <td width="90%"><input type="text" name="galleryName" value="<?=$galleryName?>" /></td>
                </tr>
                <tr>
                    <td valign="top">Image </td>
                    <td><?php if($galleryImage!=""){ 
                            echo "<img src='".$siteUrl."/include/timthumb.php?src=".$siteUrlMain."/images/".$galleryImage."&h=200&w=200&zc=1' />";
                        ?>
                        <br/>
                        <input type="hidden" name="preImageName" value="<?=$galleryImage;?>" />
                        <?php }?>
                        <input type="file" name="galleryImage" />
                    </td>
                </tr>
                <tr>
                    <td align="right">&nbsp;</td>
                    <td><input type="hidden" name="action" value="<?=$action;?>" />
                    <input type="hidden" name="id" value="<?=$id;?>" />
                    <input type="submit" name="submit" class="smtButton" value="Submit" /></td>
                </tr>
                
             </table>
             </form>
        <?php }else{?>
    			<table class="listTb" border="1" cellpadding="0" cellspacing="0" width="100%">
        	 		<?php
                    if(isset($_GET['act']) && $_GET['act']=="1"){
                        echo "<tr>
                            <td colspan='5' align='center'><span class='success'>Delete gallery sucessfully</span></td>
                        </tr>";
                    }else  if(isset($_GET['act']) && $_GET['act']=="2"){
                        echo '<tr>
                            <td colspan="5" align="center"><span class="success">Update gallery successfully.</span></td>	
                        </tr>';	
                    }
                    ?>
                    <tr class="addTdRow">
                        <td align="right" colspan="4" >
                            <input type="button" class="smtButton" onclick="window.location.href='<?=$siteUrl;?>gallery.php?action=add'" value="Add New">
                        </td>
                    </tr>
                    <tr>
                        <th align="left" width="10%">&nbsp; SNo</th>
                        <th align="left" width="20%">Name</th>
                        <th align="center" width="50%">Images</th>
                        <th align="center" width="10%">Action</th>
                    </tr>
                    <?php
                    $page_name="gallery.php"; 
                    if(!isset($_REQUEST["start"])) {
                        $start = 0;
                    }
                    else
                    $start = $_REQUEST["start"];
                    
                    $eu = ($start - 0); 
                    $limit = 20;          
                    $this1 = $eu + $limit; 
                    $back = $eu - $limit; 
                    $next = $eu + $limit; 
                    $sql = mysql_query("limit $eu, $limit");
                    
                    $sqlSeller = "SELECT * FROM gallery ORDER BY id DESC limit $eu, $limit";
                    $sqltot = "SELECT * FROM gallery ORDER BY id DESC ";
                    
                    $resultSeller= mysql_query($sqlSeller);
                    $resulttot=mysql_query($sqltot);
                    $nume=mysql_num_rows($resulttot);
                    if (@mysql_num_rows($resultSeller)!=0){
                    
                        $sno=0;
                        while($rows=mysql_fetch_array($resultSeller)){
                            $sno++;
                            echo '<tr>
                                <td>&nbsp; '.$sno.'</td>
                                <td>'.$rows['galleryName'].'</td>
                                <td align="center"><img src="'.$siteUrlMain.'/php/timthumb.php?src='.$siteUrlMain.'images/'.$rows['galleryImage'].'&h=200&w=200&zc=1" /></td>
                                <td align="center">
                                    <a href="gallery.php?action=edit&id='.$rows['id'].'"><img src="img/edit.gif" /></a>
                                    <a onclick="return confirm(\'Are you sure you want to delete?\');" href="gallery.php?act=delete&id='.$rows['id'].'"><img src="img/delete.gif" /></a>
                                </td>
                            </tr>';
                        }
                    ?>
                    <tr>
                        <td colspan="5">
                        <?php
                            echo "<table align = 'center' width='100%'><tr><td  align='left' width='30%'>";
                            //// if our variable $back is equal to 0 or more then only we will display the link to move back ////////
                            if($back >=0) { 
                            print "<a href='$page_name?start=$back'><font face='Verdana' size='2'>PREV</font></a>"; 
                            } 
                            //////////////// Let us display the page links at  center. We will not display the current page as a link ///////////
                            echo "</td><td align=center width='30%'>Page:";
                            $i=0;
                            $l=1;
                            $total=0;
                            for($i=0;$i < $nume;$i=$i+$limit){
                            if($i <> $eu){
                            echo " <a href='$page_name?start=$i'><font face='Verdana' size='2'>$l</font></a> ";
                            }
                            else { echo "<font face='Verdana' size='2' color=red>$l</font>";}        /// Current page is not displayed as link and given font color red
                            $l=$l+1;
                            $total = $total+1;
                            }
                            echo " of $total</td><td  align='right' width='30%'>";
                            
                            ///////////// If we are not in the last page then Next link will be displayed. Here we check that /////
                            if($this1 < $nume) { 
                            print "<a href='$page_name?start=$next'><font face='Verdana' size='2'>NEXT</font></a>";} 
                            echo "</td></tr></table>";
                            ?>
                        </td>
                    </tr><?php
                    }else{
                        echo "<tr>
                            <td colspan='5' align='center'>No Data Found.</td>
                        </tr>";
                    } ?>
                </table>    
	        
        <?php }?>
        
    </div>
<?php include "include/footer.php"; ?>


PK 99