[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 | |
---|
[61] | 24 | <div class="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; |
---|
[93] | 50 | |
---|
[64] | 51 | // ============================================================= |
---|
[93] | 52 | |
---|
| 53 | function addSurvey() { |
---|
[66] | 54 | var surveysList = document.getElementById("surveysList"); |
---|
[93] | 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) |
---|
[69] | 73 | { |
---|
[70] | 74 | var pipeline = document.getElementById("pipeline"); |
---|
| 75 | var entry = document.createElement("option"); |
---|
[93] | 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 | |
---|
[70] | 86 | pipeline.appendChild(entry); |
---|
[93] | 87 | } |
---|
[67] | 88 | } |
---|
[93] | 89 | |
---|
[67] | 90 | function addDashboard() { |
---|
[68] | 91 | pipelineCount++; |
---|
[67] | 92 | var pipeline = document.getElementById("pipeline"); |
---|
[93] | 93 | |
---|
[67] | 94 | var entry = document.createElement("option"); |
---|
| 95 | entry.setAttribute("value", "dashboard"); |
---|
| 96 | entry.style.backgroundColor = "#555"; |
---|
| 97 | entry.style.color = "white"; |
---|
[68] | 98 | entry.innerHTML = pipelineCount + ". " + "Dashboard"; |
---|
| 99 | entry.name = pipelineCount + "d"; |
---|
[69] | 100 | entry.entryType = "d"; |
---|
[93] | 101 | |
---|
[66] | 102 | pipeline.appendChild(entry); |
---|
[64] | 103 | } |
---|
[93] | 104 | |
---|
[69] | 105 | function removeFromPipeline() { |
---|
| 106 | var pipeline = document.getElementById("pipeline"); |
---|
[70] | 107 | if (pipeline.selectedIndex != -1) |
---|
[69] | 108 | { |
---|
| 109 | var index = pipeline.selectedIndex; |
---|
| 110 | pipeline.remove(index); |
---|
[93] | 111 | if (pipelineCount > 1 && |
---|
| 112 | pipeline.options[index] != null) |
---|
[70] | 113 | { |
---|
| 114 | pipeline.options[index].selected = true; |
---|
| 115 | } |
---|
[93] | 116 | |
---|
[69] | 117 | for(var i = index; i < pipeline.length; i++) |
---|
[70] | 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 | } |
---|
[69] | 125 | pipelineCount--; |
---|
| 126 | } |
---|
| 127 | } |
---|
[93] | 128 | |
---|
[68] | 129 | function submitPipeline() |
---|
| 130 | { |
---|
| 131 | var form = document.getElementById("sessionCreationForm"); |
---|
[93] | 132 | |
---|
[68] | 133 | var pipeline = document.getElementById("pipeline").options; |
---|
[93] | 134 | |
---|
| 135 | |
---|
[68] | 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"; |
---|
[93] | 142 | |
---|
[68] | 143 | form.appendChild(pipelineElem); |
---|
| 144 | } |
---|
[93] | 145 | |
---|
[69] | 146 | var count = document.createElement("input"); |
---|
| 147 | count.name = "pipelineCount"; |
---|
| 148 | count.value = pipelineCount; |
---|
| 149 | count.type = "hidden"; |
---|
[93] | 150 | |
---|
[69] | 151 | form.appendChild(count); |
---|
[68] | 152 | } |
---|
[64] | 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 | ?> |
---|
[72] | 163 | <input type="text" id="sessionTitle" class="titleBox" name="sessionTitle" value="<?php echo str_replace("\"", """, $value); ?>" onblur="handleBlur(this)" onfocus="handleFocus(this)" /> |
---|
[64] | 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 | ?> |
---|
[65] | 179 | <div id="pipelineWrapper"> |
---|
| 180 | <h2 class="pipelineHead">Pipeline</h2> |
---|
| 181 | <?php $this->pipelineSelect(); ?> |
---|
| 182 | <div id="pipelineOptions"> |
---|
| 183 | <?php |
---|
| 184 | $this->addDashboardToPipelineButton(); |
---|
[69] | 185 | $this->removeFromPipelineButton(); |
---|
[65] | 186 | ?> |
---|
| 187 | </div> |
---|
[64] | 188 | </div> |
---|
[69] | 189 | <?php |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | private function surveysApplications() { |
---|
| 193 | ?> |
---|
[65] | 194 | <div id="surveysApplicationsWrapper"> |
---|
| 195 | <div id="surveysForPipelineWrapper"> |
---|
| 196 | <h2 class="pipelineHead">Surveys</h2> |
---|
[66] | 197 | <?php |
---|
| 198 | $this->surveysSelect(); |
---|
[69] | 199 | $this->addSurveyToPipelineButton(); |
---|
[66] | 200 | ?> |
---|
[65] | 201 | </div> |
---|
| 202 | <div id="applicationsForPipelineWrapper"> |
---|
| 203 | <h2 class="pipelineHead">Applications</h2> |
---|
[66] | 204 | <?php |
---|
| 205 | $this->applicationsSelect(); |
---|
| 206 | $this->addApplicationToPipelineButton(); |
---|
| 207 | ?> |
---|
[65] | 208 | </div> |
---|
| 209 | </div> |
---|
| 210 | <?php |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | private function pipelineSelect() { |
---|
| 214 | ?> |
---|
[69] | 215 | <select id="pipeline" size="1000"></select> |
---|
[65] | 216 | <?php |
---|
| 217 | } |
---|
| 218 | |
---|
| 219 | private function surveysSelect() { |
---|
| 220 | ?> |
---|
[66] | 221 | <select id="surveysList" size="5" class="width100p"> |
---|
[64] | 222 | <?php |
---|
[65] | 223 | foreach ($this->surveys as $survey) { |
---|
| 224 | ?> |
---|
[69] | 225 | <option name="<?php echo $survey->id; ?>" value="<?php echo $survey->id; ?>"> |
---|
[65] | 226 | <?php echo $survey->title; ?> |
---|
| 227 | </option> |
---|
| 228 | <?php |
---|
| 229 | } |
---|
| 230 | ?> |
---|
| 231 | </select> |
---|
[64] | 232 | <?php |
---|
| 233 | } |
---|
| 234 | |
---|
[65] | 235 | private function applicationsSelect() { |
---|
| 236 | ?> |
---|
[67] | 237 | <select id="applicationsList" size="5" class="width100p"> |
---|
[83] | 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 | ?> |
---|
[65] | 247 | </select> |
---|
| 248 | <?php |
---|
| 249 | } |
---|
| 250 | |
---|
[64] | 251 | private function addSurveyToPipelineButton() { |
---|
| 252 | ?> |
---|
[66] | 253 | <input type="button" id="surveyToPipeline" class="surveyButton pipelineButton leftAlign leftPadding1" value="<=====" onclick="addSurvey()"/> |
---|
[64] | 254 | <?php |
---|
| 255 | } |
---|
| 256 | |
---|
| 257 | private function addApplicationToPipelineButton() { |
---|
| 258 | ?> |
---|
[93] | 259 | <input type="button" class="surveyButton pipelineButton leftAlign leftPadding1" value="<=====" onclick="addApplication()"/> |
---|
[64] | 260 | <?php |
---|
| 261 | } |
---|
| 262 | |
---|
| 263 | private function addDashboardToPipelineButton() { |
---|
| 264 | ?> |
---|
[69] | 265 | <input type="button" class="surveyButton pipelineButton leftAlign leftPadding1" value="+ Dashboard" onclick="addDashboard()"/> |
---|
[64] | 266 | <?php |
---|
| 267 | } |
---|
| 268 | |
---|
[69] | 269 | private function removeFromPipelineButton() { |
---|
| 270 | ?> |
---|
| 271 | <input type="button" class="surveyButton" value="x" onclick="removeFromPipeline()"/> |
---|
| 272 | <?php |
---|
| 273 | } |
---|
| 274 | |
---|
[64] | 275 | private function makeSessionButton() { |
---|
| 276 | ?> |
---|
[68] | 277 | <input type="submit" id="makeSessionButton" class="topRight surveyButton" value="Make session" /> |
---|
[64] | 278 | <?php |
---|
| 279 | } |
---|
| 280 | |
---|
[69] | 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 | |
---|
[58] | 302 | } |
---|
| 303 | ?> |
---|