forked from salzh/mobevoice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.cgi
executable file
·221 lines (201 loc) · 6.53 KB
/
index.cgi
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/usr/bin/perl
require "include.cgi";
#commit by yang
#=======================================================
# clear cookie se necessario
#=======================================================
if ($form{delete_invite_cookie} eq 1) {
&cookie_save("i","","expires=Sun, 26-Jun-2011 00:00:00 GMT;");
print "content-type: text/html\n\n";
print qq[
<html><head>
<META HTTP-EQUIV="Expires" CONTENT="0">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=/">
</head><body><script>window.location='/'</script></body></html>
];
exit;
}
#=======================================================
#=======================================================
# do the magic
#=======================================================
%t = ();
#
#--------------------------------
# get invite
#--------------------------------
%invite = ();
$invite{ok} = 0;
$buf = $ENV{REQUEST_URI};
$refcode=$form{referal};
$t{dic}{referal_code}="";
$t{dic}{referal_default}="soup";
if( $refcode eq "" )
{
$t{dic}{referal_error}=0;
$t{dic}{referal_code}="";
}
else
{
$t{dic}{referal_error}=1;
$t{dic}{referal_code}=$refcode;
}
$invite{no_invite}=1;
if( ($buf eq "/" ) || ( $buf eq "" ) ) { $buf = "soup" ; $invite{no_invite} = 1;};
if ( ($buf ne "") && (index($buf,"=") eq -1) && (index($buf,"&") eq -1) ) {
#
# tentar pegar invite pela url
warning($buf);
$buf = (index($buf,"?") ne -1) ? substr($buf,index($buf,"?")+1,100) : $buf;
warning("2:".$buf);
$buf = (index($buf,"=") ne -1) ? substr($buf,0,index($buf,"=")) : $buf;
warning("3:".$buf);
$buf = (index($buf,"&") ne -1) ? substr($buf,0,index($buf,"&")) : $buf;
warning("5:".$buf);
$buf = (length($buf) < 5) ? "" : $buf;
$buf = (length($buf) > 10) ? "" : $buf;
if ($buf ne "") {
if( $buf ne "soup" ) { $invite{no_invite} = 0};
$sql = "
select
1,1,
service.id,
service.name,
service_status.refer_status
from
service_invite,
service,
service_status
where
service_invite.free = 0 and
service_invite.service_id = service.id and
service.status = service_status.id and
service_status.deleted = 0 and
service_status.can_add_refer = 1 and
service_invite.id = '$buf'
";
%hash = database_select_as_hash($sql,"flag,id,name,referral_status");
if ($hash{1}{flag} eq 1)
{
$invite{ok} = 1;
$invite{id} = $buf;
$invite{service_name} = $hash{1}{name};
$invite{service_id} = $hash{1}{id};
$invite{service_referral_status}= $hash{1}{referral_status};
&cookie_save("i",$invite{id},"expires=Thu, 31-Dec-2020 00:00:00 GMT;");
}
}
}
if ($invite{ok} eq 0) {
#
# se nao veio por url, tentar por cookie
$buf = $cookie{"i"};
$buf = ($buf eq "") && ($form{invite} ne "") ? $form{invite} : $buf;
$buf = clean_str(substr($buf,0,100),"MINIMAL");
$buf = (length($buf) < 5) ? "" : $buf;
$buf = (length($buf) > 20) ? "" : $buf;
if( $buf eq "soup" ) { $invite{no_invite} = 1; }
if ($buf ne "") {
$sql = "
select
1,1,
service.id,
service.name,
service_status.refer_status
from
service_invite,
service,
service_status
where
service_invite.free = 0 and
service_invite.service_id = service.id and
service.status = service_status.id and
service_status.deleted = 0 and
service_status.can_add_refer = 1 and
service_invite.id = '$buf'
";
%hash = database_select_as_hash($sql,"flag,id,name,referral_status");
if ($hash{1}{flag} eq 1) {
$invite{ok} = 1;
$invite{id} = $buf;
$invite{service_name} = $hash{1}{name};
$invite{service_id} = $hash{1}{id};
$invite{service_referral_status}= $hash{1}{referral_status};
&cookie_save("i",$invite{id},"expires=Thu, 31-Dec-2020 00:00:00 GMT;");
}
}
}
#
#--------------------------------
# get coupon
#--------------------------------
%coupon = ();
$coupon{exists} = 0;
$coupon{in_stock} = 0;
$coupon{stock_qtd} = 0;
$coupon{assigned} = 0;
if ( ($invite{ok} eq 1) && ($invite{service_referral_status} ne "") && ($invite{service_referral_status} > 0) ) {
$sql = "
select
1,1,
service_coupon_type.id,
service_coupon_type.title,
service_coupon_type.ui_msg_in_stock,
service_coupon_type.ui_msg_out_stock,
service_coupon_type.ui_msg_assigned
from
service_status,service_coupon_type,service_coupon_type_status
where
service_status.id='$invite{service_referral_status}' and
service_status.coupon_id_new_service = service_coupon_type.id and
service_coupon_type.status = service_coupon_type_status.id and
service_coupon_type_status.is_active = 1
";
%hash = database_select_as_hash($sql,"flag,id,title,msg_in_stock,msg_out_stock,msg_assigned");
if ($hash{1}{flag} eq 1) {
$coupon{exists} = 1;
$coupon{type_id} = $hash{1}{id};
$coupon{title} = $hash{1}{title};
$coupon{msg_in_stock} = $hash{1}{msg_in_stock};
$coupon{msg_out_stock} = $hash{1}{msg_out_stock};
$coupon{msg_assigned} = $hash{1}{msg_assigned};
$sql = "
select 1,1,count(*)
from
service_coupon_stock,
service_coupon_stock_status
where
service_coupon_stock.coupon_type_id='$coupon{type_id}' and
service_coupon_stock.status = service_coupon_stock_status.id and
service_coupon_stock_status.is_ready_to_assign
";
%hash = database_select_as_hash($sql,"flag,value");
if ($hash{1}{flag} eq 1) {
$coupon{in_stock} = ($hash{1}{value}>0) ? 1 : 0;
$coupon{stock_qtd} = $hash{1}{value};
}
}
}
#
#--------------------------------
# print page
#--------------------------------
$t{dic}{my_url} = "index.cgi";
$t{dic}{coupon_exists} = $coupon{exists};
$t{dic}{coupon_in_stock} = $coupon{in_stock};
$t{dic}{coupon_stock_qtd} = &format_number($coupon{stock_qtd},0);
$t{dic}{coupon_type_id} = $coupon{type_id};
$t{dic}{coupon_title} = $coupon{title};
$t{dic}{coupon_msg_in_stock} = $coupon{msg_in_stock};
$t{dic}{coupon_msg_out_stock} = $coupon{msg_out_stock};
$t{dic}{coupon_msg_assigned} = $coupon{msg_assigned};
$t{dic}{invite_ok} = $invite{ok};
$t{dic}{invite_id} = $invite{id};
$t{dic}{invite_service_id} = $invite{service_id};
$t{dic}{invite_service_name} = $invite{service_name};
$t{dic}{no_invite_service} = $invite{no_invite};
&template_print("template.services.html",%t);
exit;
#=======================================================