php_pracownia-programowania/index.php

135 lines
3.6 KiB
PHP

<?php
session_start();
?>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ToDoList</title>
<link rel="stylesheet" type="text/css" href="style/main.css">
<link rel="stylesheet" type="text/css" href="style/login.css">
<link rel="stylesheet" type="text/css" href="style/tasks.css">
</head>
<?php
include 'sql/db_login.php';
mysql_connect("$db_servername", "$db_login", "$db_password");
mysql_select_db("$db_name");
$db = mysqli_connect("$db_servername", "$db_login_tasks", "$db_password_tasks", "$db_name_tasks");
function filter($variable)
{
if(get_magic_quotes_gpc())
$variable = stripslashes($variable);
return mysql_real_escape_string(htmlspecialchars(trim($variable)));
}
if (isset($_GET['wyloguj'])==1)
{
$_SESSION['zalogowany'] = false;
session_destroy();
}
if (isset($_POST['loguj']))
{
$login = filter($_POST['login']);
$password = filter($_POST['password']);
$password = md5($password);
if (mysql_num_rows(mysql_query("SELECT * FROM `users` WHERE `user_login`='$login' && `user_pass`='$password' && `aktywne`='1'")) > 0)
{
$_SESSION['zalogowany'] = true;
$_SESSION['login'] = strtolower($login);
}
else if (mysql_num_rows(mysql_query("SELECT * FROM `users` WHERE `user_login`='$login' && `user_pass`='$password' && `aktywne`='0'")) > 0)
{ $error = "Konto nieaktywne.";}
else { $error = "Zły login lub hasło"; }
}
if ($_SESSION['zalogowany']==true)
{
?>
<div class="header">
<a class="logo">ToDoList</a>
<div class="header-right">
<a>Zalogowano jako <b><?php echo $_SESSION['login']; ?></b></a>
<a class="active" href="?wyloguj=1">Wyloguj</a>
</div>
</div>
<div class="addform">
<form method="POST" action="add.php">
<input type="text" name="task" class="task_input" placeholder="Nowe zadanie" required>
<input type="submit" value="Dodaj" name="submit">
</form>
</div>
<?php
$login = $_SESSION['login'];
$query = "SELECT * FROM `tasks_$login` WHERE done = 0";
$tasks = mysqli_query($db, $query);
$query_done = "SELECT * FROM `tasks_$login` WHERE done = 1";
$tasks_done = mysqli_query($db, $query_done);
?>
<div class="todo">
<h4 class="todo-header">Do zrobienia</h4>
<ul class="tasks">
<?php while ($row = mysqli_fetch_array($tasks)) { ?>
<li> <span class="task"><?php echo $row['task']; ?>
<a class="done-button" href="mark.php?mark_task=<?php echo $row['ID'];?>">Oznacz jako zrobione</a>
<a class="delete-button" href="delete.php?del_task=<?php echo $row['ID'];?>">Usuń</a>
</span> </li>
<?php } ?>
</ul>
</div>
<div class="done">
<h4 class="todo-header">Zrobione</h4>
<ul class="tasks">
<?php $i=1; while ($row = mysqli_fetch_array($tasks_done)) { ?>
<li> <span class="task"><?php echo $row['task']; ?>
<a class="delete-button" href="delete.php?del_task=<?php echo $row['ID'];?>">Usuń</a>
</span> </li>
<?php } ?>
</ul>
</tbody>
</table>
</div>
<?php
}
if ($_SESSION['zalogowany']==false): ?>
<div class="loginbox">
<img src="img/avatar.png" class="avatar">
<h1>Logowanie</h1>
<form method="POST" action="index.php">
<p>Login</p>
<input type="text" name="login" placeholder="Wpisz swój login" required>
<p>Hasło</p>
<input type="password" name="password" placeholder="Wpisz swoje hasło" required>
<input type="submit" name="loguj" value="Zaloguj">
<h2><?php echo $error; ?></h2>
<a href="nowe_konto.php">Zarejestruj się</a>
</form>
</div>
<?php
endif;
mysql_close();
?>
</html>