source: Dev/trunk/returnStep.php @ 155

Last change on this file since 155 was 155, checked in by fpvanagthoven, 13 years ago
File size: 4.5 KB
Line 
1<?php
2
3require '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
12if (isset($_POST['uids'])) {
13    if (!empty($_POST['uids'])) {
14        $uids = $_POST['uids'];
15    } else {
16        echo "Invalid UIDs passed!";
17        return;
18    }
19} else {
20    echo "No UID passed!";
21}
22
23$sUids = explode(",", $uids);
24$response = "";
25$dbi = new DatabaseInterface();
26foreach ($sUids as $uid) {
27    $response .= processUid($uid);
28}
29
30echo $response;
31
32
33/*
34 * 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.
35 * Additional onclick events for selecting objects would need to be added as well.
36 */
37
38
39
40function processUid($uid) {
41    if ($uid == "123") {        // test case for when steps aren't actually working
42        $imageURL = "images/icons/unknowntype.png";
43        $responsePart = '<div class="displayStep" id="' . "123" . '" onClick="selectStep(this.id);"><div class="displayStepIcon"><img src="' . $imageURL . '" /></div>' . "123" . '</div>';
44        return $responsePart;
45    } else if ($uid == '456') {
46        $imageURL = "images/icons/unknowntype.png";
47        $responsePart = '<div class="displayStep" id="' . "456" . '" onClick="selectStep(this.id);"><div class="displayStepIcon"><img src="' . $imageURL . '" /></div>' . "456" . '</div>';
48        return $responsePart;
49    } else {
50
51
52        if ($uid == "divider") {    //a divider has been requested instead of a displaystep
53            $responsePart = '<div class="divider"></div>';
54            return $responsePart;
55        } else {        // an actual step has been requested.
56           
57//Check in order: survey, application, dashboard.
58            $result = null;
59            $resultType = null;
60            $surveys = $dbi->get("Survey", array("uid" => $uid));
61            if (count($surveys) > 0) {
62                if ($surveys[0] != null) {
63                    // A survey exists with the given UID!
64                    $result = $surveys[0];
65                    $resultType = "Survey";
66                }
67            }
68
69            if (result != null) {
70                $applications = $dbi->get("Application", array("uid" => $uid));
71                if (count($applications) > 0) {
72                    if ($applications[0] != null) {
73                        // An application exists with the given UID!
74                        $result = $applications[0];
75                        $resultType = "Application";
76                    }
77                }
78            }
79
80            if (result != null) {
81                $dashboards = $dbi->get("Dashboard", array("uid" => $uid));
82                if (count($dashboards) > 0) {
83                    if ($dashboards[0] != null) {
84                        // A dashboard exists with the given UID!
85                        $result = $dashboards[0];
86                        $resultType = "Dashboard";
87                    }
88                }
89            }
90
91// If result is still null at this point, the passed UID does not refer to an existing object!
92            if ($result == null || $resultType == null) {
93                echo "Non-existing UID passed!";
94            } else {
95
96                // set relevant variables based on the type and properties of the step in question (currently stored in $result)
97                switch (strtolower($resultType)) {
98                    case "survey":
99                        $imageURL = "images/icons/survey.png";
100                        break;
101                    case "dashboard":
102                        $imageURL = "images/icons/dashboard.png";
103                        break;
104                    case "application":
105                        $imageURL = "images/icons/application.png";
106                        break;
107                    default:
108                        $imageURL = "images/icons/unknowntype.png";
109                        break;
110                }
111
112//echo out the HTML markup
113                $responsePart = '<div class="displayStep" id="' . $result->uid . '" onClick="selectStep(this.id);"><div class="displayStepIcon"><img src="' . $imageURL . '" /></div>' . $result->name . '</div>';
114                return $responsePart;
115            }
116        }
117    }
118}
119
120?>
Note: See TracBrowser for help on using the repository browser.