-
Notifications
You must be signed in to change notification settings - Fork 0
/
entity-edit.php
executable file
·223 lines (205 loc) · 9.8 KB
/
entity-edit.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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<?php
/**
* Chronolabs Cooperative Entitisms Repository Services REST API
*
* You may not change or alter any portion of this comment or credits
* of supporting developers from this source code or any supporting source code
* which is considered copyrighted (c) material of the original comment or credit authors.
* 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.
*
* @copyright Chronolabs Cooperative http://syd.au.snails.email
* @license ACADEMIC APL 2 (https://sourceforge.net/u/chronolabscoop/wiki/Academic%20Public%20License%2C%20version%202.0/)
* @license GNU GPL 3 (http://www.gnu.org/licenses/gpl.html)
* @package entities-api
* @since 2.2.1
* @author Dr. Simon Antony Roberts <simon@snails.email>
* @version 2.2.8
* @description A REST API for the storage and management of entities + persons + beingness collaterated!
* @link http://internetfounder.wordpress.com
* @link https://github.com/Chronolabs-Cooperative/Emails-API-PHP
* @link https://sourceforge.net/p/chronolabs-cooperative
* @link https://facebook.com/ChronolabsCoop
* @link https://twitter.com/ChronolabsCoop
*/
global $version, $output, $name, $clause, $callback, $mode, $state;
require_once __DIR__ . DIRECTORY_SEPARATOR . 'header.php';
$help=false;
if (isset($_GET['output']) || !empty($_GET['output']) ) {
$version = isset($_GET['version'])?(string)$_GET['version']:'v2';
$output = isset($_GET['output'])?(string)$_GET['output']:'';
$name = isset($_GET['name'])?(string)$_GET['name']:'';
$clause = isset($_GET['clause'])?(string)$_GET['clause']:'';
$callback = isset($_REQUEST['callback'])?(string)$_REQUEST['callback']:'';
$mode = isset($_GET['mode'])?(string)$_GET['mode']:'';
$state = isset($_GET['state'])?(string)$_GET['state']:'';
switch($output)
{
default:
case "html":
if (in_array($mode, array('entity')) && !in_array($_SERVER["REQUEST_METHOD"], array('POST', 'post')))
$help=true;
break;
}
} else {
header("Location: " . API_URL);
exit(0);
}
$sql = sprintf("SELECT * FROM `" . $GLOBALS['APIDB']->prefix('entities') . "` WHERE md5(concat(`entity-id`, `edit-password`)) LIKE '%s' AND `edit-protected` = 'Yes'", $clause);
if ($results = $GLOBALS['APIDB']->queryF($sql))
if ($entity = $GLOBALS['APIDB']->fetchArray($results))
$clause = $entity['entity-id'];
else {
$sql = sprintf("SELECT * FROM `" . $GLOBALS['APIDB']->prefix('entities') . "` WHERE `entity-id` LIKE '%s' AND `edit-protected` = 'Yes'", $clause);
if ($results = $GLOBALS['APIDB']->queryF($sql))
if ($entity = $GLOBALS['APIDB']->fetchArray($results))
{
if (function_exists('http_response_code'))
http_response_code(400);
include dirname(__FILE__).'/entity-edit-password.php';
exit(0);
}
}
if ($help==false) {
switch($_POST['op'])
{
case "password":
if (!empty($_POST['password']))
{
if ($_POST['request'] == 'Yes') {
setNewPassword($clause, 'edit');
}
$sql = sprintf("SELECT md5(concat(`entity-id`, `edit-password`, '%s', '%s')) as `clause` FROM `" . $GLOBALS['APIDB']->prefix('entities') . "` WHERE `view-password` = md5('%s') AND `entity-id` LIKE '%s' AND `edit-protected` = 'Yes'", $GLOBALS['peerid'], date("Y-M-W"), $_POST['password'], $clause);
if ($results = $GLOBALS['APIDB']->queryF($sql))
if ($entity = $GLOBALS['APIDB']->fetchArray($results))
{
if (function_exists('http_response_code'))
http_response_code(301);
header("Location: " . API_URL . '/v2/' . $entity['clause'] . '/edit.api');
exit(0);
}
} elseif ($_POST['request'] == 'Yes') {
setNewPassword($clause, 'edit');
if (function_exists('http_response_code'))
http_response_code(301);
header("Location: " . API_URL);
exit(0);
}
case "entity":
$sql = sprintf("SELECT * FROM `" . $GLOBALS['APIDB']->prefix('imports') . "` WHERE md5(concat(`maps-id`, `import-id`)) LIKE '%s'",$clause);
if (!$results = $GLOBALS['APIDB']->queryF($sql))
die('SQL Failed: ' . $sql);
if (!$import = $GLOBALS['APIDB']->fetchArray($results))
die('Recordset Failed: ' . $sql);
$categories = array();
$sql = "SELECT * FROM `" . $GLOBALS['APIDB']->prefix('categories_codes') . "` WHERE `maps-id` LIKE '".$import['maps-id']."' AND `code` IN ('" . implode("', '", array_keys($_POST['category'])) . "') ORDER BY `code` ASC";
if (!$results = $GLOBALS['APIDB']->queryF($sql))
die('SQL Failed: ' . $sql);
while ($category = $GLOBALS['APIDB']->fetchArray($results))
{
if ($_POST['category'][$category['code']]=='--user--')
{
$create = false;
$sql = "SELECT * FROM `" . $GLOBALS['APIDB']->prefix('categories') . "` where `category` LIKE '" . ($catstr = ucwords($_POST['user'][$category['code']])) . "'";
if ($results = $GLOBALS['APIDB']->queryF($sql))
if ($cat = $GLOBALS['APIDB']->fetchArray($results))
{
$sql = "UPDATE `" . $GLOBALS['APIDB']->prefix('categories_codes') . "` SET `category-id` = '".$cat['category-id'] . "' WHERE `category-code-id` = '" . $cat['category-code-id'] . "'";
if (!$GLOBALS['APIDB']->queryF($sql))
die('SQL Failed: ' . $sql);
} else {
$create = true;
}
else
$create = true;
if ($create==true)
{
$categoryid = md5(microtime(true).$catstr);
$sql = "INSERT INTO `" . $GLOBALS['APIDB']->prefix('categories') . "` (`category-id`, `category`) VALUES('$categoryid', '".mysql_escape_string($catstr)."')";
if (!$GLOBALS['APIDB']->queryF($sql))
die('SQL Failed: ' . $sql);
$sql = "INSERT INTO `" . $GLOBALS['APIDB']->prefix('categories_codes') . "` (`category-id`, `maps-id`, `code`) VALUES('$categoryid', '".$import['maps-id']."','".mysql_escape_string($category['code'])."')";
if (!$GLOBALS['APIDB']->queryF($sql))
die('SQL Failed: ' . $sql);
}
} else {
$sql = "UPDATE `" . $GLOBALS['APIDB']->prefix('categories_codes') . "` SET `category-id` = '" . $_POST['category'][$category['code']] . "' WHERE `category-id` = '" . $category['category-id'] . "'";
if (!$GLOBALS['APIDB']->queryF($sql))
die('SQL Failed: ' . $sql);
}
unset($_POST['category'][$category['code']]);
unset($_POST['user'][$category['code']]);
}
if (count($_POST['category'])>0)
{
foreach(array_keys($_POST['category']) as $code)
{
if ($_POST['category'][$code]=='--user--')
{
$create = false;
$sql = "SELECT * FROM `" . $GLOBALS['APIDB']->prefix('categories') . "` where `category` LIKE '" . $catstr = ucwords($_POST['user'][$category['code']]) . "'";
if ($results = $GLOBALS['APIDB']->queryF($sql))
if ($cat = $GLOBALS['APIDB']->fetchArray($results))
{
$sql = "UPDATE `" . $GLOBALS['APIDB']->prefix('categories_codes') . "` SET `category-id` = '".$cat['category-id'] . "' WHERE `category-code-id` = '" . $cat['category-code-id'] . "'";
if (!$GLOBALS['APIDB']->queryF($sql))
die('SQL Failed: ' . $sql);
} else {
$create = true;
}
else
$create = true;
if ($create==true)
{
$categoryid = md5(microtime(true).$catstr);
$sql = "INSERT INTO `" . $GLOBALS['APIDB']->prefix('categories') . "` (`category-id`, `category`) VALUES('$categoryid', '".mysql_escape_string($catstr)."')";
if (!$GLOBALS['APIDB']->queryF($sql))
die('SQL Failed: ' . $sql);
$sql = "INSERT INTO `" . $GLOBALS['APIDB']->prefix('categories_codes') . "` (`category-id`, `maps-id`, `code`) VALUES('$categoryid', '".$import['maps-id']."','".mysql_escape_string($code)."')";
if (!$GLOBALS['APIDB']->queryF($sql))
die('SQL Failed: ' . $sql);
}
} else {
$sql = "INSERT INTO `" . $GLOBALS['APIDB']->prefix('categories_codes') . "` (`category-id`, `maps-id`, `code`) VALUES('".$_POST['category'][$code]."', '".$import['maps-id']."','".mysql_escape_string($code)."')";
if (!$GLOBALS['APIDB']->queryF($sql))
die('SQL Failed: ' . $sql);
}
}
}
$sql = "UPDATE `" . $GLOBALS['APIDB']->prefix('imports_maps') . "` SET `state` = 'Defined' WHERE `maps-id` = '" . $import['maps-id'] . "'";
if (!$GLOBALS['APIDB']->queryF($sql))
die('SQL Failed: ' . $sql);
header("Location: " . API_URL);
exit(0);
break;
}
}
$sql = sprintf("SELECT * FROM `" . $GLOBALS['APIDB']->prefix('entities') . "` WHERE md5(concat(`entity-id`, `edit-password`, '%s', '%s')) LIKE '%s' AND `edit-protected` = 'Yes'", $GLOBALS['peerid'], date("Y-M-W"), $clause);
if ($results = $GLOBALS['APIDB']->queryF($sql))
if ($entity = $GLOBALS['APIDB']->fetchArray($results))
$clause = $entity['entity-id'];
else {
$sql = sprintf("SELECT * FROM `" . $GLOBALS['APIDB']->prefix('entities') . "` WHERE `entity-id` LIKE '%s' AND `view-protected` = 'Yes'", $clause);
if ($results = $GLOBALS['APIDB']->queryF($sql))
if ($entity = $GLOBALS['APIDB']->fetchArray($results))
{
if (function_exists('http_response_code'))
http_response_code(400);
include dirname(__FILE__).'/entity-edit-password.php';
exit(0);
}
}
$sql = sprintf("SELECT * FROM `" . $GLOBALS['APIDB']->prefix('entities') . "` WHERE `entity-id` LIKE '%s'", $clause);
if ($results = $GLOBALS['APIDB']->queryF($sql))
if ($entity = $GLOBALS['APIDB']->fetchArray($results))
{
if (function_exists('http_response_code'))
http_response_code(400);
include dirname(__FILE__).'/entity-edit-form.php';
exit;
}
if (function_exists('http_response_code'))
http_response_code(301);
header("Location: " . API_URL);
?>