XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
viewpmsg.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 $xoopsConfig['module_cache'] = 0; //disable caching since the URL will be the same, but content different from one user to another
28 $xoopsOption['template_main'] = "pm_viewpmsg.html";
29 include $GLOBALS['xoops']->path('header.php');
30 
31 $valid_op_requests = array('out', 'save', 'in');
32 $_REQUEST['op'] = !empty($_REQUEST['op']) && in_array($_REQUEST['op'], $valid_op_requests) ? $_REQUEST['op'] : 'in' ;
33 
34 $start = empty($_REQUEST["start"]) ? 0 : intval($_REQUEST["start"]);
35 $pm_handler =& xoops_getModuleHandler('message');
36 
37 if (isset($_POST['delete_messages']) && isset($_POST['msg_id'])) {
38  if (!$GLOBALS['xoopsSecurity']->check()) {
39  $GLOBALS['xoopsTpl']->assign('errormsg', implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
40  } else if (empty($_REQUEST['ok'])) {
41  xoops_confirm(array('ok' => 1, 'delete_messages' => 1, 'op' => $_REQUEST['op'], 'msg_id'=> serialize(array_map("intval", $_POST['msg_id']))), $_SERVER['REQUEST_URI'], _PM_SURE_TO_DELETE);
42  include $GLOBALS['xoops']->path('footer.php');
43  exit();
44  } else {
45  $_POST['msg_id'] = unserialize($_REQUEST['msg_id']);
46  $size = count($_POST['msg_id']);
47  $msg = $_POST['msg_id'];
48  for ($i = 0; $i < $size; $i++) {
49  $pm =& $pm_handler->get($msg[$i]);
50  if ($pm->getVar('to_userid') == $GLOBALS['xoopsUser']->getVar('uid')) {
51  $pm_handler->setTodelete($pm);
52  } else if ($pm->getVar('from_userid') == $GLOBALS['xoopsUser']->getVar('uid')) {
53  $pm_handler->setFromdelete($pm);
54  }
55  unset($pm);
56  }
57  $GLOBALS['xoopsTpl']->assign('msg', _PM_DELETED);
58  }
59 }
60 if (isset($_POST['move_messages']) && isset($_POST['msg_id'])) {
61  if (!$GLOBALS['xoopsSecurity']->check()) {
62  $GLOBALS['xoopsTpl']->assign('errormsg', implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
63  } else{
64  $size = count($_POST['msg_id']);
65  $msg = $_POST['msg_id'];
66  if ($_POST['op'] == 'save') {
67  for ($i = 0; $i < $size; $i++) {
68  $pm =& $pm_handler->get($msg[$i]);
69  if ($pm->getVar('to_userid') == $GLOBALS['xoopsUser']->getVar('uid')) {
70  $pm_handler->setTosave($pm, 0);
71  } else if ($pm->getVar('from_userid') == $GLOBALS['xoopsUser']->getVar('uid')) {
72  $pm_handler->setFromsave($pm, 0);
73  }
74  unset($pm);
75  }
76  } else {
77  if (!$GLOBALS['xoopsUser']->isAdmin()) {
78  $total_save = $pm_handler->getSavecount();
79  $size = min($size, ($GLOBALS['xoopsModuleConfig']['max_save'] - $total_save));
80  }
81  for ($i = 0; $i < $size; $i++) {
82  $pm =& $pm_handler->get($msg[$i]);
83  if ($_POST['op']=='in') {
84  $pm_handler->setTosave($pm);
85  } else if ($_POST['op'] == 'out') {
86  $pm_handler->setFromsave($pm);
87  }
88  unset($pm);
89  }
90  }
91  if ($_POST['op'] == 'save') {
92  $GLOBALS['xoopsTpl']->assign('msg', _PM_UNSAVED);
93  } else if (isset($total_save) && !$GLOBALS['xoopsUser']->isAdmin()) {
94  $GLOBALS['xoopsTpl']->assign('msg', sprintf(_PM_SAVED_PART, $GLOBALS['xoopsModuleConfig']['max_save'], $i));
95  } else {
96  $GLOBALS['xoopsTpl']->assign('msg', _PM_SAVED_ALL);
97  }
98  }
99 }
100 if (isset($_REQUEST['empty_messages'])) {
101  if (!$GLOBALS['xoopsSecurity']->check()) {
102  $GLOBALS['xoopsTpl']->assign('errormsg', implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
103  } else if (empty($_REQUEST['ok'])) {
104  xoops_confirm(array('ok' => 1, 'empty_messages' => 1, 'op' => $_REQUEST['op']), $_SERVER['REQUEST_URI'], _PM_RUSUREEMPTY);
105  include $GLOBALS['xoops']->path('footer.php');
106  exit();
107  } else {
108  if ($_POST['op'] == 'save') {
109  $crit_to = new CriteriaCompo(new Criteria('to_delete', 0));
110  $crit_to->add(new Criteria('to_save',1));
111  $crit_to->add(new Criteria('to_userid',$GLOBALS['xoopsUser']->getVar('uid')));
112  $crit_from = new CriteriaCompo(new Criteria('from_delete', 0));
113  $crit_from->add(new Criteria('from_save', 1));
114  $crit_from->add(new Criteria('from_userid',$GLOBALS['xoopsUser']->getVar('uid')));
115  $criteria = new CriteriaCompo($crit_to);
116  $criteria->add($crit_from, "OR");
117  } else if ($_POST['op'] == 'out') {
118  $criteria = new CriteriaCompo(new Criteria('from_delete', 0));
119  $criteria->add(new Criteria('from_userid', $GLOBALS['xoopsUser']->getVar('uid')));
120  $criteria->add(new Criteria('from_save', 0));
121  } else{
122  $criteria = new CriteriaCompo(new Criteria('to_delete', 0));
123  $criteria->add(new Criteria('to_userid', $GLOBALS['xoopsUser']->getVar('uid')));
124  $criteria->add(new Criteria('to_save', 0));
125  }
126  /*
127  * The following method has critical scalability problem !
128  * deleteAll method should be used instead
129  */
130  $pms = $pm_handler->getObjects($criteria);
131  unset($criteria);
132  if (count($pms)>0) {
133  foreach (array_keys($pms) as $i) {
134  if ($pms[$i]->getVar('to_userid') == $GLOBALS['xoopsUser']->getVar('uid')) {
135  if ($_POST['op'] == 'save') {
136  $pm_handler->setTosave($pms[$i], 0);
137  } else if ($_POST['op'] == 'in') {
138  $pm_handler->setTodelete($pms[$i]);
139  }
140  }
141  if ($pms[$i]->getVar('from_userid') == $GLOBALS['xoopsUser']->getVar('uid')) {
142  if ($_POST['op']=='save') {
143  $pm_handler->setFromsave($pms[$i],0);
144  } else if ($_POST['op']=='out') {
145  $pm_handler->setFromdelete($pms[$i]);
146  }
147  }
148  }
149  }
150  $GLOBALS['xoopsTpl']->assign('msg', _PM_EMPTIED);
151  }
152 }
153 
154 if ($_REQUEST['op'] == "out") {
155  $criteria = new CriteriaCompo(new Criteria('from_delete', 0));
156  $criteria->add(new Criteria('from_userid', $GLOBALS['xoopsUser']->getVar('uid')));
157  $criteria->add(new Criteria('from_save', 0));
158 } else if ($_REQUEST['op'] == "save") {
159  $crit_to = new CriteriaCompo(new Criteria('to_delete', 0));
160  $crit_to->add(new Criteria('to_save', 1));
161  $crit_to->add(new Criteria('to_userid', $GLOBALS['xoopsUser']->getVar('uid')));
162  $crit_from = new CriteriaCompo(new Criteria('from_delete', 0));
163  $crit_from->add(new Criteria('from_save', 1));
164  $crit_from->add(new Criteria('from_userid', $GLOBALS['xoopsUser']->getVar('uid')));
165  $criteria = new CriteriaCompo($crit_to);
166  $criteria->add($crit_from, "OR");
167 } else {
168  $criteria = new CriteriaCompo(new Criteria('to_delete', 0));
169  $criteria->add(new Criteria('to_userid', $GLOBALS['xoopsUser']->getVar('uid')));
170  $criteria->add(new Criteria('to_save', 0));
171 }
173 $criteria->setStart($start);
174 $criteria->setLimit($GLOBALS['xoopsModuleConfig']['perpage']);
175 $criteria->setSort("msg_time");
176 $criteria->setOrder("DESC");
177 $pm_arr = $pm_handler->getAll($criteria, null, false, false);
178 unset($criteria);
179 
180 $GLOBALS['xoopsTpl']->assign('total_messages', $total_messages);
181 $GLOBALS['xoopsTpl']->assign('op', $_REQUEST['op']);
182 
183 if ($total_messages > $GLOBALS['xoopsModuleConfig']['perpage']) {
184  include $GLOBALS['xoops']->path('class/pagenav.php');
185  $nav = new XoopsPageNav($total_messages, $GLOBALS['xoopsModuleConfig']['perpage'], $start, "start", 'op=' . htmlspecialchars($_REQUEST['op']));
186  $GLOBALS['xoopsTpl']->assign('pagenav', $nav->renderNav(4));
187 }
188 
189 $GLOBALS['xoopsTpl']->assign('display', $total_messages > 0);
190 $GLOBALS['xoopsTpl']->assign('anonymous', $xoopsConfig['anonymous']);
191 if (count($pm_arr)>0) {
192  foreach (array_keys($pm_arr) as $i) {
193  if (isset($_REQUEST['op']) && $_REQUEST['op'] == "out") {
194  $uids[] = $pm_arr[$i]['to_userid'];
195  } else {
196  $uids[] = $pm_arr[$i]['from_userid'];
197  }
198  }
199  $member_handler =& xoops_gethandler('member');
200  $senders = $member_handler->getUserList(new Criteria('uid', "(" . implode(", ", array_unique($uids) ) . ")", "IN"));
201  foreach (array_keys($pm_arr) as $i) {
202  $message = $pm_arr[$i];
203  $message['msg_time'] = formatTimestamp($message["msg_time"]);
204  if (isset($_REQUEST['op']) && $_REQUEST['op'] == "out") {
205  $message['postername'] = $senders[$pm_arr[$i]['to_userid']];
206  $message['posteruid'] = $pm_arr[$i]['to_userid'];
207  } else {
208  $message['postername'] = $senders[$pm_arr[$i]['from_userid']];
209  $message['posteruid'] = $pm_arr[$i]['from_userid'];
210  }
211  $message['msg_no'] = $i;
212  $GLOBALS['xoopsTpl']->append('messages', $message);
213  }
214 }
215 
216 include_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
218 $send_button->setExtra("onclick='javascript:openWithSelfMain(\"" . XOOPS_URL . "/modules/pm/pmlite.php?send=1\", \"pmlite\", 550, 450);'");
219 $delete_button = new XoopsFormButton('', 'delete_messages', _PM_DELETE, 'submit');
220 $move_button = new XoopsFormButton('', 'move_messages', ($_REQUEST['op'] == 'save') ? _PM_UNSAVE : _PM_TOSAVE, 'submit');
221 $empty_button = new XoopsFormButton('', 'empty_messages', _PM_EMPTY, 'submit');
222 
223 $pmform = new XoopsForm('', 'pmform', 'viewpmsg.php', 'post', true);
224 $pmform->addElement($send_button);
225 $pmform->addElement($move_button);
226 $pmform->addElement($delete_button);
227 $pmform->addElement($empty_button);
228 $pmform->addElement(new XoopsFormHidden('op', $_REQUEST['op']));
229 $pmform->assign($GLOBALS['xoopsTpl']);
230 
231 include $GLOBALS['xoops']->path('footer.php');
232 ?>