Skip to content

Commit

Permalink
Assignment-1
Browse files Browse the repository at this point in the history
  • Loading branch information
omarmagdy217 committed Nov 9, 2018
1 parent 2b5ab66 commit a061047
Show file tree
Hide file tree
Showing 45 changed files with 33,992 additions and 0 deletions.
Binary file added assignment-1/ascending.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions assignment-1/components/head.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="./images/favicon.ico">

<title>SIS - School Information System</title>

<!-- Bootstrap core CSS -->
<link href="./css/bootstrap.min.css" rel="stylesheet">

<!-- Custom styles for this template -->
<link href="./css/sticky-footer-navbar.css" rel="stylesheet">

<script src="./js/jquery-3.3.1.min.js"></script>

<link href="./jqueryUI/jquery-ui.css" rel="stylesheet">
<script src="./jqueryUI/jquery-ui.js"></script>
</head>

<body>

<header>
<!-- Fixed navbar -->
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
<a class="navbar-brand" href="#">SIS</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href=".">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="./students.php">Students</a>
</li>
<li class="nav-item">
<a class="nav-link" href="./courses.php">Courses</a>
</li>
<li class="nav-item">
<a class="nav-link" href="./grades.php">Grades</a>
</li>
</ul>
<form id="form" class="form-inline mt-2 mt-md-0">
<input class="form-control mr-sm-2" type="text" name="keywords" placeholder="Search" aria-label="Search" value="<?=safeGet('keywords')?>" required>
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
</header>
<script type="text/javascript">
$(document).ready(function() {
var href = document.location.href;
var sub = href.substr(href.lastIndexOf('/')+1);
if(sub.includes("courses"))
{
document.getElementById("form").setAttribute("action","./courses.php");
}
else if(sub.includes("students"))
{
document.getElementById("form").setAttribute("action","./students.php");
}
else
{
document.getElementById("form").setAttribute("action","./customview.php");
}
});
</script>
<main role="main" class="container">
16 changes: 16 additions & 0 deletions assignment-1/components/tail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
</main>

<footer class="footer">
<div class="container">
<span class="text-muted">Copyright 2018, Software Engineering Course, ASUENG.</span>
</div>
</footer>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="./js/jquery.min.js">
<script src="./js/popper.min.js"></script>
<script src="./js/bootstrap.min.js"></script>
</body>
</html>
5 changes: 5 additions & 0 deletions assignment-1/connect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
$link = mysqli_connect("localhost","root","","school");
if(mysqli_connect_error())
echo "there was an error";
?>
5 changes: 5 additions & 0 deletions assignment-1/controllers/common.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
function safeGet($name, $default = null){
return (isset($_REQUEST[$name]))?$_REQUEST[$name]:$default;
}
?>
8 changes: 8 additions & 0 deletions assignment-1/controllers/deletecourse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
include_once("../controllers/common.php");
include_once('../connect.php');
$id = safeGet('id');
$query = "DELETE FROM `courses` WHERE id = '".$id."'";
mysqli_query($link, $query);
header('Location: ../courses.php');
?>
8 changes: 8 additions & 0 deletions assignment-1/controllers/deletestudent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
include_once("../controllers/common.php");
include_once('../connect.php');
$id = safeGet('id');
$query = "DELETE FROM `students` WHERE id = '".$id."'";
mysqli_query($link, $query);
header('Location: ../students.php');
?>
14 changes: 14 additions & 0 deletions assignment-1/controllers/savecourse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
include_once("../controllers/common.php");
include_once('../connect.php');
$id = safeGet("id", 0);
if($id==0) {
$query = "INSERT INTO `courses` (`name`,`max_degree`,`study_year`) VALUES ('".mysqli_real_escape_string($link, $_POST['name'])."',
'".$_POST['max_degree']."','".$_POST['study_year']."')";
mysqli_query($link, $query);}
else {
$query = "UPDATE `courses` SET `name`= '".mysqli_real_escape_string($link, $_POST['name'])."',
`max_degree`= '".$_POST['max_degree']."',`study_year`= '".$_POST['study_year']."' WHERE id = '".$id."'";
mysqli_query($link, $query);}
header('Location: ../courses.php');
?>
13 changes: 13 additions & 0 deletions assignment-1/controllers/savestudent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
include_once("../controllers/common.php");
include_once('../connect.php');
$id = safeGet("id", 0);
if($id==0) {
$query = "INSERT INTO `students` (`name`) VALUES ('".mysqli_real_escape_string($link, $_POST['name'])."')";
mysqli_query($link, $query);}
else {
$query = "UPDATE `students` SET `name`= '".mysqli_real_escape_string($link, $_POST['name'])."'
WHERE id = '".$id."'";
mysqli_query($link, $query);}
header('Location: ../students.php');
?>
48 changes: 48 additions & 0 deletions assignment-1/courses.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
include_once('./controllers/common.php');
include_once('./components/head.php');
include_once('connect.php');
?>
<div style="padding: 10px 0px 10px 0px; vertical-align: text-bottom;">
<span style="font-size: 125%;">Courses</span>
<button class="button float-right edit_student" id="0">Add Course</button>
</div>

<table class="table table-striped">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Name</th>
<th scope="col">Max Degree</th>
<th scope="col">Study Year</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<?php
$keyword = str_replace(" ", "%", safeGet('keywords'));
$query = "SELECT * FROM courses WHERE name like '%$keyword%'";
if ($result = mysqli_query($link, $query)) {
while($row = mysqli_fetch_array($result)){
echo "<tr><td>" . $row[0]. "</td><td>" . $row[1] . "</td><td>" . $row[2] ."</td>
<td>". $row[3] ."</td>";
?>
<td>
<button class="button edit_student" id="<?=$row[0]?>">Edit</button>&nbsp;
<button class="button delete_student" id="<?=$row[0]?>">Delete</button>
</td>
</tr>
<?php }} ?>
</tbody>
</table>
<?php include_once('./components/tail.php') ?>
<script type="text/javascript">
$(document).ready(function() {
$(".edit_student").click(function(event) {
window.location.href = "editcourse.php?id="+$(this).attr('id');
});
$(".delete_student").click(function(event) {
window.location.href = "controllers/deletecourse.php?id="+$(this).attr('id');
});
});
</script>
7 changes: 7 additions & 0 deletions assignment-1/css/bootstrap.min.css

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions assignment-1/css/sticky-footer-navbar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* Sticky footer styles
-------------------------------------------------- */
html {
position: relative;
min-height: 100%;
}
body {
/* Margin bottom by footer height */
margin-bottom: 60px;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
/* Set the fixed height of the footer here */
height: 60px;
line-height: 60px; /* Vertically center the text there */
background-color: #f5f5f5;
}


/* Custom page CSS
-------------------------------------------------- */
/* Not required for template or sticky footer method. */

body > .container {
padding: 60px 15px 0;
}

.footer > .container {
padding-right: 15px;
padding-left: 15px;
}

code {
font-size: 80%;
}
34 changes: 34 additions & 0 deletions assignment-1/customview.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
include_once('./controllers/common.php');
include_once('./components/head.php');
include_once('connect.php');
?>
<div style="padding: 10px 0px 10px 0px; vertical-align: text-bottom;">
<span style="font-size: 125%;">Custom View</span>
</div>

<table class="table table-striped">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Course</th>
<th scope="col">Degree</th>
<th scope="col">Max Degree</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<?php
$keyword = str_replace(" ", "%", safeGet('keywords'));
$query = "SELECT students.name, courses.name, grades.degree, courses.max_degree FROM grades
JOIN students ON students.id = grades.student_id JOIN courses ON courses.id = grades.course_id
WHERE students.name like '%$keyword%' or courses.name like '%$keyword%'
ORDER BY students.name, courses.name";
if ($result = mysqli_query($link, $query)) {
while($row = mysqli_fetch_array($result)){
echo "<tr><td>" . $row[0]. "</td><td>" . $row[1] . "</td><td>" . $row[2] ."</td>
<td>". $row[3] ."</td></tr>";}}
?>
</tbody>
</table>
<?php include_once('./components/tail.php') ?>
8 changes: 8 additions & 0 deletions assignment-1/deletegrade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
include_once("./controllers/common.php");
include_once('connect.php');
$id = safeGet('id');
$query = "DELETE FROM `grades` WHERE `id`=$id";
mysqli_query($link,$query);
header("Location:grades.php");
?>
Binary file added assignment-1/descending.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions assignment-1/edit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
include_once('connect.php');
if(isset($_POST['edit']))
{
$grade = mysqli_real_escape_string($link,$_POST['grade']);
$student_id = mysqli_real_escape_string($link,$_POST['student']);
$course_id = mysqli_real_escape_string($link,$_POST['course']);
$date = mysqli_real_escape_string($link,$_POST['date']);
$id = $_POST['id'];
if($id == "")
{
$update = "INSERT INTO `grades` (`course_id`,`student_id`,`degree`,`examine_at`) VALUES ($course_id,$student_id,$grade,'$date')";
}
else
{
$update = "UPDATE `grades` SET `student_id`=$student_id, `course_id`=$course_id, `degree`=$grade, `examine_at`='$date' WHERE `id` = $id";
}
if(mysqli_query($link,$update))
{
header("Location:grades.php");
}
else
{
echo "There was an error, try again.";
}
}?>
42 changes: 42 additions & 0 deletions assignment-1/editcourse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
include_once("./controllers/common.php");
include_once('./components/head.php');
include_once('connect.php');
$id = safeGet('id');
$query = "SELECT * FROM courses WHERE id = '".$id."'";
if ($result = mysqli_query($link, $query)){
$row = mysqli_fetch_array($result);}
?>

<h2 class="mt-4"><?=($id)?"Edit":"Add"?> Course</h2>

<form action="controllers/savecourse.php" method="post">
<input type="hidden" name="id" value="<?=$id?>">
<div class="card">
<div class="card-body">
<div class="form-group row gutters">
<label for="inputEmail3" class="col-sm-2 col-form-label">Name</label>
<div class="col-sm-10">
<input class="form-control" type="text" name="name" value="<?=$row[1]?>" required>
</div>
</div>
<div class="form-group row gutters">
<label for="inputEmail3" class="col-sm-2 col-form-label">Max Degree</label>
<div class="col-sm-10">
<input class="form-control" type="text" name="max_degree" value="<?=$row[2]?>" required>
</div>
</div>
<div class="form-group row gutters">
<label for="inputEmail3" class="col-sm-2 col-form-label">Study Year</label>
<div class="col-sm-10">
<input class="form-control" type="text" name="study_year" value="<?=$row[3]?>" required>
</div>
</div>
<div class="form-group">
<button class="button float-right" type="submit"><?=($id)?"Edit":"Add"?></button>
</div>
</div>
</div>
</form>

<?php include_once('./components/tail.php') ?>
Loading

0 comments on commit a061047

Please sign in to comment.