1 | <?php |
---|
2 | /* |
---|
3 | * To change this template, choose Tools | Templates |
---|
4 | * and open the template in the editor. |
---|
5 | */ |
---|
6 | |
---|
7 | /** |
---|
8 | * A visual interface object for editing and viewing a session's pipeline. |
---|
9 | * |
---|
10 | * @author Tschipper |
---|
11 | */ |
---|
12 | class PipelineSequencer { |
---|
13 | |
---|
14 | // properties |
---|
15 | private $pipeline; // array of UID strings. |
---|
16 | private $name = "empty"; |
---|
17 | private $numStepsInArray = 0; |
---|
18 | private $maxNumStepsInArray = 10; |
---|
19 | private $selectedStep; |
---|
20 | |
---|
21 | public function __construct($uid) { |
---|
22 | $dbi = new DatabaseInterface(); |
---|
23 | $this->pipeline = $dbi->get("pipeline", array("uid" => $uid)); |
---|
24 | } |
---|
25 | |
---|
26 | public function init() { |
---|
27 | ?> |
---|
28 | <br /><form name="sequencer" action="pipelineEditor.php" method="post"> |
---|
29 | <fieldset id="sequencer"> |
---|
30 | <div class="title">Name: <?php echo $this->pipeline->name; ?> </div> |
---|
31 | |
---|
32 | <div id="seqContent"> |
---|
33 | <?php $this->DrawSteps(); ?> |
---|
34 | </div> |
---|
35 | |
---|
36 | <div id="controls"> |
---|
37 | <input type="submit" name="moveSelectedLeft" value="< Move" class="surveyButton" /> |
---|
38 | <input type="submit" name="moveSelectedRight" value="Move >" class="surveyButton" /> |
---|
39 | <input type="submit" name="editSelected" value="Edit step" class="surveyButton" /> |
---|
40 | <input type="submit" name="deleteSelected" value="Delete step" class="surveyButton" /> |
---|
41 | <input type="submit" name="clearPipeline" value="Clear pipeline" class="surveyButton dis" disabled="true"/> |
---|
42 | <input type="checkbox" name="confirmClear" onChange="IsCheckEnabled(this, document.sequencer.clearPipeline);" />Really clear? |
---|
43 | <input type="hidden" name="selectedStep" /> |
---|
44 | <input type="hidden" name="numSteps" /> |
---|
45 | <input type="hidden" name="pipeline" /> |
---|
46 | </div> |
---|
47 | </fieldset> |
---|
48 | </form> |
---|
49 | <?php |
---|
50 | } |
---|
51 | |
---|
52 | public function DrawSteps() { |
---|
53 | |
---|
54 | } |
---|
55 | |
---|
56 | private function Javascript() { |
---|
57 | ?> |
---|
58 | <!-- |
---|
59 | Add JS code for selecting steps, highlighting them, reordering, etc. |
---|
60 | Is a refresh of the page (with subsequent querying of database really necessary? |
---|
61 | |
---|
62 | --> |
---|
63 | <script type="text/javascript"> |
---|
64 | function selectStep(uid) { |
---|
65 | document.getElementById(uid).addClass("selected"); |
---|
66 | document.sequencer.controls.selectedStep.value = uid; |
---|
67 | } |
---|
68 | |
---|
69 | |
---|
70 | /* |
---|
71 | * ajaxStepRequest gets the markup for displaying a step in the sequencer from returnStep.php |
---|
72 | * Using ajax principle allows for editing of pipeline without constantly refreshing the page. |
---|
73 | */ |
---|
74 | |
---|
75 | function ajaxStepRequest(uid) { |
---|
76 | var xmlhttp; |
---|
77 | if (window.XMLHttpRequest) { // IE7+, FF, Chrome, Opera, Safari |
---|
78 | xmlhttp = new XMLHttpRequest(); |
---|
79 | } |
---|
80 | else { //IE 5, 6 |
---|
81 | xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); |
---|
82 | } |
---|
83 | |
---|
84 | xmlhttp.onreadystatechange = function () { |
---|
85 | if (xmlhttp.readyState==4 && xmlhttp.status==200) { |
---|
86 | if (xmlhttp.responseText.length > 0) { |
---|
87 | var newDiv = xmlhttp.responseText; |
---|
88 | document.getElementById("seqContent").appendChild(newDiv); |
---|
89 | } |
---|
90 | } |
---|
91 | } |
---|
92 | |
---|
93 | xmlhttp.open("POST", "returnStep.php", true); |
---|
94 | xmlhttp.send(); |
---|
95 | } |
---|
96 | |
---|
97 | function drawSteps() { |
---|
98 | var sequencer = document.getElementById("sequencer"); |
---|
99 | var seqContent = document.getElementById("seqContent"); |
---|
100 | |
---|
101 | // first delete all current children of seqContent (to reset the sequencer). |
---|
102 | while (seqContent.childNodes.length > 0) { |
---|
103 | var step = seqContent.childNodes[0]; |
---|
104 | step.parentNode.removeChild(step); |
---|
105 | } |
---|
106 | |
---|
107 | // get pipeline contents from hidden form inputs. |
---|
108 | var pipeline = sequencer.controls.pipeline.value; |
---|
109 | var pipeline = pipeline.split(", "); |
---|
110 | |
---|
111 | // then do an xmlhttp request for each step to be added to the sequencer |
---|
112 | var numberOfSteps = pipeline.length; |
---|
113 | for (var i = 0; i > numberOfSteps; i++) { |
---|
114 | ajaxStepRequest(pipeline[i]); |
---|
115 | } |
---|
116 | |
---|
117 | } |
---|
118 | |
---|
119 | |
---|
120 | </script> |
---|
121 | |
---|
122 | |
---|
123 | <?php |
---|
124 | } |
---|
125 | |
---|
126 | public function GetDromDB() { // Initialize variables on page load. |
---|
127 | $dbi = new DatabaseInterface(); |
---|
128 | if (isset($_POST['currentSession'])) { |
---|
129 | $currentSession = $dbi->get("Session", array("UID" => $uid)); |
---|
130 | $this->pipeline = $currentSession->pipeline; |
---|
131 | } |
---|
132 | } |
---|
133 | |
---|
134 | } |
---|
135 | ?> |
---|