<?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");
if($_POST['action'] == "NewAdmin"){
$password = $_POST['password'];
$name = $_POST['teacher_name'];
$encryptedpass = crypt($password);
$filename="/home/stonewal/chem/.htpasswd";
$line = $_POST['teacher_name'].':'.$encryptedpass.'
';
// 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, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $line) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote the password";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
$sql = "INSERT INTO students
(name,student_id,is_teacher,teacher_name,email)
VALUES
(\"\",\"\",\"1\",\"".$_POST['teacher_name']."\",\"".$_POST['email']."\")";
$result = @mysql_query($sql, $connection) or die("Error #". mysql_errno() . ": " . mysql_error());
}
?>
<!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>Add a new teacher/administrator</h2>
<form action = "newadmin.php" method = "post">
<table><tr><th>Name</th><th>E-mail</th><th>Password</th></tr>
<tr>
<td><input type="text" name="teacher_name" /></td>
<td><input type="text" name="email" /></td>
<td><input type="password" name="password" /></td>
</tr>
</table>
<p> <input type = "hidden" name = "action" value = "NewAdmin" /><input type="submit" name="Add new Admin" value="Add new Admin" /></p>
</form>
</td>
</tr>
</table>
<?php include("../footer.inc.php"); ?>
</body>
</html>