(no commit message)
[mailer.git] / 0.2.1 / inc / mails / beg_mails.php
1 <?php\r
2 /************************************************************************\r
3  * MXChange v0.2.1                                    Start: 11/22/2005 *\r
4  * ===============                              Last change: 11/22/2005 *\r
5  *                                                                      *\r
6  * -------------------------------------------------------------------- *\r
7  * File              : beg_mails.php                                    *\r
8  * -------------------------------------------------------------------- *\r
9  * Short description : Sends out reminder mails                         *\r
10  * -------------------------------------------------------------------- *\r
11  * Kurzbeschreibung  : Versendet Erinnerungsmails                       *\r
12  * -------------------------------------------------------------------- *\r
13  *                                                                      *\r
14  * -------------------------------------------------------------------- *\r
15  * Copyright (c) 2003 - 2007 by Roland Haeder                           *\r
16  * For more information visit: http://www.mxchange.org                  *\r
17  *                                                                      *\r
18  * This program is free software; you can redistribute it and/or modify *\r
19  * it under the terms of the GNU General Public License as published by *\r
20  * the Free Software Foundation; either version 2 of the License, or    *\r
21  * (at your option) any later version.                                  *\r
22  *                                                                      *\r
23  * This program is distributed in the hope that it will be useful,      *\r
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *\r
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *\r
26  * GNU General Public License for more details.                         *\r
27  *                                                                      *\r
28  * You should have received a copy of the GNU General Public License    *\r
29  * along with this program; if not, write to the Free Software          *\r
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *\r
31  * MA  02110-1301  USA                                                  *\r
32  ************************************************************************/\r
33 \r
34 // Some security stuff...\r
35 if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))\r
36 {\r
37         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";\r
38         require($INC);\r
39 }\r
40  elseif ((!EXT_IS_ACTIVE("beg")) && (!IS_ADMIN()))\r
41 {\r
42         ADD_FATAL(EXTENSION_PROBLEM_EXT_INACTIVE, "beg");\r
43         return;\r
44 }\r
45 \r
46 // Do not execute when script is in CSS mode\r
47 if ($CSS == 1) return;\r
48 \r
49 // Create timemark from saved month\r
50 $mark = mktime(0, 0, 0, $CONFIG['beg_month'], date("d", time()), date("Y", time()));\r
51 $SQL = ""; $MODE = "";\r
52 \r
53 // Shall I sent activation or deactivation mail?\r
54 $SQL = "SELECT userid, email FROM "._MYSQL_PREFIX."_user_data WHERE (beg_ral_notify ";\r
55 switch ($CONFIG['beg_rallye'])\r
56 {\r
57 case "Y": // Begging rallye is activated\r
58         if ($CONFIG['beg_ral_en_notify'] == "Y")\r
59         {\r
60                 // Okay, let's check for member accounts\r
61                 $SQL .= "= 0 OR (beg_ral_notify > 0 AND beg_ral_en_notify < beg_ral_di_notify)";\r
62                 $MODE = "en";\r
63         }\r
64          else\r
65         {\r
66                 // Do not notify!\r
67                 $SQL = "";\r
68         }\r
69         break;\r
70 \r
71 case "N": // Begging rallye is deactivated\r
72         if ($CONFIG['beg_ral_di_notify'] == "Y")\r
73         {\r
74                 // Okay, let's check for member accounts\r
75                 $SQL .= " > 0 AND beg_ral_di_notify < beg_ral_en_notify";\r
76                 $MODE = "di";\r
77         }\r
78          else\r
79         {\r
80                 // Do not notify!\r
81                 $SQL = "";\r
82         }\r
83         break;\r
84 }\r
85 \r
86 if (!empty($SQL))\r
87 {\r
88         // The SQL command needs to be finisched here (only confirmed accounts!)\r
89         $SQL .= ") AND status='CONFIRMED' ORDER BY last_online ASC";\r
90 \r
91         // Prepare data for the template\r
92         define('__BEG_MIN_POINTS' , TRANSLATE_COMMA($CONFIG['beg_points']));\r
93         define('__BEG_MAX_POINTS' , TRANSLATE_COMMA($CONFIG['beg_points_max']));\r
94         define('__BEG_MAX_WINNERS', round($CONFIG['beg_ranks']));\r
95         if ($CONFIG['beg_ip_timeout'] == 0)\r
96         {\r
97                 // No IP locking setuped!\r
98                 define('__BEG_IP_LOCKER', BEG_NO_LIMITATION);\r
99         }\r
100          else\r
101         {\r
102                 // Create timemark\r
103                 define('__BEG_IP_LOCKER', CREATE_FANCY_TIME($CONFIG['beg_ip_timeout']));\r
104         }\r
105 \r
106         // Check for accounts to be notified\r
107         $result_main = SQL_QUERY($SQL, __FILE__, __LINE__);\r
108         if (SQL_NUMROWS($result_main) > 0)\r
109         {\r
110                 // Normal notification mails or bonus mails?\r
111                 $MAIL_MODE = (($CONFIG['beg_notify_bonus'] > 0) && ($MODE == "en") && (EXT_IS_ACTIVE("bonus")));\r
112 \r
113                 // Generate subject line\r
114                 $eval = "\$SUBJECT = BEG_RALLYE_".strtoupper($MODE)."_NOTIFY;";\r
115                 eval($eval);\r
116 \r
117                 // Load message body for bonus mails\r
118                 $MSG = LOAD_EMAIL_TEMPLATE("beg_en_notify_body", "", "{PER}uid{PER}");\r
119                 $RECEIVER = ""; $UIDs = array();\r
120 \r
121                 // Okay lets notify all users!\r
122                 while(list($uid, $email) = SQL_FETCHROW($result_main))\r
123                 {\r
124                         // Update account\r
125                         $result_update = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data\r
126 SET beg_ral_notify='%s', beg_ral_%s_notify='%s' WHERE userid=%d LIMIT 1",\r
127  array(time(), $MODE, time(), $uid), __FILE__, __LINE__);\r
128 \r
129                         // Load email template and send it to the user!\r
130                         if ($MAIL_MODE)\r
131                         {\r
132                                 // Add userid to queue\r
133                                 $UIDs[] = $uid;\r
134                         }\r
135                          else\r
136                         {\r
137                                 // Send normal notification mail to the members\r
138                                 $MSG = LOAD_EMAIL_TEMPLATE("beg_".$MODE."_notify", "", $uid);\r
139                                 SEND_EMAIL($email, $SUBJECT, $MSG);\r
140                         }\r
141                 }\r
142 \r
143                 // Shall I send out bonus mails?\r
144                 if ($MAIL_MODE)\r
145                 {\r
146                         // Okay, make array to string\r
147                         $RECEIVER = implode(";", $UIDs);\r
148                         $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_bonus\r
149 (subject, text, receivers, points, time, data_type, timestamp, url, cat_id, target_send, mails_sent, is_notify)\r
150 VALUES ('%s', '%s', '%s', '%s', '%s', 'NEW', UNIX_TIMESTAMP(), '%s', '%s', '%s', '%s', 'Y')",\r
151  array(\r
152         $SUBJECT,\r
153         $MSG,\r
154         $RECEIVER,\r
155         $CONFIG['beg_notify_bonus'],\r
156         $CONFIG['beg_notify_wait'],\r
157         URL."/modules.php?module=index&what=login",\r
158         0,\r
159         SELECTION_COUNT(explode(";", $RECEIVER)),\r
160         SQL_NUMROWS($result_main),\r
161 ), __FILE__, __LINE__);\r
162                 }\r
163         }\r
164 \r
165         // Free memory\r
166         SQL_FREERESULT($result_main);\r
167 }\r
168 \r
169 //\r
170 ?>\r