-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrequest.php
75 lines (59 loc) · 2.14 KB
/
request.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
<?php
include_once "./template/functions.php";
include_once "./template/config.php";
include_once "globals.php";
$username = isset($_SESSION['user']) ? $_SESSION['user'] : null;
if (empty($username)) { exit; }
if (isDemo()) { exit; }
$ids = getEscGPost('ids');
if (empty($ids)) { exit; }
if (!isLoggedIn()) { echo '-3'; return; }
$isShow = isset($_POST['isShow']) || isset($_GET['isShow']);
$copyAsScript = getEscGPost('copyAsScript', 0);
$forOrder = getEscGPost('forOrder', 0);
$res = getItemsForRequest($ids, $isShow);
if (empty($res)) {
echo $forOrder == 1 ? '-1' : null;
return;
}
if ($forOrder == 0) {
echo $isShow ? doTheStuffTvShow($res) : doTheStuffMovie($res, fetchVariantIds());
return;
}
$saveOrderInDB = isset($GLOBALS['SAVE_ORDER_IN_DB']) ? $GLOBALS['SAVE_ORDER_IN_DB'] : false;
if ($saveOrderInDB && existsOrderzTable()) {
$append = isset($_SESSION['param_idOrder']);
$idOrder = $append ? $_SESSION['param_idOrder'] : getIdOrder();
$_SESSION['param_idOrder'] = $idOrder;
$SQL = "INSERT OR IGNORE INTO orderz VALUES(".$idOrder.", '".time()."', '".$username."', 1);";
execSQL($SQL, false);
$idAr = explode(", ", $ids);
foreach($idAr as $id) {
$SQL = "INSERT OR IGNORE INTO orderItemz VALUES(".$idOrder.", ".$id.", ".($isShow ? 0 : 1).");";
execSQL($SQL, false);
}
echo $append ? '2' : '1';
} else if (existsOrdersTable()) {
//to prevent spamming, no minutes and seconds in filename!
$fname = './orders/'.date('Ymd_').$username.'.order';
$append = isFile($fname);
$content = $isShow ? doTheStuffTvShow($res, true) : doTheStuffMovie($res, true);
if ($append) {
$fsize = filesize($fname);
$file = fopen($fname, 'r');
$content0 = fread($file, $fsize);
fclose($file);
$ar0 = explode("\n", $content0);
$ar1 = explode("\n", $content);
$ar = array_filter(array_unique(array_merge($ar0, $ar1)));
sort($ar);
$content = implode("\n", $ar);
}
$file = fopen($fname, 'w+');
fwrite($file, $content);
fclose($file);
$SQL = "REPLACE INTO orders VALUES('".$fname."', '".time()."', '".$username."', 1);";
execSQL($SQL, false);
echo $append ? '2' : '1';
}
?>