source: Dev/trunk/classes/pipelineSequencer.php @ 151

Last change on this file since 151 was 151, checked in by fpvanagthoven, 13 years ago
File size: 5.3 KB
RevLine 
[144]1<?php
2/*
3 * To change this template, choose Tools | Templates
4 * and open the template in the editor.
5 */
6
7/**
[151]8 * A visual interface object for editing and viewing a session's pipeline.
[144]9 *
[151]10 * @author Tschipper
[144]11 */
[146]12class PipelineSequencer {
[144]13
14    // properties
[151]15    private $pipeline;      // array of UID strings.
[150]16    private $name = "empty";
[144]17    private $numStepsInArray = 0;
[146]18    private $maxNumStepsInArray = 10;
[144]19    private $selectedStep;
20
[150]21    public function __construct($uid) {
22        $dbi = new DatabaseInterface();
[151]23        $this->pipeline = $dbi->get("pipeline", array("uid" => $uid));
[146]24    }
[144]25
[150]26    public function init() {
[144]27        ?>
[151]28        <br /><form name="sequencer" action="pipelineEditor.php" method="post">
29            <fieldset id="sequencer">
[150]30                <div class="title">Name: <?php echo $this->pipeline->name; ?> </div>
[144]31
[151]32                <div id="seqContent">
[146]33                    <?php $this->DrawSteps(); ?>         
[144]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" />
[146]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?
[144]43                    <input type="hidden" name="selectedStep" />
[151]44                    <input type="hidden" name="numSteps" />
45                    <input type="hidden" name="pipeline" />
[144]46                </div>
47            </fieldset>
48        </form>
49        <?php
50    }
51
[146]52    public function DrawSteps() {
[150]53       
[146]54    }
55
[150]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?
[151]61
[150]62        -->
63        <script type="text/javascript">
[151]64            function selectStep(uid) {
65                document.getElementById(uid).addClass("selected");
66                document.sequencer.controls.selectedStep.value = uid;
[150]67            }
[151]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                                               
[150]120        </script>
121
122
123        <?php
124    }
125
[151]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
[144]134}
135?>
Note: See TracBrowser for help on using the repository browser.