Merge branch 'release' into bug-440
[cacert-devel.git] / scripts / send_thawte.php.txt
1 #!/usr/bin/php -q
2 <? /*
3 LibreSSL - CAcert web application
4 Copyright (C) 2004-2009 CAcert Inc.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; version 2 of the License.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 include_once("../includes/mysql.php");
20
21 // english (use the same for foreign language, too)
22
23 $lines_EN = "";
24 if (file_exists("thawte_EN.txt"))
25 {
26 $fp = fopen("thawte_EN.txt", "r");
27 while(!feof($fp))
28 {
29 $line = trim(fgets($fp, 4096));
30 $line = wordwrap($line, 75, "\n")."\n";
31 $line = mb_convert_encoding($line, "HTML-ENTITIES", "UTF-8");
32 $lines_EN .= $line;
33 }
34 fclose($fp);
35 }
36
37 $lines_DE = "";
38 if (file_exists("thawte_DE.txt"))
39 {
40 $fp = fopen("thawte_DE.txt", "r");
41 while(!feof($fp))
42 {
43 $line = trim(fgets($fp, 4096));
44 $line = wordwrap($line, 75, "\n")."\n";
45 $line = mb_convert_encoding($line, "HTML-ENTITIES", "UTF-8");
46 $lines_DE .= $line;
47 }
48 fclose($fp);
49 }
50
51 $lines_NL = "";
52 if (file_exists("thawte_NL.txt"))
53 {
54 $fp = fopen("thawte_NL.txt", "r");
55 while(!feof($fp))
56 {
57 $line = trim(fgets($fp, 4096));
58 $line = wordwrap($line, 75, "\n")."\n";
59 $line = mb_convert_encoding($line, "HTML-ENTITIES", "UTF-8");
60 $lines_NL .= $line;
61 }
62 fclose($fp);
63 }
64
65 $lines_FR = "";
66 if (file_exists("thawte_FR.txt"))
67 {
68 $fp = fopen("thawte_FR.txt", "r");
69 while(!feof($fp))
70 {
71 $line = trim(fgets($fp, 4096));
72 $line = wordwrap($line, 75, "\n")."\n";
73 $line = mb_convert_encoding($line, "HTML-ENTITIES", "UTF-8");
74 $lines_FR .= $line;
75 }
76 fclose($fp);
77 }
78
79 $lines_ES = "";
80 if (file_exists("thawte_ES.txt"))
81 {
82 $fp = fopen("thawte_ES.txt", "r");
83 while(!feof($fp))
84 {
85 $line = trim(fgets($fp, 4096));
86 $line = wordwrap($line, 75, "\n")."\n";
87 $line = mb_convert_encoding($line, "HTML-ENTITIES", "UTF-8");
88 $lines_ES .= $line;
89 }
90 fclose($fp);
91 }
92
93 $lines_RU = "";
94 if (file_exists("thawte_RU.txt"))
95 {
96 $fp = fopen("thawte_RU.txt", "r");
97 while(!feof($fp))
98 {
99 $line = trim(fgets($fp, 4096));
100 $line = wordwrap($line, 75, "\n")."\n";
101 $line = mb_convert_encoding($line, "HTML-ENTITIES", "UTF-8");
102 $lines_RU .= $line;
103 }
104 fclose($fp);
105 }
106
107 // read last used id
108 $lastid = 0;
109 if (file_exists("send_thawte_lastid.txt"))
110 {
111 $fp = fopen("send_thawte_lastid.txt", "r");
112 $lastid = trim(fgets($fp, 4096));
113 fclose($fp);
114 }
115
116 echo "ID now: $lastid\n";
117
118
119 $count = 0;
120
121 $query = "select `id`,`fname`,`lname`,`email`,`language` from `users` where `deleted` = 0 and `id` > '$lastid' order by `id`";
122
123 $res = mysql_query($query);
124
125 while($row = mysql_fetch_assoc($res))
126 {
127 $mailtxt = "Hello ${row["fname"]} ${row["lname"]},\n".$lines_EN."\n\n";
128 switch ($row["language"])
129 {
130 case "de_DE":
131 case "de":
132 $mailtxt .= $lines_DE;
133 break;
134
135 case "nl_NL":
136 case "nl":
137 $mailtxt .= $lines_NL;
138 break;
139
140 case "fr_FR":
141 case "fr":
142 $mailtxt .= $lines_FR;
143 break;
144
145 case "es_ES":
146 case "es":
147 $mailtxt .= $lines_ES;
148 break;
149
150 case "ru_RU":
151 case "ru":
152 $mailtxt .= $lines_RU;
153 break;
154 }
155
156 sendmail($row['email'], "[CAcert.org] Changes at CAcert", $mailtxt, "mailing@cacert.org", "", "", "CAcert", "returns@cacert.org", "");
157
158 $fp = fopen("send_thawte_lastid.txt", "w");
159 fputs($fp, $row["id"]."\n");
160 fclose($fp);
161
162 $count++;
163 echo "Sent ${count}th mail. User ID: ${row["id"]}\n";
164
165 sleep (1);
166 }
167 ?>