XOOPS  2.6.0
pmlite.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
22 include __DIR__ . DIRECTORY_SEPARATOR . 'mainfile.php';
25 $xoops->preload()->triggerEvent('core.pmlite.start');
26 
27 $reply = !empty($_GET['reply']) ? 1 : 0;
28 $send = !empty($_GET['send']) ? 1 : 0;
29 $send2 = !empty($_GET['send2']) ? 1 : 0;
30 $sendmod = !empty($_POST['sendmod']) ? 1 : 0; // send from other modules with post data
31 $to_userid = isset($_GET['to_userid']) ? intval($_GET['to_userid']) : 0;
32 $msg_id = isset($_GET['msg_id']) ? intval($_GET['msg_id']) : 0;
33 
34 if (empty($_GET['refresh']) && isset($_POST['op']) && $_POST['op'] != "submit") {
35  $jump = "pmlite.php?refresh=" . time();
36  if ($send == 1) {
37  $jump .= "&amp;send={$send}";
38  } else {
39  if ($send2 == 1) {
40  $jump .= "&amp;send2={$send2}&amp;to_userid={$to_userid}";
41  } else {
42  if ($reply == 1) {
43  $jump .= "&amp;reply={$reply}&amp;msg_id={$msg_id}";
44  } else {
45  }
46  }
47  }
48  header('location: ' . $jump);
49  exit();
50 }
51 
52 if (!$xoops->isUser()) {
54 }
55 $xoops->simpleHeader();
56 
58 if (isset($_POST['op']) && $_POST['op'] == "submit") {
59  $member_handler = $xoops->getHandlerMember();
60  $count = $member_handler->getUserCount(new Criteria('uid', intval($_POST['to_userid'])));
61  $tpl = new XoopsTpl();
62  if ($count != 1) {
64  $error_message .= "<br />" . XoopsLocale::E_GO_BACK_AND_TRY_AGAIN;
65  $error_message .= "<br />[ <a href='javascript:history.go(-1)'>" . XoopsLocale::GO_BACK . "</a> ]";
66  $tpl->assign('error_message', $error_message);
67  } else {
68  if ($xoops->security()->check()) {
69  $pm_handler = $xoops->getHandlerPrivmessage();
70  $pm = $pm_handler->create();
71  $pm->setVar("msg_time", time());
72  if (isset($_POST['msg_image'])) {
73  $pm->setVar("msg_image", $_POST['msg_image']);
74  }
75  $pm->setVar("subject", $_POST['subject']);
76  $pm->setVar("msg_text", $_POST['message']);
77  $pm->setVar("to_userid", $_POST['to_userid']);
78  $pm->setVar("from_userid", $xoops->user->getVar("uid"));
79  if (!$pm_handler->insert($pm)) {
80  $error_message = $pm->getHtmlErrors();
81  $error_message .= "<br /><a href='javascript:history.go(-1)'>" . XoopsLocale::GO_BACK . "</a>";
82  $tpl->assign('error_message', $error_message);
83  } else {
84  // @todo: Send notification email if user has selected this in the profile
86  $info_message .= "<br />";
87  $info_message .= "<br /><a href=\"javascript:window.opener.location='" . $xoops_url . "/viewpmsg.php';window.close();\">" . XoopsLocale::CLICK_HERE_TO_VIEW_YOU_PRIVATE_MESSAGES . "</a>";
88  $info_message .= "<br /><br /><a href=\"javascript:window.close();\">" . XoopsLocale::OR_CLICK_HERE_TO_CLOSE_WINDOW . "</a>";
89  $tpl->assign('info_message', $info_message);
90  }
91  } else {
92  $error_message = implode('<br />', $xoops->security()->getErrors());
93  $error_message .= "<br /><a href=\"javascript:window.close();\">" . XoopsLocale::OR_CLICK_HERE_TO_CLOSE_WINDOW . "</a>";
94  $tpl->assign('error_message', $error_message);
95  }
96  }
97  $tpl->display("module:system/system_pmlite.tpl");
98 
99 } else {
100  $message = '';
101  $pm_uname = '';
102  if ($reply == 1 || $send == 1 || $send2 == 1 || $sendmod == 1) {
103  if ($reply == 1) {
104  $pm_handler = $xoops->getHandlerPrivmessage();
105  $pm = $pm_handler->get($msg_id);
106  if ($pm->getVar("to_userid") == $xoops->user->getVar('uid')) {
107  $pm_uname = XoopsUser::getUnameFromId($pm->getVar("from_userid"));
108  $message = "[quote]\n";
109  $message .= sprintf(XoopsLocale::CF_WROTE, $pm_uname);
110  $message .= "\n" . $pm->getVar("msg_text", "E") . "\n[/quote]";
111  } else {
112  unset($pm);
113  $reply = 0;
114  $send2 = 0;
115  }
116  }
117 
118  $tpl = new XoopsTpl();
119  $form = new Xoops\Form\ThemeForm('', 'pmform', 'pmlite.php', 'post', true);
120 
121  if ($reply == 1) {
122  $subject = $pm->getVar('subject', 'E');
123  if (!preg_match("/^" . XoopsLocale::C_RE . "/i", $subject)) {
124  $subject = XoopsLocale::C_RE . ' ' . $subject;
125  }
126  $form->addElement(new Xoops\Form\Label(XoopsLocale::C_TO, $pm_uname));
127  $form->addElement(new Xoops\Form\Hidden('to_userid', $pm->getVar("from_userid")));
128  } else {
129  if ($sendmod == 1) {
130  $form->addElement(new Xoops\Form\Label(XoopsLocale::C_TO, XoopsUser::getUnameFromId($_POST["to_userid"])));
131  $form->addElement(new Xoops\Form\Hidden('to_userid', $_POST["to_userid"]));
132  $subject = $myts->htmlSpecialChars($myts->stripSlashesGPC($_POST['subject']));
133  $message = $myts->htmlSpecialChars($myts->stripSlashesGPC($_POST['message']));
134  } else {
135  if ($send2 == 1) {
136  $form->addElement(new Xoops\Form\Label(XoopsLocale::C_TO, XoopsUser::getUnameFromId($to_userid, false)));
137  $form->addElement(new Xoops\Form\Hidden('to_userid', $to_userid));
138  } else {
139  $form->addElement(new Xoops\Form\SelectUser(XoopsLocale::C_TO, 'to_userid'));
140  }
141  $subject = "";
142  $message = "";
143  }
144  }
145  $form->addElement(new Xoops\Form\Text(XoopsLocale::SUBJECT, 'subject', 4, 100, $subject), true);
146 
147  $icons = new Xoops\Form\Radio(XoopsLocale::MESSAGE_ICON, 'msg_image', '', true);
148  $subject_icons = XoopsLists::getSubjectsList();
149  foreach (array_keys($subject_icons) as $i) {
150  $icons->addOption($i, "<img src='" . $xoops->url("images/subject/") . $i . "' alt='" . $i . "' />");
151  }
152  $form->addElement($icons, false);
153  $form->addElement(new Xoops\Form\DhtmlTextArea(XoopsLocale::MESSAGE, 'message', $message, 8, 37), true);
154  $form->addElement(new Xoops\Form\Hidden('op', 'submit'));
155 
156  $buttons = new Xoops\Form\ElementTray('');
157  $buttons ->addElement(new Xoops\Form\Button('', 'submit', XoopsLocale::A_SUBMIT, 'submit'));
158  $buttons ->addElement(new Xoops\Form\Button('', 'reset', XoopsLocale::A_CLEAR, 'reset'));
159  $cancel_send = new Xoops\Form\Button('', 'cancel', XoopsLocale::CANCEL_SEND, 'button');
160  $cancel_send->setExtra("onclick='javascript:window.close();'");
161  $buttons ->addElement($cancel_send);
162  $form->addElement($buttons);
163  $tpl->assign('form', $form->render());
164  $tpl->display("module:system/system_pmlite.tpl");
165  }
166 }
167 $xoops->simpleFooter();
$send2
Definition: pmlite.php:29
$reply
Definition: pmlite.php:27
$tpl
Definition: backend.php:39
const A_SUBMIT
Definition: en_US.php:128
if($uname== ''||$pass== '') $member_handler
Definition: checklogin.php:44
$i
Definition: dialog.php:68
static getInstance()
Definition: Xoops.php:160
$xoops_url
Definition: pmlite.php:24
$form
Definition: xoops_code.php:21
const MESSAGE_ICON
Definition: en_US.php:836
exit
Definition: browse.php:104
defined('DS') or define('DS' DIRECTORY_SEPARATOR
Definition: common.php:41
$send
Definition: pmlite.php:28
const CANCEL_SEND
Definition: en_US.php:146
const S_MESSAGED_HAS_BEEN_POSTED
Definition: en_US.php:1029
$sendmod
Definition: pmlite.php:30
$myts
Definition: pmlite.php:57
static getUnameFromId($userid, $usereal=0)
Definition: user.php:124
static get($name)
$xoops
Definition: pmlite.php:23
$to_userid
Definition: pmlite.php:31
const CF_WROTE
Definition: en_US.php:152
const E_NO_ACCESS_PERMISSION
Definition: en_US.php:351
$msg_id
Definition: pmlite.php:32
const OR_CLICK_HERE_TO_CLOSE_WINDOW
Definition: en_US.php:892
const CLICK_HERE_TO_VIEW_YOU_PRIVATE_MESSAGES
Definition: en_US.php:161
$pm_handler
Definition: readpmsg.php:37
const MESSAGE
Definition: en_US.php:835
const A_CLEAR
Definition: en_US.php:85
const E_SELECTED_USER_DOES_NOT_EXIST
Definition: en_US.php:365
$pm_uname
Definition: pmlite.php:101
const E_GO_BACK_AND_TRY_AGAIN
Definition: en_US.php:331
const GO_BACK
Definition: en_US.php:452