File: /home/nyiet8349bzl/Backup/sbc_back/homedir/public_html/old-myadmin/ImageGallery/imageCategory.php
<?php
require_once '../../library/config.php';
require_once '../library/functions.php';
function catAdd()
{
$txtCat = $_POST['txtCat'];
$sql = "INSERT INTO image_category(category_name) VALUES ('$txtCat')";
$result = dbQuery($sql);
$msg ="Category Added";
return $msg;
}
function catModify()
{
$id = $_GET['Id'];
$txtCat = $_POST['txtCat'];
$sql = "UPDATE image_category SET category_name = '$txtCat' WHERE category_id=$id";
$result = dbQuery($sql);
$msg ="Category Modified";
return $msg;
}
function catDelete()
{
$id = $_GET['Id'];
$sql = "DELETE FROM image_category WHERE category_id=$id";
$result = dbQuery($sql);
$msg ="Category Deleted";
return $msg;
}
if(isset($_POST['Add_New']) && $_POST['Add_New'] == 'Add New')
{ $msg = catAdd(); }
if(isset($_GET['CatDelete']) && $_GET['Id'] > 0 )
{ $msg = catDelete(); }
if(isset($_GET['CatEdit']) && $_GET['Id'] > 0 )
{
if(isset($_POST['Edit'])) { $msg = catModify(); }
$id = $_GET['Id'];
$sql1 = "SELECT * FROM image_category WHERE category_id=$id";
$result1 = dbQuery($sql1);
$row = dbFetchRow($result1);
$catName = $row[1];
}
?>
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1">
<tr align="center">
<td>
<div><?php echo @$msg; ?> </div>
<form name="form2" method="post" action="">
<label>Category Name
<input type="text" name="txtCat" value="<?php if(isset($catName)) echo $catName; ?>">
</label>
<input type="submit" name="<?php if(isset($catName)) echo 'Edit'; else echo 'Add New'; ?>" value="<?php if(isset($catName)) echo 'Edit'; else echo 'Add New'; ?>">
</form>
</td>
</tr>
<tr align="center" bgcolor="#669999">
<th >Category</th>
<th ></th>
</tr>
<?php
$sql = "SELECT * FROM image_category";
$result = dbQuery($sql);
$i=0;
while($row = dbFetchAssoc($result)) {
extract($row);
if ($i%2) {
$class = 'bgcolor="#DDDDDD" onMouseover="this.bgColor='."'#56A5EC'".'" onMouseout="'."this.bgColor="."'#DDDDDD'".'"';
} else {
$class = 'bgcolor="#CCCCCC" onMouseover="this.bgColor='."'#56A5EC'".'" onMouseout="'."this.bgColor="."'#CCCCCC'".'"';
}
$i += 1;
?>
<tr <?php echo $class; ?>>
<td align="center"> <a href="index.php?view=add&CatEdit&Id=<?php echo $category_id;?>" ><?php echo $category_name; ?></td>
<td align="center"><a href="#" onclick="confirmation(<?php echo $category_id;?>)" ><img src="../images/b_drop.png" /></a></td>
</tr>
<?php
}
?>
</table>
<script type="text/javascript">
<!--
function confirmation(id) {
var answer = confirm("Realy want to Delete ?")
if (answer){
window.location = 'index.php?view=add&CatDelete&Id='+ id ;
}
}
//-->
</script>