
PK 
<?php
include "include/session.php";
include "include/configure.php";
if(isset($_POST['submit']) && $_POST['submit']=="Submit"){
if(isset($_POST['action']) && $_POST['action']=="add"){
$title = $_POST["title"];
if(!empty($title)) {
$imageName = $_FILES["featuredImg"]["name"];
if(!empty($imageName)) {
if(isset($_POST['preImageName']) && $_POST['preImageName']!="" )
@unlink("../images/".$_POST['preImageName']);
$strDtMix = @date("d").substr((string)microtime(), 2, 8);
$uploadfile = $strDtMix.".".pathinfo($imageName, PATHINFO_EXTENSION);
move_uploaded_file($_FILES['featuredImg']['tmp_name'], "../images/".$uploadfile);
}
mysql_query("INSERT INTO blog_articles (featuredImg,blogDate,title,description,createdDate) VALUES ('".$uploadfile."','".mysql_real_escape_string($_POST['blogDate'])."','".mysql_real_escape_string($_POST['title'])."','".mysql_real_escape_string($_POST['description'])."',now())");
}
header("location: blogArticle.php");
}else if(isset($_POST['action']) && $_POST['action']=="update"){
$title = $_POST["title"];
if(!empty($title)) {
$sqlCondition = "";
$imageName = $_FILES["featuredImg"]["name"];
if(!empty($imageName)) {
if(isset($_POST['preImageName']) && $_POST['preImageName']!="" )
@unlink("../images/".$_POST['preImageName']);
$strDtMix = @date("d").substr((string)microtime(), 2, 8);
$uploadfile = $strDtMix.".".pathinfo($imageName, PATHINFO_EXTENSION);
move_uploaded_file($_FILES['featuredImg']['tmp_name'], "../images/".$uploadfile);
$sqlCondition = ",featuredImg ='".$uploadfile."' ";
}
mysql_query("UPDATE blog_articles SET blogDate='". mysql_real_escape_string($_POST['blogDate'])."',title='". mysql_real_escape_string($_POST['title'])."',description='". mysql_real_escape_string($_POST['description'])."' ".$sqlCondition." where id='".$_POST['id']."'");
}
header("location: blogArticle.php?act=2");
}
}
if(isset($_GET['act']) && $_GET['act']=="delete"){
$sqlImg = mysql_query("select * from blog_articles where id='".$_GET['id']."'");
$rowImg = mysql_fetch_array($sqlImg);
@unlink("../images/".$rowImg['featuredImg']);
mysql_query("DELETE FROM blog_articles WHERE id='".$_GET['id']."'");
header("location: blogArticle.php?act=1");
}
$action = "add";
if(isset($_GET['action']) && $_GET['action']=="edit"){
$sqlEdit = mysql_query("SELECT * FROM blog_articles WHERE id='".$_GET['id']."'");
$rowsEdit = mysql_fetch_array($sqlEdit);
extract($rowsEdit);
$action = "update";
}
include "include/header.php";
?>
<div class="openHead">Manage News</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;?>blogArticle.php'" class="smtButton" /></td>
</tr>
<tr>
<td valign="top" width="10%">Title</td>
<td width="90%"><input type="text" style="width:700px;" name="title" id="title" value="<?=$title?>" /><br/ >
<span class="hintTxt">i.e Books, Music etc</span>
</td>
</tr>
<tr>
<td valign="top">Date</td>
<td ><input type="text" readonly="readonly" id="blogDate" name="blogDate" value="<?=$blogDate;?>" class="blogDate">
<script type="text/javascript">Zapatec.Calendar.setup({ inputField : "blogDate", ifFormat : "%Y-%m-%d", button : "blogDate" });</script></td>
</tr>
<tr>
<td valign="top">Description</td>
<td ><textarea class="page_desc" cols="60" rows="10" style="height:300px;width:702px;" id="description" name="description" ><?=$description?></textarea>
</td>
</tr>
<tr>
<td valign="top">Featured Image </td>
<td><?php if($featuredImg!=""){
echo "<img src='".$siteUrl."/include/timthumb.php?src=".$siteUrlMain."/images/".$featuredImg."&h=350&w=200&zc=1' />";
?>
<br/>
<input type="hidden" name="preImageName" value="<?=$featuredImg;?>" />
<?php }?>
<input type="file" name="featuredImg" />
</td>
</tr>
<tr>
<td align="right"> </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="2" cellspacing="0" width="100%">
<?php
if(isset($_GET['act']) && $_GET['act']=="1"){
echo "<tr>
<td colspan='5' align='center'><span class='success'>Delete article sucessfully</span></td>
</tr>";
}else if(isset($_GET['act']) && $_GET['act']=="2"){
echo '<tr>
<td colspan="5" align="center"><span class="success">Update article successfully.</span></td>
</tr>';
}
?>
<tr class="addTdRow">
<td align="right" colspan="5" >
<input type="button" class="smtButton" onclick="window.location.href='<?=$siteUrl;?>blogArticle.php?action=add'" value="Add New">
</td>
</tr>
<tr>
<th align="left" width="10%"> SNo</th>
<th align="left" width="60%">Title</th>
<th align="left" width="20%"> Created</th>
<th align="center" width="10%">Action</th>
</tr>
<?php
$page_name="blogArticle.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 blog_articles ORDER BY id DESC limit $eu, $limit";
$sqltot = "SELECT * FROM blog_articles 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> '.$sno.'</td>
<td>'.$rows['title'].'</td>
<td> '.$rows['createdDate'].'</td>
<td align="center">
<a title="Edit this record" href="blogArticle.php?action=edit&id='.$rows['id'].'"><img src="img/edit.gif" /></a>
<a title="Delete this record" onclick="return confirm(\'Are you sure you want to delete?\');" href="blogArticle.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