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