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

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

db_connect($db_host, $db_user, $db_pass);
if (istleer($ident))
	{
	 header("Location: ./email_autoresponder.php");
	}

$id = safe_query( "select admin.email as email, kunden.maxemail as maxemail, kunden.maxautoresponder from admin, kunden where kunden.kunde = ? ", TRUE, new SQLString( $PHP_AUTH_USER ) );
$werte = db_fetch_array($id);
$maxautoresponder = $werte["maxautoresponder"];
if (($werte["email"] == 0) || ($werte["maxemail"] == 0))
	{
	 $id = safe_query( "select count(kunde) as email from email where kunde = ? ", TRUE, new SQLString( $PHP_AUTH_USER ) );
	 $werte = db_fetch_array($id);
	 if ($werte["email"] == 0)
		{
		 $id = safe_query( "select count(kunde) as pop3 from pop3 where kunde = ? ", TRUE, new SQLString( $PHP_AUTH_USER ) );
		 $werte = db_fetch_array($id);
		 if ($werte["pop3"] == 0)
			{
			 db_close();
			 header("Location: ./noemail.php");
			}
		}
	}
$id = safe_query( "select prefix, domain from email where ident = ?  and kunde = ? ", TRUE, new SQLInteger( $ident ), new SQLString( $PHP_AUTH_USER ) );
$werte = db_fetch_array($id);
$emailadresse = $werte["prefix"]."@".$werte["domain"];
$emailadresse2 = $emailadresse;
if ($emailadresse == "@")
	{
	 header("Location: ./email_autoresponder.php");
	}

if ($ausdb != "nein")
	{
	 $id = safe_query( "select * from autoresponder where ident = ? ", TRUE, new SQLInteger( $ident ) );
	 while ($werte = db_fetch_array($id))
		{
		 $bearbeiten = 1;
		 $emailtext = $werte["emailtext"];
		 $emailbetreff = $werte["emailbetreff"];
		 $absenderemail = $werte["absenderemail"];
		 $absendername = $werte["absendername"];
		}
	}

	 $id = safe_query( "select count(ident) as autoresponder from autoresponder where kunde = ? ", TRUE, new SQLString( $PHP_AUTH_USER ) );
	 $werte = db_fetch_array($id);
	 $autoresponder = $werte["autoresponder"];

if (($bearbeiten != 1) && ($autoresponder >= $maxautoresponder) && ($maxautoresponder != "-1"))
	{ 
	 $fehlertext = ltext("emau2_error1");
	 db_close();
	 include("email_autoresponder.php");
	 exit();
	}
?>
<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"); ?>
<script>
<?
echo js_f_call_help('emau2_desc1', 'emau2_desc2');
?>
function doChange2()
{
document.forms[1].submit();
}
function doChange()
{
document.forms[0].submit();
}
</script>
<table class="tblbgcolor" align="left" border="1" cellpadding="3" cellspacing="0" bordercolorlight="#CCCCCC" bordercolordark="#FFFFFF">
      <form action="email_autoresponder3.php" method="post" name="autoresp">
        <tr > 
          <td colspan="2" class="titel-3" ><? echo ltext("emau2_cell_title"); ?> <? echo $emailadresse; if ($bearbeiten == 1) { echo " ".ltext("emau2_cell_title_text1"); } else { echo " ".ltext("emau2_cell_title_text2");  }?></td>
        </tr>
        <tr > 
          <td ><? echo ltext("emau2_cell_subject"); ?></td>
          <td  > 
            <input type="text" name="emailbetreff" size="62" value="<? echo htmlspecialchars($emailbetreff); ?>">
          </td>
        </tr>
        <tr > 
          <td ><? echo ltext("emau2_cell_text"); ?></td>
          <td  >
            <textarea name="emailtext" cols="60" rows="8"><? echo htmlspecialchars($emailtext); ?></textarea>
          </td>
        </tr>
        <tr >
          <td ><? echo ltext("emau2_cell_sender1"); ?></td>
          <td  > 
            <select name="absenderemail">
              <?
$id = safe_query( "select prefix, domain, ident from email where kunde = ?  and prefix not like '%*%'", TRUE, new SQLString( $PHP_AUTH_USER ) );
while ($werte = db_fetch_array($id))
	{
	 $emailadresse = $werte["prefix"]."@".$werte["domain"];
	 $ident2 = $werte["ident"];
	 if ($bearbeiten != 1)
		{
?>
              <option value="<? echo $emailadresse; ?>"<? if ($ident2 == $ident) { echo " selected"; } ?>><? echo $emailadresse; ?></option>
<?
		} else
		{
?>
              <option value="<? echo $emailadresse; ?>"<? if ($emailadresse == $absenderemail) { echo " selected"; } ?>><? echo $emailadresse; ?></option>
<?
		}
	}
?>
            </select>
            </td>
        </tr>
        <tr > 
          <td><? echo ltext("emau2_cell_sender2"); ?></td>
          <td> 
            <input type="text" name="absendername" value="<? echo htmlspecialchars($absendername); ?>">
            </td>
        </tr>
        <tr >
          <td >
            <input type="hidden" name="ident" value="<? echo $ident; ?>">&nbsp;
            <input type="hidden" name="bearbeiten" value="<? echo $bearbeiten; ?>">
          </td>
          <td><? echo std_button(($bearbeiten == 1)?ltext("emau2_btn_save"):ltext("emau2_btn_new"), 'javascript:doChange()') ?></td>
        </tr>
     </form>
	<? if ($bearbeiten == 1) { ?>
	<form action="email_autoresponder_loeschen.php" method="post" name="loeschen">
        <tr>
          <td colspan=2 class="titel-3" ><? echo ltext("emau2_cell_title2", array($emailadresse2)); ?></td>
        </tr>
        <tr>
          <td colspan=2><? echo std_button(ltext('emau2_btn_del'), 'javascript:doChange2()') ?><input type="hidden" name="ident" value="<? echo $ident; ?>"></td>
        </tr>
      </table></form>
	<? } ?>
</td>
  </tr>
</table>
</BODY>
</HTML>

<?
db_close();
?>
