Index: /Dev/trunk/classes/pipelineSequencer.php
===================================================================
--- /Dev/trunk/classes/pipelineSequencer.php	(revision 165)
+++ /Dev/trunk/classes/pipelineSequencer.php	(revision 166)
@@ -1,4 +1,3 @@
 <?php
-
 /*
  * To change this template, choose Tools | Templates
@@ -27,17 +26,12 @@
         $stringPipelineUpdated = "";
         $numberOfSteps = 0;
-        
+
         if (is_array($this->loadedSession->pipeline)) {
             foreach ($this->loadedSession->pipeline as $object) {
                 $stringPipeline .= "$object->uid,";
-                $stringPipelineType .= get_class($object).",";
+                $stringPipelineType .= get_class($object) . ",";
                 $stringPipelineUpdated .= "1,";
                 $numberOfSteps++;
-                
             }
-            $stringPipeline = rtrim($stringPipeline, ",");
-            $stringPipelineType = rtrim($stringPipelineType, ",");
-            $stringPipelineUpdated = rtrim($stringPipelineUpdated, ",");
-            
         } else {
             $stringPipeline = $this->loadedSession->pipeline;
@@ -69,4 +63,5 @@
                     <input type="hidden" name="pipelineUpDated" id="pipelineUpdatedField" value="<?php echo $stringPipelineUpdated; ?>" />
                     <input type="hidden" name="numSteps" id="numSteps" value="<?php echo $numberOfSteps; ?>" />
+                    <input type="hidden" name="session" id="sessionField" value="<?php echo $this->loadedSession->uid; ?>" />
                 </div>
             </fieldset>
@@ -108,5 +103,5 @@
         if (isset($_SESSION['updateNeeded'])) {    // user has performed an operation that flags session to be reloaded from DB, or is first load of page for that session
             $sessionResults = $this->dbi->get("Session", array("uid" => $currentSession));
-            
+
             if (count($sessionResults) > 0) {
                 $_SESSION['localSessionCopy'] = $sessionResults[0];
@@ -116,12 +111,10 @@
             }
         }
-            //var_dump($_SESSION['localSessionCopy']);   
-        
+
         if (isset($_SESSION['localSessionCopy']) && !empty($_SESSION['localSessionCopy'])) {
-            
+
             $this->loadedSession = $_SESSION['localSessionCopy'];
             unset($_SESSION['updateNeeded']);
         }
-        
     }
 
@@ -180,5 +173,4 @@
     }
 
-
 }
 ?>
Index: /Dev/trunk/createObject.php
===================================================================
--- /Dev/trunk/createObject.php	(revision 165)
+++ /Dev/trunk/createObject.php	(revision 166)
@@ -8,9 +8,9 @@
     }
     else {
-        die ("Invalid arguments passed!");
+        //die ("Invalid arguments passed!");
     }
 }
 else {
-    die ("No arguments passed!");
+    //die ("No arguments passed!");
 }
 
@@ -21,5 +21,5 @@
 }
 else {
-    die ("Invalid creator, make sure you are logged in!");
+    //die ("Invalid creator, make sur0e you are logged in!");
 }
 
@@ -40,5 +40,5 @@
         break;
     default:
-        die ("Variable \$otc: $otc does not match a compatible object type!");
+        //die ("Variable \$otc: $otc does not match a compatible object type!");
         break;
 }
Index: /Dev/trunk/js/sequencerScripts.js
===================================================================
--- /Dev/trunk/js/sequencerScripts.js	(revision 165)
+++ /Dev/trunk/js/sequencerScripts.js	(revision 166)
@@ -25,9 +25,8 @@
 }
 
-/*
-function SubmitToolbox() {
-    document.forms['toolbox'].submit();
-}
-*/
+function removeNL(s){ 
+    return s.replace(/[\n\r\t]/g,""); 
+}
+
 function SubmitToolbox(type) {
     var c = "objectToCreate="+type;
@@ -39,11 +38,10 @@
     
     newAjaxRequest(c, u, function(result){
-        var resultUid = result.responseText;
-        console.log(resultUid);
-        console.log("lol");
-        console.log(resultUid);
-        pipeline.value += ","+resultUid;
-        pipelineType += ","+type;
-        pipelineUpdated += ",0";
+        var resultUid = removeNL(result.responseText);
+        //resultUid.replace("\n","").replace("\r","");
+        
+        pipeline.value += resultUid+",";
+        pipelineType.value += type+",";
+        pipelineUpdated.value += "0,";
         updateSequencer();
     }, a);
@@ -74,5 +72,4 @@
     var nodes = document.getElementById("seqContent").childNodes;
     for (var i = 0; i < nodes.length; i++) {     //loop through childNodes. Skip first node (whitespace)
-        //debugger;
         if (hasClass(nodes[i], "displayStep")) {    //check if current childNode is a displayStep, not divider or text.
             if (nodes[i].id == uid) {
@@ -96,22 +93,4 @@
 }
                                                                             
-                                                                            
-/*
- * This function allows for simple use of AJAX requests.
- * Calling format:
- * 
- * var c[] = "uid=123";
- *  var c[] = "name=tschipper";
- *  var u = "getResult.php";
- *  newAjaxRequest(c, u, function(xml) {
- *      <!--Do something-->
- *  });
- *  
- *  It is of course also possible to refer to an external function instead of 
- *  defining function(xml){} in the call itself, as below:
- *  
- *  newAjaxRequest(c, u, externalFunction(xml));
- */
-
 function newAjaxRequest(c, u, cb, async) {
     
@@ -145,9 +124,8 @@
         }
     }
-    else {                      // single parameter or string already formatted by calling function
+    else { // single parameter or string already formatted by calling function
         contentString = content;
     }
     // finally send the formatted request
-    //alert(contentString);
     xml.send(contentString);
 }
@@ -183,7 +161,10 @@
     var pipeline = document.getElementById("pipelineStringField").value;
     var pipelineTypes = document.getElementById("pipelineTypeField").value;
-    pipeline = pipeline.replace(/,/g , ",divider,");    //regex search for commas, global (repeat), to represent them with visual dividers.
-    pipelineTypes = pipelineTypes.replace(/,/g, ",divider,");
-    ajaxStepRequest(pipeline, pipelineTypes);
+    var numSteps = document.getElementById("numSteps").value;
+    if (numSteps > 0) {
+        pipeline = pipeline.replace(/,/g , ",divider,");    //regex search for commas, global (repeat), to represent them with visual dividers.
+        pipelineTypes = pipelineTypes.replace(/,/g, ",divider,");
+        ajaxStepRequest(pipeline, pipelineTypes);
+    }
 }
 
@@ -192,10 +173,13 @@
     var plTypeString = document.getElementById("pipelineTypeField").value;
     var plUpdatedString = document.getElementById("pipelineUpdatedField").value;
-        
-    var pl = plString.split(",");
-    var plType = plTypeString.split(",");
-    var plUpdated = plUpdatedString.split(",");
-    //console.log(plUpdated);
-    
+    
+    
+    var pl = stringToArray(plString, ",");    
+    var plType = stringToArray(plTypeString, ",");    
+    var plUpdated = stringToArray(plUpdatedString, ",");
+    
+    var count = pl.length;
+    
+    document.getElementById("numSteps").value = count;
     
     for (var i = 0; i < pl.length; i++) {   // loop through pipeline contents
@@ -204,52 +188,117 @@
             var seqContent = document.getElementById("seqContent");
             var element = document.getElementById(pl[i]);
-            var nextElement = element.nextSibling;
+            if (element == null) {
+                element = document.createElement("div");
+                element.name = "placeholder";
+                seqContent.appendChild(element);
+            }
+            if (element.nextSibling) {
+                var nextElement = element.nextSibling;
+            }
+            else {
+                var nextElement = document.createElement("div");
+                nextElement.name = "placeholderNext";
+                seqContent.appendChild(nextElement);
+            }
             
             // now request a new step representation and insert it after previousElement
             var holderDiv = document.createElement("div");
             var requestString = "uids="+pl[i];
-            var resultText;
+            
+            if (plType[i]) {
+                requestString += "&types="+plType[i];
+            }
+            // globally declare newDiv so it can be passed to the updateDividers function
+            var newDiv;
+            
             newAjaxRequest(requestString, "returnStep.php", function(result) {
-                holderDiv.innerHTML = result.responseText; 
+                holderDiv.innerHTML = result.responseText;
+                newDiv = holderDiv.childNodes[1];            
+                seqContent.replaceChild(newDiv, element);
+                if (nextElement.name == "placeholderNext") {
+                    seqContent.removeChild(nextElement);
+                }
+                plUpdated[i] = "1";
             }, false);
             
-            //debugger;
-            while (holderDiv.childNodes.length == 1) {
-            // wait for response
-            }
-            var newDiv = holderDiv.childNodes[1];
-            seqContent.replaceChild(newDiv, element);
-            plUpdated[i] = "1";
-        // ALTERNATIVE METHOD TO REPLACECHILD!!!
-        //seqContent.removeChild(element);
-        //seqContent.insertBefore(newDiv, nextElement);
-            
-            
-        }
-        else {
-            
-    }
-    }
-    
-    // afterwards, convert the arrays back to strings
-    var newUpdatedString = "";
-    
-    for (var i = 0; i < plUpdated.length; i++) {
-        newUpdatedString += plUpdated[i]+",";
-    }
-    
-    if (newUpdatedString.substring(newUpdatedString.length - 1) == ",") {   // remove comma at the end of string!
-        newUpdatedString = newUpdatedString.substring(0, newUpdatedString.length-1);
-        
-    }
+                       
+            // ALTERNATIVE METHOD TO REPLACECHILD!!!
+            //seqContent.removeChild(element);
+            //seqContent.insertBefore(newDiv, nextElement);
+            
+            // Now check if dividers are necessary.
+            
+            //alert("INSERT CODE FOR UPDATEDIVIDERS HERE!");
+            updateDividers(newDiv);
+        }
+    }
+    
+    // afterwards, convert the arrays back to strings and set to appropriate fields
+    var newUpdatedString = arrayToString(plUpdated, ",");
     document.getElementById("pipelineUpdatedField").value = newUpdatedString;
     
 }
+
+
+
+
+
+
+function updateDividers (element) {
+    var seqContent = document.getElementById("seqContent");
+    
+    if (element.nextSibling){
+        var nextElement = element.nextSibling;
+    }
+    if (element.previousSibling) {
+        var previousElement = element.previousSibling;
+    }
+    
+    if (nextElement){
+        if (!hasClass(nextElement, "divider")) {
+            var holderDiv = document.createElement("div");
+            newAjaxRequest("uids=divider&types=divider", "returnStep.php", function(result) {
+                holderDiv.innerHTML = result.responseText;
+                var newDivider = holderDiv.childNodes[1];
+                seqContent.insertBefore(newDivider, nextElement);
+            }, false);
+        }
+    }
+    
+    if (previousElement){
+        if (!hasClass(previousElement, "divider")) {
+            var holderDiv = document.createElement("div");
+            newAjaxRequest("uids=divider&types=divider", "returnStep.php", function(result) {
+                holderDiv.innerHTML = result.responseText;
+                var newDivider = holderDiv.childNodes[1];
+                seqContent.insertBefore(newDivider, element);
+            }, false);
+        }
+    }
+    
+}
+
+
+
+
+
 
 function savePipeline() {
     var answer = confirm("Save changes to pipeline?");
     if (answer) {
-        newAjaxRequest("", "savesession.php", function(){}, false);
-        alert("Saved!");
+        var pipeline = document.getElementById("pipelineStringField").value;
+        pipeline = pipeline.slice(0, pipeline.length - 1);
+        var types = document.getElementById("pipelineTypeField").value;
+        types = types.slice(0, types.length - 1);
+        var session = document.getElementById("sessionField").value;
+        var requestString = "uids="+pipeline+"&types="+types+"&sessionUid="+session;
+        //console.log(requestString);
+        
+        
+        var success;
+        newAjaxRequest(requestString, "savesession.php", function(result){
+            success = result.responseText;
+        }, false);
+        console.log(success);
     }
 }
@@ -268,29 +317,35 @@
     var plUpdatedString = document.getElementById("pipelineUpdatedField").value;
     
-    var pl = plString.split(",");
-    var plType = plTypeString.split(",");
-    var plUpdated = plUpdatedString.split(",");
-    
-    
+    
+    var pl = stringToArray(plString, ",");    
+    var plType = stringToArray(plTypeString, ",");    
+    var plUpdated = stringToArray(plUpdatedString, ",");    
     
     // set the targeted element's tag for "Needs updating"
-    for (var i = 0; i < pl.length; i++) {
-        if (pl[i] == uid) {
-            plUpdated[i] = 0;
-        }
-    }
+    plUpdated[pl.indexOf(uid)] = "0";
     
     // then rewrite the content strings and set them to the appropriate fields
-    
-    var newUpdatedString = "";
-    for (var i = 0; i < pl.length; i++) {
-        newUpdatedString += plUpdated[i]+",";
-    }
-    if (newUpdatedString.substring(newUpdatedString.length-1) == ",") {
-        newUpdatedString = newUpdatedString.substring(0, newUpdatedString.length-1);
-    }
-    
-    
+    var newUpdatedString = arrayToString(plUpdated, ",");
     document.getElementById("pipelineUpdatedField").value = newUpdatedString;
-//alert("OOD set");
-}
+}
+
+function stringToArray(s, c) {
+    var a = s.split(c);
+    for (var i = 0; i < a.length; i++) {    // remove empty items
+        if (a[i] == "") {
+            a.splice(i, 1);
+            i--;
+        }
+    }
+    return a;
+}
+
+function arrayToString(a, c) {
+    var s = "";
+    for (var i = 0; i < a.length; i++) {
+        if (a[i] != "") {
+            s += a[i]+c;
+        }
+    }
+    return s;
+}
Index: /Dev/trunk/savesession.php
===================================================================
--- /Dev/trunk/savesession.php	(revision 165)
+++ /Dev/trunk/savesession.php	(revision 166)
@@ -3,8 +3,37 @@
 require 'classes/master.php'; //should be at top of every page
 
-$session = $_SESSION['localSessionCopy'];
-$dbi = new DatabaseInterface();
-$dbi->set($session);
+if (isset($_POST['uids']) && isset($_POST['types']) && isset($_POST['sessionUid'])) {
+    if (!empty($_POST['uids']) && !empty($_POST['types']) && !empty($_POST['sessionUid'])) {
+        // user has passed a pipeline/type string from javascript in order to save the session.
+        $pl = explode(",", $_POST['uids']);
+        $t = explode(",", $_POST['types']);
 
-redirect('pipelineEditor.php');
+        $sessionUid = $_POST['sessionUid'];
+        //var_dump($t);
+        $dbi = new DatabaseInterface();
+        $session_results = $dbi->get("Session", array("uid" => $sessionUid));
+        if (count($session_results) > 0) {
+            $session = $session_results[0];
+        } else {
+            echo "!!!!!!!!!!!!!!!!!!!!!!NO SESSION FOUND!!!!!!!!!!!!!!!!!!!!";
+            die();
+        }
+        if (count($pl) == count($t)) {
+            $count = count($pl);
+        } else {
+            echo "!!!!!!!!!!!!!!!!!NON MATCHING ARGUMENTS PASSED!!!!!!!!!!!!!!!";
+            die();
+        }
+        for ($i = 0; $i < count($pl); $i++) {
+            $results = $dbi->get($t[$i], array("uid" => $pl[$i]));
+            if (count($results) > 0) {
+                $result = $results[0];
+            }
+            $session->pipeline[] = $result;
+        }
+
+        $dbi->set($session);
+        echo "true";
+    }
+}
 ?>
Index: /Dev/trunk/selectSession.php
===================================================================
--- /Dev/trunk/selectSession.php	(revision 165)
+++ /Dev/trunk/selectSession.php	(revision 166)
@@ -22,5 +22,7 @@
                 // make new session!
                 unset($matching);
-                $session = new Session(null, $_POST['newSessionName'], $_SESSION['username'], new DateTime(), null, null);
+                $creators = $dbi->get("User", array("username"=>$_SESSION['username']));
+                $creator = $creators[0];
+                $session = new Session(null, $_POST['newSessionName'], $creator, new DateTime(), null, null);
                 $dbi->set($session);
             } else {
