Location: PHPKode > projects > MembersGear > membersgear/admin/admin_country_m.php
<?php

require_once "../config/config.php"; 
require_once "../includes/location_class.php";
require_once INCLUDE_DIR."/users_class.php"; 
$users=new users_class();
  
 if($_SERVER['REQUEST_METHOD']=="GET")
        $_SESSION[SESSION_PREFIX.'page_referrer']=$_SERVER['HTTP_REFERER'];
        
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] = 1;
           $lsValues[2] = $_POST['txtDescription'];
           $lsValues[3] = 0;
           $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('Country created is successfully.');
           }
           else
           {
                $message->SetMessage('Some error occure while inserting country.');
           }
          
          if(isset($_SESSION[SESSION_PREFIX.'page_referrer']))
             Redirect($_SESSION[SESSION_PREFIX.'page_referrer'],true);
        else  
          Redirect('admin_country_v.php');         
           
           break;
    case 'update':                     
           //Update           
           $lTypes=null;   
           $query = 'UPDATE '.TABLE_PREFIX.'location SET name=?,description=?,status=?,modifiedby=?,modifiedon=?,modifiedipaddress=? WHERE id=?';
                    //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']; 
           
           $lsUpdatedrows = $loLocation->Update($query,$lsValues,$lTypes);
           
           if($lsUpdatedrows > 0)
           {
                $message->SetMessage('Country is updated successfully.');
           }
           else
           {
                $message->SetMessage('Some error occure while updating records.');
           }

          if(isset($_SESSION[SESSION_PREFIX.'page_referrer']))
             Redirect($_SESSION[SESSION_PREFIX.'page_referrer'],true);
         else  
            Redirect('admin_country_v.php?'.$_SESSION['gsQueryStr']);
         
           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['gsQueryStr']);
                //echo $_SESSION['gsQueryStr'];die;
                $smarty->assign('IsEdit','yes');
                $smarty->assign('Location','Country');
                $smarty->display('admin_location_m.tpl'); 
            break;      
     case 'delete':
            $lTypes = false;
            $lsValues = array($_GET['id'],$_GET['id']);
            $query = 'DELETE FROM '.TABLE_PREFIX.'location WHERE id=? OR parentid=?';
            
            $lsDeletedrow = $loLocation->Delete($query,$lsValues,null);
           
            $query = "SELECT count(*) as `totalrecord` FROM ".TABLE_PREFIX."location WHERE type=1";
                                           
            $liRowCount = $loLocation->View($query);
            
            $explodeSession = explode('&',$_SESSION['gsQueryStr']);
            
            $explodeBeginRow = explode('=',$explodeSession[2]);
            
            $explodePageRows = explode('=',$explodeSession[3]);
            // print_r($liRowCount);die;
            if($explodeBeginRow[1] >= $liRowCount[0]['totalrecord'])
            {
                  $explodeSession[2] = 'begin='.(($explodeBeginRow[1]+0) - $explodePageRows[1]);
                  $_SESSION['gsQueryStr'] = implode('&',$explodeSession);
            } 
            
            if($lsDeletedrow > 0)
            {
                $message->SetMessage('Country 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."&";
                    }     
             
             }       
            
           if(isset($_SESSION[SESSION_PREFIX.'page_referrer']))
             Redirect($_SESSION[SESSION_PREFIX.'page_referrer'],true);
         else  
           Redirect('admin_country_v.php?'.$_SESSION['gsQueryStr'].$quest);  
     

            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'] = 0;
           $smarty->assign('data',$data);
           $smarty->assign('Location','Country');
           $smarty->display('admin_location_m.tpl');
                       
}
?>
Return current item: MembersGear