| 1 | <?php |
|---|
| 2 | // $Id: mailusers.php,v 1.6 2006/07/27 00:17:18 onokazu Exp $ |
|---|
| 3 | // ------------------------------------------------------------------------ // |
|---|
| 4 | // XOOPS - PHP Content Management System // |
|---|
| 5 | // Copyright (c) 2000 XOOPS.org // |
|---|
| 6 | // <http://www.xoops.org/> // |
|---|
| 7 | // ------------------------------------------------------------------------ // |
|---|
| 8 | // This program is free software; you can redistribute it and/or modify // |
|---|
| 9 | // it under the terms of the GNU General Public License as published by // |
|---|
| 10 | // the Free Software Foundation; either version 2 of the License, or // |
|---|
| 11 | // (at your option) any later version. // |
|---|
| 12 | // // |
|---|
| 13 | // You may not change or alter any portion of this comment or credits // |
|---|
| 14 | // of supporting developers from this source code or any supporting // |
|---|
| 15 | // source code which is considered copyrighted (c) material of the // |
|---|
| 16 | // original comment or credit authors. // |
|---|
| 17 | // // |
|---|
| 18 | // This program is distributed in the hope that it will be useful, // |
|---|
| 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|---|
| 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|---|
| 21 | // GNU General Public License for more details. // |
|---|
| 22 | // // |
|---|
| 23 | // You should have received a copy of the GNU General Public License // |
|---|
| 24 | // along with this program; if not, write to the Free Software // |
|---|
| 25 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
|---|
| 26 | // ------------------------------------------------------------------------ // |
|---|
| 27 | // Author: Kazumi Ono (AKA onokazu) // |
|---|
| 28 | // URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ // |
|---|
| 29 | // Project: The XOOPS Project // |
|---|
| 30 | // ------------------------------------------------------------------------- // |
|---|
| 31 | |
|---|
| 32 | define ('SEND_SIM_PROCESS_AMMO',100); |
|---|
| 33 | |
|---|
| 34 | if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) { |
|---|
| 35 | exit("Access Denied"); |
|---|
| 36 | } else { |
|---|
| 37 | include_once XOOPS_ROOT_PATH."/class/xoopsformloader.php"; |
|---|
| 38 | $op = "form"; |
|---|
| 39 | |
|---|
| 40 | if (!empty($_POST['op']) && $_POST['op'] == "send") { |
|---|
| 41 | $op = $_POST['op']; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | if ( $op == "form" ) { |
|---|
| 45 | xoops_cp_header(); |
|---|
| 46 | //OpenTable(); |
|---|
| 47 | $display_criteria = 1; |
|---|
| 48 | include XOOPS_ROOT_PATH."/modules/system/admin/mailusers/mailform.php"; |
|---|
| 49 | $form->display(); |
|---|
| 50 | //CloseTable(); |
|---|
| 51 | xoops_cp_footer(); |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | if ( $op == "send" && !empty($_POST['mail_send_to']) ) { |
|---|
| 55 | if(!XoopsSingleTokenHandler::quickValidate('mailusers_send')) { |
|---|
| 56 | xoops_cp_header(); |
|---|
| 57 | xoops_error("Ticket Error"); |
|---|
| 58 | xoops_cp_footer(); |
|---|
| 59 | exit(); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | $added = array(); |
|---|
| 63 | $added_id = array(); |
|---|
| 64 | $criteria = array(); |
|---|
| 65 | if ( !empty($_POST['mail_inactive']) ) { |
|---|
| 66 | $criteria[] = "level = 0"; |
|---|
| 67 | } else { |
|---|
| 68 | if (!empty($_POST['mail_mailok'])) { |
|---|
| 69 | $criteria[] = 'user_mailok = 1'; |
|---|
| 70 | } |
|---|
| 71 | if (!empty($_POST['mail_to_group'])) { |
|---|
| 72 | $member_handler =& xoops_gethandler('member'); |
|---|
| 73 | $user_list = array(); |
|---|
| 74 | foreach ($_POST['mail_to_group'] as $groupid ) { |
|---|
| 75 | $members = $member_handler->getUsersByGroup($groupid, false); |
|---|
| 76 | // Mith: Changed this to not fetch user objects with getUsersByGroup |
|---|
| 77 | // as it is resource-intensive and all we want is the userIDs |
|---|
| 78 | $user_list = array_merge($members, $user_list); |
|---|
| 79 | |
|---|
| 80 | // RMV: changed this because makes more sense to me |
|---|
| 81 | // if options all grouped by 'AND', not 'OR' |
|---|
| 82 | /* |
|---|
| 83 | foreach ($members as $member) { |
|---|
| 84 | if (!in_array($member->getVar('uid'), $user_list)) { |
|---|
| 85 | $user_list[] = $member->getVar('uid'); |
|---|
| 86 | } |
|---|
| 87 | } |
|---|
| 88 | */ |
|---|
| 89 | // if (!in_array($member->getVar('uid'), $added_id) ) { |
|---|
| 90 | // $added_id[] = $member->getVar('uid'); |
|---|
| 91 | // $added[] =& $member; |
|---|
| 92 | // unset($member); |
|---|
| 93 | // } |
|---|
| 94 | //} |
|---|
| 95 | } |
|---|
| 96 | if (!empty($user_list)) { |
|---|
| 97 | $criteria[] = 'uid IN (' . join(',', $user_list) . ')'; |
|---|
| 98 | } |
|---|
| 99 | } |
|---|
| 100 | if ( !empty($_POST['mail_lastlog_min']) ) { |
|---|
| 101 | $f_mail_lastlog_min = trim($_POST['mail_lastlog_min']); |
|---|
| 102 | $time = mktime(0,0,0,substr($f_mail_lastlog_min,5,2),substr($f_mail_lastlog_min,8,2),substr($f_mail_lastlog_min,0,4)); |
|---|
| 103 | if ( $time > 0 ) { |
|---|
| 104 | $criteria[] = "last_login > $time"; |
|---|
| 105 | } |
|---|
| 106 | } |
|---|
| 107 | if ( !empty($_POST['mail_lastlog_max']) ) { |
|---|
| 108 | $f_mail_lastlog_max = trim($_POST['mail_lastlog_max']); |
|---|
| 109 | $time = mktime(0,0,0,substr($f_mail_lastlog_max,5,2),substr($f_mail_lastlog_max,8,2),substr($f_mail_lastlog_max,0,4)); |
|---|
| 110 | if ( $time > 0 ) { |
|---|
| 111 | $criteria[] = "last_login < $time"; |
|---|
| 112 | } |
|---|
| 113 | } |
|---|
| 114 | if ( !empty($_POST['mail_idle_more']) && is_numeric($_POST['mail_idle_more']) ) { |
|---|
| 115 | $f_mail_idle_more = intval(trim($_POST['mail_idle_more'])); |
|---|
| 116 | $time = 60 * 60 * 24 * $f_mail_idle_more; |
|---|
| 117 | $time = time() - $time; |
|---|
| 118 | if ( $time > 0 ) { |
|---|
| 119 | $criteria[] = "last_login < $time"; |
|---|
| 120 | } |
|---|
| 121 | } |
|---|
| 122 | if ( !empty($_POST['mail_idle_less']) && is_numeric($_POST['mail_idle_less']) ) { |
|---|
| 123 | $f_mail_idle_less = intval(trim($_POST['mail_idle_less'])); |
|---|
| 124 | $time = 60 * 60 * 24 * $f_mail_idle_less; |
|---|
| 125 | $time = time() - $time; |
|---|
| 126 | if ( $time > 0 ) { |
|---|
| 127 | $criteria[] = "last_login > $time"; |
|---|
| 128 | } |
|---|
| 129 | } |
|---|
| 130 | } |
|---|
| 131 | if ( !empty($_POST['mail_regd_min']) ) { |
|---|
| 132 | $f_mail_regd_min = trim($_POST['mail_regd_min']); |
|---|
| 133 | $time = mktime(0,0,0,substr($f_mail_regd_min,5,2),substr($f_mail_regd_min,8,2),substr($f_mail_regd_min,0,4)); |
|---|
| 134 | if ( $time > 0 ) { |
|---|
| 135 | $criteria[] = "user_regdate > $time"; |
|---|
| 136 | } |
|---|
| 137 | } |
|---|
| 138 | if ( !empty($_POST['mail_regd_max']) ) { |
|---|
| 139 | $f_mail_regd_max = trim($_POST['mail_regd_max']); |
|---|
| 140 | $time = mktime(0,0,0,substr($f_mail_regd_max,5,2),substr($f_mail_regd_max,8,2),substr($f_mail_regd_max,0,4)); |
|---|
| 141 | if ( $time > 0 ) { |
|---|
| 142 | $criteria[] = "user_regdate < $time"; |
|---|
| 143 | } |
|---|
| 144 | } |
|---|
| 145 | if ( !empty($criteria) ) { |
|---|
| 146 | if ( empty($_POST['mail_inactive']) ) { |
|---|
| 147 | $criteria[] = "level > 0"; |
|---|
| 148 | } |
|---|
| 149 | $criteria_object = new CriteriaCompo(); |
|---|
| 150 | foreach ($criteria as $c) { |
|---|
| 151 | list ($field, $op, $value) = split(' ', $c); |
|---|
| 152 | $criteria_object->add(new Criteria($field,$value,$op), 'AND'); |
|---|
| 153 | } |
|---|
| 154 | $member_handler =& xoops_gethandler('member'); |
|---|
| 155 | $getusers = $member_handler->getUsers($criteria_object); |
|---|
| 156 | foreach (array_keys($getusers) as $i) { |
|---|
| 157 | if ( !in_array($getusers[$i]->getVar("uid"), $added_id) ) { |
|---|
| 158 | $added[] =& $getusers[$i]; |
|---|
| 159 | $added_id[] = $getusers[$i]->getVar("uid"); |
|---|
| 160 | } |
|---|
| 161 | } |
|---|
| 162 | } |
|---|
| 163 | if ( !empty($_POST['mail_to_user']) ) { |
|---|
| 164 | foreach ($_POST['mail_to_user'] as $to_user) { |
|---|
| 165 | if ( !in_array($to_user, $added_id) ) { |
|---|
| 166 | $added[] =& new XoopsUser($to_user); |
|---|
| 167 | $added_id[] = $to_user; |
|---|
| 168 | } |
|---|
| 169 | } |
|---|
| 170 | } |
|---|
| 171 | $added_count = count($added); |
|---|
| 172 | xoops_cp_header(); |
|---|
| 173 | //OpenTable(); |
|---|
| 174 | if ( $added_count > 0 ) { |
|---|
| 175 | $mail_start = !empty($_POST['mail_start']) ? $_POST['mail_start'] : 0; |
|---|
| 176 | $mail_end = ($added_count > ($mail_start + SEND_SIM_PROCESS_AMMO)) ? ($mail_start + SEND_SIM_PROCESS_AMMO) : $added_count; |
|---|
| 177 | $myts =& MyTextSanitizer::getInstance(); |
|---|
| 178 | $xoopsMailer =& getMailer(); |
|---|
| 179 | for ( $i = $mail_start; $i < $mail_end; $i++) { |
|---|
| 180 | $xoopsMailer->setToUsers($added[$i]); |
|---|
| 181 | } |
|---|
| 182 | $xoopsMailer->setFromName($myts->oopsStripSlashesGPC($_POST['mail_fromname'])); |
|---|
| 183 | $xoopsMailer->setFromEmail($myts->oopsStripSlashesGPC($_POST['mail_fromemail'])); |
|---|
| 184 | $xoopsMailer->setSubject($myts->oopsStripSlashesGPC($_POST['mail_subject'])); |
|---|
| 185 | $xoopsMailer->setBody($myts->oopsStripSlashesGPC($_POST['mail_body'])); |
|---|
| 186 | if ( in_array("mail", $_POST['mail_send_to']) ) { |
|---|
| 187 | $xoopsMailer->useMail(); |
|---|
| 188 | } |
|---|
| 189 | if ( in_array("pm", $_POST['mail_send_to']) && empty($_POST['mail_inactive']) ) { |
|---|
| 190 | $xoopsMailer->usePM(); |
|---|
| 191 | } |
|---|
| 192 | $xoopsMailer->send(true); |
|---|
| 193 | echo $xoopsMailer->getSuccess(); |
|---|
| 194 | echo $xoopsMailer->getErrors(); |
|---|
| 195 | |
|---|
| 196 | |
|---|
| 197 | if ( $added_count > $mail_end ) { |
|---|
| 198 | $form = new XoopsThemeForm(_AM_SENDMTOUSERS, "mailusers", "admin.php?fct=mailusers"); |
|---|
| 199 | $form->addElement(new XoopsFormToken(XoopsSingleTokenHandler::quickCreate('mailusers_send'))); |
|---|
| 200 | if ( !empty($_POST['mail_to_group']) ) { |
|---|
| 201 | foreach ( $_POST['mail_to_group'] as $mailgroup) { |
|---|
| 202 | $group_hidden = new XoopsFormHidden("mail_to_group[]", $mailgroup); |
|---|
| 203 | $form->addElement($group_hidden); |
|---|
| 204 | } |
|---|
| 205 | } |
|---|
| 206 | if(isset($_POST['mail_inactive'])) |
|---|
| 207 | $form->addElement(new XoopsFormHidden("mail_inactive", intval($_POST['mail_inactive']))); |
|---|
| 208 | if(isset($_POST['mail_mailok'])) |
|---|
| 209 | $form->addElement(new XoopsFormHidden("mail_mailok", intval($_POST['mail_mailok']))); |
|---|
| 210 | $lastlog_min_hidden = new XoopsFormHidden("mail_lastlog_min", $myts->makeTboxData4PreviewInForm($_POST['mail_lastlog_min'])); |
|---|
| 211 | $lastlog_max_hidden = new XoopsFormHidden("mail_lastlog_max", $myts->makeTboxData4PreviewInForm($_POST['mail_lastlog_max'])); |
|---|
| 212 | $regd_min_hidden = new XoopsFormHidden("mail_regd_min", $myts->makeTboxData4PreviewInForm($_POST['mail_regd_max'])); |
|---|
| 213 | $regd_max_hidden = new XoopsFormHidden("mail_regd_max", $myts->makeTboxData4PreviewInForm($_POST['mail_regd_max'])); |
|---|
| 214 | $idle_more_hidden = new XoopsFormHidden("mail_idle_more", $myts->makeTboxData4PreviewInForm($_POST['mail_idle_more'])); |
|---|
| 215 | $idle_less_hidden = new XoopsFormHidden("mail_idle_less", $myts->makeTboxData4PreviewInForm($_POST['mail_idle_less'])); |
|---|
| 216 | $fname_hidden = new XoopsFormHidden("mail_fromname", $myts->makeTboxData4PreviewInForm($_POST['mail_fromname'])); |
|---|
| 217 | $femail_hidden = new XoopsFormHidden("mail_fromemail", $myts->makeTboxData4PreviewInForm($_POST['mail_fromemail'])); |
|---|
| 218 | $subject_hidden = new XoopsFormHidden("mail_subject", $myts->makeTboxData4PreviewInForm($_POST['mail_subject'])); |
|---|
| 219 | $body_hidden = new XoopsFormHidden("mail_body", $myts->makeTareaData4PreviewInForm($_POST['mail_body'])); |
|---|
| 220 | $start_hidden = new XoopsFormHidden("mail_start", $mail_end); |
|---|
| 221 | $op_hidden = new XoopsFormHidden("op", "send"); |
|---|
| 222 | $submit_button = new XoopsFormButton("", "mail_submit", _AM_SENDNEXT, "submit"); |
|---|
| 223 | $sent_label = new XoopsFormLabel(_AM_SENT, sprintf(_AM_SENTNUM, $_POST['mail_start']+1, $mail_end, $added_count)); |
|---|
| 224 | $form->addElement($sent_label); |
|---|
| 225 | $form->addElement($lastlog_min_hidden); |
|---|
| 226 | $form->addElement($lastlog_max_hidden); |
|---|
| 227 | $form->addElement($regd_min_hidden); |
|---|
| 228 | $form->addElement($regd_max_hidden); |
|---|
| 229 | $form->addElement($idle_more_hidden); |
|---|
| 230 | $form->addElement($idle_less_hidden); |
|---|
| 231 | $form->addElement($fname_hidden); |
|---|
| 232 | $form->addElement($femail_hidden); |
|---|
| 233 | $form->addElement($subject_hidden); |
|---|
| 234 | $form->addElement($body_hidden); |
|---|
| 235 | if (in_array('mail', $_POST['mail_send_to'])) { |
|---|
| 236 | $to_hidden = new XoopsFormHidden('mail_send_to[]', 'mail'); |
|---|
| 237 | $form->addElement($to_hidden); |
|---|
| 238 | } |
|---|
| 239 | if (in_array('pm', $_POST['mail_send_to']) && empty($_POST['mail_inactive'])) { |
|---|
| 240 | $to_hidden = new XoopsFormHidden('mail_send_to[]', 'pm'); |
|---|
| 241 | $form->addElement($to_hidden); |
|---|
| 242 | } |
|---|
| 243 | $form->addElement($op_hidden); |
|---|
| 244 | $form->addElement($start_hidden); |
|---|
| 245 | $form->addElement($submit_button); |
|---|
| 246 | $form->display(); |
|---|
| 247 | } else { |
|---|
| 248 | echo "<h4>"._AM_SENDCOMP."</h4>"; |
|---|
| 249 | } |
|---|
| 250 | } else { |
|---|
| 251 | echo "<h4>"._AM_NOUSERMATCH."</h4>"; |
|---|
| 252 | } |
|---|
| 253 | //CloseTable(); |
|---|
| 254 | xoops_cp_footer(); |
|---|
| 255 | } |
|---|
| 256 | } |
|---|
| 257 | ?> |
|---|