1 |
14353
|
antonis.le
|
<?php
|
2 |
15087
|
antonis.le
|
require_once "Mail.php";
|
3 |
14353
|
antonis.le
|
|
4 |
|
|
if (!class_exists('TBase')) {
|
5 |
|
|
$DS = '/';
|
6 |
|
|
|
7 |
|
|
$GLOBALS['THRIFT_ROOT'] = dirname(__FILE__) . $DS . 'models' . $DS . 'thrift';
|
8 |
|
|
|
9 |
|
|
require_once($GLOBALS['THRIFT_ROOT'] . $DS . 'Thrift.php');
|
10 |
|
|
require_once($GLOBALS['THRIFT_ROOT'] . $DS . 'protocol' . $DS . 'TBinaryProtocol.php');
|
11 |
|
|
require_once($GLOBALS['THRIFT_ROOT'] . $DS . 'transport' . $DS . 'TSocket.php');
|
12 |
|
|
require_once($GLOBALS['THRIFT_ROOT'] . $DS . 'transport' . $DS . 'TBufferedTransport.php');
|
13 |
|
|
require_once($GLOBALS['THRIFT_ROOT'] . $DS . 'packages' . $DS . 'openaire' . $DS . 'OpenAireConnector.php');
|
14 |
|
|
|
15 |
|
|
|
16 |
|
|
function init() {
|
17 |
|
|
$host = 'localhost';
|
18 |
|
|
$port = '7911';
|
19 |
|
|
|
20 |
|
|
$socket = new TSocket($host, $port);
|
21 |
|
|
|
22 |
|
|
$socket->setRecvTimeout(10000);
|
23 |
|
|
|
24 |
|
|
$_transport = new TBufferedTransport($socket);
|
25 |
|
|
$protocol = new TBinaryProtocol($_transport);
|
26 |
|
|
|
27 |
|
|
$_client = new OpenAireConnectorClient($protocol);
|
28 |
|
|
|
29 |
|
|
return array("client" => $_client, "transport" => $_transport);
|
30 |
|
|
}
|
31 |
|
|
|
32 |
|
|
function callThrift(&$thriftHandle, $methodName, $params) {
|
33 |
|
|
$thriftHandle["transport"]->open();
|
34 |
|
|
|
35 |
|
|
$result = call_user_func_array(array($thriftHandle['client'], $methodName), $params);
|
36 |
|
|
|
37 |
|
|
$thriftHandle["transport"]->close();
|
38 |
|
|
|
39 |
|
|
return $result;
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
function getMessage($sc39) {
|
43 |
14469
|
antonis.le
|
$file = 'message-'.($sc39?'sc39':'nonsc39').'.txt';
|
44 |
14353
|
antonis.le
|
$fp = fopen($file, 'r');
|
45 |
|
|
$text = fread($fp, filesize($file));
|
46 |
|
|
fclose($fp);
|
47 |
|
|
|
48 |
|
|
return $text;
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
function getSubject($sc39) {
|
52 |
14469
|
antonis.le
|
$file = 'subject-'.($sc39?'sc39':'nonsc39').'.txt';
|
53 |
14353
|
antonis.le
|
$fp = fopen($file, 'r');
|
54 |
|
|
$text = fread($fp, filesize($file));
|
55 |
|
|
fclose($fp);
|
56 |
|
|
|
57 |
|
|
return $text;
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
function getUrl($projectId) {
|
61 |
|
|
$url = 'http://www.openaire.eu/en/component/openaire/project_info/default/625?id='.$projectId;
|
62 |
|
|
$url .= '&confirm='.getHash($projectId);
|
63 |
|
|
|
64 |
|
|
return $url;
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
function getHash($projectId) {
|
68 |
|
|
return hash_hmac('sha1', $projectId, 'asupercoolsecret');
|
69 |
|
|
}
|
70 |
|
|
|
71 |
|
|
function replaceVars($message, $project) {
|
72 |
14469
|
antonis.le
|
$message = str_replace('$projectName', $project->acronym, $message);
|
73 |
|
|
$message = str_replace('$grantAgreementNumber', $project->grandAgreement, $message);
|
74 |
|
|
$message = str_replace('$projectInfoURL', getUrl($project->projectId), $message);
|
75 |
15087
|
antonis.le
|
$message = str_replace('$coordinatorName', $project->coordinator->name.' '.$project->coordinator->surname, $message);
|
76 |
14469
|
antonis.le
|
|
77 |
|
|
return $message;
|
78 |
14353
|
antonis.le
|
}
|
79 |
|
|
|
80 |
|
|
$thrift = init();
|
81 |
|
|
$projects = callThrift($thrift, 'getProjectsWithNonHarverstedDocuments', array(true, true));
|
82 |
14469
|
antonis.le
|
|
83 |
14353
|
antonis.le
|
|
84 |
15087
|
antonis.le
|
foreach (array_slice($projects, 0, 1) as $project) {
|
85 |
|
|
$to = $project->coordinator->email;
|
86 |
14353
|
antonis.le
|
$message = getMessage($project->sc39);
|
87 |
|
|
$subject = getSubject($project->sc39);
|
88 |
|
|
|
89 |
15087
|
antonis.le
|
$headers = array('From' => 'test.openaire@gmail.com', 'To' => $to, 'Subject' => $subject);
|
90 |
|
|
|
91 |
|
|
$subject = replaceVars($subject, $project);
|
92 |
14353
|
antonis.le
|
$message = replaceVars($message, $project);
|
93 |
|
|
|
94 |
15087
|
antonis.le
|
$host = "smtp.gmail.com";
|
95 |
|
|
$port = "587";
|
96 |
|
|
$username = "test.openaire@gmail.com";
|
97 |
|
|
$password = "^($*@$)*!$";
|
98 |
|
|
|
99 |
|
|
$smtp = Mail::factory('smtp', array ('host' => $host, 'port' => $port, 'auth' => true, 'debug'=>true, 'username' => $username, 'password' => $password));
|
100 |
|
|
|
101 |
|
|
//$to = "antleb@di.uoa.gr";
|
102 |
14469
|
antonis.le
|
echo 'to: '.$to;
|
103 |
15087
|
antonis.le
|
echo $subject;
|
104 |
14469
|
antonis.le
|
echo 'message: '.$message;
|
105 |
|
|
|
106 |
15087
|
antonis.le
|
|
107 |
|
|
$mail = $smtp->send($to, $headers, $message);
|
108 |
|
|
|
109 |
|
|
if (PEAR::isError($mail)) {
|
110 |
|
|
echo("<p>" . $mail->getMessage() . "</p>");
|
111 |
|
|
} else {
|
112 |
|
|
echo("<p>Message successfully sent!</p>");
|
113 |
|
|
}
|
114 |
14353
|
antonis.le
|
}
|
115 |
|
|
}
|
116 |
|
|
|
117 |
|
|
?>
|