<?
session_start();
if(strlen($user)<=0)
{
 print "<script> alert('Please login again'); parent.document.location='ind.php'; </script>";
 return;
}
print "User: $user <br> ";
 include("../opendb.php");
if($sub)
{
 $sql="create table salesgroup (saman varchar(100), exe varchar(100))";
 mysqli_query($db,$sql);
 foreach($exe as $a)
 {
   $sql="insert into salesgroup values('$saman','$a')";
   mysqli_query($db,$sql)or die(mysqli_error($db));
 }
}
if($rem)
{
 foreach($exe_rem as $a)
 {
   $sql="delete from salesgroup where exe='$a' and saman='$saman_rem'";
   mysqli_query($db,$sql)or die(mysqli_error($db));
   print "<font color='red'><blink>Record has been deleted</blink></font>";
 }
}
?>
<link rel="stylesheet" href="style.css" type="text/css" />
<body bgcolor=fcfff1>
<font color=green size=4> <b>Sales Group Creation</font>
<hr bgcolor=red>
<center>
<form name='f1' action='<?print $PHP_SELF?>' method='post' onSubmit="return validate()">
<table  cellspacing=1 cellpadding=5 bgcolor='green'>
<tr><td align=center bgcolor='white'>
<table border=0  cellspacing=2 cellpadding=5>
<tr><td>Sales Manager</td><td><select name='saman'>
<?
$re=mysqli_query($db,"select username from bruser where level=11 order by username");

while($row=mysqli_fetch_array($re))
{
 print "\n<option>$row[0]</option>";
}
?>
</select> </td></tr>
<tr><td colspan=2 align=center bgcolor='pink'><b>Users</td></tr>
<?
$re1=mysqli_query($db,"select username from bruser where level=0  and username not in(select exe from salesgroup) order by username");

while($row=mysqli_fetch_array($re1))
{
 print "\n<tr><td><input type=checkbox name='exe[]' value='$row[0]'></td><td>$row[0]</td>";
 print "</tr>";
}
?>
<tr><td colspan=2 align=center bgcolor='pink'><input type=submit value='Assign to Above Manager' name='sub'></td></tr>
</table>
</td></tr></table>
</form>
<hr>


<?
//***************************************************************************************
 $re3=mysqli_query($db,"select distinct saman from salesgroup order by saman");
 while($row=mysqli_fetch_array($re3))
 {
?>
<form name='f1' action='<?print $PHP_SELF?>' method='post' onSubmit="return validate()">
<table  cellspacing=1 cellpadding=5 bgcolor='green'>
<tr><td align=center bgcolor='white'>
<table border=0  cellspacing=2 cellpadding=5>
<tr><td>Sales Manager</td><td>
<?
$re=mysqli_query($db,"select * from salesgroup where saman='$row[0]' order by saman")or die(mysqli_error($db));
$row1=mysqli_fetch_array($re);
print "<input type=text readonly name='saman_rem' value='$row1[0]'";
?>
</select> </td></tr>
<tr><td colspan=2 align=center bgcolor='pink'><b>Users</td></tr>
<?
$re1=mysqli_query($db,"select exe from salesgroup where saman='$row[0]' order by exe");

while($row=mysqli_fetch_array($re1))
{
 print "\n<tr><td><font color='red'>Remove <input type=checkbox name='exe_rem[]' value='$row[0]'></td><td>$row[0]</td>";
 print "</tr>";
}
?>
<tr><td colspan=2 align=center bgcolor='pink'><input type=submit value='Remove from above Manager' name='rem'></td></tr>
</table>
</td></tr></table>
<?
}
?>
</form>
