-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathajax.php
More file actions
115 lines (92 loc) · 3.92 KB
/
ajax.php
File metadata and controls
115 lines (92 loc) · 3.92 KB
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
115
<?php
require 'includes/init.inc.php';
require 'includes/template.inc.php';
require 'includes/resourcemanager.inc.php';
switch ($_GET['action']) {
/**
* Add one or more resources to a deliverable
* Params:
* deliverable_id - id of the deliverable
* resourcetype - id of the resourcetype
* (other) - depending on resourcetype
*/
case 'add-resource':
$resource_manager = new ResourceManager(array($_GET['resourcetype']));
$resourcetype =& $resource_manager->resourcetypes[$_GET['resourcetype']];
$fields = $resourcetype->getFieldsToSave($_GET);
$data = array(
'deliverable_id' => $_GET['deliverable_id'],
'resourcetype' => $_GET['resourcetype'],
'data' => serialize($fields)
);
// Insert into db
list($Resource) = load_models('Resource');
$Resource->insert($data);
// Add to JSON output
$json = array(
'resource_id' => $Resource->db->getLastID(),
'deliverable_id' => $data['deliverable_id'],
'resourcetype' => $data['resourcetype'],
'link' => $resourcetype->getLink($fields)
);
$template = new Template();
$template->render('json', array(
'data' => $json
));
break;
/**
* Refresh one or more resources
* Params:
* resource_id - id of an individual resource to refresh
* deliverable_id - id of a deliverable to refresh all associated resources
* milestone_id - id of a milestone to refresh all associated resources
*/
case 'refresh-resources':
$resource_manager = new ResourceManager;
// Get resource info
list($Resource) = load_models('Resource');
if (!empty($_GET['resource_id'])) {
$query = 'id = \''.escape($_GET['resource_id']).'\'';
$resources = $Resource->getAll($query);
}
elseif (!empty($_GET['deliverable_id'])) {
$query = 'deliverable_id = \''.escape($_GET['deliverable_id']).'\'';
$resources = $Resource->getAll($query);
}
elseif (!empty($_GET['milestone_id'])) {
$query = "SELECT resources.* FROM resources INNER JOIN deliverables ON resources.deliverable_id = deliverables.id WHERE deliverables.milestone_id = ".escape($_GET['milestone_id']);
$resources = $Resource->db->query($query);
}
$updated = array();
if (!empty($resources)) {
foreach ($resources as $resource) {
// Make sure resourcetype has been loaded
$resource_manager->loadAdditionalResourcetype($resource['resourcetype']);
$new = $resource_manager->resourcetypes[$resource['resourcetype']]->refreshAndUpdate($Resource, $resource['id'], unserialize($resource['data']));
if (is_array($new)) {
$updated[] = array(
'resource_id' => $resource['id'],
'link' => $resource_manager->resourcetypes[$resource['resourcetype']]->getLink($new)
);
}
}
}
$template = new Template();
$template->render('json', array(
'data' => $updated
));
break;
/**
* Calls a resourcetype's custom handler function
* Params:
* resourcetype - the resourcetype
* handler - name of the handler
* (other) - other data to be passed on to handler
*/
case 'resourcetype-custom':
$resource_manager = new ResourceManager(array($_GET['resourcetype']));
$resourcetype =& $resource_manager->resourcetypes[$_GET['resourcetype']];
$resourcetype->handle($_GET['handler'], $_GET);
break;
}
?>