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