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

function instructor_login()
{
	$sel=executework("select * from lms_instructor_register where email_id='".$_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['email_id'];
		$_SESSION['login_type']="Instructor";
		$_SESSION['login_id']=$row['id'];
		redirect("dashboard.php");
	}
	else
	{
		redirect("index.php?fail=1");
	}	
}

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

function instructor_signup()
{	
	$sel=executework("select * from lms_instructor_register where email_id='".$_POST['email_id']."'");
	$cnt=@mysqli_num_rows($sel);
	
	if(!empty($_FILES['instructor_resume']['name']))
	{
		$image_name = $_FILES['instructor_resume']['name'];
		$tmp_name   = $_FILES['instructor_resume']['tmp_name'];
		$filename = $_FILES['instructor_resume']['name'];
		$len=strlen($filename);
		$pos=strrpos($filename,'.');
		$ext1=substr($filename,$pos,$len);
		$fname=substr($filename,0,$pos);
		$file_name='';
		$target_dir = "Instructor_Resume/";
		$file_name= preg_replace("/[^a-zA-Z0-9]/", "", $fname)."_".time().$ext1;
		$target_file = $target_dir.$file_name;
		move_uploaded_file($_FILES['instructor_resume']['tmp_name'],$target_file);
		$qry=",instructor_resume='".$file_name."'";

	}
	if(!empty($_POST['mid']))
	{
		
		$upd=executework("update lms_instructor_register set instructor_name='".$_POST['instructor_name']."', email_id='".$_POST['email_id']."',instructor_mobile='".$_POST['instructor_mobile']."',instructor_education='".$_POST['instructor_education']."', instructor_linkedIn='".$_POST['instructor_linkedIn']."',instructor_address='".$_POST['instructor_address']."',university_name='".$_POST['university_name']."', university_major='".$_POST['university_major']."',teaching_exp='".$_POST['teaching_exp']."'".$qry." where id='".$_POST['mid']."'");
		
		redirect("dashboard.php");
	}
	if($cnt>0)
	{
			redirect("register.php?exist=1");
	}
	else
	{
		$int=executeworkins("insert into lms_instructor_register (instructor_name,email_id,password,instructor_mobile,instructor_education,instructor_linkedIn,instructor_address,university_name,university_major,teaching_exp,instructor_resume,created_by,created_on,status) values('".$_POST['instructor_name']."','".$_POST['email_id']."','123','".$_POST['instructor_mobile']."','".$_POST['instructor_education']."','".$_POST['instructor_linkedIn']."','".$_POST['instructor_address']."','".$_POST['university_name']."','".$_POST['university_major']."','".$_POST['teaching_exp']."','".$file_name."','".$_SESSION['user_name']."','".date('Y-m-d h:i:s')."','1')");
		
//		$_SESSION['instructor_email']=$_POST['email_id'];
//		$_SESSION['login_type']="Instructor";
//		$_SESSION['login_id']=$int;
		
		redirect("index.php?succ=1");
	}
}

?>