Location: PHPKode > projects > Kudos > nirap/update_group_emp.php
<?php
require_once('includes/kudos.php');
require_once('includes/kudos_cookie.php');

$groupID=$_GET['GroupID'];

$query_Group = "SELECT GroupName FROM Team WHERE GroupID='$groupID';";
$execute_Group = mysql_query($query_Group, $kudos) or die("q1");
$group = mysql_fetch_assoc($execute_Group);

$query_selectedEmployees = "SELECT Employee.FirstName, Employee.LastName, Employee.EmpID FROM Employee JOIN EmployeeGroup ON Employee.EmpID=EmployeeGroup.EmpID WHERE EmployeeGroup.GroupID=$groupID;";
$execute_selectedEmployees = mysql_query($query_selectedEmployees, $kudos) or die("q2");
$sEmp = mysql_fetch_assoc($execute_selectedEmployees);

$query_unselectedEmployees = "SELECT Employee.FirstName, Employee.LastName, Employee.EmpID FROM Employee WHERE EmpID!='admin' && Employee.EmpID NOT IN (SELECT EmployeeGroup.EmpID FROM EmployeeGroup WHERE GroupID = $groupID);";
$execute_unselectedEmployees = mysql_query($query_unselectedEmployees, $kudos) or die("q3");
$nEmp = mysql_fetch_assoc($execute_unselectedEmployees);
 
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$groupID=$_POST['groupID'];
$newEmployees=$_POST['nemp'];
$new_count=count($newEmployees);
$remEmployees=$_POST['remp'];
$rem_count=count($remEmployees);
$i=0;
$j=0;

while ($i < $rem_count) {
$queryD = "DELETE FROM EmployeeGroup WHERE EmpID='$remEmployees[$i]' && GroupID=$groupID;";
$executeD = mysql_query($queryD, $kudos) or die(mysql_error());
$i++;
}

while ($j < $new_count) {
$queryI = "INSERT INTO EmployeeGroup VALUES ($groupID, '$newEmployees[$j]');";
$executeI = mysql_query($queryI, $kudos) or die(mysql_error());
$j++;
}

  $insertGoTo = "update_groups.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License

Title      : The Island
Version    : 1.0
Released   : 20070612
Description: A two-column, fixed-width, blue-themed template that can be easily converted into a blog theme.
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>KUDOS!  :::  Employee Recognition System</title>
  <link href="style/default.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
	<?php include ("includes/header_nav.html"); ?>
	<!-- end menu -->
	<div id="page">
		<div id="content">
			<h1 class="title">Updating Group <?php echo $group['GroupName']; ?></h1>
            <form name="cGroup" id="cGroup" action="<?php echo $editFormAction; ?>" method="POST"> 
	    	<p>
			  <h2>Current Employees</h2>
              <table border="0">
			  <tr><td><strong>Remove</strong></td>
			  <td><strong>Employee</strong></td>
			  </tr>
			  <?php do{ ?> 
			  	<tr><td align="center"><input type="checkbox" name="remp[]" value="<?php echo $sEmp['EmpID']; ?>" /></td>
			  		<td><?php echo $sEmp['FirstName'], " ", $sEmp['LastName'];?></td>
			  	</tr>
			  <?php } while ($sEmp = mysql_fetch_assoc($execute_selectedEmployees)); ?></table>
		   	</p>
	    	<p>
			  <h2>Available Employees</h2>
              <table border="0">
			  <tr><td><strong>Include</strong></td>
			  <td><strong>Employee</strong></td>
			  </tr>
			  <?php do{ ?> 
			  	<tr><td align="center"><input type="checkbox" name="nemp[]" value="<?php echo $nEmp['EmpID']; ?>" /></td>
			  		<td><?php echo $nEmp['FirstName'], " ", $nEmp['LastName'];?></td>
			  	</tr>
			  <?php } while ($nEmp = mysql_fetch_assoc($execute_unselectedEmployees)); ?></table>
		   	</p>
            <p>
              <input type="hidden" name="groupID" value="<?php echo $groupID; ?>" />
              <input type="hidden" name="MM_insert" value="form1">
		   	  <input type="submit" name="submit" value="Continue" />
            </p>
		   	</form>
		  <br>
		</div>
		<!-- end content -->
	  <div id="sidebar">
			 
				<h2>Updating Group Members</h2>
                <p>Here you can select new members for your group or remove previously selected members.</p>
                <br />
                <p></p>
	  </div>
        <!-- end sidebar -->
		<div style="clear: both;">&nbsp;</div>
  </div>
	<!-- end page -->
	<div id="footer">
		<p id="legal">Copyright &copy; 2008 National Instruments. All Rights Reserved.</p>
		 
	</div>
	<!-- end footer -->
</div>
<!-- end wrapper -->
</body>
</html>
<!--Template Copyright &copy; 2007 The Island. All Rights Reserved. Designed by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a> -->
Return current item: Kudos