home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / CMS / xoops-2.0.18.1.exe / xoops-2.0.18.1 / htdocs / modules / system / admin / mailusers / mailusers.php < prev    next >
Encoding:
PHP Script  |  2007-09-09  |  12.2 KB  |  225 lines

  1. <?php
  2. // $Id: mailusers.php 1029 2007-09-09 03:49:25Z phppp $
  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. if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) {
  33.     exit("Access Denied");
  34. } else {
  35.     include_once XOOPS_ROOT_PATH."/class/xoopsformloader.php";
  36.     $op = "form";
  37.     $limit = 100;
  38.     
  39.     if (!empty($_POST['op']) && $_POST['op'] == "send") {
  40.         $op =  $_POST['op'];
  41.     }
  42.  
  43.     if ( !$GLOBALS['xoopsSecurity']->check() || $op == "form" ) {
  44.         xoops_cp_header();
  45.         //OpenTable();
  46.         if ($op != "form" && $error_msg = $GLOBALS['xoopsSecurity']->getErrors(true)) {
  47.             echo "<div class='errorMsg'>{$error_msg}</div>";
  48.         }
  49.         $display_criteria = 1;
  50.         include XOOPS_ROOT_PATH."/modules/system/admin/mailusers/mailform.php";
  51.         $form->display();
  52.         //CloseTable();
  53.         xoops_cp_footer();
  54.     }
  55.  
  56.     if ($op == "send" && !empty($_POST['mail_send_to'])) {
  57.         $added = array();
  58.         $added_id = array();
  59.         $criteria = array();
  60.         $count_criteria = 0; // user count via criteria;
  61.         if ( !empty($_POST['mail_inactive']) ) {
  62.             $criteria[] = "level = 0";
  63.         } else {
  64.             if (!empty($_POST['mail_mailok'])) {
  65.                 $criteria[] = 'user_mailok = 1';
  66.             }
  67.             if ( !empty($_POST['mail_lastlog_min']) ) {
  68.                 $f_mail_lastlog_min = trim($_POST['mail_lastlog_min']);
  69.                 $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));
  70.                 if ( $time > 0 ) {
  71.                     $criteria[] = "last_login > $time";
  72.                 }
  73.             }
  74.             if ( !empty($_POST['mail_lastlog_max']) ) {
  75.                 $f_mail_lastlog_max = trim($_POST['mail_lastlog_max']);
  76.                 $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));
  77.                 if ( $time > 0 ) {
  78.                     $criteria[] = "last_login < $time";
  79.                 }
  80.             }
  81.             if ( !empty($_POST['mail_idle_more']) && is_numeric($_POST['mail_idle_more']) ) {
  82.                 $f_mail_idle_more = intval(trim($_POST['mail_idle_more']));
  83.                 $time = 60 * 60 * 24 * $f_mail_idle_more;
  84.                 $time = time() - $time;
  85.                 if ( $time > 0 ) {
  86.                     $criteria[] = "last_login < $time";
  87.                 }
  88.             }
  89.             if ( !empty($_POST['mail_idle_less']) && is_numeric($_POST['mail_idle_less']) ) {
  90.                 $f_mail_idle_less = intval(trim($_POST['mail_idle_less']));
  91.                 $time = 60 * 60 * 24 * $f_mail_idle_less;
  92.                 $time = time() - $time;
  93.                 if ( $time > 0 ) {
  94.                     $criteria[] = "last_login > $time";
  95.                 }
  96.             }
  97.         }
  98.         if ( !empty($_POST['mail_regd_min']) ) {
  99.             $f_mail_regd_min = trim($_POST['mail_regd_min']);
  100.             $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));
  101.             if ( $time > 0 ) {
  102.                 $criteria[] = "user_regdate > $time";
  103.             }
  104.         }
  105.         if ( !empty($_POST['mail_regd_max']) ) {
  106.             $f_mail_regd_max = trim($_POST['mail_regd_max']);
  107.             $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));
  108.             if ( $time > 0 ) {
  109.                 $criteria[] = "user_regdate < $time";
  110.             }
  111.         }
  112.         if ( !empty($criteria) || !empty($_POST['mail_to_group']) ) {
  113.             $criteria_object = new CriteriaCompo();
  114.             $criteria_object->setStart( @$_POST['mail_start'] );
  115.             $criteria_object->setLimit( $limit );
  116.             foreach ($criteria as $c) {
  117.                 list ($field, $op, $value) = split(' ', $c);
  118.                 $crit = new Criteria($field, $value, $op);
  119.                 $crit->prefix = "u";
  120.                 $criteria_object->add($crit, 'AND');
  121.             }
  122.             $member_handler =& xoops_gethandler('member');
  123.             $groups = empty($_POST['mail_to_group']) ? array() : array_map("intval", $_POST['mail_to_group']);
  124.             $getusers = $member_handler->getUsersByGroupLink($groups, $criteria_object, true);
  125.             $count_criteria = $member_handler->getUserCountByGroupLink($groups, $criteria_object);
  126.             foreach ($getusers as $getuser) {
  127.                 if ( !in_array($getuser->getVar("uid"), $added_id) ) {
  128.                     $added[] = $getuser;
  129.                     $added_id[] = $getuser->getVar("uid");
  130.                 }
  131.             }
  132.         }
  133.         if ( !empty($_POST['mail_to_user']) ) {
  134.             foreach ($_POST['mail_to_user'] as $to_user) {
  135.                 if ( !in_array($to_user, $added_id) ) {
  136.                     $added[] = new XoopsUser($to_user);
  137.                     $added_id[] = $to_user;
  138.                 }
  139.             }
  140.         }
  141.         $added_count = count($added);
  142.         xoops_cp_header();
  143.         //OpenTable();
  144.         if ( $added_count > 0 ) {
  145.             $myts =& MyTextSanitizer::getInstance();
  146.             $xoopsMailer =& getMailer();
  147.             for ( $i = 0; $i < $added_count; $i++) {
  148.                 $xoopsMailer->setToUsers($added[$i]);
  149.             }
  150.             $xoopsMailer->setFromName($myts->oopsStripSlashesGPC($_POST['mail_fromname']));
  151.             $xoopsMailer->setFromEmail($myts->oopsStripSlashesGPC($_POST['mail_fromemail']));
  152.             $xoopsMailer->setSubject($myts->oopsStripSlashesGPC($_POST['mail_subject']));
  153.             $xoopsMailer->setBody($myts->oopsStripSlashesGPC($_POST['mail_body']));
  154.             if ( in_array("mail", $_POST['mail_send_to']) ) {
  155.                 $xoopsMailer->useMail();
  156.             }
  157.             if ( in_array("pm", $_POST['mail_send_to']) && empty($_POST['mail_inactive']) ) {
  158.                 $xoopsMailer->usePM();
  159.             }
  160.             $xoopsMailer->send(true);
  161.             echo $xoopsMailer->getSuccess();
  162.             echo $xoopsMailer->getErrors();
  163.  
  164.  
  165.             if ( $count_criteria > $limit ) {
  166.                 $form = new XoopsThemeForm(_AM_SENDMTOUSERS, "mailusers", "admin.php?fct=mailusers", 'post', true);
  167.                 if ( !empty($_POST['mail_to_group']) ) {
  168.                     foreach ( $_POST['mail_to_group'] as $mailgroup) {
  169.                         $group_hidden = new XoopsFormHidden("mail_to_group[]", $mailgroup);
  170.                         $form->addElement($group_hidden);
  171.                     }
  172.                 }
  173.                 $inactive_hidden = new XoopsFormHidden("mail_inactive", @$_POST['mail_inactive']);
  174.                 $lastlog_min_hidden = new XoopsFormHidden("mail_lastlog_min", $myts->makeTboxData4PreviewInForm($_POST['mail_lastlog_min']));
  175.                 $lastlog_max_hidden = new XoopsFormHidden("mail_lastlog_max", $myts->makeTboxData4PreviewInForm($_POST['mail_lastlog_max']));
  176.                 $regd_min_hidden = new XoopsFormHidden("mail_regd_min", $myts->makeTboxData4PreviewInForm($_POST['mail_regd_min']));
  177.                 $regd_max_hidden = new XoopsFormHidden("mail_regd_max", $myts->makeTboxData4PreviewInForm($_POST['mail_regd_max']));
  178.                 $idle_more_hidden = new XoopsFormHidden("mail_idle_more", $myts->makeTboxData4PreviewInForm($_POST['mail_idle_more']));
  179.                 $idle_less_hidden = new XoopsFormHidden("mail_idle_less", $myts->makeTboxData4PreviewInForm($_POST['mail_idle_less']));
  180.                 $fname_hidden = new XoopsFormHidden("mail_fromname", $myts->makeTboxData4PreviewInForm($_POST['mail_fromname']));
  181.                 $femail_hidden = new XoopsFormHidden("mail_fromemail", $myts->makeTboxData4PreviewInForm($_POST['mail_fromemail']));
  182.                 $subject_hidden = new XoopsFormHidden("mail_subject", $myts->makeTboxData4PreviewInForm($_POST['mail_subject']));
  183.                 $body_hidden = new XoopsFormHidden("mail_body", $myts->makeTareaData4PreviewInForm($_POST['mail_body']));
  184.                 $start_hidden = new XoopsFormHidden("mail_start", $_POST['mail_start'] + $limit);
  185.                 $mail_mailok_hidden = new XoopsFormHidden("mail_mailok", $myts->makeTboxData4PreviewInForm( @$_POST['mail_mailok'] ));
  186.                 $op_hidden = new XoopsFormHidden("op", "send");
  187.                 $submit_button = new XoopsFormButton("", "mail_submit", _AM_SENDNEXT, "submit");
  188.                 $sent_label = new XoopsFormLabel(_AM_SENT, sprintf(_AM_SENTNUM, $_POST['mail_start']+1, $_POST['mail_start'] + $limit, $count_criteria + $added_count - $limit));
  189.                 $form->addElement($sent_label);
  190.                 $form->addElement($inactive_hidden);
  191.                 $form->addElement($lastlog_min_hidden);
  192.                 $form->addElement($lastlog_max_hidden);
  193.                 $form->addElement($regd_min_hidden);
  194.                 $form->addElement($regd_max_hidden);
  195.                 $form->addElement($idle_more_hidden);
  196.                 $form->addElement($idle_less_hidden);
  197.                 $form->addElement($fname_hidden);
  198.                 $form->addElement($femail_hidden);
  199.                 $form->addElement($subject_hidden);
  200.                 $form->addElement($body_hidden);
  201.                 $form->addElement($op_hidden);
  202.                 $form->addElement($start_hidden);
  203.                 $form->addElement($mail_mailok_hidden);
  204.                 if (isset($_POST['mail_send_to']) && is_array($_POST['mail_send_to'])) {
  205.                     foreach ($_POST['mail_send_to'] as $v) {
  206.                         $form->addElement(new XoopsFormHidden("mail_send_to[]", $v));
  207.                     }
  208.                 } else {
  209.                     $to_hidden = new XoopsFormHidden("mail_send_to", 'mail');
  210.                     $form->addElement($to_hidden);
  211.                 }
  212.                 $form->addElement($submit_button);
  213.                 $form->display();
  214.             } else {
  215.                 echo "<h4>"._AM_SENDCOMP."</h4>";
  216.             }
  217.         } else {
  218.             echo "<h4>"._AM_NOUSERMATCH."</h4>";
  219.         }
  220.         //CloseTable();
  221.         xoops_cp_footer();
  222.     }
  223. }
  224. ?>
  225.