1 | <?php |
---|
2 | |
---|
3 | /* |
---|
4 | * To change this template, choose Tools | Templates |
---|
5 | * and open the template in the editor. |
---|
6 | */ |
---|
7 | |
---|
8 | /** |
---|
9 | * A visual interface object for editing and viewing a session's pipeline. |
---|
10 | * |
---|
11 | * @author Tschipper |
---|
12 | */ |
---|
13 | class PipelineSequencer { |
---|
14 | |
---|
15 | // properties |
---|
16 | private $loadedSession; |
---|
17 | private $selectedStep; |
---|
18 | private $dbi; |
---|
19 | |
---|
20 | public function __construct() { |
---|
21 | $this->dbi = new DatabaseInterface(); |
---|
22 | } |
---|
23 | |
---|
24 | public function init() { |
---|
25 | $stringPipeline = ""; |
---|
26 | $stringPipelineType = ""; |
---|
27 | $stringPipelineUpdated = ""; |
---|
28 | $numberOfSteps = 0; |
---|
29 | |
---|
30 | if (is_array($this->loadedSession->pipeline)) { |
---|
31 | foreach ($this->loadedSession->pipeline as $object) { |
---|
32 | $stringPipeline .= "$object->uid,"; |
---|
33 | $stringPipelineType .= get_class($object).","; |
---|
34 | $stringPipelineUpdated .= "1,"; |
---|
35 | $numberOfSteps++; |
---|
36 | |
---|
37 | } |
---|
38 | $stringPipeline = rtrim($stringPipeline, ","); |
---|
39 | $stringPipelineType = rtrim($stringPipelineType, ","); |
---|
40 | $stringPipelineUpdated = rtrim($stringPipelineUpdated, ","); |
---|
41 | |
---|
42 | } else { |
---|
43 | $stringPipeline = $this->loadedSession->pipeline; |
---|
44 | $stringPipelineType = $_POST['pipelineTypes']; |
---|
45 | $stringPipelineUpdated = $_POST['pipelineUpdatedField']; |
---|
46 | } |
---|
47 | ?> |
---|
48 | <br /><form name="sequencerForm" action="pipelineEditor.php" method="post"> |
---|
49 | <fieldset id="sequencer"> |
---|
50 | <div class="title">Name: <?php echo $this->loadedSession->title; ?> </div> |
---|
51 | |
---|
52 | <div id="seqContent"></div> |
---|
53 | |
---|
54 | <div id="controls"> |
---|
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? |
---|
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" /> |
---|
64 | </div> |
---|
65 | <div id="hiddenInputs"> |
---|
66 | <input type="hidden" name="selectedStep" id="selectedStepField" value="" /> |
---|
67 | <input type="hidden" name="pipelineString" id="pipelineStringField" value="<?php echo $stringPipeline; ?>" /> |
---|
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; ?>" /> |
---|
71 | </div> |
---|
72 | </fieldset> |
---|
73 | </form> |
---|
74 | <?php |
---|
75 | } |
---|
76 | |
---|
77 | public function DrawSteps() { |
---|
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 |
---|
87 | } |
---|
88 | |
---|
89 | public function Javascript() { |
---|
90 | $pipelineString = "ERROR"; |
---|
91 | |
---|
92 | echo "<!--$pipelineString-->"; |
---|
93 | ?> |
---|
94 | <script type="text/javascript" src="js/sequencerScripts.js"></script> |
---|
95 | <script type="text/javascript" src="js/jquery.js"></script> |
---|
96 | <script type="text/javascript"> |
---|
97 | $(document).ready(function() { |
---|
98 | drawSteps(); |
---|
99 | }); |
---|
100 | </script> |
---|
101 | <?php |
---|
102 | } |
---|
103 | |
---|
104 | public function LoadSession($currentSession) { // Initialize variables on page load. |
---|
105 | if (!isset($currentSession)) { |
---|
106 | redirect("selectSession.php"); |
---|
107 | } |
---|
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]; |
---|
113 | unset($_SESSION['updateNeeded']); |
---|
114 | } else { |
---|
115 | die("No session with that UID found!"); |
---|
116 | } |
---|
117 | } |
---|
118 | //var_dump($_SESSION['localSessionCopy']); |
---|
119 | |
---|
120 | if (isset($_SESSION['localSessionCopy']) && !empty($_SESSION['localSessionCopy'])) { |
---|
121 | |
---|
122 | $this->loadedSession = $_SESSION['localSessionCopy']; |
---|
123 | unset($_SESSION['updateNeeded']); |
---|
124 | } |
---|
125 | |
---|
126 | } |
---|
127 | |
---|
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'])) { |
---|
137 | $this->MoveStep($_POST['selectedStep'], -1); |
---|
138 | } |
---|
139 | } |
---|
140 | |
---|
141 | if (isset($_POST['moveSelectedRight'])) { |
---|
142 | if (isset($_POST['selectedStep']) && !empty($_POST['selectedStep'])) { |
---|
143 | $this->MoveStep($_POST['selectedStep'], 1); |
---|
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++) { |
---|
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; |
---|
174 | break; |
---|
175 | } |
---|
176 | } |
---|
177 | |
---|
178 | $this->loadedSession = $newSession; |
---|
179 | redirect("pipelineEditor.php"); |
---|
180 | } |
---|
181 | |
---|
182 | |
---|
183 | } |
---|
184 | ?> |
---|