<?php
require_once "../config/config.php";
require_once "../includes/location_class.php";
require_once INCLUDE_DIR."/users_class.php";
$users=new users_class();
if($users->IsAdminhavePermission($_SESSION[SESSION_PREFIX.'Admin_UserID'],'Can view countries/states')==false)
{
Redirect('admin_nopermission.php',true);
}
if($users->IsAdminhavePermission($_SESSION[SESSION_PREFIX.'Admin_UserID'],'Can manage countries/states')==false)
{
Redirect('admin_nopermission.php',true);
}
$loLocation = new location_class();
//print_r($users->View());die;
switch($_action)
{
case 'insert':
//Insert
$lTypes=null;
$query = 'INSERT INTO '.TABLE_PREFIX.'location
(name, type, description, parentid, status, createdby, createdon, createdipaddress)
VALUES(?,?,?,?,?,?,?,?)';
//VALUES('user4','user4','hide@address.com','address1','1950-12-12 00:00:00',1,1)'
//$lsValues = array('user4','user4','hide@address.com','address1','1950-12-12 00:00:00',1,1);
$lsValues = array();
$lsValues[0] = $_POST['txtName'];
$lsValues[1] = $_POST['hdnLocationType'];
$lsValues[2] = $_POST['txtDescription'];
$lsValues[3] = $_POST['hdnParentID'];
$lsValues[4] = $_POST['ddlStatus']+0;
$lsValues[5] = $_SESSION[SESSION_PREFIX.'Admin_UserID'];
$lsValues[6] = mktime();
$lsValues[7] = $_SERVER['REMOTE_ADDR'];
$lsInsertedrows = $loLocation->Insert($query,$lsValues,$lTypes);
if($lsInsertedrows > 0)
{
$message->SetMessage('State is added successfully.');
}
else
{
$message->SetMessage('Some error occure while inserting records.');
}
Redirect('admin_country_state_v.php?id='.$lsValues[3]);
break;
case 'update':
//Update
$lTypes=null;
$query = 'UPDATE '.TABLE_PREFIX.'location SET name=?,description=?,status=?,modifiedby=?,modifiedon=?,modifiedipaddress=? WHERE id=? and parentid=?';
//VALUES('user4','user4','hide@address.com','address1','1950-12-12 00:00:00',1,1)'
//$lsValues = array('user4','user4','hide@address.com','address1','1950-12-12 00:00:00',1,1);
$lsValues = array();
$lsValues[0] = $_POST['txtName'];
$lsValues[1] = $_POST['txtDescription'];
$lsValues[2] = $_POST['ddlStatus']+0;
$lsValues[3] = $_SESSION[SESSION_PREFIX.'Admin_UserID'];
$lsValues[4] = mktime();
$lsValues[5] = $_SERVER['REMOTE_ADDR'];
$lsValues[6] = $_POST['hdnID'];
$lsValues[7] = $_POST['hdnParentID'];
$lsUpdatedrows = $loLocation->Update($query,$lsValues,$lTypes);
if($lsUpdatedrows > 0)
{
$message->SetMessage('State is updated successfully.');
}
else
{
$message->SetMessage('Some error occure while updating records.');
}
Redirect('admin_country_state_v.php?id='.$lsValues[7].'&'.$_SESSION['gsStateQueryStr']);
break;
case 'edit':
$lTypes=null;
$lsValues = array($_GET['id']);
$query = "SELECT * FROM ".TABLE_PREFIX."location WHERE id=?";
$result = $loLocation->View($query,$lsValues,null);
$smarty->assign('data',$result);
$smarty->assign('QueryString',$_SESSION['gsStateQueryStr']);
$smarty->assign('IsEdit','yes');
$smarty->assign('Location','State');
$smarty->display('admin_location_m.tpl');
break;
case 'delete':
$lTypes = false;
$lsValues = array($_GET['id']);
$query = 'SELECT parentid FROM '.TABLE_PREFIX.'location WHERE id='.$_GET['id'];
$lsParentID = mysql_fetch_array(mysql_query($query)) or die(mysql_error());
$query = 'DELETE FROM '.TABLE_PREFIX.'location WHERE id=?';
$lsDeletedrow = $loLocation->Delete($query,$lsValues,null);
/****************************** For PHP Grid *********************************************/
$query = "SELECT count(*) as `totalrecord` FROM ".TABLE_PREFIX."location WHERE parentid=".$lsParentID[0];
$liRowCount = mysql_fetch_array(mysql_query($query)) or die(mysql_error());
$explodeSession = explode('&',$_SESSION['gsStateQueryStr']);
$explodeBeginRow = explode('=',$explodeSession[2]);
$explodePageRows = explode('=',$explodeSession[3]);
// print_r($liRowCount);die;
if($explodeBeginRow[1] >= $liRowCount[0])
{
$explodeSession[2] = 'begin='.(($explodeBeginRow[1]+0) - $explodePageRows[1]);
$_SESSION['gsStateQueryStr'] = implode('&',$explodeSession);
}
if($lsDeletedrow > 0)
{
$message->SetMessage('State is delete successfully.');
}
else
{
$message->SetMessage('Some error occure! Please try again.');
}
$quest="&";
if(isset($_GET) && !empty($_GET))
{
foreach($_GET as $keyname => $value) {
if(strtoupper($keyname)!='ACTION')
$quest.=$keyname."=".$value."&";
}
}
Redirect('admin_country_state_v.php?id='.$lsParentID[0].'&'.$_SESSION['gsStateQueryStr']);
break;
default:
////Parameterized View
/*$lsValues = array("user4");
$lTypes=null;
$result = $users->View('SELECT * FROM tbluser1 t where username=?',$lsValues,$lTypes,1,1000);
$smarty->assign('row',$result);
$smarty->display('users.tpl'); */
$data[0]['parentid'] = $_GET['parentid'];
$smarty->assign('data',$data);
$smarty->assign('Location','State');
$smarty->display('admin_location_m.tpl');
}
?>