-
Notifications
You must be signed in to change notification settings - Fork 1
/
form_post.php
184 lines (161 loc) · 5.83 KB
/
form_post.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
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
<?php
######################################################################
# Wi-Fi-voucher-o-matic - Wi-Fi voucher manager
# Copyright (C) 2017, 2018 Valerio Bozzolan, Ivan Bertotto, IIS Avogadro
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
######################################################################
require 'load.php';
Header::spawn('form_post');
?>
<section class="mbr-section mbr-section-nopadding" id="video1-l">
<div class="mbr-figure">
<div><img src="<?php echo STATIC_ROOT ?>/images/avowifiok-1400x602.png"></div>
<div class="mbr-figure-caption">
<div class="container">
<?php
if( isset(
$_POST['user_name'],
$_POST['user_surname'],
$_POST['user_uid'],
$_POST['user_type']
) ) {
$_POST['user_name'] = luser_input( $_POST['user_name'], 32 );
$_POST['user_surname'] = luser_input( $_POST['user_surname'], 32 );
$_POST['user_uid'] = luser_input( $_POST['user_uid'], 128 );
$type = User::filterType( $_POST['user_type'] );
$existing_user = User::factoryFromUID( $_POST['user_uid'] )
->queryRow();
// An administrator should send manually a voucher to the registered user?
$rausa_must_send_voucher = false;
// create if not exists
if( ! $existing_user ) {
$create = true;
if( $type === User::TYPE_ATA || $type === User::TYPE_MENTHOR ) {
if( ! has_permission('register_whatever_ata_mail') ) {
if( ! User::filterCompanyEmail( $_POST['user_uid'] ) ) {
$create = false;
}
}
} elseif( $type === User::TYPE_STUDENT ) {
if( ! User::filterCompanyEmail( $_POST['user_uid'] ) ) {
// It's OK to create this user, but it's not OK to send directly the voucher
$rausa_must_send_voucher = true;
}
}
if( $create ) {
$class_name = User::filterClassNumber( @ $_POST[ User::CLASS_NUMBER ] );
$section = User::filterClassSection( @ $_POST[ User::CLASS_SECTION ] );
$daytype = User::filterDaytype( @ $_POST[ User::DAYTYPE ] );
$specialization = User::filterSpecialization( @ $_POST[ User::SPECIALIZATION ] );
insert_row( User::T, [
new DBCol( User::NAME, $_POST['user_name'], 's' ),
new DBCol( User::SURNAME, $_POST['user_surname'], 's' ),
new DBCol( User::UID, $_POST['user_uid'], 's' ),
new DBCol( User::TYPE, $type, 's' ),
new DBCol( User::CLASS_NUMBER, $class_number, 'snull' ),
new DBCol( User::CLASS_SECTION, $class_section, 'snull' ),
new DBCol( User::DAYTYPE, $daytype, 'snull' ),
new DBCol( User::SPECIALIZATION, $specialization, 'snull' ),
] );
$existing_user = User::factoryFromID( last_inserted_ID() )
->queryRow();
} else {
MessageBox::error( __( "Non hai i permessi per registrare personale interno." ) );
}
}
// send if it exists
if( $existing_user ) {
$voucher_type = Voucher::filterType( $existing_user->get(User::TYPE) );
$yet_obtained_vouchers = 0;
$MAX_VOUCHERS = 5;
if( $voucher_type === User::TYPE_MENTHOR ) {
$MAX_VOUCHERS = 10;
}
$yet_obtained_vouchers = (int) RelUserVoucher::factory()
->whereInt( RelUserVoucher::USER_, $existing_user->get( User::ID ) )
->select('COUNT(*) as count')
->queryValue('count');
if( $yet_obtained_vouchers > $MAX_VOUCHERS ) {
MessageBox::warning( __( "Hai raggiunto il massimo numero di voucher a tua disposizione." ) );
}
$voucher = Voucher::factory()
->whereStr( Voucher::TYPE, $voucher_type )
->where( 'NOT EXISTS (' .
RelUserVoucher::factory()
->equals( RelUserVoucher::VOUCHER_, Voucher::ID_ )
->getQuery() .
')' )
->limit( 1 )
->queryRow();
if( $voucher ) {
RelUserVoucher::insertUserVoucher(
$existing_user->get( User::ID ),
$voucher ->get( Voucher::ID )
);
$yet_obtained_vouchers++;
$email = $rausa_must_send_voucher
? RAUSA_EMAIL
: $existing_user->get( User::UID );
$subject = $rausa_must_send_voucher
? sprintf(
__( "L'utente %s chiede un voucher %s" ),
esc_html( $existing_user->get( User::UID ) ),
$existing_user->get( User::TYPE )
)
: __("Il tuo voucher IIS Avogadro");
SMTPMail::send(
$email,
$subject,
file_get_contents( STATIC_PATH . __ . 'email.html' ),
[
'CODICE' => esc_html( $voucher->get(Voucher::CODE) ),
'NOME' => esc_html( $_POST['user_name'] ),
'COGNOME' => esc_html( $_POST['user_surname'] ),
'NUMERO' => $yet_obtained_vouchers,
'NUMERI' => $MAX_VOUCHERS
]
);
if( $rausa_must_send_voucher ) {
MessageBox::info( sprintf(
__(
"Una e-mail è stata inviata a %s (%s) che ti contatterà privatamente. ".
"Se non ricevi comunicazioni, contattalo."
),
RAUSA_NAME,
RAUSA_EMAIL
) );
} else {
$done = true;
}
} else {
MessageBox::error( __( "Voucher terminati. Contattare Ivan." ) );
}
}
}
?>
<?php if( $done ): ?>
<p><h1><?php _e( "Ottimo!" ) ?></h1></p>
<p><?php _e( "Leggi la posta." ) ?></p>
<?php _e( "Ti abbiamo inviato il codice per iniziare da subito a navigare." ) ?>
<br />
<b><?php _e( "Buona navigazione!" ) ?></b>
<?php endif ?>
</div>
<!-- /.container -->
</div>
<!-- /.figure-caption -->
</div>
</section>
<?php
Footer::spawn();