-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddresourcewithlink.php
145 lines (125 loc) · 5.6 KB
/
addresourcewithlink.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
<?php
/**
* api/addresourcewithlink.php add new user's resources.
*
* Api add's users resources with url of the file
* such as images, url, videos, pdf.
*
* Copyright (C) 2012 Karl Englund <[email protected]>
*
* LICENSE: 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 3
* 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, see <http://opensource.org/licenses/gpl-3.0.html>;.
*
* @package OpenEMR
* @author Karl Englund <[email protected]>
* @link http://www.open-emr.org
*/
header("Content-Type:text/xml");
$ignoreAuth = true;
require_once('classes.php');
$xml_array = array();
$token = $_POST['token'];
$title = $_POST['title'];
$option_id = $_POST['option_id'];
$type = $_POST['type'];
$link = isset($_POST['link']) ? $_POST['link'] : '';
$ext = $_POST['ext'];
$list_id = 'ExternalResources';
$seq = 0;
$is_default = 0;
$notes = '';
$mapping = '';
if ($userId = validateToken($token)) {
$username = getUsername($userId);
$acl_allow = acl_check('admin', 'users', $username);
if ($acl_allow) {
$provider_id = $userId;
$path = $sitesDir . "{$site}/documents/userdata";
if (!file_exists($path)) {
mkdir($path);
mkdir($path . "/images");
mkdir($path . "/images/thumb/");
mkdir($path . "/pdf");
mkdir($path . "/videos");
} elseif (!file_exists($path . "/images") || !file_exists($path . "/images/thumb/") || !file_exists($path . "/pdf") || !file_exists($path . "/videos")) {
mkdir($path . "/images");
mkdir($path . "/images/thumb/");
mkdir($path . "/pdf");
mkdir($path . "/videos");
}
$data = file_get_contents($link);
if ($data) {
switch ($type) {
case 'link':
$notes = $link;
break;
case 'image':
$image_date_name = date('Y-m-d_H-i-s');
$image_name = $image_date_name . "." . $ext;
$image_path = $path . "/images/" . $image_name;
file_put_contents($image_path, $data);
$thumb_path = $path . "/images/thumb/";
createThumbnail($image_path, $image_date_name, 250, $thumb_path);
$notes = $sitesUrl . "{$site}/documents/userdata/images/" . $image_name;
break;
case 'pdf':
$pdf_name = date('Y-m-d_H-i-s') . "." . $ext;
file_put_contents($path . "/pdf/" . $pdf_name, $data);
$notes = $sitesUrl . "{$site}/documents/userdata/pdf/" . $pdf_name;
break;
case 'video':
$video_name = date('Y-m-d_H-i-s') . "." . $ext;
file_put_contents($path . "/videos/" . $video_name, $data);
$notes = $sitesUrl . "{$site}/documents/userdata/videos/" . $video_name;
break;
}
$select_query = "SELECT * FROM `list_options`
WHERE `list_id` LIKE 'lists' AND `option_id` LIKE '" . add_escape_custom($list_id) . "' AND `title` LIKE '" . add_escape_custom($list_id) . "'";
$result_select = sqlQuery($select_query);
$result1 = true;
if (!$result_select) {
$insert_list = "INSERT INTO list_options ( list_id, option_id, title, seq, is_default, option_value )
VALUES ( 'lists','" . add_escape_custom($list_id) . "','" . add_escape_custom($list_id) . "', '0','1', '0')";
$result1 = sqlInsert($insert_list);
}
$strQuery = "INSERT INTO `list_options`(`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `mapping`, `notes`)
VALUES (
'" . add_escape_custom($list_id) . "',
'" . add_escape_custom($option_id) . "',
'" . add_escape_custom($title) . "',
'" . add_escape_custom($seq) . "',
'" . add_escape_custom($is_default) . "',
'" . add_escape_custom($provider_id) . "',
'" . add_escape_custom($mapping) . "',
'" . add_escape_custom($notes) . "')";
$result = sqlInsert($strQuery);
if ($result && $result1) {
$xml_array['status'] = "0";
$xml_array['reason'] = "The Resource has been added";
} else {
$xml_array['status'] = "-1";
$xml_array['reason'] = "ERROR: Sorry, there was an error processing your data. Please re-submit the information again.";
}
} else {
$xml_array['status'] = "-1";
$xml_array['reason'] = "Invalid Url (Resource not found)";
}
} else {
$xml_array['status'] = -2;
$xml_array['reason'] = 'You are not Authorized to perform this action';
}
} else {
$xml_array['status'] = "-2";
$xml_array['reason'] = 'Invalid Token';
}
$xml = ArrayToXML::toXml($xml_array, 'Resource');
echo $xml;
?>