This repository has been archived by the owner on Aug 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcrud.Highlight.php
90 lines (83 loc) · 3.06 KB
/
crud.Highlight.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
<?php
include "conn.php";
include "class.Highlight.php";
$conn->query("SET NAMES utf8");
$success = true;
$html = "";
if ($_POST["action"] == "create"){
try {
$stmt = $conn->prepare('INSERT INTO highlights (talk_id, title, start_at, thumbnail_link, owner) VALUES(:talk_id, :title, :start_at, :thumbnail_link, :owner)');
$stmt->bindParam(':talk_id', $_POST["talk_id"], PDO::PARAM_INT);
$stmt->bindParam(':title', $_POST["title"], PDO::PARAM_STR);
$stmt->bindParam(':start_at', $_POST["start_at"], PDO::PARAM_STR);
$stmt->bindParam(':thumbnail_link', $_POST["thumbnail_link"], PDO::PARAM_STR);
$stmt->bindParam(':owner', $_POST["owner"], PDO::PARAM_STR);
$stmt->execute();
if ($stmt->rowCount() != 1)
$success = false;
else {
$stmt2 = $conn->prepare("SELECT * from highlights WHERE id=:id");
$stmt2->setFetchMode(PDO::FETCH_CLASS, "Highlight");
$stmt2->execute(array('id' => $conn->lastInsertId()));
while($obj = $stmt2->fetch()) {
$highlight = $obj;
}
$html = $highlight->getHTML();
$json = array(
"id"=>$highlight->id,
"start_at"=>$highlight->start_at,
"html"=>$html,
"success"=>$success
);
}
} catch(PDOException $e) {
$success = false;
file_put_contents('log/database.log', date("Y-m-d H:i:s") . " " . $e->getMessage() . "\n", FILE_APPEND);
}
} else if ($_POST["action"] == "update"){
try {
$stmt = $conn->prepare('UPDATE highlights SET title=:title, start_at=:start_at, thumbnail_link=:thumbnail_link, owner=:owner WHERE id=:id');
$stmt->bindParam(':id', $_POST["id"], PDO::PARAM_INT);
$stmt->bindParam(':title', $_POST["title"], PDO::PARAM_STR);
$stmt->bindParam(':start_at', $_POST["start_at"], PDO::PARAM_STR);
$stmt->bindParam(':thumbnail_link', $_POST["thumbnail_link"], PDO::PARAM_STR);
$stmt->bindParam(':owner', $_POST["owner"], PDO::PARAM_STR);
$stmt->execute();
// not checking for rowCount == 1, because if duplicate info was inserted for save, it will return 0.
$stmt2 = $conn->prepare("SELECT * from highlights WHERE id=:id");
$stmt2->setFetchMode(PDO::FETCH_CLASS, "Highlight");
$stmt2->execute(array('id' => $_POST["id"]));
while($obj = $stmt2->fetch()) {
$highlight = $obj;
}
$html = $highlight->getHTML();
$json = array(
"id"=>$highlight->id,
"start_at"=>$highlight->start_at,
"html"=>$html,
"success"=>$success
);
} catch(PDOException $e) {
$success = false;
file_put_contents('log/database.log', date("Y-m-d H:i:s") . " " . $e->getMessage() . "\n", FILE_APPEND);
}
} else if ($_POST["action"] == "delete"){
try {
$stmt = $conn->prepare('DELETE FROM highlights WHERE id=:id');
$stmt->execute(array(
'id' => $_POST["id"]
));
if ($stmt->rowCount() != 1)
$success = false;
else {
$json = array(
"success"=>$success
);
}
} catch(PDOException $e) {
$success = false;
file_put_contents('log/database.log', date("Y-m-d H:i:s") . " " . $e->getMessage() . "\n", FILE_APPEND);
}
}
echo json_encode($json);
?>