3 * Site Admin page for setting up massmailings.
5 * This is frontend of SF massmail facility, which allows to prepare
6 * messages for delivery to target categories of site users. very
7 * delivery is performed via cronjob.
9 * Copyright 1999-2001 (c) VA Linux Systems
10 * Copyright 2010 (c) Franck Villaume - Capgemini
11 * Copyright (C) 2010 Alain Peyrat - Alcatel-Lucent
12 * Copyright 2014, Franck Villaume - TrivialDev
14 * This file is part of FusionForge. FusionForge is free software;
15 * you can redistribute it and/or modify it under the terms of the
16 * GNU General Public License as published by the Free Software
17 * Foundation; either version 2 of the Licence, or (at your option)
20 * FusionForge is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License along
26 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
27 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 require_once '../env.inc.php';
31 require_once $gfcommon.'include/pre.php';
32 require_once $gfwww.'admin/admin_utils.php';
35 global $error_msg, $feedback;
37 session_require_global_perm ('forge_admin');
39 if (getStringFromRequest('action')) {
40 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
41 exit_form_double_submit('admin');
43 switch (getStringFromRequest('action')) {
45 $mail_type = getStringFromRequest('mail_type');
46 $mail_message = getStringFromRequest('mail_message');
47 $mail_subject = getStringFromRequest('mail_subject');
50 form_release_key(getStringFromRequest('form_key'));
51 exit_missing_param('',array(_('Target Audience')),'admin');
54 if (!trim($mail_message)) {
55 form_release_key(getStringFromRequest('form_key'));
56 exit_missing_param('',array(_('No Message')),'admin');
59 if (trim($mail_subject) == '['.forge_get_config ('forge_name').']') {
60 form_release_key(getStringFromRequest('form_key'));
61 exit_missing_param('',array(_('No Subject')),'admin');
64 $res = db_query_params ('
65 INSERT INTO massmail_queue(type,subject,message,queued_date)
73 if (!$res || db_affected_rows($res)<1) {
74 form_release_key(getStringFromRequest('form_key'));
75 $error_msg = _('Scheduling Mailing, Could not schedule mailing, database error')._(': ').db_error();
77 $systasksq = new SysTasksQ();
78 $systasksq->add(SYSTASK_CORE, 'MASSMAIL', null, user_getid());
79 $feedback = _('Mailing successfully scheduled for delivery');
84 $id = getIntFromRequest('id');
86 form_release_key(getStringFromRequest('form_key'));
87 exit_missing_param('',array(_('Delivery Id')),'admin');
89 $res = db_query_params('DELETE FROM massmail_queue WHERE id = $1',
91 if (!$res || db_affected_rows($res)<1) {
92 form_release_key(getStringFromRequest('form_key'));
93 $error_msg = _('Scheduling Mailing, Could not delete mailing, database error')._(': ').db_error();
95 $feedback = _('Mailing successfully deleted');
102 $title = sprintf(_('Mail Engine for %s Subscribers'), forge_get_config('forge_name'));
103 site_admin_header(array('title' => $title));
105 echo html_e('p', array(), util_make_link('/admin/massmail.php#active', _('Active Deliveries')));
106 echo html_e('p', array(), _('Be <span class="important">VERY</span> careful with this form, because submitting it WILL lead to sending email to lots of users.'));
108 echo $HTML->openForm(array('action' => '/admin/massmail.php?action=add', 'method' => 'post'))
109 .html_e('input', array('type' => 'hidden', 'name' => 'form_key', 'value' => form_generate_key()))
110 .html_e('strong', array(), _('Target Audience').utils_requiredField()._(':'))
112 .html_build_select_box_from_arrays(
113 array(0,'SITE','COMMNTY','DVLPR','ADMIN','ALL','SFDVLPR'),
116 _('Subscribers to “Site Updates”'),
117 _('Subscribers to “Additional Community Mailings”'),
118 _('All Project Developers'),
119 _('All Project Admins'),
121 forge_get_config('forge_name'). _('Developers (test)')
123 'mail_type',false,false
127 echo html_e('p', array(),
128 html_e('strong', array(), _('Subject').utils_requiredField()._(':'))
130 .html_e('input', array('type' => 'text', 'required' => 'required', 'name' => 'mail_subject', 'size' => 50, 'value' => '['.forge_get_config('forge_name').']')));
131 echo html_e('p', array(),
132 html_e('strong', array(), _('Text of Message').utils_requiredField()._(': '))._('(will be appended with unsubscription information, if applicable)'));
134 echo html_e('textarea', array('required' => 'required', 'name' => 'mail_message', 'cols' => 70, 'rows' => 20), '' , false);
136 echo html_e('p', array(), html_e('input', array('type' => 'submit', 'value' => _('Schedule for Mailing'))));
137 echo $HTML->closeForm();
139 $res = db_query_params('
142 WHERE finished_date=0
150 $title[]=_('Subject');
152 $title[]=_('Last user_id mailed');
154 echo html_e('h2', array('id' => 'active'), _('Active Deliveries')._(':'));
158 while ($row = db_fetch_array($res)) {
160 echo $HTML->listTableTop($title);
164 $cells[][] = util_make_link('/admin/massmail.php?id='.$row['id'].'&action=del', _('Delete'));
165 $cells[][] = $row['id'];
166 $cells[][] = $row['type'];
167 $cells[][] = $row['subject'];
168 $cells[][] = date(_('Y-m-d H:i'), $row['queued_date']);
169 $cells[][] = $row['last_userid'];
170 echo $HTML->multiTableRow(array(), $cells);
174 echo $HTML->listTableBottom();
176 echo $HTML->information(_('No deliveries active.'));
183 // c-file-style: "bsd"