IMAGE_DIR . "/mail_mark_unread_new.png", 'read' => IMAGE_DIR . "/mail_mark_read.png" ); /************************************/ /* Title */ /************************************/ print_title($_SESSION[$_PAGE_INFO['id']]['title']); /************************************/ /* New/reply/delete message button */ /************************************/ $msg_buttons = array(); if (!is_valid_action("messages_read","messages_new")) { $msg_buttons['but_new'] = _("New message"); } if (is_valid_action("messages_read")) { $msg_buttons['but_delete'] = _("Delete message"); $msg_buttons['but_reply'] = _("Reply message"); } if( $msg_buttons ) print_save_buttons($msg_buttons, array('style' => "padding-top: 0px;")); if (is_valid_action("messages_inbox")) { // Clear old session info unset($_SESSION[$_PAGE_INFO['id']]['messages_info']); // Retrieve all received messages $messages = db_fetch_messages_user($_SESSION[$_PAGE_INFO['id']]['login']['user']['id']); $prev_date = FALSE; if( $messages ) { print_hidden_input("messages", FALSE); print_embedded_table_start(FALSE, FALSE, array('css_class' => "inbox")); foreach( $messages as $item ) { if( ($date = strip_time($item['datum'])) != $prev_date || !$prev_date ) { print_embedded_table_row_start($row = 0); print_embedded_table_cell($date, array('css_class' => "date", 'colspan' => 2)); $row++; $prev_date = $date; } $status = ($item['status'] == "marked") ? 'new' : 'read'; $subject = trim(strip_tags($item['onderwerp'])); if( !$subject ) { $subject = _("No subject"); $subject_style = "font-style: italic;"; } else $subject_style = FALSE; if( ($user = db_fetch_user($item['van'], "", 1)) ) { $cust = db_fetch_customer($user['klant'], 1); } $from = _("From") . ": "; if( $user ) { $from .= getUser($user['id']); $from .= " (" . $cust['klantnaam'] . ")"; } else $from .= _("Unknown"); $encrypted_id = encrypt($item['id'], "msg_id_" . $_SESSION[$_PAGE_INFO['id']]['login']['user']['id']); print_embedded_table_row_start($row, array('css_class' => "message ". $status)); print_embedded_table_cell( "", array( 'css_class' => "status " . $status, 'rowspan' => 2, 'icon' => array( 'src' => $icons[$status], 'href' => "?id=" . $_PAGE_INFO['id'] . "&href=page/menu_messages&action=messages_read&msg_id=" . urlencode($encrypted_id) . $page_project ) ) ); print_embedded_table_cell( $subject, array( 'css_class' => "subject " . $status, 'style' => $subject_style, 'href' => "?id=" . $_PAGE_INFO['id'] . "&href=page/menu_messages&action=messages_read&msg_id=" . urlencode($encrypted_id) . $page_project ) ); print_embedded_table_row_start($row, array('css_class' => "message ". $status)); print_embedded_table_cell($from, array('css_class' => "from " . $status)); $row++; } print_embedded_table_end(); } else print_text(_("No messages")); } 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) if( $_GET['msg_id'] ) { $msg_id = decrypt($_GET['msg_id'], "msg_id_" . $_SESSION[$_PAGE_INFO['id']]['login']['user']['id']); } else { $msg_id = $_SESSION[$_PAGE_INFO['id']]['messages_info']['messages']; } // Replace 'info' for the "message read" action, but maintain the message identifier // (I think...) $backup = $_SESSION[$_PAGE_INFO['id']]['messages_info']; $_SESSION[$_PAGE_INFO['id']]['messages_info'] = db_fetch_message($msg_id); // Restore message identifier $_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 */ /************************************/ // Default value if( !isset($_SESSION[$_PAGE_INFO['id']]['messages_info']['klant']) ) { $_SESSION[$_PAGE_INFO['id']]['messages_info']['klant'] = $_SESSION[$_PAGE_INFO['id']]['login']['customer']['id']; } // Collect all customers down the pyramid $row_customers = db_search_customers(); // Add customers down the pyramid $customer_list = array(); if( $row_customers ) foreach( $row_customers as $item ) $customer_list[$item['id']] = strip_tags($item['bedrijfsnaam']) . " (" . strip_tags($item['klantnaam']) . ")"; // When contact person => Add customer above (when available!) if( is_array(db_fetch_contact_user($_SESSION[$_PAGE_INFO['id']]['login']['user']['id'])) ) { // Collect all customers up the pyramid $row_customers_up = db_search_customers("", "up"); if( $row_customers_up ) foreach( $row_customers_up as $item ) if( !isset($customer_list[$item['id']]) ) $customer_list[$item['id']] = strip_tags($item['bedrijfsnaam']) . " (" . strip_tags($item['klantnaam']) . ")"; } print_dropdownlist( _("To"), "klant", $_SESSION[$_PAGE_INFO['id']]['messages_info']['klant'], $customer_list, FALSE, NULL, array('onchange' => "onSubmit('list_customer', '', 1);") ); /************************************/ /* To user */ /************************************/ $row_users = db_fetch_users($_SESSION[$_PAGE_INFO['id']]['messages_info']['klant']); // Default: myself (huh?) if( !isset($_SESSION[$_PAGE_INFO['id']]['messages_info']['naar']) ) { $_SESSION[$_PAGE_INFO['id']]['messages_info']['naar'] = $_SESSION[$_PAGE_INFO['id']]['login']['user']['id']; } // Fill listbox $user_list = array(); if( $row_users ) foreach ($row_users as $row_user) $user_list[$row_user['id']] = strip_tags(getUser($row_user['id'])); $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); print_dropdownlist( "", "naar", $_SESSION[$_PAGE_INFO['id']]['messages_info']['naar'], $user_list, FALSE, $info ); } /************************************/ /* 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")) { $buttons = array( 'but_ok' => _("Send"), 'but_cancel' => _("Cancel") ); print_save_buttons($buttons); } } print_form_end(); ?>