 <?php
 error_reporting(0);
include("../../include/Class.php");
$unit = new Unit();

function check_item($user_name,$user_screen,$form_name)
{
$Isql=mysql_query("select * from user_rights where user_name ='$user_name' AND user_screen ='$user_screen' AND user_form_name='$form_name' order by user_id asc");
$rscounts=mysql_num_rows($Isql);
return $rscounts;
}

/********************************** ADD & UPDATE QUERY ***************************************/
if($_POST[action] == 'ADD')
{
$user_name=$_POST['user_name'];
$user_screen=$_POST['user_screen'];
$user_form_name = $_POST['form_name'];
$user_form_name=substr($user_form_name,0,strlen($user_form_name)-1);
$final = split(',',$user_form_name);
foreach($final as $value)
{
$form_name = $value;
$check_item1=check_item($user_name,$user_screen,$form_name);
if($check_item1==0)
{
$Insql=mysql_query("insert into user_rights(user_name,user_screen,user_form_name,access_form)values('$user_name','$user_screen','$form_name','$user_form_name')");
echo "<script>alert('Successfully Added')</script>";
}
}
}
//******************************* Delete *******************************************************/
if($_POST[action]== 'del_user')
{
$Insql=mysql_query("delete from user_rights where user_id='$_POST[del_id]'");
}
echo $msg;
echo "<br><br>";
include("user_rights_list.php");
?>
