PK

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

<?php
	include "include/session.php";  
	include "include/configure.php";
	
	if(isset($_POST['submit']) && $_POST['submit']=="Submit"){
		
		
		if(isset($_POST['action']) && $_POST['action']=="add"){
		
			$categoryName = $_POST["categoryName"];
			if(!empty($categoryName)) {
				mysql_query("INSERT INTO department (categoryName,createdDate) VALUES ('".mysql_real_escape_string($_POST['categoryName'])."',now())");
			}
			header("location: department.php");
		
		}else if(isset($_POST['action']) && $_POST['action']=="update"){
		
			$categoryName = $_POST["categoryName"];
			if(!empty($categoryName)) {
				mysql_query("UPDATE department SET categoryName='". mysql_real_escape_string($_POST['categoryName'])."' where id='".$_POST['id']."'");					 
			}
			
			header("location: department.php?act=2");
		}
	}
	
	if(isset($_GET['act']) && $_GET['act']=="delete"){
	 	mysql_query("UPDATE department SET isDelete='1' where id='".$_GET['id']."'");	
		header("location: department.php?act=1");
	}
	
	$action = "add";
	if(isset($_GET['action']) && $_GET['action']=="edit"){
		$sqlEdit = mysql_query("SELECT * FROM  department WHERE id='".$_GET['id']."'");
		$rowsEdit = mysql_fetch_array($sqlEdit);
		extract($rowsEdit);
		$action = "update";
	} 
 	include "include/header.php"; 
?>
	<div class="openHead">Manage Departments</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;?>department.php'" class="smtButton" /></td>
                </tr>
                <tr>
                    <td width="15%" valign="top">Department Name</td>
                    <td width="85%"><input type="text" name="categoryName" value="<?=$categoryName?>" /><br/ >
                    	<span class="txtHint">i.e General surgery, Ear nose and throat (ENT) etc</span>
                    </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 departments sucessfully</span></td>
                        </tr>";
                    }else  if(isset($_GET['act']) && $_GET['act']=="2"){
                        echo '<tr>
                            <td colspan="5" align="center"><span class="success">Update departments successfully.</span></td>	
                        </tr>';	
                    }
                    ?>
                    <tr class="addTdRow">
                        <td align="right" colspan="4" >
                            <input type="button" class="smtButton" onclick="window.location.href='<?=$siteUrl;?>department.php?action=add'" value="Add New">
 					     </td>
                    </tr>
                    <tr>
                        <th align="left" width="10%">&nbsp; SNo</th>
                        <th align="left" width="60%">Departments</th>
                        <th align="left" width="20%">Created</th>
                        <th align="center" width="10%">Action</th>
                    </tr>
                    <?php
                    $page_name="department.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 department where isDelete='0' ORDER BY id DESC limit $eu, $limit";
                    $sqltot = "SELECT * FROM department where isDelete='0' ORDER BY id DESC ";
                    
                    $resultSeller= mysql_query($sqlSeller);
                    $resulttot=mysql_query($sqltot);
                    $nume=mysql_num_rows($resulttot);
                    if (@mysql_num_rows($resultSeller)!=0){
                    
                        $sno= (isset($_GET['start']) && $_GET['start']!="")?$_GET['start']:0;
                        while($rows=mysql_fetch_array($resultSeller)){
                            $sno++;
                            echo '<tr>
                                <td>&nbsp; '.$sno.'</td>
                                <td>'.$rows['categoryName'].'</td>
								<td>'.$rows['createdDate'].'</td>
                                <td align="center">
                                    <a href="department.php?action=edit&id='.$rows['id'].'"><img src="img/edit.gif" /></a>
                                    <a onclick="return confirm(\'Are you sure you want to delete?\');" href="department.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