Advertisement
Guest User

Untitled

a guest
May 14th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 15.31 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <link rel="stylesheet" href="main.css" type="text/css" />
  5.         <title>FancyNoteList</title>
  6.     </head>
  7. <body>
  8. <h1>FancyNoteList</h1>
  9.  
  10. <?php
  11.  
  12. //-------------Einbindungen------------
  13. require_once("FancyNoteList.php");
  14. require_once("FancyNote.php");
  15. require_once("User.php");
  16. //-------------------------------------
  17.  
  18. //------------start session-----------
  19. session_start();
  20.  
  21. $aErrors = array();
  22. $aErrorsNote = array();
  23. $counter = 0;
  24.  
  25. error_reporting(E_ALL);
  26.     ini_set('display_errors',1);
  27.  
  28.  
  29. //----------FancyNoteList-----------
  30. //two FancyNoteLists
  31. $oFancyNoteList1 = new FancyNoteList();
  32. $oFancyNoteList2 = new FancyNoteList();
  33. //----------------------------------
  34.  
  35.  
  36. //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  37.  
  38. //there is no user already in the session
  39. if(!isset($_SESSION['username'])) {
  40.  
  41.     //check if User has submitted the >LOGIN< form
  42.     if(isset($_REQUEST['action'])&& $_REQUEST['action'] == 'login'){
  43.         //if so: check if Login is okay, if okay: store username to session variable
  44.         echo "Loginformular wurde abgesendet!";
  45.         if (checkLogin($_REQUEST['username'], $_REQUEST['password'])) {
  46.             //do the login
  47.  
  48.             $_SESSION['username'] = $_REQUEST['username'];
  49.             printContent();
  50.             printNewFancyNote();
  51.             printLogoutForm();
  52.         }
  53.         else{
  54.             //show error message and login form
  55.             echo "Wrong login information submitted!";
  56.             printLoginForm();
  57.             printRegistrationForm();
  58.         }
  59.     }
  60.     //check if user has submitted the >REGISTRATION< form
  61.     elseif(isset($_REQUEST['action'])&& $_REQUEST['action'] == 'register') {
  62.         if(checkRegistration()) {
  63.             echo "Registration successfully completed!";
  64.             //Login Benutzername kommt in das $_SESSION Array rein
  65.             $loggedInUser = new User( 3, $_REQUEST['username'], $_REQUEST['password'], $_REQUEST['email']);
  66.             $_SESSION['user'] = $loggedInUser;
  67.             $_SESSION['username'] = $loggedInUser->getName();
  68.             $_SESSION['userID'] = $loggedInUser->getUserID();
  69.             printContent();
  70.             printLogoutForm();
  71.             printNewFancyNote();
  72.            
  73.         ;
  74.             //actual registration
  75.             //Todoproceed with actual registration in the database
  76.             $_SESSION['registeredUsers'] = array($loggedInUser->getName() => $loggedInUser->getPassword());
  77.         }
  78.         else{
  79.             echo "Registration not completed!";
  80.  
  81.             printRegistrationForm();
  82.         }
  83.     }
  84.     //when no form was submitted
  85.     else{
  86.  
  87.         printLoginForm();
  88.         printRegistrationForm();
  89.     }
  90. }
  91. //user is already logged in
  92. else{
  93.     if(isset($_REQUEST['action'])&& $_REQUEST['action'] == 'newFancyNote') {
  94.  
  95.         if (validate_form()) {
  96.             $oFancyNoteList1->addNote(processForm());
  97.  
  98.             $_REQUEST['iID'] = "";
  99.             $_REQUEST['dDateTime'] = "";
  100.             $_REQUEST['userID'] = "";
  101.             $_REQUEST['sTitle'] = "";
  102.             $_REQUEST['aStringArray'] = "";
  103.             $_REQUEST['sDescription'] = "";
  104.  
  105.             echo 'Note erfolgreich gespeichert';
  106.  
  107.             printContent();
  108.             printLogoutForm();
  109.             printNewFancyNote();
  110.         } else {
  111.             echo 'Form Input false try again';
  112.             printContent();
  113.             printLogoutForm();
  114.             printNewFancyNote();
  115.  
  116.         }
  117.  
  118.     }
  119.         //logout form was sent
  120.     if(isset($_REQUEST['action'])&& $_REQUEST['action'] == "logout") {
  121.             unset($_SESSION['username']);
  122.             printLoginForm();
  123.             printRegistrationForm();
  124.     }
  125. }
  126.  
  127.  
  128.  
  129.  
  130.  
  131. /*function printNote($iID,$dDateTime, $sUserID, $sTitle, $aStringArray, $sDescription){
  132.     echo "$iID, $dDateTime, $sUserID,$sTitle, $aStringArray, $sDescription";
  133. }*/
  134.  
  135. function printContent(){
  136.     echo "This is some hidden content. You are already logged in!.<br/></br/>";
  137. }
  138.  
  139.  
  140.  
  141. function checkLogin($sUsername, $sPassword){
  142.     //global $sCorrectUsername;
  143.     //global $sCorrectPassword;
  144.     if(isset($_SESSION['registeredUsers'])){
  145.         if(array_key_exists($sUsername, $_SESSION['registeredUsers'])) {
  146.             if($_SESSION['registeredUsers'][$sUsername] == $sPassword) {
  147.                 return true;
  148.             }
  149.         } else {
  150.             return false;
  151.         }
  152.     }
  153.  
  154.  
  155.     //return (($sUsername == $sCorrectUsername) && ($sPassword == $sCorrectPassword));
  156. }
  157.  
  158. function checkRegistration(){
  159.     global $aErrors;
  160.    
  161.     if(!isset($_REQUEST['username']) || !checkLength($_REQUEST['username'],4)){
  162.         $aErrors['username']= "Username not set or too short. (4 chars minimum).";
  163.     }
  164.     if(!isset($_REQUEST['password']) || !isset($_REQUEST['password2']) ||
  165.      $_REQUEST['password'] != $_REQUEST['password2']  || !checkLength($_REQUEST['password'], 4)) {
  166.         $aErrors['password'] ="Password not set or too short (4 chars minimum) or not matching!";
  167.      }
  168.     if(!isset($_REQUEST['email']) || !checkEmail($_REQUEST['email'])){
  169.         $aErrors['email'] = "Email not set or not a valid email adress";
  170.     }
  171.     //wenn Fehler gefunden, wenn Anzahl der Fehler >0 also Fehler aufgetreten
  172.     if(count($aErrors) > 0){
  173.         return false;
  174.     }
  175.     return true;
  176.  
  177. }
  178.  
  179. function checkEmail($sCheckValue){
  180.     if(filter_var($sCheckValue, FILTER_VALIDATE_EMAIL) !== false){
  181.         return true;
  182.     }
  183.     return false;
  184. }
  185.  
  186.  
  187. function checkLength($sCheckValue, $iMinLength){
  188.     return (strlen($sCheckValue)>= $iMinLength);
  189. }
  190.  
  191. function checkNoteLength($sCheckValue, $iMinLength){
  192.     return (strlen($sCheckValue)>= $iMinLength);
  193. }
  194.  
  195.  
  196. function checkNewFancyNote(){
  197.     $aErrors = [];
  198.    
  199.     if(!isset($_REQUEST['iID']) || !checkLength($_REQUEST['iID'],1)){
  200.         $aErrors['iID'] = "ID Note darf nicht leer sein!(Minimum ist 1 Zeichen)";
  201.  
  202.         return false;
  203.     }else{
  204.  
  205.         return true;
  206.     }
  207.  
  208. }
  209.  
  210. function processForm(){
  211.     $iID = $_POST['iID'];
  212.     $dDateTime = new DateTime($_POST['dDateTime']);
  213.     $sUserID = $_SESSION['userID'];
  214.     $sTitle = $_POST['sTitle'];
  215.     $issuesArray = explode(",", $_POST['aStringArray']);
  216.     $aStringArray = $issuesArray;
  217.     $sDescription = $_POST['sDescription'];
  218.     $sharedUsersArray = explode(",",  $_POST['aArrayUsers']);
  219.     $aArrayUsers = $sharedUsersArray;
  220.  
  221.     $ofancyNote = new FancyNote( $iID, $dDateTime, $sUserID, $sTitle, $aStringArray, $sDescription, new DateTime("2017-04-01 01:01:01"), $sUserID, $aArrayUsers);
  222.     return $ofancyNote;
  223.  
  224. }
  225. function validate_form(){
  226.     global $aErrorsNote;
  227.  
  228.     if(!isset($_REQUEST['iID']) || !checkLength($_REQUEST['iID'],1)) {
  229.        $aErrorsNote['iID'] = "ID Note darf nicht leer sein!(Minimum ist 1 Zeichen)";
  230.    }
  231.    if(!isset($_REQUEST['dDateTime']) || !checkLength($_REQUEST['dDateTime'],1 )){
  232.        $aErrorsNote['dDateTime'] = "Date Time darf nicht leer sein!(Minimum ist 1 Zeichen)";
  233.    }
  234.    if(!isset($_REQUEST['sTitle']) || !checkLength($_REQUEST['sTitle'],1 )){
  235.        $aErrorsNote['sTitle'] = "Title darf nicht leer sein!(Minimum ist 1 Zeichen)";
  236.    }
  237.    if(!isset($_REQUEST['aStringArray']) || !checkLength($_REQUEST['aStringArray'],1 )){
  238.        $aErrorsNote['aStringArray'] = "Notizen darf nicht leer sein!(Minimum ist 1 Zeichen)";
  239.    }
  240.    if(!isset($_REQUEST['sDescription']) || !checkLength($_REQUEST['sDescription'],1 )){
  241.        $aErrorsNote['sDescription'] = "Die Description darf nicht leer sein!(Minimum ist 1 Zeichen)";
  242.    }
  243.  
  244.    if(count($aErrorsNote)>0){
  245.        return false;
  246.    } else {
  247.        return true;
  248.    }
  249. }
  250.  
  251. function printLoginForm(){
  252.     ?>
  253.     <fieldset id="form">
  254.         <legend>Login</legend>
  255.     <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" name="login">
  256.         <label for="username">Username: </label>
  257.         <input type="text" id="username" name="username" value="<?php echo @$_REQUEST['username']?>" size="40" maxlength="40"/><br/>
  258.         <label for="password">Passwort: </label>
  259.         <input type="password" id="password" name="password" />
  260.         <input type="hidden" name="action" value="login"/><br/>
  261.         <?php //username->max password->123 action->login geheimer input der zur Zuordnung von Input-feldern dient ?>
  262.        
  263.         <button type="button" onclick="submit();">Submit</button>
  264.         <?php //<input type="submit" value="Submit"/> ?>
  265.     </form>
  266.     </fieldset>
  267.     <?php  
  268. }
  269.  
  270. function printRegistrationForm(){
  271.     global $aErrors;
  272.         ?>
  273.     <fieldset id="form">
  274.         <legend>Registration</legend>
  275.     <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" name="register">
  276.         <?php
  277.         $sClass = "";
  278.         if(isset($aErrors['username'])) {
  279.             $sClass = "error";
  280.             echo $aErrors['username']."<br/>";
  281.         }?>
  282.         <label for="username">Username: </label>
  283.         <input class="<?php echo $sClass;?>" type="text" id="username" name="username" value="<?php echo @$_REQUEST['username']?>" size="40" maxlength="40"/><br/>
  284.        
  285.         <?php
  286.         $sClass = "";
  287.         if(isset($aErrors['password'])) {
  288.             $sClass = "error";
  289.             echo $aErrors['password']."<br/>";
  290.         }?>
  291.         <label for="password">Passwort: </label>
  292.         <input class="<?php echo $sClass;?>" type="password" id="password" name="password" /><br/>
  293.        
  294.         <?php
  295.         $sClass = "";
  296.         if(isset($aErrors['password2'])) {
  297.             $sClass = "error";
  298.             echo $aErrors['password2']."<br/>";
  299.         }?>
  300.         <label for="password2">Passwort repeat: </label>
  301.         <input class="<?php echo $sClass;?>" type="password" id="password2" name="password2" /><br/>
  302.        
  303.         <?php
  304.         $sClass = "";
  305.         if(isset($aErrors['email'])) {
  306.             $sClass = "error";
  307.             echo $aErrors['email']."<br/>";
  308.         }?>
  309.         <label for="email">E-Mail: </label>
  310.         <input class="<?php echo $sClass;?>" type="email" id="email" name="email" />
  311.         <input type="hidden" name="action" value="register"/><br/>
  312.         <?php //username->max password->123 action->login geheimer input der zur Zuordnung von Input-feldern dient ?>
  313.        
  314.         <button type="button" onclick="submit();">Submit</button>
  315.         <?php //<input type="submit" value="Submit"/> ?>
  316.     </form>
  317.     </fieldset>
  318.     <?php
  319. }
  320.  
  321. function printLogoutForm(){
  322.     ?>
  323.     <fieldset id="form">
  324.         <legend>Logout</legend>
  325.     <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" name="logout">
  326.         <input type="hidden" name="action" value="logout" /> <br/>
  327.         <button type="button" onclick="submit();">Logout</button>
  328.     </form>
  329.     </fieldset>
  330.     <?php
  331. }
  332.  
  333. function printNewFancyNote(){
  334.  
  335.         global $aErrorsNote;
  336.         ?>
  337.  
  338.     <fieldset id="form">
  339.         <legend>neue Fancy Note erstellen</legend>
  340.     <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" name="newFancyNote">
  341.         <?php
  342.         $sClass = "";
  343.         if(isset($aErrorsNote['iID'])) {
  344.             $sClass = "error";
  345.             echo $aErrorsNote['iID']."<br/>";
  346.         }?>
  347.         <label for="iID">ID Note: </label>
  348.         <input class="<?php echo $sClass;?>" type="text" id="iID" required  name="iID" value="<?php echo @$_REQUEST['iID']?>" /><br/>
  349.        
  350.         <?php
  351.         $sClass = "";
  352.         if(isset($aErrorsNote['dDateTime'])) {
  353.             $sClass = "error";
  354.             echo $aErrorsNote['dDateTime']."<br/>";
  355.         }?>
  356.         <label for="dDateTime">Datum: </label>
  357.         <input class="<?php echo $sClass;?>" type="date" id="dDateTime" required name="dDateTime" value="<?php echo @$_REQUEST['dDateTime']?>" /><br/>
  358.  
  359.         <?php
  360.         $sClass = "";
  361.         if(isset($aErrorsNote['sTitle'])) {
  362.             $sClass = "error";
  363.             echo $aErrorsNote['sTitle']."<br/>";
  364.         }?>
  365.         <label for="sTitle">Titel: </label>
  366.         <input class="<?php echo $sClass;?>" type="text" id="sTitle" required name="sTitle" value="<?php echo @$_REQUEST['sTitle']?>" /><br/>
  367.        
  368.         <?php
  369.         $sClass = "";
  370.         if(isset($aErrorsNote['aStringArray'])) {
  371.             $sClass = "error";
  372.             echo $aErrorsNote['aStringArray']."<br/>";
  373.         }?>
  374.         <label for="aStringArray">Notizen: </label>
  375.         <input class="<?php echo $sClass;?>" type="text" id="aStringArray" name="aStringArray" value="<?php echo @$_REQUEST['aStringArray']?>" /><br/>
  376.        
  377.         <?php
  378.         $sClass = "";
  379.         if(isset($aErrorsNote['sDescription'])) {
  380.             $sClass = "error";
  381.             echo $aErrorsNote['sDescription']."<br/>";
  382.         }?>
  383.         <label for="sDescription">Beschreibung: </label>
  384.         <input class="<?php echo $sClass;?>" type="text" id="sDescription" name="sDescription" value="<?php echo @$_REQUEST['sDescription']?>" /><br/>
  385.  
  386.         <?php
  387.         $sClass = "";
  388.         if(isset($aErrorsNote['aArrayUsers'])) {
  389.             $sClass = "error";
  390.             echo $aErrorsNote['aArrayUsers']."<br/>";
  391.         }?>
  392.         <label for="aArrayUsers">Shared Users: </label>
  393.         <input class="<?php echo $sClass;?>" type="text" id="aArrayUsers" name="aArrayUsers" value="<?php echo @$_REQUEST['aArrayUsers']?>" /><br/>
  394.  
  395.  
  396.  
  397.         <input type="hidden" name="action" value="newFancyNote" /> <br/>
  398.         <?php //username->max password->123 action->login geheimer input der zur Zuordnung von Input-feldern dient ?>
  399.         <button type="button" onclick="submit();">Note speichern</button>
  400.  
  401.         <?php //<input type="submit" value="Submit"/> ?>
  402.     </form>
  403.     </fieldset>
  404.     <?php
  405. }
  406.  
  407.  
  408.  
  409. //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  410.  
  411.  
  412.  
  413.  
  414.  
  415.  
  416. //----------FancyNote-----------
  417. //set values for each Note
  418. $oFancyNote1 = new FancyNote(1, new DateTime("2017-04-01 01:01:01"), "1", "Einkaufsliste", array ("Milch", "Fleisch", "Eier", "Käse"), "Billa","", "" , [3,5]); // new DateTime("2017-04-01 01:11:11"), "edit UID 1"
  419. $oFancyNote2 = new FancyNote(2, new DateTime("2017-05-01 02:02:02"), "2", "To Do", array("PHP Abgabe", "Datenbanken", "Marketing Wahlfach", "JavaScript Abgabe"), "Aufgaben FH","", "", [3,5] ); //new DateTime("2017-05-01 02:22:22"), "edit UID 2"
  420. $oFancyNote3 = new FancyNote(3, new DateTime("2017-06-01 03:03:03"), "3", "Rezept", array("200g Mehl", "4 Eier", "2Tafel Schokolade"), "für Sachertorte","", "",[3,5]); //new DateTime("2017-06-01 03:33:33"), "edit UID 3"
  421. $oFancyNote4 = new FancyNote(4, new DateTime("2017-05-01 04:04:04"), "4", "Shopping", array("Hose", "Kleid", "Shirt", "Tasche"), "Aufgaben FH","", "",[3,5] ); //new DateTime("2017-05-01 02:22:22"), "edit UID 2"
  422. //$oFancyNote5 = new FancyNote(5, new DateTime("2017-06-01 05:05:05"), "UID 5", "Freizeit", array("laufen", "tanzen", "klettern"), "in meiner Freizeit","", "" ); //new DateTime("2017-06-01 03:33:33"), "edit UID 3"
  423. //$oFancyNote6 = new FancyNote(6, new DateTime("2017-05-01 06:06:06"), "UID 26", "Fotografieren", array("Objektiv", "SD-Karte", "Gurt", "Kamera"), "meine Kameraausrüstung","", "" ); //new DateTime("2017-05-01 02:22:22"), "edit UID 2"
  424.  
  425.  
  426. //add Note to FancyNoteList
  427. //add "Einkaufsliste" & "To Do" to FancyNoteList1
  428. //add "Rezept" to FancyNoteList2
  429. $oFancyNoteList1->addNote($oFancyNote1);
  430. $oFancyNoteList1->addNote($oFancyNote2);
  431. $oFancyNoteList1->addNote($oFancyNote4);
  432. $oFancyNoteList2->addNote($oFancyNote3);
  433. //$oFancyNoteList2->addNote($oFancyNote5);
  434. //$oFancyNoteList2->addNote($oFancyNote6);
  435.  
  436. //edit Note
  437. $oFancyNoteList1->editNote(1, "Einkaufsliste","neue Einkaufsliste", "Billa", "neue frische Sachen",array ("Milch", "Fleisch", "Eier", "Käse"),array ("Müsli", "Frischkäse", "Eier", "Senf" , "Salat", "Speck" , "Wurst"),new DateTime("2017-04-01 01:01:01"), new DateTime("2017-06-01 03:33:33"), " 1","edit UID 3", [3,12]);
  438. $oFancyNoteList2->editNote(3, "Rezept","verbesserte Rezeptur", "für Sachertorte", "neuartige Sachertorte",array ("200g Mehl", "4 Eier", "2Tafel Schokolade"), array ("400g Mehl", "8 Eier", "2 Bananen", "4 Tafel Schokolade" , "100g braunen Zucker", "3 Packungen Schokogla"),new DateTime("2017-04-01 01:01:01"), new DateTime("2017-12-12 12:12:12"), "4","edit UID 4", [3,15]);
  439.  
  440. //delete Note
  441. $oFancyNoteList1->deleteNote($oFancyNote1);
  442.  
  443. //output of Notes in the two FancyNoteLists
  444.  
  445. if(isset($_SESSION['userID'])){
  446.     echo $oFancyNoteList1->outputNoteList($_SESSION['userID']);
  447.     echo $oFancyNoteList2->outputNoteList($_SESSION['userID']);
  448. }
  449.  
  450. ?>
  451. </body>
  452. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement