Add project admin interface
This commit is contained in:
parent
751967c5fa
commit
7e3d256f93
@ -32,4 +32,8 @@ class Project{
|
||||
public function getOwnerUName(){
|
||||
return $this->owneruname;
|
||||
}
|
||||
|
||||
public function getActive(){
|
||||
return $this->active;
|
||||
}
|
||||
}
|
@ -43,6 +43,7 @@ class ProjectManager{
|
||||
$dbProj['name'],
|
||||
$dbProj['description'],
|
||||
$dbProj['owner'],
|
||||
$dbProj['owneruname'],
|
||||
$dbProj['active']
|
||||
);
|
||||
|
||||
|
15
www/admin/prosjekter/delete.php
Normal file
15
www/admin/prosjekter/delete.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
require __DIR__ . '/../../../src/_autoload.php';
|
||||
require __DIR__ . '/../../../sql_config.php';
|
||||
$pdo = new \PDO($dbDsn, $dbUser, $dbPass);
|
||||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$projectID = $_GET['id'];
|
||||
|
||||
$query = 'DELETE FROM projects WHERE id=\'' . $projectID . '\'';
|
||||
$statement = $pdo->prepare($query);
|
||||
$statement->execute();
|
||||
|
||||
header('Location: ' . $_SERVER['HTTP_REFERER']);
|
||||
?>
|
||||
|
||||
<a href=".?page=1">Om du ikke ble omdirigert tilbake klikk her</a>
|
89
www/admin/prosjekter/edit.php
Normal file
89
www/admin/prosjekter/edit.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
ini_set('display_errors', '1');
|
||||
date_default_timezone_set('Europe/Oslo');
|
||||
setlocale(LC_ALL, 'no_NO');
|
||||
error_reporting(E_ALL);
|
||||
require __DIR__ . '/../../../src/_autoload.php';
|
||||
require __DIR__ . '/../../../sql_config.php';
|
||||
$pdo = new \PDO($dbDsn, $dbUser, $dbPass);
|
||||
$projectManager = new \pvv\side\ProjectManager($pdo);
|
||||
$projects = $projectManager->getAll();
|
||||
|
||||
$new = 0;
|
||||
if(isset($_GET['new'])){
|
||||
$new = $_GET['new'];
|
||||
}
|
||||
|
||||
$projectID = 0;
|
||||
if(isset($_GET['id'])){
|
||||
$projectID = $_GET['id'];
|
||||
}else if($new == 0){
|
||||
echo "\nID not set";
|
||||
exit();
|
||||
}
|
||||
|
||||
$project = new \pvv\side\Project(
|
||||
0,
|
||||
'Kult Prosjekt',
|
||||
'',
|
||||
'kåre knoll',
|
||||
'pvvadmin',
|
||||
0
|
||||
);
|
||||
if($new == 0){
|
||||
$project = $projectManager->getByID($projectID);
|
||||
}
|
||||
?>
|
||||
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<link rel="stylesheet" href="../../css/normalize.css">
|
||||
<link rel="stylesheet" href="../../css/style.css">
|
||||
<link rel="stylesheet" href="../../css/events.css">
|
||||
<link rel="stylesheet" href="../../css/admin.css">
|
||||
|
||||
<nav><ul>
|
||||
<li class="active"><a href="index.php">hjem</a></li>
|
||||
<li><a href="aktiviteter/">aktiviteter</a></li>
|
||||
<li><a href="kontakt">kontakt</a></li>
|
||||
<li><a href="pvv/">wiki</a></li>
|
||||
</nav>
|
||||
|
||||
<header class="admin">Prosjekt­administrasjon</header>
|
||||
|
||||
<main>
|
||||
|
||||
<article>
|
||||
<h2><?= ($new == 1 ? "Nytt prosjekt" : "Rediger prosjekt"); ?></h2>
|
||||
|
||||
<form action="update.php", method="post" class="gridsplit5050">
|
||||
<div class="gridl">
|
||||
<p class="subtitle">Tittel</p>
|
||||
<?= '<input type="text" name="title" value="' . $project->getName() . '" class="boxinput">' ?><br>
|
||||
|
||||
<p class="subtitle">Beskrivelse</p>
|
||||
<textarea name="desc" cols="40" rows="5" class="boxinput"><?= $project->getDescription(); ?></textarea>
|
||||
</div>
|
||||
|
||||
<div class="gridr noborder">
|
||||
<p class="subtitle">Prosjekteier (Brukernavn)</p>
|
||||
<?= '<input type="text" name="organiser" value="' . $project->getOwnerUName(). '" class="boxinput">' ?><br>
|
||||
|
||||
<p class="subtitle">Prosjekteier (Navn)</p>
|
||||
<?= '<input type="text" name="organisername" value="' . $project->getOwner(). '" class="boxinput">' ?>
|
||||
|
||||
<p class="subtitle">Aktiv</p>
|
||||
<?= '<input type="checkbox" '. ($project->getActive() ? 'checked' : '') . ' name="active"/>' ?>
|
||||
</div>
|
||||
|
||||
<?= '<input type="hidden" name="id" value="' . $project->getID() . '" />' ?>
|
||||
|
||||
<div class="allgrids" style="margin-top: 2em;">
|
||||
<hr class="ruler">
|
||||
|
||||
<input type="submit" class="btn" value="Lagre"></a>
|
||||
</div>
|
||||
</form>
|
||||
<p>
|
||||
</article>
|
||||
|
||||
</main>
|
124
www/admin/prosjekter/index.php
Normal file
124
www/admin/prosjekter/index.php
Normal file
@ -0,0 +1,124 @@
|
||||
<?php
|
||||
ini_set('display_errors', '1');
|
||||
date_default_timezone_set('Europe/Oslo');
|
||||
setlocale(LC_ALL, 'no_NO');
|
||||
error_reporting(E_ALL);
|
||||
require __DIR__ . '/../../../src/_autoload.php';
|
||||
require __DIR__ . '/../../../sql_config.php';
|
||||
$pdo = new \PDO($dbDsn, $dbUser, $dbPass);
|
||||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$projectManager = new \pvv\side\ProjectManager($pdo);
|
||||
$projects = $projectManager->getAll();
|
||||
|
||||
$page = 1;
|
||||
if(isset($_GET['page'])){
|
||||
$page = $_GET['page'];
|
||||
}
|
||||
|
||||
$filterTitle = '';
|
||||
if(isset($_POST['title'])){
|
||||
$filterTitle = $_POST['title'];
|
||||
}
|
||||
|
||||
$filterOrganiser = '';
|
||||
if(isset($_POST['organiser'])){
|
||||
$filterOrganiser = $_POST['organiser'];
|
||||
}
|
||||
|
||||
// filter
|
||||
$projects = array_values(array_filter(
|
||||
$projects,
|
||||
function($project) use ($filterTitle, $filterOrganiser){
|
||||
return (preg_match('/.*'.$filterTitle.'.*/i', $project->getName()) and preg_match('/.*'.$filterOrganiser.'.*/i', $project->getOwner()));
|
||||
}
|
||||
));
|
||||
?>
|
||||
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<link rel="stylesheet" href="../../css/normalize.css">
|
||||
<link rel="stylesheet" href="../../css/style.css">
|
||||
<link rel="stylesheet" href="../../css/events.css">
|
||||
<link rel="stylesheet" href="../../css/admin.css">
|
||||
|
||||
<nav>
|
||||
<ul>
|
||||
<li class="active"><a href="index.php">hjem</a></li>
|
||||
<li><a href="aktiviteter/">aktiviteter</a></li>
|
||||
<li><a href="../prosjekt/">prosjekter</a></li>
|
||||
<li><a href="kontakt">kontakt</a></li>
|
||||
<li><a href="pvv/">wiki</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<header class="admin">Prosjekt­administrasjon</header>
|
||||
|
||||
<main>
|
||||
|
||||
<article class="gridsplit">
|
||||
<div class="gridl">
|
||||
<h2 class="no-chin">Prosjekter</h2>
|
||||
|
||||
<ul class="event-list">
|
||||
<?php
|
||||
$counter = 0;
|
||||
$pageLimit = 4;
|
||||
|
||||
for($i = ($pageLimit * ($page - 1)); $i < count($projects); $i++){
|
||||
if($counter == $pageLimit){
|
||||
break;
|
||||
}
|
||||
|
||||
$project = $projects[$i];
|
||||
$projectID = $project->getID();
|
||||
?>
|
||||
|
||||
<li>
|
||||
<div class="event admin">
|
||||
<div class="event-info">
|
||||
<h3 class="no-chin"><?= $project->getName() . " (ID: " . $projectID . ")"; ?></h3>
|
||||
<p class="subnote"><?= 'Organisert av: ' . $project->getOwner(); ?></p>
|
||||
<p><?= $project->getDescription(); ?></p>
|
||||
</div>
|
||||
|
||||
<div class="event-actions">
|
||||
<?= '<a href="edit.php?id=' . $projectID . '">🖊</a>'; ?>
|
||||
<?= '<a href="delete.php?id=' . $projectID . '" onclick="return confirm(\'Knallsikker? (ID: ' . $projectID . ')\');">🗑</a>'; ?>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<?php
|
||||
$counter++;
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
|
||||
<?php
|
||||
if($page != 1){
|
||||
echo '<a class="btn float-left" href="?page=' . ($page - 1) . '">Forrige side</a>';
|
||||
}
|
||||
|
||||
if(($counter == $pageLimit) and (($pageLimit * $page) < count($projects))){
|
||||
echo '<a class="btn float-right" href="?page=' . ($page + 1) . '">Neste side</a>';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
<div class="gridr">
|
||||
<h2>Verktøy</h2>
|
||||
<a class="btn adminbtn" href="edit.php?new=1">Legg inn nytt prosjekt</a>
|
||||
<h2>Filter</h2>
|
||||
<form action="." method="post">
|
||||
<p class="no-chin">Navn</p>
|
||||
<?= '<input type="text" name="title" class="boxinput" value="' . $filterTitle . '">' ?><br>
|
||||
<p class="no-chin">Organisator</p>
|
||||
<?= '<input type="text" name="organiser" class="boxinput" value="' . $filterOrganiser . '">' ?><br>
|
||||
|
||||
<div style="margin-top: 2em;">
|
||||
<input type="submit" class="btn" value="Filtrer"></input>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
</main>
|
54
www/admin/prosjekter/update.php
Normal file
54
www/admin/prosjekter/update.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
ini_set('display_errors', '1');
|
||||
date_default_timezone_set('Europe/Oslo');
|
||||
setlocale(LC_ALL, 'no_NO');
|
||||
error_reporting(E_ALL);
|
||||
require __DIR__ . '/../../../src/_autoload.php';
|
||||
require __DIR__ . '/../../../sql_config.php';
|
||||
$pdo = new \PDO($dbDsn, $dbUser, $dbPass);
|
||||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
if(!isset($_POST['title']) or !isset($_POST['desc']) or !isset($_POST['organisername']) or !isset($_POST['organiser'])){
|
||||
header('Location: ' . $_SERVER['HTTP_REFERER']);
|
||||
exit();
|
||||
}
|
||||
|
||||
$id = 0;
|
||||
if(isset($_POST['id'])){
|
||||
$id = $_POST['id'];
|
||||
}
|
||||
|
||||
$title = $_POST['title'];
|
||||
$desc = $_POST['desc'];
|
||||
$owner = $_POST['organisername'];
|
||||
$uname = $_POST['organiser'];
|
||||
$active = (isset($_POST['active']) ? $_POST['active'] : 0);
|
||||
|
||||
$statement;
|
||||
if($id == 0){
|
||||
$query = 'INSERT INTO projects (name, owner, owneruname, description, active) VALUES (:title, :owner, :uname, :desc, :active)';
|
||||
$statement = $pdo->prepare($query);
|
||||
|
||||
$statement->bindParam(':title', $title, PDO::PARAM_STR);
|
||||
$statement->bindParam(':desc', $desc, PDO::PARAM_STR);
|
||||
$statement->bindParam(':owner', $owner, PDO::PARAM_STR);
|
||||
$statement->bindParam(':uname', $uname, PDO::PARAM_STR);
|
||||
$statement->bindParam(':active', $active, PDO::PARAM_INT);
|
||||
}else{
|
||||
$query = 'UPDATE projects SET name=:title, owner=:owner, owneruname=:uname, description=:desc, active=:active WHERE id=:id';
|
||||
$statement = $pdo->prepare($query);
|
||||
|
||||
$statement->bindParam(':title', $title, PDO::PARAM_STR);
|
||||
$statement->bindParam(':desc', $desc, PDO::PARAM_STR);
|
||||
$statement->bindParam(':owner', $owner, PDO::PARAM_STR);
|
||||
$statement->bindParam(':uname', $uname, PDO::PARAM_STR);
|
||||
$statement->bindParam(':active', $active, PDO::PARAM_INT);
|
||||
$statement->bindParam(':id', $id, PDO::PARAM_INT);
|
||||
}
|
||||
|
||||
$statement->execute();
|
||||
|
||||
header('Location: .');
|
||||
?>
|
||||
|
||||
<a href=".?page=1">Om du ikke ble automatisk omdirigert tilbake klikk her</a>
|
Loading…
Reference in New Issue
Block a user