<?php
 	session_start(); 

	if(!isset($_SESSION['tulsilogin']))
	{
		header('Location: index.php');
		return;
	}


date_default_timezone_set("Asia/Kolkata");
$mdate1= date('Y-m-d H:i:s');
$mdate= date('d-m-Y');
$_SESSION['_token']=bin2hex(openssl_random_pseudo_bytes(16));
	
	$umid = $_SESSION['umid'];
	include("connect.php");

	
	//$cmname=$_POST['cmname'];
	
	
	
	
	$traningservicemid=$_POST['traningservicemid'];
	$traningsubservicemid=$_POST['traningsubservicemid'];
	$countrymid=$_POST['countrymid'];
	$traningdocsmid=$_POST['traningdocsmid'];
	$rolemid=$_POST['rolemid'];
	

	if(!in_array('All',$traningsubservicemid))
{
	$traningsubservicemid = $_POST['traningsubservicemid'];
}
else{
	 $eve = "select traningsubservicemid from res_traningsubservice_master where traningservicemid=$traningservicemid";
		$re = mysqli_query($conn, $eve);
			$traningsubservicemid = array();																
		while($rt = mysqli_fetch_assoc($re))

		{
			$traningsubservicemid1 = $rt['traningsubservicemid'];
			array_push($traningsubservicemid,$traningsubservicemid1);
		}
}
	
	
	foreach ($traningsubservicemid as $one_by_one_sid) 
					{
						foreach ($traningdocsmid as $one_by_one_sid1) 
					{
						 $eve1 = "INSERT INTO res_traningmoduleroleallocation_detail (countrymid,traningservicemid,tmraddedby,tmraddedon,tmrupdatedby,tmrupdatedon,traningsubservicemid,traningdocsmid,rolemid) VALUES('$countrymid','$traningservicemid','$umid','$mdate1','$umid','$mdate1','$one_by_one_sid','$one_by_one_sid1','$rolemid')";
		$re1 = mysqli_query($conn, $eve1);
					}
					
					}
		 

	header("Location: moduleallocationdetail.php?id=$rolemid");
			
	
?>