Итак, я получил это
Примечание: неопределенная переменная: щелчок по дате
Я знаю откуда это, но я не знаю, как это решить. А также я пытаюсь сделать так, чтобы календарь начинался с текущего дня в URL. Не заставляя меня нажимать на этот день.
Любая помощь с моими проблемами?
моя база данных
CREATE TABLE `events` (
`id` int(11) NOT NULL,
`type` int(2) NOT NULL DEFAULT '0',
`name` varchar(255) DEFAULT NULL,
`date` date DEFAULT NULL,
`created` datetime DEFAULT NULL
)
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) DEFAULT NULL,
`password` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
calendar.php
<?php
session_start();
include "connection.php";
if(!isset($_SESSION["username"]))
{
?>
<script type="text/javascript">
window.location="calendar1.php?";
</script>
<?php
}
?>
<style type="text/css">
<?php include 'style.css'; ?>
</style>
<?php
$month_date = date('m');
$year_date = date('Y');
date_default_timezone_set("Europe/Bucharest");
if(isset($_GET['month'])) {
$month = $_GET['month'];
} else {
$month = $month_date;
}
if(isset($_GET['year'])) {
$year = $_GET['year'];
} else {
$year = $year_date;
}
if(isset($_GET['day'])) {
$day_clicked = $_GET['day'];
$date_clicked = $year . '-' . $month . '-' . $day_clicked;
}
if(isset($_POST['submit'])){
$created = date('Y-m-d H:i:s');
if($_FILES["f1"]["error"] == 0) {
$tm=md5(time());
$fnm=$_FILES["f1"]["name"];
$destination="./images/".$tm.$fnm;
$destination1="images/".$tm.$fnm;
move_uploaded_file($_FILES["f1"]["tmp_name"],$destination);
mysqli_query($link,"insert into events (`type`, `name`, `date`, `created`, `image`)
values ('$_POST[radio]','$_POST[name]','$date_clicked','$created','$destination1')");
} else {
mysqli_query($link,"insert into events (`type`, `name`, `date`, `created`)
values ('$_POST[radio]','$_POST[name]','$date_clicked','$created')");
}
header('Location: ' . $_SERVER['REQUEST_URI']);
exit;
}
$today = 0;
if($month == $month_date && $year == $year_date) {
$today = date('d');
}
$data = mktime(0,0,0,$month,1,$year);
$last_day = date("t",$data);
$this_month = getdate ($data);
$start_day = $this_month['wday']-1;
if($start_day < 0 ) {
$start_day = 6;
}
$prev = $next = 'calendar1.php?month=';
$prev .= ($month == 1 ? '12&year='.($year-1) : ($month-1).'&year='.$year);
$next .= ($month == 12 ? '1&year='.($year+1) : ($month+1).'&year='.$year);
echo '
<div class="calendar">
<div class="direction">
<a href="',$prev,'" class="previous">Previous</a>
<a href="',$next,'" class="next">Next</a>
</div>
<table>
<caption>',date("F",$data),' ',$year,'</caption>
<thead>
<tr>
<th scope="col">Mo</th>
<th scope="col">Tu</th>
<th scope="col">We</th>
<th scope="col">Th</th>
<th scope="col">Fr</th>
<th scope="col">Sa</th>
<th scope="col">Su</th>
</tr>
</thead>
<tbody>
<tr>';
$i=0;
while ($i < $start_day) {
echo '<td></td>';
$i++;
}
$month_events = mysqli_query($link,"select date from events where date LIKE '".$year . '-' . $month."%' GROUP BY date");
while($month_event = mysqli_fetch_assoc($month_events)) {
$has_event[$month_event['date']] = true;
}
$day = 1;
while($day <= $last_day) {
if (($i % 7) == 0) {
echo '<tr>';
}
?>
<?php if(strlen($day) == 1) {
$comp_date = $year . '-' . $month . '-0' . $day;
} else {
$comp_date = $year . '-' . $month . '-' . $day;
}
?>
<td <?php if($day == $today){
echo "class='today'";
} elseif(isset($has_event[$comp_date])) {
echo "class='evenbox'";
}
?>>
<?php echo "<a class='onclick' href='?month=".$month."&day=".$day."&year=".$year."'>".$day."</a>"; ?>
</td>
<?php
if ((++$i % 7) == 0) { ?>
</tr>
<?php
}
$day++;
}
if (($i % 7) > 0) {
while ($i++ % 7 > 0) { ?>
<td></td>
<?php
} ?>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<div id="details">
<?php
$res=mysqli_query($link,"select * from events where date='$date_clicked'");
while($row=mysqli_fetch_array($res))
{ ?>
Today: <?php echo $row["name"]; ?><br />
Event type: <?php echo $row["type"]; ?><br />
Added: <?php echo date('d-m-Y H:i', strtotime($row["created"])); ?><br />
<?php if($row["image"] != '') {
echo '<img src="'.$row["image"].'" style="max-width:100px;height:auto;" />';
} ?>
<hr />
<?php
}
?>
</div>
<br/>
<button id="button" onclick="javascript:showhide();" >Add events </button>
<div id="events" class="events">
<form id="form1" name="form1" action="" method="post" enctype="multipart/form-data" >
<table>
<tr>
<td> <label for="name">Insert data</label>
<br/>
<textarea name="name" id="name" cols="30" rows="3" placeholder="Add details about event here" required=""></textarea>
<br class="clear" />
</td>
</tr>
<tr>
<td>
<label for="type">Type</label>
<input type="radio" name="radio" value="0" id="type" required="" />0
<input type="radio" name="radio" value="1" id="type" required="" />1
<input type="radio" name="radio" value="2" id="type" required=""/>2
<br class="clear" />
</td>
</tr>
<tr>
<td><label for="type">Insert image</label>
<input type="file" name="f1" /></td>
</tr>
<tr>
<td>
<input type="submit" name="submit" class="click" value="Submit">
</td>
</tr>
</table>
</form>
</div>
</div>
<script type="text/javascript">
function showhide()
{
var div = document.getElementById("events");
if (div.style.display === "block") {
div.style.display = "none";
}
else {
div.style.display = "block";
}
}
</script>
login.php
<?php
session_start();
include "connection.php";
?>
<style type="text/css">
<?php include 'loginform.css'; ?>
</style>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body class="login">
<div class="login_wrapper">
<section class="login_content">
<form name="form1" action="" method="post">
<h1>Login</h1>
<div>
<input type="text" name="username" class="form-control" placeholder="Username" required=""/>
</div>
<div>
<input type="password" name="password" class="form-control" placeholder="Password" required=""/>
</div>
<div>
<input class="btn btn-default submit" type="submit" name="submit1" value="Login">
</div>
<div class="clearfix"></div>
<br/>
</div>
</form>
</section>
<?php
if(isset($_POST["submit1"]))
{
$reg = mysqli_query($link, "select * from users where username='$_POST[username]'");
if($count = mysqli_num_rows($reg)){
$security_hash = '&*^HJVkhjJYHGF7896(*jkbad78JHB#)R(JV';
$password = hash('md5', $_POST['password'].$security_hash);
?>
<?php
$_SESSION["username"]=$_POST["username"];
?>
<script type="text/javascript">
window.location="calendar1.php?";
</script>
<?php
}
else
{
?>
<div class="alert alert-danger col-lg-6 col-lg-push-3">
<strong style="color:white">Incorect</strong> username or password
</div>
<?php
}
}
?>
</body>
</html>
connection.h
<?php
$link=mysqli_connect("localhost","root","");
mysqli_select_db($link,"calendar");
if ($link->connect_error) {
die("Connection failed: " . $link->connect_error);
}
?>
loginform.css
.login {
background: white;
}
.login_wrapper {
right: 0px;
margin: 0px auto;
margin-top: 5%;
max-width: 350px;
position: relative
}
.clearfix:after,
form:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden
}
.login_content {
margin: 0 auto;
padding: 25px 0 0;
position: relative;
text-align: center;
text-shadow: 0 1px 0 #fff;
min-width: 280px
}
.login_content form {
margin: 20px 0;
position: relative
}
.form-control{
margin-right:5px;
margin-bottom:10px
}
.login_content .btn-default:hover {
text-decoration: none
}
.login_content a:hover {
text-decoration: underline
}
.login_content h1 {
font: normal 25px Helvetica, Arial, sans-serif;
line-height: 20px;
margin: 10px 0 30px
}
.login_content h1:after {
background: #7e7e7e;
background: linear-gradient(left, #7e7e7e 0%, #fff 100%);
right: 0
}
.login_content h1:before {
background: #7e7e7e;
background: linear-gradient(right, #7e7e7e 0%, #fff 100%);
left: 0
}
.login_content h1:before,
.login_content h1:after {
content: "";
height: 1px;
position: absolute;
top: 10px;
width: 27%
}
style.css
* {
margin:0;
padding-right:10px;
padding-top:0;
padding-bottom:0;
padding-left:0;
}
body {
margin:0;
padding:0;
}
.calendar {
table-layout: fixed;
border-collapse:collapse;
color: #000000;
background: white;
width:800px;
float:left;
}
.calendar .direction a {
color: #010101;
}
.calendar .direction .previous {
padding:0.25em;
float: left;
}
.calendar .direction .next {
padding:0.25em;
float: right;
}
.calendar table {
width:80%;
table-layout: fixed;
border-collapse:collapse;
color: #000000;
margin-left: auto;
margin-right: auto;
}
.calendar caption {
font-weight:bold;
padding:0.25em;
background: #AAA;
text-align: center;
}
.calendar th,
.calendar td {
padding:0.1em;
text-align:center;
border:1px solid #AAA;
height:100px;
}
.calendar .today {
font-weight: bold;
background: orange;
}
.calendar th:nth-of-type(6),
.calendar td:nth-of-type(6) {
color: red;
}
.calendar th:nth-of-type(7),
.calendar td:nth-of-type(7) {
color: red;
}
#events {
width:600px;
float:right;
display: none;
text-align: center;
}
.calendar .evenbox{
background: linear-gradient(225deg, red, red 10px, transparent 10px, transparent);
}