XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
main.php
Go to the documentation of this file.
1 <?php
2 // $Id: main.php 8066 2011-11-06 05:09:33Z beckmi $
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 // Check users rights
33 if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) exit( _NOPERM );
34 // Check is active
35 if ( !xoops_getModuleOption('active_mailusers', 'system') ) redirect_header( 'admin.php', 2, _AM_SYSTEM_NOTACTIVE );
36 
37 // Parameters
38 $limit = 100;
39 // Get Action type
40 $op = system_CleanVars ( $_REQUEST, 'op', 'list', 'string' );
41 // Define main template
42 $xoopsOption['template_main'] = 'system_mailusers.html';
43 // Call Header
45 // Define Stylesheet
46 $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css' );
47 $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
48 $xoTheme->addScript('modules/system/js/admin.js');
49 
50 switch ($op) {
51 
52  case 'list': default:
53  // Define Breadcrumb and tips
54  $xoBreadCrumb->addLink(_AM_SYSTEM_MAILUSERS_MANAGER, system_adminVersion('mailusers', 'adminpath'));
55  $xoBreadCrumb->addHelp( system_adminVersion('mailusers', 'help') );
56  $xoBreadCrumb->render();
57 
58  $display_criteria = 1;
59  $form = new XoopsThemeForm(_AM_SYSTEM_MAILUSERS_LIST, "mailusers", "admin.php?fct=mailusers", 'post', true);
60  if (!empty($_POST['memberslist_id'])) {
61  $user_count = count($_POST['memberslist_id']);
62  $display_names = "";
63  for ( $i = 0; $i < $user_count; $i++ ) {
64  $uid_hidden = new XoopsFormHidden("mail_to_user[]", $_POST['memberslist_id'][$i]);
65  $form->addElement($uid_hidden);
66  $display_names .= "<a href='".XOOPS_URL."/userinfo.php?uid=".$_POST['memberslist_id'][$i]."' rel='external'>".XoopsUser::getUnameFromId($_POST['memberslist_id'][$i])."</a>, ";
67  unset($uid_hidden);
68  }
69  $users_label = new XoopsFormLabel(_AM_SYSTEM_MAILUSERS_SENDTOUSERS2, substr($display_names, 0, -2));
70  $form->addElement($users_label);
71  $display_criteria = 0;
72  }
73  if ( !empty($display_criteria) ) {
74  $selected_groups = array();
75  $group_select = new XoopsFormSelectGroup( '<div class="bold spacer">' . _AM_SYSTEM_MAILUSERS_GROUPIS . '<span class="bold green">*</span></div>', "mail_to_group", false, $selected_groups, 5, true);
76 
77  $lastlog_min = new XoopsFormTextDateSelect( _AM_SYSTEM_MAILUSERS_LASTLOGMIN . '<span class="bold green">*</span>', 'mail_lastlog_min');
78  $lastlog_min->setValue('');
79  $lastlog_max = new XoopsFormTextDateSelect( _AM_SYSTEM_MAILUSERS_LASTLOGMAX . '<span class="bold green">*</span>', 'mail_lastlog_max');
80  $lastlog_max->setValue('');
81 
82  $date = new XoopsFormElementTray( '<div class="bold spacer">' . _AM_SYSTEM_MAILUSERS_DATE . '</div>', '' );
83  $date->addElement($lastlog_min);
84  $date->addElement($lastlog_max);
85 
86  $idle_more = new XoopsFormText( _AM_SYSTEM_MAILUSERS_IDLEMORE . '<span class="bold green">*</span>', "mail_idle_more", 10, 5);
87  $idle_less = new XoopsFormText( _AM_SYSTEM_MAILUSERS_IDLELESS . '<span class="bold green">*</span>', "mail_idle_less", 10, 5);
88 
89  $idle = new XoopsFormElementTray( '<div class="bold spacer">' . _AM_SYSTEM_MAILUSERS_DAY . '</div>', '' );
90  $idle->addElement($idle_more);
91  $idle->addElement($idle_less);
92 
93  $regd_min = new XoopsFormTextDateSelect(_AM_SYSTEM_MAILUSERS_REGDMIN . '<span class="bold green">*</span>', "mail_regd_min");
94  $regd_min->setValue('');
95  $regd_max = new XoopsFormTextDateSelect(_AM_SYSTEM_MAILUSERS_REGDMAX . '<span class="bold green">*</span>', "mail_regd_max");
96  $regd_max->setValue('');
97 
98  $regdate = new XoopsFormElementTray( '<div class="bold spacer">' . _AM_SYSTEM_MAILUSERS_REGDATE . '</div>', '' );
99  $regdate->addElement($regd_min);
100  $regdate->addElement($regd_max);
101 
102  $mailok_cbox = new XoopsFormCheckBox( '', 'mail_mailok');
103  $mailok_cbox->addOption(1, _AM_SYSTEM_MAILUSERS_MAILOK . '<span class="bold green">*</span>');
104  $inactive_cbox = new XoopsFormCheckBox( '', "mail_inactive");
105  $inactive_cbox->addOption(1, _AM_SYSTEM_MAILUSERS_INACTIVE . '<span class="bold green">*</span>');
106  $inactive_cbox->setExtra("onclick='javascript:disableElement(\"mail_lastlog_min\");disableElement(\"mail_lastlog_max\");disableElement(\"mail_idle_more\");disableElement(\"mail_idle_less\");disableElement(\"mail_to_group[]\");'");
107  $criteria_tray = new XoopsFormElementTray(_AM_SYSTEM_MAILUSERS_SENDTOUSERS, "<br /><br />");
108  $criteria_tray->setDescription ('<span class="bold green">*</span>' . _AM_SYSTEM_MAILUSERS_OPTIONAL );
109  $criteria_tray->addElement($group_select);
110  //$criteria_tray->addElement($lastlog);
111  $criteria_tray->addElement($date);
112  //$criteria_tray->addElement($lastlog_max);
113  $criteria_tray->addElement($idle);
114  //$criteria_tray->addElement($idle_less);
115  $criteria_tray->addElement($regdate);
116 
117  $criteria_tray->addElement($mailok_cbox);
118  $criteria_tray->addElement($inactive_cbox);
119 
120  //$criteria_tray->addElement($regd_max);
121  $form->addElement($criteria_tray);
122  }
123  $fname_text = new XoopsFormText(_AM_SYSTEM_MAILUSERS_MAILFNAME, "mail_fromname", 30, 255, htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES));
124  $fromemail = !empty($xoopsConfig['adminmail']) ? $xoopsConfig['adminmail'] : $xoopsUser->getVar("email", "E");
125  $femail_text = new XoopsFormText(_AM_SYSTEM_MAILUSERS_MAILFMAIL, "mail_fromemail", 30, 255, $fromemail);
126  $subject_caption = _AM_SYSTEM_MAILUSERS_MAILSUBJECT."<br /><br /><span style='font-size:x-small;font-weight:bold;'>" . _AM_SYSTEM_MAILUSERS_MAILTAGS . "</span><br /><span style='font-size:x-small;font-weight:normal;'>" . _AM_SYSTEM_MAILUSERS_MAILTAGS2 . "</span>";
127  $subject_text = new XoopsFormText($subject_caption, "mail_subject", 50, 255);
128  $body_caption = _AM_SYSTEM_MAILUSERS_MAILBODY."<br /><br /><span style='font-size:x-small;font-weight:bold;'>" . _AM_SYSTEM_MAILUSERS_MAILTAGS . "</span><br /><span style='font-size:x-small;font-weight:normal;'>" . _AM_SYSTEM_MAILUSERS_MAILTAGS1 . "<br />" . _AM_SYSTEM_MAILUSERS_MAILTAGS2 . "<br />" . _AM_SYSTEM_MAILUSERS_MAILTAGS3 . "<br />" . _AM_SYSTEM_MAILUSERS_MAILTAGS4 . "</span>";
129  $body_text = new XoopsFormTextArea($body_caption, "mail_body", "", 10);
130  $to_checkbox = new XoopsFormCheckBox(_AM_SYSTEM_MAILUSERS_SENDTO, "mail_send_to", "mail");
131  $to_checkbox->addOption("mail", _AM_SYSTEM_MAILUSERS_EMAIL);
132  $to_checkbox->addOption("pm", _AM_SYSTEM_MAILUSERS_PM);
133  $start_hidden = new XoopsFormHidden("mail_start", 0);
134  $op_hidden = new XoopsFormHidden("op", "send");
135  $submit_button = new XoopsFormButton("", "mail_submit", _SEND, "submit");
136 
137  $form->addElement($fname_text);
138  $form->addElement($femail_text);
139  $form->addElement($subject_text);
140  $form->addElement($body_text);
141  $form->addElement($to_checkbox);
142  $form->addElement($op_hidden);
143  $form->addElement($start_hidden);
144  $form->addElement($submit_button);
145  $form->setRequired($subject_text);
146  $form->setRequired($body_text);
147  // Assign form
148  $xoopsTpl->assign('form', $form->render());
149  break;
150 
151  // Send
152  case 'send':
153  // Define Breadcrumb and tips
154 
155  $xoBreadCrumb->addLink(_AM_SYSTEM_MAILUSERS_MANAGER, system_adminVersion('mailusers', 'adminpath'));
157  $xoBreadCrumb->render();
158 
159  if (!empty($_POST['mail_send_to'])) {
160  $added = array();
161  $added_id = array();
162  $criteria = array();
163  $count_criteria = 0; // user count via criteria;
164  if ( !empty($_POST['mail_inactive']) ) {
165  $criteria[] = "level = 0";
166  } else {
167  if (!empty($_POST['mail_mailok'])) {
168  $criteria[] = 'user_mailok = 1';
169  }
170  if ( !empty($_POST['mail_lastlog_min']) ) {
171  $time = strtotime(trim($_POST['mail_lastlog_min']));
172  if ( $time > 0 ) {
173  $criteria[] = "last_login > $time";
174  }
175  }
176  if ( !empty($_POST['mail_lastlog_max']) ) {
177  $time = strtotime(trim($_POST['mail_lastlog_max']));
178  if ( $time > 0 ) {
179  $criteria[] = "last_login < $time";
180  }
181  }
182  if ( !empty($_POST['mail_idle_more']) && is_numeric($_POST['mail_idle_more']) ) {
183  $f_mail_idle_more = intval(trim($_POST['mail_idle_more']));
184  $time = 60 * 60 * 24 * $f_mail_idle_more;
185  $time = time() - $time;
186  if ( $time > 0 ) {
187  $criteria[] = "last_login < $time";
188  }
189  }
190  if ( !empty($_POST['mail_idle_less']) && is_numeric($_POST['mail_idle_less']) ) {
191  $f_mail_idle_less = intval(trim($_POST['mail_idle_less']));
192  $time = 60 * 60 * 24 * $f_mail_idle_less;
193  $time = time() - $time;
194  if ( $time > 0 ) {
195  $criteria[] = "last_login > $time";
196  }
197  }
198  }
199  if ( !empty($_POST['mail_regd_min']) ) {
200  $time = strtotime(trim($_POST['mail_regd_min']));
201  if ( $time > 0 ) {
202  $criteria[] = "user_regdate > $time";
203  }
204  }
205  if ( !empty($_POST['mail_regd_max']) ) {
206  $time = strtotime(trim($_POST['mail_regd_max']));
207  if ( $time > 0 ) {
208  $criteria[] = "user_regdate < $time";
209  }
210  }
211  if ( !empty($criteria) || !empty($_POST['mail_to_group']) ) {
212  $criteria_object = new CriteriaCompo();
213  $criteria_object->setStart( @$_POST['mail_start'] );
214  $criteria_object->setLimit( $limit );
215  foreach ($criteria as $c) {
216  list ($field, $op, $value) = explode(' ', $c);
217  $crit = new Criteria($field, $value, $op);
218  $crit->prefix = "u";
219  $criteria_object->add($crit, 'AND');
220  }
221  $member_handler =& xoops_gethandler('member');
222  $groups = empty($_POST['mail_to_group']) ? array() : array_map("intval", $_POST['mail_to_group']);
223  $getusers = $member_handler->getUsersByGroupLink($groups, $criteria_object, true);
224  $count_criteria = $member_handler->getUserCountByGroupLink($groups, $criteria_object);
225  foreach ($getusers as $getuser) {
226  if ( !in_array($getuser->getVar("uid"), $added_id) ) {
227  $added[] = $getuser;
228  $added_id[] = $getuser->getVar("uid");
229  }
230  }
231  }
232  if ( !empty($_POST['mail_to_user']) ) {
233  foreach ($_POST['mail_to_user'] as $to_user) {
234  if ( !in_array($to_user, $added_id) ) {
235  $added[] = new XoopsUser($to_user);
236  $added_id[] = $to_user;
237  }
238  }
239  }
240  $added_count = count($added);
241 
242  //OpenTable();
243  if ( $added_count > 0 ) {
245  $xoopsMailer =& xoops_getMailer();
246  for ( $i = 0; $i < $added_count; $i++) {
247  $xoopsMailer->setToUsers($added[$i]);
248  }
249  $xoopsMailer->setFromName($myts->stripSlashesGPC($_POST['mail_fromname']));
250  $xoopsMailer->setFromEmail($myts->stripSlashesGPC($_POST['mail_fromemail']));
251  $xoopsMailer->setSubject($myts->stripSlashesGPC($_POST['mail_subject']));
252  $xoopsMailer->setBody($myts->stripSlashesGPC($_POST['mail_body']));
253  if ( in_array("mail", $_POST['mail_send_to']) ) {
254  $xoopsMailer->useMail();
255  }
256  if ( in_array("pm", $_POST['mail_send_to']) && empty($_POST['mail_inactive']) ) {
257  $xoopsMailer->usePM();
258  }
259  $xoopsMailer->send(true);
260  $xoopsTpl->assign('Sucess', $xoopsMailer->getSuccess());
261  $xoopsTpl->assign('Errors', $xoopsMailer->getErrors());
262  //echo $xoopsMailer->getSuccess();
263  //echo $xoopsMailer->getErrors();
264 
265  if ( $count_criteria > $limit ) {
266  $form = new XoopsThemeForm(_AM_SENDMTOUSERS, "mailusers", "admin.php?fct=mailusers", 'post', true);
267  if ( !empty($_POST['mail_to_group']) ) {
268  foreach ( $_POST['mail_to_group'] as $mailgroup) {
269  $group_hidden = new XoopsFormHidden("mail_to_group[]", $mailgroup);
270  $form->addElement($group_hidden);
271  }
272  }
273  $inactive_hidden = new XoopsFormHidden("mail_inactive", @$_POST['mail_inactive']);
274  $lastlog_min_hidden = new XoopsFormHidden("mail_lastlog_min", $myts->htmlSpecialChars($myts->stripSlashesGPC($_POST['mail_lastlog_min'])));
275  $lastlog_max_hidden = new XoopsFormHidden("mail_lastlog_max", $myts->htmlSpecialChars($myts->stripSlashesGPC($_POST['mail_lastlog_max'])));
276  $regd_min_hidden = new XoopsFormHidden("mail_regd_min", $myts->htmlSpecialChars($myts->stripSlashesGPC($_POST['mail_regd_min'])));
277  $regd_max_hidden = new XoopsFormHidden("mail_regd_max", $myts->htmlSpecialChars($myts->stripSlashesGPC($_POST['mail_regd_max'])));
278  $idle_more_hidden = new XoopsFormHidden("mail_idle_more", $myts->htmlSpecialChars($myts->stripSlashesGPC($_POST['mail_idle_more'])));
279  $idle_less_hidden = new XoopsFormHidden("mail_idle_less", $myts->htmlSpecialChars($myts->stripSlashesGPC($_POST['mail_idle_less'])));
280  $fname_hidden = new XoopsFormHidden("mail_fromname", $myts->htmlSpecialChars($myts->stripSlashesGPC($_POST['mail_fromname'])));
281  $femail_hidden = new XoopsFormHidden("mail_fromemail", $myts->htmlSpecialChars($myts->stripSlashesGPC($_POST['mail_fromemail'])));
282  $subject_hidden = new XoopsFormHidden("mail_subject", $myts->htmlSpecialChars($myts->stripSlashesGPC($_POST['mail_subject'])));
283  $body_hidden = new XoopsFormHidden("mail_body", $myts->htmlSpecialChars($myts->stripSlashesGPC($_POST['mail_body'])));
284  $start_hidden = new XoopsFormHidden("mail_start", $_POST['mail_start'] + $limit);
285  $mail_mailok_hidden = new XoopsFormHidden("mail_mailok", $myts->htmlSpecialChars($myts->stripSlashesGPC( @$_POST['mail_mailok'] )));
286  $op_hidden = new XoopsFormHidden("op", "send");
287  $submit_button = new XoopsFormButton("", "mail_submit", _AM_SYSTEM_MAILUSERS_SENDNEXT, "submit");
288  $sent_label = new XoopsFormLabel(_AM_SYSTEM_MAILUSERS_SENT, sprintf(_AM_SYSTEM_MAILUSERS_SENTNUM, $_POST['mail_start']+1, $_POST['mail_start'] + $limit, $count_criteria + $added_count - $limit));
289  $form->addElement($sent_label);
290  $form->addElement($inactive_hidden);
291  $form->addElement($lastlog_min_hidden);
292  $form->addElement($lastlog_max_hidden);
293  $form->addElement($regd_min_hidden);
294  $form->addElement($regd_max_hidden);
295  $form->addElement($idle_more_hidden);
296  $form->addElement($idle_less_hidden);
297  $form->addElement($fname_hidden);
298  $form->addElement($femail_hidden);
299  $form->addElement($subject_hidden);
300  $form->addElement($body_hidden);
301  $form->addElement($op_hidden);
302  $form->addElement($start_hidden);
303  $form->addElement($mail_mailok_hidden);
304  if (isset($_POST['mail_send_to']) && is_array($_POST['mail_send_to'])) {
305  foreach ($_POST['mail_send_to'] as $v) {
306  $form->addElement(new XoopsFormHidden("mail_send_to[]", $v));
307  }
308  } else {
309  $to_hidden = new XoopsFormHidden("mail_send_to", 'mail');
310  $form->addElement($to_hidden);
311  }
312  $form->addElement($submit_button);
313  $form->display();
314  } else {
315  echo "<h4>"._AM_SYSTEM_MAILUSERS_SENDCOMP."</h4>";
316  }
317  } else {
318  echo "<h4>"._AM_SYSTEM_MAILUSERS_NOUSERMATCH."</h4>";
319  }
320  }
321  break;
322 }
323 // Call Footer
325 
326 
327 ?>