modules/email/edit.php
90ff5748
 <?php
c208bd90
 /*
 This file belongs to the Webinterface of schokokeks.org Hosting
 
 Written 2008-2012 by schokokeks.org Hosting, namely
   Bernd Wurst <bernd@schokokeks.org>
   Hanno Böck <hanno@schokokeks.org>
 
 To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
 
 You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
 http://creativecommons.org/publicdomain/zero/1.0/
 
 Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
 */
90ff5748
 
 require_once('inc/debug.php');
 require_once('inc/security.php');
171c5fec
 require_once('inc/icons.php');
90ff5748
 
 require_once('vmail.php');
 
3000accf
 $section = 'email_vmail';
aa811d39
 require_role(array(ROLE_SYSTEMUSER, ROLE_VMAIL_ACCOUNT));
90ff5748
 
684c6a6c
 $account = empty_account();
da0e59cc
 $id = (isset($_GET['id']) ? (int) $_GET['id'] : 0);
90ff5748
 
 if ($id != 0)
   $account = get_account_details($id);
 
aa811d39
 $accountlogin = false;
 if ($_SESSION['role'] == ROLE_VMAIL_ACCOUNT) {
c12c27e9
   $section = 'email_edit';
aa811d39
   $id = get_vmail_id_by_emailaddr($_SESSION['mailaccount']);
   $account = get_account_details($id, false);
   $accountlogin = true;
   $accountname = filter_input_general($_SESSION['mailaccount']);
 }
 
 
90ff5748
 DEBUG($account);
 if ($id == 0) {
f2550e90
   title("E-Mail-Adresse anlegen");
90ff5748
 }
 else {
aa811d39
   if ($accountlogin) {
     title("Einstellungen für {$accountname}");
   } else {
     title("E-Mail-Adresse bearbeiten");
   }
90ff5748
 }
 
 
f3525141
 $is_autoresponder = is_array($account['autoresponder']) && $account['autoresponder']['valid_from'] != NULL;
83d84151
 $is_forward = (count($account['forwards']) > 0);
 $is_mailbox = ($account['password'] != NULL  ||  $id == 0);
 $numforwards = max(count($account['forwards']), 1);
90ff5748
 
c2fdf5e3
 output("<script type=\"text/javascript\">
   
83d84151
   var numForwards = {$numforwards};
171c5fec
   var forwardsCounter = {$numforwards};
c2fdf5e3
 
   function moreForward()
   {
     numForwards += 1;
171c5fec
     forwardsCounter += 1;
 
     if ( document.getElementById('vmail_forward_' + forwardsCounter) ) {
       document.getElementById('vmail_forward_' + forwardsCounter).style.display = ''
     }
c2fdf5e3
 
4912d233
     P1 = document.createElement('p');
 
     TXT1 = document.createTextNode('Weiterleiten an ');
c2fdf5e3
 
     INPUT = document.createElement('input');
     INPUT.type = 'text';
171c5fec
     INPUT.name = 'forward_to_' + forwardsCounter;
     INPUT.id = 'forward_to_' + forwardsCounter;
c2fdf5e3
     INPUT.value = '';
 
4912d233
     P1.appendChild(TXT1);
     P1.appendChild(INPUT);
 
     P2 = document.createElement('p');
 
     TXT2 = document.createTextNode('Spam-Mails an diese Adresse ');
 
c2fdf5e3
     SELECT = document.createElement('select');
171c5fec
     SELECT.id = 'spamfilter_action_' + forwardsCounter;
     SELECT.name = 'spamfilter_action_' + forwardsCounter;
c2fdf5e3
 
caf209e2
     SELECT.options[0] = new Option('nicht filtern', 'none', 1);
13eb3efd
     SELECT.options[1] = new Option('markieren und zustellen', 'tag', 0);
c2fdf5e3
     SELECT.options[2] = new Option('nicht zustellen', 'delete', 0);
 
4912d233
     P2.appendChild(TXT2);
     P2.appendChild(SELECT);
 
     DIV = document.createElement('div');
     DIV.className = 'vmail-forward';
171c5fec
     DIV.id = 'vmail_forward_' + forwardsCounter;
 
     DELETE = document.getElementById('vmail_forward_1').getElementsByTagName('div')[0].cloneNode(true);
c2fdf5e3
 
171c5fec
     DIV.appendChild(DELETE);
4912d233
     DIV.appendChild(P1);
     DIV.appendChild(P2);
c2fdf5e3
 
171c5fec
     parent = document.getElementById('forward_entries');
4912d233
     parent.appendChild(DIV);
c2fdf5e3
   }
5f53b473
 
171c5fec
   function removeForward(elem) 
   {
     div_id = elem.parentNode.parentNode.id;
     div = document.getElementById(div_id);
     input = div.getElementsByTagName('input')[0];
     input.value = '';
     select = div.getElementsByTagName('select')[0];
     select.options[0].selected = 'selected';
     if (numForwards >= 1) {
       numForwards -= 1;
     }
     if (numForwards >= 1) {
       div.style.display = 'none';
       document.getElementById('forward_entries').removeChild(div);
     }
   }
 
5f53b473
   function toggleDisplay(checkbox_id, item_id) 
   {
     if (document.getElementById(checkbox_id).checked == true) {
       document.getElementById(item_id).style.display = 'block';
     } else {
       document.getElementById(item_id).style.display = 'none';
     }
   }
 
c2fdf5e3
 </script>
 ");
90ff5748
 
aa811d39
 $form = '';
90ff5748
 
aa811d39
 if ($accountlogin) {
   $form.= "<p class=\"spamfilter_options\">Unerwünschte E-Mails (Spam, Viren) in diesem Postfach ".html_select('spamfilter_action', array("none" => 'nicht filtern', "folder" => 'in Unterordner »Spam« ablegen', "tag" => 'markieren und zustellen', "delete" => 'nicht zustellen (löschen)'), $account['spamfilter'])."</p>";
 } else {
   $form .= "
     <p><strong>E-Mail-Adresse:</strong>&#160;<input type=\"text\" name=\"local\" id=\"local\" size=\"10\" value=\"{$account['local']}\" /><strong style=\"font-size: 1.5em;\">&#160;@&#160;</strong>".domainselect($account['domain'])."</p>";
90ff5748
 
aa811d39
   $password_message = '';
   $password_value = '';
   if ($is_mailbox and ($account['password'] != ''))
   {
     $password_message = '<span style="font-size: 80%"><br /><em>Sie haben bereits ein Passwort gesetzt. Wenn Sie dieses Feld nicht ändern, wird das bisherige Passwort beibehalten.</em></span>';
     $password_value = '**********';
   } 
   
   $form .= "
5f53b473
     <p><input onchange=\"toggleDisplay('mailbox', 'mailbox_options')\" type=\"checkbox\" id=\"mailbox\" name=\"mailbox\" value=\"yes\" ".($is_mailbox ? 'checked="checked" ' : '')." /><label for=\"mailbox\">&#160;<strong>In Mailbox speichern</strong></label></p>
     <div style=\"margin-left: 2em;".($is_mailbox ? '' : ' display: none;')."\" id=\"mailbox_options\">
     <p>Passwort für Abruf:&#160;<input type=\"password\" id=\"password\" name=\"password\" value=\"{$password_value}\" />{$password_message}</p>";
c2fdf5e3
 
aa811d39
   $form.= "<p class=\"spamfilter_options\">Unerwünschte E-Mails (Spam, Viren) in diesem Postfach ".html_select('spamfilter_action', array("none" => 'nicht filtern', "folder" => 'in Unterordner »Spam« ablegen', "tag" => 'markieren und zustellen', "delete" => 'nicht zustellen (löschen)'), $account['spamfilter'])."</p>";
67d3ffab
 
aa811d39
   $quota = config('vmail_basequota');
   if ($is_mailbox and $account['quota']) {
     $quota = $account['quota'];
   }
   $form .= "<p class=\"quota_options\">Größe des Postfachs: <input type=\"text\" id=\"quota\" name=\"quota\" value=\"{$quota}\" /> MB<br /><span style=\"font-size: 80%\"><em>Hinweis: Die Differenz zwischen dem hier gesetzten Wert und dem Sockelbetrag von ".config('vmail_basequota')." MB wird vom Speicherplatz Ihres Benutzer-Kontos abgezogen.</em></span></p>";
5f53b473
 
aa811d39
   $quota_notify = ($account['quota_threshold'] >= 0) ? ' checked="checked" ' : '';
   $quota_threshold = ($account['quota_threshold'] >= 0) ? $account['quota_threshold'] : '';
   $form .= "<p class=\"quota_options\"><input type=\"checkbox\" id=\"quota_notify\" name=\"quota_notify\" value=\"1\" {$quota_notify} /><label for=\"quota_notify\">Benachrichtigung wenn weniger als</label> <input type=\"text\" name=\"quota_threshold\" id=\"quota_threshold\" value=\"{$quota_threshold}\" /> MB Speicherplatz zur Verfügung stehen.</p>";
5f53b473
 
aa811d39
   $form .= "</div>";
 }
5f53b473
 
67d3ffab
 
 
5f53b473
 $form .= "<p><input onchange=\"toggleDisplay('autoresponder', 'autoresponder_config')\" type=\"checkbox\" id=\"autoresponder\" name=\"autoresponder\" value=\"yes\" ".($is_autoresponder ? 'checked="checked" ' : '')." /><label for=\"autoresponder\">&#160;<strong>Automatische Antwort versenden</strong></label></p>";
c2fdf5e3
 
5f53b473
 $form .= "<div style=\"margin-left: 2em;".($is_autoresponder ? '' : ' display: none;')."\" id=\"autoresponder_config\">";
 
 $ar = $account['autoresponder'];
 if (! $ar) {
   $ar = empty_autoresponder_config();
 }
 
 if ($ar['valid_until'] != NULL && $ar['valid_until'] < date('Y-m-d')) {
   // Daten sind Restbestand von einem früheren Einsatz des Autoresponders
   $ar['valid_from'] = NULL;
   $ar['valid_until'] = NULL;
 }
 $valid_from_now_checked = ($ar['valid_from'] <= date('Y-m-d H:i:s') || $ar['valid_from'] == NULL) ? ' checked="checked"' : '';
 $valid_from_future_checked = ($ar['valid_from'] > date('Y-m-d H:i:s')) ? ' checked="checked"' : '';
 $startdate = $ar['valid_from'];
65aab10c
 if (! $startdate || $startdate <= date('Y-m-d')) {
5f53b473
   $startdate = date('Y-m-d', time() + 1*24*60*60);
 }
 $form .= "<p><input type=\"radio\" name=\"ar_valid_from\" value=\"now\" id=\"ar_valid_from_now\"{$valid_from_now_checked} /> <label for=\"ar_valid_from_now\">Ab sofort</label><br />".
   "<input type=\"radio\" name=\"ar_valid_from\" value=\"future\" id=\"ar_valid_from_future\"{$valid_from_future_checked} /> <label for=\"ar_valid_from_future\">Erst ab dem </label>".
   html_datepicker("ar_valid_from", strtotime($startdate))."</p>";
 
 $valid_until_infinity_checked = ($ar['valid_until'] == NULL) ? ' checked="checked"' : '';
 $valid_until_date_checked = ($ar['valid_until'] != NULL) ? ' checked="checked"' : '';
 $enddate = $ar['valid_until'];
 if (! $enddate) {
   $enddate = date('Y-m-d', time() + 7*24*60*60);
 }
 $form .= "<h4>Deaktivierung</h4>";
 $form .= "<p><input type=\"radio\" name=\"ar_valid_until\" value=\"infinity\" id=\"ar_valid_until_infinity\"{$valid_until_infinity_checked} /> <label for=\"ar_valid_until_infinity\">Unbefristet</label><br />".
   "<input type=\"radio\" name=\"ar_valid_until\" value=\"date\" id=\"ar_valid_until_date\"{$valid_until_date_checked} /> <label for=\"ar_valid_until_date\">Keine Antworten mehr versenden ab dem </label>".
   html_datepicker("ar_valid_until", strtotime($enddate))."</p>";
 
 
 $subject = $ar['subject'];
 if ($subject == NULL)
   $subject = '';
 $ar_subject_default_checked = ($subject == NULL) ? ' checked="checked"' : '';
 $ar_subject_custom_checked = ($subject) ? ' checked="checked"' : '';
 $form .= "<h4>Betreffzeile der automatischen Antwort</h4>".
   "<p><input type=\"radio\" name=\"ar_subject\" value=\"default\" id=\"ar_subject_default\"{$ar_subject_default_checked} /> ".
   "<label for=\"ar_subject_default\">Automatisch (Re: <em>&lt;Betreff der Originalnachricht&gt;</em>)</label><br />".
   "<input type=\"radio\" name=\"ar_subject\" value=\"custom\" id=\"ar_subject_custom\"{$ar_subject_custom_checked} /> ".
   "<label for=\"ar_subject_custom\">Anderer Betreff:</label> <input type=\"text\" name=\"ar_subject_value\" id=\"ar_subject_value\" value=\"{$subject}\"/></p>";
 
 $message = $ar['message'];
 $form .= "<h4>Inhalt der automatischen Antwort</h4>".
   "<p><textarea cols=\"80\" rows=\"10\" name=\"ar_message\" id=\"ar_message\">".$ar['message']."</textarea></p>";
 $quote = $ar['quote'];
 if (! $quote) 
   $quote = 'none';
 $form .= "<p><label for=\"ar_quote\">Originalnachricht des Absenders </label>".
   html_select('ar_quote', array("none" => 'nicht in Antwort einschließen', 
                                 "inline" => 'zitieren (max. 50 Zeilen)', 
                                 "attach" => 'vollständig als Anhang beifügen'), $quote)."</p>";
 
 
 $ar_from_default_checked = ($ar['fromname'] == NULL) ? ' checked="checked"' : '';
 $ar_from_custom_checked = ($ar['fromname'] != NULL) ? ' checked="checked"' : '';
 $fromname = $ar['fromname'];
 $form .= "<h4>Absender der automatischen Antwort</h4>".
   "<p><input type=\"radio\" name=\"ar_from\" value=\"default\" id=\"ar_from_default\"{$ar_from_default_checked} /> <label for=\"ar_from_default\">Nur E-Mail-Adresse</label><br />".
   "<input type=\"radio\" name=\"ar_from\" value=\"custom\" id=\"ar_from_custom\"{$ar_from_custom_checked} /> <label for=\"ar_from_custom\">Mit Name: </label> ".
   "<input type=\"text\" name=\"ar_fromname\" id=\"ar_fromname\" value=\"{$fromname}\"/></p>";
4912d233
 
5f53b473
 
 
 
 $form .= '</div>';
 
 
 
 
 
 $form .= "<p><input onchange=\"toggleDisplay('forward', 'forward_config')\" type=\"checkbox\" id=\"forward\" name=\"forward\" value=\"yes\" ".($is_forward ? 'checked="checked" ' : '')." /><label for=\"forward\">&#160;<strong>Weiterleitung an andere E-Mail-Adressen</strong></label></p>";
 
 
 $form .= "<div style=\"margin-left: 2em;".($is_forward ? '' : ' display: none;')."\" id=\"forward_config\">";
c2fdf5e3
 
171c5fec
 $form .= '<div id="forward_entries">
 ';
 if (! isset($account['forwards'][0])) {
   $account['forwards'][0] = array('destination' => '', 'spamfilter' => 'none');
83d84151
 }
171c5fec
 for ($i = 0 ; $i < $numforwards ; $i++)
83d84151
 {
171c5fec
   $num = $i+1;
   $form .= "<div class=\"vmail-forward\" id=\"vmail_forward_{$num}\">
   <div style=\"float: right;\"><a href=\"#\" onclick=\"removeForward(this);\">".icon_delete("Diese Weiterleitung entfernen")."</a></div>
   <p>Weiterleiten an <input type=\"text\" id=\"forward_to_{$num}\" name=\"forward_to_{$num}\" value=\"{$account['forwards'][$i]['destination']}\" /></p>
   <p>Spam-Mails an diese Adresse ".html_select('spamfilter_action_'.$num, array("none" => 'nicht filtern', "tag" => 'markieren und zustellen', "delete" => 'nicht zustellen'), $account['forwards'][$i]['spamfilter'])."</p>
   </div>\n";
83d84151
 }
171c5fec
 $form .= '</div>';
83d84151
 
171c5fec
 $form .= '<p><a href="#" onclick="moreForward();">'.icon_add().' Weiteren Empfänger hinzufügen</a></p>
5f53b473
 </div>';
4912d233
 
5f53b473
 $form .= '<p><input type="submit" value="Speichern" />&#160;&#160;&#160;&#160;'.internal_link('vmail', 'Abbrechen').'</p>';
90ff5748
 
63a0529b
 output(html_form('vmail_edit_mailbox', 'save', 'action=edit'.($id != 0 ? '&id='.$id : ''), $form));
90ff5748
 
 
 ?>