Changeset 152


Ignore:
Timestamp:
11/09/11 17:14:25 (13 years ago)
Author:
fpvanagthoven
Message:
  • getInfo.php returnet informatie over het aangevraagde object. Dit kan via ajax routines op verscheidene infopanels weergegeven worden. (Bijvoorbeeld in de huidige versie van selectSession.php). Deze script wordt later nog uitgebreid om verschillende soorten objecten en sets informatie weer te geven. (Momenteel alleen sessions!)
  • selectSession werkt grotendeels, op deleteSession en een non-fatal error bij createSession na.
  • logout.php gebruikt nu ook destroy_session();
  • sequencerScripts.js uitgebreid om een simpel aan te roepen AJAX routine mogelijk te maken. Dit biedt de mogelijkheid om pagina's aan te passen zonder een refresh.
Location:
Dev/trunk
Files:
1 added
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/classes/SessionConnector.php

    r151 r152  
    6060                $uid = ""; $title = ""; $datetime = ""; $applications = ""; $surveys = ""; $answersets = "";
    6161                if(in_array("uid", $keys))
    62                         $uid = 'predicates:uid \''.$arguements["uid"].'\' ';
     62                        $uid = 'predicates:uid \''.$arguments["uid"].'\' ';
    6363                if(in_array("title", $keys))
    6464                        $title = 'predicates:title \''.$arguments["title"].'\' ';
  • Dev/trunk/classes/pipelineSequencer.php

    r151 r152  
    1313
    1414    // properties
    15     private $pipeline;      // array of UID strings.
    16     private $name = "empty";
    17     private $numStepsInArray = 0;
    18     private $maxNumStepsInArray = 10;
     15    private $loadedSession;
    1916    private $selectedStep;
    2017
    21     public function __construct($uid) {
    22         $dbi = new DatabaseInterface();
    23         $this->pipeline = $dbi->get("pipeline", array("uid" => $uid));
     18    public function __construct() {
     19        //nothing yet
    2420    }
    2521
     
    2824        <br /><form name="sequencer" action="pipelineEditor.php" method="post">
    2925            <fieldset id="sequencer">
    30                 <div class="title">Name: <?php echo $this->pipeline->name; ?> </div>
     26                <div class="title">Name: <?php echo $this->loadedSession->title; ?> </div>
    3127
    3228                <div id="seqContent">
     
    5652    private function Javascript() {
    5753        ?>
    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 
     54        <script type="text/javascript" src="js/sequencerScripts.js"></script>
    12255
    12356        <?php
    12457    }
    12558
    126     public function GetDromDB() {   // Initialize variables on page load.
     59    public function GetFromDB($currentSession) {   // Initialize variables on page load.
    12760        $dbi = new DatabaseInterface();
    128         if (isset($_POST['currentSession'])) {
    129             $currentSession = $dbi->get("Session", array("UID" => $uid));
    130             $this->pipeline = $currentSession->pipeline;
     61        if (!isset($currentSession)) {
     62            $_SESSION['message'] = "No session set!";
     63            redirect("selectSession.php");
     64        }
     65       
     66        $sessionResults = $dbi->get("Session", array("uid" => $currentSession));
     67        if (count($sessionResults) > 0) {
     68            $this->loadedSession = $sessionResults[0];
     69        }
     70        else {
     71            die("Invalid session!");
    13172        }
    13273    }
  • Dev/trunk/index.php

    r151 r152  
    5656
    5757if (isset($_SESSION['username'])) {
    58     redirect('pipelineEditor.php');
     58    redirect('selectSession.php');
    5959}
    6060?>
  • Dev/trunk/js/sequencerScripts.js

    r150 r152  
    2929}
    3030
    31 
    32 
    33 /*
    34  * Selection code
    35  *
    36  */
    37 
    38 function checkSelectedStep(number){
    39     document.sequencer.selectedStep.value = number;
    40     var step = document.getElementById("seqContent")
    41     document.refresh();
    42 }
    43 
    44 function highlightSelectedStep() {
    45    
    46 }
    47 
    48 
    49 
    50 
    51 
    52 
    53 
    54 
    55 
    56 
    5731// Class manipulation
    5832
    5933function hasClass(ele,cls) {
    60         return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
     34    return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
    6135}
    6236 
    6337function addClass(ele,cls) {
    64         if (!this.hasClass(ele,cls)) ele.className += " "+cls;
     38    if (!this.hasClass(ele,cls)) ele.className += " "+cls;
    6539}
    6640 
    6741function removeClass(ele,cls) {
    68         if (hasClass(ele,cls)) {
    69         var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
    70                 ele.className=ele.className.replace(reg,' ');
    71         }
     42    if (hasClass(ele,cls)) {
     43        var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
     44        ele.className=ele.className.replace(reg,' ');
     45    }
    7246}
    7347
     48//new scripts!
     49//start here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     50
     51function selectStep(uid) {
     52    document.getElementById(uid).addClass("selected");
     53    document.sequencer.controls.selectedStep.value = uid;
     54}
     55                                                                           
     56                                                                           
     57/*
     58 * ajaxStepRequest gets  the markup for displaying a step in the sequencer from returnStep.php
     59 * Using ajax principle allows for editing of pipeline without constantly refreshing the page.
     60 */
     61
     62function ajaxStepRequest(UID) {
     63    var c = "uid="+UID;
     64    var u = "returnStep.php";
     65    newAjaxRequest(c, u, function(result) {
     66        var newDiv = result.responseText;
     67        document.getElementById("seqContent").appendChild(newDiv);
     68    });
     69}
     70
     71function ajaxInfoRequest(id, el) {
     72    var uid = id;
     73    var c = "uid="+uid;
     74    var u = "getInfo.php";
     75    newAjaxRequest(c, u, function(result) {
     76        el.innerHTML = result.responseText;
     77    });
     78}
     79
     80/*
     81 * This function allows for simple use of AJAX requests.
     82 * Calling format:
     83 *
     84 * var c[] = "uid=123";
     85 *  var c[] = "name=tschipper";
     86 *  var u = "getResult.php";
     87 *  newAjaxRequest(c, u, function(xml) {
     88 *      <!--Do something-->
     89 *  });
     90 * 
     91 *  It is of course also possible to refer to an external function instead of
     92 *  defining function(xml){} in the call itself, as below:
     93 * 
     94 *  newAjaxRequest(c, u, externalFunction(xml));
     95 */
     96
     97function newAjaxRequest(c, u, cb) {
     98   
     99    var xml;
     100    var content = c;    //an array of strings, in "key=value"  format.
     101    // assign a compatible request format
     102    if (window.XMLHttpRequest) {    //Not IE5, IE6
     103        xml = new XMLHttpRequest();
     104    }
     105    else {                          //IE5, IE6
     106        xml = new ActiveXObject("Microsoft.XMLHTTP");
     107    }
     108    // subscribe the callback function to a response event
     109    xml.onreadystatechange = function() {
     110        if (xml.readyState == 4 && xml.status == 200) {
     111            //alert("Received!");
     112            cb(xml);
     113        }
     114    };
     115    // initialize XMLRequest
     116    xml.open("POST", u, true);
     117    xml.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
     118    var contentString = "";
     119    //iterate through parameters passed in variable c
     120    if (typeof(content)=='object'&&(input instanceof Array)) {    // parameters were passed as an array of key=value strings
     121        for (var i = 0; i < content.length; i++) {
     122            contentString += content[i];
     123            if (i != (content.length - 1)) {
     124                contentString += "&";
     125            }
     126        }
     127    }
     128    else {                      // single parameter or string already formatted by calling function
     129        contentString = content;
     130    }
     131    // finally send the formatted request
     132    //alert(contentString);
     133    xml.send(contentString);
     134}
     135                           
     136
     137function drawSteps() {
     138    var sequencer = document.getElementById("sequencer");
     139    var seqContent = document.getElementById("seqContent");
     140               
     141    // first delete all current children of seqContent (to reset the sequencer).
     142    while (seqContent.childNodes.length > 0) {
     143        var step = seqContent.childNodes[0];
     144        step.parentNode.removeChild(step);
     145    }
     146               
     147    // get pipeline contents from hidden form inputs.
     148    var pipeline = sequencer.controls.pipeline.value;
     149    var pipeline = pipeline.split(", ");
     150               
     151    // then do an xmlhttp request for each step to be added to the sequencer
     152    var numberOfSteps = pipeline.length;
     153    for (var i = 0; i > numberOfSteps; i++) {
     154        ajaxStepRequest(pipeline[i]);
     155    }
     156               
     157}
     158
  • Dev/trunk/logout.php

    r151 r152  
    66require 'classes/master.php';
    77
    8 unset($_SESSION['username']);
     8session_destroy();
    99redirect("index.php");
    1010?>
  • Dev/trunk/pipelineEditor.php

    r151 r152  
    33
    44if (!isset($_SESSION['username'])) {
     5    $_SESSION['message'] = "You were redirected here because your session timed out or you used an invalid link.";
    56    redirect('index.php');
    67}
    78
    8 $dbtemp = new DatabaseInterface();
    9 
    10 
    11 if (!isset($_SESSION['currentSession'])) {
    12     redirect('selectSession.php');
    13 }
    14 
    15 $dbi = new DatabaseInterface();
    16 $sessions = $dbi->get("session", array("user"=>$_SESSION['username']));
    17 
    18 
    19 
    20 
    21 
    22 if (isset($_SESSION['currentPipeline'])) {
    23     $sequencer = new PipelineSequencer($_SESSION['currentPipeline'], "Test Pipeline #1", 1);
    24 } else {
    25     $sequencer = new PipelineSequencer(null, "Test Pipeline #1", 1);
    26 }
    27 
    28 $sequencer->HandlePost();    // doesn't actually currently get from db, uses session/post as a temporary alternative.
     9$sequencer = new PipelineSequencer();
     10$sequencer->GetFromDB($_SESSION['currentSession']);
    2911?>
    3012
     
    3921        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    4022        <title></title>
    41 <?php new StyleSheet("awesome"); ?>
     23        <?php new StyleSheet("awesome"); ?>
    4224        <script type="text/javascript" src="js/menu.js"></script>
    4325        <script type="text/javascript" src="js/jquery.jps"></script>
     
    4628    <body>
    4729        <div id="header">
    48 <?php new Logo(); ?>
     30            <?php new Logo(); ?>
    4931        </div>
    5032
    5133        <div id="wrapper">
    5234            <div id="content">
    53 <?php $sequencer->init(); ?>
    54 <?php $toolbox = new Toolbox(); ?>
     35                <?php $sequencer->init(); ?>
     36                <?php $toolbox = new Toolbox(); ?>
    5537            </div>
    5638    </body>
  • Dev/trunk/selectSession.php

    r151 r152  
    55    redirect("index.php");
    66}
     7
     8if (isset($_SESSION['message'])) {
     9    echo $_SESSION['message'];
     10    unset($_SESSION['message']);
     11}
     12
    713$dbi = new DatabaseInterface();
     14
    815if (isset($_POST['createSession'])) {
    916    //check if name is set
     
    1118        // check if name is available
    1219        if (!empty($_POST['newSessionName'])) {
    13             $matchingNames = $dbi->get("Session", array("title" => $_POST['newSessionName']));
    14             if (count($matchingNames) == 0) {
     20            $matching = $dbi->get("Session", array("title" => $_POST['newSessionName']));
     21            if (count($matching) == 0) {
    1522                // make new session!
     23                unset($matching);
    1624                $session = new Session(null, $_POST['newSessionName'], null, null, null);
    1725                $dbi->set($session);
     
    2533}
    2634
     35if (isset($_POST['deleteSession'])) {
     36    if (isset($_POST['sessionUID'])) {
     37        //Kan de database al objecten verwijderen?
     38    }
     39}
     40
     41if (isset($_POST['editSession'])) {
     42    if (isset($_POST['sessionUID'])) {
     43        $matching = $dbi->get("SESSION", array("uid" => $_POST['sessionUID']));
     44        if (count($matching) == 1 && $matching[0] != null) {
     45            $_SESSION['currentSession'] = $_POST['sessionUID'];
     46            redirect("pipelineEditor.php");
     47        }
     48    }
     49}
     50
    2751//Get available sessions for current user
    28 //$sessions = $dbi->get("Session", array("creator"=>$_SESSION['username']));  //Dit werkt niet, SessionConnector/Session.php hebben nog geen creator property
    29 $sessions = $dbi->get("Session", array());  // In plaats daarvan maar gewoon alles laden dan... lol
    30 var_dump($sessions);
     52//$sessions = $dbi->get("Session", array("creator"=>$_SESSION['username']));  //This does not work, session.php does not yet have a property 'creator'
     53$sessions = $dbi->get("Session", array());  // Let's just load everything then...
     54//var_dump($sessions);
    3155?>
    3256
     
    3761        <title>Select a session</title>
    3862        <?php new StyleSheet("awesome"); ?>
     63        <script type="text/javascript" src="js/sequencerScripts.js"></script>
    3964    </head>
    4065    <body>
    4166        <form action="selectSession.php" method="POST">
    4267            <fieldset name="selectionMenu">
    43                 <select name="sessionName" style="float: left;">
     68                <!-- onchange van volgende select linkt deze aan de ajax-based info panel, script staat in sequencerScripts.js -->
     69                <select name="sessionUID" style="float: left;" onChange="ajaxInfoRequest(this.value, document.getElementById('sessionDescription'));">
    4470                    <?php
    4571                    foreach ($sessions as $session) {
    46                         echo '<option value="' . $session->uid . '">' . $session->title . '</option>';
     72                        echo '<option value="' . $session->uid . '">' . $session->title . '</option>' . "\n";
    4773                    }
    4874                    ?>                   
     
    6389            </fieldset>
    6490            <fieldset id="sessionDescription">
    65 
     91                Info goes here:
    6692            </fieldset>
    6793        </form>
Note: See TracChangeset for help on using the changeset viewer.