Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Copyright 2012 Galicia de Moda
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License. You may obtain
- * a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- */
- // Import config
- require 'fakepath/configure.php';
- // Import and Instance Facebook PHP SDK
- require 'fakepath/facebook.php';
- $facebook = new Facebook(array('appId' => APP_ID, 'secret' => APP_PW, 'cookie' => true));
- // Import and Instance resources
- require 'fakepath/resources.php';
- $resources = new Resources();
- // Get Facebook user id
- try {
- $userbook = $facebook->getUser(); }
- catch (Exception $e) {
- $facebook = null; }
- // User with authorize app
- if ($userbook) {
- // Check for register user.
- $resources->execute(sprintf("SELECT COUNT(facebook) AS participante FROM participantes WHERE facebook='%s'", $userbook), 'check-register');
- $data = mysql_fetch_array($resources->mysql['check-register']);
- // User in database, move to score.php
- if ($data['participante'] >= 1) {
- $resources->logwrite($userbook, 'participa => REJECT (user exists)');
- header('Location: puntuacion.php');
- }
- $profile = $facebook->api('/'.$userbook.'?fields=id,username,first_name,last_name,email,picture');
- $resources->assign('ini-sdk-javascript', '<!-- not allow sdk');
- $resources->assign('end-sdk-javascript', '-->');
- }
- // Unauthorized app, enable javascript sdk in template
- else {
- $resources->logwrite($userbook, 'participa - first view');
- $resources->assign('ini-sdk-javascript', '');
- $resources->assign('end-sdk-javascript', ''); }
- // User send $_POST and auth user app
- if (!empty($_POST['app_submit_data']) and ($userbook != 0)) {
- // Fields in form and form_errors
- $form_error = false;
- $form_reqs = array('NAME', 'LAST', 'MAIL', 'TELL', 'TOS');
- // Check form fields
- foreach ($reqs as $field) {
- if (empty($_POST[strtolower($field)])) {
- $resources->assign('class-'.strtolower($field), 'v');
- $form_error = true; }
- else {
- $_POST[strtolower($field)] = mysql_real_escape_string(trim($_POST[strtolower($field)]));
- $resources->assign('class-'.strtolower($field), 'h'); }
- }
- if ($form_error == false) {
- // No errors?, insert user in database
- $resources->execute(sprintf("INSERT INTO participantes VALUES('%s', '%s', '%s', '%s', '%s', '%s', '%s')", $userbook, trim($profile['username']), $_POST['name'], $_POST['last'], $_POST['mail'], $_POST['tell'], date('Y-m-d')), 'user-register');
- if (mysql_affected_rows($resources->mysql['connect']) == 1) {
- $extra = '';
- $resources->execute(sprintf("INSERT INTO puntuaciones VALUES('%s', '0', '0', '0')", $userbook), 'user-register');
- // Come from other user?, update friend score
- if (!empty($_SESSION['from-wall-id'])) {
- $extra = ' (from '.$_SESSION['from-wall-id'].')';
- $resources->execute(sprintf("UPDATE puntuaciones SET joined=joined + 1 WHERE facebook='%s'", $_SESSION['from-wall-id']), 'update-user'); }
- $resources->logwrite($userbook, 'participa => ACCEPT'.$extra);
- header('Location: puntuacion.php');
- }
- // Something is wrong with sql
- else {
- $resources->logwrite($userbook, 'participa => ERROR (unable mysql)');
- $resources->assign('warning', 'No se pudo registrar su ingreso, intentelo más tarde.');
- }
- }
- }
- // Cant get facebook id... ops
- else if (!empty($_POST['app_submit_data']) and ($userbook == 0)) {
- $resources->logwrite($userbook, 'participa => ERROR (form send)');
- $resources->assign('warning', 'No se pudo registrar su ingreso, intentelo más tarde.');
- }
- // Empty form
- else {
- // Fields in form
- $reqs = array('NAME', 'LAST', 'MAIL', 'TELL', 'TOS');
- // Check form fields
- foreach ($reqs as $field) {
- $resources->assign('class-'.strtolower($field), 'h'); }
- $resources->assign('warning', '');
- }
- // Assign vars in template
- $resources->assign('app-id', APP_ID);
- $resources->assign('user-picture', $profile['picture']['data']['url']);
- $resources->assign('user-name', $profile['first_name']);
- $resources->assign('user-last', $profile['last_name']);
- $resources->assign('user-mail', $profile['email']);
- $resources->assign('user-tell', trim($_POST['tell']));
- // Debug, display user and other data
- $resources->assign('user-display', 'ID usuario en facebook '.$userbook);
- //require 'fakepath/debugmode.php';
- // Show site
- $resources->display('participa.html');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement