forked from wosenbo/happyfactory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
95 lines (85 loc) · 2.32 KB
/
index.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
91
92
93
94
95
<?php
function get_factories() {
global $db;
static $factories = null;
if (is_null($factories)) {
$factories = array();
$query = $db->query("SELECT * FROM game_factorys");
while ($factory = $db->fetch_array($query)) {
$factories[] = $factory;
}
}
return $factories;
}
function get_user_factories($uid) {
global $db;
$user_facts = array();
$factories = get_factories();
foreach ($factories as $factory) {
$user_fact = $db->fetch_first("SELECT factid, status FROM game_userfactory WHERE uid = {$uid} AND factid = {$factory['factid']}");
$status = $user_fact ? $user_fact['status'] : 0;
$user_facts[] = array(
'factid' => $factory['factid'],
'factoryname' => $factory['factoryname'],
'pic' => $factory['pic'],
'pic_act' => $factory['pic2'],
'status' => $status,
);
}
return $user_facts;
}
function get_studies() {
global $db;
$studies = [];
$query = $db->query("SELECT * FROM game_studys ORDER BY level");
while ($study = $db->fetch_array($query)) {
$studies[] = $study;
}
return $studies;
}
function get_advises($uid) {
global $db;
$advises = array();
$query = $db->query("SELECT * FROM game_advices WHERE uid = '{$uid}'");
while ($advise = $db->fetch_array($query)) {
$advises[] = $advise;
}
return $advises;
}
require_once './include/api.php';
require_once './include/user.func.php';
$action = gp('action');
// inviter_reward();
// login_reward();
$logs = array();
switch($action){
case 'factory':
json_result(['factories' => get_user_factories($uid)]);
break;
case 'study':
json_result([
'studies' => get_studies(),
'user_study' => get_user_study($uid)]);
break;
}
$smarty->assign('factoryList', get_user_factories($uid));
$userStudy = get_user_study($uid);
if (!$userStudy) {
$smarty->assign('userStudy', 0);
} else {
$levels = array();
$studies = get_studies();
foreach ($studies as $study) {
$levels[] = array(
'efficiency' => $study['efficiency'],
'cost' => $study['cost'],
'level' => $study['level'],
);
}
$smarty->assign('elevel', $userStudy['elevel']);
$smarty->assign('clevel', $userStudy['clevel']);
$smarty->assign('studyLevels', $levels);
$smarty->assign('userStudy', 1);
}
$smarty->assign('adviceList', get_advises($uid));
$smarty->display('index.html');