Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as PHP by moin ( 4 years ago )
<?php
session_start();
?>

<html>
<body>
<?php
if(!isset($_SESSION["boss"]) && !isset($_POST["login"]))
//if(isset($_SESSION["boss"]))
{
	session_unset();
    session_destroy();


?>
<h1>If you are the boss, login here</h1>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
	Please type your ID:	<input type="text" name="id"><br/>
    Please type your passwd:<input type="password" name="passwd"><br/>
    <input type="submit" name="login" value="Login">
</form>
<?php
}
?>

<?php
if(!isset($_SESSION["boss"]))
{
	if(isset($_POST["login"]))
    {
    	if($_POST["id"] == "admin" && $_POST["passwd"] == "admin")
        {
        	$_SESSION["boss"] = "admin";
            
            require_once "My-DB-Functions.php";
            $conn = My_Connect_DB();
            $sql = "SELECT * FROM Employee;";
            //Run_Select_Show_Result($conn, $sql);
            $result = My_SQL_EXE($conn, $sql);
            Show_Editable_Result($result);
            
            My_Disconnect_DB($conn);
        }
        else
        {
        	echo "Your id or password is not correct. 
            	Click <a href='Activity-10-27-1.php'>here</a> to try again.<br/>";
        }
    }
    return;
}

if($_GET["act"] == "remove")
{
	$id = $_GET["id"];
	require_once "My-DB-Functions.php";
	$conn = My_Connect_DB();
    
    	$sql = "DELETE FROM Employee WHERE id='".$id."';";
        $result = My_SQL_EXE($conn, $sql);
    	$sql = "SELECT * FROM Employee;";
        //Run_Select_Show_Result($conn, $sql);
        $result = My_SQL_EXE($conn, $sql);
        Show_Editable_Result($result);
        
	My_Disconnect_DB($conn);

}

if(isset($_POST["update"]))
{
	$salary = $_POST["salary"]; //1d array
	$bonus = $_POST["bonus"]; //1d array
	$id = $_POST["id"]; //1d array
    
    if(count($id) > 0)
    {
            require_once "My-DB-Functions.php";
            $conn = My_Connect_DB();
            foreach($id as $index => $em)
            {
            $sql = "UPDATE Employee SET bonus='".$bonus[$index]."', salary='".$salary[$index]."' 
            		WHERE id='".$em."';";
               $result = My_SQL_EXE($conn, $sql);
            }
            $sql = "SELECT * FROM Employee;";
            $result = My_SQL_EXE($conn, $sql);
            Show_Editable_Result($result);
            
            My_Disconnect_DB($conn);

    }
}


if(isset($_POST["logoff"]))
{
	session_unset();
    session_destroy();
    echo "You have successfully logged off.<br/>";
    echo "Click <a href='Activity-10-27-1.php'>here</a> to go back to homepage.<br/>";
}

function Show_Editable_Result($result)
{
	echo "<h2>As the boss, you can modify the following information as you will.</h2>";
    echo "<hr/>";
    echo "<form method = 'post' action='".$_SERVER['PHP_SELF']."'>";
    echo "<table border=1>";
    echo "<tr><th>id</th><th>name</th><th>salary</th><th>bonus</th>
    					<th>email</th><th>photo</th><th>remove</th></tr>";
    while($row = mysqli_fetch_row($result))
    {
    	echo "<tr>";
        	echo "<td><input type=hidden name=id[] value='".$row[0]."'>".$row[0]."</td>";
            echo "<td>".$row[2]."</td>";
        	echo "<td><input type=text name=salary[] value='".$row[3]."'></td>";
        	echo "<td><input type=text name=bonus[] value='".$row[4]."'></td>";
            echo "<td>".$row[6]."</td>";
			echo "<td><img src='".$row[5]."' width=100 height=100></td>";
            echo "<td><a class='confirmLink' href='".$_SERVER['PHP_SELF']."?act=remove&id=".$row[0]."'>Fire him/her</a></td>";
        echo "</tr>";    
    
    }
    echo "</table>";
    echo "<input type = submit name=update value='Update Info'>";
    echo "<input type = submit name=logoff value='Boss Logoff'>";
 	echo "</form>";
    
    
    echo "<script type='text/javascript'>
    var elems = document.getElementsByClassName('confirmLink');
    var confirmIt = function (e) 
    {
        if (!confirm('Really want to delete this test attempt?')) e.preventDefault();
    };
    for (var i = 0, l = elems.length; i < l; i++) {
        elems[i].addEventListener('click', confirmIt, false);
    }
</script>";

}

?>
</body>
</html>

 

Revise this Paste

Your Name: Code Language: