<!-- Developed by AbdulRahman @ http://FireflyDevelopers.cf -->
<?php
   require('Database.php');
   class DbFunction{
   	function login($loginid,$password){
         if(!ctype_alpha($loginid) || !ctype_alpha($password)){
           echo "<script>alert('Either Username or Password is Wrong')</script>";
         }		
      else{		
   	$db = Database::getInstance();
   	$mysqli = $db->getConnection();
   	$query = "SELECT loginid, password FROM tbl_login where loginid=? and password=? ";
   	$stmt= $mysqli->prepare($query);
   	if(false===$stmt){
   		
   		trigger_error("Error in query: " . mysqli_connect_error(),E_USER_ERROR);
   	}
   	else{
   		
   		$stmt->bind_param('ss',$loginid,$password);
   		$stmt->execute();
   		$stmt -> bind_result($loginid,$password);
   		$rs=$stmt->fetch();
   		if(!$rs)
   		{
   			echo "<script>alert('Invalid Details')</script>";
   			header('location:login.php');
   			
   		}
   		else{
   			echo "<script>location='https://nmjportal.stech.co.ke/Admin/pages/add-announcement.php'</script>";
   	// 		header('location:Admin/pages/add-announcement.php');
   		}
   	}
   	}
   	}
   	
   	function create_announcement($atitle,$atype,$alink,$adate){
   		
		if($atitle==""){
   			 
   			echo "<script>alert('Enter Announcement Title')</script>";
   		
   		}
		
   		elseif($atype==""){
   			 
   			echo "<script>alert('Enter Announcement Type')</script>";
   		
   		}
   		
   		else if($alink==""){
   			 
   			echo "<script>alert('Enter Announcement Link')</script>";
   		}
   		
   		else{
			
   			$db = Database::getInstance();
   			$mysqli = $db->getConnection();
   			$query = "insert into tbl_announcement (atitle,atype,alink,adate)values(?,?,?,?)";
   			$stmt= $mysqli->prepare($query);
   			if(true===$stmt){
   			
   				trigger_error("Error in query: " . mysqli_connect_error(),E_USER_ERROR);
   			}
   			
   			else{
   			
   				$stmt->bind_param('ssss',$atitle,$atype,$alink,$adate);
   				$stmt->execute();
   				echo "<script>alert('Announcement Sent Successfully')</script>";
   				
   			}
   		}				
   	}   

	function create_user($username,$password,$firstname,$lastname,$email,$adate){
   		
		if($username==""){
   			 
   			echo "<script>alert('Enter username ')</script>";
   		
   		}
		
   		elseif($firstname==""){
   			 
   			echo "<script>alert('Enter firstname')</script>";
   		
   		}
   		
   		else if($lastname==""){
   			 
   			echo "<script>alert('Enter lastname ')</script>";
   		}
	    else if($email==""){
   			 
			echo "<script>alert('Enter email ')</script>";
		}
   		
   		else{
			
   			$db = Database::getInstance();
   			$mysqli = $db->getConnection();
   			$query = "insert into tbl_login (loginid,password,Firstname,Lastname,Email,adate)values(?,?,?,?,?,?)";
   			$stmt= $mysqli->prepare($query);
   			if(true===$stmt){
   			
   				trigger_error("Error in query: " . mysqli_connect_error(),E_USER_ERROR);
   			}
   			
   			else{
   			
   				$stmt->bind_param('ssssss',$username,$password,$firstname,$lastname,$email,$adate);
   				$stmt->execute();
   				echo "<script>alert('User created Successfully')</script>";
   				
   			}
   		}				
   	}
	function create_Reminder($banner,$message,$paymnent,$author,$adate,$status){
	
	if($banner==""){
			
		echo "<script>alert('Enter banner ')</script>";
	
	}
	
	elseif($message==""){
			
		echo "<script>alert('Enter message')</script>";
	
	}
	
// 	else if($paymnent==""){
			
// 		echo "<script>alert('Enter payment info ')</script>";
// 	}
// 	else if($author==""){
			
// 		echo "<script>alert('Enter author ')</script>";
// 	}
	
	else{
		
		$db = Database::getInstance();
		$mysqli = $db->getConnection();
		$query = "insert into tbl_reminders(Banner,Message,Payment,Author,CreationDate,Status)values(?,?,?,?,?,?)";
		$stmt= $mysqli->prepare($query);
		if(true===$stmt){
		
			trigger_error("Error in query: " . mysqli_connect_error(),E_USER_ERROR);
		}
		
		else{
		
			$stmt->bind_param('ssssss',$banner,$message,$paymnent,$author,$adate,$status);
			$stmt->execute();
			echo "<script>alert('Reminder created Successfully')</script>";
			
		}
	}				
}

function edit_Reminder($banner,$message,$paymnent,$author,$adate,$status,$id){
	
	if($banner==""){
			
		echo "<script>alert('Enter banner ')</script>";
	
	}
	
	elseif($message==""){
			
		echo "<script>alert('Enter message')</script>";
	
	}
	
// 	else if($paymnent==""){
			
// 		echo "<script>alert('Enter payment info ')</script>";
// 	}
// 	else if($author==""){
			
// 		echo "<script>alert('Enter author ')</script>";
// 	}
	
	else{
		
		$db = Database::getInstance();
		$mysqli = $db->getConnection();
		$query = "UPDATE tbl_reminders set Banner=?,Message=?,Payment=?,Author=?,CreationDate=?,Status=? where id=?";
		$stmt= $mysqli->prepare($query);
		if(true===$stmt){
		
			trigger_error("Error in query: " . mysqli_connect_error(),E_USER_ERROR);
		}
		
		else{
		
			$stmt->bind_param('sssssss',$banner,$message,$paymnent,$author,$adate,$status,$id);
			$stmt->execute();
			echo "<script>alert('Reminder edited Successfully')</script>";
			
		}
	}				
}
   function show_announcement(){
   	
   	$db = Database::getInstance();
   	$mysqli = $db->getConnection();
   	$query = "SELECT * FROM tbl_announcement ";
   	$stmt= $mysqli->query($query);
   	return $stmt; 	
   } 
   function show_users(){
   	
	$db = Database::getInstance();
	$mysqli = $db->getConnection();
	$query = "SELECT * FROM tbl_login ";
	$stmt= $mysqli->query($query);
	return $stmt; 	
   } 
   function show_Regsterdusers(){
   	
	$db = Database::getInstance();
	$mysqli = $db->getConnection();
	$query = "SELECT * FROM user ";
	$stmt= $mysqli->query($query);
	return $stmt; 	
   } 
   function show_reminders(){
   	
	$db = Database::getInstance();
	$mysqli = $db->getConnection();
	$query = "SELECT * FROM tbl_reminders ";
	$stmt= $mysqli->query($query);
	return $stmt; 	
   } 
   function get_reminders($id){
   	
	$db = Database::getInstance();
	$mysqli = $db->getConnection();
	$query = "SELECT * FROM tbl_reminders where id='$id' ";
	$stmt= $mysqli->query($query);
	return $stmt; 	
   } 
   }
?>