1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * Description of SessionCreationTool |
---|
5 | * |
---|
6 | * @author fpvanagthoven |
---|
7 | */ |
---|
8 | class SessionCreationTool { |
---|
9 | |
---|
10 | private $session; |
---|
11 | private $surveys; |
---|
12 | private $applications; |
---|
13 | |
---|
14 | public function __construct($session = null) { |
---|
15 | $this->session = $session; |
---|
16 | |
---|
17 | $this->init(); |
---|
18 | |
---|
19 | $this->javascript(); |
---|
20 | var_dump($_POST); |
---|
21 | var_dump($session); |
---|
22 | ?> |
---|
23 | |
---|
24 | <div class="creation"> |
---|
25 | <form id="sessionCreationForm" action="" onsubmit="submitPipeline()" method="post"> |
---|
26 | <?php |
---|
27 | $this->title(); |
---|
28 | $this->description(); |
---|
29 | $this->pipeline(); |
---|
30 | $this->surveysApplications(); |
---|
31 | |
---|
32 | $this->makeSessionButton(); |
---|
33 | ?> |
---|
34 | </form> |
---|
35 | </div> |
---|
36 | <?php |
---|
37 | $this->populatePipeline(); |
---|
38 | } |
---|
39 | |
---|
40 | private function init() { |
---|
41 | $this->surveys = Loader::loadSurveys(); |
---|
42 | $this->applications = Loader::loadApplications(); |
---|
43 | } |
---|
44 | |
---|
45 | private function javascript() { |
---|
46 | ?> |
---|
47 | <script type="text/javascript" src="js/creation.js"></script> |
---|
48 | <script type="text/javascript"> |
---|
49 | var pipelineCount = 0; |
---|
50 | |
---|
51 | // ============================================================= |
---|
52 | |
---|
53 | function addSurvey() { |
---|
54 | var surveysList = document.getElementById("surveysList"); |
---|
55 | var entryType = "s"; |
---|
56 | var color = "#00ccff"; |
---|
57 | |
---|
58 | addFromList(surveysList, entryType, color); |
---|
59 | } |
---|
60 | |
---|
61 | function addApplication() |
---|
62 | { |
---|
63 | var applicationsList = document.getElementById("applicationsList"); |
---|
64 | var entryType = "a"; |
---|
65 | var color = "gold"; |
---|
66 | |
---|
67 | addFromList(applicationsList, entryType, color); |
---|
68 | } |
---|
69 | |
---|
70 | function addFromList(list, entryType, color) |
---|
71 | { |
---|
72 | if(list.selectedIndex != -1) |
---|
73 | { |
---|
74 | var pipeline = document.getElementById("pipeline"); |
---|
75 | var entry = document.createElement("option"); |
---|
76 | |
---|
77 | pipelineCount++; |
---|
78 | |
---|
79 | entry.setAttribute("value", list.options[list.selectedIndex].value); |
---|
80 | entry.innerHTML = pipelineCount + ". " + list.options[list.selectedIndex].innerHTML; |
---|
81 | |
---|
82 | entry.style.backgroundColor = color; |
---|
83 | entry.name = pipelineCount + entryType; |
---|
84 | entry.entryType = entryType; |
---|
85 | |
---|
86 | pipeline.appendChild(entry); |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | function addDashboard() { |
---|
91 | pipelineCount++; |
---|
92 | var pipeline = document.getElementById("pipeline"); |
---|
93 | |
---|
94 | var entry = document.createElement("option"); |
---|
95 | entry.setAttribute("value", "dashboard"); |
---|
96 | entry.style.backgroundColor = "#555"; |
---|
97 | entry.style.color = "white"; |
---|
98 | entry.innerHTML = pipelineCount + ". " + "Dashboard"; |
---|
99 | entry.name = pipelineCount + "d"; |
---|
100 | entry.entryType = "d"; |
---|
101 | |
---|
102 | pipeline.appendChild(entry); |
---|
103 | } |
---|
104 | |
---|
105 | function removeFromPipeline() { |
---|
106 | var pipeline = document.getElementById("pipeline"); |
---|
107 | if (pipeline.selectedIndex != -1) |
---|
108 | { |
---|
109 | var index = pipeline.selectedIndex; |
---|
110 | pipeline.remove(index); |
---|
111 | if (pipelineCount > 1 && |
---|
112 | pipeline.options[index] != null) |
---|
113 | { |
---|
114 | pipeline.options[index].selected = true; |
---|
115 | } |
---|
116 | |
---|
117 | for(var i = index; i < pipeline.length; i++) |
---|
118 | { |
---|
119 | var entry = pipeline.options[i]; |
---|
120 | entry.name = "" + (i+1) + entry.entryType; |
---|
121 | var htmlStr = entry.innerHTML; |
---|
122 | var dotIndex = htmlStr.indexOf('.'); |
---|
123 | entry.innerHTML = (i+1) + htmlStr.substr(dotIndex); |
---|
124 | } |
---|
125 | pipelineCount--; |
---|
126 | } |
---|
127 | } |
---|
128 | |
---|
129 | function submitPipeline() |
---|
130 | { |
---|
131 | var form = document.getElementById("sessionCreationForm"); |
---|
132 | |
---|
133 | var pipeline = document.getElementById("pipeline").options; |
---|
134 | |
---|
135 | |
---|
136 | for (var i = 0; i < pipeline.length; i++) |
---|
137 | { |
---|
138 | var pipelineElem = document.createElement("input"); |
---|
139 | pipelineElem.name = pipeline[i].name; |
---|
140 | pipelineElem.value = pipeline[i].value; |
---|
141 | pipelineElem.type = "hidden"; |
---|
142 | |
---|
143 | form.appendChild(pipelineElem); |
---|
144 | } |
---|
145 | |
---|
146 | var count = document.createElement("input"); |
---|
147 | count.name = "pipelineCount"; |
---|
148 | count.value = pipelineCount; |
---|
149 | count.type = "hidden"; |
---|
150 | |
---|
151 | form.appendChild(count); |
---|
152 | } |
---|
153 | </script> |
---|
154 | <?php |
---|
155 | } |
---|
156 | |
---|
157 | private function title() { |
---|
158 | if (isset($this->session->title)) |
---|
159 | $value = $this->session->title; |
---|
160 | else |
---|
161 | $value = 'Untitled Session'; |
---|
162 | ?> |
---|
163 | <input type="text" id="sessionTitle" class="titleBox" name="sessionTitle" value="<?php echo str_replace("\"", """, $value); ?>" onblur="handleBlur(this)" onfocus="handleFocus(this)" /> |
---|
164 | <?php |
---|
165 | } |
---|
166 | |
---|
167 | private function description() { |
---|
168 | if (isset($this->session->description)) |
---|
169 | $value = $this->session->description; |
---|
170 | else |
---|
171 | $value = 'Write a description for this session here.'; |
---|
172 | ?> |
---|
173 | <textarea id="sessionDescription" class="descriptionBox" name="sessionDescription" onblur="handleBlur(this)" onfocus="handleFocus(this)"><?php echo $value; ?></textarea> |
---|
174 | <?php |
---|
175 | } |
---|
176 | |
---|
177 | private function pipeline() { |
---|
178 | ?> |
---|
179 | <div id="pipelineWrapper"> |
---|
180 | <h2 class="pipelineHead">Pipeline</h2> |
---|
181 | <?php $this->pipelineSelect(); ?> |
---|
182 | <div id="pipelineOptions"> |
---|
183 | <?php |
---|
184 | $this->addDashboardToPipelineButton(); |
---|
185 | $this->removeFromPipelineButton(); |
---|
186 | ?> |
---|
187 | </div> |
---|
188 | </div> |
---|
189 | <?php |
---|
190 | } |
---|
191 | |
---|
192 | private function surveysApplications() { |
---|
193 | ?> |
---|
194 | <div id="surveysApplicationsWrapper"> |
---|
195 | <div id="surveysForPipelineWrapper"> |
---|
196 | <h2 class="pipelineHead">Surveys</h2> |
---|
197 | <?php |
---|
198 | $this->surveysSelect(); |
---|
199 | $this->addSurveyToPipelineButton(); |
---|
200 | ?> |
---|
201 | </div> |
---|
202 | <div id="applicationsForPipelineWrapper"> |
---|
203 | <h2 class="pipelineHead">Applications</h2> |
---|
204 | <?php |
---|
205 | $this->applicationsSelect(); |
---|
206 | $this->addApplicationToPipelineButton(); |
---|
207 | ?> |
---|
208 | </div> |
---|
209 | </div> |
---|
210 | <?php |
---|
211 | } |
---|
212 | |
---|
213 | private function pipelineSelect() { |
---|
214 | ?> |
---|
215 | <select id="pipeline" size="1000"></select> |
---|
216 | <?php |
---|
217 | } |
---|
218 | |
---|
219 | private function surveysSelect() { |
---|
220 | ?> |
---|
221 | <select id="surveysList" size="5" class="width100p"> |
---|
222 | <?php |
---|
223 | foreach ($this->surveys as $survey) { |
---|
224 | ?> |
---|
225 | <option name="<?php echo $survey->id; ?>" value="<?php echo $survey->id; ?>"> |
---|
226 | <?php echo $survey->title; ?> |
---|
227 | </option> |
---|
228 | <?php |
---|
229 | } |
---|
230 | ?> |
---|
231 | </select> |
---|
232 | <?php |
---|
233 | } |
---|
234 | |
---|
235 | private function applicationsSelect() { |
---|
236 | ?> |
---|
237 | <select id="applicationsList" size="5" class="width100p"> |
---|
238 | <?php |
---|
239 | foreach ($this->applications as $application) { |
---|
240 | ?> |
---|
241 | <option name="<?php echo $application->id; ?>" value="<?php echo $application->id; ?>"> |
---|
242 | <?php echo $application->title; ?> |
---|
243 | </option> |
---|
244 | <?php |
---|
245 | } |
---|
246 | ?> |
---|
247 | </select> |
---|
248 | <?php |
---|
249 | } |
---|
250 | |
---|
251 | private function addSurveyToPipelineButton() { |
---|
252 | ?> |
---|
253 | <input type="button" id="surveyToPipeline" class="surveyButton pipelineButton leftAlign leftPadding1" value="<=====" onclick="addSurvey()"/> |
---|
254 | <?php |
---|
255 | } |
---|
256 | |
---|
257 | private function addApplicationToPipelineButton() { |
---|
258 | ?> |
---|
259 | <input type="button" class="surveyButton pipelineButton leftAlign leftPadding1" value="<=====" onclick="addApplication()"/> |
---|
260 | <?php |
---|
261 | } |
---|
262 | |
---|
263 | private function addDashboardToPipelineButton() { |
---|
264 | ?> |
---|
265 | <input type="button" class="surveyButton pipelineButton leftAlign leftPadding1" value="+ Dashboard" onclick="addDashboard()"/> |
---|
266 | <?php |
---|
267 | } |
---|
268 | |
---|
269 | private function removeFromPipelineButton() { |
---|
270 | ?> |
---|
271 | <input type="button" class="surveyButton" value="x" onclick="removeFromPipeline()"/> |
---|
272 | <?php |
---|
273 | } |
---|
274 | |
---|
275 | private function makeSessionButton() { |
---|
276 | ?> |
---|
277 | <input type="submit" id="makeSessionButton" class="topRight surveyButton" value="Make session" /> |
---|
278 | <?php |
---|
279 | } |
---|
280 | |
---|
281 | private function populatePipeline() { |
---|
282 | |
---|
283 | if (isset($this->session)) { |
---|
284 | for ($i = 1; $i < $this->session->count + 1; $i++) { |
---|
285 | if (isset($this->session->pipeline[$i . 's'])) { |
---|
286 | ?> |
---|
287 | <script type="text/javascript"> |
---|
288 | addSurvey(<?php echo "'" . $this->session->pipeline[$i . 's'] . "'"; ?>); |
---|
289 | </script> |
---|
290 | <?php |
---|
291 | } else if (isset($this->session->pipeline[$i . 'd'])) { |
---|
292 | ?> |
---|
293 | <script type="text/javascript"> |
---|
294 | addDashboard(); |
---|
295 | </script> |
---|
296 | <?php |
---|
297 | } |
---|
298 | } |
---|
299 | } |
---|
300 | } |
---|
301 | |
---|
302 | } |
---|
303 | ?> |
---|