source: Dev/trunk/classes/SessionCreationTool.php @ 78

Last change on this file since 78 was 72, checked in by fpvanagthoven, 14 years ago

Okay input is now a lot more robust. Apostrophes and quotes should no longer be a problem.

File size: 12.7 KB
Line 
1<?php
2
3/**
4 * Description of SessionCreationTool
5 *
6 * @author fpvanagthoven
7 */
8class SessionCreationTool {
9
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();
19        var_dump($_POST);
20        var_dump($session);
21       
22        ?>
23
24        <div class="creation">
25            <form id="sessionCreationForm" action="" onsubmit="submitPipeline()" method="post">
26                <?php
27                $this->title();
28                $this->description();
29                $this->pipeline();
30                $this->surveysApplications();
31
32                $this->makeSessionButton();
33                ?>
34            </form>
35        </div>
36        <?php
37        $this->populatePipeline();
38    }
39
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">
48            var pipelineCount = 0;
49                                                                                                                                                                                                                                                                                                                                     
50            // =============================================================
51                                                                                                                                                                                                                                                                                                                                                           
52            function addSurvey(surveyID) {       
53                var surveysList = document.getElementById("surveysList");
54                           
55                if(surveysList.selectedIndex != -1 || surveyID != null)
56                {
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                }                         
80            }
81                                                                                                                                                                                                                                   
82            function addDashboard() {
83                pipelineCount++;
84                var pipeline = document.getElementById("pipeline");
85                                                                                                                                                                                                                                       
86                var entry = document.createElement("option");
87                entry.setAttribute("value", "dashboard");
88                entry.style.backgroundColor = "#555";
89                entry.style.color = "white";
90                entry.innerHTML = pipelineCount + ". " + "Dashboard";
91                entry.name = pipelineCount + "d";
92                entry.entryType = "d";
93                                                                                                                                                                                                                                       
94                pipeline.appendChild(entry);
95            }
96                                                                                   
97            function removeFromPipeline() {
98                var pipeline = document.getElementById("pipeline");
99                if (pipeline.selectedIndex != -1)
100                {
101                    var index = pipeline.selectedIndex;
102                    pipeline.remove(index);
103                    if (pipelineCount > 1)
104                    {
105                        pipeline.options[index].selected = true;
106                    }
107                                                                           
108                    for(var i = index; i < pipeline.length; i++)
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                    }
116                    pipelineCount--;
117                }
118            }
119                                                                                                                                                                                                                                                     
120            function submitPipeline()
121            {
122                var form = document.getElementById("sessionCreationForm");
123                                                                                                                                                                                                                       
124                var pipeline = document.getElementById("pipeline").options;
125                                                                                                                                                                                                                               
126                                                                                                                                                                                                                               
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";
133                                                                                                                                                                                                                           
134                    form.appendChild(pipelineElem);
135                }
136                                                                                                                                                                                                               
137                var count = document.createElement("input");
138                count.name = "pipelineCount";
139                count.value = pipelineCount;
140                count.type = "hidden";
141                                                                                                                                                                                                               
142                form.appendChild(count);
143            }
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 str_replace("\"", "&quot;", $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        ?>
170        <div id="pipelineWrapper">
171            <h2 class="pipelineHead">Pipeline</h2>
172            <?php $this->pipelineSelect(); ?>
173            <div id="pipelineOptions">
174                <?php
175                $this->addDashboardToPipelineButton();
176                $this->removeFromPipelineButton();
177                ?>
178            </div>
179        </div>
180        <?php
181    }
182
183    private function surveysApplications() {
184        ?>
185        <div id="surveysApplicationsWrapper">
186            <div id="surveysForPipelineWrapper">
187                <h2 class="pipelineHead">Surveys</h2>
188                <?php
189                $this->surveysSelect();
190                $this->addSurveyToPipelineButton();
191                ?>
192            </div>
193            <div id="applicationsForPipelineWrapper">
194                <h2 class="pipelineHead">Applications</h2>
195                <?php
196                $this->applicationsSelect();
197                $this->addApplicationToPipelineButton();
198                ?>
199            </div>
200        </div>
201        <?php
202    }
203
204    private function pipelineSelect() {
205        ?>
206        <select id="pipeline" size="1000"></select>
207        <?php
208    }
209
210    private function surveysSelect() {
211        ?>
212        <select id="surveysList" size="5" class="width100p">
213            <?php
214            foreach ($this->surveys as $survey) {
215                ?>
216                <option name="<?php echo $survey->id; ?>" value="<?php echo $survey->id; ?>">
217                    <?php echo $survey->title; ?>
218                </option>
219                <?php
220            }
221            ?>
222        </select>
223        <?php
224    }
225
226    private function applicationsSelect() {
227        ?>
228        <select id="applicationsList" size="5" class="width100p">
229        </select>
230        <?php
231    }
232
233    private function addSurveyToPipelineButton() {
234        ?>
235        <input type="button" id="surveyToPipeline" class="surveyButton pipelineButton leftAlign leftPadding1" value="<=====" onclick="addSurvey()"/>
236        <?php
237    }
238
239    private function addApplicationToPipelineButton() {
240        ?>
241        <input type="button" class="surveyButton pipelineButton leftAlign leftPadding1" value="<=====" />
242        <?php
243    }
244
245    private function addDashboardToPipelineButton() {
246        ?>
247        <input type="button" class="surveyButton pipelineButton leftAlign leftPadding1" value="+ Dashboard" onclick="addDashboard()"/>
248        <?php
249    }
250
251    private function removeFromPipelineButton() {
252        ?>
253        <input type="button" class="surveyButton" value="x" onclick="removeFromPipeline()"/>
254        <?php
255    }
256
257    private function makeSessionButton() {
258        ?>
259        <input type="submit" id="makeSessionButton" class="topRight surveyButton" value="Make session" />
260        <?php
261    }
262
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
284}
285?>
Note: See TracBrowser for help on using the repository browser.