2 /* Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Arun Persaud <arun@nubati.net>
4 * This file is part of e-DoKo.
6 * e-DoKo 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, either version 3 of the License, or
9 * (at your option) any later version.
11 * e-DoKo 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. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with e-DoKo. If not, see <http://www.gnu.org/licenses/>.
21 error_reporting(E_ALL);
23 include_once("config.php"); /* needs to be first in list, since other includes use this */
24 include_once("./include/output.php"); /* html output only */
25 include_once("./include/db.php"); /* database only */
26 include_once("./include/functions.php"); /* the rest */
28 /* make sure that user has set all variables in config.php */
31 /* open the database */
35 /* only callable via cron or CLI */
36 if(isset($_SERVER['REMOTE_ADDR']))
39 /* get userid for users that have digest set != digest-off */
40 $users = DB_get_digest_users();
44 global $defaulttimezone;
45 foreach($users as $uid)
48 $zone = DB_get_user_timezone($uid);
49 date_default_timezone_set($zone);
50 $time = (int)(date("H"));
52 // load users preferences
53 $PREF = DB_get_PREF($uid);
55 // set users language preference
56 set_language($PREF['language']);
58 // calculate mod by digest-time
59 switch($PREF['digest'])
86 // make default time to send email 18:00
87 if( ( ($time-18) % $every) == 0 )
89 $email = DB_get_email('userid',$uid);
92 $messages = DB_get_digest_message_by_email($email);
94 // check messages for outdated ones and delete those
95 foreach ($messages as $key=>$mess)
97 if($mess[2] == 'your_turn' && $uid != DB_get_player_by_gameid($mess[3]) )
99 DB_digest_delete_message($mess[0]);
100 unset($messages[$key]);
105 if(sizeof($messages))
109 foreach($messages as $mess )
111 $text[$i] = $mess[1]."\n++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
115 $text = implode("\n",$text);
117 // add header, footer, sent out
118 $name = DB_get_name('userid',$uid);
119 $header = _("Hello")." $name\n\n"._("Here is a digest of the latest emails:")."\n\n";
121 $footer = "\n"._('Have a nice day')."\n".
122 " ".('your E-Doko digester')."\n\n".
124 _('You can change your mail delivery mode in the preference menu.')."\n".
125 _('web').': http://doko.nubati.net '.
126 _('help, bugs, etc.').": $WIKI";
128 $subject = "$EmailName Digest";
130 sendmail($email,$subject,$header.$text.$footer);
133 // delete all messages
134 foreach($messages as $mess )
135 DB_digest_delete_message($mess[0]);
137 } /* end foreach users */