+ ";
+
+
+ return $txt;
+
+
+ }
+
+
+
+
+ /**
+ * Do PM DB maintenance
+ * @param array $opts of tasks key = sent|rec|blocked|expired (one or more present). ATM value not used
+ * @return array where key is message type (E_MESSAGE_SUCCESS|E_MESSAGE_ERROR|E_MESSAGE_INFO etc), data is array of messages of that type (key = timestamp)
+ */
+ private function doMaint($opts, $pmPrefs)
+ {
+ if (!count($opts))
+ {
+ return array(E_MESSAGE_ERROR => array(ADLAN_PM_66));
+ }
+
+
+
+ $results = array(E_MESSAGE_INFO => array(ADLAN_PM_67)); // 'Maintenance started' - primarily for a log entry to mark start time
+ $logResults = array();
+ $e107 = e107::getInstance();
+ e107::getLog()->log_event('PM_ADM_04', implode(', ',array_keys($opts)));
+ $pmHandler = new private_message($pmPrefs);
+ $db2 =e107::getDb('sql2'); // Will usually need a second DB object to avoid over load
+ $start = 0; // Use to ensure we get different log times
+
+
+ if (isset($opts['sent'])) // Want pm_from = deleted user and pm_read_del = 1
+ {
+ $cnt = 0;
+ if ($res = $db2->gen("SELECT pm.pm_id FROM `#private_msg` AS pm LEFT JOIN `#user` AS u ON pm.`pm_from` = `#user`.`user_id`
+ WHERE (pm.`pm_read_del = 1) AND `#user`.`user_id` IS NULL"))
+ {
+ while ($row = $db2->fetch())
+ {
+ if ($pmHandler->del($row['pm_id']) !== FALSE)
+ {
+ $cnt++;
+ }
+ }
+ }
+ $start = time();
+ $results[E_MESSAGE_SUCCESS][$start] = str_replace('--COUNT--', $cnt, ADLAN_PM_74);
+ }
+ if (isset($opts['rec'])) // Want pm_to = deleted user and pm_sent_del = 1
+ {
+ $cnt = 0;
+ if ($res = $db2->gen("SELECT pm.pm_id FROM `#private_msg` AS pm LEFT JOIN `#user` AS u ON pm.`pm_to` = `#user`.`user_id`
+ WHERE (pm.`pm_sent_del = 1) AND `#user`.`user_id` IS NULL"))
+ {
+ while ($row = $db2->fetch())
+ {
+ if ($pmHandler->del($row['pm_id']) !== FALSE)
+ {
+ $cnt++;
+ }
+ }
+ }
+ $start = max($start + 1, time());
+ $results[E_MESSAGE_SUCCESS][$start] = str_replace('--COUNT--', $cnt, ADLAN_PM_75);
+ }
+
+
+ if (isset($opts['blocked']))
+ {
+ if ($res = $db2->gen("DELETE `#private_msg_block` FROM `#private_msg_block` LEFT JOIN `#user` ON `#private_msg_block`.`pm_block_from` = `#user`.`user_id`
+ WHERE `#user`.`user_id` IS NULL"))
+ {
+ $start = max($start + 1, time());
+ $results[E_MESSAGE_ERROR][$start] = str_replace(array('--NUM--', '--TEXT--'), array($this->sql->getLastErrorNum, $this->sql->getLastErrorText), ADLAN_PM_70);
+ }
+ else
+ {
+ $start = max($start + 1, time());
+ $results[E_MESSAGE_SUCCESS][$start] = str_replace('--COUNT--', $res, ADLAN_PM_69);
+ }
+ if ($res = $db2->gen("DELETE `#private_msg_block` FROM `#private_msg_block` LEFT JOIN `#user` ON `#private_msg_block`.`pm_block_to` = `#user`.`user_id`
+ WHERE `#user`.`user_id` IS NULL"))
+ {
+ $start = max($start + 1, time());
+ $results[E_MESSAGE_ERROR][$start] = str_replace(array('--NUM--', '--TEXT--'), array($this->sql->getLastErrorNum, $this->sql->getLastErrorText), ADLAN_PM_70);
+ }
+ else
+ {
+ $start = max($start + 1, time());
+ $results[E_MESSAGE_SUCCESS][$start] = str_replace('--COUNT--', $res, ADLAN_PM_68);
+ }
+ }
+
+
+ if (isset($opts['expired']))
+ {
+ $del_qry = array();
+ $read_timeout = intval($pmPrefs['read_timeout']);
+ $unread_timeout = intval($pmPrefs['unread_timeout']);
+ if($read_timeout > 0)
+ {
+ $timeout = time()-($read_timeout * 86400);
+ $del_qry[] = "(pm_sent < {$timeout} AND pm_read > 0)";
+ }
+ if($unread_timeout > 0)
+ {
+ $timeout = time()-($unread_timeout * 86400);
+ $del_qry[] = "(pm_sent < {$timeout} AND pm_read = 0)";
+ }
+ if(count($del_qry) > 0)
+ {
+ $qry = implode(' OR ', $del_qry);
+ $cnt = 0;
+ if($db2->db_Select('private_msg', 'pm_id', $qry))
+ {
+ while ($row = $db2->db_Fetch())
+ {
+ if ($pmHandler->del($row['pm_id']) !== FALSE)
+ {
+ $cnt++;
+ }
+ }
+ }
+ $start = max($start + 1, time());
+ $results[E_MESSAGE_SUCCESS][$start] = str_replace('--COUNT--', $cnt, ADLAN_PM_73);
+ }
+ else
+ {
+ $start = max($start + 1, time());
+ $results[E_MESSAGE_ERROR][$start] = ADLAN_PM_72;
+ }
+ }
+
+
+ if (isset($opts['attach']))
+ { // Check for orphaned and missing attachments
+
+ $fl = e107::getFile();
+ $missing = array();
+ $orphans = array();
+ $fileArray = $fl->get_files(e_PLUGIN.'pm/attachments'); //FIXME wrong path.
+ if ($db2->select('private_msg', 'pm_id, pm_attachments', "pm_attachments != ''"))
+ {
+ while ($row = $db2->fetch())
+ {
+ $attachList = explode(chr(0), $row['pm_attachments']);
+ foreach ($attachList as $a)
+ {
+ $found = FALSE;
+ foreach ($fileArray as $k => $fd)
+ {
+ if ($fd['fname'] == $a)
+ {
+ $found = TRUE;
+ unset($fileArray[$k]);
+ break;
+ }
+ }
+ if (!$found)
+ {
+ $missing[] = $row['pm_id'].':'.$a;
+ }
+ }
+ }
+ }
+ // Any files left in $fileArray now are unused
+ if (count($fileArray))
+ {
+ foreach ($fileArray as $k => $fd)
+ {
+ unlink($fd['path'].$fd['fname']);
+ $orphans[] = $fd['fname'];
+ }
+ }
+ $attachMessage = str_replace(array('--ORPHANS--', '--MISSING--'), array(count($orphans), count($missing)), ADLAN_PM_79);
+ if (TRUE)
+ { // Mostly for testing - probably disable this
+ if (count($orphans))
+ {
+ $attachMessage .= '[!br!]Orphans:[!br!]'.implode('[!br!]', $orphans);
+ }
+ if (count($missing))
+ {
+ $attachMessage .= '[!br!]Missing:[!br!]'.implode('[!br!]', $missing);
+ }
+ }
+ $start = max($start + 1, time());
+ $results[E_MESSAGE_SUCCESS][$start] = $attachMessage;
+ }
+
+
+ e107::getLog()->logArrayAll('PM_ADM_03', $this->makeLogEntry($results));
+
+ foreach ($results as $k => $r)
+ {
+ foreach ($r as $sk => $s)
+ {
+ $results[$k][$sk] = str_replace('[!br!]','
PMLAN_PM
diff --git a/e107_plugins/pm/pm_conf.php b/e107_plugins/pm/pm_conf.php
index bb733964b..b2c24eae8 100755
--- a/e107_plugins/pm/pm_conf.php
+++ b/e107_plugins/pm/pm_conf.php
@@ -287,6 +287,30 @@ function show_options($pm_prefs)
".ADLAN_PM_16." |
".$frm->text('pm_option-title', $pm_prefs['title'], '50')." |
+
+ ".ADLAN_PM_23." |
+ ".e107::getUserClass()->uc_dropdown('pm_option-pm_class', $pm_prefs['pm_class'], 'member,admin,classes')." |
+
+
+ ".ADLAN_PM_29." |
+ ".e107::getUserClass()->uc_dropdown('pm_option-sendall_class', $pm_prefs['sendall_class'], 'nobody,member,admin,classes')." |
+
+
+ User may send PMs to |
+ "; //TODO LAN
+
+ $list = e107::getUserClass()->getClassList('nobody,main,admin,member,classes');
+ $list['matchclass'] = "(Any user with the same class)"; //TODO LAN
+
+ //$txt .= print_a($list,true);
+ $txt .= $frm->select('pm_option-send_to_class', $list, varset($pm_prefs['send_to_class'], e_UC_MEMBER));
+
+ //$text .= ".e107::getUserClass()->uc_dropdown('pm_option-sendall_class', $pm_prefs['sendall_class'], 'nobody,member,admin,classes')." |
+
+ $txt .= "
+
+
+
".ADLAN_PM_17." |
".$frm->radio_switch('pm_option-animate', $pm_prefs['animate'], LAN_YES, LAN_NO)." |
@@ -309,12 +333,9 @@ function show_options($pm_prefs)
".ADLAN_PM_22." |
- ".$frm->text('pm_option-popup_delay', $pm_prefs['popup_delay'], '5', array('class' => 'tbox input-text'))." ".ADLAN_PM_44." |
-
-
- ".ADLAN_PM_23." |
- ".e107::getUserClass()->uc_dropdown('pm_option-pm_class', $pm_prefs['pm_class'], 'member,admin,classes')." |
+ ".$frm->text('pm_option-popup_delay', $pm_prefs['popup_delay'], '5', array('class' => 'tbox input-text'))." ".ADLAN_PM_44." |
+
".ADLAN_PM_24." |
".$frm->text('pm_option-perpage', $pm_prefs['perpage'], '5', array('class' => 'tbox input-text'))." |
@@ -333,12 +354,9 @@ function show_options($pm_prefs)
".ADLAN_PM_28." |
- ".$frm->text('pm_option-attach_size', $pm_prefs['attach_size'], '8', array('class' => 'tbox input-text'))." kB |
-
-
- ".ADLAN_PM_29." |
- ".e107::getUserClass()->uc_dropdown('pm_option-sendall_class', $pm_prefs['sendall_class'], 'nobody,member,admin,classes')." |
+ ".$frm->text('pm_option-attach_size', $pm_prefs['attach_size'], '8', array('class' => 'tbox input-text'))." kB |
+
".ADLAN_PM_30." |
".e107::getUserClass()->uc_dropdown('pm_option-multi_class', $pm_prefs['multi_class'], 'nobody,member,admin,classes')." |
@@ -349,7 +367,7 @@ function show_options($pm_prefs)
".ADLAN_PM_81." |
- ".$frm->text('pm_option-pm_max_send', $pm_prefs['pm_max_send'], '5', array('class' => 'tbox input-text'))."".ADLAN_PM_82." |
+ ".$frm->text('pm_option-v', $pm_prefs['pm_max_send'], '5', array('class' => 'tbox input-text'))."".ADLAN_PM_82." |