forked from philippK-de/Collabtive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.php
114 lines (100 loc) · 3.86 KB
/
api.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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/*
This is the BETA version of the Collabtive Web API.
It allows you to export data from Collabtive for use in Web applications.
By default the data is sent in XML format. To switch the output to JSON, you have to append mode=json to your queries.
**************
Authorization
**************
In order to prevent data from being served to unauthorized users, the Collabtive web api implements the same logins as Collabtive itself.
You have to append the parameters "username" and "pass" to every query you issue to the API.
These parameters need to contain username and Password of a valid Collabtive user.
Example:http://www.example.com/api.php?username=your_user&pass=your_pass
This authorizes you against the API, but performs no API action.
More on using the API below.
******
Usage
******
The Collabtive API can be used by issuing a GET request with several parameters.
An example: http://www.example.com/api.php?action=user.list.get&username=your_user&pass=your_pass
Calling this URL gets you a list of all users registered in the system in XML format.
*****************************
The parameters available are:
*****************************
action = specifies the API action you want to call
id = specifies the ID of the object to be fetched (optional)
user = specifies the ID of the user to be fetched (optional)
mode = specifies if the output is rendered in XML or JSON (XML is the default)
Another example:
http://www.example.com/api.php?action=user.tasks.get&user=1&username=your_user&pass=your_pass&mode=json
This gives you all tasks of the user with ID1 in JSON format.
*/
require("./init.php");
die("<span style = \"color:red;\">The API is deactivated. The API does not properly enforce permissions yet. For example every user can request every project / task etc. <br />To activate the API remove the die() statement in api.php line 38.<br /><strong>DO NOT USE THE API ON PRODUCTION SERVERS !</strong></span>");
$userobj = new user();
$usr = $_GET["username"];
$pass = $_GET["pass"];
$pass = urldecode($pass);
$usr = urldecode($usr);
if (!$userobj->login($usr, $pass)) {
die("not authorized");
}
// variables
$action = getArrayVal($_GET, "action");
$id = getArrayVal($_GET, "id");
$user = getArrayVal($_GET, "user");
// output in xml or json
$mode = getArrayVal($_GET, "mode");
// create new array to xml converter
$xml = new toXml();
// Projects
if ($action == "project.get") {
$obj = (object) new project();
$theData = $obj->getProject($id);
$theRootNode = "project";
} elseif ($action == "myprojects.get") {
$obj = (object) new project();
$theData = $obj->getMyProjects($id);
$theRootNode = "myprojects";
} elseif ($action == "project.members.get") {
$obj = (object) new project();
$theData = $obj->getProjectMembers($id);
$theRootNode = "members";
}
// Users
elseif ($action == "user.profile.get") {
$obj = (object) new user();
$theData = $obj->getProfile($id);
$theRootNode = "user";
} elseif ($action == "user.id.get") {
$obj = (object) new user();
$theData = $obj->getId($id);
$theRootNode = "user";
} elseif ($action == "user.list.get") {
$obj = (object) new user();
$theData = $obj->getAllUsers(100000);
$theRootNode = "userlist";
} elseif ($action == "user.tasks.get") {
$obj = (object) new task();
$project = new project();
$myprojects = $project->getMyProjects($user);
$theData = array();
foreach($myprojects as $proj) {
$theArr = $obj->getAllMyProjectTasks($proj["ID"], 10000, $user);
if (!empty($theArr)) {
foreach($theArr as $task) {
array_push($theData, array("ID" => $task["ID"], "name" => $task["title"]));
}
}
}
$theRootNode = "tasks";
}
// convert to XML or JSON
if ($mode == "json") {
$theXml = $xml->arrToJSON($theData);
} else {
$theXml = $xml->arrToXml($theData, $theRootNode);
}
// output to the user
echo $theXml;
?>