Commit e896c161 authored by jlopez's avatar jlopez
Browse files

Add Container gestion

parent c2d46dae
<?php
define("PATH","..");
define("PAGE","actionContainer");
session_start ();
if(!isset($_SESSION['username'])) {
header("Location: ../login.php");
}
require_once '../dao/DBquery.php';
$db = new DBquery();
$action = NULL;
$id = NULL;
$name = NULL;
$value = NULL;
$type = NULL;
$visibility = "public";
$description = NULL;
$author = 0;
if(isset($_POST['action'])) {
$action = $_POST['action'];
} else {
if(isset($_GET['action'])) {
$action = $_GET['action'];
} else {
$action = "";
}
}
if(isset($_POST['containerid'])) {
$id = $_POST['containerid'];
} else {
if(isset($_GET['containerid'])) {
$id = $_GET['containerid'];
} else {
$id = -1;
}
}
if(isset($_POST['name'])) {
$name = $_POST['name'];
}
if(isset($_POST['value'])) {
$value = $_POST['value'];
}
if(isset($_POST['type'])) {
$type = $_POST['type'];
}
if(isset($_POST['visibility'])) {
$visibility = intval($_POST['visibility']);
}
if(isset($_POST['description'])) {
$description = $_POST['description'];
}
$author = $_SESSION['username'];
$container = new Container($id, $name, $value, $type, $visibility, $description, $author);
if($action == "create") {
$container->escape($db);
$db->create($container);
} else if ($action == "update") {
$container->escape($db);
$db->update($container);
} else if ($action == "delete") {
$db->delete($container);
}
header("Location: ../container.php");
<?php
session_start ();
require_once "./dao/DBquery.php";
$db = new DBquery();
$containers = $db->getContainers();
?>
<!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
echo ' <a class="nav-item nav-link" href="./index.php"> Home </a>';
echo ' <a class="nav-item nav-link active" href="./container.php"> Containers </a>';
if(isset($_SESSION['username']) && !empty($_SESSION['username']))
{
if(isset($_SESSION['manage']) && !empty($_SESSION['manage']))
{
echo ' <a class="nav-item nav-link" href="./manage.php"> Manage </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/><br/>
<div class="row">
<div class="col-12">
<table id="Table_Container" class="table table-striped table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Author</th>
<th>Type</th>
<th>Visibility</th>
<th>Description</th>
<th>Labels</th>
<th>Action</th>
</tr>
</thead>
<tbody id="TableSection">
<?php
foreach ($containers as $container) {
$visibility = "private";
if($container->visibility) {
$visibility = "public";
}
if(!$container->visibility) {
if($container->author != $_SESSION['username']) {
continue;
}
}
echo '<tr>';
echo '<td>' . $container->name . '</td>';
echo '<td>' . $container->author . '</td>';
echo '<td>' . $container->type . '</td>';
echo '<td>' . $visibility . '</td>';
echo '<td>' . $container->description . '</td>';
echo '<td>' . "" . '</td>';
echo '<td>';
echo '<div class="btn-group" mr-3><a class="btn btn-success btn-sm" href="#" >show</a></div>';
echo '<div class="btn-group" mr-3><a class="btn btn-primary btn-sm" href="#" >dowload</a></div>';
if($container->author == $_SESSION['username'] || $_SESSION['manage'] ) {
echo '<div class="btn-group mr-3"><a class="btn btn-danger btn-sm" href="#" >delete</a></div>';
}
echo '</div></td>';
echo '</tr>';
}
?>
</tbody>
</table>
</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>
<script >
</script>
</body>
</html>
\ No newline at end of file
......@@ -11,7 +11,7 @@ require_once(__DIR__.'/../model/Section.php');
require_once(__DIR__.'/../model/Manager.php');
require_once(__DIR__.'/../model/Distribution.php');
require_once(__DIR__.'/../model/Package.php');
require_once(__DIR__.'/../model/Container.php');
class DBquery
{
......@@ -80,6 +80,17 @@ class DBquery
return $results;
}
public function getContainers() {
$sql = "SELECT * FROM `Container`;";
$result = mysqli_query($this->dbh, $sql);
$results = array();
while($row = mysqli_fetch_assoc($result)){
$cnt = new Container($row['ID'], $row['name'], $row['value'], $row['type'], $row['visibility'], $row['description'], $row['author']);
array_push($results, $cnt);
}
return $results;
}
public function getMaxSectionArrangement() {
$sql = "SELECT MAX(arrangement) FROM `Section` WHERE `Section`.`parent` IS NULL;";
......
......@@ -108,8 +108,13 @@ function printPanel($name) {
echo ' <a class="nav-item nav-link active" href="./index.php"> Home </a>';
echo ' <a class="nav-item nav-link" href="./container.php"> Containers </a>';
if(isset($_SESSION['username']) && !empty($_SESSION['username']))
{
if(isset($_SESSION['manage']) && !empty($_SESSION['manage']))
{
echo ' <a class="nav-item nav-link" href="./manage.php"> Manage </a>';
......@@ -203,6 +208,18 @@ function printPanel($name) {
<button type="button" id="generateButton" class="btn btn-primary" onclick="buildRecipe()">Build recipe</button>
<button type="button" id="generateButton" class="btn btn-primary">Push recipe</button>
</div>
<div class="form-group">
<?php
if(isset($_SESSION['username']) && !empty($_SESSION['username']))
{
echo '<button type="button" class="btn btn-success" onclick="showFormContainer()">Publish recipe</button>';
}
?>
</div>
</div>
</div>
......@@ -377,8 +394,60 @@ function printPanel($name) {
</div>
</div>
<!-- Start Modal Publish -->
<div class="modal" id="modalSaveRecipe">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Publish container file</h4>
<button type="button" class="close" data-dismiss="modal">&times;</button>
</div>
<form action="./action/action_container.php" method="post">
<!-- Modal body -->
<div class="modal-body">
<input type="text" class="form-control" style="display: none;" placeholder="action" name="action" value="create">
<textarea type="text" rows="5" class="form-control" id="valueContainer" style="display: none;" name="value" value=""></textarea>
<div class="form-group">
<label for="nameContainer">Name :</label>
<input type="text" class="form-control" id="nameContainer" name="name" required>
</div>
<div class="form-group">
<label for="typeContainer">Type :</label>
<input type="text" class="form-control" id="typeContainer" name="type" value="" readonly>
</div>
<div class="form-group">
<label for="visibilityContainer">Visibility :</label>
<select class="form-control" id="visibilityContainer" name="visibility">
<option value="1">Public</option>
<option value="0">Private</option>
</select>
</div>
<div class="form-group">
<label for="descriptionContainer">Description :</label>
<textarea class="form-control" rows="5" id="descriptionContainer" maxlength="500" name ="description" required></textarea>
</div>
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="submit" class="btn btn-success">Submit</button>
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</form>
</div>
</div>
</div> <!-- End Modal Publish -->
</div>
<!-- Optional JavaScript -->
......@@ -412,6 +481,29 @@ function printPanel($name) {
});
function showFormContainer() {
if(PREVIEW !== "") {
var isSingularity = document.getElementById("singularityRadio").checked;
if(isSingularity) {
document.getElementById("typeContainer").value = "Singularity";
} else {
document.getElementById("typeContainer").value = "Docker";
}
document.getElementById("valueContainer").value = PREVIEW;
$('#modalSaveRecipe').modal();
} else {
alert("Generate once before publish file");
}
}
function hide_os_rows() {
var e = document.getElementById("selectedOS");
var selectedOSRelease = e.options[e.selectedIndex].value;
......@@ -433,8 +525,6 @@ function printPanel($name) {
<?php
foreach($data_distribs as $value){
echo "if(selectedOSRelease.includes(\"$value->name\")) {\n";
......
......@@ -56,14 +56,24 @@ foreach ($sections_parent as $section) {
<a class="navbar-brand" href="#">WICOPA</a>
<div class="collapse navbar-collapse justify-content-between" id="navbar">
<div class="navbar-nav">
<?php
<?php
echo ' <a class="nav-item nav-link" href="./index.php"> Home </a>';
echo ' <a class="nav-item nav-link" href="./container.php"> Containers </a>';
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="./manage.php"> Manage </a>';
if(isset($_SESSION['manage']) && !empty($_SESSION['manage']))
{
echo ' <a class="nav-item nav-link active" href="./manage.php"> Manage </a>';
}
}
?>
</div>
<div class="navbar-nav">
<?php
......
<?php
/**
* Created by PhpStorm.
* User: jimmy
* Date: 11/04/19
* Time: 10:21
*/
require_once(__DIR__.'/../dao/DBquery.php');
class Container
{
var $ID = 0;
var $name = "";
var $value = "";
var $type = "";
var $visibility = 1;
var $description = "";
var $author = 0;
/**
* Section constructor.
* @param int $ID
* @param string $name
* @param int $type
*/
public function __construct($ID, $name, $value, $type, $visibility, $description, $author)
{
$this->ID = $ID;
$this->name = $name;
$this->value = $value;
$this->type = $type;
$this->visibility = $visibility;
$this->description = $description;
$this->author = $author;
}
public function escape(DBquery $db) {
$this->name = utf8_decode($db->escape($this->name));
$this->value = utf8_decode($db->escape($this->value));
$this->description = utf8_decode($db->escape($this->description));
}
public function getInsert() {
return "INSERT INTO Container (name, value, type, visibility, description, author)
VALUES ('$this->name', '$this->value', '$this->type', '$this->visibility', '$this->description', '$this->author');";
}
public function getUpdate() {
return "UPDATE Container
SET name='$this->name', value='$this->value', type='$this->type',
visiblity='$this->visibility', description='$this->description', author='$this->author'
WHERE ID = '$this->ID';";
}
public function getDelete() {
return "DELETE FROM Container WHERE ID = '$this->ID';";
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment