-
Notifications
You must be signed in to change notification settings - Fork 0
/
references.php
295 lines (266 loc) · 7.18 KB
/
references.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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<?php
/**
* @package tikiwiki
*/
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$
require_once ('tiki-setup.php');
global $dbTiki;
if (!isset($prefs['feature_references']) && !$prefs['feature_references'] === 'y') {
header('location: index.php');
exit;
}
$referenceslib = TikiLib::lib('references');
if (!isset($_REQUEST['page'])) {
$smarty->assign('msg', tra('No page indicated'));
$smarty->display('error.tpl');
die;
}
$smarty->assign('page', $_REQUEST['page']);
$page = $_REQUEST['page'];
$perms = Perms::get(array('wiki page', $page));
$page_id = TikiLib::lib('tiki')->get_page_id_from_name($_REQUEST['page']);
$action = $_REQUEST['action'];
$ref_id = $_REQUEST['ref_id'];
$ref_biblio_code = $_REQUEST['ref_biblio_code'];
$ref_author = $_REQUEST['ref_author'];
$ref_title = $_REQUEST['ref_title'];
$ref_part = $_REQUEST['ref_part'];
$ref_uri = $_REQUEST['ref_uri'];
$ref_code = $_REQUEST['ref_code'];
$ref_publisher = $_REQUEST['ref_publisher'];
$ref_location = $_REQUEST['ref_location'];
$ref_year = $_REQUEST['ref_year'];
$ref_style = $_REQUEST['ref_style'];
$ref_template = $_REQUEST['ref_template'];
if (isset($_REQUEST['addreference']) && $action='a_ref') {
if (! $perms->edit_references) {
echo json_encode(
array(
'result'=>tra('failure'),
'message'=>tra('You do not have sufficient permissions to perform this action.')
)
);
exit;
}
$errors = array();
if (intval($page_id)) {
if ($ref_biblio_code=='') {
$errors[] = tra('Please enter Biblio Code.');
}
if (strlen($ref_biblio_code)>50) {
$errors[] = tra('Biblio code must not exceed 50 characters.');
}
if (count($errors)<1) {
$exists = $referenceslib->check_existence($page_id, $ref_biblio_code);
if ($exists > 0) {
echo json_encode(array('result'=>tra('failure'), 'id'=>-1));
} else {
$is_library = $referenceslib->check_lib_existence($ref_biblio_code);
$id = $referenceslib->add_reference(
$page_id,
$ref_biblio_code,
$ref_author,
$ref_title,
$ref_part,
$ref_uri,
$ref_code,
$ref_year,
$ref_style,
$ref_template,
$ref_publisher,
$ref_location
);
echo json_encode(array('result'=>tra('success'), 'id'=>$id, 'is_library'=>$is_library));
}
exit;
} else {
foreach ($errors as $error) {
echo json_encode(array('result'=>$error, 'id'=>''));
exit;
}
}
} else {
$error = tra('Page not found. Please save the page first.');
echo json_encode(array('result'=>$error, 'id'=>''));
exit;
}
}
if (isset($_REQUEST['addlibreference']) && $action = 'a_lib') {
$errors = array();
if (! $perms->use_references) {
echo json_encode(
array(
'result'=>tra('failure'),
'message'=>tra('You do not have sufficient permissions to perform this action.')
)
);
exit;
}
if ($ref_biblio_code == '') {
$errors[] = tra('Please enter Biblio Code.');
}
if (strlen($ref_biblio_code) > 50) {
$errors[] = tra('Biblio code must not exceed 50 characters.');
}
if (count($errors) < 1) {
$exists = $referenceslib->check_lib_existence($ref_biblio_code);
if ($exists > 0) {
echo json_encode(
array(
'result'=>tra('failure'),
'message'=>tra('This reference already exists in the library.'),
'is_library'=>$exists
)
);
} else {
$id = $referenceslib->add_reference(
$ref_biblio_code,
$ref_author,
$ref_title,
$ref_part,
$ref_uri,
$ref_code,
$ref_year,
$ref_style,
$ref_template,
$ref_publisher,
$ref_location
);
echo json_encode(
array(
'result'=>tra('success'),
'message'=>tra('Reference added to library.'),
'id'=>$id,
'is_library'=>$exists
)
);
}
exit;
} else {
foreach ($errors as $error) {
echo json_encode(array('result'=>$error, 'message'=>$error));
exit;
}
}
}
if (isset($_REQUEST['editreference'])) {
if (! $perms->edit_references) {
echo json_encode(
array(
'result'=>tra('failure'),
'message'=>tra('You do not have sufficient permissions to perform this action.')
)
);
exit;
}
$errors = array();
if ($ref_biblio_code == '') {
$errors[] = tra('Please enter Biblio Code.');
} elseif (strlen($ref_biblio_code) > 50) {
$errors[] = tra('Biblio code must not exceed 50 characters.');
} else {
$ref_details = $referenceslib->get_reference_from_id($ref_id);
/*If new code is not equal to previous code, check_existence*/
if ($ref_details['data'][0]['biblio_code'] != $ref_biblio_code) {
$count = $referenceslib->check_existence($page_id, $ref_biblio_code);
if ($count > 0) {
$errors[] = tra('This biblio code already exists.');
}
}
}
if (count($errors)<1) {
$referenceslib->edit_reference(
$ref_id,
$ref_biblio_code,
$ref_author,
$ref_title,
$ref_part,
$ref_uri,
$ref_code,
$ref_year,
$ref_style,
$ref_template,
$ref_publisher,
$ref_location
);
$exists = $referenceslib->check_lib_existence($ref_biblio_code);
echo json_encode(
array(
'result'=>tra('success'),
'message'=>tra('Bibliography saved.'),
'is_library'=>$exists
)
);
exit;
} else {
foreach ($errors as $error) {
echo json_encode(array('result'=>tra('failure'), 'message'=>$error));
}
exit;
}
}
if (isset($_REQUEST['action']) && isset($ref_id)) {
if (! $perms->use_references) {
echo json_encode(
array(
'result'=>tra('failure'),
'message'=>tra('You do not have sufficient permissions to perform this action.')
)
);
exit;
}
if ($_REQUEST['action'] == 'u_lib') {
$exists = $referenceslib->check_existence($page_id, $ref_biblio_code);
$id = $referenceslib->add_lib_ref_to_page($ref_id, $page_id);
if ($id == -1) {
echo json_encode(array('result'=>tra('failure'), 'message'=>tra('Reference already exists.'), 'id'=>$id));
} else {
$details = $referenceslib->get_reference_from_id($id);
foreach ($details['data'][0] as $key=>$data) {
if ($details['data'][0][$key] == NULL) {
if (!$details['data'][0][$key]) {
$details['data'][0][$key] = '';
}
}
}
echo json_encode(
array(
'result'=>tra('success'),
'message'=>tra('Reference added.'),
'id'=>$id,
'ref_biblio_code'=>$details['data'][0]['biblio_code'],
'ref_author'=>$details['data'][0]['author'],
'ref_title'=>$details['data'][0]['title'],
'ref_year'=>$details['data'][0]['year'],
'ref_part'=>$details['data'][0]['part'],
'ref_uri'=>$details['data'][0]['uri'],
'ref_code'=>$details['data'][0]['code'],
'ref_publisher'=>$details['data'][0]['publisher'],
'ref_location'=>$details['data'][0]['location'],
'ref_style'=>$details['data'][0]['style'],
'ref_template'=>$details['data'][0]['template']
)
);
}
exit;
}
}
if (isset($_REQUEST['action']) && isset($ref_id)) {
if (! $perms->edit_references) {
echo json_encode(
array(
'result'=>tra('failure'),
'message'=>tra('You do not have sufficient permissions to perform this action.')
)
);
exit;
}
if ($_REQUEST['action'] == 'e_del') {
$referenceslib->remove_reference($ref_id);
echo tra('success');
}
}