1<?php
2
3$id = sprintf('%d', $_GET['id']);
4if (!$id) {
5    return '';
6}
7$message = Sql_Fetch_Assoc_Query(sprintf('select *,unix_timestamp(embargo) - unix_timestamp(now()) as secstowait from %s where id = %d',
8    $GLOBALS['tables']['message'], $id));
9$messagedata = loadMessageData($id);
10$pqchoice = getConfig('pqchoice');
11
12$totalsent = $messagedata['astext'] +
13    $messagedata['ashtml'] +
14    $messagedata['astextandhtml'] +
15    $messagedata['aspdf'] +
16    $messagedata['astextandpdf'] +
17    $messagedata['sentastest'];
18
19$num_users = 0;
20if (isset($messagedata['to process'])) {
21    $num_users = $messagedata['to process'];
22}
23
24$sent = $totaltime = $sampletime = $samplesent = 0;
25if (!isset($messagedata['sampletime'])) { //# take a "sample" of the send speed, to calculate msg/hr
26    $sampletime = time();
27    $samplesent = $totalsent;
28    setMessageData($id, 'sampletime', $sampletime);
29    setMessageData($id, 'samplesent', $samplesent);
30} else {
31    $totaltime = time() - $messagedata['sampletime'];
32    $sent = $totalsent - $messagedata['samplesent'];
33    if ($totaltime > MESSAGE_SENDSTATUS_SAMPLETIME) { //# refresh speed sampling
34        setMessageData($id, 'sampletime', time());
35        setMessageData($id, 'samplesent', $totalsent);
36    }
37}
38
39if ($sent > 0 && $totaltime > 0) {
40    $msgperhour = (int) (3600 / $totaltime) * $sent;
41    $secpermsg = $totaltime / $sent;
42    $timeleft = ($num_users - $sent) * $secpermsg;
43    $eta = date('D j M H:i', time() + $timeleft);
44} else {
45    $msgperhour = 0;
46    $secpermsg = 0;
47    $timeleft = 0;
48    $eta = $GLOBALS['I18N']->get('unknown');
49}
50
51//# 16850 - convert to string, to avoid an SQL error
52$msgperhour = "$msgperhour ";
53
54setMessageData($id, 'ETA', $eta);
55setMessageData($id, 'msg/hr', $msgperhour);
56
57if ($message['status'] != 'inprocess') {
58    $html = $GLOBALS['I18N']->get($message['status']);
59
60    if ($message['secstowait'] > 0) {
61        $secstowait = secs2time($message['secstowait']);
62        $html .= '<br/>'.sprintf($GLOBALS['I18N']->get('%s left until embargo'), $secstowait);
63    }
64    foreach ($GLOBALS['plugins'] as $plname => $plugin) {
65        $html .= $plugin->messageStatus($id, $message['status']);
66    }
67
68    if ($message['status'] != 'submitted' && $message['status'] != 'draft') {
69        $html .= '<br/>'.PageLinkButton('messages', $GLOBALS['I18N']->get('requeue'), 'resend='.$message['id'], '',
70                s('Requeue'));
71    }
72    if (!empty($messagedata['to process'])) {
73        $html .= '<br/>'.$messagedata['to process'].' '.$GLOBALS['I18N']->get('still to process').'<br/>'.
74            $GLOBALS['I18N']->get('sent').': '.$totalsent;
75    }
76} else {
77    if (empty($messagedata['last msg sent'])) {
78        $messagedata['last msg sent'] = 0;
79    }
80    if (empty($messagedata['to process'])) {
81        $messagedata['to process'] = $GLOBALS['I18N']->get('Unknown');
82    }
83
84    $active = time() - $messagedata['last msg sent'];
85    $html = $GLOBALS['I18N']->get($message['status']).'<br/>';
86    if ($messagedata['to process'] > 0) {
87        $html .= $messagedata['to process'].' '.$GLOBALS['I18N']->get('still to process').'<br/>';
88    }
89    $pluginhtml = '';
90    foreach ($GLOBALS['plugins'] as $plname => $plugin) {
91        $pluginhtml .= $plugin->messageStatus($id, $message['status']);
92    }
93
94    //# if the plugins don't return anything do the speed calculation
95    //# otherwise just what the plugins retunr
96    if (empty($pluginhtml)) {
97        //# not sure this calculation is accurate
98        //  $html .= $GLOBALS['I18N']->get('sent').': '.$totalsent.'<br/>';
99        $recently_sent = Sql_Fetch_Row_Query(sprintf('select count(*) from %s where entered > date_sub(now(),interval %d second) and status = "sent"',
100            $tables['usermessage'], MAILQUEUE_BATCH_PERIOD));
101        if (MAILQUEUE_BATCH_PERIOD && MAILQUEUE_BATCH_SIZE && $recently_sent[0] >= MAILQUEUE_BATCH_SIZE) {
102            $html .= '<h4>'.$GLOBALS['I18N']->get('limit reached').'</h4>';
103            foreach ($GLOBALS['plugins'] as $plname => $plugin) {
104                $html .= $plugin->messageStatusLimitReached($recently_sent[0]);
105            }
106            $nextbatch = Sql_Fetch_Row_Query(sprintf('select now(),date_add(entered,interval %d second) from %s where entered > date_sub(now(),interval %d second) and status = "sent" order by entered desc limit 1',
107                MAILQUEUE_BATCH_PERIOD + 60, $tables['usermessage'], MAILQUEUE_BATCH_PERIOD));
108            $html .= '<p>'.sprintf($GLOBALS['I18N']->get('next batch of %s in %s'), MAILQUEUE_BATCH_SIZE,
109                    timeDiff($nextbatch[0], $nextbatch[1])).'</p>';
110        } elseif ($msgperhour <= 0 || $active > MESSAGE_SENDSTATUS_INACTIVETHRESHOLD) {
111            if (MANUALLY_PROCESS_QUEUE) {
112                $html .= $GLOBALS['I18N']->get('Waiting');
113                if ($pqchoice == 'local') {
114                    $html .= PageLinkButton('processqueue', s('Send the queue'));
115                } elseif ($pqchoice == 'phplistdotcom') {
116                    $html .= '<a href="https://www.phplist.com/myaccount" target="_blank" class="button">'.s('Check status').'</a>';
117                }
118            } else {
119                $html .= $GLOBALS['I18N']->get('Processing');
120            }
121        } else {
122            $html .=
123                $GLOBALS['I18N']->get('ETA').': '.$eta.'<br/>'.
124                $GLOBALS['I18N']->get('Processing').' '.sprintf('%d',
125                    $msgperhour).' '.$GLOBALS['I18N']->get('msgs/hr');
126        }
127    } else {
128        $html .= $pluginhtml;
129    }
130}
131
132if (!empty($GLOBALS['developer_email1'])) {
133    if (isset($messagedata['sampletime'])) {
134        $html .= '<br/>ST: '.$messagedata['sampletime'];
135    }
136    if (isset($messagedata['samplesent'])) {
137        $html .= '<br/>SS: '.$messagedata['samplesent'];
138    }
139    if (isset($totaltime)) {
140        $html .= '<br/>TT: '.$totaltime;
141    }
142    if (isset($sent)) {
143        $html .= '<br/>TS: '.$sent;
144    }
145}
146
147$status = $html;
148#exit;
149