Issues (1963)

html/ops/mass_email.php (5 issues)

1
<?php
2
// This file is part of BOINC.
3
// http://boinc.berkeley.edu
4
// Copyright (C) 2008 University of California
5
//
6
// BOINC is free software; you can redistribute it and/or modify it
7
// under the terms of the GNU Lesser General Public License
8
// as published by the Free Software Foundation,
9
// either version 3 of the License, or (at your option) any later version.
10
//
11
// BOINC is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
// See the GNU Lesser General Public License for more details.
15
//
16
// You should have received a copy of the GNU Lesser General Public License
17
// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
18
19
//   This is a script for sending mass email to project participants.
20
//   Test it first and use it with care, to avoid alienating your
21
//   project's volunteers.
22
23
//   Note also that the queries such as the one to find lapsed users
24
//   assume that the project keeps the results in the DB for some interval
25
//   such as a week, before purging them.  So active users will always
26
//   have at least one result in the database.
27
28
require_once("../inc/util_ops.inc");
29
require_once("../inc/email.inc");
30
31
function exit_error($message) {
32
    echo "Error: $message <br>";
33
    exit();
0 ignored issues
show
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
34
}
35
36
// These are set to large values because otherwise the script has
37
// a tendency to just stop after some time.
38
//
39
ini_set ("memory_limit", "20M");
40
set_time_limit(3600);
41
42
$receiver = 0;
43
$receiver = post_int('receiver', true);
44
$subject = post_str('subject', true);
45
$body = post_str('body', true);
46
if ($body) {
47
    $body = stripslashes($body);
48
}
49
50
admin_page_head("Send mass email");
51
52
if ($receiver > 0) {
53
    db_init();
54
    switch ($receiver) {
55
    case 1:
56
        // all users
57
        $query = "select * from user where send_email > 0";
58
        break;
59
    case 2:
60
        // unsuccessful users
61
        $week_ago = time(0) - 7*86400;
0 ignored issues
show
The call to time() has too many arguments starting with 0. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

61
        $week_ago = /** @scrutinizer ignore-call */ time(0) - 7*86400;

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
62
        $query = "select user.id,user.name,user.email_addr from user left join result on user.id=result.userid where send_email>0 and total_credit=0 and user.create_time<$week_ago and isnull(result.id)";
63
        break;
64
    case 3:
65
        // successful users
66
        $query = "select * from user where send_email>0 and total_credit>0";
67
        break;
68
    case 4:
69
        // currently contributing users
70
        $query = "select distinct user.id,user.name,user.email_addr from user left join result on user.id=result.userid where send_email>0 and !isnull(result.id)";
71
        break;
72
    case 5:
73
        // lapsed users
74
        $query = "select user.id,user.name,user.email_addr from user left join result on user.id=result.userid where send_email>0 and total_credit>0 and isnull(result.id)";
75
        break;
76
    case 6:
77
        $userids = post_str('userids');
78
        $query = "select * from user where id in ($userids)";
79
        break;
80
    default:
0 ignored issues
show
DEFAULT keyword must be indented 4 spaces from SWITCH keyword
Loading history...
DEFAULT case must have a breaking statement
Loading history...
81
        // should never happen!
82
        exit_error("Got impossible value of receiver from selection!");
83
    }
84
    // FOR DEBUGGING
85
    //$query .= " LIMIT 10";
86
87
    $result = _mysql_query($query);
88
    while ($user = _mysql_fetch_object($result)) {
89
    	// TODO: might want to also replace TOTAL_CREDIT, RAC, and similar.
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
90
        $body_to_send = str_replace("USERNAME", $user->name, $body);
91
        $body_to_send .= "\n\nTo opt out of future emails from ".PROJECT.", please edit your project preferences at ".secure_url_base()."prefs.php?subset=project\n";
92
        $retval = send_email($user, $subject, $body_to_send);
93
        if ($retval) {
94
            // send_email returns TRUE on success
95
            echo "Sent email to $user->name [$user->id] at $user->email_addr <br>";
96
        } else {
97
            echo "<font color=RED>send_email() to $user->name [$user->id] at $user->email_addr failed with error $retval</font><br>";
98
        }
99
        // try to get output on the screen for feedback.  May not help...
100
        flush();
101
    }
102
    exit();
103
}
104
105
echo "<form method=\"post\" action=\"mass_email.php\">\n";
106
echo "<p>\n";
107
108
start_table();
109
echo "<tr><td align=right>Send email to: </td><td> ";
110
echo "
111
    <input type=radio name=receiver value='1' > All users
112
    <br><input type=radio name=receiver value='2' > Unsuccessful users: total_credit = 0, create time > 1 week ago, no jobs in DB
113
    <br><input type=radio name=receiver value='3' > Successful users: total_credit > 0
114
    <br><input type=radio name=receiver value='4' > Currently contributing users: total_credit > 0 and at least one job in DB
115
    <br><input type=radio name=receiver value='5' > Lapsed users: total_credit > 0 but no jobs in DB
116
    <br><input type=radio name=receiver value='6' checked> User IDs, comma-separated: <input name=userids>
117
    </td></tr>
118
    <tr>
119
      <td align=\"right\">Email subject</td>
120
      <td><input name=\"subject\" size=\"50\"></td>
121
      </tr>
122
    <tr>
123
      <td align=\"right\">Email body (USERNAME will be replaced)</td>
124
      <td><textarea name=\"body\" rows=25 cols=50 id=\"body\"></textarea></td>
125
    </tr>
126
        ";
127
row2("", "<input class=\"btn btn-default\" type=\"submit\" value=\"OK\">\n");
128
129
end_table();
130
echo "</form>\n";
131
?>
132