WackoWiki: Aktion: Wiki-Messenger

https://wackowiki.org/doc     Version: 30.05.2021 08:12
Dev[link3]/PatchesHacks[link4]/WikiMessenger
Compatible with: R6.0
Current version: 0.4
Credits: AhA[link1]


{{messenger}}

1. Description

Ein einfacher Wiki-Messenger, der es registrierten Nutzern ermöglicht sich innerhalb des Wikis Nachrichten zu schreiben.

Desweiteren hat man die Möglichkeit eine Kontaktliste zu führen und eigene Ordner anzulegen, um die erhaltenen Nachrichten
entsprechend zu verwalten.
Der Absender kann Nachrichten markieren und wird darüber informiert, ob eine Nachricht gelesen wurde.
Ebenfalls vorbereitet ist eine Codezeile, die in der header.php integriert werden kann – um den Nutzer sofort nach der Anmeldung
im Wiki anzuzeigen, dass er neue Nachrichten bekommen hat.

Der Code basiert auf dem Script Wikka Mail[link2] und wurde nur etwas angepasst und übersetzt.
Die Filterfunktion wurde komplett entfernt, da sie nur bedingt brauchbar bzw sinvoll ist. Mail wurde der Verwechslung wegen in Messenger umbenannt.
Die Funktion Nachrichten löschen wurde ebenfalls überarbeitet, da die Nachrichten im ursprünglichen Code nicht aus der Datenbank
gelöscht wurden, sondern lediglich nicht mehr im Posteingang angezeigt wurden. Die Nachricht ist dann zwar nicht mehr im 
Posteingang, aber es baut sich eine enorme Datenbank auf – da die Nachrichten ja nicht wirklich gelöscht wurden.

Die implementierte Hilfe für den Wiki-Messenger ist noch nicht ganz fertig, wird aber in kürze vervollständigt.
Da aber so gut wie alle Funktionen selbsterklärend sind steht einem Einsatz eigentlich nichts im Wege.

2. Installation

Um das Message-System zu installieren, muss die bestehende Datenbank um 2 Tabellen erweitert werden sowie die nachfolgende PHP-Datei in den Ordner /action kopiert werden.

Aufgerufen wird der Messenger im Wiki mit {{messenger}}

2.1. Action

Dieses Script muss unter dem Namen messenger.php gespeichert werden und in den Ordner /action kopiert werden.

/action/messenger.php


<?php

if (!defined('IN_WACKO'))
{
    exit;
}

/* messenger action:
 * https://wackowiki.org/doc/Dev/PatchesHacks/WikiMessenger
 * modify the script for your needs, please conribute your improvements
 */

// Aufrufen: {{messenger}} (ohne parameter). Benötigt: 2 Tabellen in MYSQL-Datenbank & sowie diese Datei, welche in den Ordner "action" eingefügt werden muss.

$prefix $this->db->table_prefix;

$create_table = function() use ($prefix)
{
    
$this->db->sql_query(
        
"CREATE TABLE IF NOT EXISTS {$prefix}messenger (
            message_id INT(10) NOT NULL AUTO_INCREMENT,
            user_to_id INT(10) UNSIGNED NOT NULL DEFAULT '0',
            repliedto TINYINT(1) DEFAULT '0',
            folder TINYTEXT NOT NULL,
            user_from_id INT(10) UNSIGNED NOT NULL DEFAULT '0',
            urgent TINYINT(1) DEFAULT NULL,
            subject MEDIUMTEXT NOT NULL,
            message LONGTEXT NOT NULL,
            status TEXT NOT NULL,
            datesent DATETIME NULL DEFAULT NULL,
            viewrecipient TINYINT(1) DEFAULT '1',
        PRIMARY KEY (message_id)
    );"
);

    
$this->db->sql_query(
        
"CREATE TABLE IF NOT EXISTS {$prefix}messenger_info (
            msg_info_id INT(80) NOT NULL AUTO_INCREMENT,
            owner_id INT(10) UNSIGNED NOT NULL DEFAULT '0',
            type TINYTEXT NOT NULL,
            info TINYTEXT NOT NULL,
            notes TINYTEXT,
        PRIMARY KEY (msg_info_id)
    );"
);
};

if (
$user_id $this->get_user_id())
{
    
$folder            $_GET['folder'] ?? null;
    
$which            $_REQUEST['whichfolder'] ?? null;
    if (!
$folder) {$folder $which;}
    
$message_id        = (int) ($_GET['message_id'] ?? null);
    
$move2folder    $_REQUEST['move2folder'] ?? null;
    
$action            $_GET['action'] ?? null;
    
$to                = (int) ($_GET['to'] ?? null);

    
// table
    
$tpl->hrefinbox        $this->href('''', ['action' => 'inbox']);
    
$tpl->hrefcompose    $this->href('''', ['action' => 'compose']);
    
$tpl->hrefsend        $this->href('''', ['action' => 'sent']);
    
$tpl->hreffolders    $this->href('''', ['action' => 'folders']);
    
$tpl->hrefcontacts    $this->href('''', ['action' => 'contacts']);
    
$tpl->hrefusers        $this->href('''', ['action' => 'users']);
    
$tpl->hrefhelp        $this->href('''', ['action' => 'help']);

    
$results $this->db->load_all(
        
"SELECT DISTINCT info
        FROM 
{$prefix}messenger_info
        WHERE type = 'folder'
            AND owner_id = " 
. (int) $user_id "
        ORDER BY info ASC"
);

    foreach (
$results as $row)
    {
        
$tpl->o_info    $row['info'];

        if (
$_REQUEST['whichfolder'] == $row['info'])
        {
            
$tpl->o_selected ' selected';
        }
    }

    if (! 
in_array($action, ['compose''forward''contacts''folders''users''help''reply''delete''store']))
    {
        if (
$action == 'inbox' || (($action == '' || $action == 'view')
            && @
$_REQUEST['whichfolder'] == '' && $folder == ''))
        {
            
$which2 '<b>' $this->_t('Inbox') . '</b>';
        }
        else if (
$action == 'sent' || $action == 'view2')
        {
            
$which2 '<b>' $this->_t('SentItems') . '</b>';
        }
        else if (
$folder != '')
        {
            
$which    $folder;
            
$which2    '<a href="' $this->href('''', ['folder' => $folder]) . '">' $which '</a>';
        }

        
$tpl->folder '<br><b>' $this->_t('Folder') . ': </b>' $which2;
    }

    
// [A] code for moving messages to folders
    
if ($move2folder)
    {
        
$rs $this->db->sql_query(
            
"UPDATE {$prefix}messenger SET
                folder = " 
$this->db->q($move2folder) . "
            WHERE message_id = " 
. (int) $message_id "
                AND user_to_id = " 
. (int) $user_id);

        
$tpl->a_message $rs
            
'<br>' Ut::perc_replace($this->_t('MessageMoved'), '<b>' $move2folder '</b>')
            : 
$this->_t('MessageNotMoved');
    }

    
// [B] shows inbox
    
else if (($action == '' || $action == 'inbox')
        && @
$_REQUEST['whichfolder'] == '' && (!$folder))
    {
        
$search '';

        
//needed for pagination of sent box
        
$limit 10;

        
$selector =
            
"FROM {$prefix}messenger m
                LEFT JOIN 
{$prefix}user u ON (m.user_from_id = u.user_id)
            WHERE m.user_to_id = " 
. (int) $user_id " " .
            
$search "
                AND m.folder = 'inbox'
                AND m.viewrecipient = '1' "
;

        
// count pages
        
$count $this->db->load_single(
            
"SELECT COUNT(message_id) AS n " .
            
$selector
            
true);

        
$pagination $this->pagination($count['n'], $limit'm' , ['action' => 'inbox']);

        
$result $this->db->load_all(
            
"SELECT m.*, u.user_name " .
            
$selector .
            
"ORDER BY m.datesent DESC " .
            
$pagination['limit']);

        
$tpl->enter('b_');

        
// to paginate the "inbox" page messeges
        
$tpl->pagination_text $pagination['text'];

        
$tpl->enter('n_');

        foreach (
$result as $row )
        {
            
// setzt Zeichen für Status der Nachricht (wichtig/gelesen/beantwortet)
            
if ($row['status'] == 'pending')
            {
                
$status '<a title="' $this->_t('MessageNotRead') . '"><span class="cite">*</span></a>';
            }
            else
            {
                
$status '';
            }

            if (
$row['urgent'] == 1)
            {
                
$urgent_flag '<a title="' $this->_t('UrgentMessage') . '"><span class="cite"><strong>!</strong></span></a>';
            }
            else
            {
                
$urgent_flag '';
            }

            if (
$row['repliedto'] == 1)
            {
                
$replied '<a title="' $this->_t('MessageReplied') . '"><font color="grey"><strong> beantwortet am: </strong></grey></a>';
            }
            else
            {
                
$replied '';
            }

            
$tpl->time            $row['datesent'];
            
$tpl->status        $status;
            
$tpl->urgent        $urgent_flag;
            
$tpl->replied        $replied;
            
$tpl->subject        strip_tags($row['subject']);
            
$tpl->username        $this->format($row['user_name']);
            
$tpl->hrefview        $this->href('''', ['action' => 'view''message_id' => $row['message_id'], 'page' => 'viewmessage']);
            
$tpl->hrefcontact    $this->href('''', ['action' => 'contacts''contact' => $row['user_from_id']]);
            
$tpl->hrefdelete    $this->href('''', ['action' => 'delete''message_id' => $row['message_id']]);
            
$tpl->hrefform        $this->href('''', ['message_id' => $row['message_id']]);

            
// code to put in drop down box to move to a new folder
            
$resultdrop2 $this->db->load_all(
                
"SELECT DISTINCT info
                FROM 
{$prefix}messenger_info
                WHERE type='folder'
                    AND owner_id = " 
. (int) $user_id "
                ORDER BY info ASC"
);

            foreach (
$resultdrop2 as $row2)
            {
                
$tpl->o_info $row2['info'];
            }
        }

        
$tpl->leave(); // n_

        
if ($count['n'] == 0)
        {
            echo 
'<br>' $this->_t('NoMessagesInbox') . '<br><br>';
        }

        
$tpl->leave(); // b_
    
}
    
// [C] send a new message to a user
    
else if ($action == 'compose')
    {
        
$users $this->db->load_all(
            
"SELECT user_id, user_name
            FROM 
{$prefix}user
            ORDER BY user_name ASC"
);

        
$tpl->enter('c_');

        
$tpl->hrefform        $this->href('''', ['action' => 'store']);
        
$tpl->hrefusers        $this->href('''', ['action' => 'users']);

        foreach (
$users as $user)
        {
            
$tpl->o_userid        $user['user_id'];
            
$tpl->o_username    $user['user_name'];

            if (
$to == $user['user_id'])
            {
                
$tpl->o_selected    ' selected';
            }
        }

        
$contacts $this->db->load_all(
            
"SELECT i.info, u.user_name
            FROM 
{$prefix}messenger_info i
                LEFT JOIN 
{$prefix}user u ON (i.info = u.user_id)
            WHERE i.type = 'contact'
                AND i.owner_id = " 
. (int) $user_id "
            ORDER BY i.info ASC"
);

        foreach (
$contacts as $row)
        {
            
$tpl->u_username    $row['user_name'];
            
$tpl->u_hrefcompose    $this->href('''', ['action' => 'compose''to' => (int) $row['info']]);
        }

        
$tpl->leave(); // c_
    
}

    
// [D] Antwort an den Absender einer Nachricht schicken
    
else if ($action == 'reply')
    {
        
$row $this->db->load_single(
            
"SELECT *
            FROM 
{$prefix}messenger
            WHERE user_to_id = " 
. (int) $user_id "
                AND message_id = " 
. (int) $message_id);

        
$user $this->db->load_single(
            
"SELECT user_id, user_name
            FROM 
{$prefix}user
            WHERE user_id = " 
. (int) $to "
                LIMIT 1"
);

        
$tpl->enter('d_');

        
$tpl->subject    $row['subject'];
        
$tpl->userid    $user['user_id'];
        
$tpl->username    $user['user_name'];
        
$tpl->hrefform    $this->href('''', ['action' => 'store''replyto' => $message_id]);
        
$tpl->origmsg    =     "\n\n++++++++++ " $this->_t('OriginalMessage') . " ++++++++++\n" .
                            
strip_tags($row['message']) .
                            
"\n+++++++++++++++++++++++++++++++++";

        
$tpl->leave(); // d_
    
}

    
// [E] Nachricht weiterleiten
    
else if ($action == 'forward' && $message_id != '')
    {
        
$row $this->db->load_single(
            
"SELECT *
            FROM 
{$prefix}messenger
            WHERE user_to_id = " 
. (int) $user_id "
                AND message_id = " 
. (int) $message_id);

        
$users $this->db->load_all(
            
"SELECT user_id, user_name
            FROM 
{$prefix}user
            ORDER BY user_name ASC"
);

        
$tpl->enter('e_');

        
$tpl->subject    'FWD: ' $row['subject'];
        
$tpl->hrefusers    $this->href('''', ['action' => 'users']);
        
$tpl->hrefform    $this->href('''', ['action' => 'store']);
        
$tpl->origmsg    =    "\n\n++++++++++++ " $this->_t('Forward') . " ++++++++++++++\n" .
                            
strip_tags($row['message']) .
                            
"\n+++++++++++++++++++++++++++++++++";

        foreach (
$users as $user)
        {
            
$tpl->o_userid        $user['user_id'];
            
$tpl->o_username    $user['user_name'];

            if (
$to == $user['user_id'])
            {
                
$tpl->o_selected    ' selected';
            }
        }

        
$contacts $this->db->load_all(
            
"SELECT i.info, u.user_name
            FROM 
{$prefix}messenger_info i
                LEFT JOIN 
{$prefix}user u ON (i.info = u.user_id)
            WHERE i.type='contact'
                AND i.owner_id = " 
. (int) $user_id "
            ORDER BY i.info ASC"
);

        foreach (
$contacts as $row)
        {
            
$tpl->u_username    $row['user_name'];
            
$tpl->u_hrefforward    $this->href('''', ['action' => 'forward''to' => (int) $row['info'], 'message_id' => $message_id]);
        }

        
$tpl->leave(); // e_
    
}

    
// [F] schreibt versendete Nachrichten (original/weitergeleitet) in die Datenbank
    
if ($action == 'store')
    {
        
$urgent        = (int) ($_POST['urgent'] ?? null);
        
$to            = (int) ($_POST['to'] ?? null);
        
$subject    $_POST['subject'] ?? null;
        
$message    $_POST['message'] ?? null;
        
$message    strip_tags($message);
        
$replyto    $_GET['replyto'] ?? null;
        
$date        date('YmdHis');

        
$tpl->enter('f_');

        
// prüft ob der Nutzer existiert und versendet die Nachricht
        
if ($subject == '' || $message == '' || $to == '')
        {
            
$tpl->x_hrefcompose    $this->href('''', ['action' => 'compose']);
        }
        else
        {
            if (
$this->load_user(''$to))
            {
                
$user $this->db->load_single(
                    
"SELECT user_id, user_name
                    FROM 
{$prefix}user
                    WHERE user_id = " 
. (int) $to "
                    LIMIT 1"
);

                
$this->db->sql_query(
                    
"INSERT INTO {$prefix}messenger (
                        user_to_id,
                        folder,
                        user_from_id,
                        subject,
                        message,
                        datesent,
                        status,
                        urgent
                    )
                    VALUES (" 
.
                        (int) 
$to ", " .
                        
$this->db->q('inbox') . ", " .
                        (int) 
$user_id ", " .
                        
$this->db->q($subject) . ", " .
                        
$this->db->q($message) . ", " .
                        
$this->db->q($date) . ", " .
                        
$this->db->q('pending') . ", " .
                        (int) 
$urgent "
                    )"
);

                
$tpl->sendto    Ut::perc_replace($this->_t('MessageSentTo'), $user['user_name']);

                
// to set the database so that the message has been replied to
                
$this->db->sql_query(
                    
"UPDATE {$prefix}messenger SET
                        repliedto = '1'
                    WHERE message_id = " 
. (int) $replyto "
                        AND user_to_id = " 
. (int) $user_id);
            }
            else
            {
                
$tpl->e_hrefcompose    $this->href('''', ['action' => 'compose']);
            }
        }

        
$tpl->leave(); // f_
    
}
    
// [G] zeigt den Ordner "versendete Nachrichten"
    
else if ($action == 'sent')
    {
        
// needed for pagination of sent box
        
$limit 10;

        
$selector =
            
"FROM {$prefix}messenger m
                LEFT JOIN 
{$prefix}user u ON (m.user_to_id = u.user_id)
            WHERE m.user_from_id = " 
. (int) $user_id " ";

        
// count pages
        
$count $this->db->load_single(
            
"SELECT COUNT(message_id) AS n " .
            
$selector
            
true);

        
$pagination $this->pagination($count['n'], $limit'm' , ['action' => 'sent']);

        
$result $this->db->load_all(
            
"SELECT m.*, u.user_name " .
            
$selector .
            
"ORDER BY m.datesent DESC " .
            
$pagination['limit']);

        
$tpl->enter('g_');

        
// to paginate the "sent" page messages
        
$tpl->pagination_text $pagination['text'];

        
$tpl->enter('n_');

        foreach (
$result as $row)
        {
            
$tpl->time            $row['datesent'];
            
$tpl->status        $row['status'];
            
$tpl->subject        strip_tags($row['subject']);
            
$tpl->username        $this->format($row['user_name']);
            
$tpl->hrefview2        $this->href('''', ['action' => 'view2''message_id' => $row['message_id'], 'page' => 'view2']);
            
$tpl->hrefcontact    $this->href('''', ['action' => 'contacts''contact' => $row['user_to_id']]);
        }

        
$tpl->leave(); // n_
        
$tpl->leave(); // g_
    
}

    
// [H] show selected folder
    
else if (((@$_REQUEST['whichfolder'] != '') || ($folder)) && ($action != 'view'))
    {
        
$search '';

        if (isset(
$_REQUEST['whichfolder']) && $_REQUEST['whichfolder'] != '')
        {
            
$showfolder $_REQUEST['whichfolder'];
        }
        else
        {
            
$showfolder $folder;
        }

        
$result $this->db->load_all(
            
"SELECT message_id
            FROM 
{$prefix}messenger
            WHERE user_to_id = " 
. (int) $user_id " " .
            
$search "
                AND folder = " 
$this->db->q($folder) . "
                AND viewrecipient = '1'
            ORDER BY datesent DESC"
);

        
//needed for pagination of sent box
        
$limit 10;

        
$selector =
            
"FROM {$prefix}messenger m
                LEFT JOIN 
{$prefix}user u ON (m.user_from_id = u.user_id)
            WHERE m.user_to_id = " 
. (int) $user_id " " .
            
$search "
                AND m.folder = " 
$this->db->q($showfolder);

        
// count pages
        
$count $this->db->load_single(
            
"SELECT COUNT(message_id) AS n " .
            
$selector
            
true);

        
$pagination $this->pagination($count['n'], $limit'm' , ['action' => 'message_folder''whichfolder' => $showfolder]);

        
$result $this->db->load_all(
            
"SELECT m.*, u.user_name " .
            
$selector .
            
"ORDER BY m.datesent DESC " .
            
$pagination['limit']);

        
$tpl->enter('h_');

        
// to paginate the "inbox" page messeges
        
$tpl->pagination_text $pagination['text'];

        
$tpl->enter('n_');

        foreach (
$result as $row)
        {
            if (
$row['status'] == 'unread')
            {
                
$status '<a title="' $this->_t('MessageNotRead') . '"><span class="cite">*</span></a>';
            }
            else
            {
                
$status '';
            }

            if (
$row['urgent'] == 1)
            {
                
$urgent_flag '<a title="' $this->_t('UrgentMessage') . '"><span class="cite"><strong>!</strong></span></a>';
            }
            else
            {
                
$urgent_flag '';
            }

            if (
$row['repliedto'] == 1)
            {
                
$replied '<a title="' $this->_t('MessageReplied') . '"><strong>+</strong></a>';
            }
            else
            {
                
$replied ' ';
            }

            
$tpl->time            $row['datesent'];
            
$tpl->status        $status;
            
$tpl->urgent        $urgent_flag;
            
$tpl->replied        $replied;
            
$tpl->subject        strip_tags($row['subject']);
            
$tpl->username        $this->format($row['user_name']);
            
$tpl->hrefview        $this->href('''', ['action' => 'view''message_id' => $row['message_id'], 'folder' => $which]);
            
$tpl->hrefcontact    $this->href('''', ['action' => 'contacts''contact' => $row['user_from_id']]);
            
$tpl->hrefdelete    $this->href('''', ['action' => 'delete''message_id' => $row['message_id']]);
            
$tpl->hrefform        $this->href('''', ['message_id' => $row['message_id'], 'folder' => $which]);

            
// code to put in drop down box to move to a new folder
            
$resultdrop2 $this->db->load_all(
                
"SELECT DISTINCT info
                FROM 
{$prefix}messenger_info
                WHERE type = 'folder'
                    AND owner_id = " 
. (int) $user_id "
                ORDER BY info ASC"
);

            foreach (
$resultdrop2 as $row2)
            {
                
$tpl->o_info $row2['info'];
            }
        }

        
$tpl->leave(); // n_

        
if ($count['n'] == 0)
        {
            
$tpl->nomessages '<br>' $this->_t('NoMessagesFolder') . '<br><br>';
        }

        
$tpl->leave(); // h_
    
}
    
// [I] view individual messages
    
else if ($action == 'view')
    {
        
$row $this->db->load_single(
            
"SELECT m.*, u.user_name
            FROM 
{$prefix}messenger m
                LEFT JOIN 
{$prefix}user u ON (m.user_from_id = u.user_id)
            WHERE m.user_to_id = " 
. (int) $user_id "
                AND m.message_id = " 
. (int) $message_id);

        if (
$row['repliedto'] == 1)
        {
            
$replied '<a title="' $this->_t('MessageReplied') . '"><small>replied to<small></a>';
        }
        else
        {
            
$replied ' ';
        }

        
$tpl->enter('i_');

        
// code to set filter in database
        
if ($row['user_to_id'] == $user_id)
        {
            
$tpl->time            $row['datesent'];
            
$tpl->subject        strip_tags($row['subject']);
            
$tpl->username        $this->format($row['user_name']);
            
$tpl->message        strip_tags($row['message']);
            
$tpl->replied        $replied;
            
$tpl->hrefcontact    $this->href('''', ['action' => 'contacts''contact' => $row['user_from_id']]);
            
$tpl->hrefreply        $this->href('''', ['action' => 'reply''to' => $row['user_from_id'], 'message_id' => $row['message_id']]);
            
$tpl->hrefforward    $this->href('''', ['action' => 'forward''message_id' => $row['message_id']]);
            
$tpl->hrefdelete    $this->href('''', ['action' => 'delete''message_id' => $row['message_id']]);

            
$rs $this->db->sql_query(
                
"UPDATE {$prefix}messenger SET
                    status = 'gelesen'
                WHERE message_id = " 
. (int) $message_id);
        }
        else
        {
            
$tpl->forbidden 'Das ist nicht Deine Post!';
        }

        
$tpl->leave(); // i_
    
}

    
// [J] added filter for viewing "folder sorted" messages
    
else if ($action == 'view2')
    {
        
$row $this->db->load_single(
            
"SELECT m.*, u.user_name
            FROM 
{$prefix}messenger m
                LEFT JOIN 
{$prefix}user u ON (m.user_to_id = u.user_id)
            WHERE m.user_from_id = " 
. (int) $user_id "
                AND m.message_id = " 
. (int) $message_id);

        
$tpl->enter('j_');

        if (
$row['user_from_id'] == $user_id)
        {
            
$tpl->time            $row['datesent'];
            
$tpl->subject        strip_tags($row['subject']);
            
$tpl->username        $this->format($row['user_name']);
            
$tpl->message        strip_tags($row['message']);
            
$tpl->hrefcontact    $this->href('''', ['action' => 'contacts''contact' => $row['user_from_id']]);
        }

        
$tpl->leave(); // j_
    
}

    
// [K] Nachrichten löschen (geändert - Nachrichten werden jetzt komplett aus Datenbank entfernt)
    
else if ($action == 'delete')
    {
        
$rs $this->db->sql_query(
            
"DELETE FROM {$prefix}messenger
            WHERE message_id = " 
. (int) $message_id);

        
$tpl->k_message    = ($rs
            
$this->_t('MessageDeleted')
            : 
$this->_t('MessageNotDeleted'));
    }

    
// [L] Kontaktliste verwalten
    
else if ($action == 'contacts')
    {
        
$add_contact    $_GET['contact'] ?? '';
        
$delete_contact    $_GET['delete_contact'] ?? null;
        
$field1_value    $_POST['field1_value'] ?? null;
        if (
$field1_value)
        {
$insert '1';}
        else {
$insert '';}
        
$field2_value    $_POST['field2_value'] ?? null;
        
$category        'contact';

        if (
$insert)
        {
            if (
$this->load_user(''$field1_value))
            {
                
$this->db->sql_query(
                    
"INSERT INTO {$prefix}messenger_info (
                        owner_id,
                        info,
                        notes,
                        type
                    )
                    VALUES (" 
.
                        (int) 
$user_id ", " .
                        
$this->db->q($field1_value) . ", " .
                        
$this->db->q($field2_value) . ", " .
                        
$this->db->q($category) . "
                    )"
);
            }
        }

        if (
$delete_contact)
        {
            
$this->db->sql_query(
                
"DELETE FROM {$prefix}messenger_info
                WHERE msg_info_id = 
$delete_contact
                    AND owner_id = " 
. (int) $user_id);
        }

        
$users $this->db->load_all(
            
"SELECT user_id, user_name
            FROM 
{$prefix}user
            ORDER BY user_name ASC"
);

        
$contacts $this->db->load_all(
            
"SELECT i.msg_info_id, i.owner_id, i.type, i.info, i.notes, u.user_name
            FROM 
{$prefix}messenger_info i
                LEFT JOIN 
{$prefix}user u ON (i.info = u.user_id)
            WHERE i.owner_id = " 
. (int) $user_id "
                AND i.type = " 
$this->db->q($category) . "
            ORDER BY i.info ASC"
);

        
$tpl->enter('l_');

        
$tpl->hrefform            $this->href('''', ['action' => 'contacts']);
        
$tpl->hrefusers            $this->href('''', ['action' => 'users']);

        foreach (
$contacts as $contact)
        {
            
$in_list[]                 = $contact['info'];
            
$tpl->c_username        $contact['user_name'];
            
$tpl->c_notes            strip_tags($contact['notes']);
            
$tpl->c_hrefcompose        $this->href('''', ['action' => 'compose''to' => $contact['info']]);
            
$tpl->c_hrefdelete        $this->href('''', ['action' => 'contacts''delete_contact' => $contact['msg_info_id']]);
        }

        foreach (
$users as $user)
        {
            if (!
in_array($user['user_id'], $in_list))
            {
                
$tpl->o_userid        $user['user_id'];
                
$tpl->o_username    $user['user_name'];

                if (
$add_contact == $user['user_id'])
                {
                    
$tpl->o_selected    ' selected';
                }
            }
        }

        
$tpl->leave(); // l_
    
}

    
// [M] Ordner verwalten
    
else if ($action == 'folders')
    {
        
$delete_folder    $_GET['delete_folder'] ?? null;
        
$folder            $_GET['folder'] ?? null;
        
$field1_value    $_POST['field1_value'] ?? null;
        if (
$field1_value) {$insert '1';}
        else {
$insert '';}
        
$field2_value    $_POST['field2_value'] ?? null;
        
$category        'folder';

        if (
$insert)
        {
            
$this->db->sql_query(
                
"INSERT INTO {$prefix}messenger_info (
                    owner_id,
                    info,
                    notes,
                    type
                )
                VALUES (" 
.
                    (int) 
$user_id ", " .
                    
$this->db->q($field1_value) . ", " .
                    
$this->db->q($field2_value) . ", " .
                    
$this->db->q($category) . "
                )"
);
        }

        if (
$delete_folder)
        {
            
// delete folder name from messenger_info
            
$this->db->sql_query(
                
"DELETE from {$prefix}messenger_info
                WHERE msg_info_id = '
$delete_folder'
                    AND owner_id = " 
. (int) $user_id "
                    AND type = 'folder'"
);

            
// change files from being stored in folder being deleted to being stored in inbox
            
$this->db->sql_query(
                
"UPDATE {$prefix}messenger SET
                    folder = 'inbox'
                WHERE folder = " 
$this->db->q($folder) . "
                    AND user_to_id = " 
. (int) $user_id);
        }

        
$result    $this->db->load_all(
            
"SELECT msg_info_id, owner_id, type, info, notes
            FROM 
{$prefix}messenger_info
            WHERE owner_id = " 
. (int) $user_id "
                AND type = " 
$this->db->q($category) . "
            ORDER BY info ASC"
);

        
$tpl->enter('m_');

        
$tpl->hrefform            $this->href('''', ['action' => 'folders']);

        foreach (
$result as $row)
        {
            
$tpl->f_info        strip_tags($row['info']);
            
$tpl->f_notes        strip_tags($row['notes']);
            
$tpl->f_hreffolder    $this->href('''', ['folder' => strip_tags($row['info'])]);
            
$tpl->f_hrefdelete    $this->href('''', ['action' => 'folders''delete_folder' => $row['msg_info_id'], 'folder' => $row['info']]);
        }

        
$tpl->leave(); // m_
    
}

    
// [N] code to display user list
    
else if ($action == 'users')
    {
        
$users $this->db->load_all(
            
"SELECT user_id, user_name
            FROM 
{$prefix}user
            ORDER BY user_name ASC"
);

        
$tpl->enter('n_');

        foreach (
$users as $user)
        {
            
$tpl->u_username    $user['user_name'];
            
$tpl->u_hrefcontact    $this->href('''', ['action' => 'contacts''contact' => $user['user_id']]);
        }

        
$tpl->leave(); // n_
    
}

    
// [O] help
    
else if ($action == 'help')
    {
        
$tpl->true;
    }
}
else
{
    
$tpl->forbidden $this->_t('MessagingForbidden');
}


2.2. Template

Dieses Script muss unter dem Namen messenger.tpl gespeichert werden und in den Ordner /action/template kopiert werden.

/action/template/messenger.tpl

[ === main === ]

    <script>
    <!-- Begin
    function textCounter(field, countfield, maxlimit)
    {
        if (field.value.length> maxlimit)        // if too long...trim it!
            field.value = field.value.substring(0, maxlimit);
                else                            // otherwise, update 'characters left' counter
            countfield.value = maxlimit - field.value.length;
    }
    // End -->
    </script>

    <table>
        <tr>
            <td> <a href="[ ' hrefinbox ' ]">[ ' _t: Inbox ' ]</a> </td>
            <td> | <a href="[ ' hrefcompose ' ]">[ ' _t: Compose ' ]</a> </td>
            <td> | <b>[ ' _t: Folder ' ]</b></td>
            <td>
                <form action="[ ' href: ' ]" method="post" name="message_folder">
                    [ ' csrf: message_folder ' ]
                    <select name="whichfolder">
                    [= o _ =
                        <option value="[ ' info ' ]"[ ' selected ' ]>[ ' info ' ]</option>
                    =]
                    </select>
                    <button type="submit">[ ' _t: View ' ]</button>
                </form>
            </td>
            <td> | <a href="[ ' hrefsend ' ]">[ ' _t: SentItems ' ]</a> </td>
            <td> | <b>[ ' _t: Manage ' ]: </b><a href="[ ' hreffolders ' ]">[ ' _t: Folders ' ]</a> | <a href="[ ' hrefcontacts ' ]">[ ' _t: Contacts ' ]</a> </td>
            <td> | <a href="[ ' hrefusers ' ]">[ ' _t: Users ' ]</a></td>
            <td> | <a href="[ ' hrefhelp ' ]">[ ' _t: Help ' ]</a></td>
        </tr>
    </table>
    [ ' folder ' ]<br>
    [ ' forbidden ' ]
    [= a _ =
        [ ' message ' ]
    =]
    [= b _ =
        <table class="hl-line" cellpadding="2" cellspacing="3">
            <tr>
                <td colspan="5" align="center">
                    [ '' pagination '' ]
                </td>
            </tr>
            <tr bgcolor=#93B2DD>
                <td width="400"><b>[ ' _t: Subject ' ]</b></td>
                <td width=""><b>[ ' _t: Date ' ]</b></td>
                <td width="100"><b>[ ' _t: Sender ' ]</b></td>
                <td width="250"><b>[ ' _t: MoveToFolder ' ]</b></td>
                <td width="80"><b>[ ' _t: Delete ' ]</b></td>
            </tr>
            [= n _ =
                <tr>
                    <td>[ ' status ' ][ ' urgent ' ] <a href="[ ' hrefview ' ]">[ ' subject ' ]</a><small>[ ' replied ' ]</small></td>
                    <td>[ ' time | time_formatted ' ]</td>
                    <td>[ ' username ' ]<small> [<a href="[ ' hrefcontact ' ]">-></a>]</small></td>
                    <td width="155">
                        <form action="[ ' hrefform ' ]" method="post" name="move_folder">
                            [ ' csrf: move_folder ' ]
                            <select name="move2folder">
                            [= o _ =
                                <option value="[ ' info ' ]">[ ' info ' ]</option>
                            =]
                            </select>
                            <button type="submit">[ ' _t: Move ' ]</button>
                        </form>
                    </td>
                    <td>
                        <a href="javascript: if (confirm('[ ' _t: DeleteItem ' ]')){ window.self.location='[ ' hrefdelete ' ]' }">[ ' _t: Delete ' ]</a><br>
                    </td>
                </tr>
            =]
        </table>
    =]
    [= c _ =
        <br><b>[ ' _t: ComposeMessage ' ]</b><br><br>
        <table width="675">
            <tr>
                <td>
                    <form action="[ ' hrefform ' ]" method="post" name="message_store">
                        [ ' csrf: message_store ' ]
                        <table>
                            <tr>
                                <td>[ ' _t: Subject ' ]:</td>
                                <td><input type="text" name="subject" maxlength="65" size="30" value="" required></td>
                            </tr>
                            <tr>
                                <td>[ ' _t: Recipient ' ]:</td>
                                <td>
                                    <select name="to" required>
                                        <option value="">[ ' _t: ChooseRecipient ' ]</option>
                                        [= o _ =
                                            <option value="[ ' userid ' ]"[ ' selected ' ]>[ ' username ' ]</option>
                                        =]
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td>[ ' _t: Message ' ]:</td>
                                <td>
                                    <textarea rows="16" cols="45" name="message" onKeyDown="textCounter(this.form.message,this.form.remLen,2000);" onKeyUp="textCounter(this.form.message,this.form.remLen,2000);"></textarea><br>
                                    <input readonly type="text" name="remLen" size="4" maxlength="4" value="2000"> [ ' _t: CharactersLeft ' ]
                                </td>
                            </tr>
                            <tr>
                                <td><button type="submit">[ ' _t: Send ' ]</button></td>
                                <td align="right">[ ' _t: Urgent ' ] <input type="checkbox" name="urgent" value="1"></td>
                            </tr>
                        </table>
                    </form>
                </td>
                <td width="200">
                    Um einen User zu Deiner Kontaktliste hinzuzufügen bitte <a href="[ ' hrefusers ' ]">hier</a> klicken!<br><br>
                    <b>[ ' _t: ContactList ' ]:</b><br><small>([ ' _t: ClickName ' ])</small><br><br>
                    [= u _ =
                        <a href="[ ' hrefcompose ' ]">[ ' username ' ]</a><br>
                    =]
                </td>
            </tr>
        </table>
    =]
    [= d _ =
        <br><b>[ ' _t: ReplyToMessage ' ]</b><br><br>
        <form action="[ ' hrefform ' ]" method="post" name="message_reply">
            [ ' csrf: message_reply ' ]
            <table width="400">
                <tr>
                    <td>[ ' _t: Subject ' ]:</td>
                    <td><input readonly type="text" name="subject" maxlength="65" size="30" value="[ ' subject ' ]" required></td>
                </tr>
                <tr>
                    <td>[ ' _t: Recipient ' ]:</td>
                    <td>
                        <select name="to" readonly required>
                            <option value="[ ' userid ' ]">[ ' username ' ]</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>[ ' _t: Message ' ]:</td>
                    <td><textarea rows="16" cols="45" name="message" onKeyDown="textCounter(this.form.message,this.form.remLen,2000);" onKeyUp="textCounter(this.form.message,this.form.remLen,2000);">[ ' origmsg | pre ' ]</textarea><br>
                        <input readonly type="text" name="remLen" size="4" maxlength="4" value="2000"> [ ' _t: CharactersLeft ' ]
                    </td>
                </tr>
                <tr>
                    <td><button type="submit">[ ' _t: Send ' ]</button></td>
                    <td align="right">[ ' _t: Urgent ' ] <input type="checkbox" name="urgent" value="1"></td>
                </tr>
            </table>
        </form>
    =]
    [= e _ =
        <br><b>[ ' _t: ForwardMessage ' ]</b><br><br>
        <table width="675">
            <tr>
                <td>
                    <form action="[ ' hrefform ' ]" method="post" name="message_forward">
                        [ ' csrf: message_forward ' ]
                        <table>
                            <tr>
                                <td>[ ' _t: Subject ' ]:</td>
                                <td><input type="text" name="subject" maxlength="65" size="30" value="[ ' subject ' ]" required></td>
                            </tr>
                            <tr>
                                <td>[ ' _t: Recipient ' ]:</td>
                                <td>
                                    <select name="to" required>
                                        <option value="">[ ' _t: ChooseRecipient ' ]</option>
                                        [= o _ =
                                            <option value="[ ' userid ' ]"[ ' selected ' ]>[ ' username ' ]</option>
                                        =]
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td>[ ' _t: Message ' ]:</td>
                                <td>
                                    <textarea rows="16" cols="45" name="message" onKeyDown="textCounter(this.form.message,this.form.remLen,2500);" onKeyUp="textCounter(this.form.message,this.form.remLen,2500);">[ ' origmsg | pre ' ]</textarea><br>
                                    <input readonly type="text" name="remLen" size="4" maxlength="4" value="2500"> [ ' _t: CharactersLeft ' ]
                                </td>
                            </tr>
                            <tr>
                                <td><button type="submit">[ ' _t: Send ' ]</button></td>
                                <td align="right">[ ' _t: Urgent ' ] <input type="checkbox" name="urgent" value="1"></td>
                            </tr>
                        </table>
                    </form>
                </td>
                <td width="200">
                    Um einen User zu Deiner Kontaktliste hinzuzufügen bitte <a href="[ ' hrefusers ' ]">hier</a> klicken!<br><br>
                    <b>[ ' _t: ContactList ' ]:</b><br><small>([ ' _t: ClickName ' ])</small><br><br>
                    [= u _ =
                        <a href="[ ' hrefforward ' ]">[ ' username ' ]</a><br>
                    =]
                </td>
            </tr>
        </table>
    =]
    [= f _ =
        [= x _ =
            <br><center><span class="cite">Ein Feld wurde nicht ausgefüllt. Es müssen alle Felder ausgefüllt sein!</span></center><br><br>
            <a href="[ ' hrefcompose ' ]">Zurück</a>
        =]
        [= e _ =
            <br><span class="cite">Die Nachricht konnte nicht versendet werden, da der eingetragende Empfänger kein registrierter Benutzer ist.</span><br><br>
            <a href="[ ' hrefcompose ' ]">Zurück</a>
        =]
        [ ' sendto ' ]
    =]
    [= g _ =
        <table class="hl-line" cellpadding="2" cellspacing="3" width="100%">
            <tr>
                <td colspan="4" align="center">
                    [ '' pagination '' ]
                </td>
            </tr>
            <tr bgcolor=#93B2DD>
                <td width="400"><b>[ ' _t: Subject ' ]</b></td>
                <td width=""><b>[ ' _t: Date ' ]</b></td>
                <td width="100"><b>[ ' _t: Recipient ' ]</b></td>
                <td width="75"><b>[ ' _t: Read ' ]</b></td>
            </tr>
            [= n _ =
                <tr>
                    <td><a href="[ ' hrefview2 ' ]">[ ' subject ' ]</a></td>
                    <td>[ ' time | time_formatted ' ]</td>
                    <td>[ ' username ' ]<small> [<a href="[ ' hrefcontact ' ]">-></a>]</small></td>
                    <td width="50">[ ' status ' ]<br></td>
                </tr>
            =]
        </table>
        [ ' // <br><br>Löscht der Empfänger eine Nachricht, wird sie auch hier automatisch entfernt! ' ]
    =]
    [= h _ =
        <table class="hl-line" cellpadding="2" cellspacing="3" width="800">
            <tr>
                <td colspan="5" align="center">
                    [ '' pagination '' ]
                </td>
            </tr>
            <tr bgcolor="#93B2DD">
                <td>
                    <table border="0" cellpadding="0" cellspacing="0" width="100%">
                        <tr>
                            <td width="400"><b> [ ' _t: Subject ' ]:</b></td>
                            <td align="right"></td>
                        </tr>
                    </table>
                </td>
                <td width="100"><b> [ ' _t: Sender ' ]</b></td>
                <td width="250"><b> [ ' _t: MoveToFolder ' ]</b></td>
                <td width="80"><b> [ ' _t: Delete ' ]</b></td>
            </tr>
            [= n _ =
                <tr>
                    <td>
                        [ ' status ' ][ ' urgent ' ]<a href="[ ' hrefview ' ]">[ ' subject ' ]</a>[ ' replied ' ]<small>([ ' time | time_formatted ' ])</small>
                    </td>
                    <td width="125">[ ' username ' ]<small> [<a href="[ ' hrefcontact ' ]">-></a>]</small></td>
                    <td>
                        <form action="[ ' hrefform ' ]" method="post" name="move_folder">
                            [ ' csrf: move_folder ' ]
                            <select name="move2folder">
                            [= o _ =
                                <option value="[ ' info ' ]">[ ' info ' ]</option>
                            =]
                            </select>
                            <button type="submit">[ ' _t: Move ' ]</button>
                        </form>
                    </td>
                    <td>
                        <a href="javascript: if (confirm('[ ' _t: DeleteItem ' ]')){ window.self.location='[ ' hrefdelete ' ]' }">[ ' _t: Delete ' ]</a><br>
                    </td>
                </tr>
            =]
        </table>
        [ ' nomessages ' ]
    =]
    [= i _ =
        [ ' forbidden ' ]
        <table border="1" bordercolor="#666699" width="600">
            <tr>
                <td width="350"><strong> [ ' _t: Subject ' ]: </strong>[ ' subject ' ]</td>
                <td></td>
                <td><strong> Von: </strong>[ ' username ' ]<small> [<a href="[ ' hrefcontact ' ]">-></a>]</small></td>
            </tr>
            <tr>
                <td colspan="3"><strong> [ ' _t: Message ' ]: </strong>[ ' message ' ]</td>
            </tr>
            <tr>
                <td>
                    <a href="[ ' hrefreply ' ]"> [ ' _t: Reply ' ]</a>
                    / <a href="[ ' hrefforward ' ]">[ ' _t: Forward ' ]</a>
                    / <a href="javascript: if (confirm('[ ' _t: DeleteItem ' ]')){ window.self.location='[ ' hrefdelete ' ]' }">[ ' _t: Delete ' ]</a>
                </td>
                <td>[ ' replied ' ]</td>
                <td><small><strong>[ ' _t: Date ' ]:</strong> [ ' time | time_formatted ' ]</small></td>
            </tr>
        </table><br>
    =]
    [= j _ =
        <table border="1" width="600">
            <tr>
                <td colspan="2"><strong>[ ' _t: Subject ' ]:</strong> [ ' subject ' ]</td>
            </tr>
            <tr>
                <td colspan="2"><strong>[ ' _t: Recipient ' ]:</strong> [ ' username ' ]<small> [<a href="[ ' hrefcontact ' ]">-></a>]</small></td>
            </tr>
            <tr>
                <td colspan="2"><strong>[ ' _t: Message ' ]: </strong>[ ' message ' ]</td>
            </tr>
            <tr>
                <td colspan="2"><small><strong>[ ' _t: Date ' ]: </strong>[ ' time | time_formatted ' ]</small></td>
            </tr>
        </table>
    =]
    [= k _ =
        [ ' message ' ]
    =]
    [= l _ =
        <br><b>[ ' _t: ContactList ' ]:</b><br><br>
        <form action="[ ' hrefform ' ]" method="post" name="edit_contacts">
            [ ' csrf: edit_contacts ' ]
            <input type="hidden" name="insert" value="1">
            <table border="1" cellspacing="0" width="70%" align="left">
                <tr>
                    <td><strong>[ ' _t: ContactNames ' ]</strong></td>
                    <td><strong>[ ' _t: Notes ' ]</strong></td>
                    <td> </td>
                </tr>
                <tr>
                    <td>
                        <select name="field1_value" required>
                            <option value="">[ ' _t: ChooseRecipient ' ]</option>
                            [= o _ =
                                <option value="[ ' userid ' ]"[ ' selected ' ]>[ ' username ' ]</option>
                            =]
                        </select>
                    </td>
                    <td>
                        <input type="text" size="35" maxlength="65" name="field2_value">
                    </td>
                    <td colspan="2" align="center">
                        <button type="submit">[ ' _t: Add ' ]</button>
                    </td>
                </tr>
                [= c _ =
                    <tr>
                        <td><a href="[ ' hrefcompose ' ]">[ ' username ' ]</a></td>
                        <td>[ ' notes ' ]</td>
                        <td><a href="javascript: if (confirm('[ ' _t: DeleteItem ' ]')){ window.self.location='[ ' hrefdelete ' ]' }">[ ' _t: Delete ' ]</a></td>
                    </tr>
                =]
            </table>
            <table>
                <td width="25"></td>
                <td width="150">
                    <span class="cite">[ ' _t: ClickContact ' ]</span><br><br>
                    Um einen Benutzer zu Deiner Kontaktliste hinzuzufügen bitte <a href="[ ' hrefusers ' ]">hier</a> klicken!<br><br>
                    Es können <b>nur</b> registrierte Benutzer hinzugefügt werden.
                </td>
            </table>
        </form>
    =]
    [= m _ =
        <br><b>[ ' _t: FolderList ' ]:</b><br><br>
        <form action="[ ' hrefform ' ]" method="post" name="message_folders">
            [ ' csrf: message_folders ' ]
            <input type="hidden" name="insert" value="1">
            <table border="1" cellspacing='0' width="65%" align="left">
                <tr>
                    <td><strong>[ ' _t: Folder ' ]</strong></td>
                    <td><strong>[ ' _t: Notes ' ]</strong></td>
                    <td> </td>
                </tr>
                <tr>
                    <td>
                        <input type="text" size="25" maxlength="65" name="field1_value"></td>
                    <td>
                        <input type="text" size="35" maxlength="65" name="field2_value">
                    </td>
                    <td colspan="2" align="center">
                        <button type="submit">[ ' _t: Add ' ]</button>
                    </td>
                </tr>
                [= f _ =
                    <tr>
                        <td><a href="[ ' hreffolder ' ]">[ ' info ' ]</a></td>
                        <td>[ ' notes ' ]</td>
                        <td>
                            <a href="javascript: if (confirm('[ ' _t: DeleteItem ' ]')){ window.self.location='[ ' hrefdelete ' ]' }">[ ' _t: Delete ' ]</a>
                        </td>
                    </tr>
                =]
            </table>
            <table>
                <tr>
                    <td width="25"></td>
                    <td width="200">
                        <span class="cite">[ ' _t: ClickFolder ' ]</span><br><br><b>Ordner erstellen:</b><br><br>
                        Gib in das leere Feld unter <b>Ordner:</b> den Namen für den neuen Ordner ein.<br><br>In das Feld <b>Beschreibung:</b> kannst Du eine Beschreibung für den Ordner eingeben.<br><br>
                        Nun noch ein Klick auf <b>Hinzufügen</b> und der neue Ordner steht Dir zur Verfügung.
                    </td>
                </tr>
            </table>
        </form>
    =]
    [= n _ =
        <table width="650">
            <tr>
                <td>
                    <br><b>[ ' _t: Users ' ]:</b><br><br>
                    [= u _ =
                        <a href="[ ' hrefcontact ' ]">[ ' username ' ]</a><br>
                    =]
                </td>
            </tr>
        </table>
        <span class="cite"><br><br>[ ' _t: ClickContact2 ' ]</span><br><br>
    =]

    [ ' z help ' ]


[ == help == ]
[ ' nonstatic ' ]
<table width="100%">
    <tr>
        <td>
            <a name= anfang></a>
            <h3>Hilfe für das WackoWiki-Message-System</h3>
            <br><br>Auf dieser Seite gibt es einige Hilfestellungen zu den Funktionen des WackoWiki-Message-Systems. Die Erklärungen sind kurz gehalten, da die meisten Funktionen selbsterklärend sind.<br>Nachfolgend findest Du ein Inhaltsverzeichnis zu den hier erläuterten Funktionen:
            <br><br><br>
            <a href=#post>Posteingang</a><br>
            <a href=#verf>Verfassen</a><br>
            <a href=#vers>Postausgang</a><br>
            <a href=#verw>Verwalten</a><br>
                - <a href=#ordn>Ordner</a><br>
                - <a href=#kont>Kontaktliste</a><br>
            <a href=#benu>Benutzer</a><br><br>
            <a name= post><h3>Posteingang</h3></a><br><br>
            Im Posteing werden alle eingetroffenen Nachrichten angezeigt, sowie einige zusätzliche Info`s zu den einzelnen Nachrichten.<br><br>
            In der folgenden Darstellung siehst Du ein Beispiel, wie der Posteingangsordner aussehen kann:<br><br><br>
            <table>
                <tr bgcolor="#93B2DD">
                    <td width="400">
                        <table border="0" cellspacing="0" cellpadding="0" width="100%">
                            <tr><td width="100"><b> Betreff</b></td></tr>
                        </table>
                    </td>
                    <td width="100"><b> Absender</b></td>
                    <td width="250"><b> Verschieben in Ordner</b></td>
                    <td width="80"><b> Löschen</b></td>
                </tr>
            </table>
            <table>
                <tr>
                    <td width="400">
                        <table border="0" cellspacing="0" cellpadding="0" width="100%">
                            <tr><td width="100"><span class="cite">!*</span><a href=#test>Testnachricht</a> (03Jun06 2:57 pm)</td></tr>
                        </table>
                    </td>
                    <td width="100"><a href=#testuser>Testuser</a> [<a href=#pfeil>-></a>]</td>
                    <td width="250">
                        <form method=post>
                            <select name="move2folder"></select>
                            <button type="submit">Verschieben</button>
                        </form>
                    </td>
                    <td width="80"><a href=#loeschen>Löschen</a></td>
                </tr>
            </table>
            <table>
                <tr>
                    <td width="400">
                        <table border="0" cellspacing="0" cellpadding="0" width="100%">
                            <tr>
                                <td width="100">
                                    <span class="cite">!</span><a href=#test1>Testnachricht1</a><font color= #808080><small><b> beantwortet am:</b> (01Jun06 1:02 pm)</small></font>
                                </td>
                            </tr>
                        </table>
                    </td>
                    <td width="100"><a href=#testuser>Testuser16</a> [<a href=#pfeil>-></a>]</td>
                    <td width="250"><right>
                        <form method=post>
                            <select name="move2folder"></select>
                            <button type="submit">Verschieben</button>
                        </form></right>
                    </td>
                    <td width="80"><a href=#loeschen>Löschen</a></td>
                </tr>
            </table><br>
            <a href=#anfang>Seitenanfang</a><br><br>
            <h4>Was bedeuten die Zeichen vor und hinter den Nachrichten?</h4>
            <br><br> - Das <b><span class="cite">!</span></b> vor einer Nachricht erscheint, wenn der Absender die Nachricht als <b>dringend</b> markiert hat.
            <br><br> - Das <b><span class="cite">*</span></b> vor der Nachricht zeigt an, das die Nachricht noch nicht gelesen wurde. Sobald die Nachricht gelesen wurde verschwindet<br>
            das <b><span class="cite">*</span></b> und der Absender erhält die Information, dass die Nachricht gelesen wurde.<br><br>
            - Die Daten hinter der Nachricht geben an, wann die Nachricht erhalten bzw. gesendet wurde. Ausserdem wird in einer anderen<br>
            Farbe angezeigt ob und wann eine Nachricht beantwortet wurde.<br><br>
            <h4>Wie kann ich eine Nachricht öffnen?</h4><br><br>
            Um eine Nachricht zu lesen muss man auf den <b>Betreff</b> der Nachricht klicken, die geöffnet werden soll. Anschliessend wird die Nachricht<br>
            in einem neuen Fenster dargestellt.<br><br>
            <h4>Nachrichten in andere Ordner verschieben!</h4><br><br>
        </td>
    </tr>
</table>

[= pagination =]
<nav class="pagination">[ ' text ' ]</nav>

2.3. Database

Die bestehende Wacko-MySQL-Datenbank muss um die folgenden 2 Tabellen erweitert werden. Den Präfix für die Tabellen entsprechend ändern falls erforderlich.

CREATE TABLE wacko_messenger (
  message_id INT(10NOT NULL AUTO_INCREMENT,
  user_to_id INT(10) UNSIGNED NOT NULL DEFAULT '0',
  repliedto TINYINT(1DEFAULT '0',
  folder TINYTEXT NOT NULL,
  user_from_id INT(10) UNSIGNED NOT NULL DEFAULT '0',
  urgent TINYINT(1DEFAULT NULL,
  subject MEDIUMTEXT NOT NULL,
  message LONGTEXT NOT NULL,
  status TEXT NOT NULL,
  datesent DATETIME NULL DEFAULT NULL,
  viewrecipient TINYINT(1DEFAULT '1',
PRIMARY KEY (message_id)
);

CREATE TABLE wacko_messenger_info (
  msg_info_id INT(10NOT NULL AUTO_INCREMENT,
  owner_id INT(10) UNSIGNED NOT NULL DEFAULT '0',
  type TINYTEXT NOT NULL,
  info TINYTEXT NOT NULL,
  notes TINYTEXT,
PRIMARY KEY (msg_info_id)
);

2.4. Message sets

en
	// messenger
	'Inbox'						=> 'Inbox',
	'Compose'					=> 'Compose',
	'View'						=> 'View',
	'SentItems'					=> 'Sent Items',
	'Manage'					=> 'Manage',
	'Folders'					=> 'Folders',
	'Contacts'					=> 'Contacts',
	'Users'						=> 'Users',
	'SentMessage'				=> 'Sent Message',
	'Folder'					=> 'Folder',
	'MessageMoved'				=> 'Message moved to %1 folder.',
	'MessageNotMoved'			=> 'The message wasn\'t moved.',
	'MessageTopic'				=> 'Message Topic',
	'Sender'					=> 'Sender',
	'Date'						=> 'Date',
	'MoveToFolder'				=> 'Move to Folder',
	'Delete'					=> 'Delete',
	'MessageDeleted'			=> 'The message was deleted.',
	'MessageNotDeleted'			=> 'The message was not deleted.',
	'MessageNotRead'			=> 'This message has not been read yet!',
	'UrgentMessage'				=> 'This is an urgent message!',
	'MessageReplied'			=> 'You have replied to this message!',
	'Move'						=> 'Move',
	'DeleteItem'				=> 'Are you sure you want to delete this item?',
	'ClickArrow'				=> 'Clicking on the right arrow indicator [->] will add the users name to the contacts list.',
	'AlreadyReplied'			=> 'A + sign to the right of the message title indicates that you have replied to the message.',
	'NoMessagesInbox'			=> 'There are no currently no messages in the in-box.',
	'ComposeMessage'			=> 'Compose a message',
	'Subject'					=> 'Subject',
	'Message'					=> 'Message',
	'CharactersLeft'			=> '%1 characters left.',
	'Urgent'					=> 'Urgent?',
	'ContactList'				=> 'Contact List',
	'ClickName'					=> 'click on name to add to form',
	'ReplyToMessage'			=> 'Reply to the message',
	'OriginalMessage'			=> 'Original Message',
	'Fwd'						=> 'Fwd:',
	'MessageSentTo'				=> 'Message Sent to %1!',
	'MessagingForbidden'		=> 'You must be registered and logged in to use this Private Messaging System.',
	'SentTo'					=> 'Sent to',
	'Read'						=> 'Read?',
	'NoMessagesFolder'			=> 'There are no messages currently stored in this folder.',
	'Re'						=> 'Re:',
	'Reply'						=> 'Reply',
	'Forward'					=> 'Forward',
	'ForwardMessage'			=> 'Forward message',
	'Recipient'					=> 'Recipient',
	'ChooseRecipient'			=> 'Choose a recipient',
	'MessageDeleted'			=> 'Message was deleted.',
	'MessageNotDeleted'			=> 'The message was not deleted.',
	'ContactNames'				=> 'Contact Names',
	'Notes'						=> 'Notes',
	'Send'						=> 'Send',
	'Add'						=> 'Add',
	'ClickContact'				=> 'Clicking on the contact name will take you to message entry screen.',
	'ClickContact2'				=> 'Click on the name to add it to the contact list.',
	'FolderList'				=> 'Folder Management',
	'ClickFolder'				=> 'Clicking on the folder name will take you to that folder.',


de
	// messenger
	'Inbox'						=> 'Posteingang',
	'Compose'					=> 'Verfassen',
	'View'						=> 'Anzeigen',
	'SentItems'					=> 'Postausgang',
	'Manage'					=> 'Verwalten',
	'Folders'					=> 'Ordner',
	'Contacts'					=> 'Kontaktliste',
	'Users'						=> 'Benutzer',
	'SentMessage'				=> 'gesendete Nachrichten',
	'Folder'					=> 'Ordner',
	'MessageMoved'				=> 'Die Nachricht wurde in Ordner %1 verschoben.',
	'MessageNotMoved'			=> 'Die Nachricht wurde nicht verschoben!',
	'MessageTopic'				=> 'Message Topic',
	'Sender'					=> 'Absender',
	'Date'						=> 'Datum',
	'MoveToFolder'				=> 'Verschieben in Ordner',
	'Delete'					=> 'Löschen',
	'MessageDeleted'			=> 'Die Nachricht wurde gelöscht.',
	'MessageNotDeleted'			=> 'Die Nachricht wurde nicht gelöscht.',
	'MessageNotRead'			=> 'Diese Nachricht wurde noch nicht gelesen!',
	'UrgentMessage'				=> 'Dies ist eine dringende Nachricht!',
	'MessageReplied'			=> 'Auf diese Nachricht wurde bereits geantwortet!',
	'Move'						=> 'Verschieben',
	'DeleteItem'				=> 'Bist Du sicher, dass Du diesen Eintrag löschen möchtest?',
	'ClickArrow'				=> 'Wenn Sie auf die rechte Pfeilanzeige [->] klicken, wird der Name des Benutzers in die Kontaktliste aufgenommen.',
	'AlreadyReplied'			=> 'Ein +-Zeichen rechts neben dem Nachrichtentitel zeigt an, dass du auf die Nachricht geantwortet hast.',
	'NoMessagesInbox'			=> 'Zur Zeit sind keine Nachrichten im Posteingang.',
	'ComposeMessage'			=> 'Nachricht verfassen',
	'Subject'					=> 'Betreff',
	'Message'					=> 'Nachricht',
	'CharactersLeft'			=> '%1 Zeichen stehen noch zur Verfügung.',
	'Urgent'					=> 'Dringend?',
	'ContactList'				=> 'Kontakt-Liste',
	'ClickName'					=> 'Klick auf den Namen um den Benutzer als Empfänger einzusetzen',
	'ReplyToMessage'			=> 'Antwort erstellen',
	'OriginalMessage'			=> 'Ursprüngliche Nachricht',
	'Fwd'						=> 'Fwd:',
	'MessageSentTo'				=> 'Nachricht gesendet an %1!',
	'MessagingForbidden'		=> 'Du must registriert und angemeldet sein um das Message-System nutzen zu können!',
	'SentTo'					=> 'Sent to',
	'Read'						=> 'Gelesen',
	'NoMessagesFolder'			=> 'Zur Zeit sind keine Nachrichten in diesem Ordner!',
	'Re'						=> 'Re:',
	'Reply'						=> 'Antworten',
	'Forward'					=> 'Weiterleiten',
	'ForwardMessage'			=> 'Nachricht weiterleiten',
	'Recipient'					=> 'Empfänger',
	'ChooseRecipient'			=> 'Wähle einen Empfänger',
	'MessageDeleted'			=> 'Nachricht wurde gelöscht.',
	'MessageNotDeleted'			=> 'Die Nachricht wurde nicht gelöscht.',
	'ContactNames'				=> 'Name',
	'Notes'						=> 'Beschreibung',
	'Send'						=> 'Abschicken',
	'Add'						=> 'Hinzufügen',
	'ClickContact'				=> 'Klick auf den Benutzernamen um einem Benutzer aus der Kontaktliste eine Nachricht zu schreiben.',
	'ClickContact2'				=> 'Klick auf den Namen um den User zu Deiner Kontaktliste hinzuzufügen.',
	'FolderList'				=> 'Ordner verwalten',
	'ClickFolder'				=> 'Klick auf den Ordnernamen um einen Ordner zu öffnen!',

3. Notify there are messages in the Box


You might wish to have a little icon appearing besite your Username after loging in, if you have still messages in your inbox. Here is a codesnippet wo do this for you.

Die nachfolgende Codezeile kann z.B. in die header.php eingefügt werden. Bekommt der Nutzer eine neue Nachricht, wird das dann an der entsprechende Stelle angezeigt sobald er sich anmeldet.


<?php
if ($this->db->load_all(
         
"SELECT status
         FROM 
{$this->db->table_prefix}messenger
         WHERE user_to_id = " 
. (int) $this->get_user_id() . "
             AND folder = 'inbox'
             AND status = 'pending'
             AND viewrecipient = '1'
         LIMIT 1"
)) != 0)
{
         echo 
'<a title="Du hast neue Nachrichten."><span class="cite"><strong>Neue Nachricht</strong></span></a>';
}

4. Changelog

0.1 Intitial version
0.2 Ported to WackoWiki, removed filter function
0.3 Ported to R6.0
0.4 Adds template and localizes message sets

5. ToDo