<?php
/*
	File     : adminAdmins.php
	Version  : 0.2.1 Beta
	Copyright: Attila Soki 2001
	e-mail   : atiware@gmx.net
	Date     : 2001-05-12
*/

	if (strlen($erase)>0) {
		$erase=true;
	}
	if (strlen($sure)>0) {
		$sure=true;
	}
	if (strlen($notsure)>0) {
		$notsure=true;
	}

	if (strlen($cancel)>0) {
		header("Location: adminMenu.php");
		printf('<a href="adminMenu.php">Your browser does not support Header:Location tag. Please CLICK HERE to continue</a>');
		die;
	}
	if (strlen($create)>0) {
		header("Location: adminAdminsEdit.php");
		printf('<a href="adminAdminsEdit.php">Your browser does not support Header:Location tag. Please CLICK HERE to continue</a>');
		die;
	}
	/*
	if ($notsure) {
		header("Location: adminAdmins.php");
		printf('<a href="adminAdmins.php">Your browser does not support Header:Location tag. Please CLICK HERE to continue</a>');
		die;
	}
	*/
	include_once("checkLogin.inc.php");
	if (!$login->isRoot())
		$rights=false;
	else
		$rights=true;

	if (($sure) && ($rights)) {
		$dbo=new MySql();
		$dbo->query("select Id from ".MMCADMINSTABLE."");
		if ($dbo->numRows()) {
			while ($mr=$dbo->fetchArray()) {
				if ((DEMOMODE) && ($mr["Id"]==1))
					continue; //in demomode can't delete admin 1
				if ((int)$MMCADMINID==$mr["Id"])
					continue; //you can't delete yourself (lamer protection)
				$cbname="cb".$mr["Id"];
				if ((int)$$cbname) {
					$admin=new Admin($mr["Id"]);
					$admin->kill();
				}
			}
			$dbo->freeResult();
		}
		$dbo->close();
	}
	if ($erase)
		$modifyhead="&nbsp;";
	else
		$modifyhead="Modify";
	require("head.inc.php");
?>
  <tr> 
    <td colspan="2" align="left" valign="top">
<?php
	if ($rights) {
?>
      <form method="post" action="adminAdmins.php" name="form1" ENCTYPE="multipart/form-data">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr> 
            <td colspan="4" bgcolor="#0099CC"> 
              <div align="center"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Administrators</font></b></div>
            </td>
          </tr>
          <tr> 
            <td bgcolor="#FFFFCC"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Name</font></b></td>
            <td bgcolor="#FFFFCC"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">E-mail</font></b></td>
            <td bgcolor="#FFFFCC"> 
              <div align="center"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><?php echo $modifyhead ?></font></b></div>
            </td>
            <td bgcolor="#FFFFCC"> 
              <div align="center"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Delete</font></b></div>
            </td>
          </tr>
<?php
	$dbo=new MySql();
	$dbo->query("select Id from ".MMCADMINSTABLE."");
	if ($dbo->numRows()) {
		$invert=-1;
		while ($mr=$dbo->fetchArray()) {
			$admin=new Admin($mr["Id"]);
			$cbname="cb".$mr["Id"];
			if ((!(int)$$cbname) && ($erase))
				continue;
			if ((int)$$cbname)
				$checked=" checked";
			else
				$checked="";
			if ($invert>0)
				$bg=' bgcolor="#F2F2E0"';
			else
				$bg="";
			if ((DEMOMODE) && ($mr["Id"]==1))
				$note=" <i>(In demo mode you can't edit or delete this admin!)</i>";
			else
				$note="";
?>
			<tr> 
			<td<?php echo $bg ?>><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><?php echo $admin->getName().$note ?></font></td>
			<td <?php echo $bg ?>><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><a href="mailto:<?php echo $admin->getEmail() ?>"><?php echo $admin->getEmail() ?></a></font></td>
			<td<?php echo $bg ?>> 
<?php
			if (!$erase) {
?>
			<div align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><a href="adminAdminsEdit.php?id=<?php echo $admin->getId() ?>"><img src="images/simnext.gif" width="32" height="32" alt="Modify <?php echo $admin->getName() ?>" border="0"></a></font></div>
<?php
			}
?>
			</td>
			<td<?php echo $bg ?>> 
			<div align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"> 
			<input type="checkbox" name="<?php echo $cbname ?>" value="1"<?php echo $checked ?>>
			</font></div>
			</td>
			</tr>
<?php
			$invert*=-1;
		}
		$dbo->freeResult();
	}
	$dbo->close();
?>
          <tr> 
            <td colspan="4" bgcolor="#FFFFCC"> 
              <div align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font><font face="Verdana, Arial, Helvetica, sans-serif" size="2"> 
<?php
	if (!$erase) {
?>
                <input type="submit" name="create" value="Create new admin">
                <input type="submit" name="cancel" value="Cancel">
                <input type="submit" name="erase" value="Delete selected admins">
<?php
	}
	else {
?>
                <input type="submit" name="notsure" value="Cancel">
                <input type="submit" name="sure" value="I am Sure! Delete selected admins">
<?php
	}
?>
                </font></div>
            </td>
          </tr>
        </table>
      </form>
<?php
	}
	else
		require("norights.inc.php");
?>
    </td>
  </tr>
<?php
	require("foot.inc.php");
?>