Projects/nettsiden-old
Projects
/
nettsiden-old
Archived
8
0
Fork 0

My projects page

This commit is contained in:
Markus Wang Halvorsen 2017-10-28 20:09:54 +02:00
parent 446d966e80
commit e5dcb07659
6 changed files with 192 additions and 4 deletions

View File

@ -49,4 +49,26 @@ class ProjectManager{
return $project;
}
public function getByUName($uname){
$query = 'SELECT * FROM projects WHERE owneruname=:uname';
$statement = $this->pdo->prepare($query);
$statement->bindParam(':uname', $uname, PDO::PARAM_STR);
$statement->execute();
$projects = [];
foreach($statement->fetchAll() as $dbProj){
$project = new Project(
$dbProj['id'],
$dbProj['name'],
$dbProj['description'],
$dbProj['owner'],
$dbProj['owneruname'],
$dbProj['active']
);
$projects[] = $project;
}
return $projects;
}
}

View File

@ -37,6 +37,15 @@ header.admin {
word-wrap: break-word;
}
.event-info a {
color: black;
text-decoration: none;
}
.event-info a:hover {
text-decoration: underline;
}
.event-actions {
grid-column: 2;
text-align: center;

View File

@ -15,6 +15,19 @@ $pdo = new \PDO($dbDsn, $dbUser, $dbPass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$projectManager = new \pvv\side\ProjectManager($pdo);
$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,
'Nytt Prosjekt',
@ -23,6 +36,15 @@ $project = new \pvv\side\Project(
$attrs["uid"][0],
1
);
if($new == 0){
$project = $projectManager->getByID($projectID);
if($project->getOwnerUName() != $attrs["uid"][0]){
header('HTTP/1.0 403 Forbidden');
echo "wrong user";
exit();
}
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
@ -68,10 +90,12 @@ $project = new \pvv\side\Project(
<p class="subnote">Hva går prosjektet ditt ut ?</p>
<textarea name="desc" cols="40" rows="5" class="boxinput"><?= $project->getDescription() ?></textarea>
<?= '<input type="hidden" name="id" value="' . $project->getID() . '" />' ?>
<div style="margin-top: 2em;">
<hr class="ruler">
<input type="submit" class="btn" value="Opprett prosjekt"></a>
<?= '<input type="submit" class="btn" value="' . ($new ? 'Opprett prosjekt' : 'Lagre endringer') . '"></a>'; ?>
</div>
</form>
</article>

View File

@ -35,12 +35,14 @@ $projects = $projectManager->getAll();
?>
<p>PVV har for øyeblikket ingen aktive prosjekter. Tenker du at noe bør gjøres? Har du en kul ide for noe PVV kan samarbeide om? Sett opp et prosjekt!</p>
<br>
<a class="btn" href="ny.php">Lag prosjekt</a>
<a class="btn" href="edit.php?new=1">Lag prosjekt</a>
<a class="btn" href="mine.php">Mine prosjekter</a>
<?php
}else{
?>
<p>Lyst til å gjøre noe kult? Her er et utvalg av de prosjektene som PVVere har laget. Mangler det noe, eller brenner du for noe annet? Sett opp et eget prosjekt!</p>
<a class="btn" href="ny.php">Lag prosjekt</a>
<a class="btn" href="edit.php?new=1">Lag prosjekt</a>
<a class="btn" href="mine.php">Mine prosjekter</a>
<ul class="calendar-events">
<?php

131
www/prosjekt/mine.php Normal file
View File

@ -0,0 +1,131 @@
<?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';
require_once(__DIR__ . '/../../vendor/simplesamlphp/simplesamlphp/lib/_autoload.php');
$as = new SimpleSAML_Auth_Simple('default-sp');
$as->requireAuth();
$attrs = $as->getAttributes();
$pdo = new \PDO($dbDsn, $dbUser, $dbPass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$projectManager = new \pvv\side\ProjectManager($pdo);
$projects = $projectManager->getByUName($attrs['uid'][0]);
$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>
<?php
$attr = $as->getAttributes();
if($attr){
$uname = $attr["uid"][0];
echo '<p class="login">logget inn som: ' . $uname . '</p>';
}else{
echo '<a class="login" href="' . $as->getLoginURL() . '">logg inn</a>';
}
?>
</nav>
<header>Prosjekt&shy;verkstedet</header>
<main>
<article class="gridsplit">
<div class="gridl">
<h2 class="no-chin">Mine 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">
<div class="event-info">
<h3 class="no-chin"><?= '<a href="edit.php?id=' . $project->getID() . '">' . $project->getName() . '</a>'; ?></h3>
<p><?= $project->getDescription(); ?></p>
</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" href="edit.php?new=1">Lag 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>
<div style="margin-top: 2em;">
<input type="submit" class="btn" value="Filtrer"></input>
</div>
</form>
</div>
</article>
</main>

View File

@ -51,7 +51,7 @@ if($id == 0){
$statement->execute();
header('Location: ..');
header('Location: ./mine.php');
?>
<a href="..">Om du ikke ble omdirigert tilbake klikk her</a>