-
Notifications
You must be signed in to change notification settings - Fork 44
/
action.php
75 lines (65 loc) · 2.62 KB
/
action.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/**
* Automatic Api Rest
*
* @package Automatic Api Rest
* @author Alejandro Esquiva Rodríguez [@alex_esquiva] <alejandro@geekytheory.com>
* @license Apache License, Version 2.0
* @link https://github.com/GeekyTheory/Automatic-API-REST
*/
include_once 'inc/functions.php';
require_once("inc/autentification.php");
$blacklist = new BlackList();
if(isset($_GET["a"])){
if($_GET["a"]=="add"){
$tool = new Tools();
$fields = $tool->getFieldsByTable($_GET["table"]);
$num_fields = count($fields);
if($_GET["column"]=="*"){
//Get all columns from table
for($i=0;$i<count($fields);$i++){
if(!$blacklist->existItem($_GET["type"],$_GET["table"],$fields[$i])){
$blacklist->createItem($_GET["type"],$_GET["table"],$fields[$i]);
}
}
$blacklist->createItem($_GET["type"],$_GET["table"],$_GET["column"]);
}else{
$blacklist->createItem($_GET["type"],$_GET["table"],$_GET["column"]);
$num_fields_check = 0;
for($i=0;$i<count($fields);$i++){
if($blacklist->existItem($_GET["type"],$_GET["table"],$fields[$i])){
$num_fields_check++;
}
}
if($num_fields == $num_fields_check){
//Añadimos *
$blacklist->createItem($_GET["type"],$_GET["table"],"*");
}
}
}
if($_GET["a"]=="delete"){
if($_GET["column"]=="*"){
//Get all columns from table
$tool = new Tools();
$fields = $tool->getFieldsByTable($_GET["table"]);
for($i=0;$i<count($fields);$i++){
$id_item = $blacklist->getIDbyParameters($_GET["type"],$_GET["table"],$fields[$i]);
$blacklist->id_item = $id_item;
if($id_item!=0)$blacklist->deleteItem();
}
//delete *
$id_item = $blacklist->getIDbyParameters($_GET["type"],$_GET["table"],"*");
$blacklist->id_item = $id_item;
if($id_item!=0)$blacklist->deleteItem();
}else{
//delete field
$id_item = $blacklist->getIDbyParameters($_GET["type"],$_GET["table"],$_GET["column"]);
$blacklist->id_item = $id_item;
if($id_item!=0)$blacklist->deleteItem();
//delete *
$id_item = $blacklist->getIDbyParameters($_GET["type"],$_GET["table"],"*");
$blacklist->id_item = $id_item;
if($id_item!=0)$blacklist->deleteItem();
}
}
}