XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
readpmsg.php
Go to the documentation of this file.
1 <?php
21 include_once dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'mainfile.php';
22 
23 if (!is_object($GLOBALS['xoopsUser'])) {
24  redirect_header(XOOPS_URL, 3, _NOPERM);
25  exit();
26 }
27 $valid_op_requests = array('out', 'save', 'in');
28 $_REQUEST['op'] = !empty($_REQUEST['op']) && in_array($_REQUEST['op'], $valid_op_requests) ? $_REQUEST['op'] : 'in' ;
29 $msg_id = empty($_REQUEST['msg_id']) ? 0 : intval($_REQUEST['msg_id']);
30 $pm_handler =& xoops_getModuleHandler('message');
31 if ($msg_id > 0) {
32  $pm =& $pm_handler->get($msg_id);
33 } else {
34  $pm = null;
35 }
36 
37 if (is_object($pm) && ($pm->getVar('from_userid') != $GLOBALS['xoopsUser']->getVar('uid'))
38  && ($pm->getVar('to_userid') != $GLOBALS['xoopsUser']->getVar('uid'))
39 ){
40  redirect_header(XOOPS_URL . '/modules/' . $GLOBALS['xoopsModule']->getVar("dirname", "n") . '/index.php', 2, _NOPERM);
41  exit();
42 }
43 
44 if (is_object($pm) && !empty($_POST['action']) ) {
45  if (!$GLOBALS['xoopsSecurity']->check()) {
46  echo implode('<br />', $GLOBALS['xoopsSecurity']->getErrors());
47  exit();
48  }
49  $res = false;
50  if (!empty($_REQUEST['email_message'])) {
51  $res = $pm_handler->sendEmail($pm, $GLOBALS['xoopsUser']);
52  } else if (!empty($_REQUEST['move_message'])
53  && $_REQUEST['op'] != 'save'
54  && !$GLOBALS['xoopsUser']->isAdmin()
55  && $pm_handler->getSavecount() >= $GLOBALS['xoopsModuleConfig']['max_save']
56  ) {
57  $res_message = sprintf(_PM_SAVED_PART, $GLOBALS['xoopsModuleConfig']['max_save'], 0);
58  } else {
59  switch ($_REQUEST['op']) {
60  case 'out':
61  if ($pm->getVar('from_userid') != $GLOBALS['xoopsUser']->getVar('uid')) break;
62  if (!empty($_REQUEST['delete_message'])) {
63  $res = $pm_handler->setFromdelete($pm);
64  } else if (!empty($_REQUEST['move_message'])) {
65  $res = $pm_handler->setFromsave($pm);
66  }
67  break;
68  case 'save':
69  if ($pm->getVar('to_userid') == $GLOBALS['xoopsUser']->getVar('uid')) {
70  if (!empty($_REQUEST['delete_message'])) {
71  $res1 = $pm_handler->setTodelete($pm);
72  $res1 = ($res1) ? $pm_handler->setTosave($pm, 0) : false;
73  } else if (!empty($_REQUEST['move_message'])) {
74  $res1 = $pm_handler->setTosave($pm, 0);
75  }
76  }
77  if ($pm->getVar('from_userid') == $GLOBALS['xoopsUser']->getVar('uid')) {
78  if (!empty($_REQUEST['delete_message'])) {
79  $res2 = $pm_handler->setFromDelete($pm);
80  $res2 = ($res2) ? $pm_handler->setFromsave($pm, 0) : false;
81  } else if (!empty($_REQUEST['move_message'])) {
82  $res2 = $pm_handler->setFromsave($pm, 0);
83  }
84  }
85  $res = $res1 && $res2;
86  break;
87 
88  case 'in':
89  default:
90  if ($pm->getVar('to_userid') != $GLOBALS['xoopsUser']->getVar('uid')) {
91  break;
92  }
93  if (!empty($_REQUEST['delete_message'])) {
94  $res = $pm_handler->setTodelete($pm);
95  } else if (!empty($_REQUEST['move_message'])) {
96  $res = $pm_handler->setTosave($pm);
97  }
98  break;
99  }
100  }
101  $res_message = isset($res_message) ? $res_message : (($res) ? _PM_ACTION_DONE : _PM_ACTION_ERROR);
102  redirect_header('viewpmsg.php?op=' . htmlspecialchars($_REQUEST['op'] ) , 2, $res_message);
103 }
104 $start = !empty($_GET['start']) ? intval($_GET['start']) : 0;
105 $total_messages = !empty($_GET['total_messages']) ? intval($_GET['total_messages']) : 0;
106 $xoopsOption['template_main'] = "pm_readpmsg.html";
107 include $GLOBALS['xoops']->path('header.php');
108 
109 if (!is_object($pm)) {
110  if ($_REQUEST['op'] == "out") {
111  $criteria = new CriteriaCompo(new Criteria('from_delete', 0));
112  $criteria->add(new Criteria('from_userid', $GLOBALS['xoopsUser']->getVar('uid')));
113  $criteria->add(new Criteria('from_save', 0));
114  } else if ($_REQUEST['op'] == "save") {
115  $crit_to = new CriteriaCompo(new Criteria('to_delete', 0));
116  $crit_to->add(new Criteria('to_save', 1));
117  $crit_to->add(new Criteria('to_userid',$GLOBALS['xoopsUser']->getVar('uid')));
118  $crit_from = new CriteriaCompo(new Criteria('from_delete', 0));
119  $crit_from->add(new Criteria('from_save', 1));
120  $crit_from->add(new Criteria('from_userid', $GLOBALS['xoopsUser']->getVar('uid')));
121  $criteria = new CriteriaCompo($crit_to);
122  $criteria->add($crit_from, "OR");
123  } else {
124  $criteria = new CriteriaCompo(new Criteria('to_delete', 0));
125  $criteria->add(new Criteria('to_userid', $GLOBALS['xoopsUser']->getVar('uid')));
126  $criteria->add(new Criteria('to_save', 0));
127  }
128 
129  $criteria->setLimit(1);
130  $criteria->setStart($start);
131  $criteria->setSort('msg_time');
132  $criteria->setOrder("DESC");
133  list($pm) = $pm_handler->getObjects($criteria);
134 }
135 
136 include_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
137 
138 $pmform = new XoopsForm('', 'pmform', 'readpmsg.php', 'post', true);
139 if (is_object($pm) && !empty($pm)) {
140  if ($pm->getVar('from_userid') != $GLOBALS['xoopsUser']->getVar('uid')) {
141  $reply_button = new XoopsFormButton('', 'send', _PM_REPLY);
142  $reply_button->setExtra("onclick='javascript:openWithSelfMain(\"" . XOOPS_URL . "/modules/pm/pmlite.php?reply=1&amp;msg_id={$msg_id}\", \"pmlite\", 565,500);'");
143  $pmform->addElement($reply_button);
144  }
145  $pmform->addElement(new XoopsFormButton('', 'delete_message', _PM_DELETE, 'submit'));
146  $pmform->addElement(new XoopsFormButton('', 'move_message', ($_REQUEST['op'] == 'save') ? _PM_UNSAVE : _PM_TOSAVE, 'submit'));
147  $pmform->addElement(new XoopsFormButton('', 'email_message', _PM_EMAIL, 'submit'));
148  $pmform->addElement(new XoopsFormHidden('msg_id', $pm->getVar("msg_id")));
149  $pmform->addElement(new XoopsFormHidden('op', $_REQUEST['op']));
150  $pmform->addElement(new XoopsFormHidden('action', 1));
151  $pmform->assign($GLOBALS['xoopsTpl']);
152 
153  if ($pm->getVar("from_userid") == $GLOBALS['xoopsUser']->getVar("uid")) {
154  $poster = new XoopsUser($pm->getVar("to_userid"));
155  } else {
156  $poster = new XoopsUser($pm->getVar("from_userid"));
157  }
158  if (!is_object($poster)) {
159  $GLOBALS['xoopsTpl']->assign('poster', false);
160  $GLOBALS['xoopsTpl']->assign('anonymous', $xoopsConfig['anonymous']);
161  } else {
162  $GLOBALS['xoopsTpl']->assign('poster', $poster);
163  }
164 
165  if ($pm->getVar("to_userid") == $GLOBALS['xoopsUser']->getVar("uid") && $pm->getVar('read_msg') == 0) {
166  $pm_handler->setRead($pm);
167  }
168 
169  $message = $pm->getValues();
170  $message['msg_time'] = formatTimestamp($pm->getVar("msg_time"));
171 }
172 $GLOBALS['xoopsTpl']->assign('message', $message);
173 $GLOBALS['xoopsTpl']->assign('op', $_REQUEST['op']);
174 $GLOBALS['xoopsTpl']->assign('previous', $start - 1);
175 $GLOBALS['xoopsTpl']->assign('next', $start + 1);
176 $GLOBALS['xoopsTpl']->assign('total_messages', $total_messages);
177 
178 include $GLOBALS['xoops']->path('footer.php');
179 ?>