php_pracownia-programowania/index.php

131 lines
3.1 KiB
PHP

<?php
session_start();
?>
<title>ToDoList</title>
<link rel="stylesheet" type="text/css" href="style.css">
<?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']);
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 { echo "Wpisano zle dane lub konto nieaktywne."; }
}
if ($_SESSION['zalogowany']==true)
{
echo "Zalogowano jako <b>".$_SESSION['login']."</b>"; echo '<a href="?wyloguj=1"> [Wyloguj]</a>';
?>
<form method="POST" action="add.php">
<input type="text" name="task" class="task_input" required>
<input type="submit" value="Dodaj zadanie" name="submit">
</form>
<?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);
?>
<table>Do zrobienia
<thead>
<tr>
<td>Nr</td>
<td>Zadanie</td>
<td>Akcja</td>
</tr>
</thead>
<tbody>
<?php $i=1; while ($row = mysqli_fetch_array($tasks)) { ?>
<tr>
<td><?php echo $i; ?></td>
<td class="task"><?php echo $row['task']; ?></td>
<td class="action">
<a href="delete.php?del_task=<?php echo $row['ID'];?>">x</a>
<a href="mark.php?mark_task=<?php echo $row['ID'];?>">v</a>
</td>
</tr>
<?php i++; } ?>
</tbody>
</table>
<table>Zrobione
<thead>
<tr>
<td>Nr</td>
<td>Zadanie</td>
<td>Akcja</td>
</tr>
</thead>
<tbody>
<?php $i=1; while ($row = mysqli_fetch_array($tasks_done)) { ?>
<tr>
<td><?php echo $i; ?></td>
<td class="task"><?php echo $row['task']; ?></td>
<td class="action">
<a href="delete.php?del_task=<?php echo $row['ID'];?>">x</a>
</td>
</tr>
<?php $i++; } ?>
</tbody>
</table>
<?php
}
if ($_SESSION['zalogowany']==false): ?>
<div class="loginbox">
<img src="img/avatar.png" class="avatar">
<h1>Zaloguj się</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">
<a href="nowe_konto.php">Zarejestruj się</a>
</form>
</div>
<?php
endif;
mysql_close();
?>