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

	if (strlen($create)>0) {
		header("Location: adminDomainsEdit.php");
		printf('<a href="adminDomainsEdit.php">Your browser does not support Header:Location tag. Please CLICK HERE to continue</a>');
		die;
	}
	if (strlen($notsure)>0) {
		header("Location: adminDomains.php");
		printf('<a href="adminDomains.php">Your browser does not support Header:Location tag. Please CLICK HERE to continue</a>');
		die;
	}
	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;
	}
	include_once("Domain.class.php");
	include_once("checkLogin.inc.php");
	if (strlen($sure)>0) {
		$dbo=new MySql();
		$dbo->query("select Id from ".MMCDOMAINTABLE."");
		if ($dbo->numRows()) {
			while ($mr=$dbo->fetchArray()) {
				if ((DEMOMODE) && ($mr["Id"]==1))
					continue; //in demo mode you cant delete domain id 1
				$cbname="cb".$mr["Id"];
				if ((($login->haveRightToDomain($mr["Id"])) || ($login->isRoot())) && ((int)$$cbname)) {
					$domain=new Domain($mr["Id"]);
					if ((int)$allusertoo)
						$domain->killall();
					else
						$domain->kill();
				}
			}
			$dbo->freeResult();
		}
		$dbo->close();
	}
	if (strlen($erase)>0) {
		$headmodify="&nbsp;";
		$headdelete="Delete";
		$headline="!! Delete domains !!";
	}
	else {
		$headmodify="Modify";
		$headdelete="Delete";
		$headline="Domain table administration";
	}
	require("head.inc.php");
?>
  <tr> 
    <td colspan="2" align="left" valign="top"> 
      <form method="post" action="adminDomains.php" name="form1" ENCTYPE="multipart/form-data">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr> 
            <td colspan="3" bgcolor="#0099CC"> 
              <div align="center"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><?php echo $headline ?>
              </font></b></div>
            </td>
          </tr>
          <tr bgcolor="#FFFFCC"> 
            <td><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Domain 
              name</font></b></td>
            <td height="32"> 
              <div align="center"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><?php echo $headmodify ?></font></b></div>
            </td>
            <td> 
              <div align="center"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><?php echo $headdelete ?></font></b></div>
            </td>
          </tr>
<?php
	$dbo=new MySql();
	$invert=-1;
	$dbo->query("select Id from ".MMCDOMAINTABLE." order by Domain");
	if ($dbo->numRows()) {
		while ($mr=$dbo->fetchArray()) {
			$domain=new Domain($mr["Id"]);
			if ($invert>0)
				$bgcolor=' bgcolor="#F2F2E0"';
			else
				$bgcolor="";
			if ((!$login->haveRightToDomain($domain->getId())) && (!$login->isRoot())) {
				$right=false;
				continue;
			}
			else
				$right=true;
			$cbname="cb".$mr["Id"];
			if (($erase) && (!(int)$$cbname))
				$show=false; //dont show at this moment
			else
				$show=true;
			if ((DEMOMODE) && ($mr["Id"]==1))
				$note=" <i>(You can't edit or delete this domain in demo mode!)</i>";
			else
				$note="";
			if ($show) {
				printf("<tr%s>\n",$bgcolor);
				printf('<td><font face="Verdana, Arial, Helvetica, sans-serif" size="2">%s</font></td>%s',$domain->getName().$note,"\n");
				printf('<td%s height="32">%s',$bgcolor,"\n"); 
				printf('<div align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">');
				if (($right) && (!$erase)) {
					printf('<a href="adminDomainsEdit.php?id=%s">',$domain->getId());
					printf('<img src="images/simnext.gif" width="32" height="32" alt="Modify %s" vspace="0" hspace="0" border="0">',$domain->getName());
					printf("</a>");
				}
				printf("</font></div>\n");
				printf("</td>\n");
				printf("<td>\n");
				printf('<div align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">%s',"\n");
				if ((int)$$cbname)
					$checked=" checked";
				else
					$checked="";
					printf('<input type="checkbox" name="%s" value="1"%s>%s',$cbname,$checked,"\n");
				printf("</font></div>\n");
				printf("</td>\n");
				printf("</tr>\n");
				$invert*=-1;
			}
		}
		$dbo->freeResult();
	}
	$dbo->close();
	if ($erase) {
?>
          <tr bgcolor="#FF8080">
           <td><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
           Erase all userdata from Exims mailtable with these domains:
           </font></td>
          <td>&nbsp;</td>
          <td><div align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
           <input type="checkbox" name="allusertoo" value="1">
          </div></font></td>
<?
	}
?>
          <tr> 
            <td colspan="3" bgcolor="#FFFFCC" align="center" valign="middle"> 
              <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">
<?php
	if (($login->isRoot()) && (!$erase)) {
?>
                <input type="submit" name="create" value="Create new domain">
<?php
	}
	if (!$erase) {
?>
                <input type="submit" name="cancel" value="Cancel">
                <input type="submit" name="erase" value="Delete selected domains">
<?php
	}
	else {
?>
                <input type="submit" name="notsure" value="Cancel">
                <input type="submit" name="sure" value="Delete domains">
<?php
	}
?>
                </font></div>
            </td>
          </tr>
        </table>
      </form>
    </td>
  </tr>
<?php
	require("foot.inc.php");
?>