<?
########## Confixx(R) 3.0 Professional ############
####### Copyright SWsoft, Inc. 2004-2005 ##########
#### http://www.sw-soft.com - info@sw-soft.com ####

include_once( "../include/class.SQLString.php" );
include_once("auth.php");

db_connect($db_host, $db_user, $db_pass);

$kunde_unsecure = new SQLString($PHP_AUTH_USER);

$id = safe_query( "SELECT COUNT(domain) AS domain FROM domains WHERE kunde = ? AND (richtigedomain=1 OR richtigedomain=0)", TRUE, $kunde_unsecure);
$werte = db_fetch_array($id);
$domains = $werte["domain"];

if ($domains > 0) {
  $id = safe_query( "SELECT count(prefix) AS emails FROM email WHERE kunde = ? ", TRUE, $kunde_unsecure );
  $werte = db_fetch_array($id);
  $emails = $werte["emails"];
  
  $id = safe_query( "SELECT maxemail, maxautoresponder FROM kunden WHERE kunde = ? ", TRUE, $kunde_unsecure );
  $werte = db_fetch_array($id);
  $maxemail = $werte["maxemail"];
  $maxautoresponder = $werte["maxautoresponder"];
  
  $id = safe_query( "SELECT count(account) AS pop FROM pop3 WHERE kunde = ? ", TRUE, $kunde_unsecure );
  $werte = db_fetch_array($id);
  $pop = $werte["pop"];
  
  $id = safe_query( "SELECT count(ident) AS autoresponder FROM autoresponder WHERE kunde = ? ", TRUE, $kunde_unsecure );
  $werte = db_fetch_array($id);
  $autoresponder = $werte["autoresponder"];
}

?>
<HTML>
<HEAD>
<META content="text/html; charset=<? echo $lang_html_charset; ?>" http-equiv=Content-Type>
<LINK href="<?=$strSkinName?>/style.css" rel=stylesheet type=text/css>
</HEAD>

<BODY bgColor=#ffffff bottomMargin=0 leftMargin=0 topMargin=0 MARGINHEIGHT="0" MARGINWIDTH="0">
<br><? include("../fehler.inc.php"); ?>

<? if ($domains > 0) { ?>

<script>
<?
echo js_f_call_help('emem_desc1', 'emem_desc2');
?>
</script>
<? if ($pop > 0 ) { ?>
    <script>
	function doChange()
        {
	    document.forms[0].submit();
        }
	function doChange2()
	{
	    document.forms[1].submit();
	}
    </script>
<? } else { ?>
    <script>
        function doChange()
        {
	    document.forms[0].submit();
	}
	function doChange2()
	{
	    document.forms[0].submit();
	}
    </script>
<? } ?>

<table class="tblbgcolor" align="left" border="1" cellpadding="3" cellspacing="0" bordercolorlight="#CCCCCC" bordercolordark="#FFFFFF">
<tr>
    <td colspan=4>

    <? 
    if ($emails > 0) { 
	echo ltext("emem_desc3", array($emails, sinnv_intwert($maxemail, ltext("g_nolimit")))); 	
    } else { 
	echo ltext("emem_noemail"); 
    } 
    ?>

    <table  border="1" cellpadding="3" cellspacing="0" bordercolorlight="#CCCCCC" bordercolordark="#FFFFFF">

    <? if ($pop > 0) { ?>
    
    <tr>
	<form method="post" action="email_email_anlegen.php">
	    <tr>
		<td colspan=4  class="titel-3" >
		    <? echo ltext("emem_subtitle2"); ?> 
		</td>
	    </tr>
    	    <tr>
    		<td class="titel-3" >
		    <? echo ltext("emem_cell_newmail"); ?>
		</td>
                <td colspan=3 class="titel-3" >
		    <? echo ltext("emem_cell_pop3"); ?>
	        </td>
    	    </tr>
    	    <tr> 
    		<td> 
        	    <input type="text" name="prefix" maxlength="50" size="10">
                    @ 
                    <select name="domain">
                    <?
			$id = safe_query( "select domain from domains where kunde = ?  and (richtigedomain = '1' or richtigedomain='0') order by domain", TRUE, new SQLString( $PHP_AUTH_USER ) );
			while ($werte = db_fetch_array($id)) {
			    $domain = $werte["domain"];
			    if (!ereg("^\*\.", $domain)) {
				echo '<option value="'.$domain.'">'.$domain.'</option>'; 
			    }
			}
		    ?> 
            	    </select>
    		</td>
        	<td colspan=3>
        	    <select name="pop3">
            	    <?
			$id = safe_query( "select account, kommentar from pop3 where kunde = ?  order by number", TRUE, new SQLString( $PHP_AUTH_USER ) );
			while ($werte = db_fetch_array($id)) {
			    $account = $werte["account"];
			    $comment = $werte["kommentar"];
			    $comment = sub_comment($comment,10);
			    echo '<option value="'.$account.'">'.$account.$comment.'</option>';
			}
		    ?> 
            	    </select>
    		</td>
	    </tr>
    	    <tr> 
        	<td>&nbsp; </td>
        	<td colspan=3>
		    <? echo std_button(ltext('emem_btn_add'), 'javascript:doChange()') ?>
		</td>
    	    </tr>
	</form>
    </tr>

    <? } ?>

    <tr>
        <form method="post" action="email_email_anlegen2.php">
	    <tr>
		<td colspan=4 class="titel-3" >
		    <? echo ltext("emem_subtitle3"); ?>
	        </td>
	    </tr>
	    <tr> 
    		<td colspan=1 class="titel-3" >
		    <? echo ltext("emem_cell_newmail"); ?>
		</td>
        	<td colspan=3 class="titel-3" >
		    <? echo ltext("emem_cell_alias"); ?>
		</td>
    	    </tr>
    	    <tr> 
    		<td> 
        	    <input type="text" name="prefix" maxlength="50" size="10">
            	    @ 
            	    <select name="domain">
            	    <?
			$id = safe_query( "select domain from domains where kunde = ?  and (richtigedomain = '1' or richtigedomain='0') order by domain", TRUE, new SQLString( $PHP_AUTH_USER ) );
			while ($werte = db_fetch_array($id)) {
			    $domain = $werte["domain"];
			    if (! ereg("^\*\.", $domain)) {
				echo '<option value="'.$domain.'">'.$domain.'</option>'; 
			    }
			}
		    ?> 
            	    </select>
    		</td>
        	<td colspan=3> 
        	    <input type="text" name="pop3" maxlength="120">
        	</td>
    	    </tr>
    	    <tr> 
    		<td>&nbsp;</td> 
        	<td colspan=3>
		    <? echo std_button(ltext('emem_btn_add'), 'javascript:doChange2()') ?>
		</td>
	    </tr>
	</form>
    </tr>

    <? if ($emails > 0) { ?>

    <tr>
	<td  colspan=4 class="titel-3" >
	    <? echo ltext("emem_subtitle1"); ?>
	</td>
    </tr>
    <tr>
        <td class="titel-3" >
	    <? echo ltext("emem_cell_email"); ?>
	</td>
	<td class="titel-3" >
	    <? echo ltext("emem_cell_to"); ?>
	</td>
	<td class="titel-3" >
	    <? echo ltext("emem_cell_recipient"); ?>
	</td>
	<td class="titel-3" >
	    <? echo ltext("emem_cell_action"); ?>
	</td>
    </tr>

	<? $id = safe_query( "select * from email where kunde = ?  order by prefix, domain", TRUE, new SQLString( $PHP_AUTH_USER ) );
	    while ($werte = db_fetch_array($id)) {
		$emailadresse = $werte["prefix"]."@".$werte["domain"];
		$ziel = $werte["pop3"];
		$comment = get_comment($ziel);
		$comment = sub_comment($comment,15);
		$ident = $werte["ident"];
	?>

	<tr>
	    <td>
		<? echo $emailadresse; ?>
	    </td>
	    <td>
		<? echo $ziel.$comment; ?>
	    </td>
	    <td>
		<a class=data href="email_email_bearbeiten.php?ident=<? echo $ident; ?>">
		    <? echo ltext("emem_link_edit"); ?>
		</a>
	    </td>
	    <td>
		<a class=data href="email_email_loeschen.php?ident=<? echo $ident; ?>">
		    <? echo ltext("emem_link_del"); ?>
		</a>
	    </td>
	</tr>
    <?
	 } 
    } 
    ?>
    </table>

    </td>
</tr>
</table>

<? } else { ?>

<table class="tblbgcolor" align="left" border="1" cellpadding="3" cellspacing="0" bordercolorlight="#CCCCCC" bordercolordark="#FFFFFF">
<tr>
    <td colspan=4>
	  <? echo ltext("emem_nodomain"); ?>
	</td>
</tr>
</table>
<? } ?>

</BODY>
</HTML>
<?
db_close();
?>
