Skip to content

Commit 707169d

Browse files
seperate files and add functionality
1 parent 69ee132 commit 707169d

19 files changed

+428
-324
lines changed

app/controllers/admin.php

-120
This file was deleted.

app/controllers/admin/addbook.php

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Controller;
4+
5+
6+
class Adminadd
7+
{
8+
public function post()
9+
{
10+
\Utils\Auth::adminAuth();
11+
$_POST = json_decode(file_get_contents("php://input"), true);
12+
$bookname = $_POST["bookname"];
13+
$number = $_POST["number"];
14+
$rows = \Postlogin\Dashboard::bookSearch($bookname);
15+
if ($rows) {
16+
$updatenumber = $number + $rows[0]["number"];
17+
if (\Postlogin\Admindashboard::updateBookNumber($updatenumber, $rows[0]["id"])) {
18+
echo "book added";
19+
} else {
20+
echo "some error in book addition";
21+
}
22+
} else {
23+
if ((\Postlogin\Admindashboard::addBook($bookname, $number))) {
24+
echo "book added";
25+
} else {
26+
echo "some error in book addition";
27+
}
28+
}
29+
}
30+
}

app/controllers/admin/changestate.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Controller;
4+
5+
6+
7+
class Adminupdate
8+
{
9+
public function post()
10+
{
11+
\Utils\Auth::adminAuth();
12+
$_POST = json_decode(file_get_contents("php://input"), true);
13+
$id = $_POST["id"];
14+
$avail = $_POST["avail"];
15+
$rows=\Postlogin\Admindashboard::bookSearchbyId($id);
16+
if($rows[0]['number'] != 0){
17+
if (\Postlogin\Admindashboard::updateBooks($id, $avail)) {
18+
echo "book state changed";
19+
} else {
20+
echo "error";
21+
}
22+
}
23+
else{
24+
echo "error";
25+
}
26+
}
27+
}

app/controllers/admin/reqsearch.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Controller;
4+
5+
6+
class Adminhistory
7+
{
8+
public function get()
9+
{
10+
\Utils\Auth::adminAuth();
11+
$username = $_GET['username'];
12+
$rows = \Postlogin\Admindashboard::pastResolve($username);
13+
if ($rows) {
14+
echo \View\Loader::make()->render("templates/requests.twig", array(
15+
"requests" => $rows
16+
));
17+
} else {
18+
echo "error in admin-user search";
19+
}
20+
}
21+
}
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace Controller;
4+
5+
6+
class Admin
7+
{
8+
public function get()
9+
{
10+
\Utils\Auth::adminAuth();
11+
$rows = \Postlogin\Admindashboard::bookApprovalRender();
12+
13+
echo \View\Loader::make()->render("templates/requests.twig", array(
14+
"requests" => $rows
15+
));
16+
17+
}
18+
19+
public function post()
20+
{
21+
\Utils\Auth::adminAuth();
22+
$_POST = json_decode(file_get_contents("php://input"), true);
23+
$id = $_POST["id"];
24+
$status = $_POST["status"];
25+
$bookid = $_POST["bookid"];
26+
session_start();
27+
$username = $_SESSION["username"];
28+
if ($status == 1) {
29+
$rows = \Postlogin\Admindashboard::bookSearchbyId($bookid);
30+
if ($rows[0]["number"] == 1) {
31+
\Postlogin\Admindashboard::finishedBook($bookid);
32+
} else {
33+
\Postlogin\Admindashboard::updateBookNumber($rows[0]["number"] - 1, $bookid);
34+
}
35+
}
36+
if (\Postlogin\Admindashboard::requestResolve($id, $status, $username)) {
37+
echo "resolved";
38+
} else {
39+
echo "error in resolving";
40+
}
41+
}
42+
}

app/controllers/admin/returnadmin.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Controller;
4+
5+
6+
class Adminreturn
7+
{
8+
public function post()
9+
{
10+
\Utils\Auth::adminAuth();
11+
$_POST = json_decode(file_get_contents("php://input"), true);
12+
$id = $_POST["id"];
13+
$bookid = $_POST["bookid"];
14+
$rows = \Postlogin\Admindashboard::bookSearchbyId($bookid);
15+
if ($rows[0]["number"] == 0) {
16+
\Postlogin\Admindashboard::updateFinishedBook($rows[0]["number"] + 1, $bookid);
17+
} else {
18+
\Postlogin\Admindashboard::updateBookNumber($rows[0]["number"] + 1, $bookid);
19+
}
20+
if (\Postlogin\Admindashboard::returnBooks($id)) {
21+
echo "returned";
22+
} else {
23+
echo "error in returning";
24+
}
25+
}
26+
}

app/controllers/login.php

-85
This file was deleted.

0 commit comments

Comments
 (0)