source: Dev/trunk/returnStep.php @ 154

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