This repository has been archived by the owner on Jun 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ops.php
129 lines (112 loc) · 2.92 KB
/
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
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
<?php
# vim:tabstop=2:softtabstop=2:shiftwidth=2:noexpandtab
# Documentation
# Correct way of calling is
# http://upload_ndpa.php
# When called with incorrect or unknown parameters returns a JSON with list of
# algorithms in list key. Also returns name = None to indicate that algorithm
# was not successfully returned
# Tests without json
# Adds
# http://ayodhya:82/ops.php?col=images&id=4e6bf58d83ff8d0bac000000&op=change¶m=test&data=99
# Delets
# http://ayodhya:82/ops.php?col=images&id=4e6bf58d83ff8d0bac000000&op=del¶m=test
# Adds with json
# http://ayodhya:82/ops.php?col=images&id=4e6bf58d83ff8d0bac000000&op=change¶m=test&data={%22center%22:[100,100],%22rotation%22:35,%22zoom%22:3}
# Report all PHP errors (see changelog)
require_once("config.php");
# Get the parameters
@$col = $_REQUEST['col']; # images or chapters
@$id = $_REQUEST['id']; # id
@$param = $_REQUEST["param"]; # parameter like label or default_view
@$data_str = $_REQUEST['data']; # data, converts structure from json
@$op = $_REQUEST['op']; # intended operation like add, del, change
$data = json_decode($data_str);
//var_dump($data_str);
//var_dump($data);
# Make sure the user has access rights
# Currently check that the login is admin
if($_SESSION['auth'] != 'admin')
{
echo('Admin access required');
return;
}
# Parse the parameters and report the errors
// if(!isset($label) || !isset($image_id))
// {
// header('Location: ' . $_SERVER['HTTP_REFERER']);
// }
$success = false;
try
{
## Find the concerned image
# connect
$m = new Mongo($server);
# select a collection (analogous to a relational database's table)
$collection = $m->selectDB($database)->selectCollection($col);
# Perform the query to get chapter name
$oid = new MongoId($id);
}
# catch exception
catch(Exception $e)
{
echo('Error while accessing mongo: ' .$e->getMessage());
var_dump($col);
var_dump($id);
return;
}
try
{
switch ($op)
{
case "change":
$success = $collection->update( array( "_id" => $oid), array('$set' => array($param => $data)));
break;
case "del":
$success = $collection->update( array( "_id" => $oid), array('$unset' => array($param => 1)));
break;
case "add":
# Make sure that there is no record of that kind
default:
echo('Unsupported operation');
return;
break;
}
}
# catch exception
catch(Exception $e)
{
echo('Error while operation: ' .$e->getMessage());
return;
}
try
{
if($success == true)
{
switch($col)
{
case "images":
$headstring = 'location: image.php?id=' . trim($id);
break;
case "chapters":
$headstring = 'location: chapter.php?id=' . trim($id);
break;
}
# Append the submit button
//header("Content-type: text/plain");
//echo json_encode($contents);
header($headstring);
return;
}
else
{
echo('Operation Failed, probably nothing to do');
return;
}
}
catch(Exception $e)
{
echo('Operation may be successful, but error: ' .$e->getMessage());
return;
}
?>