Skip to content

Commit

Permalink
Merge pull request #180 from DasunThathsara/dasun
Browse files Browse the repository at this point in the history
Add admin creation for superadmin
  • Loading branch information
DasunThathsara authored Dec 9, 2023
2 parents 5b37815 + 7afcd60 commit 0fbf48f
Show file tree
Hide file tree
Showing 12 changed files with 450 additions and 24 deletions.
1 change: 1 addition & 0 deletions app/controllers/SuperAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
3 changes: 2 additions & 1 deletion app/models/LandModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,15 @@ public function sendEmail($email, $name, $subject, $message){
public function verifyLand($id): bool
{
// Get the landowner's id
$this->db->query('SELECT uid, name FROM land WHERE id = :id');
$this->db->query('SELECT * FROM land WHERE id = :id');

// Bind values
$this->db->bind(':id', $id);
$row = $this->db->single();

$uid = $row->uid;
$parking_name = $row->name;
$deed = $row->deed;

// Prepare statement
$this->db->query('UPDATE land SET status = :status WHERE id = :id');
Expand Down
70 changes: 47 additions & 23 deletions app/models/UserModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,31 @@ public function __construct(){
// Register user
public function register($data): bool
{
$name = $data['name'];
$email = $data['email'];

// Prepare statement
$this->mail->isSMTP(); //Send using SMTP
$this->mail->Host = 'smtp.gmail.com'; //Set the SMTP server to send through
$this->mail->SMTPAuth = true; //Enable SMTP authentication
$this->mail->Username = '[email protected]'; //SMTP username
$this->mail->Password = 'pcop yjvy adrx mlcl'; //SMTP password
$this->mail->Port = 587; //TCP port to connect to; use 587 if you have set SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS

//Recipients
$this->mail->setFrom('[email protected]', 'Your One-Time Password (OTP) for eZpark Registration');
$this->mail->addAddress($email, $name); //Add a recipient

//Attachments
if ($data['user_type'] != 'admin'){
$name = $data['name'];
$email = $data['email'];

// Prepare statement
$this->mail->isSMTP(); //Send using SMTP
$this->mail->Host = 'smtp.gmail.com'; //Set the SMTP server to send through
$this->mail->SMTPAuth = true; //Enable SMTP authentication
$this->mail->Username = '[email protected]'; //SMTP username
$this->mail->Password = 'pcop yjvy adrx mlcl'; //SMTP password
$this->mail->Port = 587; //TCP port to connect to; use 587 if you have set SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS

//Recipients
$this->mail->setFrom('[email protected]', 'Your One-Time Password (OTP) for eZpark Registration');
$this->mail->addAddress($email, $name); //Add a recipient

//Attachments
// $mail->addAttachment('/var/tmp/file.tar.gz'); //Add attachments
// $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); //Optional name

//Content
$this->mail->isHTML(true); //Set email format to HTML
$this->mail->Subject = 'Verification code';
$verification_code = substr(number_format(time() * rand(), 0, '', ''), 0, 6);
$this->mail->Body = '<div id="overview" style="margin: auto; width: 80%; font-size: 13px">
//Content
$this->mail->isHTML(true); //Set email format to HTML
$this->mail->Subject = 'Verification code';
$verification_code = substr(number_format(time() * rand(), 0, '', ''), 0, 6);
$this->mail->Body = '<div id="overview" style="margin: auto; width: 80%; font-size: 13px">
<p style="color: black">
Dear '.$name.',<br><br>
Expand All @@ -55,9 +56,13 @@ public function register($data): bool
eZpark Team
</p>
</div>';
$this->mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$this->mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

$this->mail->send();
$this->mail->send();
}
else{
$verification_code = '000000';
}

// Prepare statement
$this->db->query('INSERT INTO user (name, username, email, password, userType, contactNo, otp, otpTime) VALUES (:name, :username, :email, :password, :userType, :contactNo, :otp, :otpTime)');
Expand Down Expand Up @@ -325,4 +330,23 @@ public function removeProfilePhoto(): bool
return false;
}
}

// View all admins
public function viewAdmins(){
$this->db->query('SELECT * FROM user WHERE userType = "admin"');

$results = $this->db->resultSet();

return $results;
}

// View specific admin
public function viewAdmin($admin_id){
$this->db->query('SELECT * FROM user WHERE id = :id');
$this->db->bind(':id', $admin_id);

$row = $this->db->single();

return $row;
}
}
1 change: 1 addition & 0 deletions app/views/superAdmin/admins.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
1 change: 1 addition & 0 deletions app/views/superAdmin/admins/add.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
1 change: 1 addition & 0 deletions app/views/superAdmin/admins/update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
1 change: 1 addition & 0 deletions app/views/superAdmin/admins/view.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
216 changes: 216 additions & 0 deletions app/views/superAdmin/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="refresh" content="300">
<title><?php echo SITENAME ?></title>

<!-- External CSS -->
<link rel="stylesheet" href="<?php echo URLROOT ?>/css/style.css">

<!-- External js -->
<script src="<?php echo URLROOT ?>/js/script.js" defer></script>
</head>
<body>

<!-- Loading screen -->
<div class="loader-wrapper">
<div class="logo-container">
<img src="<?php echo URLROOT ?>/images/logo.png" alt="">
</div>
<div class="loader"></div>
</div>

<!-- TOP NAVIGATION -->
<?php require APPROOT.'/views/inc/components/topnavbar.php'; ?>

<!-- SIDE NAVIGATION -->
<?php
$section = 'dashboard';
require APPROOT.'/views/inc/components/sidenavbar.php';
?>

<main class="page-container">
<section class="section" id="main">
<div class="container">
<h1>Dashboard</h1>

<div class="cards">
<!-- Card 1 -->
<a class="card-link" href="<?php echo URLROOT ?>/admin/viewRegistrationRequests">
<div class="card">
<div class="row">
<div class="left-col">
<div class="sub-row">
<div class="top-row">
<img src="<?php echo URLROOT ?>/images/parking.svg" alt="">
</div>
<div class="bottom-row"><?php echo $data['request_count'] ?></div>
</div>
</div>
<div class="right-col">Registration Requests</div>
</div>
</div>
</a>

<!-- Card 2 -->
<a class="card-link" href="<?php echo URLROOT ?>/parkingOwner/parkingCapacity">
<div class="card">
<div class="row">
<div class="left-col">
<div class="sub-row">
<div class="top-row">
<img src="<?php echo URLROOT ?>/images/vehicle.svg" alt="">
</div>
<div class="bottom-row">20</div>
</div>
</div>
<div class="right-col">Complaints</div>
</div>
</div>
</a>

<!-- Card 3 -->
<a class="card-link" href="">
<div class="card">
<div class="row">
<div class="left-col">
<div class="sub-row">
<div class="top-row">
<img src="<?php echo URLROOT ?>/images/dollar.svg" alt="">
</div>
<div class="bottom-row"></div>
</div>
</div>
<div class="right-col">Total Income</div>
</div>
</div>
</a>
</div>

<div class="charts">
<h2>Analysis</h2>
<div class="chart-container">
<div class="chart">
<canvas id="lineChart1" style="width:100%;max-width:600px"></canvas>
</div>
<div class="chart">
<canvas id="lineChart2" style="width:100%;max-width:600px"></canvas>
</div>
</div>
</div>
</div>

<div class="open-side-cards-btn" onclick="closeRightCard()">View Transaction</div>

<div class="side-cards">
<div class="close-btn" onclick="closeRightCard()">X</div>
<h2>Recent Transaction</h2>

<p><span>&#9632;</span>Today</p>

<div class="side-card">
<div class="date-time">2023.11.22</div>
<div class="parking">Nolimit</div>
<div class="transaction-type in">In</div>
</div>

<div class="side-card">
<div class="date-time">2023.11.22</div>
<div class="parking">Keels</div>
<div class="transaction-type out">Out</div>
</div>

<div class="side-card">
<div class="date-time">2023.11.22</div>
<div class="parking">Nolimit</div>
<div class="transaction-type in">In</div>
</div>

<div class="side-card">
<div class="date-time">2023.11.22</div>
<div class="parking">Keels</div>
<div class="transaction-type out">Out</div>
</div>

<p><span>&#9632;</span>Yesterday</p>

<div class="side-card">
<div class="date-time">2023.11.22</div>
<div class="parking">Nolimit</div>
<div class="transaction-type in">In</div>
</div>

<div class="side-card">
<div class="date-time">2023.11.22</div>
<div class="parking">Keels</div>
<div class="transaction-type out">Out</div>
</div>

<div class="side-card">
<div class="date-time">2023.11.22</div>
<div class="parking">Nolimit</div>
<div class="transaction-type in">In</div>
</div>

<div class="side-card">
<div class="date-time">2023.11.22</div>
<div class="parking">Keels</div>
<div class="transaction-type out">Out</div>
</div>
</div>
</section>
</main>

<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js"></script>
<script>
const xValues = ['jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov', 'dec'];
const yValues = [7,8,8,9,9,9,10,11,14,14,15];

var xValues2 = ["Italy", "France", "Spain", "USA", "Argentina"];
var yValues2 = [55, 49, 44, 24, 15];
var barColors = ["red", "green","blue","orange","brown"];

new Chart("lineChart1", {
type: "line",
data: {
labels: xValues,
datasets: [{
fill: false,
lineTension: 0,
backgroundColor: "rgb(0,0,0)",
borderColor: "rgb(252,212,38)",
data: yValues
}]
},
options: {
legend: {display: false},
scales: {
yAxes: [{ticks: {min: 6, max:16}}],
}
}
});

// Create a new chart with a different id for the second canvas
new Chart("lineChart2", {
type: "bar",
data: {
labels: xValues,
datasets: [{
backgroundColor: barColors,
data: yValues
}]
},
options: {
legend: {display: false},
title: {
display: true,
text: "Vehicle Count"
}
}
});
</script>

<?php require APPROOT.'/views/inc/footer.php'; ?>
Loading

0 comments on commit 0fbf48f

Please sign in to comment.