1 | <?php |
---|
2 | |
---|
3 | require 'classes/master.php'; //should be at top of every page |
---|
4 | /* |
---|
5 | * Return the HTML markup for visualisation of an object in a pipeline, to be used in the PipelineSequencer.php |
---|
6 | * Called by PipelineSequencer, posting UID of the step in question. |
---|
7 | * TODO: Selection code. Onload doen of serverside? |
---|
8 | * Javascript voor selection scripts staat ook nog niet in de -onclick- property, eerst dat script uitzoeken, daarna pas invoegen. |
---|
9 | */ |
---|
10 | |
---|
11 | // Check if calling script actually passed a uid to use |
---|
12 | if (isset($_POST['uids'])) { |
---|
13 | if (!empty($_POST['uids'])) { |
---|
14 | $sUids = $_POST['uids']; // string uids |
---|
15 | } else { |
---|
16 | echo "Invalid UIDs passed!"; |
---|
17 | return; |
---|
18 | } |
---|
19 | } else { |
---|
20 | echo "No UID passed!"; |
---|
21 | } |
---|
22 | |
---|
23 | $sTypes = "unknown"; // string types |
---|
24 | if (isset($_POST['types'])) { |
---|
25 | if (!empty($_POST['types'])) { |
---|
26 | $sTypes = $_POST['types']; |
---|
27 | } |
---|
28 | } |
---|
29 | |
---|
30 | $uids = explode(",", $sUids); // array uids |
---|
31 | if ($sTypes != "unknown") { |
---|
32 | $types = explode(",", $sTypes); |
---|
33 | } |
---|
34 | $response = ""; |
---|
35 | $dbi = new DatabaseInterface(); |
---|
36 | |
---|
37 | if (isset($types)) { |
---|
38 | for ($i = 0; $i < count($uids); $i++) { |
---|
39 | $response .= processUid($uids[$i], $types[$i]); |
---|
40 | } |
---|
41 | } else { |
---|
42 | for ($i = 0; $i < count($uids); $i++) { |
---|
43 | $response .= processUid($uids[$i]); |
---|
44 | } |
---|
45 | } |
---|
46 | |
---|
47 | |
---|
48 | |
---|
49 | echo $response; |
---|
50 | |
---|
51 | |
---|
52 | /* |
---|
53 | * ProcessUid needs to be changed once all the object classes are fixed. The '123', '456' test cases are not functional and are for testing puroses only. |
---|
54 | * Additional onclick events for selecting objects would need to be added as well. |
---|
55 | */ |
---|
56 | |
---|
57 | function processUid($uid, $type = null) { |
---|
58 | $dbi = new DatabaseInterface(); |
---|
59 | |
---|
60 | if ($uid == "divider") { //a divider has been requested instead of a displaystep |
---|
61 | $responsePart = '<div class="divider"></div>'; |
---|
62 | return $responsePart; |
---|
63 | } |
---|
64 | |
---|
65 | $result = null; |
---|
66 | $resultType = null; |
---|
67 | |
---|
68 | if ($type != null) { // Als er een type is gespecificeerd |
---|
69 | $resultType = $type; |
---|
70 | $results = $dbi->get($type, array("uid" => $uid)); |
---|
71 | if (count($results) > 0) { |
---|
72 | $result = $results[0]; |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | // Als er geen type is gespecificeerd, doorloop de queries in de volgorde: Survey, Application, Dashboard |
---|
77 | else { |
---|
78 | $surveys = $dbi->get("Survey", array("uid" => $uid)); |
---|
79 | if (count($surveys) > 0) { |
---|
80 | if ($surveys[0] != null) { |
---|
81 | // A survey exists with the given UID! |
---|
82 | $result = $surveys[0]; |
---|
83 | $resultType = "Survey"; |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | if ($result == null) { |
---|
88 | $applications = $dbi->get("Application", array("uid" => $uid)); |
---|
89 | if (count($applications) > 0) { |
---|
90 | if ($applications[0] != null) { |
---|
91 | // An application exists with the given UID! |
---|
92 | $result = $applications[0]; |
---|
93 | $resultType = "Application"; |
---|
94 | } |
---|
95 | } |
---|
96 | } |
---|
97 | |
---|
98 | if ($result == null) { |
---|
99 | $dashboards = $dbi->get("Dashboard", array("uid" => $uid)); |
---|
100 | if (count($dashboards) > 0) { |
---|
101 | if ($dashboards[0] != null) { |
---|
102 | // A dashboard exists with the given UID! |
---|
103 | $result = $dashboards[0]; |
---|
104 | $resultType = "Dashboard"; |
---|
105 | } |
---|
106 | } |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | // If result is still null at this point, the passed UID does not refer to an existing object! |
---|
111 | if ($result == null || $resultType == null) { |
---|
112 | echo "Non-existing UID passed!"; |
---|
113 | } else { |
---|
114 | |
---|
115 | // set relevant variables based on the type and properties of the step in question (currently stored in $result) |
---|
116 | switch (strtolower($resultType)) { |
---|
117 | case "survey": |
---|
118 | $imageURL = "images/icons/survey.png"; |
---|
119 | break; |
---|
120 | case "dashboard": |
---|
121 | $imageURL = "images/icons/dashboard.png"; |
---|
122 | break; |
---|
123 | case "application": |
---|
124 | $imageURL = "images/icons/application.png"; |
---|
125 | break; |
---|
126 | default: |
---|
127 | $imageURL = "images/icons/unknowntype.png"; |
---|
128 | break; |
---|
129 | } |
---|
130 | |
---|
131 | //echo out the HTML markup |
---|
132 | $responsePart = '<div class="displayStep" id="' . $result->uid . '" onClick="selectStep(this.id);"><div class="displayStepIcon"><img src="' . $imageURL . '" /></div>' . $result->title . '</div>'; |
---|
133 | return $responsePart; |
---|
134 | } |
---|
135 | } |
---|
136 | |
---|
137 | ?> |
---|