PageRenderTime 40ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/boinc/boinc/html/ops/mass_email.php

http://decs.googlecode.com/
PHP | 112 lines | 80 code | 12 blank | 20 comment | 5 complexity | 8626b5bd549d4e8a4d924f1ac64af8d7 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, LGPL-2.0
  1. <?php
  2. // This is a script for sending mass email to project participants.
  3. // Test it first and use it with care, to avoid alienating your
  4. // project's volunteers.
  5. // Note also that the queries such as the one to find lapsed users
  6. // assume that the project keeps the results in the DB for some interval
  7. // such as a week, before purging them. So active users will always
  8. // have at least one result in the database.
  9. require_once("../inc/db.inc");
  10. require_once("../inc/util_ops.inc");
  11. require_once("../inc/email.inc");
  12. function exit_error($message) {
  13. echo "Error: $message <br>";
  14. exit();
  15. }
  16. // These are set to large values because otherwise the script has
  17. // a tendency to just stop after some time.
  18. //
  19. ini_set ("memory_limit", "20M");
  20. set_time_limit(3600);
  21. $receiver = 0;
  22. $receiver = post_int('receiver', true);
  23. $subject = post_str('subject', true);
  24. $body = post_str('body', true);
  25. $body = stripslashes($body);
  26. admin_page_head("Send mass email");
  27. if ($receiver > 0) {
  28. db_init();
  29. switch ($receiver) {
  30. case 1:
  31. // all users
  32. $query = "select * from user where send_email > 0";
  33. break;
  34. case 2:
  35. // unsuccessful users
  36. $week_ago = time(0) - 7*86400;
  37. $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)";
  38. break;
  39. case 3:
  40. // successful users
  41. $query = "select * from user where send_email>0 and total_credit>0";
  42. break;
  43. case 4:
  44. // currently contributing users
  45. $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)";
  46. break;
  47. case 5:
  48. // lapsed users
  49. $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)";
  50. break;
  51. default:
  52. // should never happen!
  53. exit_error("Got impossible value of receiver from selection!");
  54. }
  55. // FOR DEBUGGING
  56. $query .= " LIMIT 10";
  57. $result = mysql_query($query);
  58. while ($user = mysql_fetch_object($result)) {
  59. // TODO: might want to also replace TOTAL_CREDIT, RAC, and similar.
  60. $body_to_send = str_replace(USERNAME, $user->name, $body);
  61. $body_to_send .= "\n\nTo opt out of future emails from ".PROJECT.", please edit your project preferences at ".URL_BASE."prefs.php?subset=project\n";
  62. $retval = send_email($user, $subject, $body_to_send);
  63. if ($retval) {
  64. // send_email returns TRUE on success
  65. echo "Sent email to $user->name [$user->id] at $user->email_addr <br>";
  66. } else {
  67. echo "<font color=RED>send_email() to $user->name [$user->id] at $user->email_addr failed with error $retval</font><br>";
  68. }
  69. // try to get output on the screen for feedback. May not help...
  70. flush();
  71. }
  72. exit();
  73. }
  74. echo "<form method=\"post\" action=\"mass_email.php\">\n";
  75. echo "<p>\n";
  76. start_table();
  77. echo "<tr><td align=right>Send email to: </td><td> ";
  78. echo "
  79. <select name=\"receiver\">
  80. <option value='0' selected> PLEASE CHOOSE DESIRED SET OF USERS TO EMAIL
  81. <option value='1' > All users
  82. <option value='2' > Unsuccessful users: total_credit = 0, create time > 1 week ago, NO results in DB
  83. <option value='3' > Successful users: total_credit > 0
  84. <option value='4' > Currently contributing users: total_credit > 0 and at least one result in DB
  85. <option value='5' > Lapsed users: total_credit > 0 but NO results in DB
  86. </select>
  87. </td></tr>
  88. <tr>
  89. <td align=\"right\">Email subject</td>
  90. <td><input name=\"subject\" size=\"50\"></td>
  91. </tr>
  92. <tr>
  93. <td align=\"right\">Email body (USERNAME will be replaced)</td>
  94. <td><textarea name=\"body\" rows=25 cols=50 id=\"body\"></textarea></td>
  95. </tr>
  96. ";
  97. row2("", "<input type=\"submit\" value=\"OK\">\n");
  98. end_table();
  99. echo "</form>\n";
  100. ?>