-
Notifications
You must be signed in to change notification settings - Fork 0
/
Controller.php
49 lines (38 loc) · 995 Bytes
/
Controller.php
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
<?php
require_once("Messages.php");
$messages = new Messages();
//header('Access-Control-Allow-Origin: *');
//header("Access-Control-Allow-Headers: Content-Type")
$view = "";
if ( isset ( $_GET["view"] ) )
$view = $_GET["view"];
$body = file_get_contents('php://input');
switch ( $view ){
case "sendcall":
global $messages;
$dao->deleteOldMessages();
$messages->addToList($_GET["sender"], $_GET["receiver"], $_GET["message"], null);
break;
case "sendmessage":
global $messages;
$messages->deleteOldMessages();
$messages->addToList($_GET["sender"], $_GET["receiver"], $_GET["message"], $body);
break;
case "receive":
global $messages;
$messages->deleteOldMessages();
$returnData = $messages->searchForReceiver($_GET["sender"]);
if ( $returnData != null )
{
$messages->deleteFromList($returnData["id"]);
echo json_encode($returnData);
}
else{
echo json_encode('');
}
break;
case "":
//404 - not found;
break;
}
?>