source: Dev/trunk/returnStep.php @ 159

Last change on this file since 159 was 157, checked in by jkraaijeveld, 13 years ago

Edited the pipelineeditor slightly so it does not error when adding a Survey.

File size: 4.6 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        $dbi = new DatabaseInterface();
42    if ($uid == "123") {        // test case for when steps aren't actually working
43        $imageURL = "images/icons/unknowntype.png";
44        $responsePart = '<div class="displayStep" id="' . "123" . '" onClick="selectStep(this.id);"><div class="displayStepIcon"><img src="' . $imageURL . '" /></div>' . "123" . '</div>';
45        return $responsePart;
46    } else if ($uid == '456') {
47        $imageURL = "images/icons/unknowntype.png";
48        $responsePart = '<div class="displayStep" id="' . "456" . '" onClick="selectStep(this.id);"><div class="displayStepIcon"><img src="' . $imageURL . '" /></div>' . "456" . '</div>';
49        return $responsePart;
50    } else {
51
52
53        if ($uid == "divider") {    //a divider has been requested instead of a displaystep
54            $responsePart = '<div class="divider"></div>';
55            return $responsePart;
56        } else {        // an actual step has been requested.
57           
58//Check in order: survey, application, dashboard.
59            $result = null;
60            $resultType = null;
61            $surveys = $dbi->get("Survey", array("uid" => $uid));
62            if (count($surveys) > 0) {
63                if ($surveys[0] != null) {
64                    // A survey exists with the given UID!
65                    $result = $surveys[0];
66                    $resultType = "Survey";
67                }
68            }
69
70            if ($result != null) {
71                $applications = $dbi->get("Application", array("uid" => $uid));
72                if (count($applications) > 0) {
73                    if ($applications[0] != null) {
74                        // An application exists with the given UID!
75                        $result = $applications[0];
76                        $resultType = "Application";
77                    }
78                }
79            }
80
81            if ($result != null) {
82                $dashboards = $dbi->get("Dashboard", array("uid" => $uid));
83                if (count($dashboards) > 0) {
84                    if ($dashboards[0] != null) {
85                        // A dashboard exists with the given UID!
86                        $result = $dashboards[0];
87                        $resultType = "Dashboard";
88                    }
89                }
90            }
91
92// If result is still null at this point, the passed UID does not refer to an existing object!
93            if ($result == null || $resultType == null) {
94                echo "Non-existing UID passed!";
95            } else {
96
97                // set relevant variables based on the type and properties of the step in question (currently stored in $result)
98                switch (strtolower($resultType)) {
99                    case "survey":
100                        $imageURL = "images/icons/survey.png";
101                        break;
102                    case "dashboard":
103                        $imageURL = "images/icons/dashboard.png";
104                        break;
105                    case "application":
106                        $imageURL = "images/icons/application.png";
107                        break;
108                    default:
109                        $imageURL = "images/icons/unknowntype.png";
110                        break;
111                }
112
113//echo out the HTML markup
114                $responsePart = '<div class="displayStep" id="' . $result->uid . '" onClick="selectStep(this.id);"><div class="displayStepIcon"><img src="' . $imageURL . '" /></div>' . $result->title . '</div>';
115                return $responsePart;
116            }
117        }
118    }
119}
120
121?>
Note: See TracBrowser for help on using the repository browser.