aboutsummaryrefslogtreecommitdiffstats
path: root/mod/dreport.php
blob: 31a6274c85551828866258f16878e206d701f75f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php

function dreport_content(&$a) {

	if(! local_channel()) {
		notice( t('Permission denied') . EOL);
		return;
	}

	$channel = $a->get_channel();
	
	$mid = ((argc() > 1) ? argv(1) : '');

	if(! $mid) {
		notice( t('Invalid message') . EOL);
		return;
	}
	
	$r = q("select * from dreport where dreport_xchan = '%s' and dreport_mid = '%s'",
		dbesc($channel['channel_hash']),
		dbesc($mid)
	);

	if(! $r) {
		notice( t('no results') . EOL);
		return;
	}


	$o .= '<h2>' . sprintf( t('Delivery report for %1$s'),substr($mid,0,32)) . '...' . '</h2>';
	$o .= '<table>';

	for($x = 0; $x < count($r); $x++ ) {
		$r[$x]['name'] = escape_tags(substr($r[$x]['dreport_recip'],strpos($r[$x]['dreport_recip'],' ')));

		switch($r[$x]['dreport_result']) {
			case 'channel sync processed':
				$r[$x]['gravity'] = 0;
				$r[$x]['dreport_result'] = t('channel sync processed');
				break;
			case 'queued':
				$r[$x]['gravity'] = 2;
				$r[$x]['dreport_result'] = t('queued');
				break;
			case 'posted':
				$r[$x]['gravity'] = 3;
				$r[$x]['dreport_result'] = t('posted');
				break;
			case 'accepted for delivery':
				$r[$x]['gravity'] = 4;
				$r[$x]['dreport_result'] = t('accepted for delivery');
				break;
			case 'updated':
				$r[$x]['gravity'] = 5;
				$r[$x]['dreport_result'] = t('updated');
			case 'update ignored':
				$r[$x]['gravity'] = 6;
				$r[$x]['dreport_result'] = t('update ignored');
				break;
			case 'permission denied':
				$r[$x]['dreport_result'] = t('permission denied');
				$r[$x]['gravity'] = 6;
				break;
			default:
				$r[$x]['gravity'] = 1;
				break;
		}
	}

	usort($r,'dreport_gravity_sort');
		

	foreach($r as $rr) {
		$o .= '<tr><td width="40%">' . $rr['name'] . '</td><td width="20%">' . escape_tags($rr['dreport_result']) . '</td><td width="20%">' . escape_tags($rr['dreport_time']) . '</td></tr>';
	}
	$o .= '</table>';

	return $o;



}

function dreport_gravity_sort($a,$b) {
	if($a['gravity'] == $b['gravity']) {
		if($a['name'] === $b['name'])
			return strcmp($a['dreport_time'],$b['dreport_time']);
		return strcmp($a['name'],$b['name']);
	}
	return (($a['gravity'] > $b['gravity']) ? 1 : (-1));
}