-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage.php
131 lines (107 loc) · 4.32 KB
/
message.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/**
* Message page
*
* @copyright Copyright Madfish (Simon Wilkinson) 2011
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License (GPL)
* @since 1.0
* @author Madfish (Simon Wilkinson) <simon@isengard.biz>
* @package contact
* @version $Id$
*/
/**
* Edit a Message
*
* @param int $message_id Messageid to be edited
*/
function editmessage($clean_message_id = 0) {
global $contact_message_handler, $icmsTpl;
$module = icms::handler("icms_module")->getByDirname(basename(dirname(__FILE__)), TRUE);
$messageObj = $contact_message_handler->get($clean_message_id);
if ($messageObj->isNew()) {
$sform = $messageObj->getSecureForm(_CO_CONTACT_MESSAGE_CREATE, 'addmessage', FALSE,
_CO_CONTACT_SUBMIT_MAIL);
// add captcha, if required
if ($module->config['use_captcha'] == TRUE) {
$sform->addElement(new icms_form_elements_Captcha(_SECURITYIMAGE_GETCODE, 'scode'));
}
$sform->assign($icmsTpl, 'contact_messageform');
} else {
exit;
}
}
include_once 'header.php';
$xoopsOption['template_main'] = 'contact_message.html';
include_once ICMS_ROOT_PATH . '/header.php';
$module = icms::handler("icms_module")->getByDirname(basename(dirname(__FILE__)), TRUE);
$dirty_op = $clean_op = '';
$clean_message_id = 0;
$valid_op = array ('mod', 'addmessage','confirmsent', '');
$contact_message_handler = icms_getModuleHandler('message', basename(dirname(__FILE__)), 'contact');
// check the option
if (isset($_GET['op'])) $dirty_op = trim($_GET['op']);
if (isset($_POST['op'])) $dirty_op = trim($_POST['op']);
// proceed only if the option is valid (whitelisted)
if (in_array($dirty_op, $valid_op, TRUE)){
$clean_op = $dirty_op;
switch ($clean_op) {
// show an empty message form
case "mod":
editmessage();
break;
// submit the message form and store in the database
case "addmessage":
$ret = 'message.php?op=confirmsent';
$controller = new icms_ipf_Controller($contact_message_handler);
///////////////////////////////////////////////////////////////////////////////////////
///// Verify captcha code, based on McDonald's implementation in Impression 1.0.2 /////
///////////////////////////////////////////////////////////////////////////////////////
if ($module->config['use_captcha'] == TRUE) {
$icmsCaptcha = icms_form_elements_captcha_Object::instance();
if (!$icmsCaptcha->verify(FALSE)) {
redirect_header('message.php?op=mod', 2, $icmsCaptcha->getMessage());
exit;
}
}
///////////////////////////////////////////////////////////////////////////////////////
$controller->storeFromDefaultForm(_CO_CONTACT_MESSAGE_CREATED,
_CO_CONTACT_MESSAGE_MODIFIED, $ret);
break;
// Confirmation message and email to the addresses specified in the module's preferences
case "confirmsent":
$mailaddress = $mailsubject = $mailbody = $headers = '';
$contact_message_handler = icms_getModuleHandler('message', basename(dirname(__FILE__)),
'contact');
// Retrieve the last saved message as an object
$criteria = new icms_db_criteria_Compo();
$criteria->setSort('message_id');
$criteria->setOrder('DESC');
$criteria->setLimit(1);
$messageObj = $contact_message_handler->getObjects($criteria);
$messageObj = $messageObj[0];
// Send message as email - maybe should try/catch this?
$mailaddress = str_replace(' ', '', $module->config['primary_contact']);
$mailcreator = $messageObj->getVar('creator');
$mailsubject = $messageObj->getVar('title');
$mailbody = $messageObj->getVar('description', 'e');
$mailbody = trim($mailbody);
$headers = "From: " . $mailcreator . "<" . $mailcreator . ">\r\nContent-type: text/plain\r\n";
mail($mailaddress, $mailsubject, $mailbody, $headers);
// Display confirmation message
$icmsTpl->assign('contact_messagesent', TRUE);
break;
default: // Show an empty message form
editmessage();
break;
}
}
// Check if the module's breadcrumb should be displayed
if ($module->config['show_breadcrumb'] == TRUE) {
$icmsTpl->assign('contact_show_breadcrumb', $module->config['show_breadcrumb']);
} else {
$icmsTpl->assign('contact_show_breadcrumb', FALSE);
$icmsTpl->assign('contact_page_title', _CO_CONTACT_MODULE_NAME);
}
$icmsTpl->assign("contact_module_home", '<a href="' . ICMS_URL . "/modules/"
. icms::$module->getVar("dirname") . '/">' . icms::$module->getVar("name") . "</a>");
include_once 'footer.php';