Commit 9c2dd363 authored by jlopez's avatar jlopez
Browse files

Update with admin page gestion

parent 21fa0032
<?php
/**
* Created by PhpStorm.
* User: jimmy
* Date: 26/02/19
* Time: 13:01
*/
session_start ();
require_once '../dao/DBquery.php';
$db = new DBquery();
$today = date("Y-m-d G:i:s");
session_start ();
$login = $db->escape($_POST['username']);
$pwd = $db->escape($_POST['password']);
$passcode = $db->verifyPass($login, $pwd);
if($passcode == 1) {
$_SESSION['username'] = $login;
$_SESSION['usercode'] = 1;
header("Location: ../gestion.php");
} elseif ($passcode == 2) {
$_SESSION['username'] = "guest";
$_SESSION['usercode'] = 2;
header("Location: ../gestion.php");
} else {
header("Location: ../login.php");
}
<?php
/**
* Created by PhpStorm.
* User: jimmy
* Date: 26/02/19
* Time: 13:08
*/
session_start ();
session_destroy();
header("Location: ../index.php");
......@@ -7,7 +7,9 @@
*/
require_once(__DIR__.'/../conf/Conf.php');
require_once(__DIR__.'/../model/Section.php');
require_once(__DIR__.'/../model/Manager.php');
require_once(__DIR__.'/../model/Distribution.php');
class DBquery
......@@ -44,12 +46,13 @@ class DBquery
return mysqli_real_escape_string($this->dbh, $value);
}
public function getDistribs() {
public function getDistributions() {
$sql = "SELECT * FROM `Distrib` ORDER BY `Distrib`.`name` ASC;";
$result = mysqli_query($this->dbh, $sql);
$results = array();
while($row = mysqli_fetch_assoc($result)){
array_push($results,array($row['name'], $row['version'], $row['manager']));
$d = new Distribution($row['ID'], $row['name'], $row['version'], $row['manager'], $row['active']);
array_push($results, $d);
}
return $results;
}
......@@ -59,17 +62,25 @@ class DBquery
$result = mysqli_query($this->dbh, $sql);
$results = array();
while($row = mysqli_fetch_assoc($result)){
array_push($results,array($row['name'], $row['value']));
$m = new Manager($row['ID'], $row['name'], $row['value']);
array_push($results, $m);
}
return $results;
}
public function getSectionParent() {
public function getMaxSectionArrangement() {
$sql = "SELECT MAX(arrangement) FROM `Section` WHERE `Section`.`parent` IS NULL;";
}
public function getAllSectionParent() {
$sql = "SELECT * FROM `Section` WHERE `Section`.`parent` IS NULL ORDER BY `Section`.`arrangement` ASC;";
$result = mysqli_query($this->dbh, $sql);
$results = array();
while($row = mysqli_fetch_assoc($result)){
array_push($results,array($row['name'], $row['active'], $row['color']));
$s = new Section($row['ID'], $row['name'], $row['active'], $row['color'], $row['arrangement'], $row['parent']);
array_push($results,$s);
}
return $results;
}
......@@ -84,16 +95,39 @@ class DBquery
return $results;
}
public function getAllSectionWhithParent($parent) {
$sql = "SELECT * FROM `Section` WHERE `Section`.`parent` = '$parent' ORDER BY `Section`.`arrangement` ASC;";
$result = mysqli_query($this->dbh, $sql);
$results = array();
while($row = mysqli_fetch_assoc($result)){
$s = new Section($row['ID'], $row['name'], $row['active'], $row['color'], $row['arrangement'], $row['parent']);
array_push($results,$s);
}
return $results;
}
public function getSection() {
$sql = "SELECT * FROM `Section` ORDER BY `Section`.`arrangement` ASC;";
$result = mysqli_query($this->dbh, $sql);
$results = array();
while($row = mysqli_fetch_assoc($result)){
array_push($results,array($row['name'], $row['active'], $row['color'], $row['parent']));
$s = new Section($row['ID'], $row['name'], $row['active'], $row['color'], $row['arrangement'], $row['parent']);
array_push($results,$s);
}
return $results;
}
public function getNumberPackage($name) {
$sql = "SELECT COUNT(*) as number FROM `$name` WHERE 1 ";
$result = mysqli_query($this->dbh, $sql);
while($row = mysqli_fetch_assoc($result)){
return $row['number'];
}
return 0;
}
public function getPackages($distrib, $filter, $patternName, $patternDescription, $limit) {
if($patternName and $patternDescription) {
$sql = "SELECT * FROM `$distrib` WHERE `name` LIKE '%$filter%' or `description` LIKE '%$filter%' ORDER BY CASE WHEN `name` LIKE '$filter' THEN 1 WHEN `name` LIKE '$filter%' THEN 2 WHEN `name` LIKE '%$filter' THEN 4 ELSE 3 END LIMIT $limit;";
......@@ -131,5 +165,18 @@ class DBquery
return $results;
}
public function verifyPass($username, $pass) {
if($username == "admin" && sha1($pass)==Conf::$KK) {
return 1;
} else {
if($username == "guest" && $pass == "2019mbb") {
return 2;
} else {
return 0;
}
}
}
//LOAD DATA LOCAL INFILE "/home/jimmy/jimmy/web/wicopa/packages/fedora:28/packages.csv" INTO TABLE fedora COLUMNS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '"' LINES TERMINATED BY '\n';
}
\ No newline at end of file
......@@ -4,4 +4,401 @@
* User: jimmy
* Date: 04/02/19
* Time: 14:09
*/
\ No newline at end of file
*/
session_start ();
if(!isset($_SESSION['username'])) {
header("Location: ../login.php");
}
require_once "./dao/DBquery.php";
require_once "./model/Section.php";
$db = new DBquery();
$sections_parent = $db->getAllSectionParent();
$distribs = $db->getDistributions();
$managers = $db->getManagers();
$max_arrangement = 0;
foreach ($sections_parent as $section) {
if($section->arrangement > $max_arrangement) {
$max_arrangement = $section->arrangement;
}
}
?>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" crossorigin="anonymous">
<link rel="stylesheet" href="./css/style.css">
<script src="./js/jscolor.js"></script>
<title>wicopa</title>
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark navbar-custom p-1">
<a class="navbar-brand" href="#">WICOPA</a>
<div class="collapse navbar-collapse justify-content-between" id="navbar">
<div class="navbar-nav">
<?php
if(isset($_SESSION['username']) && !empty($_SESSION['username']))
{
echo ' <a class="nav-item nav-link" href="./index.php"> Home </a>';
echo ' <a class="nav-item nav-link active" href="./gestion.php"> Gestion </a>';
}
?>
</div>
<div class="navbar-nav">
<?php
if(isset($_SESSION['username']) && !empty($_SESSION['username']))
{
echo '<a class="nav-item btn btn-primary " href="./action/action_logout.php"> Logout ('.$_SESSION['username'].') </a>';
}
else
{
echo '<a class="nav-item btn btn-primary" href="./login.php"> Login </a>';
}
?>
</div>
</nav>
<div class="container-fluid">
<br/>
<div class="row">
<div class="col-12">
<div class="card border border-dark">
<div class="card-header bg-dark text-light">
Gestion section :
</div>
<div class="card-body">
<table id="Table_Section" class="table table-striped table-bordered">
<thead>
<tr>
<th>Active</th>
<th>Name</th>
<th>Color</th>
<th>Arrangement</th>
<th>SubArrangement</th>
<th>Parent</th>
<th>Packages</th>
<th>Update</th>
</tr>
</thead>
<tbody id="TableSection">
<?php
foreach ($sections_parent as $section) {
echo '<tr>';
if($section->active) {
echo '<td>' . '<input type="checkbox" name="section" value="'.$section->name.'" checked>' . '</td>';
} else {
echo '<td>' . '<input type="checkbox" name="section" value="'.$section->name.'">' . '</td>';
}
echo '<td>' . $section->name . '</td>';
echo '<td>' . '<input class="jscolor form-control" name="color_" value="'.$section->color.'">' . '</td>';
echo '<td>' . '<input id="number" class="form-control" type="number" value="'.$section->arrangement.'">' . '</td>';
echo '<td>' . "" . '</td>';
echo '<td>' . $section->parent . '</td>';
echo '<td>' . $db->getNumberPackage($section->name). '</td>';
echo '<td>' . '<a href="#" class="btn btn-warning btn-sm">update</a>' . '</td>';
echo '</tr>';
foreach ($db->getAllSectionWhithParent($section->name) as $subsection) {
echo '<tr>';
if($subsection->active) {
echo '<td>' . '<input type="checkbox" name="section" value="'.$subsection->name.'" checked>' . '</td>';
} else {
echo '<td>' . '<input class="btn" type="checkbox" name="section" value="'.$subsection->name.'">' . '</td>';
}
echo '<td>' . $subsection->name . '</td>';
echo '<td>' . '<input class="jscolor form-control" name="color_" value="'.$subsection->color.'">' . '</td>';
echo '<td>' . "" . '</td>';
echo '<td>' . '<input id="number" class="form-control" type="number" value="'.$subsection->arrangement.'">' . '</td>';
echo '<td>' . $subsection->parent . '</td>';
echo '<td>' . $db->getNumberPackage($subsection->name). '</td>';
echo '<td>' . '<a href="#" class="btn btn-warning btn-sm">update</a>' . '</td>';
echo '</tr>';
}
}
?>
</tbody>
</table>
<button type="button" class="btn btn-primary" >Save change</button>
<br/>
<br/>
<br/>
<br/>
<form>
<div class="row">
<div class="col-2">
<label for="nameSection">Name :</label>
<input type="text" class="form-control" id="nameSection" name="nameSection" >
</div>
<div class="col-2">
<label for="colorSection">Color :</label>
<input class="jscolor form-control" name="colorSection" value="#FFFFFF">
</div>
<div class="col-2">
<label for="arrangementSection">Arrangement :</label>
<input id="arrangementSection" name="arrangementSection" class="form-control" type="number" value="<?php echo $max_arrangement + 1; ?>">
</div>
<div class="col-2">
<label for="subarrangementSection">SubArrangement :</label>
<input id="subarrangementSection" name="subarrangementSection" class="form-control" type="number" value="">
</div>
<div class="col-2">
<label for="parentSection">Parent :</label>
<select class="form-control" id="parentSection" name="parentSection">
<?php
echo '<option value=""></option>';
foreach ($sections_parent as $section) {
echo '<option value="'.$section->name.'">'.$section->name.'</option>';
}
?>
</select>
</div>
<div class="col-12">
<br/>
<button type="submit" class="btn btn-success">Create</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<br/>
<div class="row">
<div class="col-12">
<div class="card border border-dark">
<div class="card-header bg-dark text-light">
Gestion distribution :
</div>
<div class="card-body">
<table id="Table_Distrib" class="table table-striped table-bordered">
<thead>
<tr>
<th>Active</th>
<th>Name</th>
<th>Version</th>
<th>Manager</th>
<th>Packages</th>
<th>Update</th>
</tr>
</thead>
<tbody id="TableSection">
<?php
foreach ($distribs as $dist) {
echo '<tr>';
if($dist->active == 1) {
echo '<td>' . '<input type="checkbox" name="distrib" value="'.$dist->ID.'" checked>' . '</td>';
} else {
echo '<td>' . '<input type="checkbox" name="distrib" value="'.$dist->ID.'">' . '</td>';
}
echo '<td>' . $dist->name . '</td>';
echo '<td>' . $dist->version . '</td>';
echo '<td><select name="managers">';
foreach ($managers as $manager) {
if($manager->value == $dist->manager) {
echo '<option value="'.$manager->value.'" selected="selected">'.$manager->name.'</option>';
} else {
echo '<option value="'.$manager->value.'">'.$manager->name.'</option>';
}
}
//echo '<td>' . $dist[2] . '</td>';
echo '</select></td>';
echo '<td>' . $db->getNumberPackage($dist->getFullName()) . '</td>';
echo '<td>' . '<a href="#" class="btn btn-warning btn-sm">update</a>' . '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
<button type="button" class="btn btn-primary" >Save change</button>
<br/>
<br/>
<br/>
<br/>
<form>
<div class="row">
<div class="col-2">
<label for="nameManager">Name :</label>
<input type="text" class="form-control" id="nameManager" name="nameManager" >
</div>
<div class="col-2">
<label for="versionManager">Version :</label>
<input type="text" class="form-control" id="versionManager" name="versionManager" >
</div>
<div class="col-2">
<label for="managerManager">Manager :</label>
<select class="form-control" id="managerManager" name="managerManager">
<?php
foreach ($managers as $manager) {
echo '<option value="'.$manager->value.'">'.$manager->name.'</option>';
}
?>
</select>
</div>
<div class="col-12">
<br/>
<button type="submit" class="btn btn-success">Create</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<br/>
<div class="row">
<div class="col-12">
<div class="card border border-dark">
<div class="card-header bg-dark text-light">
Gestion managers :
</div>
<div class="card-body">
<table id="Table_Distrib" class="table table-striped table-bordered">
<thead>
<tr>
<th>Delete</th>
<th>Name</th>
<th>Value</th>
</tr>
</thead>
<tbody id="TableSection">
<?php
foreach ($managers as $manager) {
echo '<tr>';
echo '<td>' . '<a class="btn btn-danger btn-sm" href="./action/actionManager.php?action=delete&manager_id='.$manager->ID.'" >x</a>' . '</td>';
echo '<td>' . '<input type="text" name="name" value="'.$manager->name.'">' . '</td>';
echo '<td>' . '<input type="text" name="value" value="'.$manager->value.'">' . '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
<button type="button" class="btn btn-primary" >Save change</button>
<br/>
<br/>
<br/>
<br/>
<form>
<div class="row">
<div class="col-2">
<label for="nameManager">Name :</label>
<input type="text" class="form-control" id="nameManager" name="nameManager" >
</div>
<div class="col-2">
<label for="valueManager">Value :</label>
<input type="text" class="form-control" id="valueManager" name="valueManager" >
</div>
<div class="col-12">
<br/>
<button type="submit" class="btn btn-success">Create</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<br/><br/><br/><br/><br/><br/>
</div>
<!-- jQuery Version 1.11.1 -->
<script src="http://code.jquery.com/jquery-latest.min.js"
type="text/javascript"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</body>
</html>
\ No newline at end of file
......@@ -10,27 +10,30 @@
//$tools = json_decode($content)->containers;
session_start ();
require_once "./dao/DBquery.php";
$db = new DBquery();
$distribs = [];
$data_distribs = $db->getDistribs();
$data_distribs = $db->getDistributions();
foreach($data_distribs as $value){
array_push($distribs,$value[0].":".$value[1]);
array_push($distribs,$value->name.":".$value->version);
}
$manager = $db->getManagers();
$managers = $db->getManagers();
$data_section = $db->getSection();
$section = array();
foreach ($db->getSectionParent() as $value){
if($value[1]) {
array_push($section, $value[0]);
foreach ($db->getAllSectionParent() as $s){
if($s->active == 1) {
array_push($section, $s->name);
}
}
......@@ -54,11 +57,33 @@ foreach ($db->getSectionParent() as $value){
<body>
<nav class="navbar navbar-expand-md navbar-dark navbar-custom p-0">
<nav class="navbar navbar-expand-md navbar-dark navbar-custom p-1">
<a class="navbar-brand" href="#">WICOPA</a>
<button class="navbar-toggler mr-3" type="button" data-toggle="collapse" data-target="#navbarContent" aria-controls="navbarContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-between" id="navbar">
<div class="navbar-nav">
<?php
if(isset($_SESSION['username']) && !empty($_SESSION['username']))
{
echo ' <a class="nav-item nav-link active" href="./index.php"> Home </a>';
echo ' <a class="nav-item nav-link" href="./gestion.php"> Gestion </a>';
}
?>
</div>
<div class="navbar-nav">