diff options
author | Camil Staps | 2020-02-03 09:47:21 +0100 |
---|---|---|
committer | Camil Staps | 2020-02-03 09:47:21 +0100 |
commit | 2af4ffce19df7cdb34d4b509a66bc916ffcb88d1 (patch) | |
tree | 481bc542d1298e1bcb3e39c107a22b39f13f0395 /add.php |
Initial commit
Diffstat (limited to 'add.php')
-rw-r--r-- | add.php | 49 |
1 files changed, 49 insertions, 0 deletions
@@ -0,0 +1,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> |