Your IP : 3.133.148.130
<?php
session_start();
include("lib/connect.inc.php");
if($uidx != 1){
header("Location:../login.php");
}
$rep=$uidx;
$report = $_SESSION['report'] ?? $report;
class training
{
//User Array Keys
/* Class constructor */
function __construct()
{
global $report, $count;
if(array_key_exists('UpdateTraining', $_POST)) { $this->UpdateTraining(); }
elseif (array_key_exists('AddNewTraining', $_POST)) { $this->AddNewTraining(); }
elseif (array_key_exists('Activate', $_POST)) { $this->Activate(); }
elseif (array_key_exists('DeActivate', $_POST)) { $this->DeActivate(); }
elseif (array_key_exists('delete', $_GET)) { $this->deleteTraining(); }
}
function DeActivate() {
global $db;
$sn = $_POST['DeActivate'];
$db->query("UPDATE trainings SET status = 0 WHERE sn = '$sn'");
header('Location: ?');
}
function Activate(){
global $db;
$sn = $_POST['Activate'];
$db->query("UPDATE trainings SET status = 1 WHERE sn = '$sn'");
header('Location: ?');
}
function UpdateTraining()
{
global $db, $report, $count, $rep;
$title = mysqli_real_escape_string($db, $_POST['title']);
$description = mysqli_real_escape_string($db, $_POST['description']);
$price = $_POST['price'];
$image = $_FILES['image']['name'];
$sn = $_POST['UpdateTraining'];
$upgrade = $_POST['upgrade'];
$hiddenImage = $_POST['hiddenImage'];
$start = $_POST['start'];
$end = $_POST['end'];
$start1 = strtotime($start);
$end1 = strtotime($end);
if($image == '' || trim($image) == ''){
$db->query("UPDATE trainings SET title = '$title', description = '$description', upgrade='$upgrade', price = '$price', start = '$start1', end = '$end1' WHERE sn = '$sn'");
$report = $_SESSION['report'] = "Updated Successfully";
header('Location: ?');
}
else {
$ext = pathinfo($image, PATHINFO_EXTENSION);
$extension = array('jpg', 'png', 'jpeg');
$size = $_FILES['image']['size'];
$tmp = $_FILES['image']['tmp_name'];
$name2 = uniqid('trainings').'.'.$ext;
if(in_array(strtolower($ext), $extension)){
if($this->compress_image($tmp, 'img/trainings/'.$name2, 90)){
$deleteImage = getcwd().'/img/trainings/'.$hiddenImage;
unlink($_SERVER['DOCUMENT_ROOT'].'/profile/img/trainings/'.$hiddenImage);
// unlink($deleteImage);
$db->query("UPDATE trainings SET title = '$title', description = '$description', upgrade='$upgrade', price = '$price', start = '$start1', end = '$end1', image = '$name2' WHERE sn = '$sn'");
$report = $_SESSION['report'] = "Updated Successfully";
header('Location: ?');
} else {
$count = 1;
$report = $name2;
}
} else {
$count = 1;
$report = "Image only supports .png, .jpg, .jpeg extensions". $size;
}
}
}
function compress_image($source_url, $destination_url, $quality)
{
$info = getimagesize($source_url);
if ($info['mime'] == 'image/jpeg' || $info['mime'] == 'image/jpg') $image = imagecreatefromjpeg($source_url);
// elseif ($info['mime'] == 'image/jpg') $image = imagecreatefromgif($source_url);
elseif ($info['mime'] == 'image/png') $image = imagecreatefrompng($source_url);
imagejpeg($image, $destination_url, $quality);
return true;
}
function AddNewTraining()
{
global $db, $report, $count, $rep;
$title = $_POST['title'];
$description = mysqli_real_escape_string($db, $_POST['description']);
$price = $_POST['price'];
$start = $_POST['start'];
$end = $_POST['end'];
$upgrade = $_POST['upgrade'];
$image = $_FILES['image']['name'];
$start1 = strtotime($start);
$end1 = strtotime($end);
if(empty($image)){
$count = 1; $report = "Image Cannot be empty";
} else {
$ext = pathinfo($image, PATHINFO_EXTENSION);
$extension = array('jpg', 'png', 'jpeg');
$size = $_FILES['image']['size'];
$tmp = $_FILES['image']['tmp_name'];
$name2 = uniqid('trainings').'.'.$ext;
if(in_array(strtolower($ext), $extension)){
if($this->compress_image($tmp, 'img/trainings/'.$name2, 90)){
$db->query("INSERT INTO trainings(title, description, price, image, rep, upgrade, start, end)
VALUES('$title', '$description', '$price', '$name2', '$rep', '$upgrade', '$start1', '$end1')");
$report = "Added Successfully";
}
} else {
$count = 1;
$report = "Image only supports .png, .jpg, .jpeg extensions". $size;
}
}
}
function deleteTraining(){
global $db, $count, $report ;
$sn = $_GET['delete'];
$sql = $db->query("SELECT * FROM trainingapplications WHERE training = '$sn'");
if($sql->num_rows > 0) {
$count = 1;
$report = $_SESSION['report'] = "OOPS!!! Unable to delete";
} else {
$db->query("DELETE FROM trainings WHERE sn = '$sn'");
$report = $_SESSION['report'] = "Deleted Successfully";
}
header('Location: ?');
}
function fileExt($name){
$ext = strtolower(substr($name, strpos($name,'.'), strlen($name)-1));
if($ext=='.jpg' OR $ext=='.jpeg' OR $ext=='.png'){ $res = TRUE; }else{$res= FALSE; }
return $res;
}
function fileExt2($name){
$ext = strtolower(substr($name, strpos($name,'.'), strlen($name)-1));
// if($ext=='.jpg' OR $ext=='.jpeg' OR $ext=='.png'){ $res = TRUE; }else{$res= FALSE; }
return $ext;
}
function win_hashs($length)
{
return substr(str_shuffle(str_repeat('123456789abcdefghijklmnopqrstuvwxyz', $length)), 0, $length);
}
function countApplication($sn){
global $db;
$sql = $db->query("SELECT * FROM trainingapplications WHERE training = '$sn'");
return $sql->num_rows;
}
}
$training = new training;
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="treant/examples/tree/basic-example2.css">
<!-- Neptune CSS -->
<link rel="stylesheet" href="css/core.css">
<title>Post a Training</title>
<link rel="shortcut icon" href="img/fav.png" />
<link rel="stylesheet" href="treant/Treant.css">
<link rel="stylesheet" href="treant/examples/tree/basic-example2.css">
<!-- Neptune CSS -->
<link rel="stylesheet" href="css/core.css">
<!-- Neptune CSS -->
<!-- Tell the browser to be responsive to screen width -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Neptune CSS -->
<link rel="stylesheet" href="css/core.css">
<!-- Vendor CSS -->
<link rel="stylesheet" href="../vendor/bootstrap4/css/bootstrap.min.css">
<link rel="stylesheet" href="../vendor/themify-icons/themify-icons.css">
<link rel="stylesheet" href="../vendor/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="../vendor/animate.css/animate.min.css">
<link rel="stylesheet" href="../vendor/jscrollpane/jquery.jscrollpane.css">
<link rel="stylesheet" href="../vendor/waves/waves.min.css">
<link rel="stylesheet" href="../vendor/switchery/dist/switchery.min.css">
<link rel="stylesheet" href="../vendor/morris/morris.css">
<link rel="stylesheet" href="../vendor/dropify/dist/css/dropify.min.css">
<!-- Font Awesome -->
<?php include('head.php'); ?>
</head>
<body class="hold-transition sidebar-mini layout-fixed">
<?php include('nav.php'); ?>
<div class="content-wrapper">
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h3> Post a Training</h3>
</div>
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item"><a href="index.php">Home</a></li>
<li class="breadcrumb-item active">Post a Training</li>
</ol>
</div>
</div>
</div><!-- /.container-fluid -->
</section>
<div class="content">
<div class="container-fluid">
<!-- ============================================================== -->
<!-- Sales chart -->
<!-- ============================================================== -->
<div class="row">
<div class="col-lg-4">
<?php if(isset($_GET['edit'])){ $edit = $_GET['edit']; unset($_SESSION['report']);
$sql =$db->query("SELECT * FROM trainings WHERE sn = '$edit'");
$row = $sql->fetch_object();
?>
<div class="card">
<div class="card-header text-white bg-dark"> <h5>Edit Training</h5></div>
<div class="card-body">
<form method="POST" enctype="multipart/form-data">
Title<input type="text" name="title" class="form-control" placeholder="Training's Title" value="<?= $row->title ?>" required /><br>
Description<textarea name="description" class="form-control" placeholder="Training's Description" required ><?= $row->description ?></textarea><br>
Price<input type="number" class="form-control" name="price" value="<?= $row->price; ?>" required/> <br/>
Start Date<input type="date" class="form-control" name="start" value="<?= date('Y-m-d', $row->start); ?>" required/> <br/>
Closing Date<input type="date" class="form-control" name="end" value="<?= date('Y-m-d', $row->end); ?>" required/> <br/>
<input type="file" name="image" accept="image/*" class="form-control"/> <br/>
<img src="img/trainings/<?= $row->image ?>" class="img img-thumbnail"/>
Select Package
<select name="upgrade" id="" class="form-control" required>
<option value="0">All</option>
<?php
$sql4 = $db2->query("SELECT * FROM packages");
while($row4 = $sql4->fetch_object()):
?>
<option value="<?= $row4->sn ?>" <?= $row->upgrade == $row4->sn ? 'selected': '' ?>>
$<?= $row4->upgradeamt ?> Package</option>
<?php endwhile; ?>
</select> <br/>
<input type="hidden" name="hiddenImage" value="<?= $row->image ?>"/>
<br/>
<button type="submit" value="<?= $row->sn ?>" class="btn btn-block btn-success" name="UpdateTraining">Update</button>
</form>
</div>
</div>
<?php } else{ ?>
<div class="card">
<div class="card-header text-white bg-dark"> <h5>Post New Training</h5></div>
<div class="card-body">
<form method="POST" enctype="multipart/form-data">
<input type="text" name="title" class="form-control" placeholder="Training's Title" required /><br>
<textarea name="description" class="form-control" placeholder="Training's Description" required ></textarea><br>
<input type="number" class="form-control" name="price" placeholder="Enter Amount" required/> <br/>
<input type="file" name="image" accept="image/*" required class="form-control"/>
<br/>
Select Package
<select name="upgrade" id="" class="form-control" required>
<option value="0">All</option>
<?php
$sql4 = $db2->query("SELECT * FROM packages");
while($row4 = $sql4->fetch_object()):
?>
<option value="<?= $row4->sn ?>">$<?= $row4->upgradeamt ?> Package</option>
<?php endwhile; ?>
</select> <br/>
Start Date<input type="date" class="form-control" name="start" required/> <br/>
Closing Date<input type="date" class="form-control" name="end" required/> <br/>
<button type="submit" class="btn btn-block btn-success" name="AddNewTraining">Add</button>
</form>
</div>
</div>
<?php } ?>
</div>
<div class="col-lg-8 col-md-12 order-lg-2 order-md-3">
<div class="card ">
<div class="card-header text-white bg-dark">
<h5>Recent Trainings</h5>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-striped" id="example1">
<thead>
<tr>
<th>Title</th>
<th>Description</th>
<th>Price</th>
<th>Image</th>
<th>Package</th>
<th>Applications</th>
<th>Start</th>
<th>End</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php $sql = $db->query("SELECT * FROM trainings ORDER BY sn DESC");
while($row1 = $sql->fetch_object()) :
$upg = $row1->upgrade == 0 ? 'All' : '$'.sqLxx('packages', 'sn', $row1->upgrade, 'upgradeamt');
?>
<tr>
<td><?= $row1->title ?></td>
<td><?= $row1->description ?></td>
<td>$<?= $row1->price ?></td>
<td>
<img src="img/trainings/<?= $row1->image ?>" class="img img-thumbnail" alt=""/>
</td>
<td><?= $upg; ?> Package</td>
<td>
<a href="?application=<?= $row1->sn ?>" class="btn btn-default">
<?= $training->countApplication($row1->sn) ?>
</a>
</td>
<td><?= date("jS M, Y", $row1->start) ?></td>
<td><?= date("jS M, Y", $row1->end) ?></td>
<td>
<a href="?edit=<?= $row1->sn ?>" class="btn btn-sm btn-primary">Edit</a>
<a href="?delete=<?= $row1->sn ?>" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure you wanna delete?')">Delete</a>
<form method="POST">
<?php if($row1->status == 1): ?>
<button type="submit" value="<?= $row1->sn ?>" name="DeActivate" class="btn btn-sm btn-info" onclick="return confirm('Are you sure you wanna De-Activate?')">De-Activate</button>
<?php else: ?>
<button type="submit" value="<?= $row1->sn ?>" name="Activate" class="btn btn-sm btn-warning" onclick="return confirm('Are you sure you wanna Re-Activate?')">Activate</button>
<?php endif; ?>
</form>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<?php if(isset($_GET['application'])): $sn = $_GET['application'];
$sql = $db->query("SELECT * FROM trainings WHERE sn = '$sn'");
$row2 = $sql->fetch_object();
?>
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header text-white bg-dark">
<h5>List of <?= $row2->title ?> Applicants</h5>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-striped" id="example1">
<thead>
<tr>
<th>S/n</th>
<th>Username</th>
<th>Whatsapp</th>
<th>Telegram</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<?php $no2 = 1;
$sql = $db->query("SELECT * FROM trainingapplications WHERE training = '$sn' ORDER BY sn DESC");
while($row3 = $sql->fetch_object()) :
?>
<tr>
<td><?= $no2 ?></td>
<td><?= userName($row3->id).' ('. userName($row3->id, 'user'). ')' ?></td>
<td><?= $row3->whatsapp ?></td>
<td><?= $row3->telegram ?></td>
<td><?= date('jS M, Y h:i A', strtotime($row3->created_at)) ?></td>
</tr>
<?php $no2 += 1;
endwhile; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<?php endif; ?>
<!-- ============================================================== -->
<!-- Email campaign chart -->
<!-- ============================================================== -->
<!-- ============================================================== -->
<!-- Ravenue - page-view-bounce rate -->
<!-- ============================================================== -->
<!-- ============================================================== -->
<!-- Ravenue - page-view-bounce rate -->
<!-- ============================================================== -->
<!-- ============================================================== -->
<!-- Recent comment and chats -->
<!-- ============================================================== -->
</div>
<!-- ============================================================== -->
<!-- End Container fluid -->
<!-- ============================================================== -->
<!-- ============================================================== -->
<!-- footer -->
<!-- ============================================================== -->
<!-- ============================================================== -->
<!-- End footer -->
<!-- ============================================================== -->
<!-- /.row (main row) -->
</div><!-- /.container-fluid -->
<!-- /.content -->
</div>
<!-- /.content-wrapper -->
<?php include('foot.php'); ?>
<!-- Control Sidebar -->
<aside class="control-sidebar control-sidebar-dark">
<!-- Control sidebar content goes here -->
</aside>
<!-- /.control-sidebar -->
</div>
<!-- ./wrapper -->
<!-- jQuery -->
<script src="../plugins/jquery/jquery.min.js"></script>
<!-- jQuery UI 1.11.4 -->
<script src="../plugins/jquery-ui/jquery-ui.min.js"></script>
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
<script>
$.widget.bridge('uibutton', $.ui.button)
</script>
<!-- Bootstrap 4 -->
<script src="../plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- ChartJS -->
<script src="../plugins/chart.js/Chart.min.js"></script>
<!-- Sparkline -->
<script src="../plugins/sparklines/sparkline.js"></script>
<!-- JQVMap -->
<script src="../plugins/jqvmap/jquery.vmap.min.js"></script>
<script src="../plugins/jqvmap/maps/jquery.vmap.usa.js"></script>
<!-- jQuery Knob Chart -->
<script src="../plugins/jquery-knob/jquery.knob.min.js"></script>
<!-- daterangepicker -->
<script src="../plugins/moment/moment.min.js"></script>
<script src="../plugins/daterangepicker/daterangepicker.js"></script>
<!-- Tempusdominus Bootstrap 4 -->
<script src="../plugins/tempusdominus-bootstrap-4/js/tempusdominus-bootstrap-4.min.js"></script>
<!-- Summernote -->
<script src="../plugins/summernote/summernote-bs4.min.js"></script>
<!-- overlayScrollbars -->
<script src="../plugins/overlayScrollbars/js/jquery.overlayScrollbars.min.js"></script>
<!-- AdminLTE App -->
<script src="../dist/js/adminlte.js"></script>
<!-- AdminLTE dashboard demo (This is only for demo purposes) -->
<script src="../dist/js/pages/dashboard.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="../dist/js/demo.js"></script>
<!-- DataTables -->
<script src="../plugins/datatables/jquery.dataTables.min.js"></script>
<script src="../plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="../plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="../plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
<!-- page script -->
<script>
$(function () {
$("#example1").DataTable({
"responsive": false,
"autoWidth": false,
"ordering": false
});
$('#example2').DataTable({
"paging": true,
"lengthChange": true,
"searching": true,
"ordering": true,
"info": true,
"autoWidth": false,
"responsive": true,
});
});
</script>
<!-- page script -->
<script src="treant/vendor/raphael.js"></script>
<script src="treant/Treant.js"></script>
<script>
new Treant( chart_config );
</script>
</body>
</html>