Skip to content

Commit b930741

Browse files
authored
City Library v2020.12.29
Front end templates with API to city library database
1 parent a06ba1e commit b930741

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2901
-0
lines changed

Frontend/addDocument.php

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
require_once('util/htmlUtil.php');
3+
require_once('util/sqlUtil.php');
4+
session_start();
5+
if(isset($_SESSION["admin_logged"])&&$_SESSION["admin_logged"]){
6+
if(isset($_SESSION["admin"]) && isset($_SESSION["password"])){
7+
$admin = $_SESSION["admin"];
8+
$password = $_SESSION["password"];
9+
$sql = new SQL();
10+
if(gettype($result = $sql->execute("SELECT * FROM ADMIN WHERE Id='$admin' AND Password='$password'"))=="array"){
11+
if(sizeof($result)>0){
12+
$title = "Admin: $admin | Add Document Copy"; $body = new Body();
13+
function getBranchOptions(){
14+
global $sql;
15+
$rows = $sql->execute("SELECT BId,Name From BRANCH");
16+
$branches="";
17+
$i=0;
18+
foreach($rows as $key=>$value){
19+
$branches.="<option value='".$value[0]."' ".((0==$i++)?"selected":" ").">".$value[1]."</option>";
20+
}
21+
return($branches);
22+
}
23+
$addReaderComponents = ("
24+
<div class='container reader' style='min-height: 80vh;'>
25+
<div class='row'>
26+
<div class='col'>
27+
<h2>Add Document Copy</h2>
28+
<form class='form' method='post' action='./documentAdd.php'>
29+
<div>
30+
<label for='dname'>Document Title*</label><input id='dname' type='text' name='dname' required/>
31+
</div>
32+
<div>
33+
<label for='pdate'> Published Date *</label><input id='pdate' type='date' name='pdate' required/>
34+
</div>
35+
<div>
36+
<label for='bid'>Type</label>
37+
<select id='bid' type='text' name='bid'>".getBranchOptions()."</select>
38+
</div>
39+
<div>
40+
<label for='position'>Position Shelf</label><br>
41+
<input id='position' type='text' name='position' required/>
42+
</div>
43+
<div>
44+
<label for='pubname'>Publisher Name</label><br>
45+
<input id='pubname' type='text' name='pubname' required/>
46+
</div>
47+
<div>
48+
<label for='pubaddress'>Publisher Address</label><br>
49+
<textarea name='pubaddress' id='pubaddress' required></textarea>
50+
</div>
51+
<div><button type='submit' class='button-green'>Add Document</button></div>
52+
</form>
53+
</div>
54+
</div>
55+
</div>
56+
<style>
57+
.reader input{
58+
border: 1px solid black;
59+
margin-bottom: 20px;
60+
margin-left: 20px;
61+
}
62+
.button-green{
63+
margin: 30px;
64+
padding: 10px 20px;
65+
}
66+
</style>
67+
");
68+
$html = new HtmlDocument("City Library | $title", $body->getBody($addReaderComponents));
69+
$html->setStyle($styleComponent->getCode()); $html->setScript($scriptComponent->getCode());
70+
$html->printHTML();
71+
}
72+
}else{echo "<html><head><title>City Library | Access Denied</title></head><body>Access Denied</body><html>";}
73+
}
74+
}else{echo "<html><head><title>City Library | Access Denied</title></head><body>Access Denied</body><html>";}
75+
?>

Frontend/addReader.php

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
require_once('util/htmlUtil.php');
3+
require_once('util/sqlUtil.php');
4+
session_start();
5+
if(isset($_SESSION["admin_logged"])&&$_SESSION["admin_logged"]){
6+
if(isset($_SESSION["admin"]) && isset($_SESSION["password"])){
7+
$admin = $_SESSION["admin"];
8+
$password = $_SESSION["password"];
9+
$sql = new SQL();
10+
if(gettype($result = $sql->execute("SELECT * FROM ADMIN WHERE Id='$admin' AND Password='$password'"))=="array"){
11+
if(sizeof($result)>0){
12+
$title = "Admin: $admin | Add Reader"; $body = new Body();
13+
$addReaderComponents = ("
14+
<div class='container reader' style='min-height: 80vh;'>
15+
<div class='row'>
16+
<div class='col'>
17+
<h2>Add Reader</h2>
18+
<form class='form' method='post' action='./readerAdd.php'>
19+
<div>
20+
<label for='rname'>Name*</label><input id='rname' type='text' name='rname' required/>
21+
</div>
22+
<div>
23+
<label for='rphone'>Phone No*</label><input id='rphone' type='text' name='rphone' required/>
24+
</div>
25+
<div>
26+
<label for='raddress'>Address</label><br>
27+
<textarea id='raddress' type='text' name='raddress'></textarea>
28+
</div>
29+
<div>
30+
<label for='rtype'>Type</label>
31+
<select id='rtype' type='text' name='rtype'>
32+
<option value='student'>STUDENT</option>
33+
<option value='reader' selected>Normal Reader</option>
34+
<option value='senior'>SENIOR CITZEN</option>
35+
<option value='staff'>STAFF</option>
36+
</select>
37+
</div>
38+
<div>
39+
<button type='submit' class='button-green'>Add Reader</button>
40+
</div>
41+
</form>
42+
</div>
43+
</div>
44+
</div>
45+
<style>
46+
.reader input{
47+
border: 1px solid black;
48+
margin-bottom: 20px;
49+
margin-left: 20px;
50+
}
51+
.button-green{
52+
margin: 30px;
53+
padding: 10px 20px;
54+
}
55+
</style>
56+
");
57+
$html = new HtmlDocument("City Library | $title", $body->getBody($addReaderComponents));
58+
$html->setStyle($styleComponent->getCode()); $html->setScript($scriptComponent->getCode());
59+
$html->printHTML();
60+
}
61+
}else{echo "<html><head><title>City Library | Access Denied</title></head><body>Access Denied</body><html>";}
62+
}
63+
}else{echo "<html><head><title>City Library | Access Denied</title></head><body>Access Denied</body><html>";}
64+
?>

Frontend/admin.php

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
$isAdmin = true;
3+
require_once("util/htmlUtil.php");
4+
require_once("util/sqlUtil.php");
5+
require("adminMenuComponents.php");
6+
session_start();
7+
$error=true; $admin = null; $password=null;
8+
if(!(isset($_SESSION["admin_logged"])&&$_SESSION["admin_logged"])){
9+
//Authenticating Admin
10+
if(isset($_POST["admin"]) && isset($_POST["password"])){
11+
$admin = $_POST["admin"]; $password = $_POST["password"];
12+
$sql = new SQL();
13+
if(gettype($result = $sql->execute("SELECT * FROM ADMIN WHERE Id='$admin' AND Password='$password'"))=="array"){
14+
if(sizeof($result)>0){
15+
$_SESSION["admin"] = $admin; $_SESSION["password"] = $password; $_SESSION["admin_logged"] = true;
16+
$error = false;
17+
}
18+
}
19+
}
20+
}else{
21+
if(isset($_SESSION["admin"]) && isset($_SESSION["password"])){
22+
$admin = $_SESSION["admin"]; $password = $_SESSION["password"]; $error = false;
23+
$_SESSION["admin_logged"] = true;
24+
}
25+
}
26+
27+
if(!$error)
28+
{
29+
$title = "Admin: $admin"; $body = new Body();
30+
$html = new HtmlDocument("City Library | $title", $body->getBody($adminMenuComponents->getCode()));
31+
$html->setStyle($styleComponent->getCode()); $html->setScript($scriptComponent->getCode());
32+
$html->printHTML();
33+
}else{
34+
echo "<html><head><title>City Library | Access Denied</title></head><body>Access Denied</body><html>";
35+
}
36+
?>

Frontend/adminMenuComponents.php

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
require_once("util/htmlUtil.php");
3+
$searchDocumentComponentDark = (
4+
"<div id='searchbox-container' class='container'><div class='row'>".
5+
"<div class='col-12'><form id='search-form' class='row' method='get' action='./adminSearch.php'>".
6+
"<div class='col-12 col-md-3 col-lg-2'><label for='search-box'>SEARCH</label></div>".
7+
"<div class='col-10 col-md-7 col-lg-9'><input id='search-box' name='search' type='text' pattern='([^\\x27\\x22])+' placeholder='SEARCH DOCUMENT COPY...' required/>".
8+
"<input style='display:none' id='search-type' name='type' type='text' value='Copy'/>".
9+
"</div><div class='col-2 col-md-2 col-lg-1'><button><img src='./images/magnify-glass.svg' alt='City Library | Search'/></button>".
10+
"</div></form></div></div></div>"
11+
);
12+
13+
$searchBoxComponentLight = new Component(
14+
"<section id='search-container'><div id='searchbox-container' class='container'><div class='row'><div class='col-12'>".
15+
"<form id='search-form' class='row' method='get' action='./adminSearch.php'>".
16+
"<div class='col-12 col-md-3 col-lg-2'><label for='search-box'>SEARCH</label></div>".
17+
"<div class='col-10 col-md-7 col-lg-9'><input id='search-box' name='search' type='text' pattern='([^\\x27\\x22])+' placeholder='SEARCH DOCUMENT COPY...' required/>".
18+
"<input style='display:none' id='search-type' name='type' type='text' value='Copy'/>".
19+
"</div><div class='col-2 col-md-2 col-lg-1'><button><img src='./images/magnify-glass.svg' alt='City Library | Search'/></button></div></form></div></div></div></section>"
20+
);
21+
22+
class AdminCard{
23+
private $TagLetter, $CardTitle, $CardBody,$Link;
24+
function __construct($tagLetter,$cardTitle,$cardBody, $onClickLink){
25+
$this->TagLetter = $tagLetter;
26+
$this->CardTitle = $cardTitle;
27+
$this->CardBody = $cardBody;
28+
$this->Link = $onClickLink;
29+
}
30+
function getCode(){
31+
return (
32+
"<div class='row p-4 h-100'><div class='col submenu-card h-90'><div><div class='submenu-card-head'>".
33+
"<div>".$this->TagLetter."</div></div><div class='submenu-card-body'><div class='text-center p-4'>".
34+
"<h3 class='m-1'>".$this->CardTitle."</h3><p class='p-2 text-body'>".$this->CardBody."</p>".
35+
"<a href='".$this->Link."' style='text-decoration:none;'><button class='button-black'>SHOW</button></div></div></div></div></div></a>"
36+
);
37+
}
38+
}
39+
$addDocumentCard = new AdminCard("+","Add Document Copy","Adds new Document Copy to the City Library Collection", "./addDocument.php");
40+
$PrintBranchInfoCard = new AdminCard("P","Show Branches","Prints all Branch Information by Name and Location", "./adminSearch.php?type=Branch&all=true");
41+
$addReaderCard = new AdminCard("+","Add Readers","Register a new Reader in the City Library Database", "./addReader.php");
42+
$commonSubsetMenu = (
43+
"<section id='reader-submenu'><div id='submenu-set' class='container h-100'><div class='row h-100'>".
44+
"<div class='col-12 col-md h-100'>".$addReaderCard->getCode()."</div>".
45+
"<div class='col-12 col-md h-100'>".$PrintBranchInfoCard->getCode()."</div>".
46+
"<div class='col-12 col-md h-100'>".$addDocumentCard->getCode()."</div>".
47+
"</div></div></section><div class='hr-grey' style='width: 75%'></div>"
48+
);
49+
$adminMenuComponents = new Component(
50+
"<main id='admin'><section id='cover-search'><div id='admin-background'></div>".$searchDocumentComponentDark."</section>".
51+
"<section id='tag-line'><div id='reader-tag-line' class='container-fluid'><div class='row'>".
52+
"<div class='display-none-md col-md-5'><div class='pl-5'><div class='reader-decor-dash'></div>".
53+
"<div class='reader-decor-dash' style='background-color: black'></div><div class='reader-decor-dash'></div>".
54+
"</div></div><div class='col-12 col-md-7'><h2>WELCOME TO THE WORLD OF READING</h2></div></div></div></section>".
55+
$commonSubsetMenu."<div class='text-center m-4'><a style='font-size:2rem' href='./getQueries.php'>Queries <small>New!!</a></small></div>".
56+
"</main>"
57+
);
58+
?>

Frontend/adminSearch.php

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!--
2+
PROJECT: CS631 - CITY LIBRARY PROJECT
3+
PROJECT TEAM: Aarjavi D, Prem K, Rahul Putcha Gautham
4+
-->
5+
<?php
6+
$isAdmin = true;
7+
require_once("util/htmlUtil.php");
8+
require("adminSearchPage.php");
9+
10+
session_start();
11+
$error = false;
12+
if((isset($_SESSION["reader_logged"])&&$_SESSION["reader_logged"]) ||
13+
(isset($_SESSION["admin_logged"])&&$_SESSION["admin_logged"])){
14+
if(isset($_GET["type"])){
15+
if(isset($_GET["search"])){
16+
$title = "SEARCH | ".$_GET["type"].": ".$_GET["search"];
17+
}else if(isset($_GET["all"])&&$_GET["all"]=="true"){
18+
$title = "SEARCH | All ".$_GET["type"];
19+
}else{$error = true;}
20+
}else{$error = true;}
21+
22+
if(!$error){
23+
$body = new Body();
24+
$html = new HtmlDocument("City Library | $title", $body->getBody($searchPageComponent->getCode()));
25+
$html->setStyle($styleComponent->getCode());
26+
$html->setScript($scriptComponent->getCode());
27+
$html->printHTML();
28+
}else{
29+
$html = new HtmlDocument("City Library | 404 Not Found", "404 Not Found");
30+
$html->printHTML();
31+
}
32+
}else{
33+
$html = new HtmlDocument("City Library | SEARCH", "Access Denied");
34+
$html->printHTML();
35+
}
36+
?>

Frontend/adminSearchPage.php

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
require_once("util/htmlUtil.php");
3+
require_once("util/sqlUtil.php");
4+
require_once("adminMenuComponents.php");
5+
/* --- Search Page --- */
6+
7+
8+
9+
class Search{
10+
private $type, $filter;
11+
public function __construct($type, $filter){
12+
$this->type = $type;
13+
$this->filter = $filter; //for get All: filter==null
14+
15+
}
16+
public function getCode(){
17+
$searchResult = $this->getInstances();
18+
global $searchBoxComponentLight, $commonSubsetMenu;
19+
return (new Component(
20+
"<main id='search-page'>".$searchBoxComponentLight->getCode().
21+
"<section id='search-results'><div id='search-result-container' class='container h-100'>".
22+
"<div class='hr-grey' style='width:100%'></div>".
23+
"<div class='row'><div class='col p-3'>SEARCH RESULTS</div></div>".
24+
"<div class='row h-100 pt-5 pb-5'><div class='col h-100'>".
25+
(($searchResult!=null)?$searchResult:"<p class='m-1 p-4 text-center bg-light'>No Results</p>").
26+
"</div></div></div></section><div class='hr-grey' style='width: 75%'></div>".$commonSubsetMenu."</main>"
27+
));
28+
}
29+
30+
private function getInstances(){
31+
$sql = new SQL();
32+
$searchResult="";
33+
$result = array();
34+
if($this->type==="Branch"){
35+
if($this->filter){
36+
$result = $sql->execute("SELECT BId, Name, Location FROM BRANCH WHERE BId like '".$this->filter."' OR Name like'".$this->filter."' OR Location like '".$this->filter."'");
37+
}else{$result = $sql->execute("SELECT BId, Name, Location FROM BRANCH");}
38+
foreach($result as $key=>$value) {$searchResult .= $this->getBranchInstance($value[0],$value[1],$value[2]);}
39+
}else if($this->type==="Copy"){
40+
41+
if($this->filter){
42+
$result = $sql->execute(
43+
"SELECT DISTINCT DocId, CopyNo, Title, PubName, Position, Name, Location FROM (BRANCH NATURAL JOIN COPY NATURAL JOIN DOCUMENT NATRUAL JOIN PUBLISHER) WHERE DocId like '%".
44+
$this->filter."%' OR Title like '%".$this->filter."%'"
45+
);
46+
}else{
47+
$result = $sql->execute(
48+
"SELECT DISTINCT DocId, CopyNo, Title, PubName, Position, Name, Location FROM (BRANCH NATURAL JOIN COPY NATURAL JOIN DOCUMENT NATRUAL JOIN PUBLISHER)"
49+
);
50+
}
51+
foreach($result as $key=>$value) {
52+
$searchResult .= $this->getCopyInstance($value[0],$value[1],$value[2],$value[3],$value[4],$value[5],$value[6]);
53+
}
54+
55+
return ($searchResult);
56+
}else{
57+
return null;
58+
}
59+
60+
return ($searchResult);
61+
}
62+
63+
private function getCopyInstance($DocId, $CopyNo, $DocName, $PublisherName, $Position, $BName, $Location) {
64+
return (
65+
"<div class='row m-1 p-4 search-instance' style='background-color:#e4e4e4'>".
66+
"<div class='col-12 col-md-2 col-lg-2'>DocumentId: $DocId</div>".
67+
"<div class='col-12 col-md-2 col-lg-2'>CopyNo: $CopyNo</div>".
68+
"<div class='col-12' style='text-transform:uppercase'>".
69+
"<p style='font-size:1.5rem'>$DocName By <small>$PublisherName</small></p>".
70+
"<p style='font-size:1.5rem'>Position : $Position <br/> stored in the $BName, $Location Branch</p>".
71+
"</div>".
72+
"</div>"
73+
);
74+
}
75+
76+
private function getBranchInstance($BId,$BName,$Location) {
77+
return (
78+
"<div class='row m-1 p-4 search-instance' style='background-color:#e4e4e4'>".
79+
"<div class='col-12 col-md-1 col-lg-1'>$BId</div>".
80+
"<div class='col-12 col-md-5 col-lg-6' style='text-transform:uppercase'>".
81+
"<p style='font-size:1.5rem'>'$BName' &nbsp;<small>$Location</small></p>".
82+
"</div>".
83+
"</div>"
84+
);
85+
}
86+
}
87+
88+
$searchPageComponent = (isset($_GET["type"]))?(
89+
((isset($_GET["all"]))?((new Search($_GET["type"],null))->getCode()):((new Search($_GET["type"],$_GET["search"]))->getCode()))
90+
):"";
91+
92+
?>

0 commit comments

Comments
 (0)