Changeset - r5:a570202d2793
[Not reviewed]
v0.2 default
0 3 0
Wolfgang Scherer (ws) - 13 years ago 2012-03-30 16:13:40
wolfgang.scherer@gmx.de
index.php: Umlaut and HTML-escaping fixed. Display enhancement.
lib/util.php: vacation_split/vacation_join functions to centralize the gory details.
Message `Content-Type: text/plain; charset="utf-8"'
and `Content-Transfer-Encoding: quoted-printable' added.
lib/language.php: Add administrator manual headline.
3 files changed with 99 insertions and 20 deletions:
0 comments (0 inline, 0 general)
index.php
Show inline comments
 
@@ -74,24 +74,25 @@ if (!$is_admin) {
 
    }
 
}
 

	
 
// --------------------------------------------------
 
// |||:sec:||| HTML Header
 
// --------------------------------------------------
 

	
 
$title = get_text('title');
 
$css = '
 
span.label {
 
    width: 100px;
 
    display: inline-block;
 
    vertical-align: top;
 
}
 
hr.sep {
 
    width: 550px;
 
    text-align: left;
 
    margin-left: 0;
 
}
 
';
 

	
 
echo substitute_elements(
 
    $HEAD, Array(
 
        'title' => $title,
 
        'css' => $css,
 
@@ -146,81 +147,90 @@ if ($forward_active)
 
    $lines = explode("\n", $forward_settings);
 
    $forward_settings = preg_split('/, */', $lines[0]);
 
    if (count($forward_settings) < 3) {
 
        $forward_settings[2] = $forward_settings[1];
 
        $forward_settings[1] = '';
 
    }
 
}
 
$vacation_forward = $forward_settings[1];
 
$vacation_forward = preg_replace('/^\\\\/', '', $vacation_forward);
 

	
 
if (!file_exists($vacation_msg_file)) {
 
    $vacation_msg = get_text('vacation');
 
    $decode = False;
 
} else {
 
    $vacation_msg = file_get_contents($vacation_msg_file);
 
    $decode = True;
 
}
 

	
 
$lines = explode("\n", $vacation_msg);
 
$vacation_subject = array_shift($lines);
 
$vacation_subject = preg_replace('/^[Ss]ubject: */', '', $vacation_subject);
 
while (True) {
 
    $line = array_shift($lines);
 
    if (empty($line)) {
 
        break;
 
    }
 
}
 
$vacation_body = implode($lines, "\n");
 
// $lines = explode("\n", $vacation_msg);
 
// $vacation_subject = array_shift($lines);
 
// $vacation_subject = preg_replace('/^[Ss]ubject: */', '', $vacation_subject);
 
// $vacation_headers = Array();
 
// // remove additional headers
 
// while (True) {
 
//     $line = array_shift($lines);
 
//     if (empty($line)) {
 
//         break;
 
//     }
 
//     $vacation_headers[] = $line;
 
// }
 
// $vacation_body = implode($lines, "\n");
 

	
 
$vacation_parts = vacation_split($vacation_msg, $decode);
 
$vacation_subject = $vacation_parts[0];
 
$vacation_headers = $vacation_parts[1];
 
$vacation_body = $vacation_parts[2];
 

	
 
// --------------------------------------------------
 
// |||:sec:||| Set vacation(1) parameters
 
// --------------------------------------------------
 

	
 
$vacation_setup = isset($_REQUEST['setzen']);
 
$vacation_clear = isset($_REQUEST['loeschen']);
 
if ($vacation_setup || $vacation_clear) {
 
    $forward_active = isset($_REQUEST['aktiv']);
 
    $vacation_forward = isset($_REQUEST['forward']) ? $_REQUEST['forward'] : '';
 
    if ($vacation_forward == $user) {
 
        $vacation_forward = '';
 
    }
 
    $vacation_subject = isset($_REQUEST['subject']) ? trim($_REQUEST['subject']) : '';
 
    $vacation_body = isset($_REQUEST['body']) ? trim($_REQUEST['body']) : '';
 
    $forward_settings = Array(
 
        '\\'.$user, $vacation_forward,
 
        sprintf($VACATION_FORWARD_ENTRY, $user));
 

	
 
    while (True) {
 
        if ($vacation_clear) {
 
            system(sprintf(
 
                       '%s -u %s %s %s -i',
 
                       $SUDO_CMD, $SUDO_OPT_H, $user, $VACATION_CMD));
 
                       $SUDO_CMD, $user, $SUDO_OPT_H, $VACATION_CMD));
 
            break;
 
        }
 
        if (empty ($vacation_subject)) {
 
            error_msg(get_text('error_no_subject'));
 
            break;
 
        }
 
        // Actually set it
 

	
 
        // If not active, remove "Vertretung"
 
        if (!$forward_active) {
 
            $vacation_forward = '';
 
        }
 
        $forward_settings = Array(
 
            '\\'.$user, $vacation_forward,
 
            sprintf($VACATION_FORWARD_ENTRY, $user));
 

	
 
        // Prepare vacation(1) message
 
        $vacation_msg = sprintf(
 
            "Subject: %s\n\n%s\n", $vacation_subject, $vacation_body);
 
        $vacation_msg = vacation_join($vacation_subject, $vacation_body);
 
        $vacation_msg_pipe = popen(sprintf(
 
                  '%s -u %s %s %s %s',
 
                  $SUDO_CMD, $user, $SUDO_OPT_H, $WRITE_TO_CMD, $vacation_msg_file),
 
            'w');
 
        fwrite($vacation_msg_pipe, $vacation_msg);
 
        pclose($vacation_msg_pipe);
 

	
 
        // Initialize vacation(1) if necessary.
 
        if (!file_exists($vacation_db_file)) {
 
            system(sprintf(
 
                       '%s -u %s %s %s -i',
 
                       $SUDO_CMD, $user, $SUDO_OPT_H, $VACATION_CMD));
 
@@ -260,26 +270,28 @@ if ($vacation_setup || $vacation_clear) 
 
// --------------------------------------------------
 

	
 
$form = Array();
 
//$form[] = '<hr class="sep"/>';
 
$form[] = '<form action="index.php" method="post">';
 

	
 
if ($_debug) {
 
    $form[] = sprintf(
 
        '<input type="hidden" name="_DEBUG_" value="%s" />', $_debug);
 
}
 

	
 
// column names
 
$form[] = '<span class="label"></span>';
 
$form[] = '<span style="display: inline-block;"><table border="0" cellspacing="0" cellpadding="2" style="width: 410px;">';
 
$form[] = '<span class="label">';
 
$form[] = sprintf('<input type="submit" name="holen" value="%s" />', get_text('refresh'));
 
$form[] = '</span>';
 
$form[] = '<span style="display: inline-block;"><table border="0" cellspacing="0" cellpadding="2" style="width: 410px; vertical-align: top;">';
 
$trow = Array();
 
$trow[] = get_text('user');
 
$trow[] = get_text('forward_to');
 
$trow[] = get_text('active');
 
$form[] = sprintf('<tr><th style="text-align: center;">&nbsp;%s&nbsp;</th></tr>', implode($trow, '&nbsp;</th><th style="text-align: center;">&nbsp;'));
 

	
 
$trow = Array();
 

	
 
// user
 
$user_control = Array();
 
if ($is_admin) {
 
    $user_control[] = '<select name="user" />';
 
@@ -328,83 +340,83 @@ if ($forward_active) {
 
}
 
$user_control[] = sprintf('<input type="checkbox" name="aktiv" value="aktiv"%s><br />',
 
                          $active_checked);
 
$user_control = implode($user_control, "\n");
 
$trow[] = $user_control;
 

	
 
$form[] = sprintf('<tr><td style="text-align: center;">%s</td></tr>', implode($trow, '</td><td style="text-align: center;">'));
 
$form[] = '</table></span><br />';
 

	
 
// subject
 
$form[] = sprintf('<span class="label">%s<sup>*</sup>:</span>', get_text('subject'));
 
$form[] = (
 
    '<input type="text" name="subject" value="' . $vacation_subject
 
    '<input type="text" name="subject" value="' . htmlspecialchars($vacation_subject, ENT_COMPAT, "UTF-8")
 
    .'" size="49" /><br />');
 

	
 
// message
 
$form[] = sprintf('<span class="label">%s<sup>*</sup>:</span>', get_text('message'));
 
$form[] = (
 
    '<textarea name="body" cols="56" rows="10"'
 
    .' style="vertical-align: top;">' . $vacation_body . '</textarea><br />');
 
    .' style="vertical-align: top;">' . htmlspecialchars($vacation_body, ENT_NOQUOTES, "UTF-8") . '</textarea><br />');
 

	
 
$form[] = '<span class="label">&nbsp;</span>';
 
$form[] = (
 
    '<span style="display: inline-block; width: 410px;"><sup>*</sup>'
 
    . get_text('explain_subject')
 
    .'</span><br />');
 

	
 
// actions
 
$form[] = '<hr class="sep"/>';
 
$form[] = '<span class="label">&nbsp;</span>';
 
$form[] = sprintf('<input type="submit" name="holen" value="%s" />', get_text('refresh'));
 
$form[] = sprintf('<input type="submit" name="setzen" value="%s" /><br />', get_text('save'));
 
$form[] = '<hr class="sep"/>';
 

	
 
// --------------------------------------------------
 
// |||:sec:||| Vacation History
 
// --------------------------------------------------
 

	
 
$vacation_list_cmd = sprintf(
 
    '%s -u %s %s %s -l', $SUDO_CMD, $user, $SUDO_OPT_H, $VACATION_CMD);
 
// echo ('<pre>'."\n");
 
// echo ($vacation_list_cmd);
 
// echo ('</pre>'."\n");
 
$vacation_ausgabe = popen ($vacation_list_cmd, 'r');
 
$vacation_list = stream_get_contents($vacation_ausgabe);
 
pclose($vacation_ausgabe);
 

	
 
if (!empty ($vacation_list)) {
 
    $form[] = shl(get_text('reply_history'));
 
    $form[] = '<hr class="sep"/>';
 
    // $form[] = '<hr class="sep"/>';
 
    $form[] = '<pre>';
 
    $form[] = $vacation_list;
 
    $form[] = '</pre>';
 
    $form[] = '<hr class="sep"/>';
 
    $form[] = '<span class="label">&nbsp;</span>';
 
    $form[] = sprintf('<input type="submit" name="loeschen" value="%s" /><br />', get_text('delete'));
 
    if ($is_admin) {
 
        echo ('<hr class="sep"/>');
 
        $form[] = ('<hr class="sep"/>');
 
    }
 
} else {
 
    $form[] = shl(get_text('reply_history_empty'));
 
}
 

	
 
$form[] = '</form>';
 
echo implode($form, "\n");
 

	
 
// --------------------------------------------------
 
// |||:sec:||| Administrator Manual
 
// --------------------------------------------------
 

	
 
if ($is_admin) {
 
    echo shl(get_text('manual_headline'));
 
    echo (sprintf('<a href="%s">%s</a><br />'."\n", get_text('manual_link'), get_text('manual')));
 
}
 

	
 
// --------------------------------------------------
 
// |||:sec:||| Debug
 
// --------------------------------------------------
 

	
 
if ($_debug) {
 
    echo "<pre>\n";                 // |:debug:|
 
    echo "\$_REQUEST: \n";
 
    var_dump($_REQUEST);
 
    echo "</pre>\n";
lib/language.php
Show inline comments
 
@@ -40,24 +40,25 @@ Your message has been forwarded to a co-
 
        'subject' => 'Subject',
 
        'message' => 'Message',
 
        'explain_subject' =>
 
        ' The expression'
 
        .' <em>$SUBJECT</em> is replaced with the subject of the incoming message.',
 
        'refresh' => 'Refresh',
 
        'save' => 'Save',
 

	
 
        'reply_history_empty' => 'Autoreply History Is Empty',
 
        'reply_history' => 'Autoreply History',
 
        'delete' => 'Delete',
 

	
 
        'manual_headline' => 'Administrator Manual',
 
        'manual' => 'Manual',
 
        'manual_link' => 'doc/README.html',
 
        // |:here:|
 
        ),
 
    'de' => Array(
 
        'vacation' => 'Subject: Re: $SUBJECT
 

	
 
Ich bin leider vorübergehend nicht per Email erreichbar.
 

	
 
Ihre Mail wird zur Bearbeitung an meine Vertretung weitergeleitet.
 
',
 
        'error_no_subject' => 'Fehler: Betreff ist leer!',
 
@@ -74,24 +75,25 @@ Ihre Mail wird zur Bearbeitung an meine 
 
        'message' => 'Nachricht',
 
        'explain_subject' =>
 
        ' Der Ausdruck'
 
        .' <em>$SUBJECT</em> wird durch den Betreff der eingehenden Email'
 
        .' ersetzt.',
 
        'refresh' => 'Neu einlesen',
 
        'save' => 'Speichern',
 

	
 
        'reply_history_empty' => 'Keine automatisch beantworteten Emails',
 
        'reply_history' => 'Automatisch  Beantwortete Emails',
 
        'delete' => 'Löschen',
 

	
 
        'manual_headline' => 'Administratorhandbuch',
 
        'manual' => 'Anleitung',
 
        'manual_link' => 'doc/README-de.html',
 
        // |:here:|
 
        ),
 
    );
 

	
 
//
 
// :ide-menu: Emacs IDE Menu - Buffer @BUFFER@
 
// . M-x `eIDE-menu' ()(eIDE-menu "z")
 
// :ide: COMPILE: PHP _DEBUG_=2 _DEBUG_TEST_=2
 
// . (compile (concat "php " (file-name-nondirectory (buffer-file-name)) " _DEBUG_=2 _DEBUG_TEST_=2"))
 

	
lib/util.php
Show inline comments
 
@@ -235,24 +235,89 @@ function shl($message)
 
}
 

	
 
function hl($message)
 
{
 
    echo shl($message)."\n";
 
}
 

	
 
function error_msg($message)
 
{
 
    echo sprintf('<span class="error"><strong>%s</strong></span>'."\n", $message);
 
}
 

	
 
// --------------------------------------------------
 
// |||:sec:||| vaccation(1) message
 
// --------------------------------------------------
 

	
 
function vacation_split($message, $decode)
 
{
 
    $lines = explode("\n", $message);
 
    $subject = array_shift($lines);
 
    $subject = preg_replace('/^[Ss]ubject: */', '', $subject);
 
    $headers = Array();
 
    // remove additional headers
 
    while (True) {
 
        $line = array_shift($lines);
 
        if (empty($line)) {
 
            break;
 
        }
 
        $headers[] = $line;
 
    }
 
    $headers = implode($headers, "\n");
 
    $body = implode($lines, "\n");
 
    if ( $decode )
 
    {
 
        if ( preg_match("/^=[?]/", $subject) )
 
        {
 
            $subject = preg_replace('/^=[?]utf-8[?]Q[?]/', '', $subject);
 
            $subject = preg_replace('/[?]=$/', '', $subject);
 
            $subject = quoted_printable_decode($subject);
 
        }
 
        $body = quoted_printable_decode($body);
 
    }
 
    return Array($subject, $headers, $body);
 
}
 

	
 
function vacation_join($subject, $body, $headers=Null)
 
{
 
    $subject = trim($subject);
 
    $subjectq = quoted_printable_encode($subject);
 
    if ( $subjectq != $subject )
 
    {
 
        $subject = sprintf('=?utf-8?Q?%s?=', $subjectq);
 
    }
 
    $subject = 'Subject: ' . $subject;
 
    $headera = Array(
 
        $subject,
 
        'Content-Type: text/plain;'."\n"
 
        .'  charset="utf-8"'."\n"
 
        .'Content-Transfer-Encoding: quoted-printable');
 
    if (!empty($headers))
 
    {
 
        $headers = trim($headers);
 
        if (!empty($headers))
 
        {
 
            $headers = preg_replace("/\n\n+/", "\n", $headers);
 
            $headera[] = $headers;
 
        }
 
    }
 
    $headers = implode($headera, "\n");
 
    if (empty($body))
 
    {
 
        $body = '';
 
    }
 
    return sprintf("%s\n\n%s\n",
 
                   $headers, quoted_printable_encode($body));
 
}
 

	
 
//
 
// :ide-menu: Emacs IDE Menu - Buffer @BUFFER@
 
// . M-x `eIDE-menu' ()(eIDE-menu "z")
 
// :ide: COMPILE: PHP _DEBUG_=2 _DEBUG_TEST_=2
 
// . (compile (concat "php " (file-name-nondirectory (buffer-file-name)) " _DEBUG_=2 _DEBUG_TEST_=2"))
 

	
 
// :ide: QUO: $this->
 
// . (insert "$this->" )
 

	
 
// :ide: COMPILE: PHP w/o args
 
// . (compile (concat "php " (file-name-nondirectory (buffer-file-name)) ""))
 

	
0 comments (0 inline, 0 general)