function gjb_registrarUsuari($year) { global $gjb_table_sufix_name; global $lang_sel; global $lang; global $current_user; global $wpdb; $table_name = $wpdb->prefix . $gjb_table_sufix_name; $userinfo = gjb_getUserInfo($year, $current_user->ID); $values = array(); gjb_ParsePost('gjb_nom', 'Nom', $values); gjb_ParsePost('gjb_cognoms', 'Cognoms', $values); if (gjb_ParsePost('gjb_dni', 'NIF', $values)) { $values['NIF'] = strtoupper($values['NIF']); } gjb_ParsePost('gjb_email', 'Email', $values); gjb_ParsePost('gjb_edat', 'Edat', $values); gjb_ParsePost('gjb_sexe', 'Sexe', $values); gjb_ParsePost('gjb_tshirt', 'Camiseta', $values); gjb_ParsePost('gjb_comarca', 'Comarca', $values); gjb_ParsePost('gjb_coneguts', 'Coneguts', $values); gjb_ParsePost('gjb_t_pc', 'TipusPC', $values); gjb_ParsePost('gjb_especialitat', 'Especialitat', $values); gjb_ParsePost('gjb_estudis', 'Estudis', $values); if (gjb_ParsePost('gjb_FinEst', 'FinEstudis', $values)) { if (!$values['FinEstudis']) { $values['FinEstudis'] = 0; } else { $values['FinEstudis'] = 1; } } gjb_ParsePost('gjb_treball', 'Treball', $values); if (gjb_ParsePost('gjb_BuscFeina', 'BuscoFeina', $values)) { if (!$values['BuscoFeina']) { $values['BuscoFeina'] = 0; } else { $values['BuscoFeina'] = 1; } } $values['Fecha'] = (string) gjb_fecha_atimestamp(date("d/m/Y")); if (count($userinfo) > 0) { $where = array("Year" => $year, "ID" => $current_user->ID); if ($wpdb->update($table_name, $values, $where)) { } else { global $gjb_errs; $gjb_errs[] = "BD: Error updating database. DNI in use."; } } else { $values['Year'] = $year; $values['ID'] = $current_user->ID; if ($wpdb->insert($table_name, $values)) { //Enviar emails informatorios $nom = html_entity_decode($values['Nom']); $cognoms = html_entity_decode($values['Cognoms']); $mailbody = "S'acava de realitzar una nova inscripcio, les dades son:\n"; $mailbody .= "{$cognoms}, {$nom} amb DNI: {$values['NIF']} i email: {$values['Email']}. El seu idioma preferent es " . strtoupper($lang_sel); $subject = "Nova inscripcio: {$nom} {$cognoms}"; $admin_email = get_option('admin_email'); wp_mail($admin_email, $subject, $mailbody); } else { global $gjb_errs; $gjb_errs[] = "BD: Error inserting to database. DNI in use."; } } }
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']; }