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