Changeset 151


Ignore:
Timestamp:
11/08/11 17:02:55 (13 years ago)
Author:
fpvanagthoven
Message:
 
Location:
Dev/trunk
Files:
4 added
5 edited

Legend:

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

    r142 r151  
    1515    // hardcoded logo div, image is defined in stylesheet. (#logo background:"";)
    1616    public function __construct() {
    17         echo '
    18             <div id="logo"><a href="index.php">Research Tool</a></div>
    19 ';
     17        echo '<div id="logo"><a href="index.php">Research Tool</a>';
     18        if (isset($_SESSION['username'])) {
     19            echo '<a href="logout.php" style="font-size: 12pt;">Log out</a>';
     20        }
     21        echo '</div>';
    2022   
    2123    }
  • Dev/trunk/classes/SessionConnector.php

    r149 r151  
    186186                $this->model->add(new Statement($resourceSession, $predicateTitle, $sessionTitle));
    187187
    188                 $sessionTimestamp = new Literal($rToolObject->datetime->getTimestamp());
    189                 $predicateTimestamp = new Resource(DATETIME);
     188                //$sessionTimestamp = new Literal($rToolObject->datetime->getTimestamp());
     189                $sessionTimestamp = new Literal($rToolObject->datetime);    // Edit of above function, allows for creation of session, but still results in errors...
     190                $predicateTimestamp = new Resource(DATETIME);
    190191                $this->model->add(new Statement($resourceSession, $predicateTimestamp, $sessionTimestamp));
    191192
  • Dev/trunk/classes/pipelineSequencer.php

    r150 r151  
    66
    77/**
    8  * Description of Sequencer
     8 * A visual interface object for editing and viewing a session's pipeline.
    99 *
    10  * @author HP
     10 * @author Tschipper
    1111 */
    1212class PipelineSequencer {
    1313
    1414    // properties
    15     private $pipeline;
     15    private $pipeline;      // array of UID strings.
    1616    private $name = "empty";
    1717    private $numStepsInArray = 0;
     
    2121    public function __construct($uid) {
    2222        $dbi = new DatabaseInterface();
    23         $this->pipeline = $dbi->get("pipeline", array("uid"=>$uid));
     23        $this->pipeline = $dbi->get("pipeline", array("uid" => $uid));
    2424    }
    2525
    2626    public function init() {
    2727        ?>
    28         <br /><form name="sequencer" action="pipelineEditor.php" method="post"><fieldset id="sequencer">
     28        <br /><form name="sequencer" action="pipelineEditor.php" method="post">
     29            <fieldset id="sequencer">
    2930                <div class="title">Name: <?php echo $this->pipeline->name; ?> </div>
    3031
    31                 <div class="seqContent">
     32                <div id="seqContent">
    3233                    <?php $this->DrawSteps(); ?>         
    3334                </div>
     
    4142                    <input type="checkbox" name="confirmClear" onChange="IsCheckEnabled(this, document.sequencer.clearPipeline);" />Really clear?
    4243                    <input type="hidden" name="selectedStep" />
     44                    <input type="hidden" name="numSteps" />
     45                    <input type="hidden" name="pipeline" />
    4346                </div>
    4447            </fieldset>
     
    4750    }
    4851
    49     public function AddStep($newStep) {
    50         $n = 1;
    51         foreach ($this->pipeline as $existingStep) {
    52             if ($existingStep->name == $newStep . " $n") {
    53                 $n++;
    54             }
    55         }
    56 
    57         $this->pipeline[] = new Step($newStep, $newStep . " " . $n, count($this->pipeline) + 1);
    58         //var_dump($this->pipeline);
    59         ?>
    60         <script type="text/javascript">
    61             document.refresh();
    62         </script>
    63         <?php
    64     }
    65 
    66     public function RemoveStep($targetStep) {
    67 
    68         $tempArray = array();
    69         $removed = false;
    70         foreach ($this->pipeline as $step) {
    71             if ($step->id != $targetStep) {
    72                 $tempArray[] = $step;
    73                 if ($removed) {
    74                     $step::AdjustID(-1);
    75                 }
    76             } else {
    77                 $removed = true;
    78             }
    79         }
    80         $this->pipeline = $tempArray;
    81     }
    82 
    83     public function GetPipeline() {
    84         return $this->pipeline;
    85     }
    86 
    8752    public function DrawSteps() {
    88         //draw the actual icons in the container div.
    89         if (!empty($this->pipeline)) {
    90             foreach ($this->pipeline as $step) {
    91                 if ($this->numStepsInArray < $this->maxNumStepsInArray) {
    92                     //var_dump($step);
    93                     $step->init();
    94                     $this->numStepsInArray++;
    95                     if ($this->numStepsInArray < $this->maxNumStepsInArray && $this->numStepsInArray < count($this->pipeline)) {
    96                         echo "<div class='divider'></div>";
    97                     }
    98                 }
    99             }
    100         }
    101     }
    102 
    103     public function MoveStep($direction) {
    104         $key = array_search($this->selectedStep, $this->pipeline);
    105         //echo $key;
    106     }
    107 
    108     private function MoveEntry(&$array, $key, $dir) {
    109         if ($dir == -1) {   // move up
    110             if ($key > 0) {
    111                 $reverseArray = array_reverse(array_slice($array, $key - 1, 2, true));   // make a reversed array of the two entries, preserving keys
    112                 array_splice($array, $key - 1, 2, $reverseArray);    // replace the given range in the oldArray with the reversed Array
    113             }
    114         } else if ($dir == 1) {   // move down
    115             if ($key < count($array) - 1) {
    116                 $reverseArray = array_reverse(array_slice($array, $key, 2, true));   // make a reversed array of the two entries, preserving keys
    117                 array_splice($array, $key, 2, $reverseArray);    // replace the given range in the oldArray with the reversed Array
    118             }
    119         }
    120     }
    121 
    122     public function SetSelected($key) {
    123 
    124         if ($key > 0 && $key < count($this->pipeline)) {
    125             $this->selectedStep = $key;
    126         }
    127     }
    128 
    129     public function GetName($name) {
    130         if ($name && $name != "") {
    131             $this->name = $name;
    132         }
    133     }
    134 
    135     public function HandlePost() {
    136 
    137         //this doesn't actually work, the sequencer doesn't know what the uid is yet. This data should be POSTed upon refresh!
    13853       
    139        
    140        
    141         if (isset($_POST['destroy'])) {
    142             unset($_POST['destroy']);
    143             unset($_SESSION['currentPipeline']);
    144         }
    145 
    146         if (isset($_POST['clearPipeline'])) {
    147             $this->pipeline = array();
    148             $_SESSION['currentPipeline'] = $this->pipeline;
    149         }
    150 
    151         if (isset($_SESSION['currentPipeline']) && !empty($_SESSION['currentPipeline'])) {      // take pipeline from session data
    152             $this->pipeline = $_SESSION['currentPipeline'];
    153         } else {
    154             $pipeline = array();
    155         }
    156 
    157         if (isset($_POST['objectToCreate'])) {      // user clicked a button in the toolbox.
    158             //$this->pipeline[] = new Step($_POST['objectToCreate'], $_POST['objectToCreate'] . " NEW", null);
    159             $this::AddStep($_POST['objectToCreate']);
    160         }
    161 
    162         if (isset($_POST['deleteSelected'])) {
    163             if (isset($_POST['selectedStep'])) {
    164                 $this->RemoveStep($_POST['selectedStep']);
    165             }
    166         }
    167 
    168         //var_dump($_POST);
    169 
    170         if (isset($_POST['selectedStep'])) {
    171             $this::SetSelected($_POST['selectedStep']);
    172         }
    173 
    174         $_SESSION['currentPipeline'] = $this->pipeline;
    17554    }
    17655
     
    18059        Add JS code for selecting steps, highlighting them, reordering, etc.
    18160        Is a refresh of the page (with subsequent querying of database really necessary?
    182        
     61
    18362        -->
    18463        <script type="text/javascript">
    185             function selectStep(step) {
    186                 step.addClass("selected");
    187                 document.sequencer.controls.selectedStep.value = step.name;
     64            function selectStep(uid) {
     65                document.getElementById(uid).addClass("selected");
     66                document.sequencer.controls.selectedStep.value = uid;
    18867            }
     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                                               
    189120        </script>
    190121
     
    193124    }
    194125
     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
    195134}
    196135?>
  • Dev/trunk/index.php

    r142 r151  
    22require 'classes/master.php'; //should be at top of every page
    33
     4/*  Page still has ambiguous design. Login and Register buttons are at same hierarchy level, makes user suspect the register button works based on input given here.
     5 *  Instead redirects to anoter page.
     6 *   
     7 */
     8
     9//Even voor tijdelijk, aangezien er nog pagina's missen en redirects daarom niet goed werken:
     10if (isset($_SESSION['username'])) {
     11    redirect("logout.php");
     12}
     13
     14$errorMessage[] = "";
     15
    416if (isset($_POST['register'])) {
    517    if ($_POST['username'] != null && $_POST['password'] != null) {
    6         $userDBI = new UserDatabaseInterface();
    7         $user_exists = $userDBI->checkUserName($_POST['username']);
     18        $dbi = new DatabaseInterface();
     19        $user_results = $dbi->get("user", array("name" => $_POST['username']));
     20        $user_exists = (count($user_results) > 0);
    821        if (!$user_exists) {
    9             $userDBI->addNewUser($_POST);
     22            if (strlen($_POST['password']) > 6) {
     23                $user = new User(null, $_POST['username'], $_POST['password']);
     24                $dbi->set($user);
     25                $_SESSION['username'] = $_POST['username'];
     26            } else {
     27                $errorMessage[] = "Password is too short!";
     28                //echo "Password is too short!";
     29            }
    1030        }
    1131        else
    12             echo "Username already exists, try something else";
     32            $errorMessage[] = "Username already exists, try something else!";
     33        //echo "Username already exists, try something else";
    1334    }
    1435    else
    15         echo "please fill in a username and password";
     36        $errorMessage[] = "Please fill in a username and password";
     37    //echo "please fill in a username and password";
    1638}
    1739
    18 if (isset($_SESSION['username']))
    19     redirect('mainmenu.php');
     40if (isset($_POST['login'])) {
     41    $dbi = new DatabaseInterface();
     42    $user_results = $dbi->get("user", array("name" => $_POST['username']));
     43    if (isset($user_results[0])) {
     44        if ($user_results[0]->password == $_POST['password']) {
     45            $_SESSION['username'] = $user_results[0]->name;
     46            // USER HAS LOGGED IN
     47        } else {
     48            $errorMessage[] = "Incorrect password!";
     49            //echo "Incorrect password!";
     50        }
     51    } else {
     52        $errorMessage[] = "Username doesn't exist!";
     53        //echo "Username doesn't exist!";
     54    }
     55}
     56
     57if (isset($_SESSION['username'])) {
     58    redirect('pipelineEditor.php');
     59}
    2060?>
    2161
     
    2767        <?php new StyleSheet("awesome"); ?>
    2868        <script type="text/javascript" src="js/menu.js"></script>
     69        <script type="text/javascript">
     70       
     71   
     72
     73        </script>
    2974    </head>
    3075    <body>
    3176        <div id="header">
    32 <?php new Logo(); ?>
     77            <?php new Logo(); ?>
    3378        </div>
    3479
     
    3782            <div id="content">
    3883                <div class="menu">
    39                     <form action="mainmenu.php" method="POST">
     84                    <form action="index.php" method="POST">
    4085                        <h3>Username</h3>
    4186                        <input type="text" name="username"><br />
    4287                        <h3>Password</h3>
    43                         <input type="password" name="password"><br/><br/><br/>
     88                        <input type="password" name="password"><br/><br />
     89                        <div id="errorDisplay">
     90                            <?php
     91                            foreach ($errorMessage as $message) {
     92                                echo "<h3 style='color: #FF0000;'>$message</h3>";
     93                            }
     94                            ?>
     95                        </div>
     96                        <br/>
    4497                        <input type="submit" name="login" class="surveyButton bigSurveyButton" value="Log in">
    4598                    </form>
  • Dev/trunk/pipelineEditor.php

    r150 r151  
    22require 'classes/master.php'; //should be at top of every page
    33
    4 /* if (!isset($_SESSION['user'])){
    5   redirect('index.php');
    6   } */
     4if (!isset($_SESSION['username'])) {
     5    redirect('index.php');
     6}
     7
     8$dbtemp = new DatabaseInterface();
     9
     10
     11if (!isset($_SESSION['currentSession'])) {
     12    redirect('selectSession.php');
     13}
     14
     15$dbi = new DatabaseInterface();
     16$sessions = $dbi->get("session", array("user"=>$_SESSION['username']));
     17
     18
    719
    820
     
    1527
    1628$sequencer->HandlePost();    // doesn't actually currently get from db, uses session/post as a temporary alternative.
    17 
    18 
    19 
    2029?>
    2130
     
    4352            <div id="content">
    4453<?php $sequencer->init(); ?>
    45                 <?php $toolbox = new Toolbox(); ?>
     54<?php $toolbox = new Toolbox(); ?>
    4655            </div>
    4756    </body>
Note: See TracChangeset for help on using the changeset viewer.