From 615a0a96618fa99e7e452523145d6c0f238d4473 Mon Sep 17 00:00:00 2001
From: tbrehm <t.brehm@ispconfig.org>
Date: Wed, 31 Jul 2013 09:33:43 -0400
Subject: [PATCH] Merged revisions 3960-4065 from stable branch.

---
 interface/web/help/support_message_edit.php |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 58 insertions(+), 0 deletions(-)

diff --git a/interface/web/help/support_message_edit.php b/interface/web/help/support_message_edit.php
index c6e992f..b1cbf2a 100644
--- a/interface/web/help/support_message_edit.php
+++ b/interface/web/help/support_message_edit.php
@@ -31,6 +31,53 @@
 		//* Set the sender_id field to the ID of the current user
 		$this->dataRecord['sender_id'] = $_SESSION['s']['user']['userid'];
 		
+		//* Get recipient email address
+		if($this->dataRecord['recipient_id'] > 1){
+			$sql = "SELECT client.email FROM sys_user, client WHERE sys_user.userid = ".$this->dataRecord['recipient_id']." AND sys_user.client_id = client.client_id";
+			$client = $app->db->queryOneRecord($sql);
+			$recipient_email = $client['email'];
+		} else {
+			$app->uses('ini_parser,getconf');
+			$system_config_mail_settings = $app->getconf->get_global_config('mail');
+			$recipient_email = $system_config_mail_settings['admin_mail'];
+		}
+		
+		//* Get sender email address
+		if($this->dataRecord['sender_id'] > 1){
+			$sql = "SELECT client.email FROM sys_user, client WHERE sys_user.userid = ".$this->dataRecord['sender_id']." AND sys_user.client_id = client.client_id";
+			$client = $app->db->queryOneRecord($sql);
+			$sender_email = $client['email'];
+		} else {
+			$app->uses('ini_parser,getconf');
+			$system_config_mail_settings = $app->getconf->get_global_config('mail');
+			$sender_email = $system_config_mail_settings['admin_mail'];
+		}
+		
+		$email_regex = '/^(\w+[\w\.\-\+]*\w{0,}@\w+[\w.-]*\.[a-z\-]{2,10}){0,1}$/i';
+		if(preg_match($email_regex, $sender_email, $match) && preg_match($email_regex, $recipient_email, $match)){
+			$subject = $app->tform->lng('support_request_subject_txt').': '.$this->dataRecord['subject'];
+			if($this->dataRecord['recipient_id'] == 1){
+				$message = $app->tform->lng('support_request_txt');
+			} else {
+				$message = $app->tform->lng('answer_to_support_request_txt');
+			}
+			$message .= "\n\n".$app->tform->lng('message_txt').": \"".$this->dataRecord['message']."\"";
+			$message .= "\n\nISPConfig: ".($_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://').$_SERVER['HTTP_HOST'];
+			$app->functions->mail($recipient_email, $subject, $message, $sender_email);
+			
+			//* Send confirmation email to sender
+			if($this->dataRecord['sender_id'] == 1){
+				$confirmation_message = $app->tform->lng('answer_to_support_request_sent_txt');
+			} else {
+				$confirmation_message = $app->tform->lng('support_request_sent_txt');
+			}
+			$confirmation_message .= "\n\n".$app->tform->lng('message_txt').": \"".$this->dataRecord['message']."\"";
+			$confirmation_message .= "\n\nISPConfig: ".($_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://').$_SERVER['HTTP_HOST'];
+			$app->functions->mail($sender_email, $subject, $confirmation_message, $recipient_email);
+		} else {
+			$app->tform->errorMessage .= $app->tform->lng("recipient_or_sender_email_address_not_valid_txt")."<br />";
+		}
+		
 		//* call the onSubmit function of the parent class
 		parent::onSubmit();
 	}
@@ -44,6 +91,17 @@
 		//*  read only template  if a existing message is loaded
 		if($this->id > 0) {
 			$app->tform->formDef['tabs']['message']['template'] = 'templates/support_message_view.htm';
+			$record = $app->db->queryOneRecord("SELECT * FROM support_message WHERE support_message_id = ".$this->id);
+			if ($record['tstamp'] > 0) {
+							// is value int?
+							if (preg_match("/^[0-9]+[\.]?[0-9]*$/", $record['tstamp'], $p)) {
+	                        	$record['tstamp'] = date($app->lng('conf_format_datetime'), $record['tstamp']);
+							} else {
+	                        	$record['tstamp'] = date($app->lng('conf_format_datetime'), strtotime($record['tstamp']));
+							}
+						}
+			$app->tpl->setVar("date", $record['tstamp']);
+			//die(print_r($this->dataRecord));
 		}
 		
 		//* call the onShow function of the parent class

--
Gitblit v1.9.1