forked from slims/ucs-2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuc-ops.php
executable file
·82 lines (77 loc) · 3.47 KB
/
uc-ops.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
76
77
78
79
80
81
82
<?php
/**
* SLiMS Union Catalog polling
*
* Copyright (C) 2010 Arie Nugraha (dicarve@yahoo.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
require 'ucsysconfig.inc.php';
require 'ucserver.inc.php';
require LIB_DIR.'http_request.inc.php';
// create http request object
$http_request = new http_request();
$http_request->get_http_request();
// get http content
$referer = trim($http_request->headers('REFERER'));
$body = trim($http_request->body());
// sent HTTP header
header('Content-type: text/json');
// check content
if ($body) {
// encode to PHP array
$op = json_decode($body, true);
if (function_exists('json_last_error')) {
// Define the errors.
$json_errors = array(
JSON_ERROR_DEPTH => 'JSON error: The maximum stack depth has been exceeded',
JSON_ERROR_CTRL_CHAR => 'JSON error: Control character error, possibly incorrectly encoded',
JSON_ERROR_SYNTAX => 'JSON error: Syntax error',
);
// get json error
$json_error = json_last_error();
if ($json_error) {
die(json_encode(array('status' => 'JSON_ERROR', 'message' => $json_errors[$json_error])));
}
}
// node ID
$node_id = $op['node_info']['id'];
// authentication
if (isset($sysconf['node'][$node_id])) {
// check for password
if ($sysconf['node'][$node_id]['password'] === $op['node_info']['password']) {
$action = $op['node_data']['operation'];
$action_data = $op['node_data']['biblio'];
// update/delete catalog data
if ($action_data) {
if ($action == 'delete') {
$_del = @$dbs->query("DELETE FROM biblio WHERE orig_biblio_id IN ($action_data) AND node_id='$node_id'");
$_deleted_num = $dbs->affected_rows;
// write log
utility::writeLogs($dbs, 'nodes', $op['node_info']['id'], 'ucs', 'Node '.$node_id.'('.$op['node_info']['name'].') delete '.$_deleted_num.' catalog data');
die(json_encode(array('status' => 'DELETED', 'message' => $_deleted_num.' catalog record(s) delete succesfully from '.$sysconf['server']['name'].'!')));
}
}
} else {
die(json_encode(array('status' => 'NOT_AUTHORIZED', 'message' => 'You not authorized to update data on server '.$sysconf['server']['name'].'! Please check your ucnode.inc.php file for correct configuration!')));
}
} else {
die(json_encode(array('status' => 'NOT_AUTHORIZED', 'message' => 'You not authorized to update data on server '.$sysconf['server']['name'].'! Please check your ucnode.inc.php file for correct configuration!')));
}
} else {
die(json_encode(array('status' => 'NO_DATA', 'message' => 'Request is empty! Could be error on HTTP request')));
}
?>