-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
145 lines (129 loc) · 4.14 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
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
<!doctype html>
<!--
Developer: Evangelos "bugos" Mamalakis <mamalakis@auth.gr>
-->
<?php
define('api', 'http://whatsup.ogilvy.phaistosnetworks.gr/api');
$phone = (isset($_COOKIE['phone']))? $_COOKIE['phone'] : '';
$code = (isset($_COOKIE['code'])) ? $_COOKIE['code'] : '';
?>
<img src="http://www.whatsup.gr/reloadit/app/media/images/logo.png"/>
<!-- Start of main form -->
<div style="background-color:grey; border:1px solid black; border-radius:5px; padding: 5px 5px 0px 10px; float:right; ">
<form name="form1" method="POST">
<? //This form is disabled by default. enable_login_form() is used to enable it when needed ?>
Phone:<input name="phone" value="<?=$phone?>" disabled />
Code: <input name="code" value="<?=$code?>" disabled />
<input type="submit" name="button" value="Go!" disabled />
<a class="link" href="?logout=1"> Logout!</a>
</form>
</div>
<!--End of main form -->
<?php
//Logout. Used by the 'Logout' link.
if ( isset($_GET['logout']) ) {
delete_cookies();
header("Location: {$_SERVER['PHP_SELF']}");
}
/* */
if ( isset($_POST['phone']) && isset($_POST['code']) )
{//Form submitted. Set the cookies and reload.
setcookie('phone', $_POST['phone'], time()+ 2* 3600);
setcookie('code', $_POST['code'], time()+ 2* 3600);
header("Location: {$_SERVER['PHP_SELF']}");
}
elseif ( $phone != '' AND $code != '' )
{//Cookies set! Let's reload!!!
if ( reload($phone, $code) ) {
reload($phone, 'trick');
}
}
else { //First visit.
enable_login_form();
}
function reload($phone, $code)
{
?>
<!--<form method="POST" action="/reload.php"><input name="prizeid"/><input type="submit"/></form> -->
<?
$url = constant('api')."?method=runLottery&msisdn=$phone&code=$code";//
/*===DEBUG===*/ if ($code == 'test') $url = './FILES/fake.php';
if ( $code == 'trick' ) $url = './FILES/data.txt';
$json = file_get_contents($url);
$d = json_decode($json, true);
//Logging
if ( $code != 'trick' ) {
$log = strftime('%c'). "\t" . $json . "\r\n\r\n" ;
file_put_contents('./FILES/log.txt', $log, FILE_APPEND);
}
if ($d['result'] == 'v')
{ //code accepted
if ( $d['type'] == 's' ) {
$type = 'Silver';
}
if ( $d['type'] == 'g' ) {
$type = 'Gold';
}
/* else ERROR */
?>
<!--<div style="background-color:<?=$type?>;"><h3><?=$type?></h3></div> -->
<!-- Start data table -->
<br><br><br>
<table cellspacing="0">
<?
foreach ( $d['extra']['chooseyourself'] as $prize)
{
$image = $prize['bigimagepath'];
$title = $prize['title'];
$description = $prize['description'];
$prizeid = $prize['prizeid'];
?>
<tr style="color:#0066CC" align="center" onclick="document.location='/reload.php?prizeid=<?=$prizeid?>';">
<td width="100px"><img width="100%" src="<?=$image?>"/></a></td>
<td width="250px"><h2><?=$title?></h2></td>
<td><?=$description?></td>
<!--<td><?=$prizeid?></td> -->
</tr>
<?
}
?>
</table>
<!-- End data table -->
<?
/*===DEBUG===*/ echo "<!--<br><div style=\"background-color:grey\">$json </div> -->"; //Debug!
return True; //Everything went well
}
else
{//Server returned an Error!
enable_login_form();
//delete_cookies();
echo "<h1>Error! Code: {$d['error_code']}</h1>";
echo "{$d['error_string']}";
/*===DEBUG===*/ echo "<br>Url: $url <br> $json";
return 0;
}
}
function enable_login_form() {
?>
<script type="text/javascript">
document.form1.phone.disabled=false;
document.form1.code.disabled=false;
document.form1.button.disabled=false;
</script>
<style type='text/css'>.link {display:none;}</style>
<?
}
function delete_cookies() {
setcookie('phone', '', time() - 3600);
setcookie('code' , '', time() - 3600);
}
?>
<!--CSS -->
<style type="text/css">
body { background: url("./FILES/bg.jpg"); text-align:center; color:white;}
h1 { color:red; text-align:center; }
h2 { color:#0066CC; text-align:center; }
table {background-color:eee000;border:3px dashed black; border-radius:10px}
tr {-webkit-transition: background-color 0.3s;}
tr:hover { background-color: yellow; cursor:pointer;}
</style>