diff --git a/.htaccess b/.htaccess index 8b77547..fc31883 100644 --- a/.htaccess +++ b/.htaccess @@ -1,4 +1,5 @@ RewriteEngine on -RewriteRule ^([a-zA-Z_]+)\/((config|proj|res|script|style|subs|uploads)\/([a-zA-Z_.\/]+)?)$ /$2 [L,R] -RewriteRule ^(config|mailer|proj|res|script|style|subs|uploads|websvn)\/?(.)+?$ - [L] +RewriteRule ^(proj)(\/(.)+?)?$ - [L] +RewriteRule ^([a-zA-Z_]+)\/((config|proj|res|script|style|subs|uploads)(\/([a-zA-Z_.\/]+)?)?)$ /$2 [L,R] +RewriteRule ^(config|proj|res|script|style|subs|uploads)(\/(.)+?)?$ - [L] RewriteRule ^([a-zA-Z_]+)(\/([a-zA-Z0-9_:]+))?\/?$ index.php?view=$1&sub=$3 [L,QSA] diff --git a/config/database setup.sql b/config/database setup.sql index a5acaf5..d1a2637 100644 --- a/config/database setup.sql +++ b/config/database setup.sql @@ -71,7 +71,7 @@ CREATE TABLE `projects` ( `path` varchar(125) NOT NULL default '', `repo` varchar(125) NOT NULL default '', `status` varchar(65) NOT NULL default '', - `image` text NOT NULL default '', + `image` varchar(125) NOT NULL default '', PRIMARY KEY (`id`), FOREIGN KEY (`owner`) REFERENCES users(`id`) ON DELETE CASCADE ) CHARACTER SET utf8 COLLATE utf8_general_ci; diff --git a/config/lang/en_US.ini b/config/lang/en_US.ini index c5bd0ef..8148af7 100644 --- a/config/lang/en_US.ini +++ b/config/lang/en_US.ini @@ -114,6 +114,7 @@ projectlist="Project list" description="Description" path="Path" repository="Repository" +image="Image" ;Errors error[1]="Wrong username or password!" @@ -146,3 +147,4 @@ message[11]="Shipping information successfully deleted." message[12]="Your profile has been deleted successfully. You won't be able to log in anymore. This process is irreversible." message[13]="Request submitted successfully. Please be patient!" message[14]="That's done, bro!" +message[15]="Project successfully created." diff --git a/config/lang/hu_HU.ini b/config/lang/hu_HU.ini index afdcf91..9382fe7 100644 --- a/config/lang/hu_HU.ini +++ b/config/lang/hu_HU.ini @@ -114,6 +114,7 @@ projectlist="Projekt lista" description="Leírás" path="Útvonal" repository="Repó" +image="Kép" ;Errors error[1]="Hibás felhasználónév vagy jelszó!" @@ -146,3 +147,4 @@ message[11]="Kiszállítási cím sikeresen törölve." message[12]="A profilod sikeresen törölve. Többször nem tudsz majd belépni. Ez visszafordíthatatlan." message[13]="Kérés sikeresen létrehozva. Kérlek légy türelemmel!" message[14]="Kész van!" +message[15]="Projeck sikeresen létrehozva." diff --git a/script/projects.js b/script/projects.js index ac1297d..7f10d2d 100644 --- a/script/projects.js +++ b/script/projects.js @@ -28,16 +28,19 @@ function loadProjects(){ type: "GET", data: {"load":"projects", "backend":true, "getprojects":true}, success: function(response){ + console.log(response); var projects=(response instanceof Object)?response:JSON.parse(response); $.each(projects, function(i, val){ var cur=(val instanceof Object)?val:JSON.parse(val); - var el=$("
"); - var content=""+cur.description+"
status: "+cur.status+", by: "+cur.owner+"
"; + el.html(content); el.hide().appendTo("#projects").slideDown(); }); diff --git a/script/userarea.js b/script/userarea.js index 8c4c21d..d7c6c56 100644 --- a/script/userarea.js +++ b/script/userarea.js @@ -722,3 +722,77 @@ function requestProfileData(){ }); } } + + +/* + * Projects + */ +function projectsNew(){ + $("#projectEditor")[0].reset(); + $("#editor").slideDown(); + $("#project_id").val("new"); +} + +function projectsSave(){ + $.ajax({ + url: "/subs/loader.php?load=userarea&backend", + type: "POST", + data: $("#projectEditor").serialize(), + success: function(response){ + loadMessage(); + if(response!="err"){ + $("#editor").slideUp(function(){ + $("#projectEditor")[0].reset(); + }); + } + } + }); +} + +function projectsEditCancel(){ + $("#editor").slideUp(function(){ + $("#projectEditor")[0].reset(); + }); +} + +function projectsEdit(id){ + $.ajax({ + url: "/subs/loader.php", + type: "GET", + data: {"load": "userarea", "backend": true, "projects_get": id}, + success: function(response){ + loadMessage(); + if(response!="err"){ + var cur=(response instanceof Object)?response:JSON.parse(response); + + $("#project_id").val(cur.id); + $("[name=project_name").val(cur.name); + $("[name=project_desc").val(cur.description); + $("[name=project_path").val(cur.path); + $("[name=project_repo").val(cur.repo); + $("[name=project_status").val(cur.status); + $("[name=project_image").val(cur.image); + + $("#editor").slideDown(); + } + } + }); +} + +function projectsDelete(id, el){ + if(confirm($("#langSure").text())){ + $.ajax({ + url: "/subs/loader.php?load=userarea&backend", + type: "POST", + data: {"projects_delete": id}, + success: function(response){ + loadMessage(); + if(response=="ok"){ + $(this).parent("td").parent("tr").css("background", "red").fadeOut(function(){ + $(this).remove(); + }); + } + } + }); + } +} \ No newline at end of file diff --git a/style/main.css b/style/main.css index ee93662..f21f08f 100644 --- a/style/main.css +++ b/style/main.css @@ -293,6 +293,7 @@ div.tileset div.tile{ div.tile .imgholder{ width: 90%; height: 9em; + margin: auto; } div.tile img{ diff --git a/subs/parts/projects_backend.php b/subs/parts/projects_backend.php index 5ce1b14..78c67e4 100644 --- a/subs/parts/projects_backend.php +++ b/subs/parts/projects_backend.php @@ -24,14 +24,15 @@ **/ if(isset($_GET['getprojects'])){ - $sql=$db->prepare("SELECT p.id, p.name, p.description, u.username, p.path, p.repo, p.status, p.image FROM projects AS p INNER JOIN users AS u ON (u.id=p.owner) ORDER BY id DESC"); + $sql=$db->prepare("SELECT p.id, p.name, p.description, u.fullname AS owner, p.path, p.repo, p.status, p.image FROM projects AS p INNER JOIN users AS u ON (u.id=p.owner) ORDER BY p.name ASC"); $sql->execute(); - + $projects=array(); - + while($row=$sql->fetch(PDO::FETCH_ASSOC)){ - array_push($projects, json_encode($projects)); + array_push($projects, json_encode($row)); } - + echo json_encode($projects); + die(); } diff --git a/subs/parts/userarea.php b/subs/parts/userarea.php index ec90224..7ff7f78 100644 --- a/subs/parts/userarea.php +++ b/subs/parts/userarea.php @@ -1,7 +1,7 @@ loginPrepare(); =1): ?> =2): ?> - =3): ?> + diff --git a/subs/parts/userarea_backend.php b/subs/parts/userarea_backend.php index c4d9a49..a9e1580 100644 --- a/subs/parts/userarea_backend.php +++ b/subs/parts/userarea_backend.php @@ -41,7 +41,7 @@ else{ } if($sub!=""){ - if($sub!="fileshare" && $sub!="blog" && $sub!="projects" && $sub!="orders" && $sub!="messages" && $sub!="news" && $sub!="admin" && $sub!="profile"){ + if($sub!="fileshare" && $sub!="blog" && $sub!="orders" && $sub!="messages" && $sub!="news" && $sub!="projects" && $sub!="admin" && $sub!="profile"){ functions::setError(500); header("Location: /userarea"); } @@ -49,11 +49,11 @@ else{ functions::setError(500); header("Location: /userarea"); } - if(($sub=="projects" || $sub=="orders" || $sub=="messages") && $_SESSION['accesslevel']<2){ + if(($sub=="orders" || $sub=="messages") && $_SESSION['accesslevel']<2){ functions::setError(500); header("Location: /userarea"); } - if(($sub=="news" || $sub=="admin") && $_SESSION['accesslevel']<3){ + if(($sub=="news" || $sub=="projects" || $sub=="admin") && $_SESSION['accesslevel']<3){ functions::setError(500); header("Location: /userarea"); } @@ -706,5 +706,66 @@ else{ } } } - -} + + + /* + * PROJECTS + */ + //get a project by id + if(isset($_GET['projects_get'])){ + $sql=$db->prepare("SELECT p.id, p.name, p.description, u.fullname AS owner, p.path, p.repo, p.status, p.image FROM projects AS p INNER JOIN users AS u ON (u.id=p.owner) WHERE p.id=:id"); + $sql->execute(array(":id"=>$_GET['projects_get'])); + $res=$sql->fetch(PDO::FETCH_ASSOC); + + echo json_encode($res); + die(); + } + + //save project + if(isset($_POST['project_id']) && isset($_POST['project_name']) && isset($_POST['project_desc']) && isset($_POST['project_path']) && isset($_POST['project_repo']) && isset($_POST['project_status']) && isset($_POST['project_image'])){ + if($_POST['project_id']=="new"){ + $sql=$db->prepare("INSERT INTO projects (name, description, owner, path, repo, status, image) VALUES (:name, :desc, :owner, :path, :repo, :status, :image)"); + $sql->execute(array(":name"=>$_POST['project_name'], ":desc"=>$_POST['project_desc'], ":owner"=>$_SESSION['id'], ":path"=>$_POST['project_path'], ":repo"=>$_POST['project_repo'], ":status"=>$_POST['project_status'], ":image"=>$_POST['project_image'])); + $res=$sql->rowCount(); + + if($res<1){ + functions::setError(6); + echo "err"; + } + else{ + functions::setMessage(15); + echo "ok"; + } + } + else{ + $sql=$db->prepare("UPDATE projects SET name=:name, description=:desc, path=:path, repo=:repo, status=:status, image=:image WHERE id=:id"); + $sql->execute(array(":name"=>$_POST['project_name'], ":desc"=>$_POST['project_desc'], ":path"=>$_POST['project_path'], ":repo"=>$_POST['project_repo'], ":status"=>$_POST['project_status'], ":image"=>$_POST['project_image'], ":id"=>$_POST['project_id'])); + $res=$sql->rowCount(); + + if($res<1){ + functions::setError(6); + echo "err"; + } + else{ + functions::setMessage(4); + echo "ok"; + } + } + } + + //delete project + if(isset($_POST['project_delete'])){ + $sql=$db->prepare("DELETE FROM projects WHERE id=:id"); + $sql->execute(array(":id"=>$_POST['project_delete'])); + $res=$sql->rowCount(); + + if($res<1){ + functions::setError(6); + echo "err"; + } + else{ + functions::setMessage(5); + echo "ok"; + } + } +} \ No newline at end of file