-
Notifications
You must be signed in to change notification settings - Fork 0
/
addlink.php
executable file
·81 lines (66 loc) · 2.07 KB
/
addlink.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
<?php
/**
* Created by PhpStorm.
* User: josh
* Date: 10/03/18
* Time: 15:08
*/
header("Access-Control-Allow-Origin: *");
/**
* @var $servername
* @var $username
* @var $password
* @var $dbname
*/
extract(parse_ini_file('config.ini'));
if (
!(isset($_POST['page']) || strlen($_POST['page']) < 1)
|| (!isset($_POST['doi']) || strlen($_POST['doi']) < 1)
|| (!isset($_POST['paper_title']) || strlen($_POST['paper_title']) < 1)
|| (!isset($_POST['paper_link']) || strlen($_POST['paper_title']) < 1)
|| (!isset($_POST['context']) || strlen($_POST['context']) < 1)
|| (!isset($_POST['reason']) || strlen($_POST['reason']) < 1)
) {
echo 'missing param';
exit;
}
$page = $_POST['page'];
$doi = $_POST['doi'];
$context = $_POST['context'];
$reason = $_POST['reason'];
$paperTitle = $_POST['paper_title'];
$paperLink = $_POST['paper_link'];
$paperId = 0;
$pageId = 0;
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id FROM web_page WHERE link = '$page'";
$result = $conn->query($sql);
if ($result->num_rows === 0) {
$sql = "INSERT INTO web_page(link) VALUES ('$page')";
$result = $conn->query($sql);
}
$sql = "SELECT id FROM web_page WHERE link = '$page'";
$result = $conn->query($sql);
$resultAssoc = $result->fetch_assoc();
$pageId = $resultAssoc['id'];
$sql = "SELECT id FROM academic_paper WHERE doi = '$doi'";
$result = $conn->query($sql);
if ($result->num_rows === 0) {
$sql = "INSERT INTO academic_paper(doi, title, link) VALUES ('$doi', '$paperTitle', '$paperLink')";
$result = $conn->query($sql);
}
$sql = "SELECT id FROM academic_paper WHERE doi = '$doi'";
$result = $conn->query($sql);
$resultAssoc = $result->fetch_assoc();
$paperId = $resultAssoc['id'];
if ($paperId && $pageId) {
$sql = "INSERT INTO page_to_paper (academic_paper_id, web_page_id, link_context, reason, vote_count)
VALUES ($paperId,$pageId,'$context','$reason', 1)";
$result = $conn->query($sql);
}
$conn->close();