commit | author | age
|
aa1724
|
1 |
<?php |
T |
2 |
|
|
3 |
//* Set the path to the form definition file. |
c3859c
|
4 |
$tform_def_file = 'form/support_message.tform.php'; |
aa1724
|
5 |
|
T |
6 |
//* include the basic application and configuration files |
7fe908
|
7 |
require_once '../../lib/config.inc.php'; |
MC |
8 |
require_once '../../lib/app.inc.php'; |
aa1724
|
9 |
|
910093
|
10 |
//* Check permissions for module |
T |
11 |
$app->auth->check_module_permissions('help'); |
aa1724
|
12 |
|
T |
13 |
//* Loading the templating and form classes |
|
14 |
$app->uses('tpl,tform,tform_actions'); |
|
15 |
$app->load('tform_actions'); |
|
16 |
|
|
17 |
//* Creating a class page_action that extends the tform_actions base class |
|
18 |
class page_action extends tform_actions { |
|
19 |
|
|
20 |
//* Custom onSubmit Event handler |
c3859c
|
21 |
function onSubmit() |
7fe908
|
22 |
{ |
aa1724
|
23 |
global $app, $conf; |
7fe908
|
24 |
|
aa1724
|
25 |
//* If the current user is not the admin user |
c3859c
|
26 |
if($_SESSION['s']['user']['typ'] != 'admin') { |
aa1724
|
27 |
//* Set the admin as recipient |
c3859c
|
28 |
$this->dataRecord['recipient_id'] = 1; |
aa1724
|
29 |
} |
7fe908
|
30 |
|
c3859c
|
31 |
//* Set the sender_id field to the ID of the current user |
P |
32 |
$this->dataRecord['sender_id'] = $_SESSION['s']['user']['userid']; |
7fe908
|
33 |
|
615a0a
|
34 |
//* Get recipient email address |
T |
35 |
if($this->dataRecord['recipient_id'] > 1){ |
cc7a82
|
36 |
$sql = "SELECT client.email FROM sys_user, client WHERE sys_user.userid = ? AND sys_user.client_id = client.client_id"; |
MC |
37 |
$client = $app->db->queryOneRecord($sql, $this->dataRecord['recipient_id']); |
615a0a
|
38 |
$recipient_email = $client['email']; |
T |
39 |
} else { |
|
40 |
$app->uses('ini_parser,getconf'); |
|
41 |
$system_config_mail_settings = $app->getconf->get_global_config('mail'); |
|
42 |
$recipient_email = $system_config_mail_settings['admin_mail']; |
|
43 |
} |
7fe908
|
44 |
|
615a0a
|
45 |
//* Get sender email address |
T |
46 |
if($this->dataRecord['sender_id'] > 1){ |
cc7a82
|
47 |
$sql = "SELECT client.email FROM sys_user, client WHERE sys_user.userid = ? AND sys_user.client_id = client.client_id"; |
MC |
48 |
$client = $app->db->queryOneRecord($sql, $this->dataRecord['sender_id']); |
615a0a
|
49 |
$sender_email = $client['email']; |
T |
50 |
} else { |
|
51 |
$app->uses('ini_parser,getconf'); |
|
52 |
$system_config_mail_settings = $app->getconf->get_global_config('mail'); |
|
53 |
$sender_email = $system_config_mail_settings['admin_mail']; |
|
54 |
} |
7fe908
|
55 |
|
615a0a
|
56 |
$email_regex = '/^(\w+[\w\.\-\+]*\w{0,}@\w+[\w.-]*\.[a-z\-]{2,10}){0,1}$/i'; |
T |
57 |
if(preg_match($email_regex, $sender_email, $match) && preg_match($email_regex, $recipient_email, $match)){ |
|
58 |
$subject = $app->tform->lng('support_request_subject_txt').': '.$this->dataRecord['subject']; |
|
59 |
if($this->dataRecord['recipient_id'] == 1){ |
|
60 |
$message = $app->tform->lng('support_request_txt'); |
|
61 |
} else { |
|
62 |
$message = $app->tform->lng('answer_to_support_request_txt'); |
|
63 |
} |
|
64 |
$message .= "\n\n".$app->tform->lng('message_txt').": \"".$this->dataRecord['message']."\""; |
|
65 |
$message .= "\n\nISPConfig: ".($_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://').$_SERVER['HTTP_HOST']; |
|
66 |
$app->functions->mail($recipient_email, $subject, $message, $sender_email); |
7fe908
|
67 |
|
615a0a
|
68 |
//* Send confirmation email to sender |
T |
69 |
if($this->dataRecord['sender_id'] == 1){ |
|
70 |
$confirmation_message = $app->tform->lng('answer_to_support_request_sent_txt'); |
|
71 |
} else { |
|
72 |
$confirmation_message = $app->tform->lng('support_request_sent_txt'); |
|
73 |
} |
|
74 |
$confirmation_message .= "\n\n".$app->tform->lng('message_txt').": \"".$this->dataRecord['message']."\""; |
|
75 |
$confirmation_message .= "\n\nISPConfig: ".($_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://').$_SERVER['HTTP_HOST']; |
52a8e7
|
76 |
if ($this->dataRecord['subject'] != '' && $this->dataRecord['message'] != '') $app->functions->mail($sender_email, $subject, $confirmation_message, $recipient_email); |
615a0a
|
77 |
} else { |
T |
78 |
$app->tform->errorMessage .= $app->tform->lng("recipient_or_sender_email_address_not_valid_txt")."<br />"; |
|
79 |
} |
7fe908
|
80 |
|
aa1724
|
81 |
//* call the onSubmit function of the parent class |
T |
82 |
parent::onSubmit(); |
|
83 |
} |
7fe908
|
84 |
|
aa1724
|
85 |
//* Custom onShow Event handler |
7fe908
|
86 |
function onShow() |
MC |
87 |
{ |
aa1724
|
88 |
global $app, $conf; |
T |
89 |
|
7fe908
|
90 |
//* We do not want that messages get edited, so we switch to a |
c3859c
|
91 |
//* read only template if a existing message is loaded |
aa1724
|
92 |
if($this->id > 0) { |
T |
93 |
$app->tform->formDef['tabs']['message']['template'] = 'templates/support_message_view.htm'; |
cc7a82
|
94 |
$record = $app->db->queryOneRecord("SELECT * FROM support_message WHERE support_message_id = ?", $this->id); |
615a0a
|
95 |
if ($record['tstamp'] > 0) { |
7fe908
|
96 |
// is value int? |
MC |
97 |
if (preg_match("/^[0-9]+[\.]?[0-9]*$/", $record['tstamp'], $p)) { |
|
98 |
$record['tstamp'] = date($app->lng('conf_format_datetime'), $record['tstamp']); |
|
99 |
} else { |
|
100 |
$record['tstamp'] = date($app->lng('conf_format_datetime'), strtotime($record['tstamp'])); |
|
101 |
} |
|
102 |
} |
615a0a
|
103 |
$app->tpl->setVar("date", $record['tstamp']); |
T |
104 |
//die(print_r($this->dataRecord)); |
aa1724
|
105 |
} |
7fe908
|
106 |
|
aa1724
|
107 |
//* call the onShow function of the parent class |
T |
108 |
parent::onShow(); |
|
109 |
} |
7fe908
|
110 |
|
MC |
111 |
function onAfterInsert() |
|
112 |
{ |
51beda
|
113 |
global $app, $conf; |
7fe908
|
114 |
|
51beda
|
115 |
if($_SESSION['s']['user']['typ'] == 'admin') { |
cc7a82
|
116 |
$app->db->query("UPDATE support_message SET sys_userid = ? WHERE support_message_id = ?", $this->dataRecord['recipient_id'], $this->id); |
51beda
|
117 |
} |
7fe908
|
118 |
|
51beda
|
119 |
} |
7fe908
|
120 |
|
aa1724
|
121 |
} |
T |
122 |
|
|
123 |
//* Create the new page object |
|
124 |
$page = new page_action(); |
|
125 |
|
|
126 |
//* Start the page rendering and action handling |
|
127 |
$page->onLoad(); |
|
128 |
|
7fe908
|
129 |
?> |