<?php
/*
Copyright 2004 by Jonathan Bell and Daniel Perelman
This file is part of STPE - the Standardized Test Practice Engine.
STPE is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
STPE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
include_once("../globals.inc.php");
?>
<?php
include("login.inc.php");
include_once("../dbinit.inc.php");
$sql2 = "SELECT * from `students` WHERE `is_teacher` = 1 order by id ASC";
$total_result = @mysql_query($sql2, $connection) or die("Error #". mysql_errno() . ": " . mysql_error());
$total_found = @mysql_num_rows($total_result);
$x = 0;
while ($row = mysql_fetch_array($total_result)) {
$Nameid[$x]=$row['id'];
$tempid=$Nameid[$x];
$teacher_name[$tempid]=$row['teacher_name'];
$email[$tempid]=$row['email'];
$x++;
}
if($_POST['positive'] == "yes"){
foreach($Nameid as $anid){
$thedelete="delete".$anid;
if($_POST[$thedelete] == "yes"){
$sql = "DELETE FROM `students` WHERE id = $anid";
$total_result = @mysql_query($sql, $connection) or die("Error #". mysql_errno() . ": " . mysql_error());
$delete=$teacher_name[$anid];
$thefile = file($filename);
foreach($thefile as $key => $line){
if(strstr($line,$delete)){
$thefile[$key]="";
}
}
$file=implode($thefile,"");
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'w')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $file) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
fflush($handle);
fclose($handle);
}
else {
echo "The file $filename is not writable";
}
}
}
$thispage = $_SERVER['request_uri'];
header("Location: $thispage");
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title><?php echo $site_name; ?> Admin</title>
<link rel="stylesheet" type="text/css" href="../style.css" />
</head>
<body>
<?php include("../header.inc.php"); ?>
<table>
<tr valign="top">
<?php include("../nav.inc.php"); ?>
<td class="maincontent">
<h2>Delete an administrator</h2>
<p>Obviously to be used with EXTREME caution...</p>
<p><br />Current administrators in the database:</p>
<form action = "deleteadmin.php" method = "post">
<input type = "hidden" name = "action" value = "DeleteAdmin" />
<table><tr><th>Delete?</th><th>Name</th><th>E-mail</th></tr>
<?php
foreach($Nameid as $x => $id){
echo'
<tr>
<td><input type="checkbox" name="delete'.$id.'" value="yes" /></td>
<td>'.$teacher_name[$id].'</td>
<td>'.$email[$id].'</td>
</tr>
';
}
?>
</table>
ARE YOU ABSOLUTELY POSITIVE THAT YOU WANT TO DELETE THE ABOVE ADMINISTRATOR?
THIS CAN NOT BE UNDONE!<br />
Yes, I am SURE!<input type="checkbox" name="positive" value="yes" />
<br /><br />
<input type="reset" /> <input type="submit" />
</td>
</tr>
</table>
<?php include("../footer.inc.php"); ?>
</body>
</html>