-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.php
More file actions
79 lines (59 loc) · 2.59 KB
/
run.php
File metadata and controls
79 lines (59 loc) · 2.59 KB
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
76
77
78
79
<?php
require_once "DbConnection.php";
$db = DbConnection::getInstance()->getPdo();
if ( $_GET['action'] == 'show' ) {
$sth = $db->query("SELECT * FROM {$_POST['table']} ORDER BY `order_id` ASC");
$sth->execute();
$info = $sth->fetchAll(PDO::FETCH_ASSOC);
echo (json_encode($info));
} elseif ( $_GET['action'] == 'insert' ) {
$sth = $db->prepare("INSERT INTO {$_POST['table']} (`id`, `type_id`, `title`, `text`, `order_id`)
VALUES (NULL, :type_id, 'TITLE', 'TEXT', :order_id)");
$params = array(
'type_id' => $_POST['type_id'],
'order_id' => $_POST['order_id'],
);
$sth->execute($params);
$sth = $db->query("SELECT * FROM {$_POST['table']} ORDER BY {$_POST['table']}.id DESC LIMIT 1");
$sth->execute();
$info = $sth->fetchAll(PDO::FETCH_ASSOC);
echo (json_encode($info));
} elseif ( $_GET['action'] == 'remove' ) {
$sth = $db->prepare("INSERT INTO `list_remove` (`id`, `type`, `title`, `text`)
VALUES (NULL, :type, :title, :text)");
$params = array(
'type' => $_POST['type'],
'title' => $_POST['title'],
'text' => $_POST['text'],
);
$sth->execute($params);
$sth = $db->prepare("DELETE FROM {$_POST['table']} WHERE `id` = :id");
$params = array(
'id' => $_POST['id']
);
$sth->execute($params);
} elseif ( $_GET['action'] == 'edit' ) {
$sth = $db->prepare("UPDATE {$_POST['table']} SET {$_POST['type']} = :text WHERE id = :id");
$params = array(
'text' => $_POST['text'],
'id' => $_POST['id'],
);
$sth->execute($params);
} elseif ( $_GET['action'] == 'swap' ) {
$params = array(
'obj_id' => $_POST['obj_id'],
'sub_order_id' => $_POST['sub_order_id']
);
if($_POST['cl'] == 'arrow start') {
$sth = $db->prepare("UPDATE {$_POST['table']} SET order_id = :sub_order_id - 1 WHERE id = :obj_id;");
} else if ($_POST['cl'] == 'arrow end') {
$sth = $db->prepare("UPDATE {$_POST['table']} SET order_id = :sub_order_id + 1 WHERE id = :obj_id;");
} else if ( ($_POST['cl'] == 'arrow up') || ($_POST['cl'] == 'arrow down') ) {
$sth = $db->prepare("UPDATE {$_POST['table']} SET order_id = :sub_order_id WHERE id = :obj_id;
UPDATE {$_POST['table']} SET order_id = :obj_order_id WHERE id = :sub_id;");
$params['obj_order_id'] = $_POST['obj_order_id'];
$params['sub_id'] = $_POST['sub_id'];
}
$sth->execute($params);
}
?>