onokazu
onoka****@users*****
2006年 5月 1日 (月) 11:37:30 JST
Index: xoops2jp/html/modules/system/admin/mailusers/mailusers.php diff -u xoops2jp/html/modules/system/admin/mailusers/mailusers.php:1.4 xoops2jp/html/modules/system/admin/mailusers/mailusers.php:1.5 --- xoops2jp/html/modules/system/admin/mailusers/mailusers.php:1.4 Wed Aug 3 21:39:16 2005 +++ xoops2jp/html/modules/system/admin/mailusers/mailusers.php Mon May 1 11:37:30 2006 @@ -1,5 +1,5 @@ <?php -// $Id: mailusers.php,v 1.4 2005/08/03 12:39:16 onokazu Exp $ +// $Id: mailusers.php,v 1.5 2006/05/01 02:37:30 onokazu Exp $ // ------------------------------------------------------------------------ // // XOOPS - PHP Content Management System // // Copyright (c) 2000 XOOPS.org // @@ -32,220 +32,220 @@ define ('SEND_SIM_PROCESS_AMMO',100); if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) { - exit("Access Denied"); + exit("Access Denied"); } else { - include_once XOOPS_ROOT_PATH."/class/xoopsformloader.php"; - $op = "form"; + include_once XOOPS_ROOT_PATH."/class/xoopsformloader.php"; + $op = "form"; - if (!empty($_POST['op']) && $_POST['op'] == "send") { - $op = $_POST['op']; - } - - if ( $op == "form" ) { - xoops_cp_header(); - //OpenTable(); - $display_criteria = 1; - include XOOPS_ROOT_PATH."/modules/system/admin/mailusers/mailform.php"; - $form->display(); - //CloseTable(); - xoops_cp_footer(); - } - - if ( $op == "send" && !empty($_POST['mail_send_to']) ) { - if(!XoopsSingleTokenHandler::quickValidate('mailusers_send')) { - xoops_cp_header(); - xoops_error("Ticket Error"); - xoops_cp_footer(); - exit(); - } - - $added = array(); - $added_id = array(); - $criteria = array(); - if ( !empty($_POST['mail_inactive']) ) { - $criteria[] = "level = 0"; - } else { - if (!empty($_POST['mail_mailok'])) { - $criteria[] = 'user_mailok = 1'; - } - if (!empty($_POST['mail_to_group'])) { - $member_handler =& xoops_gethandler('member'); - $user_list = array(); - foreach ($_POST['mail_to_group'] as $groupid ) { - $members =& $member_handler->getUsersByGroup($groupid, false); - // Mith: Changed this to not fetch user objects with getUsersByGroup - // as it is resource-intensive and all we want is the userIDs - $user_list = array_merge($members, $user_list); - - // RMV: changed this because makes more sense to me - // if options all grouped by 'AND', not 'OR' - /* - foreach ($members as $member) { - if (!in_array($member->getVar('uid'), $user_list)) { - $user_list[] = $member->getVar('uid'); - } - } - */ - // if (!in_array($member->getVar('uid'), $added_id) ) { - // $added_id[] = $member->getVar('uid'); - // $added[] =& $member; - // unset($member); - // } - //} - } - if (!empty($user_list)) { - $criteria[] = 'uid IN (' . join(',', $user_list) . ')'; - } - } - if ( !empty($_POST['mail_lastlog_min']) ) { - $f_mail_lastlog_min = trim($_POST['mail_lastlog_min']); - $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)); - if ( $time > 0 ) { - $criteria[] = "last_login > $time"; - } - } - if ( !empty($_POST['mail_lastlog_max']) ) { - $f_mail_lastlog_max = trim($_POST['mail_lastlog_max']); - $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)); - if ( $time > 0 ) { - $criteria[] = "last_login < $time"; - } - } - if ( !empty($_POST['mail_idle_more']) && is_numeric($_POST['mail_idle_more']) ) { - $f_mail_idle_more = intval(trim($_POST['mail_idle_more'])); - $time = 60 * 60 * 24 * $f_mail_idle_more; - $time = time() - $time; - if ( $time > 0 ) { - $criteria[] = "last_login < $time"; - } - } - if ( !empty($_POST['mail_idle_less']) && is_numeric($_POST['mail_idle_less']) ) { - $f_mail_idle_less = intval(trim($_POST['mail_idle_less'])); - $time = 60 * 60 * 24 * $f_mail_idle_less; - $time = time() - $time; - if ( $time > 0 ) { - $criteria[] = "last_login > $time"; - } - } - } - if ( !empty($_POST['mail_regd_min']) ) { - $f_mail_regd_min = trim($_POST['mail_regd_min']); - $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)); - if ( $time > 0 ) { - $criteria[] = "user_regdate > $time"; - } - } - if ( !empty($_POST['mail_regd_max']) ) { - $f_mail_regd_max = trim($_POST['mail_regd_max']); - $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)); - if ( $time > 0 ) { - $criteria[] = "user_regdate < $time"; - } - } - if ( !empty($criteria) ) { - if ( empty($_POST['mail_inactive']) ) { - $criteria[] = "level > 0"; - } - $criteria_object = new CriteriaCompo(); - foreach ($criteria as $c) { - list ($field, $op, $value) = split(' ', $c); - $criteria_object->add(new Criteria($field,$value,$op), 'AND'); - } - $member_handler =& xoops_gethandler('member'); - $getusers =& $member_handler->getUsers($criteria_object); - foreach ($getusers as $getuser) { - if ( !in_array($getuser->getVar("uid"), $added_id) ) { - $added[] = $getuser; - $added_id[] = $getuser->getVar("uid"); - } - } - } - if ( !empty($_POST['mail_to_user']) ) { - foreach ($_POST['mail_to_user'] as $to_user) { - if ( !in_array($to_user, $added_id) ) { - $added[] = new XoopsUser($to_user); - $added_id[] = $to_user; - } - } - } - $added_count = count($added); - xoops_cp_header(); - //OpenTable(); - if ( $added_count > 0 ) { - $mail_start = !empty($_POST['mail_start']) ? $_POST['mail_start'] : 0; - $mail_end = ($added_count > ($mail_start + SEND_SIM_PROCESS_AMMO)) ? ($mail_start + SEND_SIM_PROCESS_AMMO) : $added_count; - $myts =& MyTextSanitizer::getInstance(); - $xoopsMailer =& getMailer(); - for ( $i = $mail_start; $i < $mail_end; $i++) { - $xoopsMailer->setToUsers($added[$i]); - } - $xoopsMailer->setFromName($myts->oopsStripSlashesGPC($_POST['mail_fromname'])); - $xoopsMailer->setFromEmail($myts->oopsStripSlashesGPC($_POST['mail_fromemail'])); - $xoopsMailer->setSubject($myts->oopsStripSlashesGPC($_POST['mail_subject'])); - $xoopsMailer->setBody($myts->oopsStripSlashesGPC($_POST['mail_body'])); - if ( in_array("mail", $_POST['mail_send_to']) ) { - $xoopsMailer->useMail(); - } - if ( in_array("pm", $_POST['mail_send_to']) && empty($_POST['mail_inactive']) ) { - $xoopsMailer->usePM(); - } - $xoopsMailer->send(true); - echo $xoopsMailer->getSuccess(); - echo $xoopsMailer->getErrors(); - - - if ( $added_count > $mail_end ) { - $form = new XoopsThemeForm(_AM_SENDMTOUSERS, "mailusers", "admin.php?fct=mailusers"); - $form->addElement(new XoopsFormToken(XoopsSingleTokenHandler::quickCreate('mailusers_send'))); - if ( !empty($_POST['mail_to_group']) ) { - foreach ( $_POST['mail_to_group'] as $mailgroup) { - $group_hidden = new XoopsFormHidden("mail_to_group[]", $mailgroup); - $form->addElement($group_hidden); - } - } - if(isset($_POST['mail_inactive'])) - $form->addElement(new XoopsFormHidden("mail_inactive", intval($_POST['mail_inactive']))); - if(isset($_POST['mail_mailok'])) - $form->addElement(new XoopsFormHidden("mail_mailok", intval($_POST['mail_mailok']))); - $lastlog_min_hidden = new XoopsFormHidden("mail_lastlog_min", $myts->makeTboxData4PreviewInForm($_POST['mail_lastlog_min'])); - $lastlog_max_hidden = new XoopsFormHidden("mail_lastlog_max", $myts->makeTboxData4PreviewInForm($_POST['mail_lastlog_max'])); - $regd_min_hidden = new XoopsFormHidden("mail_regd_min", $myts->makeTboxData4PreviewInForm($_POST['mail_regd_max'])); - $regd_max_hidden = new XoopsFormHidden("mail_regd_max", $myts->makeTboxData4PreviewInForm($_POST['mail_regd_max'])); - $idle_more_hidden = new XoopsFormHidden("mail_idle_more", $myts->makeTboxData4PreviewInForm($_POST['mail_idle_more'])); - $idle_less_hidden = new XoopsFormHidden("mail_idle_less", $myts->makeTboxData4PreviewInForm($_POST['mail_idle_less'])); - $fname_hidden = new XoopsFormHidden("mail_fromname", $myts->makeTboxData4PreviewInForm($_POST['mail_fromname'])); - $femail_hidden = new XoopsFormHidden("mail_fromemail", $myts->makeTboxData4PreviewInForm($_POST['mail_fromemail'])); - $subject_hidden = new XoopsFormHidden("mail_subject", $myts->makeTboxData4PreviewInForm($_POST['mail_subject'])); - $body_hidden = new XoopsFormHidden("mail_body", $myts->makeTareaData4PreviewInForm($_POST['mail_body'])); - $start_hidden = new XoopsFormHidden("mail_start", $mail_end); - $to_hidden = new XoopsFormHidden("mail_send_to[]", "mail"); - $op_hidden = new XoopsFormHidden("op", "send"); - $submit_button = new XoopsFormButton("", "mail_submit", _AM_SENDNEXT, "submit"); - $sent_label = new XoopsFormLabel(_AM_SENT, sprintf(_AM_SENTNUM, $_POST['mail_start']+1, $mail_end, $added_count)); - $form->addElement($sent_label); - $form->addElement($lastlog_min_hidden); - $form->addElement($lastlog_max_hidden); - $form->addElement($regd_min_hidden); - $form->addElement($regd_max_hidden); - $form->addElement($idle_more_hidden); - $form->addElement($idle_less_hidden); - $form->addElement($fname_hidden); - $form->addElement($femail_hidden); - $form->addElement($subject_hidden); - $form->addElement($body_hidden); - $form->addElement($to_hidden); - $form->addElement($op_hidden); - $form->addElement($start_hidden); - $form->addElement($submit_button); - $form->display(); - } else { - echo "<h4>"._AM_SENDCOMP."</h4>"; - } - } else { - echo "<h4>"._AM_NOUSERMATCH."</h4>"; - } - //CloseTable(); - xoops_cp_footer(); - } + if (!empty($_POST['op']) && $_POST['op'] == "send") { + $op = $_POST['op']; + } + + if ( $op == "form" ) { + xoops_cp_header(); + //OpenTable(); + $display_criteria = 1; + include XOOPS_ROOT_PATH."/modules/system/admin/mailusers/mailform.php"; + $form->display(); + //CloseTable(); + xoops_cp_footer(); + } + + if ( $op == "send" && !empty($_POST['mail_send_to']) ) { + if(!XoopsSingleTokenHandler::quickValidate('mailusers_send')) { + xoops_cp_header(); + xoops_error("Ticket Error"); + xoops_cp_footer(); + exit(); + } + + $added = array(); + $added_id = array(); + $criteria = array(); + if ( !empty($_POST['mail_inactive']) ) { + $criteria[] = "level = 0"; + } else { + if (!empty($_POST['mail_mailok'])) { + $criteria[] = 'user_mailok = 1'; + } + if (!empty($_POST['mail_to_group'])) { + $member_handler =& xoops_gethandler('member'); + $user_list = array(); + foreach ($_POST['mail_to_group'] as $groupid ) { + $members = $member_handler->getUsersByGroup($groupid, false); + // Mith: Changed this to not fetch user objects with getUsersByGroup + // as it is resource-intensive and all we want is the userIDs + $user_list = array_merge($members, $user_list); + + // RMV: changed this because makes more sense to me + // if options all grouped by 'AND', not 'OR' + /* + foreach ($members as $member) { + if (!in_array($member->getVar('uid'), $user_list)) { + $user_list[] = $member->getVar('uid'); + } + } + */ + // if (!in_array($member->getVar('uid'), $added_id) ) { + // $added_id[] = $member->getVar('uid'); + // $added[] =& $member; + // unset($member); + // } + //} + } + if (!empty($user_list)) { + $criteria[] = 'uid IN (' . join(',', $user_list) . ')'; + } + } + if ( !empty($_POST['mail_lastlog_min']) ) { + $f_mail_lastlog_min = trim($_POST['mail_lastlog_min']); + $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)); + if ( $time > 0 ) { + $criteria[] = "last_login > $time"; + } + } + if ( !empty($_POST['mail_lastlog_max']) ) { + $f_mail_lastlog_max = trim($_POST['mail_lastlog_max']); + $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)); + if ( $time > 0 ) { + $criteria[] = "last_login < $time"; + } + } + if ( !empty($_POST['mail_idle_more']) && is_numeric($_POST['mail_idle_more']) ) { + $f_mail_idle_more = intval(trim($_POST['mail_idle_more'])); + $time = 60 * 60 * 24 * $f_mail_idle_more; + $time = time() - $time; + if ( $time > 0 ) { + $criteria[] = "last_login < $time"; + } + } + if ( !empty($_POST['mail_idle_less']) && is_numeric($_POST['mail_idle_less']) ) { + $f_mail_idle_less = intval(trim($_POST['mail_idle_less'])); + $time = 60 * 60 * 24 * $f_mail_idle_less; + $time = time() - $time; + if ( $time > 0 ) { + $criteria[] = "last_login > $time"; + } + } + } + if ( !empty($_POST['mail_regd_min']) ) { + $f_mail_regd_min = trim($_POST['mail_regd_min']); + $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)); + if ( $time > 0 ) { + $criteria[] = "user_regdate > $time"; + } + } + if ( !empty($_POST['mail_regd_max']) ) { + $f_mail_regd_max = trim($_POST['mail_regd_max']); + $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)); + if ( $time > 0 ) { + $criteria[] = "user_regdate < $time"; + } + } + if ( !empty($criteria) ) { + if ( empty($_POST['mail_inactive']) ) { + $criteria[] = "level > 0"; + } + $criteria_object = new CriteriaCompo(); + foreach ($criteria as $c) { + list ($field, $op, $value) = split(' ', $c); + $criteria_object->add(new Criteria($field,$value,$op), 'AND'); + } + $member_handler =& xoops_gethandler('member'); + $getusers = $member_handler->getUsers($criteria_object); + foreach (array_keys($getusers) as $i) { + if ( !in_array($getusers[$i]->getVar("uid"), $added_id) ) { + $added[] =& $getusers[$i]; + $added_id[] = $getusers[$i]->getVar("uid"); + } + } + } + if ( !empty($_POST['mail_to_user']) ) { + foreach ($_POST['mail_to_user'] as $to_user) { + if ( !in_array($to_user, $added_id) ) { + $added[] =& new XoopsUser($to_user); + $added_id[] = $to_user; + } + } + } + $added_count = count($added); + xoops_cp_header(); + //OpenTable(); + if ( $added_count > 0 ) { + $mail_start = !empty($_POST['mail_start']) ? $_POST['mail_start'] : 0; + $mail_end = ($added_count > ($mail_start + SEND_SIM_PROCESS_AMMO)) ? ($mail_start + SEND_SIM_PROCESS_AMMO) : $added_count; + $myts =& MyTextSanitizer::getInstance(); + $xoopsMailer =& getMailer(); + for ( $i = $mail_start; $i < $mail_end; $i++) { + $xoopsMailer->setToUsers($added[$i]); + } + $xoopsMailer->setFromName($myts->oopsStripSlashesGPC($_POST['mail_fromname'])); + $xoopsMailer->setFromEmail($myts->oopsStripSlashesGPC($_POST['mail_fromemail'])); + $xoopsMailer->setSubject($myts->oopsStripSlashesGPC($_POST['mail_subject'])); + $xoopsMailer->setBody($myts->oopsStripSlashesGPC($_POST['mail_body'])); + if ( in_array("mail", $_POST['mail_send_to']) ) { + $xoopsMailer->useMail(); + } + if ( in_array("pm", $_POST['mail_send_to']) && empty($_POST['mail_inactive']) ) { + $xoopsMailer->usePM(); + } + $xoopsMailer->send(true); + echo $xoopsMailer->getSuccess(); + echo $xoopsMailer->getErrors(); + + + if ( $added_count > $mail_end ) { + $form = new XoopsThemeForm(_AM_SENDMTOUSERS, "mailusers", "admin.php?fct=mailusers"); + $form->addElement(new XoopsFormToken(XoopsSingleTokenHandler::quickCreate('mailusers_send'))); + if ( !empty($_POST['mail_to_group']) ) { + foreach ( $_POST['mail_to_group'] as $mailgroup) { + $group_hidden = new XoopsFormHidden("mail_to_group[]", $mailgroup); + $form->addElement($group_hidden); + } + } + if(isset($_POST['mail_inactive'])) + $form->addElement(new XoopsFormHidden("mail_inactive", intval($_POST['mail_inactive']))); + if(isset($_POST['mail_mailok'])) + $form->addElement(new XoopsFormHidden("mail_mailok", intval($_POST['mail_mailok']))); + $lastlog_min_hidden = new XoopsFormHidden("mail_lastlog_min", $myts->makeTboxData4PreviewInForm($_POST['mail_lastlog_min'])); + $lastlog_max_hidden = new XoopsFormHidden("mail_lastlog_max", $myts->makeTboxData4PreviewInForm($_POST['mail_lastlog_max'])); + $regd_min_hidden = new XoopsFormHidden("mail_regd_min", $myts->makeTboxData4PreviewInForm($_POST['mail_regd_max'])); + $regd_max_hidden = new XoopsFormHidden("mail_regd_max", $myts->makeTboxData4PreviewInForm($_POST['mail_regd_max'])); + $idle_more_hidden = new XoopsFormHidden("mail_idle_more", $myts->makeTboxData4PreviewInForm($_POST['mail_idle_more'])); + $idle_less_hidden = new XoopsFormHidden("mail_idle_less", $myts->makeTboxData4PreviewInForm($_POST['mail_idle_less'])); + $fname_hidden = new XoopsFormHidden("mail_fromname", $myts->makeTboxData4PreviewInForm($_POST['mail_fromname'])); + $femail_hidden = new XoopsFormHidden("mail_fromemail", $myts->makeTboxData4PreviewInForm($_POST['mail_fromemail'])); + $subject_hidden = new XoopsFormHidden("mail_subject", $myts->makeTboxData4PreviewInForm($_POST['mail_subject'])); + $body_hidden = new XoopsFormHidden("mail_body", $myts->makeTareaData4PreviewInForm($_POST['mail_body'])); + $start_hidden = new XoopsFormHidden("mail_start", $mail_end); + $to_hidden = new XoopsFormHidden("mail_send_to[]", "mail"); + $op_hidden = new XoopsFormHidden("op", "send"); + $submit_button = new XoopsFormButton("", "mail_submit", _AM_SENDNEXT, "submit"); + $sent_label = new XoopsFormLabel(_AM_SENT, sprintf(_AM_SENTNUM, $_POST['mail_start']+1, $mail_end, $added_count)); + $form->addElement($sent_label); + $form->addElement($lastlog_min_hidden); + $form->addElement($lastlog_max_hidden); + $form->addElement($regd_min_hidden); + $form->addElement($regd_max_hidden); + $form->addElement($idle_more_hidden); + $form->addElement($idle_less_hidden); + $form->addElement($fname_hidden); + $form->addElement($femail_hidden); + $form->addElement($subject_hidden); + $form->addElement($body_hidden); + $form->addElement($to_hidden); + $form->addElement($op_hidden); + $form->addElement($start_hidden); + $form->addElement($submit_button); + $form->display(); + } else { + echo "<h4>"._AM_SENDCOMP."</h4>"; + } + } else { + echo "<h4>"._AM_NOUSERMATCH."</h4>"; + } + //CloseTable(); + xoops_cp_footer(); + } } ?>