system: Linux mars.sprixweb.com 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
<?php
class Model_MNews
{
function showNews()
{
$pagesize=10;
if(isset($_GET['size']))
{
$pagesize=$_GET['size'];
}
if(isset($_GET['page']))
{
$start = trim($_GET['page']-1) * $pagesize;
$end = $pagesize;
}
else
{
$start = 0;
$end = $pagesize;
}
$total=0;
$query_string = split('&size',$_SERVER['QUERY_STRING']);
$query = new Bin_Query();
$sql = "SELECT * FROM `news_table`";
if($query->executeQuery($sql))
$records = $query->records;
if(count($Err->messages) > 0 )
{
$records = $Err->values;
}
$total = ceil($query->totrows/ $pagesize);
if($query->totrows<=$pagesize)
{
$query = new Bin_Query();
$sql = "SELECT * FROM `news_table`";
if($query->executeQuery($sql))
$records = $query->records;
if(count($Err->messages) > 0 )
{
$records = $Err->values;
}
//print_r($records);
return Display_DNews::showNews($records,1,$this->data['paging'],$this->data['prev'],$this->data['next'],$start,$total,$query_string[0]);
}
else
{
$tmp = new Lib_Paging('classic',array('totalpages'=>$total, 'length'=>10),'pagination');
$this->data['paging'] = $tmp->output;
$this->data['prev'] =$tmp->prev;
$this->data['next'] = $tmp->next;
$query = new Bin_Query();
$sql = "SELECT * FROM `news_table` LIMIT $start,$end";
if($query->executeQuery($sql))
$records = $query->records;
if(count($Err->messages) > 0 )
{
$records = $Err->values;
}
return Display_DNews::showNews($records,1,$this->data['paging'],$this->data['prev'],$this->data['next'],$start,$total,$query_string[0]);
}
}
function insert()
{
$year=$_POST['txtyear'];
$title=$_POST['txtname'];
$description=$_POST['txtdescription'];
$status=$_POST['txtstatus'];
$current_date = $_POST['txtdate'];
$uploaded_path = '../uploads/news';
$saved_path = 'uploads/news';
if($_FILES['image']['size']>0)
{
$headerimage = $uploaded_path."/".$_FILES['image']['name'];
$savedpath = $saved_path."/".$_FILES['image']['name'];
move_uploaded_file($_FILES['image']['tmp_name'],$headerimage);
}
$insert="INSERT INTO `news_table` (`news_datetime`,`news_year`, `news_header`, `news_description`, `news_status`,`news_image`) VALUES('$current_date','$year','$title','$description','$status','$savedpath')";
$obj=new Bin_Query();
if($obj->updateQuery($insert))
{
$_SESSION['message'] = 'News has been added Successfully';
}
else
{
$_SESSION['error_message'] = 'Oops unable to insert';
}
}
function showEdit()
{
$testid=$_GET['newsid'];
$select="select * from news_table where news_id='$testid' ";
$obj=new Bin_Query();
$obj->executeQuery($select);
return $obj->records[0];
}
function update()
{
if(isset($_POST['update']))
{
$testid=$_GET['id'];
$year=$_POST['txtyear'];
$name=$_POST['txtname'];
$description=$_POST['txtdescription'];
$date=$_POST['txtdate'];
$status=$_POST['txtstatus'];
$uploaded_path = '../uploads/news';
$saved_path = 'uploads/news';
if($_FILES['image']['size']>0)
{
$headerimage = $uploaded_path."/".$_FILES['image']['name'];
$savedpath = $saved_path."/".$_FILES['image']['name'];
move_uploaded_file($_FILES['image']['tmp_name'],$headerimage);
}
else
{
$select="select * from news_table where news_id='$testid'";
$obj1= new Bin_Query();
$obj1->executeQuery($select);
$savedpath=$obj1->records[0]['news_image'];
}
$update="update news_table set news_datetime='$date',news_year='$year', news_header='$name', news_description='$description',news_status='$status',news_image='$savedpath' where news_id='$testid'";
$obj=new Bin_Query();
if($obj->updateQuery($update))
{
$_SESSION['message']="News updated Sucessfully";
}
else
{
$_SESSION['error_message']="Oops unable to update";
}
}
if(isset($_POST['del']))
{
$testid=$_GET['id'];
$sql1="delete from news_table WHERE news_id='".$testid."' ";
$obj=new Bin_Query();
////////////New Modification////////////
$select="select * from news_table where news_id='".$testid."'";
$obj1= new Bin_Query();
$obj1->executeQuery($select);
$mphotoM=$obj1->records[0]['news_image'];
$mphoto='../'.$mphotoM.'';
unlink($mphoto);
////////////New Modification////////////
if($obj->updateQuery($sql1))
{
$_SESSION['message']=" News Deleted Sucessfully";
}
}
}
function delete()
{
$obj= new Bin_Query();
$count = count($_POST);
foreach($_POST as $key=>$value)
{
if($key == $value)
$sql= "DELETE FROM `news_table` WHERE `news_id` ='".(int)$key."' ";
if($count > 2)
{
if($obj->updateQuery($sql));
$_SESSION['message']='News Sucessfully Deleted';
}
else
$_SESSION['error_message']='Please select the item to be Deleted';
}
header("location:?do=news");
}
}
?>