[144] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | * To change this template, choose Tools | Templates |
---|
| 4 | * and open the template in the editor. |
---|
| 5 | */ |
---|
| 6 | |
---|
| 7 | /** |
---|
[151] | 8 | * A visual interface object for editing and viewing a session's pipeline. |
---|
[144] | 9 | * |
---|
[151] | 10 | * @author Tschipper |
---|
[144] | 11 | */ |
---|
[146] | 12 | class PipelineSequencer { |
---|
[144] | 13 | |
---|
| 14 | // properties |
---|
[152] | 15 | private $loadedSession; |
---|
[144] | 16 | private $selectedStep; |
---|
[163] | 17 | private $dbi; |
---|
[144] | 18 | |
---|
[152] | 19 | public function __construct() { |
---|
[163] | 20 | $this->dbi = new DatabaseInterface(); |
---|
[146] | 21 | } |
---|
[144] | 22 | |
---|
[150] | 23 | public function init() { |
---|
[153] | 24 | $stringPipeline = ""; |
---|
[164] | 25 | $stringPipelineType = ""; |
---|
| 26 | $stringPipelineUpdated = ""; |
---|
| 27 | $numberOfSteps = 0; |
---|
[166] | 28 | |
---|
[163] | 29 | if (is_array($this->loadedSession->pipeline)) { |
---|
| 30 | foreach ($this->loadedSession->pipeline as $object) { |
---|
| 31 | $stringPipeline .= "$object->uid,"; |
---|
[166] | 32 | $stringPipelineType .= get_class($object) . ","; |
---|
[167] | 33 | $stringPipelineUpdated .= "0,"; |
---|
[164] | 34 | $numberOfSteps++; |
---|
[163] | 35 | } |
---|
| 36 | } else { |
---|
[156] | 37 | $stringPipeline = $this->loadedSession->pipeline; |
---|
[164] | 38 | $stringPipelineType = $_POST['pipelineTypes']; |
---|
| 39 | $stringPipelineUpdated = $_POST['pipelineUpdatedField']; |
---|
[156] | 40 | } |
---|
[144] | 41 | ?> |
---|
[154] | 42 | <br /><form name="sequencerForm" action="pipelineEditor.php" method="post"> |
---|
[151] | 43 | <fieldset id="sequencer"> |
---|
[167] | 44 | <div class="fieldsetTitle">Name: <?php echo $this->loadedSession->title; ?> </div> |
---|
[144] | 45 | |
---|
[167] | 46 | <div id="seqContent"> |
---|
| 47 | <div id="seqContentWrapper"></div> |
---|
| 48 | </div> |
---|
[153] | 49 | |
---|
[144] | 50 | <div id="controls"> |
---|
[167] | 51 | <input type="button" id="moveSelectedL" value="< Move" class="surveyButton" onClick="moveStep(-1);" /> |
---|
| 52 | <input type="button" id="moveSelectedR" value="Move >" class="surveyButton" onClick="moveStep(1);" /> |
---|
[168] | 53 | <input type="button" id="editSelected" value="Edit step" class="surveyButton" onClick="editStep();" /> |
---|
[156] | 54 | <input type="submit" id="deleteSelected" name="deleteSelected" value="Delete step" class="surveyButton" /> |
---|
| 55 | <input type="submit" id ="clearPipeline" name="clearPipeline" value="Clear pipeline" class="surveyButton dis" disabled="true"/> |
---|
| 56 | <input type="checkbox" id="confirmClear" name="confirmClear" onChange="IsCheckEnabled(this, document.getElementById('clearPipeline'));" />Really clear? |
---|
[168] | 57 | <input type="button" value="debug_save" onClick="savePipeline(true);" /> |
---|
[144] | 58 | </div> |
---|
[154] | 59 | <div id="hiddenInputs"> |
---|
[153] | 60 | <input type="hidden" name="selectedStep" id="selectedStepField" value="" /> |
---|
[155] | 61 | <input type="hidden" name="pipelineString" id="pipelineStringField" value="<?php echo $stringPipeline; ?>" /> |
---|
[164] | 62 | <input type="hidden" name="pipelineTypes" id="pipelineTypeField" value="<?php echo $stringPipelineType; ?>" /> |
---|
| 63 | <input type="hidden" name="pipelineUpDated" id="pipelineUpdatedField" value="<?php echo $stringPipelineUpdated; ?>" /> |
---|
| 64 | <input type="hidden" name="numSteps" id="numSteps" value="<?php echo $numberOfSteps; ?>" /> |
---|
[166] | 65 | <input type="hidden" name="session" id="sessionField" value="<?php echo $this->loadedSession->uid; ?>" /> |
---|
[153] | 66 | </div> |
---|
[144] | 67 | </fieldset> |
---|
| 68 | </form> |
---|
| 69 | <?php |
---|
| 70 | } |
---|
| 71 | |
---|
[168] | 72 | |
---|
[153] | 73 | |
---|
| 74 | public function Javascript() { |
---|
[150] | 75 | ?> |
---|
[152] | 76 | <script type="text/javascript" src="js/sequencerScripts.js"></script> |
---|
[153] | 77 | <script type="text/javascript" src="js/jquery.js"></script> |
---|
| 78 | <script type="text/javascript"> |
---|
| 79 | $(document).ready(function() { |
---|
[168] | 80 | updateSequencer(true); // true means it is the first refresh of the page. |
---|
[153] | 81 | }); |
---|
| 82 | </script> |
---|
[150] | 83 | <?php |
---|
| 84 | } |
---|
| 85 | |
---|
[163] | 86 | public function LoadSession($currentSession) { // Initialize variables on page load. |
---|
[152] | 87 | if (!isset($currentSession)) { |
---|
| 88 | redirect("selectSession.php"); |
---|
[151] | 89 | } |
---|
[163] | 90 | if (isset($_SESSION['updateNeeded'])) { // user has performed an operation that flags session to be reloaded from DB, or is first load of page for that session |
---|
| 91 | $sessionResults = $this->dbi->get("Session", array("uid" => $currentSession)); |
---|
[166] | 92 | |
---|
[163] | 93 | if (count($sessionResults) > 0) { |
---|
| 94 | $_SESSION['localSessionCopy'] = $sessionResults[0]; |
---|
[164] | 95 | unset($_SESSION['updateNeeded']); |
---|
[163] | 96 | } else { |
---|
| 97 | die("No session with that UID found!"); |
---|
| 98 | } |
---|
[152] | 99 | } |
---|
[166] | 100 | |
---|
[163] | 101 | if (isset($_SESSION['localSessionCopy']) && !empty($_SESSION['localSessionCopy'])) { |
---|
[166] | 102 | |
---|
[163] | 103 | $this->loadedSession = $_SESSION['localSessionCopy']; |
---|
| 104 | unset($_SESSION['updateNeeded']); |
---|
| 105 | } |
---|
[151] | 106 | } |
---|
| 107 | |
---|
[154] | 108 | public function HandlePostData() { |
---|
| 109 | if (isset($_POST['editSelected'])) { |
---|
| 110 | if (isset($_POST['selectedStep']) && !empty($_POST['selectedStep'])) { |
---|
| 111 | redirect("editredirect.php"); |
---|
| 112 | } |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | if (isset($_POST['moveSelectedLeft'])) { |
---|
| 116 | if (isset($_POST['selectedStep']) && !empty($_POST['selectedStep'])) { |
---|
[164] | 117 | $this->MoveStep($_POST['selectedStep'], -1); |
---|
[154] | 118 | } |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | if (isset($_POST['moveSelectedRight'])) { |
---|
| 122 | if (isset($_POST['selectedStep']) && !empty($_POST['selectedStep'])) { |
---|
[164] | 123 | $this->MoveStep($_POST['selectedStep'], 1); |
---|
[154] | 124 | } |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | if (isset($_POST['objectToCreate']) && !empty($_POST['objectToCreate'])) { |
---|
| 128 | switch (strtolower($_POST['objectToCreate'])) { |
---|
| 129 | case "survey": |
---|
| 130 | redirect("createsurvey.php"); |
---|
| 131 | break; |
---|
| 132 | case "application": |
---|
| 133 | redirect("createapplication.php"); |
---|
| 134 | break; |
---|
| 135 | case "dashboard": |
---|
| 136 | redirect("createdashboard.php"); |
---|
| 137 | break; |
---|
| 138 | default: |
---|
| 139 | // Er is iets fout gegaan, want er is geen valid type meegegeven! |
---|
| 140 | break; |
---|
| 141 | } |
---|
| 142 | } |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | // Dit is een pure php versie. Deze slaat nog niet op in de Database, en reageert nog niet op |
---|
| 146 | public function MoveStep($uid, $direction) { |
---|
| 147 | $newSession = $this->loadedSession; |
---|
| 148 | |
---|
| 149 | for ($i = 0; $i < count($newSession->pipeline); $i++) { |
---|
[164] | 150 | if ($newSession->pipeline[$i]->uid == $uid) { |
---|
| 151 | $temp = $newSession->pipeline[$i]; |
---|
| 152 | $newSession->pipeline[$i] = $newSession->pipeline[$i + $direction]; |
---|
| 153 | $newSession->pipeline[$i + $direction] = $temp; |
---|
[154] | 154 | break; |
---|
| 155 | } |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | $this->loadedSession = $newSession; |
---|
[164] | 159 | redirect("pipelineEditor.php"); |
---|
[154] | 160 | } |
---|
| 161 | |
---|
[144] | 162 | } |
---|
| 163 | ?> |
---|