<?php 
class functions extends CI_model
 {
		function getone($tblname ,$id)
		{
		$this->db->where('id',$id);
		$qry =$this->db->get($tblname);	
		if($qry->num_rows() > 0)
		     return $qry ;   
		     return FALSE; // Extra curly braces not needed. A return ends execution of a function	
		}
		
		function getjob($tblname ,$id)
		{
		$this->db->where('job_id',$id);
		$qry =$this->db->get($tblname);	
		if($qry->num_rows() > 0)
		     return $qry ;   
		     return FALSE; // Extra curly braces not needed. A return ends execution of a function	
		}


function moveUp($type,$status,$id,$order)
{            
    $up=$order-1;
    
    $this->db->where('p_order',$up);
    $this->db->where('module',$type);
    $this->db->update('posts',array('p_order'=>$order));
    
    $this->db->where('id',$id);
    $this->db->where('module',$type);
    $this->db->update('posts',array('p_order'=>$up));    
} 

function movefirst($type,$status,$id,$order)
{     
       
       
    $this->db->where('id',$id);
    $this->db->where('module',$type);
    $this->db->update('posts',array('p_order'=>'1'));  
    
     $this->db->where('id !=',$id);
     $this->db->where('p_order <',$order); 
     $this->db->where('module',$type);
     $this->db->set('p_order','p_order+1', FALSE);
     $this->db->update('posts');    

} 


function movedown($type,$status,$id,$order)
{            
    $up=$order+1;
    
    $this->db->where('p_order',$up);
    $this->db->where('module',$type);
    $this->db->update('posts',array('p_order'=>$order));
    
    $this->db->where('id',$id);
    $this->db->where('module',$type);
    $this->db->update('posts',array('p_order'=>$up));    
} 
function movelast($type,$status,$id,$order)
{    

    $this->db->where('module',$type);
    $this->db->select_max('p_order');
    $query=$this->db->get('posts');
    $row=$query->row();
    $last_order=$row->p_order;  
       
    $this->db->where('id',$id);
    $this->db->where('module',$type);
    $this->db->update('posts',array('p_order'=>$last_order));  
    
     $this->db->where('id !=',$id);
     $this->db->where('p_order >',$order); 
     $this->db->where('module',$type);
     $this->db->set('p_order','p_order-1', FALSE);
     $this->db->update('posts');    

} 



		
		function delete_one($tblname ,$id)
		{
		$this->db->where('id',$id);
		$qry =$this->db->delete($tblname);
		return $qry;	
		}
		
		
			function delete_order($tblname ,$id)
		{
		$this->db->where('session_id',$id);
		$qry =$this->db->delete($tblname);
		return $qry;	
		}

		
		function get_lang()
		{
		$q =$this->db->get('settings');
		return $q;	
		}
		
		function get_type_settings($type)
		{
		$this->db->where('title',$type);
		$st_qry =$this->db->get('modules');
		if($st_qry->num_rows() > 0)
		     return $st_qry;   
		     return FALSE;
		}
		
		
		function get_modules()
		{
		$q =$this->db->get('modules');
		return $q;	
		}
		
		function get_cats($type)
		{
		$this->db->where('module',$type);
		$q =$this->db->get('categories');
		return $q;	
		}
		function get_cat_name($catid)
		{
		$this->db->where('id',$catid);
		$q =$this->db->get('categories');
		foreach ($q->result() as $r):
		return $r->name;
		endforeach;	
		}

		function update_status($tbl,$pid,$data)
		{
        $this->db->where('id',$pid);
		$q=$this->db->update($tbl,$data);

		}

function status($data,$id)
		{
        $this->db->where('session_id',$id);
		$q=$this->db->update('orders',$data);

		}
function status2($data,$id)
		{
        $this->db->where('id',$id);
		$q=$this->db->update('members',$data);

		}





}
