<?php
class Main extends Model
{
  function Main()
  {
    parent::Model();
  }
 
 
 // Get All Members 
 
 function GetAllMembers()
 {
 
  
   $this->db->limit(5);
   $query =  $this->db->get('users');
   
  if($query->num_rows()>0)
 {  
   return $query;
 }
 else
 {
  
  return false;
 
 }
 
 }
 
 
 // Login Function //
 
 function AdminLogin($email,$password)
 {
 $query = $this->db->get_where('admin', array('username' => $email,'password' => md5($password)));
 
 if($query->num_rows()>0)
 {
 
 $data = array( 
 'id' => $query->row('id'),
 'username' => $query->row('username'),
 'admin_logged_in' => TRUE
 );
 
 $this->session->set_userdata($data);
 
 
 return true;
 
 }
 else
 {
 
 return false;
 
 
 }
 
 }
 
 
 
 // Signup Function //
  function Signup($username,$email,$password,$number)
  {

   $data = array(
               'username' => $username,
               'email' =>  $email,
               'password' => md5($password),
			   'number' => $number,
			   'status' => '1'            
			   );

  $this->db->insert('users',$data); 
    return true;

  }
  function Signup1($username,$email,$password,$number,$fullname)
  {

   $data = array(
               'username' => $username,
               'email' =>  $email,
               'password' => md5($password),
			   'number' => $number,
			   'fullname' => $fullname,
			   'status' => '1'            
			   );

  $this->db->insert('users',$data); 
    return true;

  }
 // login Function //
 
 function login($email,$password)
 {
 $query = $this->db->get_where('users', array('username' => $email,'password' => md5($password),'status' => '1'));
 
 if($query->num_rows()>0)
 {
 
 $data = array( 
 'id' => $query->row('id'),
 'username' => $query->row('username'),
 'email' => $query->row('email'),
 'logged_in' => TRUE,
 'photo' => $query->row('photo')
 );
 
 $this->session->set_userdata($data);
 
 
 return true;
 
 }
 else
 {
 
 return false;
 
 
 }

 } 
 
 function changePicture($id,$photo)
 {

 $data = array(
               'photo' => $photo
            );

  $this->db->where('id =',$id);
  $this->db->update('users',$data); 
  
  return true;
 
 }








  function get_num_groups()
  {
  
  $query = $this->db->get('groups');

  $num = $query->num_rows();
  
  return $num;  
  
 } 
 
 function get_num_updates()
 {
 
 $query = $this->db->get('messages');

  $num = $query->num_rows();
  
  return $num;  
 
 }
 
 
 function get_num_users()
 {
 
  $query = $this->db->get('users');

  $num = $query->num_rows();
  
  return $num;  
 
 
 }
 
















 




}

?>
