Fix the project editor and a delete feature

This commit is contained in:
Peder Bergebakken Sundt 2018-08-09 00:48:53 +02:00
parent 1147c1a7af
commit a63bc3e6a9
3 changed files with 40 additions and 17 deletions

View File

@ -221,7 +221,6 @@ article {
} }
.gridsplit { .gridsplit {
padding-top: 1.3em;
display: grid; display: grid;
grid-template-columns: 3fr 1fr; grid-template-columns: 3fr 1fr;
} }
@ -293,3 +292,7 @@ article {
border: none; border: none;
border-bottom: 1px dotted rgba(0,0,0,.5); border-bottom: 1px dotted rgba(0,0,0,.5);
} }
textarea.boxinput {
resize: vertical;
}

View File

@ -47,7 +47,8 @@ if($new == 0){
} }
} }
?> ?>
<!DOCTYPE html>
<html lang="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">
@ -72,7 +73,7 @@ if($new == 0){
<p class="subtitle no-chin">Beskrivelse</p> <p class="subtitle no-chin">Beskrivelse</p>
<p class="subnote no-chin">Hva går prosjektet ditt ut ?</p> <p class="subnote no-chin">Hva går prosjektet ditt ut ?</p>
<p class="subnote">Den første linjen blir vist prosjektkortet, prøv å holde den kort!</p> <p class="subnote">De første to linjene blir vist prosjektkortet, prøv å gjøre de til et fint sammendrag eller intro!</p>
<textarea name="desc" style="width:100%" rows="8" class="boxinput"><?= implode($project->getDescription(), "\n"); ?></textarea> <textarea name="desc" style="width:100%" rows="8" class="boxinput"><?= implode($project->getDescription(), "\n"); ?></textarea>
<?= '<input type="hidden" name="id" value="' . $project->getID() . '" />' ?> <?= '<input type="hidden" name="id" value="' . $project->getID() . '" />' ?>
@ -80,8 +81,8 @@ if($new == 0){
<div style="margin-top: 2em;"> <div style="margin-top: 2em;">
<hr class="ruler"> <hr class="ruler">
<input type="submit" class="btn" value="<?= ($new ? 'Opprett prosjekt' : 'Lagre endringer') ?>"></input>
<?= '<input type="submit" class="btn" value="' . ($new ? 'Opprett prosjekt' : 'Lagre endringer') . '"></a>'; ?> <?php if (!$new){?><input type="submit" class="btn" name="delete" value="Slett"></input><?php } ?>
</div> </div>
</form> </form>
</main> </main>

View File

@ -6,7 +6,7 @@ require __DIR__ . '/../../sql_config.php';
$pdo = new \PDO($dbDsn, $dbUser, $dbPass); $pdo = new \PDO($dbDsn, $dbUser, $dbPass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if(!isset($_POST['title']) or !isset($_POST['desc'])){ if(!isset($_POST['title']) or !isset($_POST['desc']) or !isset($_POST['active'])){
header('Location: ' . $_SERVER['HTTP_REFERER']); header('Location: ' . $_SERVER['HTTP_REFERER']);
exit(); exit();
} }
@ -17,6 +17,8 @@ $as->requireAuth();
$attrs = $as->getAttributes(); $attrs = $as->getAttributes();
$id = $_POST['id']; $id = $_POST['id'];
$do_delete = isset($_POST['delete']);
$active = $_POST['active']; $active = $_POST['active'];
$title = $_POST['title']; $title = $_POST['title'];
@ -49,10 +51,26 @@ if($id == 0){
if($uname != $owner['uname']){ if($uname != $owner['uname']){
header('Content-Type: text/plain', true, 403); header('Content-Type: text/plain', true, 403);
echo "Not project owner for project with ID " . $id . "\r\n"; echo "Illegal action, you're not the project owner for project with ID " . $id . "\r\n";
exit(); exit();
} }
if ($do_delete) {
// this should be done as a transaction...
$pdo->beginTransaction();
$query = 'DELETE FROM projects WHERE id=:id';
$statement = $pdo->prepare($query);
$statement->bindParam(':id', $id, PDO::PARAM_INT);
$statement->execute();
$query = 'DELETE FROM projectmembers WHERE projectid=:id';
$statement = $pdo->prepare($query);
$statement->bindParam(':id', $id, PDO::PARAM_INT);
$statement->execute();
$pdo->commit();
}else{
$query = 'UPDATE projects SET name=:title, description=:desc WHERE id=:id'; $query = 'UPDATE projects SET name=:title, description=:desc WHERE id=:id';
$statement = $pdo->prepare($query); $statement = $pdo->prepare($query);
@ -61,6 +79,7 @@ if($id == 0){
$statement->bindParam(':id', $id, PDO::PARAM_INT); $statement->bindParam(':id', $id, PDO::PARAM_INT);
$statement->execute(); $statement->execute();
}
} }
header('Location: ./mine.php'); header('Location: ./mine.php');