Commit 1c65f9b5 authored by jlopez's avatar jlopez
Browse files

Big clean and fix code

parent 0216b3f0
<?php
define("PATH","..");
define("PAGE","actionDistribution");
session_start ();
if(!isset($_SESSION['username'])) {
header("Location: ../login.php");
}
require_once '../dao/DBquery.php';
$db = new DBquery();
$today = date("Y-m-d G:i:s");
$action = NULL;
$id = NULL;
$version = NULL;
$manager = NULL;
$active = 0;
if(isset($_POST['action'])) {
$action = $_POST['action'];
} else {
if(isset($_GET['action'])) {
$action = $_GET['action'];
} else {
$action = "";
}
}
if(isset($_POST['distribid'])) {
$id = $_POST['distribid'];
} else {
if(isset($_GET['distribid'])) {
$id = $_GET['distribid'];
} else {
$id = -1;
}
}
if(isset($_POST['name'])) {
$name = $_POST['name'];
}
if(isset($_POST['version'])) {
$version = $_POST['version'];
}
if(isset($_POST['manager'])) {
$manager = $_POST['manager'];
}
if(isset($_POST['active'])) {
if($_POST['active'] == $id) {
$active = 1;
} else {
$active = 0;
}
}
$distrib = new Distribution($id, $name, $version, $manager, $active);
if($action == "create") {
$distrib->active = 1;
$distrib->escape($db);
if($db->checkTableExist($distrib->getFullName())) {
$db->create($distrib);
} else {
//TODO alert user.
}
} else if ($action == "update") {
$distrib->escape($db);
$db->update($distrib);
} else if ($action == "delete") {
$db->delete($distrib);
}
header("Location: ../gestion.php#distribution");
<?php
define("PATH","..");
define("PAGE","actionManager");
session_start ();
if(!isset($_SESSION['username'])) {
header("Location: ../login.php");
}
require_once '../dao/DBquery.php';
$db = new DBquery();
$today = date("Y-m-d G:i:s");
$action = NULL;
$id = NULL;
$value = NULL;
if(isset($_POST['action'])) {
$action = $_POST['action'];
} else {
if(isset($_GET['action'])) {
$action = $_GET['action'];
} else {
$action = "";
}
}
if(isset($_POST['managerid'])) {
$id = $_POST['managerid'];
} else {
if(isset($_GET['managerid'])) {
$id = $_GET['managerid'];
} else {
$id = -1;
}
}
if(isset($_POST['name'])) {
$name = $_POST['name'];
}
if(isset($_POST['value'])) {
$value = $_POST['value'];
}
$manager = new Manager($id, $name, $value);
if($action == "create") {
$manager->escape($db);
$db->create($manager);
} else if ($action == "update") {
$manager->escape($db);
$db->update($manager);
} else if ($action == "delete") {
$db->delete($manager);
}
header("Location: ../gestion.php#manager");
\ No newline at end of file
<?php
define("PATH","..");
define("PAGE","actionSection");
session_start ();
if(!isset($_SESSION['username'])) {
header("Location: ../login.php");
}
require_once '../dao/DBquery.php';
$db = new DBquery();
$today = date("Y-m-d G:i:s");
$action = NULL;
$id = NULL;
$name = NULL;
$visual = NULL;
$active = 0;
$color = NULL;
$arrangement = NULL;
if(isset($_POST['action'])) {
$action = $_POST['action'];
} else {
if(isset($_GET['action'])) {
$action = $_GET['action'];
} else {
$action = "";
}
}
if(isset($_POST['sectionid'])) {
$id = $_POST['sectionid'];
} else {
if(isset($_GET['sectionid'])) {
$id = $_GET['sectionid'];
} else {
$id = -1;
}
}
if(isset($_POST['name'])) {
$name = $_POST['name'];
}
if(isset($_POST['visual'])) {
$visual = $_POST['visual'];
}
if(isset($_POST['color'])) {
$color = "#".$_POST['color'];
}
if(isset($_POST['arrangement'])) {
$arrangement = $_POST['arrangement'];
}
if(isset($_POST['active'])) {
if($_POST['active'] == $id) {
$active = 1;
} else {
$active = 0;
}
}
$section = new Section($id, $name, $visual, $active, $color, $arrangement);
if($action == "create") {
$section->active = 1;
$section->escape($db);
if($db->checkTableExist($name)) {
$db->create($section);
} else {
//TODO alert user.
}
} else if ($action == "update") {
$section->escape($db);
$db->update($section);
} else if ($action == "delete") {
$db->delete($section);
}
header("Location: ../gestion.php#section");
......@@ -68,8 +68,4 @@
box-shadow: none !important;
}
.badge-bio {
background-color: #8e44ad;
color: #fff;
}
......@@ -10,6 +10,7 @@ require_once(__DIR__.'/../conf/Conf.php');
require_once(__DIR__.'/../model/Section.php');
require_once(__DIR__.'/../model/Manager.php');
require_once(__DIR__.'/../model/Distribution.php');
require_once(__DIR__.'/../model/Package.php');
class DBquery
......@@ -57,8 +58,19 @@ class DBquery
return $results;
}
public function getActiveDistributions() {
$sql = "SELECT * FROM `Distrib` WHERE active = 1 ORDER BY `Distrib`.`name` ASC;";
$result = mysqli_query($this->dbh, $sql);
$results = array();
while($row = mysqli_fetch_assoc($result)){
$d = new Distribution($row['ID'], $row['name'], $row['version'], $row['manager'], $row['active']);
array_push($results, $d);
}
return $results;
}
public function getManagers() {
$sql = "SELECT * FROM `Manager` ORDER BY `Manager`.`name` ASC;";
$sql = "SELECT * FROM `Manager`;";
$result = mysqli_query($this->dbh, $sql);
$results = array();
while($row = mysqli_fetch_assoc($result)){
......@@ -74,23 +86,36 @@ class DBquery
}
public function getAllActiveSectionParent() {
$sql = "SELECT * FROM `Section` WHERE `Section`.`parent` IS NULL AND active = 1 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['visual'], $row['active'], $row['color'], $row['arrangement'], $row['parent']);
array_push($results,$s);
}
return $results;
}
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)){
$s = new Section($row['ID'], $row['name'], $row['active'], $row['color'], $row['arrangement'], $row['parent']);
$s = new Section($row['ID'], $row['name'], $row['visual'], $row['active'], $row['color'], $row['arrangement'], $row['parent']);
array_push($results,$s);
}
return $results;
}
public function getSectionWhithParent($parent) {
$sql = "SELECT * FROM `Section` WHERE `Section`.`parent` = '$parent' ORDER BY `Section`.`arrangement` ASC;";
$sql = "SELECT * FROM `Section` WHERE `Section`.`parent` = '$parent' AND active = 1 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']));
array_push($results,array($row['name'], $row['visual'], $row['active'], $row['color']));
}
return $results;
}
......@@ -100,7 +125,18 @@ class DBquery
$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']);
$s = new Section($row['ID'], $row['name'], $row['visual'], $row['active'], $row['color'], $row['arrangement'], $row['parent']);
array_push($results,$s);
}
return $results;
}
public function getActiveSection() {
$sql = "SELECT * FROM `Section` WHERE active = 1 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['visual'], $row['active'], $row['color'], $row['arrangement'], $row['parent']);
array_push($results,$s);
}
return $results;
......@@ -111,7 +147,7 @@ class DBquery
$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']);
$s = new Section($row['ID'], $row['name'], $row['visual'], $row['active'], $row['color'], $row['arrangement'], $row['parent']);
array_push($results,$s);
}
return $results;
......@@ -144,7 +180,7 @@ class DBquery
$result = mysqli_query($this->dbh, $sql);
$results = array();
while($row = mysqli_fetch_assoc($result)){
if($distrib == "CRAN") {
/*if($distrib == "CRAN") {
$package = array($row['name'], $row['version'], $row['description'], $row['depends'], "https://cran.r-project.org/web/packages/".$row['name']."/index.html");
}
else if($distrib == "CPAN") {
......@@ -161,13 +197,66 @@ class DBquery
}
else {
$package = array($row['name'], $row['version'], $row['description'], $row['doc'], $row['rpm']);
}
}*/
$package = new Package($row['name'], $row['version'], $row['description'], $row['doc'], $row['other']);
array_push($results,$package);
}
return $results;
}
public function checkTableExist($name) {
$sql = "SELECT count(*) as number FROM information_schema.TABLES WHERE (TABLE_SCHEMA = 'wicopa') AND (TABLE_NAME = '$name')";
$result = mysqli_query($this->dbh, $sql);
if($result) {
while($row = mysqli_fetch_assoc($result)){
return $row['number'];
}
} else {
var_dump(mysqli_error($this->dbh));
die();
}
}
public function create($object) {
$result = mysqli_query($this->dbh, $object->getInsert());
if($result) {
} else {
var_dump(mysqli_error($this->dbh));
die();
}
}
public function update($object) {
$result = mysqli_query($this->dbh, $object->getUpdate());
if($result) {
} else {
var_dump(mysqli_error($this->dbh));
die();
}
}
public function delete($object) {
$result = mysqli_query($this->dbh, $object->getDelete());
if($result) {
} else {
var_dump(mysqli_error($this->dbh));
die();
}
}
public function verifyPass($username, $pass) {
if($username == "admin" && sha1($pass)==Conf::$KK) {
return 1;
......@@ -181,5 +270,7 @@ class DBquery
}
//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';
}
This diff is collapsed.
<?php
/**
* Created by PhpStorm.
* User: jimmy
* Date: 01/02/19
* Time: 13:24
*/
require_once "./dao/DBquery.php";
$db = new DBquery();
$distrib = "";
if(isset($_GET['distrib'])) {
$distrib = $_GET['distrib'];
}
$filter = "";
if(isset($_GET['filter'])) {
$filter = $_GET['filter'];
}
if(isset($_GET['filter'])) {
$filter = $_GET['filter'];
}
$patternName = false;
$patternDescription = false;
if(isset($_GET['patternName'])) {
if($_GET['patternName'] == "true") {
$patternName = true;
}
}
if(isset($_GET['patternDescription'])) {
if($_GET['patternDescription'] == "true") {
$patternDescription = true;
}
}
$limit = "25";
if(isset($_GET['limit'])) {
$limit = $_GET['limit'];
}
$result = $db->getPackages($distrib, $filter, $patternName, $patternDescription, $limit);
echo '
<div class="container">
<div class="row justify-content-center">
<h4>Packages found : '.count($result).'</h4>
</div>
</div>
<table id="Table_PackagesBioconductor" class="table table-striped table-bordered">
<thead>
<tr>
<th>Choose</th>
<th>Name</th>
<th>Version</th>
<th>Description</th>
<th>Documentation</th>
</tr>
</thead>
<tbody id="TablePackagesBioconductor">
<tr>';
foreach ($result as $t) {
echo '<td><label class="custom-control custom-checkbox">
<input type="checkbox" onclick="generatePackageSelected(this)" data-pname="'.$t[0].'" data-pversion="'.$t[1].'" data-psection="Bioconductor" id="checkbox$'.'Bioconductor'.'$'.$t[0].'$'.$t[1].'" class="custom-control-input" name="type">
<span class="custom-control-indicator"></span>
</label></td>';
echo '<td>'.$t[0].'</td>';
echo '<td>'.$t[1].'</td>';
echo '<td>'.$t[2].'</td>';
echo '<td><a href="'.$t[3].'">documentation</a></td>';
echo '</tr>';
}
echo '</tr>
</tbody>
</table>
';
return $result;
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: jimmy
* Date: 06/02/19
* Time: 12:41
*/
require_once "./dao/DBquery.php";
$db = new DBquery();
$distrib = "";
if(isset($_GET['distrib'])) {
$distrib = $_GET['distrib'];
}
$filter = "";
if(isset($_GET['filter'])) {
$filter = $_GET['filter'];
}
if(isset($_GET['filter'])) {
$filter = $_GET['filter'];
}
$patternName = false;
$patternDescription = false;
if(isset($_GET['patternName'])) {
if($_GET['patternName'] == "true") {
$patternName = true;
}
}
if(isset($_GET['patternDescription'])) {
if($_GET['patternDescription'] == "true") {
$patternDescription = true;
}
}
$limit = "25";
if(isset($_GET['limit'])) {
$limit = $_GET['limit'];
}
$result = $db->getPackages($distrib, $filter, $patternName, $patternDescription, $limit);
echo '
<div class="container">
<div class="row justify-content-center">
<h4>Packages found : '.count($result).'</h4>
</div>
</div>
<table id="Table_PackagesCPAN" class="table table-striped table-bordered">
<thead>
<tr>
<th>Choose</th>
<th>Name</th>
<th>Version</th>
<th>Description</th>
<th>Documentation</th>
<th>Download</th>
</tr>
</thead>
<tbody id="TablePackagesCRAN">
<tr>';
foreach ($result as $t) {
echo '<td><label class="custom-control custom-checkbox">
<input type="checkbox" onclick="generatePackageSelected(this)" data-pname="'.$t[0].'" data-pversion="'.$t[1].'" data-psection="CPAN" id="checkbox$'.'PackagesCPAN'.'$'.$t[0].'$'.$t[1].'" class="custom-control-input" name="type">
<span class="custom-control-indicator"></span>
</label></td>';
echo '<td>'.$t[0].'</td>';