marked some more messages for translation
[e-DoKo.git] / digest.php
1 <?php
2 /* Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 Arun Persaud <arun@nubati.net>
3  *
4  *   This file is part of e-DoKo.
5  *
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.
10  *
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.
15  *
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/>.
18  *
19  */
20
21 error_reporting(E_ALL);
22
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 */
27
28 /* make sure that user has set all variables in config.php */
29 config_check();
30
31 /* open the database */
32 if(DB_open()<0)
33   exit();
34
35 /* only callable via cron or CLI */
36 if(isset($_SERVER['REMOTE_ADDR']))
37   exit();
38
39 /* get userid for users that have digest set != digest-off */
40 $users = DB_get_digest_users();
41
42 global $WIKI;
43
44 global $defaulttimezone;
45 foreach($users as $uid)
46   {
47     // get local time
48     $zone  = DB_get_user_timezone($uid);
49     date_default_timezone_set($zone);
50     $time = (int)(date("H"));
51
52     // load users preferences
53     $PREF = DB_get_PREF($uid);
54
55     // set users language preference
56     $language = $PREF['language'];
57
58     switch($language)
59       {
60       case 'de':
61         putenv("LC_ALL=de_DE");
62         setlocale(LC_ALL, "de_DE");
63         // Specify location of translation tables
64         bindtextdomain("edoko", "./locale");
65         // Choose domain
66         textdomain("edoko");
67         break;
68       default:
69         /* do nothing */
70       }
71
72     // calculate mod by digest-time
73     switch($PREF['digest'])
74       {
75       case 'digest-off':
76         break;
77       case 'digest-1h':
78         $every = 1;
79         break;
80       case 'digest-2h':
81         $every = 2;
82         break;
83       case 'digest-3h':
84         $every = 3;
85         break;
86       case 'digest-4h':
87         $every = 4;
88         break;
89       case 'digest-6h':
90         $every = 6;
91         break;
92       case 'digest-12h':
93         $every = 12;
94         break;
95       case 'digest-24h':
96         $every = 24;
97         break;
98       }
99
100     // make default time to send email 18:00
101     if( ( ($time-18) % $every) == 0 )
102       {
103         $email = DB_get_email('userid',$uid);
104
105         // get messages
106         $messages = DB_get_digest_message_by_email($email);
107
108         // add them together
109         if(sizeof($messages))
110           {
111             $text = array();
112             $i=0;
113             foreach($messages as $mess )
114               {
115                 $text[$i] = $mess[1]."\n++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
116                 $i++;
117               }
118
119             $text = implode("\n",$text);
120
121             // add header, footer, sent out
122             $name    = DB_get_name('userid',$uid);
123             $header  = "Hello $name\n\nHere is a digest of the latest emails:\n\n";
124
125             $footer  = "\nHave a nice day\n".
126               "   your E-Doko digester\n\n".
127               "-- \n".
128               "You can change your mail delivery mode in the preference menu.\n".
129               'web: http://doko.nubati.net   '.
130               "help, bugs, etc.: $WIKI";
131
132             $subject = "$EmailName Digest";
133
134             sendmail($email,$subject,$header.$text.$footer);
135           }
136
137         // delete all messages
138         foreach($messages as $mess )
139           DB_digest_delete_message($mess[0]);
140       }
141   } /* end foreach users */
142 ?>