<!DOCTYPE html SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>RefDB admin interface</title>
        <link href="refdbqxhtml.css" type="text/css" rel="stylesheet"/>
    </head>
    <body>
	  <h1>RefDB admin interface</h1>
       <div class="navigation">
            <h2>Navigation</h2>
            <ul class="navigationMenu">
                 <li>
                    <a href="index.html">Login screen</a>
                </li>
                <li>
                    <a href="refdbquery.html">Search references</a>
                </li>
                <li>
                    <a href="refdbkajquery.html">Search keywords, authors, journals</a>
                </li>
                <li>
                    <a href="refdbadd.html">Add new references</a>
                </li>
                <li>
                    <a href="refdbdbquery.php">Change database</a>
                </li>
                <li>
                    <a href="external.php">Search external database</a>
                </li>
                <li>
                    <a href="refdbadmin.php">Administrative Interface</a>
                </li>
                <li>
                    <a href="refdblogout.php">Logout</a>
                </li>
            </ul>
        </div>
    <div class="content">
	  <?
	  	$name = $_SESSION["name"];
		$passwd = $_SESSION["passwd"];
		$database = $_SESSION["database"];
	  ?>
	  	<form action="admin.php" method="post" enctype="multipart/form-data">

		<!-- ***************************** ADD USER ********************************  -->
		<h2>Add user</h2>
		<p>Username: <input type="text" name="user" size="30"/></p>
		<p>Password: <input type="password" name="passwd" size="30"/></p>
		<p>Confirm password: <input type="password" name="passwdcfm" size="30"/></p>
		<p>Database: <select name="adduserdb">
			<option value='' selected> -- </option>
	  <?
	  	//command to list the databases available
		$refdba = $_SESSION["refdba"];
		$listdb = "$refdba -u $name -w $passwd -c stdout -C listdb";
		exec($listdb, $dblines);
		foreach($dblines as $dbline)
		{
			print "<option value='$dbline'>$dbline</option>\n";
		}
	  ?>
	  	</select></p>
		<p><input type="submit" name="submit" value="Add user"/></p>
	 	<hr>
		
		<!-- **************************** REMOVE USER ***************************** -->
		<h2>Remove user</h2>
		<!--Utilize javascript to refresh the page with the new data based on the selection of a database -->
		<p>From database: <select name="rmuserdb" onchange="window.location=('refdbadmin.php?dbselected=true&db='+this.options[this.selectedIndex].value)">

		<?
			//If a database hasn't been selected select the blank entry
			print "<option value=' '";
			if( !isset($dbselected ) )
			{
				print " selected";
			}
			print "> -- </option>\n";
			
			foreach($dblines as $dbline)
			{
				//once a database has been selected select that database
				print "<option value='$dbline'";
				if( isset($dbselected) && $db == $dbline )
				{
					print " selected";
				}
				print ">$dbline</option>\n";
			}
		?>
		</select></p>
		<?
			//Display the users for that database
			if(isset($dbselected))
			{
				//command to list users of a specific database
				$refdba = $_SESSION["refdba"];
				$listuser = "$refdba -u $name -w $passwd -c stdout -d $db -C listuser";
				exec($listuser, $userlines);

				//create dropdown for the users
				print "<p>User: <select name='rmuser'>\n";
				foreach($userlines as $userline)
				{
					print "<option value='$userline'>$userline</option>\n";
				}
				print "</select></p>\n";
			}
		?>
		<p><input type="submit" name="submit" value="Remove User"></p>
		
		<!-- ********************************** CREATE DATABASE **************************** -->
		<hr>
		<h2>Create database</h2>
		
		<p>Database name: <input type="text" name="newdb" size="30"/></p>
		<p><input type="submit" name="submit" value="Add database"/></p>

		<!-- ********************************* REMOVE DATABASE ***************************** -->
		<hr>
		<h2>Remove database</h2>
		<p><select name="removedb">
			<option value='' selected> -- </option>

		<?
			//list databases
			foreach($dblines as $dbline)
			{
				print "<option value='$dbline'>$dbline</option>\n";
			}
		?>
		</select></p>
		<p><input type="submit" name="submit" value="Remove database"/></p>

		<!-- ***************************** SCHEDULE A KEYWORD SCAN ************************* -->
		<hr>
		<h2>Schedule a keyword scan</h2>
	  	<p><select name="scandb">
			<option value=' ' selected> -- </option>	
		<?
			foreach($dblines as $dbline)
			{
				print "<option value='$dbline'>$dbline</option>\n";
			}
		?>
		</select></p>
		<p><input type="submit" name="submit" value="Scan database"/></p>


		</form>
	  	  </div>
	          <div class="footer">
            <p><a href="http://refdb.sourceforge.net">RefDB</a> reference manager and bibliography
                tool V. <!--VERSION-->0.9.8-1<!--/VERSION--></p>
        </div>	
  </body>
</html>

