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