aboutsummaryrefslogtreecommitdiff
path: root/add.php
blob: e538d2ed34926a8971a4fe535fb913a1fe139ee6 (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
<!DOCTYPE html>
<html>
<head>
	<title>Adding new events</title>
	<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<?php
require_once ('mail.php');
require_once ('db.php');

$selected_messages=$_POST['messages'];
if (count ($selected_messages)<1)
	die ('No events selected.');

$exceptions=[];

$messages=mail_get_unseen_messages();
foreach ($messages as $msg_id){
	if (!in_array ($msg_id,$selected_messages))
		continue;

	try {
		$msg=mail_fetch_message ($msg_id);
		$parsed=mail_parse_message ($msg['body'],['source' => $msg['guessed_source']]);
		$info=$parsed['info'];

		$info['added_by']=$msg['user']['id'];
		$info['keywords']=array_map ('get_or_add_keyword',$info['keywords']);
		$info['source']=get_or_add_source ($info['source']);

		$id=add_event ($info);
		echo 'Added #'.$id.': '.$info['title'].'<br/>';

		mail_mark_seen ($msg_id);
	} catch (Exception $e){
		$exceptions[]=$e->getMessage();
	}
}

if (count ($exceptions)>0){
	echo 'Exceptions:<br/>';
	foreach ($exceptions as $e)
		echo $e.'<br/>';
}
?>
<p>Back to the <a href="fetch.php">list of new events</a>?</p>
</body>
</html>