diff --git a/dist/pvv.sql b/dist/pvv.sql
index 8d43130..4ad5fa9 100644
--- a/dist/pvv.sql
+++ b/dist/pvv.sql
@@ -12,18 +12,18 @@ CREATE TABLE "projects" (
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
"name" TEXT,
"description" TEXT,
-"owner" TEXT,
-"owneruname" TEXT,
-"owneremail" TEXT,
"active" BOOLEAN
);
CREATE TABLE "projectmembers" (
"projectid" INTEGER,
-"membername" TEXT,
-"memberuname" TEXT,
-"role" TEXT
-)
+"name" TEXT,
+"uname" TEXT,
+"mail" TEXT,
+"role" TEXT,
+"lead" BOOLEAN DEFAULT 0,
+"owner" BOOLEAN DEFAULT 0
+);
CREATE TABLE "users" (
"uname" TEXT,
diff --git a/dist/pvv_mysql.sql b/dist/pvv_mysql.sql
index 66084ab..fe001fc 100644
--- a/dist/pvv_mysql.sql
+++ b/dist/pvv_mysql.sql
@@ -12,9 +12,6 @@ CREATE TABLE projects (
`id` INTEGER PRIMARY KEY AUTO_INCREMENT,
`name` TEXT,
`description` TEXT,
-`owner` TEXT,
-`owneruname` TEXT,
-`owneremail` TEXT,
`active` BOOLEAN
);
@@ -22,8 +19,11 @@ CREATE TABLE projectmembers (
`projectid` INTEGER,
`name` TEXT,
`uname` TEXT,
-`role` TEXT
-)
+`mail` TEXT,
+`role` TEXT,
+`lead` BOOLEAN DEFAULT 0,
+`owner` BOOLEAN DEFAULT 0
+);
CREATE TABLE users (
`uname` TEXT,
diff --git a/src/pvv/side/project.php b/src/pvv/side/project.php
index f9a9455..5985c1c 100644
--- a/src/pvv/side/project.php
+++ b/src/pvv/side/project.php
@@ -2,15 +2,12 @@
namespace pvv\side;
class Project{
- private $id, $name, $owner, $owneruname, $owneremail, $descr, $active;
+ private $id, $name, $descr, $active;
- public function __construct($id, $name, $descr, $owner, $owneruname, $owneremail, $active){
+ public function __construct($id, $name, $descr, $active){
$this->id = $id;
$this->name = $name;
$this->descr = explode("\n", $descr);
- $this->owner = $owner;
- $this->owneruname = $owneruname;
- $this->owneremail = $owneremail;
$this->active = $active;
}
@@ -26,18 +23,6 @@ class Project{
return $this->descr;
}
- public function getOwner(){
- return $this->owner;
- }
-
- public function getOwnerUName(){
- return $this->owneruname;
- }
-
- public function getOwnerEmail(){
- return $this->owneremail;
- }
-
public function getActive(){
return $this->active;
}
diff --git a/src/pvv/side/projectmanager.php b/src/pvv/side/projectmanager.php
index e5d39bd..c09bbca 100644
--- a/src/pvv/side/projectmanager.php
+++ b/src/pvv/side/projectmanager.php
@@ -21,9 +21,6 @@ class ProjectManager{
$dbProj['id'],
$dbProj['name'],
$dbProj['description'],
- $dbProj['owner'],
- $dbProj['owneruname'],
- $dbProj['owneremail'],
$dbProj['active']
);
$projects[] = $project;
@@ -43,33 +40,37 @@ class ProjectManager{
$dbProj['id'],
$dbProj['name'],
$dbProj['description'],
- $dbProj['owner'],
- $dbProj['owneruname'],
- $dbProj['owneremail'],
$dbProj['active']
);
return $project;
}
- public function getByUName($uname){
- $query = 'SELECT * FROM projects WHERE owneruname=:uname';
+ public function getByOwner($uname){
+ $query = 'SELECT projectid FROM projectmembers WHERE uname=:uname';
$statement = $this->pdo->prepare($query);
$statement->bindParam(':uname', $uname, PDO::PARAM_STR);
$statement->execute();
+ $projectIDs = $statement->fetchAll();
$projects = [];
- foreach($statement->fetchAll() as $dbProj){
- $project = new Project(
- $dbProj['id'],
- $dbProj['name'],
- $dbProj['description'],
- $dbProj['owner'],
- $dbProj['owneruname'],
- $dbProj['owneremail'],
- $dbProj['active']
- );
- $projects[] = $project;
+ foreach($projectIDs as $id){
+ $id = $id['projectid'];
+
+ $query = 'SELECT * FROM projects WHERE id=:id';
+ $statement = $this->pdo->prepare($query);
+ $statement->bindParam(':id', $id, PDO::PARAM_INT);
+ $statement->execute();
+
+ foreach($statement->fetchAll() as $dbProj){
+ $project = new Project(
+ $dbProj['id'],
+ $dbProj['name'],
+ $dbProj['description'],
+ $dbProj['active']
+ );
+ $projects[] = $project;
+ }
}
return $projects;
@@ -83,9 +84,35 @@ class ProjectManager{
$members = [];
foreach($statement->fetchAll() as $dbUsr){
- $members[] = ['name' => $dbUsr['name'], 'uname' => $dbUsr['uname'], 'role' => $dbUsr['role']];
+ $members[] = [
+ 'name' => $dbUsr['name'],
+ 'uname' => $dbUsr['uname'],
+ 'mail' => $dbUsr['mail'],
+ 'role' => $dbUsr['role'],
+ 'lead' => $dbUsr['lead'],
+ 'owner' => $dbUsr['owner']
+ ];
}
return $members;
}
+
+ public function getProjectOwner($id){
+ $query = 'SELECT * FROM projectmembers WHERE (projectid=:id AND owner=1)';
+ $statement = $this->pdo->prepare($query);
+ $statement->bindParam(':id', $id, PDO::PARAM_STR);
+ $statement->execute();
+
+ $dbOwner = $statement->fetch();
+ $owner = [
+ 'name' => $dbOwner['name'],
+ 'uname' => $dbOwner['uname'],
+ 'mail' => $dbOwner['mail'],
+ 'role' => $dbOwner['role'],
+ 'lead' => $dbOwner['lead'],
+ 'owner' => $dbOwner['owner']
+ ];
+
+ return $owner;
+ }
}
\ No newline at end of file
diff --git a/www/admin/prosjekter/edit.php b/www/admin/prosjekter/edit.php
index b509ce7..486a0b8 100644
--- a/www/admin/prosjekter/edit.php
+++ b/www/admin/prosjekter/edit.php
@@ -48,13 +48,24 @@ $project = new \pvv\side\Project(
if($new == 0){
$project = $projectManager->getByID($projectID);
}
+
+$members = $projectManager->getProjectMembers($projectID);
+$owner = [
+ 'name' => '',
+ 'uname' => '',
+ 'mail' => '',
+];
+foreach($members as $i => $data){
+ if($data['owner']){
+ $owner = $data;
+ }
+}
?>
-
@@ -82,13 +93,13 @@ if($new == 0){
Prosjektleder (Brukernavn)
- = '
' ?>
+ = '
' ?>
Prosjektleder (Navn)
- = '
' ?>
+ = '
' ?>
Prosjektleder E-post
- = '
' ?>
+ = '
' ?>
Aktiv
= '
getActive() ? 'checked' : '') . ' name="active"/>' ?>
@@ -96,6 +107,31 @@ if($new == 0){
= '
' ?>
+
+
+
+
+
+
Prosjektmedlemmer
+
+
+
+
diff --git a/www/admin/prosjekter/index.php b/www/admin/prosjekter/index.php
index 6eb471b..07a1f16 100644
--- a/www/admin/prosjekter/index.php
+++ b/www/admin/prosjekter/index.php
@@ -33,16 +33,18 @@ if(isset($_POST['title'])){
$filterTitle = $_POST['title'];
}
+/* Temporarily out of service :<
$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()));
+ function($project) use ($filterTitle){
+ return (preg_match('/.*'.$filterTitle.'.*/i', $project->getName()));
}
));
?>
@@ -82,13 +84,14 @@ $projects = array_values(array_filter(
$project = $projects[$i];
$projectID = $project->getID();
+ $owner = $projectManager->getProjectOwner($projectID);
?>
= $project->getName() . " (ID: " . $projectID . ")"; ?>
-
= 'Organisert av: ' . $project->getOwner(); ?>
+
= 'Organisert av: ' . $owner['name']; ?>
= implode($project->getDescription(), "
"); ?>
@@ -124,7 +127,7 @@ $projects = array_values(array_filter(
Prosjektnavn
= '
' ?>
Leders brukernavn
- = '
' ?>
+ = '
' ?>
diff --git a/www/admin/prosjekter/update.php b/www/admin/prosjekter/update.php
index 8bde074..0ee20da 100644
--- a/www/admin/prosjekter/update.php
+++ b/www/admin/prosjekter/update.php
@@ -30,36 +30,49 @@ if(isset($_POST['id'])){
$title = $_POST['title'];
$desc = $_POST['desc'];
-$owner = $_POST['organisername'];
+$name = $_POST['organisername'];
$uname = $_POST['organiser'];
-$email = $_POST['organiseremail'];
+$mail = $_POST['organiseremail'];
$active = (isset($_POST['active']) ? $_POST['active'] : 0);
$statement;
if($id == 0){
- $query = 'INSERT INTO projects (name, owner, owneruname, owneremail, description, active) VALUES (:title, :owner, :uname, :email, :desc, :active)';
+ $query = 'INSERT INTO projects (name, description, active) VALUES (:title, :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(':email', $email, PDO::PARAM_STR);
$statement->bindParam(':active', $active, PDO::PARAM_INT);
+
+ $statement->execute();
+
+ $ownerQuery = 'INSERT INTO projectmembers (projectid, name, uname, mail, role, lead, owner) VALUES (last_insert_rowid(), :owner, :owneruname, :owneremail, \'Prosjektleder\', 1, 1)';
+ $statement = $pdo->prepare($ownerQuery);
+ $statement->bindParam(':owner', $name, PDO::PARAM_STR);
+ $statement->bindParam(':owneruname', $uname, PDO::PARAM_STR);
+ $statement->bindParam(':owneremail', $mail, PDO::PARAM_STR);
+
+ $statement->execute();
}else{
- $query = 'UPDATE projects SET name=:title, owner=:owner, owneruname=:uname, owneremail=:email, description=:desc, active=:active WHERE id=:id';
+ $query = 'UPDATE projects SET name=:title, 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(':email', $email, PDO::PARAM_STR);
$statement->bindParam(':active', $active, PDO::PARAM_INT);
$statement->bindParam(':id', $id, PDO::PARAM_INT);
-}
-$statement->execute();
+ $statement->execute();
+
+ $query = 'UPDATE projectmembers SET name=:name, uname=:uname, mail=:mail';
+ $statement = $pdo->prepare($query);
+
+ $statement->bindParam(':name', $name, PDO::PARAM_STR);
+ $statement->bindParam(':uname', $uname, PDO::PARAM_STR);
+ $statement->bindParam(':mail', $mail, PDO::PARAM_STR);
+
+ $statement->execute();
+}
header('Location: .');
?>
diff --git a/www/prosjekt/edit.php b/www/prosjekt/edit.php
index 8326f6d..2ef1268 100644
--- a/www/prosjekt/edit.php
+++ b/www/prosjekt/edit.php
@@ -33,13 +33,14 @@ $project = new \pvv\side\Project(
'',
$attrs["cn"][0],
$attrs["uid"][0],
- $attrs["email"][0],
+ $attrs["mail"][0],
1
);
if($new == 0){
$project = $projectManager->getByID($projectID);
+ $owner = $projectManager->getProjectOwner($projectID);
- if($project->getOwnerUName() != $attrs["uid"][0]){
+ if($owner['uname'] != $attrs["uid"][0]){
header('HTTP/1.0 403 Forbidden');
echo "wrong user";
exit();
diff --git a/www/prosjekt/index.php b/www/prosjekt/index.php
index 04a360c..32828b1 100644
--- a/www/prosjekt/index.php
+++ b/www/prosjekt/index.php
@@ -49,6 +49,7 @@ $projects = $projectManager->getAll();
};
foreach($randProjects as $i) {
$project = $projects[$i];
+ $owner = $projectManager->getProjectOwner($project->getID());
?>
@@ -56,7 +57,7 @@ $projects = $projectManager->getAll();
= $project->getName(); ?>
= $project->getDescription()[0]; ?>
-
Organisert av
= $project->getOwner(); ?>
+
Organisert av
= $owner['name']; ?>
getProjectMembers($projectID);
Prosjektledelse
-
Prosjekteier
-
= $project->getOwner() ?>
-
= $project->getOwnerUName(); ?>
-
= $project->getOwnerEmail(); ?>
+ $data){
+ if($data['lead']){
+ ?>
+
= $data['role'] ?>
+
= $data['name']; ?>
+
= $data['uname']; ?>
+
= $data['mail']; ?>
+
Medlemmer
- $data){ ?>
+ $data){
+ if($data['lead']){ continue; }
+ ?>
-
= $data['role'] ?>
-
= $data['name'] ?>
-
= $data['uname'] ?>
+
= $data['role'] ? $data['role'] : 'Deltaker' ?>
+
= $data['name']; ?>
+
= $data['uname']; ?>
diff --git a/www/prosjekt/mine.php b/www/prosjekt/mine.php
index 653c632..21b48dc 100644
--- a/www/prosjekt/mine.php
+++ b/www/prosjekt/mine.php
@@ -13,7 +13,7 @@ $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]);
+$projects = $projectManager->getByOwner($attrs['uid'][0]);
$page = 1;
if(isset($_GET['page'])){
@@ -25,92 +25,92 @@ 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()));
+ function($project) use ($filterTitle){
+ return (preg_match('/.*'.$filterTitle.'.*/i', $project->getName()));
}
));
?>
-
-
-
-
-
+
+
+
+
+
+
+
-
+
+
-
+
+
+
Mine Prosjekter
-
-
-
Mine Prosjekter
+
+
- getID();
+ ?>
- $project = $projects[$i];
- $projectID = $project->getID();
- ?>
-
- -
-
-
-
-
= implode($project->getDescription(), "
"); ?>
+
-
+
+
+
+
= implode($project->getDescription(), "
"); ?>
+
-
-
+
+
+
+
Forrige side';
+ }
+
+ if(($counter == $pageLimit) and (($pageLimit * $page) < count($projects))){
+ echo '
Neste side';
}
?>
-
+
- Forrige side';
- }
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/www/prosjekt/update.php b/www/prosjekt/update.php
index 27583de..b5af3b7 100644
--- a/www/prosjekt/update.php
+++ b/www/prosjekt/update.php
@@ -21,33 +21,38 @@ $active = $_POST['active'];
$title = $_POST['title'];
$desc = $_POST['desc'];
-$owner = $attrs['cn'][0];
-$owneruname = $attrs['uid'][0];
-$owneremail = $attrs['mail'][0];
+$name = $attrs['cn'][0];
+$uname = $attrs['uid'][0];
+$mail = $attrs['mail'][0];
$statement;
if($id == 0){
- $query = 'INSERT INTO projects (name, owner, owneruname, owneremail, description, active) VALUES (:title, :owner, :owneruname, :owneremail, :desc, 1)';
+ $query = 'INSERT INTO projects (name, description, active) VALUES (:title, :desc, 1)';
$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(':owneruname', $owneruname, PDO::PARAM_STR);
- $statement->bindParam(':owneremail', $owneremail, PDO::PARAM_STR);
+
+ $statement->execute();
+
+ // there's a better way to do this. i just don't know it right now
+ $ownerQuery = 'INSERT INTO projectmembers (projectid, name, uname, mail, role, lead, owner) VALUES (last_insert_rowid(), :owner, :owneruname, :owneremail, \'Prosjektleder\', 1, 1)';
+ $statement = $pdo->prepare($ownerQuery);
+ $statement->bindParam(':owner', $name, PDO::PARAM_STR);
+ $statement->bindParam(':owneruname', $uname, PDO::PARAM_STR);
+ $statement->bindParam(':owneremail', $mail, PDO::PARAM_STR);
+
+ $statement->execute();
}else{
- $query = 'UPDATE projects SET name=:title, owner=:owner, owneruname=:owneruname, owneremail=:owneremail, description=:desc WHERE id=:id';
+ $query = 'UPDATE projects SET name=:title, description=:desc 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(':owneruname', $owneruname, PDO::PARAM_STR);
- $statement->bindParam(':owneremail', $owneremail, PDO::PARAM_STR);
$statement->bindParam(':id', $id, PDO::PARAM_INT);
-}
-$statement->execute();
+ $statement->execute();
+}
header('Location: ./mine.php');
?>