<?php
include("include.php");
include("phpfunctions.php");

function kid_login()
{
	$sel=executework("select * from lms_kid_register where parent_email='".$_POST['email_id']."' and password='".$_POST['password']."' and status=1");
	$cnt=@mysqli_num_rows($sel);
	if($cnt>0)
	{
		$row=@mysqli_fetch_array($sel);
		$_SESSION['instructor_email']=$row['parent_email'];
		$_SESSION['login_type']="Kid";
		$_SESSION['login_id']=$row['id'];
		redirect("dashboard.php");
	}
	else
	{
		redirect("index.php?fail=1");
	}	
}

// change Password
function kid_change_password()
{
	$sel=executework("select * from lms_kid_register where id='".$_SESSION['login_id']."' and password='".$_POST['oldpassword']."'");
	$cnt=@mysqli_num_rows($sel);
	if($cnt>0)
	{
		$update=executework("update lms_kid_register set password='".$_POST['newpassword']."' where id='".$_SESSION['login_id']."' ");
		redirect("change_password.php?succ=1");
	}
	else
	{
		redirect("change_password.php?fail=1");
	}
}

function kids_signup()
{	
	$sel=executework("select * from lms_kid_register where parent_email='".$_POST['parent_email']."'");
	$cnt=@mysqli_num_rows($sel);
	
	if(!empty($_POST['mid']))
	{
		
		$upd=executework("update lms_kid_register set age_group='".$_POST['age_group']."', kid_name='".$_POST['kid_name']."',parent_name='".$_POST['parent_name']."',parent_email='".$_POST['parent_email']."', mode_class='".$_POST['mode_class']."' where id='".$_POST['mid']."'");
		
		redirect("dashboard.php");
	}
	if($cnt>0)
	{
			redirect("register.php?exist=1");
	}
	else
	{
		$int=executeworkins("insert into lms_kid_register (age_group,kid_name,parent_name,parent_email,password,mode_class,created_on,status) values('".$_POST['age_group']."','".$_POST['kid_name']."','".$_POST['parent_name']."','".$_POST['parent_email']."','123','".$_POST['mode_class']."','".date('Y-m-d h:i:s')."','1')");
		
		redirect("index.php?succ=1");
	}
}

?>