Fix admin event editor

The date field was a lot of work, but it's a lot easier to use now.
This commit is contained in:
Peder Bergebakken Sundt 2018-08-10 00:19:16 +02:00
parent 13518f7fff
commit 29a41f5ad8
3 changed files with 85 additions and 34 deletions

View File

@ -14,6 +14,7 @@ $as = new SimpleSAML_Auth_Simple('default-sp');
$as->requireAuth(); $as->requireAuth();
$attrs = $as->getAttributes(); $attrs = $as->getAttributes();
$uname = $attrs['uid'][0]; $uname = $attrs['uid'][0];
$name = $attrs['cn'][0];
if(!$userManager->hasGroup($uname, 'aktiviteter')){ if(!$userManager->hasGroup($uname, 'aktiviteter')){
echo 'Her har du ikke lov\'t\'å\'værra!!!'; echo 'Her har du ikke lov\'t\'å\'værra!!!';
@ -36,24 +37,31 @@ if(isset($_GET['id'])){
} }
$today = new DateTimeImmutable; $today = new DateTimeImmutable;
$defaultStart = $today->format("Y-m-d H:00:00"); $today = $today->setTime(18, 15);
$inOneHour = $today->add(new DateInterval('PT1H')); $defaultStart = $today->format("Y-m-d H:15:00");
$defaultEnd = $inOneHour->format("Y-m-d H:00:00"); $inTwoHours = $today->add(new DateInterval('PT1H45M'));
$defaultEnd = $inTwoHours->format("Y-m-d H:00:00");
$event = new \pvv\side\SimpleEvent( $event;
0,
'Kul Hendelse',
$today,
$inOneHour,
'PVV',
'Norge et sted',
'her skjer det noe altså'
);
if($new == 0){ if($new == 0){
$event = $customActivity->getEventByID($eventID); $event = $customActivity->getEventByID($eventID);
} }
?> else {
$event = new \pvv\side\SimpleEvent(
0,
'',
$today,
$inTwoHours,
'',
'',
''
);
}
?>
<!DOCTYPE html>
<html lang="no" locale="no">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="../../css/normalize.css"> <link rel="stylesheet" href="../../css/normalize.css">
@ -75,34 +83,50 @@ if($new == 0){
<h2><?= ($new == 1 ? "Ny hendelse" : "Rediger hendelse"); ?></h2> <h2><?= ($new == 1 ? "Ny hendelse" : "Rediger hendelse"); ?></h2>
<form action="update.php", method="post" class="gridsplit5050"> <form action="update.php", method="post" class="gridsplit fullwidth_inputs">
<div class="gridl"> <div class="gridl">
<p class="subtitle">Tittel</p> <p class="subtitle">Tittel</p>
<?= '<input type="text" name="title" value="' . $event->getName(). '" class="boxinput">' ?><br> <input type="text" name="title" value="<?= $event->getName() ?>" class="boxinput" required placeholder="En kul hendelse"><br>
<div class="gridsplit5050">
<div class="gridl">
<p class="subtitle">Arrangør</p>
<input type="text" name="organiser" value="<?= $event->getOrganiser() ?>" class="boxinput" required placeholder="<?= $name ?>"><br>
</div>
<div class="gridr noborder">
<p class="subtitle">Sted</p>
<input type="text" name="location" value="<?= $event->getLocation() ?>" class="boxinput" required placeholder="Terminalrommet"><br>
</div>
</div>
<p class="subtitle">Beskrivelse</p> <p class="subtitle">Beskrivelse</p>
<textarea name="desc" cols="40" rows="5" class="boxinput"><?= implode($event->getDescription(), "\n"); ?></textarea> <textarea name="desc" rows="8" class="boxinput" placeholder="Beskrivese" required><?= implode($event->getDescription(), "\n"); ?></textarea>
</div> </div>
<div class="gridr noborder"> <div class="gridr" style="line-height: 1.3em;">
<p class="subtitle">Starttid (YYYY-MM-DD HH:MM:SS)</p> <h4>Starttid</h4><br>
<?= '<input name="start" type="text" class="boxinput" value="' . $event->getStart()->format('Y-m-d H:00:00') . '"><br>' ?> <i>Måned:</i><br>
<input name="start_mon" type="month" class="boxinput" required value="<?= $event->getStart()->format('Y-m') ?>"><br>
<i>Dag:</i><br>
<input name="start_day" type="number" min="1" max="31" required class="boxinput" value="<?= $event->getStart()->format('d') ?>"><br>
<i>Klokkeslett:</i><br>
<input name="start_time" type="time" class="boxinput" required value="<?= $event->getStart()->format('H:i:s') ?>"><br>
<br>
<h4>Varighet</h4><br>
<?php $diff = $event->getStart()->diff($event->getStop()); ?>
<i>Timer:</i><br>
<input name="lasts_hours" type="number" min="0" class="boxinput" required value="<?= $diff->h ?>"><br>
<i>Minutter:</i><br>
<input name="lasts_minutes" type="number" min="0" max="59" class="boxinput" required value="<?= $diff->i ?>"><br>
<p class="subtitle">Sluttid (YYYY-MM-DD HH:MM:SS)</p>
<?= '<input name="end" type="text" class="boxinput" value="' . $event->getStop()->format('Y-m-d H:00:00') . '"><br>' ?>
<p class="subtitle">Arrangør</p>
<?= '<input type="text" name="organiser" value="' . $event->getOrganiser(). '" class="boxinput">' ?><br>
<p class="subtitle">Sted</p>
<?= '<input type="text" name="location" value="' . $event->getLocation(). '" class="boxinput">' ?><br>
</div> </div>
<?= '<input type="hidden" name="id" value="' . $event->getID() . '" />' ?> <input type="hidden" name="id" value="<?= $event->getID() ?>" />
<div class="allgrids" style="margin-top: 2em;"> <div class="allgrids" style="margin-top: 2em;">
<hr class="ruler"> <hr class="ruler">
<input type="submit" class="btn" value="Lagre"></a> <input type="submit" class="btn" value="Lagre"></a>
</div> </div>
</form> </form>

View File

@ -18,7 +18,15 @@ if(!$userManager->hasGroup($uname, 'aktiviteter')){
exit(); exit();
} }
if(!isset($_POST['title']) or !isset($_POST['desc']) or !isset($_POST['start']) or !isset($_POST['end']) or !isset($_POST['organiser']) or !isset($_POST['location'])){ if((!isset($_POST['title']))
or (!isset($_POST['desc']))
or (!isset($_POST['organiser']))
or (!isset($_POST['location']))
or (!isset($_POST['start_mon']))
or (!isset($_POST['start_day']))
or (!isset($_POST['start_time']))
or (!isset($_POST['lasts_hours']))
or (!isset($_POST['lasts_minutes']))) {
header('Location: ' . $_SERVER['HTTP_REFERER']); header('Location: ' . $_SERVER['HTTP_REFERER']);
exit(); exit();
} }
@ -30,13 +38,28 @@ if(isset($_POST['id'])){
$title = $_POST['title']; $title = $_POST['title'];
$desc = $_POST['desc']; $desc = $_POST['desc'];
$start = $_POST['start']; //$start = $_POST['start'];
$stop = $_POST['end']; //$stop = $_POST['end'];
$organiser = $_POST['organiser']; $organiser = $_POST['organiser'];
$location = $_POST['location']; $location = $_POST['location'];
$date_part_start_mon = $_POST['start_mon'];
$date_part_start_day = $_POST['start_day'];
$date_part_start_time = $_POST['start_time'];
$date_part_lasts_hours = $_POST['lasts_hours'];
$date_part_lasts_minutes = $_POST['lasts_minutes'];
$start = ($date_part_start_mon . "-" . $date_part_start_day . " " . $date_part_start_time);
if (sizeof(explode(":", $date_part_start_time))==2) {
$start .= ":00";
}
print($start);
$start_date = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $start); $start_date = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $start);
$stop_date = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $stop); $stop_date = $start_date->add(new DateInterval('PT' . $date_part_lasts_hours . 'H' . $date_part_lasts_minutes . 'M'));
$stop = $stop_date->format('Y-m-d H:i:s');
print($stop);
if ($start_date >= $stop_date) { if ($start_date >= $stop_date) {
echo 'Invalid dates. End date must come after the start date!'; echo 'Invalid dates. End date must come after the start date!';
exit(); exit();

View File

@ -260,6 +260,10 @@ article {
margin-top: 0; margin-top: 0;
} }
.noborder {
border: none;
}
.btn { .btn {
padding: .5em; padding: .5em;
border-radius: 4px; border-radius: 4px;