-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathfunctions.php
More file actions
155 lines (132 loc) · 3.81 KB
/
Copy pathfunctions.php
File metadata and controls
155 lines (132 loc) · 3.81 KB
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
<?php
function get_connection(){
$dsn = "mysql:host=localhost;dbname=wftutorials";
$user = "root";
$passwd = "";
$conn = new PDO($dsn, $user, $passwd);
return $conn;
}
function save_song($name, $length, $artist){
$conn = get_connection();
$sql = "INSERT INTO songs(`name`, `length`, `artist`) VALUES (?,?,?)";
$query = $conn->prepare($sql);
$query->execute([$name, $length, $artist]);
return $conn->lastInsertId();
}
function save_lyric($song, $content, $order, $id=""){
try{
$conn = get_connection();
if($id){
$sql = "UPDATE song_lyrics set `content`=?, `priority`=? WHERE id=?";
$query = $conn->prepare($sql);
$query->execute([$content, $order, $id]);
return $id;
}else{
$sql = "INSERT INTO song_lyrics(`song_id`,`content`,`priority`) VALUES (?,?,?)";
$query = $conn->prepare($sql);
$query->execute([$song, $content, $order]);
return $conn->lastInsertId();
}
}catch (Exception $e){
echo $e->getMessage();
};
}
function get_all_songs(){
$results = [];
try{
$conn = get_connection();
$results = $conn->query("SELECT * from songs");
}catch (Exception $e){
}
return $results;
}
function get_all_lyrics($id){
$results = [];
try{
$conn = get_connection();
$query = $conn->prepare("SELECT * from song_lyrics WHERE song_id=?");
$query->execute([$id]);
$results = $query->fetchAll();
}catch (Exception $e){
}
return $results;
}
function get_lyric($id){
$results = [];
try{
$conn = get_connection();
$query = $conn->prepare("SELECT * from song_lyrics WHERE id=? LIMIT 1");
$query->execute([$id]);
$results = $query->fetchAll();
if(isset($results[0])){
$results = $results[0];
}
}catch (Exception $e){
}
return $results;
}
function delete_song_lyric($id){
$conn = get_connection();
$sql= "DELETE FROM song_lyrics WHERE id=?";
$query = $conn->prepare($sql);
$query->execute([$id]);
}
function redirectPage($page){
header("Location: $page");
exit();
}
function get_song($id){
$results = [];
try{
$conn = get_connection();
$query = $conn->prepare("SELECT * from songs WHERE id=? LIMIT 1");
$query->execute([$id]);
$results = $query->fetchAll();
if(isset($results[0])){
$results = $results[0];
}
}catch (Exception $e){
}
return $results;
}
function get_current_lyric($id){
$results = get_lyric($id);
return $results;
}
function get_next_url($song, $current){
$nextId = 0;
$conn = get_connection();
$query = $conn->prepare("SELECT * from song_lyrics WHERE song_id=? and id > ? order by priority desc LIMIT 1");
$query->execute([$song,$current]);
$results = $query->fetchAll();
if(count($results) > 0){
$nextId = $results[0]["id"];
return 'play.php?song='.$song.'¤t='.$nextId;
}else{
return 'end.php?song='.$song;
}
}
function get_previous_url($song, $current){
$nextId = 0;
$conn = get_connection();
$query = $conn->prepare("SELECT * from song_lyrics WHERE song_id=? and id < ? order by id desc LIMIT 1");
$query->execute([$song,$current]);
$results = $query->fetchAll();
if(count($results) > 0){
$nextId = $results[0]["id"];
return 'play.php?song='.$song.'¤t='.$nextId;
}else{
return 'start.php?song='.$song;
}
}
function setFontSize($val){
setcookie("FONTSIZE", $val, time() + (60*60*24*10));
}
function getFontSize(){
$fs = isset($_COOKIE['FONTSIZE']) ? $_COOKIE["FONTSIZE"] : "55";
return $fs;
}
function getStoredFontSize(){
$fs = getFontSize();
return $fs . "px";
}