Ignore:
Timestamp:
11/15/11 16:25:01 (13 years ago)
Author:
fpvanagthoven
Message:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/returnStep.php

    r153 r154  
    1010
    1111// Check if calling script actually passed a uid to use
    12 if (isset($_POST['uid'])) {
    13     if (!empty($_POST['uid'])) {
    14         $uid = $_POST['uid'];
     12if (isset($_POST['uids'])) {
     13    if (!empty($_POST['uids'])) {
     14        $uids = $_POST['uids'];
    1515    } else {
    16         echo "Invalid UID passed!";
     16        echo "Invalid UIDs passed!";
    1717    }
    1818} else {
     
    2020}
    2121
     22$sUids = explode(",", $uids);
     23$response = "";
     24$dbi = new DatabaseInterface();
     25foreach ($sUids as $uid) {
     26    $response .= processUid($uid);
     27}
     28
     29echo $response;
    2230
    2331
    24 if ($uid == "123") {        // test case for when steps aren't actually working
    25     $imageURL = "images/icons/unknowntype.png";
    26     $response = '<div class="displayStep" id="' . "123" . '"><div class="displayStepIcon"><img src="' . $imageURL . '" /></div>' . "123" . '</div>';
    27     echo $response;
    28 }
    29 else if($uid == '456') {
    30     $imageURL = "images/icons/unknowntype.png";
    31     $response = '<div class="displayStep" id="' . "456" . '"><div class="displayStepIcon"><img src="' . $imageURL . '" /></div>' . "456" . '</div>';
    32     echo $response;
    33 }
    34 else {
    35    
    36 
    37     if ($uid == "divider") {    //a divider has been requested instead of a displaystep
    38         $response = '<div class="divider"></div>';
    39         echo $response;
    40     } else {        // an actual step has been requested.
     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 */
    4136
    4237
    43         $dbi = new DatabaseInterface();
     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           
    4456//Check in order: survey, application, dashboard.
    45         $result = null;
    46         $resultType = null;
    47         $surveys = $dbi->get("Survey", array("uid" => $uid));
    48         if (count($surveys) > 0) {
    49             if ($surveys[0] != null) {
    50                 // A survey exists with the given UID!
    51                 $result = $surveys[0];
    52                 $resultType = "Survey";
    53             }
    54         }
    55 
    56         if (result != null) {
    57             $applications = $dbi->get("Application", array("uid" => $uid));
    58             if (count($applications) > 0) {
    59                 if ($applications[0] != null) {
    60                     // An application exists with the given UID!
    61                     $result = $applications[0];
    62                     $resultType = "Application";
     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";
    6365                }
    6466            }
    65         }
    6667
    67         if (result != null) {
    68             $dashboards = $dbi->get("Dashboard", array("uid" => $uid));
    69             if (count($dashboards) > 0) {
    70                 if ($dashboards[0] != null) {
    71                     // A dashboard exists with the given UID!
    72                     $result = $dashboards[0];
    73                     $resultType = "Dashboard";
     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                    }
    7476                }
    7577            }
    76         }
     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            }
    7789
    7890// If result is still null at this point, the passed UID does not refer to an existing object!
    79         if ($result == null || $resultType == null) {
    80             echo "Non-existing UID passed!";
    81         } else {
     91            if ($result == null || $resultType == null) {
     92                echo "Non-existing UID passed!";
     93            } else {
    8294
    83             // set relevant variables based on the type and properties of the step in question (currently stored in $result)
    84             switch (strtolower($resultType)) {
    85                 case "questionnaire":
    86                     $imageURL = "images/icons/questionnaire.png";
    87                     break;
    88                 case "dashboard":
    89                     $imageURL = "images/icons/dashboard.png";
    90                     break;
    91                 case "application":
    92                     $imageURL = "images/icons/application.png";
    93                     break;
    94                 default:
    95                     $imageURL = "images/icons/unknowntype.png";
    96                     break;
    97             }
     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                }
    98110
    99111//echo out the HTML markup
    100             $response = '<div class="displayStep" id="' . $result->uid . '"><div class="displayStepIcon"><img src="' . $imageURL . '" /></div>' . $result->name . '</div>';
    101             echo $response;
     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            }
    102115        }
    103116    }
    104117}
     118
    105119?>
Note: See TracChangeset for help on using the changeset viewer.