<?php
 	session_start(); 

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



$_SESSION['_token']=bin2hex(openssl_random_pseudo_bytes(16));
	
	
	include("connect.php");
	include("connectp.php");

	
	
	
	
	$rolemid=$_POST['rolemid'];
	$smodulemid=$_POST['smodulemid'];
	$attechment="";
	
	$n=0;
	foreach ($smodulemid as $one_by_one_sid) 
					{
					if(isset($_POST['malistview'][$n]) || isset($_POST['maview'][$n]) || isset($_POST['maadd'][$n]) || isset($_POST['maedit'][$n]) || isset($_POST['madelete'][$n])  )
					{
						$malistview=0;
						$maview=0;
						$maadd=0;
						$maedit=0;
						$madelete=0;
					if($_POST['malistview'][$n] == 1)
					{
						$malistview = 1;
					}
					if( $_POST['maview'][$n] ==1 || ($_POST['maadd'][$n] ==1) || ($_POST['maedit'][$n] ==1) || ($_POST['madelete'][$n] == 1)  )
					{
						$malistview = 1;
					}
					
					 if(($_POST['maview'][$n] ==1))
					{
						$maview = 1;
					}
					 if(($_POST['maadd'][$n] ==1))
					{
						$maadd = 1;
					}
					 if(($_POST['maedit'][$n]) ==1)
					{
						$maedit = 1;
					}
					 if(($_POST['madelete'][$n]) == 1)
					{
						$madelete = 1;
					}
					 $sql1="Insert into res_moduleallocation_detail (rolemid,smodulemid,malistview,maview,maadd,maedit,madelete) values (?,?,?,?,?,?,?)";
					$stmt1= $db7->prepare($sql1);
				$stmt1->execute([$rolemid,$one_by_one_sid,$malistview,$maview,$maadd,$maedit,$madelete]);
				$n =$n+2;
					}
					}
		
		
	
			
	$_SESSION['msg'] = "Record saved successfully";
	header('Location: moduleallocation.php');
			
	
?>