-
Notifications
You must be signed in to change notification settings - Fork 0
/
getData.php
66 lines (51 loc) · 1.66 KB
/
getData.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
<?php
/*** FUNCTIONS CALLED BY AJAX ***/
// turn on debugging mode
error_reporting(E_ALL);
ini_set('display_errors', True);
// includes
include "updateState.php";
include 'imgResize.php';
include "htmlFunctions.php";
require_once('DBController.phps');
if (isset($_POST['data'])) {
if($_POST['data'] == 'contentByCategory'){
echo contentByCategory();
}else if($_POST['data'] == 'embedCodeByID'){
echo embedCodeByID();
}
}
function contentByCategory(){
// new db connection
$db = new DBController();
$result = $db->getContentByCategory($_SESSION['category'], $_SESSION['sortBy'], $_SESSION['sortDir']);
// return json object
$rows = array();
while($r = $result->fetch_assoc()) {
$rows[] = $r;
}
// close database
$db->close();
return json_encode($rows);
}
// returns the embed code for a video or trailer of given video ID
function embedCodeByID(){
if (isset($_POST['id'])) {
if(isset($_POST['type']) && $_POST['type']=="watch"){
$colName = "URLwatch";
}else if($_POST['type']=="trailer"){
$colName = "URLtrailer";
}
if(isset($colName)){
$db = new DBController();
$result = $db->getEmbedCodeByID($_POST['id'], $colName);
$db->close();
return $result;
}else{
echo "Error: unknown type.";
}
}else{
echo "Error: no given ID.";
}
}
?>