-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessor.php
More file actions
155 lines (136 loc) · 6.82 KB
/
processor.php
File metadata and controls
155 lines (136 loc) · 6.82 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
include "config.php";
while(true){
$time_start = microtime(true);
$sql = "SELECT * FROM inbox WHERE flag = 0 LIMIT 10";
$qry = $conn->query($sql);
$rows = array();
$rows_id = array();
while($data = $qry->fetch_assoc()){
$rows[] = $data;
$rows_id[] = $data['id'];
}
$sql2 = "UPDATE inbox SET flag=1 WHERE id in (".join(",",$rows_id).")";
$qry2 = $conn->query($sql2);
if($qry->num_rows > 0) {
foreach($rows as $data){
$sql2 = "SELECT `format`, `flag_file` FROM operation WHERE id='".$data['message']."'";
$qry2 = $conn->query($sql2);
if($qry2->num_rows > 0) { // operation id's found
$data2 = $qry2->fetch_object();
$reply = "";
if($data2->flag_file){
$sql3 = "SELECT `type`, `keyword` FROM file_type ft
INNER JOIN operation_file_type oft ON ft.id = oft.file_type_id
WHERE oft.operation_id='".$data['message']."'";
$qry3 = $conn->query($sql3);
// operation id's found
while($data3 = $qry3->fetch_object()){
$format = $data2->format;
$format = str_replace("#keyword", "#".$data3->keyword, $format);
$reply.="<b>".$data3->type."</b>".PHP_EOL;
$reply .= "<i>Masukkan perintah berikut:</i>".PHP_EOL;
$reply.="<pre>".$format."</pre>".PHP_EOL.PHP_EOL;
}
} else {
$reply = "<i>Masukkan perintah berikut:</i>".PHP_EOL;
$reply .= "<pre>".$data2->format."</pre>";
}
} else { // operation id's not found
$messages = explode(" #", $data['message']);
$reply = "";
$sql2 = "SELECT `id`,`sql`, `sql_type`, `flag_file`, `filename` FROM operation WHERE keyword='".$messages[0]."'";
$qry2 = $conn->query($sql2);
if($qry2->num_rows > 0) { // keyword's found
$data2 = $qry2->fetch_object();
if($data2->flag_file){
$sql3 = "SELECT `id` FROM operation_file_type
WHERE operation_id='". $data2->id ."'
AND keyword='". $messages[1] ."'";
$qry3 = $conn->query($sql3);
// operation fil id's found
$data3 = $qry3->fetch_object();
$flag_file = 1;
$oft_id = $data3->id;
} else {
$sql2 = $data2->sql;
foreach($messages as $key => $val) {
if($key==0) continue;
$sql2 = substr_replace($sql2, $val, strpos($sql2, "?"), 1);
}
$qry2 = $conn->query($sql2);
switch($data2->sql_type){
case "insert":
if($qry2){
$reply = "Insert berhasil dilakukan";
} else {
$reply = "Insert gagal dilakukan";
}
break;
case "update":
if($qry2){
$reply = "Update berhasil dilakukan";
} else {
$reply = "Update gagal dilakukan";
}
break;
case "delete":
if($qry2){
$reply = "Delete berhasil dilakukan";
} else {
$reply = "Delete gagal dilakukan";
}
break;
default:
$num_rows = $qry2->num_rows;
if($num_rows > 0) {
while($data2 = $qry2->fetch_assoc()){
foreach($data2 as $key => $val){
$reply.=$key."\t: ".$val.PHP_EOL;
}
if($num_rows>1) $reply.=PHP_EOL;
}
} else {
$reply = "Data tidak ditemukan";
}
}
}
} else { // keyword's not found
$sql2 = "SELECT name FROM operation";
$qry2 = $conn->query($sql2);
$reply = "<b>List Operasi</b>".PHP_EOL.PHP_EOL;
$i = 0;
while($data2 = $qry2->fetch_object()) {
$i++;
$reply .= $i.".\t".$data2->name.PHP_EOL;
}
}
}
$sql2 = "INSERT INTO outbox (
message,
chat_id,
date_insert,
flag,
flag_file,
operation_file_type_id)
VALUES (
'".urlencode($reply)."',
'".$data['chat_id']."',
'".date('Y-m-d H:i:s')."',
0,
'".((isset($flag_file))?$flag_file:0)."',
'".((isset($oft_id))?$oft_id:'')."'
)";
echo $sql2;
$qry2 = $conn->query($sql2);
echo $reply;
}
} else {
echo "no new message to process...\n";
sleep(1);
}
$time_end = microtime(true);
$execution_time = ($time_end - $time_start);
//execution time of the script
echo '10 Qry Execution Time: '.$execution_time." sec\n";
}