src.dualinventive.com/mtinfo/dist/webroot/main/scripts/page/menu_messages_content.php

263 lines
11 KiB
PHP

<?php
/** \file scripts\page\menu_messages_content.php
* \brief DI webinterface menu messages content script.
* \author Rob Schalken, Core|Vision
* \version 1.0
* \date 17-10-2008
*
* This file contains the menu messages content script. This file creates the message menu.
* Here the user can send/receive messages
*/
echo "<form id=\"form\" name=\"form\" action=\"javascript:FormAction('action/_a_menu_messages');\" autocomplete=\"off\" method=\"post\" enctype=\"multipart/form-data\">\n";
echo "<table class=\"form_table\" align=\"center\">\n";
/************************************/
/* Title */
/************************************/
print_title($_SESSION[$_PAGE_INFO['id']]['title']);
/************************************/
/* New/reply/delete message button */
/************************************/
echo "<tr>\n";
echo "<td></td>\n";
echo "<td></td>\n";
print_button_padding();
if (!is_valid_action("messages_read","messages_new")) {
echo "<input class=\"button\" type=\"button\" value=\"" . _("New message") . "\" onClick=\"onSubmit('but_new', '', 1);\">\n";
}
if (is_valid_action("messages_read")) {
echo "<input class=\"button\" type=\"button\" value=\"" . _("Delete message") . "\" onClick=\"onSubmit('but_delete', '', 1);\">\n";
echo "<input class=\"button\" type=\"button\" value=\"" . _("Reply message") . "\" onClick=\"onSubmit('but_reply', '', 1);\">\n";
}
echo "</td>\n";
echo "</tr>\n";
if (is_valid_action("messages_inbox")) {
// Clear old session info
unset($_SESSION[$_PAGE_INFO['id']]['messages_info']);
// Fill arrays
$previous_date = "";
$id = "";
$id[0] = "";
$opt = "";
$opt[0] = "";
$value = "";
$value[0] = array("Subject", "From");
// Retrieve all received messages
$messages = db_fetch_messages_user($_SESSION[$_PAGE_INFO['id']]['login']['user']['id']);
if (is_array($messages)) {
foreach($messages as $item) {
if ($previous_date != strip_time($item['datum'])) {
// Store values
array_push($opt, 1);
array_push($id, "");
array_push($value, array(strip_time($item['datum'])));
$previous_date = strip_time($item['datum']);
}
array_push($opt, 0);
array_push($id, $item['id']);
$color = ($item['status'] == "marked") ? "unread" : "";
$bold = ($item['status'] == "marked") ? 1 : 0;
$user = db_fetch_user($item['van'], "", 1);
// Existing user?
if (is_array($user)) {
$cust = db_fetch_customer($user['klant'], 1);
$from = (is_array($user)) ? getUser($user['id']) : _("Unknown");
$from .= (is_array($cust)) ? " (" . $cust['klantnaam'] . ")" : "";
array_push($value, array((strlen($item['onderwerp'])) ? htmlspecialchars(strip_tags($item['onderwerp'])) : "<" . _("no subject") . ">", $from, color => $color, bold => $bold));
}
}
}
print_table("", "messages", $value, $opt, $id, array(43, 50), array("L","L"), "", "onSubmit('read_message', '', 1);", 15, $_SESSION[$_PAGE_INFO['id']]['messages_info']['messages'], 0, 1);
}
else if (is_valid_action("messages_new", "messages_read")) {
if ((is_valid_action("messages_read")) && (!$_SESSION[$_PAGE_INFO['id']]['recall_counter'])) {
// Determine message (and restore message id)
$backup = $_SESSION[$_PAGE_INFO['id']]['messages_info'];
$_SESSION[$_PAGE_INFO['id']]['messages_info'] = db_fetch_message($_SESSION[$_PAGE_INFO['id']]['messages_info']['messages']);
$_SESSION[$_PAGE_INFO['id']]['messages_info']['messages'] = $backup['messages'];
}
if (is_valid_action("messages_read")) {
// Add hidden input => delete message requires id
print_hidden_input("messages",$_SESSION[$_PAGE_INFO['id']]['messages_info']['messages']);
// Add hidden input => repply message requires id
print_hidden_input("van",$_SESSION[$_PAGE_INFO['id']]['messages_info']['van']);
/************************************/
/* From */
/************************************/
$user = db_fetch_user($_SESSION[$_PAGE_INFO['id']]['messages_info']['van'], "", 1);
$cust = db_fetch_customer($user['klant'], 1);
$from = (is_array($user)) ? getUser($user['id']) : _("Unknown");
$from .= (is_array($cust)) ? " (" . $cust['klantnaam'] . ")" : "";
print_input("From", "", $from, array("messages_read"));
/************************************/
/* Date */
/************************************/
print_input("Date", "datum", $_SESSION[$_PAGE_INFO['id']]['messages_info']['datum'], array("messages_read"));
}
if (is_valid_action("messages_new")) {
/************************************/
/* To company */
/************************************/
echo "<tr>\n";
echo "<td></td>\n";
echo "<td><p>" . _("To") . "</p></td>\n";
echo "<td>";
// Collect all customers down the pyramid
$row_customers = db_search_customers();
// When contact person => Add customer above (when available!)
if (is_array(db_fetch_contact_user($_SESSION[$_PAGE_INFO['id']]['login']['user']['id']))) {
$cust_ids = array();
if (is_array($row_customers)) {
foreach ($row_customers as $item) {
array_push($cust_ids, $item['id']);
}
}
// Collect all customers up the pyramid
$row_customers_up = db_search_customers("", "up");
if (is_array($row_customers_up)) {
foreach ($row_customers_up as $item) {
if (!in_array($item['id'], $cust_ids)) {
array_push($row_customers, $item);
}
}
}
}
// Default value
$_SESSION[$_PAGE_INFO['id']]['messages_info']['klant'] = (isset($_SESSION[$_PAGE_INFO['id']]['messages_info']['klant'])) ? $_SESSION[$_PAGE_INFO['id']]['messages_info']['klant'] : $_SESSION[$_PAGE_INFO['id']]['login']['customer']['id'];
echo "<select name=\"klant\" size=\"1\" onChange=\"onSubmit('list_customer', '', 1);\">\n";
// Fill listbox
if (is_array($row_customers)) {
foreach ($row_customers as $row_customer) {
echo "<option value=\"" . $row_customer['id'] . "\"";
// Selected item?
if ($_SESSION[$_PAGE_INFO['id']]['messages_info']['klant'] == $row_customer['id']) {
echo "selected=select ";
}
echo ">";
echo htmlspecialchars($row_customer['bedrijfsnaam']) . " (" . htmlspecialchars($row_customer['klantnaam']) . ")";
}
}
echo "</select>\n";
echo "</td>\n";
echo "</tr>\n";
/************************************/
/* To user */
/************************************/
echo "<tr>\n";
echo "<td></td>\n";
echo "<td></td>\n";
echo "<td>\n";
if ((isset($_SESSION[$_PAGE_INFO['id']]['messages_info']['klant'])) && (strlen($_SESSION[$_PAGE_INFO['id']]['messages_info']['klant']))) {
$row_users = db_fetch_users($_SESSION[$_PAGE_INFO['id']]['messages_info']['klant']);
}
else {
$row_users = db_search_users();
}
echo "<select name=\"naar\" size=\"1\">\n";
// Fill listbox
if (is_array($row_users)) {
foreach ($row_users as $row_user) {
$customer = db_fetch_customer($row_user['klant'],1);
echo "<option value=\"" . $row_user['id'] . "\"";
// Selected item?
if ($_SESSION[$_PAGE_INFO['id']]['messages_info']['naar'] == $row_user['id']) {
echo "selected=select ";
}
else if (!isset($_SESSION[$_PAGE_INFO['id']]['messages_info']['naar'])) {
if ($_SESSION[$_PAGE_INFO['id']]['login']['user']['id'] == $row_user['id']) {
echo "selected=\"selected\"";
}
}
echo ">";
echo htmlspecialchars(getUser($row_user['id']));
}
}
echo "</select>\n";
$info = "";
// Required for new/change message
if (isset($_SESSION[$_PAGE_INFO['id']]['messages_info'])) {
// Check if the correct recall function was set
if (is_valid_recall("but_ok")) {
if (!strlen($_SESSION[$_PAGE_INFO['id']]['messages_info']['naar'])) {
$info = "Required field!";
}
else {
$info = "*";
}
}
else if (is_valid_recall()) {
// Different recall => restore old value
$info = $_SESSION[$_PAGE_INFO['id']]['messages_info']['naar_info'];
}
else {
$info = "*";
}
}
else {
$info = "*";
}
// Print info message
print_info("naar", $info);
echo "</td>\n";
echo "</tr>\n";
}
/************************************/
/* Subject */
/************************************/
// Check if subject is available when reading messages
if (is_valid_action("messages_read")) {
$_SESSION[$_PAGE_INFO['id']]['messages_info']['onderwerp'] = (strlen($_SESSION[$_PAGE_INFO['id']]['messages_info']['onderwerp'])) ? $_SESSION[$_PAGE_INFO['id']]['messages_info']['onderwerp'] : "<" . _("no subject") . ">";
}
print_input("Subject", "onderwerp", $_SESSION[$_PAGE_INFO['id']]['messages_info']['onderwerp'], array("messages_read"));
/************************************/
/* Message */
/************************************/
print_textarea("Message", "tekst", $_SESSION[$_PAGE_INFO['id']]['messages_info']['tekst'], 15, array("messages_read"));
/************************************/
/* Buttons */
/************************************/
if (is_valid_action("messages_new")) {
echo "<tr>\n";
echo "<td></td>\n";
echo "<td></td>\n";
print_button_padding();
echo "<input class=\"button\" type=\"button\" value=\"" . _("Send") . "\" onClick=\"onSubmit('but_ok', '', 1);\">\n";
echo "<input class=\"button\" type=\"button\" value=\"" . _("Cancel") . "\" onClick=\"onSubmit('but_cancel', '', 1);\">\n";
echo "</td>\n";
echo "</tr>\n";
}
}
echo "</table>\n";
echo "</form>\n";
?>