XOOPS  2.6.0
send_mails.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
13 
25 include_once __DIR__ . '/header.php';
26 
28 // Parameters
29 $limit = 100;
30 // Get Action type
31 $op = Request::getString('op', 'list');
32 $memberslist_id = Request::getArray('memberslist_id', array());
33 
34 // Call Header
35 $xoops->header('admin:mailusers/mailusers_send_mail.tpl');
36 // Define Stylesheet
37 $xoops->theme()->addBaseStylesheetAssets('modules/system/css/admin.css');
38 $xoops->theme()->addBaseScriptAssets(array('@jquery','media/xoops/xoops.js','modules/system/js/admin.js'));
39 
40 $admin_page = new \Xoops\Module\Admin();
41 $admin_page->renderNavigation('send_mails.php');
42 
43 switch ($op) {
44 
45  case 'list':
46  default:
47  $display_criteria = 1;
48  $form = new Xoops\Form\ThemeForm(_AM_MAILUSERS_LIST, "mailusers", "send_mails.php", 'post', true);
49  //----------------------------------------
50  if (!empty($memberslist_id) && (Request::getMethod()=='POST')) {
51  $user_count = count($memberslist_id);
52  $display_names = "";
53  for ($i = 0; $i < $user_count; ++$i) {
54  $uid_hidden = new Xoops\Form\Hidden("mail_to_user[]", $memberslist_id[$i]);
55  $form->addElement($uid_hidden);
56  $display_names .= "<a href='" . \XoopsBaseConfig::get('url') . "/userinfo.php?uid=" . $memberslist_id[$i] . "' rel='external'>" . XoopsUser::getUnameFromId($memberslist_id[$i]) . "</a>, ";
57  unset($uid_hidden);
58  }
59  $users_label = new Xoops\Form\Label(_AM_MAILUSERS_SENDTOUSERS2, substr($display_names, 0, -2));
60  $form->addElement($users_label);
61  $form->addElement($users_label);
62  $display_criteria = 0;
63  }
64  //----------------------------------------
65  if (!empty($display_criteria)) {
66  $selected_groups = array();
67  $group_select = new Xoops\Form\SelectGroup('<div class="bold spacer">' . _AM_MAILUSERS_GROUPIS . '<span class="bold green">*</span></div>', "mail_to_group", false, $selected_groups, 5, true);
68 
69  $lastlog_min = new Xoops\Form\DateSelect(_AM_MAILUSERS_LASTLOGMIN . '<span class="bold green">*</span>', 'mail_lastlog_min');
70  $lastlog_min->setValue('');
71  $lastlog_max = new Xoops\Form\DateSelect(_AM_MAILUSERS_LASTLOGMAX . '<span class="bold green">*</span>', 'mail_lastlog_max');
72  $lastlog_max->setValue('');
73 
74  $date = new Xoops\Form\ElementTray('<div class="bold spacer">' . _AM_MAILUSERS_DATE . '</div>', '');
75  $date->addElement($lastlog_min);
76  $date->addElement($lastlog_max);
77 
78  $idle_more = new Xoops\Form\Text(_AM_MAILUSERS_IDLEMORE . '<span class="bold green">*</span>', "mail_idle_more", 2, 5);
79  $idle_less = new Xoops\Form\Text(_AM_MAILUSERS_IDLELESS . '<span class="bold green">*</span>', "mail_idle_less", 2, 5);
80 
81  $idle = new Xoops\Form\ElementTray('<div class="bold spacer">' . _AM_MAILUSERS_DAY . '</div>', '');
82  $idle->addElement($idle_more);
83  $idle->addElement($idle_less);
84 
85  $regd_min = new Xoops\Form\DateSelect(_AM_MAILUSERS_REGDMIN . '<span class="bold green">*</span>', "mail_regd_min");
86  $regd_min->setValue('');
87  $regd_max = new Xoops\Form\DateSelect(_AM_MAILUSERS_REGDMAX . '<span class="bold green">*</span>', "mail_regd_max");
88  $regd_max->setValue('');
89 
90  $regdate = new Xoops\Form\ElementTray('<div class="bold spacer">' . _AM_MAILUSERS_REGDATE . '</div>', '');
91  $regdate->addElement($regd_min);
92  $regdate->addElement($regd_max);
93 
94  $mailok_cbox = new Xoops\Form\Checkbox('', 'mail_mailok');
95  $mailok_cbox->addOption(1, _AM_MAILUSERS_MAILOK . '<span class="bold green">*</span>');
96  $inactive_cbox = new Xoops\Form\Checkbox('', "mail_inactive");
97  $inactive_cbox->addOption(1, _AM_MAILUSERS_INACTIVE . '<span class="bold green">*</span>');
98  $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[]\");'");
99 
100  $criteria_tray = new Xoops\Form\ElementTray(_AM_MAILUSERS_SENDTOUSERS, "<br /><br />");
101  $criteria_tray->setDescription('<span class="bold green">*</span>' . _AM_MAILUSERS_OPTIONAL);
102  $criteria_tray->addElement($group_select);
103  //$criteria_tray->addElement($lastlog);
104  $criteria_tray->addElement($date);
105  //$criteria_tray->addElement($lastlog_max);
106  $criteria_tray->addElement($idle);
107  //$criteria_tray->addElement($idle_less);
108  $criteria_tray->addElement($regdate);
109 
110  $criteria_tray->addElement($mailok_cbox);
111  $criteria_tray->addElement($inactive_cbox);
112 
113  //$criteria_tray->addElement($regd_max);
114  $form->addElement($criteria_tray);
115  }
116  $fname_text = new Xoops\Form\Text(_AM_MAILUSERS_MAILFNAME, "mail_fromname", 30, 255, $xoops->getConfig('fromname') ? $xoops->getConfig('fromname') :htmlspecialchars($xoops->getConfig('sitename'), ENT_QUOTES));
117  $fromemail = $xoops->getConfig('from') ? $xoops->getConfig('from') : $xoops->user->getVar("email", "E");
118  $femail_text = new Xoops\Form\Text(_AM_MAILUSERS_MAILFMAIL, "mail_fromemail", 30, 255, $fromemail);
119  $subject_caption = _AM_MAILUSERS_MAILSUBJECT . "<br /><br /><span style='font-size:x-small;font-weight:bold;'>" . _AM_MAILUSERS_MAILTAGS . "</span><br /><span style='font-size:x-small;font-weight:normal;'>" . _AM_MAILUSERS_MAILTAGS2 . "</span>";
120  $subject_text = new Xoops\Form\Text($subject_caption, "mail_subject", 50, 255);
121  $body_caption = _AM_MAILUSERS_MAILBODY . "<br /><br /><span style='font-size:x-small;font-weight:bold;'>" . _AM_MAILUSERS_MAILTAGS . "</span><br /><span style='font-size:x-small;font-weight:normal;'>" . _AM_MAILUSERS_MAILTAGS1 . "<br />" . _AM_MAILUSERS_MAILTAGS2 . "<br />" . _AM_MAILUSERS_MAILTAGS3 . "<br />" . _AM_MAILUSERS_MAILTAGS4 . "</span>";
122  $editor_configs = array();
123  $editor_configs["name"] = "mail_body";
124  $editor_configs["value"] = '';
125  $editor_configs["rows"] = 20;
126  $editor_configs["cols"] = 100;
127  $editor_configs["width"] = "100%";
128  $editor_configs["height"] = "400px";
129  $editor_configs["editor"] = $xoops->getModuleConfig('mailusers_editor');
130  $body_text = new Xoops\Form\Editor($body_caption, "mail_body", $editor_configs);
131  //$body_text = new Xoops\Form\TextArea($body_caption, "mail_body", "", 10);
132  $to_checkbox = new Xoops\Form\Checkbox(_AM_MAILUSERS_SENDTO, "mail_send_to", "mail");
133  $to_checkbox->addOption("mail", _AM_MAILUSERS_EMAIL);
134  $to_checkbox->addOption("pm", _AM_MAILUSERS_PM);
135  $start_hidden = new Xoops\Form\Hidden("mail_start", 0);
136  $op_hidden = new Xoops\Form\Hidden("op", "send");
137  $submit_button = new Xoops\Form\Button("", "mail_submit", XoopsLocale::A_SEND, "submit");
138 
139  $form->addElement($fname_text);
140  $form->addElement($femail_text);
141  $form->addElement($subject_text);
142  $form->addElement($body_text);
143  $form->addElement($to_checkbox);
144  $form->addElement($op_hidden);
145  $form->addElement($start_hidden);
146  $form->addElement($submit_button);
147  $form->setRequired($subject_text);
148  $form->setRequired($body_text);
149  $xoops->tpl()->assign('form', $form->render());
150  break;
151 
152  // Send
153  case 'send':
154 
155  $mail_send_to = Request::getArray('mail_send_to', array('mail'));
156  $mail_inactive = Request::getInt('mail_inactive', 0);
157  $mail_mailok = Request::getInt('mail_mailok', 0);
158  $mail_lastlog_min = Request::getString('mail_lastlog_min', '');
159  $mail_lastlog_max = Request::getString('mail_lastlog_max', '');
160  $mail_idle_more = Request::getInt('mail_idle_more', 0);
161  $mail_idle_less = Request::getInt('mail_idle_less', 0);
162  $mail_regd_min = Request::getString('mail_regd_min', '');
163  $mail_regd_max = Request::getString('mail_regd_max', '');
164  $mail_to_group = Request::getArray('mail_to_group', array());
165  $mail_to_group = array_map("intval", $mail_to_group);
166  $mail_start = Request::getInt('mail_start', 0);
167  $mail_to_user = Request::getArray('mail_to_user', array());
168  $mail_to_user = array_map("intval", $mail_to_user);
169 
170  $mail_fromname = Request::getString('mail_fromname');
171  $mail_fromemail = Request::getString('mail_fromemail');
172  $mail_subject = Request::getString('mail_subject');
173  $mail_body = Request::getString('mail_body');
174 
175  $count_criteria = 0; // user count via criteria;
176  if (!empty($mail_send_to)) {
177  $added = array();
178  $added_id = array();
179  $criteria = array();
180  if ($mail_inactive) {
181  $criteria[] = "level = 0";
182  } else {
183  if ($mail_mailok) {
184  $criteria[] = 'user_mailok = 1';
185  }
186  if ($mail_lastlog_min) {
187  $time = strtotime(trim($mail_lastlog_min));
188  if ($time > 0) {
189  $criteria[] = "last_login > $time";
190  }
191  }
192  if ($mail_lastlog_max) {
193  $time = strtotime(trim($mail_lastlog_max));
194  if ($time > 0) {
195  $criteria[] = "last_login < $time";
196  }
197  }
198  if ($mail_idle_more) {
199  $time = 60 * 60 * 24 * $mail_idle_more;
200  $time = time() - $time;
201  if ($time > 0) {
202  $criteria[] = "last_login < $time";
203  }
204  }
205  if ($mail_idle_less) {
206  $time = 60 * 60 * 24 * $mail_idle_less;
207  $time = time() - $time;
208  if ($time > 0) {
209  $criteria[] = "last_login > $time";
210  }
211  }
212  }
213  if ($mail_regd_min) {
214  $time = strtotime(trim($mail_regd_min));
215  if ($time > 0) {
216  $criteria[] = "user_regdate > $time";
217  }
218  }
219  if ($mail_regd_max) {
220  $time = strtotime(trim($mail_regd_max));
221  if ($time > 0) {
222  $criteria[] = "user_regdate < $time";
223  }
224  }
225 
226  if (!empty($criteria) || !empty($mail_to_group)) {
227  $criteria_object = new CriteriaCompo();
228  $criteria_object->setStart($mail_start);
229  $criteria_object->setLimit($limit);
230  foreach ($criteria as $c) {
231  list ($field, $op, $value) = explode(' ', $c);
232  $crit = new Criteria($field, $value, $op);
233  $crit->prefix = "u";
234  $criteria_object->add($crit, 'AND');
235  }
236  $member_handler = $xoops->getHandlerMember();
237  $getusers = $member_handler->getUsersByGroupLink($mail_to_group, $criteria_object, true);
238  $count_criteria = $member_handler->getUserCountByGroupLink($mail_to_group, $criteria_object);
239  foreach ($getusers as $getuser) {
240  /* @var $getuser XoopsUser */
241  if (!in_array($getuser->getVar("uid"), $added_id)) {
242  $added[] = $getuser;
243  $added_id[] = $getuser->getVar("uid");
244  }
245  }
246  }
247 
248  foreach ($mail_to_user as $to_user) {
249  if (!in_array($to_user, $added_id)) {
250  $added[] = new XoopsUser($to_user);
251  $added_id[] = $to_user;
252  }
253  }
254  $added_count = count($added);
255 
256  //OpenTable();
257  if ($added_count > 0) {
259  $xoopsMailer = $xoops->getMailer();
260  for ($i = 0; $i < $added_count; ++$i) {
261  $xoopsMailer->setToUsers($added[$i]);
262  }
263  $xoopsMailer->setFromName($mail_fromname);
264  $xoopsMailer->setFromEmail($mail_fromemail);
265  $xoopsMailer->setSubject($mail_subject);
266  $xoopsMailer->setBody($mail_body);
267  if (in_array("mail", $mail_send_to)) {
268  $xoopsMailer->useMail();
269  }
270  if (in_array("pm", $mail_send_to) && !$mail_inactive) {
271  $xoopsMailer->usePM();
272  }
273  $xoopsMailer->send(true);
274  $xoops->tpl()->assign('sucess', $xoopsMailer->getSuccess());
275  $xoops->tpl()->assign('errors', $xoopsMailer->getErrors());
276 
277  if ($count_criteria > $limit) {
278  //todo, is this url corret?
279  $form = new Xoops\Form\ThemeForm(_AM_MAILUSERS_SENDTOUSERS2, "mailusers", "send_mails.php", 'post', true);
280  foreach ($mail_to_group as $mailgroup) {
281  $group_hidden = new Xoops\Form\Hidden("mail_to_group[]", $mailgroup);
282  $form->addElement($group_hidden);
283  }
284  $inactive_hidden = new Xoops\Form\Hidden("mail_inactive", $mail_inactive);
285  $lastlog_min_hidden = new Xoops\Form\Hidden("mail_lastlog_min", $myts->htmlSpecialChars($mail_lastlog_min));
286  $lastlog_max_hidden = new Xoops\Form\Hidden("mail_lastlog_max", $myts->htmlSpecialChars($mail_lastlog_max));
287  $regd_min_hidden = new Xoops\Form\Hidden("mail_regd_min", $myts->htmlSpecialChars($mail_regd_min));
288  $regd_max_hidden = new Xoops\Form\Hidden("mail_regd_max", $myts->htmlSpecialChars($mail_regd_max));
289  $idle_more_hidden = new Xoops\Form\Hidden("mail_idle_more", $myts->htmlSpecialChars($mail_idle_more));
290  $idle_less_hidden = new Xoops\Form\Hidden("mail_idle_less", $myts->htmlSpecialChars($mail_idle_less));
291  $fname_hidden = new Xoops\Form\Hidden("mail_fromname", $myts->htmlSpecialChars($mail_fromname));
292  $femail_hidden = new Xoops\Form\Hidden("mail_fromemail", $myts->htmlSpecialChars($mail_fromemail));
293  $subject_hidden = new Xoops\Form\Hidden("mail_subject", $myts->htmlSpecialChars($mail_subject));
294  $body_hidden = new Xoops\Form\Hidden("mail_body", $myts->htmlSpecialChars($mail_body));
295  $start_hidden = new Xoops\Form\Hidden("mail_start", $mail_start + $limit);
296  $mail_mailok_hidden = new Xoops\Form\Hidden("mail_mailok", $myts->htmlSpecialChars($mail_mailok));
297  $op_hidden = new Xoops\Form\Hidden("op", "send");
298  $submit_button = new Xoops\Form\Button("", "mail_submit", _AM_MAILUSERS_SENDNEXT, "submit");
299  $sent_label = new Xoops\Form\Label(_AM_MAILUSERS_SENT, sprintf(_AM_MAILUSERS_SENTNUM, $mail_start + 1, $mail_start + $limit, $count_criteria + $added_count - $limit));
300  $form->addElement($sent_label);
301  $form->addElement($inactive_hidden);
302  $form->addElement($lastlog_min_hidden);
303  $form->addElement($lastlog_max_hidden);
304  $form->addElement($regd_min_hidden);
305  $form->addElement($regd_max_hidden);
306  $form->addElement($idle_more_hidden);
307  $form->addElement($idle_less_hidden);
308  $form->addElement($fname_hidden);
309  $form->addElement($femail_hidden);
310  $form->addElement($subject_hidden);
311  $form->addElement($body_hidden);
312  $form->addElement($op_hidden);
313  $form->addElement($start_hidden);
314  $form->addElement($mail_mailok_hidden);
315  foreach ($mail_send_to as $v) {
316  $form->addElement(new Xoops\Form\Hidden("mail_send_to[]", $v));
317  }
318  $form->addElement($submit_button);
319  $xoops->tpl()->assign('form', $form->render());
320  } else {
321  $xoops->tpl()->assign('sucess', _AM_MAILUSERS_SENDCOMP);
322  }
323  } else {
324  $xoops->tpl()->assign('errors', _AM_MAILUSERS_NOUSERMATCH);
325  }
326  }
327  break;
328 }
329 // Call Footer
330 $xoops->footer();
const _AM_MAILUSERS_SENDCOMP
Definition: admin.php:72
const _AM_MAILUSERS_SENT
Definition: admin.php:76
$op
Definition: send_mails.php:31
const _AM_MAILUSERS_EMAIL
Definition: admin.php:37
const _AM_MAILUSERS_LASTLOGMIN
Definition: admin.php:45
const A_SEND
Definition: en_US.php:126
if($uname== ''||$pass== '') $member_handler
Definition: checklogin.php:44
$i
Definition: dialog.php:68
const _AM_MAILUSERS_IDLELESS
Definition: admin.php:41
$admin_page
Definition: send_mails.php:40
static getInstance()
Definition: Xoops.php:160
$xoops
Definition: send_mails.php:27
const _AM_MAILUSERS_MAILTAGS3
Definition: admin.php:64
const _AM_MAILUSERS_REGDMAX
Definition: admin.php:49
const _AM_MAILUSERS_MAILFMAIL
Definition: admin.php:59
const _AM_MAILUSERS_SENDTOUSERS
Definition: admin.php:74
const _AM_MAILUSERS_MAILTAGS1
Definition: admin.php:62
$form
Definition: xoops_code.php:21
const _AM_MAILUSERS_GROUPIS
Definition: admin.php:38
const _AM_MAILUSERS_REGDATE
Definition: admin.php:47
const _AM_MAILUSERS_REGDMIN
Definition: admin.php:48
const _AM_MAILUSERS_OPTIONAL
Definition: admin.php:54
const _AM_MAILUSERS_MAILTAGS4
Definition: admin.php:65
const _AM_MAILUSERS_SENDTO
Definition: admin.php:73
const _AM_MAILUSERS_MAILSUBJECT
Definition: admin.php:66
$getuser
Definition: lostpass.php:41
static getUnameFromId($userid, $usereal=0)
Definition: user.php:124
const _AM_MAILUSERS_DATE
Definition: admin.php:43
static get($name)
const _AM_MAILUSERS_SENDTOUSERS2
Definition: admin.php:75
$regdate
const _AM_MAILUSERS_LIST
Definition: admin.php:56
const _AM_MAILUSERS_DAY
Definition: admin.php:39
const _AM_MAILUSERS_SENTNUM
Definition: admin.php:77
const _AM_MAILUSERS_MAILTAGS2
Definition: admin.php:63
const _AM_MAILUSERS_PM
Definition: admin.php:70
const _AM_MAILUSERS_IDLEMORE
Definition: admin.php:40
const _AM_MAILUSERS_SENDNEXT
Definition: admin.php:68
const _AM_MAILUSERS_NOUSERMATCH
Definition: admin.php:69
$limit
Definition: send_mails.php:29
$memberslist_id
Definition: send_mails.php:32
$criteria
const _AM_MAILUSERS_MAILFNAME
Definition: admin.php:58
const _AM_MAILUSERS_MAILTAGS
Definition: admin.php:61
$myts
Definition: edituser.php:38
const _AM_MAILUSERS_LASTLOGMAX
Definition: admin.php:44
const _AM_MAILUSERS_INACTIVE
Definition: admin.php:51
const _AM_MAILUSERS_MAILOK
Definition: admin.php:52
const _AM_MAILUSERS_MAILBODY
Definition: admin.php:57