Location: PHPKode > projects > Standardized Test Practice Engine > stpe/admin/users.php
<?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("../dbinit.inc.php");
if($_POST['action'] == "add"){
	$code = substr(md5($_POST['newtopicnum'].$_POST['newsectionnum']."23".$thisnames),0,12);
	$sql = "INSERT INTO users
	(topicnum,topicdesc,sectionnum,sectiondesc,names,code,teachername)
	VALUES
	(\"".$_POST['newtopicnum']."\",\"".$_POST['newtopicdesc']."\",\"".$_POST['newsectionnum']."\",\"".$_POST['newsectiondesc']."\",\"".$_POST['newnames']."\",\"$code\",\"".$_POST['newteachername']."\")";
	$result = @mysql_query($sql, $connection) or die("Error #". mysql_errno() . ": " . mysql_error());

}
if($_POST['action'] == "update"){
	for($x=$_POST['count'];$x>=1;$x--){
		$thistopicnum=$_POST["topicnumnew$x"];
		$thistopicdesc=$_POST["topicdescnew$x"];
		$thissectionnum=$_POST["sectionnumnew$x"];
		$thissectiondesc=$_POST["sectiondescnew$x"];
		$thisnames=$_POST["namesnew$x"];
		$thisteacher=$_POST["teachernamenew$x"];
		$newcode = substr(md5($thistopicnum.$thissectionnum."23".$thisnames),0,12);
		$sql = "UPDATE users SET topicnum='$thistopicnum', topicdesc='$thistopicdesc', sectionnum='$thissectionnum', sectiondesc='$thissectiondesc', names='$thisnames', code='$newcode', teachername='$thisteacher' WHERE id='$x'";
		$result = mysql_query($sql, $connection) or die("Error #". mysql_errno() . ": " . mysql_error());
		mysql_close($connection);
		include("../dbinit.inc.php");
	}


}


$sql = "SELECT * FROM `users` order by id";
$total_result = @mysql_query($sql, $connection) or die("Error #". mysql_errno() . ": " . mysql_error());
$total_found = @mysql_num_rows($total_result);

$x = 0;
while ($row = mysql_fetch_array($total_result)) {
	$id[$x]=$row['id'];
    $topicnum[$x]=$row['topicnum'];
    $topicdesc[$x]=$row['topicdesc'];
    $sectionnum[$x]=$row['sectionnum'];
    $sectiondesc[$x]=$row['sectiondesc'];
    $names[$x]=$row['names'];
    $code[$x]=$row['code'];
    $teachername[$x]=$row['teachername'];
	$x++;
}


?>
<!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>
	<form action="index.php" method="post">
	<p>Current users:
	<input type="hidden" name="action" value="update" /></p>
	<table>
	<tr><th>Topic Number</th><th>Topic Descripsion</th><th>Section Number</th><th>Section Description</th><th>Names</th>
	<th>Code</th></tr>
	<?php
	foreach($id as $key => $thisid){
		echo '<tr><td><input type="text" name="topicnumnew'.$thisid.'" value="'.$topicnum[$key].'" /></td>
		<td><input type="text" name="topicdescnew'.$thisid.'" value="'.$topicdesc[$key].'" /></td>
		<td><input type="text" name="sectionnumnew'.$thisid.'" value="'.$sectionnum[$key].'" /></td>
		<td><input type="text" name="sectiondescnew'.$thisid.'" value="'.$sectiondesc[$key].'" /></td>
		<td><input type="text" name="namesnew'.$thisid.'" value="'.$names[$key].'" /></td>
		<td><input type="text" name="teachernamenew'.$thisid.'" value="'.$teachername[$key].'" /></td>
		';
		echo '<td>'.$code[$key].'</td></tr>';
	}
	echo "</table>";
	echo "<p><input type=\"hidden\" name=\"count\" value=\"$thisid\" />";
	?>
	<input type="submit" name="Update" value="Update" /><input type="reset" /><br /></p></form>
	
	<form action="index.php" method="post">
	<p>Add a new section:
	<input type="hidden" name="action" value="add" /></p>
	<table>
	<tr><th>Topic Number</th><th>Topic Descripsion</th><th>Section Number</th><th>Section Description</th><th>Names</th><th>Teacher Name</th></tr>
	<tr><td><input type="text" name="newtopicnum" /></td><td><input type="text" name="newtopicdesc" /></td><td><input type="text" name="newsectionnum" /></td><td>
	<input type="text" name="newsectiondesc" /></td><td><input type="text" name="newnames" /></td><td><input type="text" name="newteachername" /></tr>
	</table>
	<p><input type="submit" name="Add new" value="Add new" /></p>
	</form>
	
	<p style="text-align: right;"><br />
		  <a href="http://jigsaw.w3.org/css-validator/">
  <img style="border:0;width:88px;height:31px"
       src="http://jigsaw.w3.org/css-validator/images/vcss" 
       alt="Valid CSS!" />
 </a>
      <a href="http://validator.w3.org/check/referer"><img
          src="http://www.w3.org/Icons/valid-xhtml10"
          alt="Valid XHTML 1.0!" height="31" width="88" /></a>
    </p>
    <p>
		<small>
			Fine print: Created by Jonathan Bell and Daniel Perelman. Everything here is the property of Jonathan Bell and Daniel Perelman, 
			except for the subject reviews and quizzes, which are the property of the creators and are credited. Neither Jonathan 
			Bell nor Daniel Perelman can be held responsible for the use or misuse of the information provided on this website. 
			No part of this website may be reproduced without prior written position from Jonathan Bell and Daniel Perelman. 
			"Reproduced" refers to both the code of the site, the database, and the pages created by them. 
			Your use of this information is at your own risk. This site is not recognized, endorsed, or affiliated with the 
			College Board. The use of this site may or may not improve your SAT II chemistry scores.
		</small>
	</p>
</body>
</html>
Return current item: Standardized Test Practice Engine