-
Notifications
You must be signed in to change notification settings - Fork 1
/
joinola.php
227 lines (192 loc) · 6.52 KB
/
joinola.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
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
219
220
221
222
223
224
225
226
227
<?php
/**
* @package Joinola
*/
/*
Plugin Name: Joinola
Plugin URI: http://vgafib.upc.es/
Description: Afegeix la cadena de text '[gjb year="XXXX"]' a una entrada on XXXX es l'any i es substituira per el formulari d'inscripcio. Es necesari instalar el plugin "Paypal Framework" per el correcte funcionament.
Version: 0.1
Author: BuD
Author URI: http://github.com/budsan
License: GPLv2 or later
*/
/*
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 2
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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
define('WP_DEBUG', true);
define('GJB_PLUGIN_URL', plugin_dir_url( __FILE__ ));
//Aqui s'acomulen els errors i es mostren tots al final.
$gjb_errs = array();
include_once dirname(__FILE__)."/global.php";
include_once dirname(__FILE__)."/lang.php";
include_once dirname(__FILE__)."/user.php";
include_once dirname(__FILE__)."/admin.php";
include_once dirname(__FILE__)."/form.php";
function gjb_displayErrors()
{
global $gjb_errs;
if (count($gjb_errs) == 0) return "";
$errDisplay = "";
for ($i = 0; $i < count($gjb_errs); $i++)
{
if ($i > 0) $errDisplay .= "<br/>";
$errDisplay .= "<tt class='gjb_err'>".$gjb_errs[$i]."</tt>";
}
return "<div class='clearfix gjb_errors'> {$errDisplay}</div>";
}
function gjb_install()
{
global $wpdb;
global $gjb_table_sufix_name;
$table_name = $wpdb->prefix.$gjb_table_sufix_name;
$sql = "CREATE TABLE {$table_name} (
Year int(11) NOT NULL,
ID int(11) NOT NULL,
Nom varchar(255) NOT NULL,
Cognoms varchar(255) NOT NULL,
NIF varchar(255) NOT NULL,
Email varchar(255) NOT NULL,
Edat int(11) DEFAULT 0 NOT NULL,
Sexe tinyint(1) DEFAULT 2 NOT NULL COMMENT '0 mujer 1 hombre 2 ns/nc',
Camiseta tinyint(1) DEFAULT 3 NOT NULL COMMENT '0 XS, 1 S, 2 M, 3 L, 4 XL, 5 XXL',
Comarca varchar(255) DEFAULT '' NOT NULL,
Coneguts int(11) DEFAULT 0 NOT NULL,
TipusPC varchar(255) DEFAULT '' NOT NULL,
Especialitat varchar(255) DEFAULT '' NOT NULL,
Estudis varchar(255) DEFAULT '' NOT NULL,
FinEstudis tinyint(1) DEFAULT 0 NOT NULL COMMENT '0 no 1 sí',
Treball varchar(255) DEFAULT '' NOT NULL,
BuscoFeina tinyint(1) DEFAULT 0 NOT NULL COMMENT '0 no 1 sí',
Fecha varchar(255) DEFAULT '' NOT NULL,
PaypalToken varchar(255) DEFAULT '' NOT NULL,
Confirmat tinyint(1) DEFAULT 0 NOT NULL COMMENT '0 no 1 sí',
PRIMARY KEY (Year, ID),
UNIQUE KEY NIF (NIF));";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
/* $gjb_db_version = 0.1;
add_option("gjb_db_version", $gjb_db_version);
$installed_ver = get_option( "gjb_db_version" );
if( $installed_ver != $gjb_db_version )
{
update_option( "gjb_db_version", $gjb_db_version );
}
*/
}
register_activation_hook(__FILE__,'gjb_install');
add_action('plugins_loaded', 'gjb_install');
function gjb_init()
{
$plugin_dir = basename(dirname(__FILE__));
load_plugin_textdomain( 'gjb', false, $plugin_dir );
wp_register_script('xregexp.js', GJB_PLUGIN_URL.'xregexp.js');
wp_enqueue_script('xregexp.js');
wp_register_script('xregexp-unicode-base.js', GJB_PLUGIN_URL.'xregexp-unicode-base.js');
wp_enqueue_script('xregexp-unicode-base.js');
wp_register_script('form.js', GJB_PLUGIN_URL.'form.js');
wp_enqueue_script('form.js');
wp_register_style('gjb-reg.css', GJB_PLUGIN_URL.'gjb-reg.css');
wp_enqueue_style('gjb-reg.css');
}
add_action('init', 'gjb_init');
function gjb_options()
{
if (!current_user_can('manage_options'))
wp_die( __('You do not have sufficient permissions to access this page.') );
echo gjb_obteOpcions();
}
function gjb_menu()
{
add_options_page('GJB Options', 'Game Jam Barcelona', 'manage_options', 'gjb', 'gjb_options');
}
add_action('admin_menu', 'gjb_menu');
function gjb_obteFormulari( $year, $closed, $limit)
{
global $lang;
global $wpdb;
global $current_user;
$command = gjb_getCommand();
if (strcmp($command, "registrar") == 0) gjb_registrarUsuari($year);
$userinfo = gjb_getUserInfo($year, $current_user->ID);
if(count($userinfo) == 0)
{
$num_users = gjb_getUserRegistred($year);
if ($limit != 0 && $limit <= $num_users)
return $lang['ERR_NO_PLACES'];
return gjb_obteFormulariRegistre($year);
}
$token = $userinfo[0]->PaypalToken;
$confirmat = $userinfo[0]->Confirmat == 1 ? true : false;
if (!$confirmat)
{
if (strcmp($command,"confirmar") == 0)
{
$confirmat = gjb_confirmarPagamentUsuari($year, $token);
if ($confirmat)
{
$email = $userinfo[0]->Email;
$nom = html_entity_decode($userinfo[0]->Nom);
$mailbody = $lang['EMAIL_HELLO'].
" ".$nom.",\n\n".$lang['EMAIL_SUCCESS_TEXT'];
$mailbody = html_entity_decode($mailbody);
$subject = html_entity_decode($lang['EMAIL_SUCCESS_SUBJECT']);
wp_mail($email, $subject, $mailbody);
}
}
else if (strcmp($command, "cancelpago") == 0)
gjb_obteNouPaypalTokenUsuari($year, $token);
}
if ($confirmat) return gjb_obteVistaUsuariConfirmat($year, $userinfo);
if (empty($token)) gjb_obteNouPaypalTokenUsuari($year, $token);
if (!empty($token))
{
$response = gjb_obtePaypalTokenInfo($token);
if (!gjb_comprovaNoError($response))
{
gjb_obteNouPaypalTokenUsuari($year, $token);
if(!empty($token)) gjb_obteVistaUsuariPerPagar($year, $token);
}
else
{
if (gjb_haIntroduitMetodePagament($response))
{
if (GJB_PAY_ON_PAYPAL)
$confirmat = gjb_confirmarPagamentUsuari($year, $token, $response);
if ($confirmat) return gjb_obteVistaUsuariConfirmat($year);
else return gjb_obteVistaUsuariPerConfirmar($year, $token, $response, $userinfo);
}
else
{
return gjb_obteVistaUsuariPerPagar($year, $token);
}
}
}
return $lang['ERR_PAYMENT'];
}
function gjb_shortCode($atts)
{
global $lang;
global $current_user;
global $gjb_errs;
extract(shortcode_atts(array('year' => '0', 'closed' => 'false', 'limit' => '0'), $atts));
$year = intval($year);
$limit = intval($limit);
if ($year == 0) $ret = $lang['ERR_NO_YEAR'];
else if (empty($current_user->ID)) $ret = $lang['ERR_NO_LOGIN'];
else $ret = gjb_obteFormulari($year, $closed, $limit);
$err = gjb_displayErrors();
return $err.$ret;
}
add_shortcode( 'gjb', 'gjb_shortCode');
?>