diff --git a/e107_handlers/admin_ui.php b/e107_handlers/admin_ui.php index f56f171a0..a88237ac2 100644 --- a/e107_handlers/admin_ui.php +++ b/e107_handlers/admin_ui.php @@ -6198,7 +6198,13 @@ class e_admin_form_ui extends e_form return $text; } - // TODO - do more + + /** + * Render Batch and Filter Dropdown options. + * @param string $type + * @param string $selected + * @return string + */ function renderBatchFilter($type='batch', $selected = '') // Common function used for both batches and filters. { $optdiz = array('batch' => LAN_BATCH_LABEL_PREFIX.' ', 'filter'=> LAN_FILTER_LABEL_PREFIX.' '); diff --git a/e107_handlers/user_select_class.php b/e107_handlers/user_select_class.php index 18df5f54f..5a8840733 100644 --- a/e107_handlers/user_select_class.php +++ b/e107_handlers/user_select_class.php @@ -19,7 +19,14 @@ include_lan(e_LANGUAGEDIR.e_LANGUAGE."/lan_user_select.php"); class user_select { - function user_list($class, $form_name) + + /** + * @deprecated use e107::getForm()->userlist() instead. + * @param $class + * @param $form_name + * @return string + */ + function user_list($class, $form_name) { global $sql, $tp; if($class === FALSE) { $class = e_UC_MEMBER;} @@ -41,15 +48,22 @@ class user_select $where = "user_class REGEXP '(^|,)(".$tp -> toDB($class, true).")(,|$)'"; break; } - + + + + $text = ""; + + $text .= $where; return $text; } @@ -57,10 +71,11 @@ class user_select /** * Display selection dropdown of all user classes * + * @deprecated * @param int $class - if its e_UC_MEMBER, all classes are shown. Otherwise only the class matching the value is shown. * @return string */ - function class_list($class, $form_name) + function class_list($class, $form_name) //TODO Find all instances of use and replace. { global $sql; $text = " + "; + + + $sel = ($pm_prefs['pm_limits'] == 0 ? "selected='selected'" : ""); + $txt .= "\n"; + + $sel = ($pm_prefs['pm_limits'] == 1 ? "selected='selected'" : ""); + $txt .= "\n"; + + $sel = ($pm_prefs['pm_limits'] == 2 ? "selected='selected'" : ""); + $txt .= "\n"; + + $txt .= "\n"; + + $txt .= '  '.ADLAN_PM_77." + + + + "; + + if (isset($limitList)) + { + foreach($limitList as $row) + { + $txt .= " + + ".e107::getUserClass()->uc_get_classname($row['limit_classnum'])." + +
+
".ADLAN_PM_39.":
+
".ADLAN_PM_40.":
+
+ + +
+
".ADLAN_PM_39.":
+
".ADLAN_PM_40.":
+
+ + + "; + } + } + else + { + $txt .= " + + ".ADLAN_PM_41." + + "; + } + + $txt .= ' + + +
+ '.$frm->admin_button('updatelimits','no-value','update', LAN_UPDATE).' +
+ + '; + + $tabs = array(); + $tabs[] = array('caption'=>ADLAN_PM_14, 'text'=>$txt); + $tabs[] = array('caption'=>ADLAN_PM_15, 'text'=>$this->addLimitPage()); + + return e107::getForm()->tabs($tabs); + } + + + + function addLimitPage() + { + $sql = e107::getDb(); + $frm = e107::getForm(); + $pm_prefs = e107::pref('pm'); + + if($sql->select('generic', "gen_id as limit_id, gen_datestamp as limit_classnum, gen_user_id as inbox_count, gen_ip as outbox_count, gen_intdata as inbox_size, gen_chardata as outbox_size", "gen_type = 'pm_limit'")) + { + while($row = $sql->fetch()) + { + $limitList[$row['limit_classnum']] = $row; + } + } + + $txt = " +
+
+ + + + + + + + + + + + + + + "; + + $txt .= " + + + + + + + "; + + $txt .= ' + +
".ADLAN_PM_36."".ADLAN_PM_37."".ADLAN_PM_38."
".e107::getUserClass()->uc_dropdown('newlimit_class', 0, 'guest,member,admin,classes')." +
+
".ADLAN_PM_39.":
+
".ADLAN_PM_40.":
+
+
+
+
".ADLAN_PM_39.":
+
".ADLAN_PM_40.":
+
+
+
+ '.$frm->admin_button('addlimit','no-value','update', LAN_ADD).' +
+
+
'; + return $txt; + } + + + + + + public function mainPageProcess() + { + $pm_prefs = e107::pref('pm'); + $mes = e107::getMessage(); + + $maintOpts = array(); + + if (vartrue($_POST['pm_maint_sent'])) + { + $maintOpts['sent'] = 1; + } + + if (vartrue($_POST['pm_maint_rec'])) + { + $maintOpts['rec'] = 1; + } + + if (vartrue($_POST['pm_maint_blocked'])) + { + $maintOpts['blocked'] = 1; + } + + if (vartrue($_POST['pm_maint_expired'])) + { + $maintOpts['expired'] = 1; + } + + if (vartrue($_POST['pm_maint_attach'])) + { + $maintOpts['attach'] = 1; + } + + $result = $this->doMaint($maintOpts, $pm_prefs); + + if (is_array($result)) + { + foreach ($result as $k => $ma) + { + foreach ($ma as $m) + { + $mes->add($m, $k); + } + } + } + + + } + + + + + public function maintPage() + { + if(isset($_POST['pm_maint_execute'])) + { + $this->mainPageProcess(); + } + + + + $frm = e107::getForm(); + $pmPrefs = e107::pref('pm'); + + $txt = " +
+ ".ADLAN_PM_62." +
+ + + + + + + + + + + + + + + + + + + "; + + if ($pmPrefs['read_timeout'] || $pmPrefs['unread_timeout']) + { + $txt .= " + + + + "; + } + + $txt .= " + + + + + +
".ADLAN_PM_63."".$frm->radio_switch('pm_maint_sent', '', LAN_YES, LAN_NO)."
".ADLAN_PM_64."".$frm->radio_switch('pm_maint_rec', '', LAN_YES, LAN_NO)."
".ADLAN_PM_65."".$frm->radio_switch('pm_maint_blocked', '', LAN_YES, LAN_NO)."
".ADLAN_PM_71."".$frm->radio_switch('pm_maint_expired', '', LAN_YES, LAN_NO)."
".ADLAN_PM_78."".$frm->radio_switch('pm_maint_attach', '', LAN_YES, LAN_NO)."
+
+ ".$frm->admin_button('pm_maint_execute','no-value','delete', LAN_GO)." +
+
+
+ "; + + + 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!]','
',$s); + } + } + return $results; + } + + + + /** + * Turn the array produced by doMaint for message display into an array of log strings. + * Data is sorted into time stamp order + * + * @param array $results - array of arrays as returned from doMaint() + * @param array|boolean $extra - optional additional information which is sorted into the main result according to keys - so use low numbers + * to make the entry appear at the beginning, and text strings to add to the end. + */ + function makeLogEntry($results, $extra = FALSE) + { + $logPrefixes = array(E_MESSAGE_SUCCESS => 'Pass - ', E_MESSAGE_ERROR => 'Fail - ', E_MESSAGE_INFO => 'Info - ', E_MESSAGE_DEBUG => 'Debug - '); + + $res = array(); + + foreach ($results as $k => $ma) + { + foreach ($ma as $ts => $m) + { + $res[$ts] = $logPrefixes[$k].$m; + } + } + + if (is_array($extra)) + { + $res = array_merge($res, $extra); + } + + ksort($res); // Sort in ascending order of timestamp + + return $res; + } + + + + public function init() { @@ -138,13 +810,6 @@ class private_msg_ui extends e_admin_ui } - if(vartrue($_GET['iframe'])) - { - define('e_IFRAME', true); - } - - - } @@ -191,6 +856,18 @@ class private_msg_ui extends e_admin_ui class private_msg_form_ui extends e_admin_form_ui { + function send_to_class($parms, $value, $id) + { + $list = e107::getUserClass()->getClassList('main,admin,member,classes'); + $list['matchclass'] = "(Any user with the same class)"; //TODO LAN + + return $this->select('pm_option-send_to_class', $list, vartrue($value, e_UC_MEMBER)); + + } + + + + function options($parms, $value, $id, $attributes) { diff --git a/e107_plugins/pm/languages/English_admin_pm.php b/e107_plugins/pm/languages/English_admin.php old mode 100755 new mode 100644 similarity index 100% rename from e107_plugins/pm/languages/English_admin_pm.php rename to e107_plugins/pm/languages/English_admin.php diff --git a/e107_plugins/pm/plugin.xml b/e107_plugins/pm/plugin.xml index 9ba557215..4a8a2fd9f 100755 --- a/e107_plugins/pm/plugin.xml +++ b/e107_plugins/pm/plugin.xml @@ -4,7 +4,7 @@ This plugin is a fully featured Private Messaging system. users - + 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."