XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
prune.php
Go to the documentation of this file.
1 <?php
20 include 'admin_header.php';
22 
24 echo $indexAdmin->addNavigation('prune.php');
25 
26 $op = isset($_REQUEST['op']) ? $_REQUEST['op'] : "form";
28 
29 switch ($op) {
30 default:
31 case "form":
32  $form = $pm_handler->getPruneForm();
33  $form->display();
34  break;
35 
36 case "prune":
37  $criteria = new CriteriaCompo();
38  if ($_REQUEST['after']['date'] && $_REQUEST['after']['date'] != "YYYY/MM/DD") {
39  $criteria->add(new Criteria('msg_time', strtotime($_REQUEST['after']['date']) + intval($_REQUEST['after']['time']), ">"));
40  }
41  if ($_REQUEST['before']['date'] && $_REQUEST['before']['date'] != "YYYY/MM/DD") {
42  $criteria->add(new Criteria('msg_time', strtotime($_REQUEST['before']['date']) + intval($_REQUEST['before']['time']), "<"));
43  }
44  if (isset($_REQUEST['onlyread']) && $_REQUEST['onlyread'] == 1) {
45  $criteria->add(new Criteria('read_msg', 1));
46  }
47  if ((!isset($_REQUEST['includesave']) || $_REQUEST['includesave'] == 0)) {
48  $savecriteria = new CriteriaCompo(new Criteria('to_save', 0));
49  $savecriteria->add(new Criteria('from_save', 0));
50  $criteria->add($savecriteria);
51  }
52  if (isset($_REQUEST['notifyusers']) && $_REQUEST['notifyusers'] == 1) {
53  $notifycriteria = $criteria;
54  $notifycriteria->add(new Criteria('to_delete', 0));
55  $notifycriteria->setGroupBy('to_userid');
56  // Get array of uid => number of deleted messages
57  $uids = $pm_handler->getCount($notifycriteria);
58  }
59  $deletedrows = $pm_handler->deleteAll($criteria);
60  if ($deletedrows === false) {
62  }
63  if (isset($_REQUEST['notifyusers']) && $_REQUEST['notifyusers'] == 1) {
64  $errors = false;
65  foreach ($uids as $uid => $messagecount) {
66  $pm = $pm_handler->create();
67  $pm->setVar("subject", $GLOBALS['xoopsModuleConfig']['prunesubject']);
68  $pm->setVar("msg_text", str_replace('{PM_COUNT}', $messagecount, $GLOBALS['xoopsModuleConfig']['prunemessage']));
69  $pm->setVar("to_userid", $uid);
70  $pm->setVar("from_userid", $GLOBALS['xoopsUser']->getVar("uid"));
71  $pm->setVar("msg_time", time());
72  if (!$pm_handler->insert($pm)) {
73  $errors = true;
74  $errormsg[] = $pm->getHtmlErrors();
75  }
76  unset($pm);
77  }
78  if ($errors == true) {
79  echo implode('<br />', $errormsg);
81  exit();
82  }
83  }
84  redirect_header('admin.php', 2, sprintf(_PM_AM_MESSAGESPRUNED, $deletedrows));
85  break;
86 }
87 include 'admin_footer.php';
88 //xoops_cp_footer();