daily pastebin goal
69%
SHARE
TWEET

join.php

Worked Nov 9th, 2012 34 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /**
  4.  * Copyright 2012 Galicia de Moda
  5.  *
  6.  * Licensed under the Apache License, Version 2.0 (the "License"); you may
  7.  * not use this file except in compliance with the License. You may obtain
  8.  * a copy of the License at
  9.  *
  10.  *     http://www.apache.org/licenses/LICENSE-2.0
  11.  *
  12.  * Unless required by applicable law or agreed to in writing, software
  13.  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14.  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  15.  * License for the specific language governing permissions and limitations
  16.  * under the License.
  17.  */
  18.  
  19. // Import config
  20. require 'fakepath/configure.php';
  21.  
  22. // Import and Instance Facebook PHP SDK
  23. require 'fakepath/facebook.php';
  24. $facebook = new Facebook(array('appId' => APP_ID, 'secret' => APP_PW, 'cookie' => true));
  25.  
  26. // Import and Instance resources
  27. require 'fakepath/resources.php';
  28. $resources = new Resources();
  29.  
  30. // Get Facebook user id
  31. try {
  32.   $userbook = $facebook->getUser(); }
  33. catch (Exception $e) {
  34.   $facebook = null; }
  35.  
  36. // User with authorize app
  37. if ($userbook) {
  38.     // Check for register user.
  39.   $resources->execute(sprintf("SELECT COUNT(facebook) AS participante FROM participantes WHERE facebook='%s'", $userbook), 'check-register');
  40.   $data = mysql_fetch_array($resources->mysql['check-register']);
  41.     // User in database, move to score.php
  42.   if ($data['participante'] >= 1) {
  43.     $resources->logwrite($userbook, 'participa => REJECT (user exists)');
  44.     header('Location: puntuacion.php');
  45.   }
  46.   $profile = $facebook->api('/'.$userbook.'?fields=id,username,first_name,last_name,email,picture');
  47.   $resources->assign('ini-sdk-javascript', '<!-- not allow sdk');
  48.   $resources->assign('end-sdk-javascript', '-->');
  49. }
  50. // Unauthorized app, enable javascript sdk in template
  51. else {
  52.   $resources->logwrite($userbook, 'participa - first view');
  53.   $resources->assign('ini-sdk-javascript', '');
  54.   $resources->assign('end-sdk-javascript', ''); }
  55.  
  56. // User send $_POST and auth user app
  57. if (!empty($_POST['app_submit_data']) and ($userbook != 0)) {
  58.     // Fields in form and form_errors
  59.   $form_error = false;  
  60.   $form_reqs = array('NAME', 'LAST', 'MAIL', 'TELL', 'TOS');
  61.     // Check form fields
  62.   foreach ($reqs as $field) {
  63.     if (empty($_POST[strtolower($field)])) {
  64.       $resources->assign('class-'.strtolower($field), 'v');
  65.       $form_error = true; }
  66.     else {
  67.       $_POST[strtolower($field)] = mysql_real_escape_string(trim($_POST[strtolower($field)]));
  68.       $resources->assign('class-'.strtolower($field), 'h'); }
  69.   }
  70.   if ($form_error == false) {
  71.       // No errors?, insert user in database
  72.     $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');
  73.     if (mysql_affected_rows($resources->mysql['connect']) == 1) {
  74.       $extra = '';
  75.       $resources->execute(sprintf("INSERT INTO puntuaciones VALUES('%s', '0', '0', '0')", $userbook), 'user-register');
  76.         // Come from other user?, update friend score
  77.       if (!empty($_SESSION['from-wall-id'])) {
  78.         $extra = ' (from '.$_SESSION['from-wall-id'].')';
  79.         $resources->execute(sprintf("UPDATE puntuaciones SET joined=joined + 1 WHERE facebook='%s'", $_SESSION['from-wall-id']), 'update-user'); }
  80.  
  81.       $resources->logwrite($userbook, 'participa => ACCEPT'.$extra);
  82.       header('Location: puntuacion.php');
  83.     }
  84.       // Something is wrong with sql
  85.     else {
  86.       $resources->logwrite($userbook, 'participa => ERROR (unable mysql)');
  87.       $resources->assign('warning', 'No se pudo registrar su ingreso, intentelo m&#225;s tarde.');
  88.     }
  89.   }
  90. }
  91.  
  92. // Cant get facebook id... ops
  93. else if (!empty($_POST['app_submit_data']) and ($userbook == 0)) {
  94.   $resources->logwrite($userbook, 'participa => ERROR (form send)');
  95.   $resources->assign('warning', 'No se pudo registrar su ingreso, intentelo m&#225;s tarde.');
  96. }
  97.  
  98. // Empty form
  99. else {
  100.     // Fields in form
  101.   $reqs = array('NAME', 'LAST', 'MAIL', 'TELL', 'TOS');
  102.     // Check form fields
  103.   foreach ($reqs as $field) {
  104.     $resources->assign('class-'.strtolower($field), 'h'); }
  105.   $resources->assign('warning', '');
  106. }
  107.  
  108. // Assign vars in template
  109. $resources->assign('app-id', APP_ID);
  110. $resources->assign('user-picture', $profile['picture']['data']['url']);
  111. $resources->assign('user-name', $profile['first_name']);
  112. $resources->assign('user-last', $profile['last_name']);
  113. $resources->assign('user-mail', $profile['email']);
  114. $resources->assign('user-tell', trim($_POST['tell']));
  115.  
  116. // Debug, display user and other data
  117. $resources->assign('user-display', 'ID usuario en facebook '.$userbook);
  118. //require 'fakepath/debugmode.php';
  119.  
  120. // Show site
  121. $resources->display('participa.html');
  122.  
  123. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top