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