XOOPS  2.6.0
readpmsg.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 
13 
24 include __DIR__ . DIRECTORY_SEPARATOR . 'mainfile.php';
26 $xoops->preload()->triggerEvent('core.readpmsg.start');
27 
28 if (!$xoops->isUser()) {
29  $xoops->redirect("user.php", 2, XoopsLocale::E_YOU_ARE_NOT_REGISTERED);
30 }
31 
32 $op = Request::getCmd('op', 'list');
33 $id = Request::getInt('msg_id', 0);
34 $start = Request::getInt('start', 0);
35 $total_messages = Request::getInt('total_messages', 0);
36 
37 $pm_handler = $xoops->getHandlerPrivmessage();
38 
39 $xoops->header('module:system/system_readpmsg.tpl');
40 
41 switch ($op) {
42 
43  case 'list':
44  default:
45 
46  $criteria = new CriteriaCompo(new Criteria('to_userid', $xoops->user->getVar('uid')));
47  if ($id > 0) {
48  $criteria->add(new Criteria('msg_id', $id));
49  } else {
50  $criteria->setStart($start);
51  }
52  $criteria->setLimit(1);
53  $criteria->setSort('msg_time');
54  $criteria->setOrder('DESC');
55  $pm_arr = $pm_handler->getObjects($criteria);
56  $xoops->tpl()->assign('uid', $xoops->user->getVar("uid"));
57  if (empty($pm_arr)) {
58  $xoops->tpl()->assign('error_msg', $xoops->alert('error', XoopsLocale::E_YOU_DO_NOT_HAVE_ANY_PRIVATE_MESSAGE));
59  } else {
60  if ($pm_arr[0]->getVar('read_msg') == 0) {
61  $pm_handler->setRead($pm_arr[0]);
62  }
63  $poster = new XoopsUser($pm_arr[0]->getVar("from_userid"));
64  if (!is_object($poster)) {
65  $xoops->tpl()->assign('poster', false);
66  $xoops->tpl()->assign('anonymous', $xoopsConfig['anonymous']);
67  } else {
68  $xoops->tpl()->assign('poster', $poster);
69  $avatar = $xoops->service('avatar')->getAvatarUrl($poster)->getValue();
70  $xoops->tpl()->assign('poster_avatar', $avatar);
71  }
72  $xoops->tpl()->assign('msg_id', $pm_arr[0]->getVar("msg_id"));
73  $xoops->tpl()->assign('subject', $pm_arr[0]->getVar("subject"));
74  $xoops->tpl()->assign('msg_time', XoopsLocale::formatTimestamp($pm_arr[0]->getVar("msg_time")));
75  $xoops->tpl()->assign('msg_image', $pm_arr[0]->getVar("msg_image", "E"));
76  $xoops->tpl()->assign('msg_text', $pm_arr[0]->getVar("msg_text"));
77  $xoops->tpl()->assign('previous', $start - 1);
78  $xoops->tpl()->assign('next', $start + 1);
79  $xoops->tpl()->assign('total_messages', $total_messages);
80  $xoops->tpl()->assign('read', true);
81  $xoops->tpl()->assign('token', $xoops->security()->getTokenHTML());
82  }
83  break;
84 
85  case 'delete':
86  $obj = $pm_handler->get($id);
87  if (isset($_POST["ok"]) && $_POST["ok"] == 1) {
88  if (!$xoops->security()->check()) {
89  $xoops->redirect("viewpmsg.php", 3, implode(",", $xoops->security()->getErrors()));
90  }
91  if ($pm_handler->delete($obj)) {
92  $xoops->redirect("viewpmsg.php", 2, XoopsLocale::S_YOUR_MESSAGES_DELETED);
93  } else {
94  echo $xoops->alert('error', $obj->getHtmlErrors());
95  }
96  } else {
97  $xoops->tpl()->assign('subject', $obj->getVar("subject"));
98  echo $xoops->confirm(array("ok" => 1, "msg_id" => $id, "op" => "delete"), 'readpmsg.php', XoopsLocale::Q_ARE_YOU_SURE_YOU_WANT_TO_DELETE_THIS_MESSAGES . '<br />' . $obj->getVar("subject"));
99  }
100  break;
101 }
102 $xoops->footer();
$pm_arr
Definition: viewpmsg.php:69
static formatTimestamp($time, $format= 'l', $timeoffset=null)
Definition: Abstract.php:289
const E_YOU_DO_NOT_HAVE_ANY_PRIVATE_MESSAGE
Definition: en_US.php:382
static getInstance()
Definition: Xoops.php:160
const S_YOUR_MESSAGES_DELETED
Definition: en_US.php:1036
defined('DS') or define('DS' DIRECTORY_SEPARATOR
Definition: common.php:41
$total_messages
Definition: readpmsg.php:35
$id
Definition: readpmsg.php:33
$start
Definition: readpmsg.php:34
const Q_ARE_YOU_SURE_YOU_WANT_TO_DELETE_THIS_MESSAGES
Definition: en_US.php:930
$avatar
Definition: userinfo.php:94
$criteria
const E_YOU_ARE_NOT_REGISTERED
Definition: en_US.php:381
if(!$xoops->isUser()) $op
Definition: readpmsg.php:32
$pm_handler
Definition: readpmsg.php:37
$xoopsConfig
Definition: common.php:130
$xoops
Definition: readpmsg.php:25