Changeset 56 for Dev/trunk


Ignore:
Timestamp:
07/26/11 17:19:26 (14 years ago)
Author:
fpvanagthoven
Message:

Stubs and some refactoring

Location:
Dev/trunk
Files:
4 added
1 deleted
3 edited

Legend:

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

    r35 r56  
    11<?php
    2 
    32/*
    43 * To change this template, choose Tools | Templates
     
    1211 */
    1312class Survey {
     13
    1414    public $id;
    1515    public $title;
    1616    public $description;
    1717    public $questions;
    18    
    19     public function __construct($id, $title, $description = null)
    20     {
     18
     19    public function __construct($id, $title, $description = null) {
    2120        $this->id = $id;
    2221        $this->title = $title;
     
    2423        $this->questions = array();
    2524    }
    26    
    27     public static function getSurvey($info)
    28     {
     25
     26    public static function getSurvey($info) {
    2927        $id = $info['surveyID'];
    3028        $title = $info['surveyTitle'];
    3129        $description = $info['surveyDescription'];
    32        
     30
    3331        $survey = new Survey($id, $title, $description);
    34        
     32
    3533        $numQ = 1; //number questions
    36         while (isset($info['questionTitle' . $numQ]))
    37         {
     34        while (isset($info['questionTitle' . $numQ])) {
    3835            $id = $info['questionID' . $numQ];
    3936            $title = $info['questionTitle' . $numQ];
    4037            $type = $info['questionType' . $numQ];
    4138            $description = $info['questionDescription' . $numQ];
    42                    
     39
    4340            $question = new Question($id, $title, $type, $description);
    4441
    4542            $numA = 1; //number answers
    46             while (isset($info['q' . $numQ . 'ans' . $numA]))
    47             {
     43            while (isset($info['q' . $numQ . 'ans' . $numA])) {
    4844                $answer = $info['q' . $numQ . 'ans' . $numA];
    4945                $question->answers[$numA] = $answer;
    50                
     46
    5147                $numA++;
    5248            }
    53            
    54            
     49
     50
    5551            $survey->questions[$numQ] = $question;
    56            
     52
    5753            $numQ++;
    5854        }
    59        
     55
    6056        return $survey;
    6157    }
    62    
     58
     59    public static function newSurveyButton() {
     60        ?>
     61
     62        <form action="surveycreation.php" method="post">
     63
     64            <input type="submit" value="Create new survey" class="surveyButton bigSurveyButton" />
     65
     66        </form>
     67
     68        <?php
     69    }
     70
     71    /**
     72     *
     73     * @param Survey $surveys An array of surveys
     74     */
     75    public static function loadSurveyButton($surveys) {
     76        ?>
     77        <form id="loadForm" action="surveycreation.php" method="post">
     78            <input type="button" onclick="loadSurvey()" value="Load survey" class="surveyButton bigSurveyButton" />
     79        </form>
     80        <br/>
     81        <select id="surveysToLoad" size="1000">
     82            <?php
     83            foreach ($surveys as $survey) {
     84                ?><option value='<?php echo $survey->id; ?>'><?php echo $survey->title; ?></option><?php
     85        }
     86            ?>
     87        </select>
     88        <?php
     89    }
     90
    6391}
    64 
    6592?>
  • Dev/trunk/mainmenu.php

    r50 r56  
    1 <?php require 'classes/master.php'; //should be at top of every page   
     1<?php
     2require 'classes/master.php'; //should be at top of every page   
    23
    3 if(isset($_POST['login']))
    4 {
    5         if($_POST['username'] == '')
    6                 die("Please log in!");
    7         else
    8         {
    9                 $userDBI = new UserDatabaseInterface();
    10                 $user_exists = $userDBI->checkUserName($_POST['username']);
    11                 if($user_exists)
    12                 {       
    13                         $correct_password = $userDBI->checkUserPassword($_POST);
    14                         if(!$correct_password)
    15                                 die("The password you entered is not correct!");
    16                 }       
    17                 else
    18                         die("Unknown user name");
    19         }       
     4if (isset($_POST['login'])) {
     5    if ($_POST['username'] == '')
     6        die("Please log in!");
     7    else {
     8        $userDBI = new UserDatabaseInterface();
     9        $user_exists = $userDBI->checkUserName($_POST['username']);
     10        if ($user_exists) {
     11            $correct_password = $userDBI->checkUserPassword($_POST);
     12            if (!$correct_password)
     13                die("The password you entered is not correct!");
     14        }
     15        else
     16            die("Unknown user name");
     17    }
    2018}
    2119
     
    4341    <body>
    4442        <div id="header">
    45                 <?php new Logo(); ?>
    46             </div>
    47        
     43            <?php new Logo(); ?>
     44        </div>
     45
    4846        <div id="wrapper">
    49            
     47
    5048            <div id="content">
    5149                <div id="menu">               
    52                     <?php
    53                     SurveyButton::newSurveyButton();
    54                     SurveyButton::loadSurveyButton($surveys);
     50                    <?php
     51                    Session::createSessionButton();
     52                    Application::createApplicationButton();
     53                    Survey::newSurveyButton();
     54                    Survey::loadSurveyButton($surveys);
    5555                    ?>
    5656                </div>
  • Dev/trunk/surveycreation.php

    r52 r56  
    3838    <head>
    3939        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    40             <title>Survey</title>
     40            <title>Survey Creation</title>
    4141            <link rel="stylesheet" type="text/css" href="css/style.css" />
    4242    </head>
Note: See TracChangeset for help on using the changeset viewer.