1 | <?php |
---|
2 | /* |
---|
3 | * To change this template, choose Tools | Templates |
---|
4 | * and open the template in the editor. |
---|
5 | */ |
---|
6 | |
---|
7 | /** |
---|
8 | * A visual interface object for editing and viewing a session's pipeline. |
---|
9 | * |
---|
10 | * @author Tschipper |
---|
11 | */ |
---|
12 | class PipelineSequencer { |
---|
13 | |
---|
14 | // properties |
---|
15 | private $loadedSession; |
---|
16 | private $selectedStep; |
---|
17 | private $dbi; |
---|
18 | |
---|
19 | public function __construct() { |
---|
20 | $this->dbi = new DatabaseInterface(); |
---|
21 | } |
---|
22 | |
---|
23 | public function init() { |
---|
24 | $stringPipeline = ""; |
---|
25 | if (is_array($this->loadedSession->pipeline)) { |
---|
26 | foreach ($this->loadedSession->pipeline as $object) { |
---|
27 | $stringPipeline .= "$object->uid,"; |
---|
28 | } |
---|
29 | $stringPipeline = rtrim($stringPipeline, ","); |
---|
30 | } else { |
---|
31 | $stringPipeline = $this->loadedSession->pipeline; |
---|
32 | } |
---|
33 | ?> |
---|
34 | <br /><form name="sequencerForm" action="pipelineEditor.php" method="post"> |
---|
35 | <fieldset id="sequencer"> |
---|
36 | <div class="title">Name: <?php echo $this->loadedSession->title; ?> </div> |
---|
37 | |
---|
38 | <div id="seqContent"></div> |
---|
39 | |
---|
40 | <div id="controls"> |
---|
41 | <input type="submit" id="moveSelectedLeft" name="moveSelectedLeft" value="< Move" class="surveyButton" /> |
---|
42 | <input type="submit" id="moveSelectedRight" name="moveSelectedRight" value="Move >" class="surveyButton" /> |
---|
43 | <input type="submit" id="editSelected" name="editSelected" value="Edit step" class="surveyButton" /> |
---|
44 | <input type="submit" id="deleteSelected" name="deleteSelected" value="Delete step" class="surveyButton" /> |
---|
45 | <input type="submit" id ="clearPipeline" name="clearPipeline" value="Clear pipeline" class="surveyButton dis" disabled="true"/> |
---|
46 | <input type="checkbox" id="confirmClear" name="confirmClear" onChange="IsCheckEnabled(this, document.getElementById('clearPipeline'));" />Really clear? |
---|
47 | </div> |
---|
48 | <div id="hiddenInputs"> |
---|
49 | <input type="hidden" name="selectedStep" id="selectedStepField" value="" /> |
---|
50 | <!-- <input type="hidden" name="pipelineString" id="pipelineStringField" value="123,456" /> --> |
---|
51 | <input type="hidden" name="pipelineString" id="pipelineStringField" value="<?php echo $stringPipeline; ?>" /> |
---|
52 | </div> |
---|
53 | </fieldset> |
---|
54 | </form> |
---|
55 | <?php |
---|
56 | } |
---|
57 | |
---|
58 | public function DrawSteps() { |
---|
59 | // Use AJAX to draw visual representations of step objects in a pipeline |
---|
60 | // <TODO> Implement parameters such as screen size in the drawing of objects </TODO> |
---|
61 | ?> |
---|
62 | <script type="text/javascript"> |
---|
63 | drawSteps(); |
---|
64 | </script> |
---|
65 | |
---|
66 | |
---|
67 | <?php |
---|
68 | } |
---|
69 | |
---|
70 | public function Javascript() { |
---|
71 | $pipelineString = "ERROR"; |
---|
72 | |
---|
73 | echo "<!--$pipelineString-->"; |
---|
74 | ?> |
---|
75 | <script type="text/javascript" src="js/sequencerScripts.js"></script> |
---|
76 | <script type="text/javascript" src="js/jquery.js"></script> |
---|
77 | <script type="text/javascript"> |
---|
78 | $(document).ready(function() { |
---|
79 | drawSteps(); |
---|
80 | }); |
---|
81 | </script> |
---|
82 | <?php |
---|
83 | } |
---|
84 | |
---|
85 | public function LoadSession($currentSession) { // Initialize variables on page load. |
---|
86 | if (!isset($currentSession)) { |
---|
87 | redirect("selectSession.php"); |
---|
88 | } |
---|
89 | 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 |
---|
90 | $sessionResults = $this->dbi->get("Session", array("uid" => $currentSession)); |
---|
91 | |
---|
92 | if (count($sessionResults) > 0) { |
---|
93 | $_SESSION['localSessionCopy'] = $sessionResults[0]; |
---|
94 | } else { |
---|
95 | die("No session with that UID found!"); |
---|
96 | } |
---|
97 | } |
---|
98 | var_dump($_SESSION['localSessionCopy']); |
---|
99 | |
---|
100 | if (isset($_SESSION['localSessionCopy']) && !empty($_SESSION['localSessionCopy'])) { |
---|
101 | |
---|
102 | $this->loadedSession = $_SESSION['localSessionCopy']; |
---|
103 | unset($_SESSION['updateNeeded']); |
---|
104 | } |
---|
105 | |
---|
106 | } |
---|
107 | |
---|
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'])) { |
---|
117 | MoveStep($_POST['selectedStep'], -1); |
---|
118 | } |
---|
119 | } |
---|
120 | |
---|
121 | if (isset($_POST['moveSelectedRight'])) { |
---|
122 | if (isset($_POST['selectedStep']) && !empty($_POST['selectedStep'])) { |
---|
123 | MoveStep($_POST['selectedStep'], 1); |
---|
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++) { |
---|
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] = $newSession->pipeline[i]; |
---|
154 | break; |
---|
155 | } |
---|
156 | } |
---|
157 | |
---|
158 | $this->loadedSession = $newSession; |
---|
159 | } |
---|
160 | |
---|
161 | public function StoreToDb() { |
---|
162 | if (isset($_SESSION['localSessionCopy']) && !empty($_SESSION['localSessionCopy'])) { |
---|
163 | $this->dbi->set($_SESSION['localSessionCopy']); |
---|
164 | unset($_SESSION['updateNeeded']); |
---|
165 | } |
---|
166 | } |
---|
167 | |
---|
168 | } |
---|
169 | ?> |
---|