var textAccountConnected = 'Ihr Acccount ist jetzt mit Facebook verbunden. Ab sofort k'+unescape("%F6")+'nnen Sie sich mit Facebook auf retter.tv anmelden.'; var textWrongUserPass = 'Die eingegebenen Login-Daten sind nicht korrekt.'; function facebookDoLogin() { FB.login(function(response) { //console.log(response); if (response.status) { if (response.status == "connected") { // user is logged in and granted some permissions. //console.log('perms'); $.ajax({ url: '/pu_retter/scripts/facebookConnect.php?action=check_login', success: function(data){ //alert(data); switch(data) { case 'new_connected': //toDo: Dynamci page setTimeout(function(){ window.location = "/de/persoenliche-startseite.html?action=facebookConnect&redirect="+escape(window.location); }, 1000); alert(textAccountConnected); break; case 'connected': //toDo: Dynamci page //window.location = "/de/persoenliche-startseite.html?action=facebookConnect&redirect="+escape(window.location); window.location.reload(); break; case 'logged': $.ajax({ url: '/pu_retter/scripts/facebookConnect.php?action=connect_account', success: function(data){ alert('connect account '+data); //window.location.reload(); } }); break; case 'not_logged': default: facebookShowRegisterForm(); break; } } }); } else { //console.log('no perms'); // user is logged in, but did not grant any permissions } } else { //console.log('not logged'); // user is not logged in } }, {scope:'publish_stream,user_location,user_birthday'}); }; function facebookShowRegisterForm() { $.ajax({ url: '/pu_retter/scripts/facebookConnect.php?action=ajax_register', success: function(data){ $('
'+data+'
').dialog({modal: true, width: 450, height: 350}); } }); } function sendFacebookConnectRegisterForm(){ // check registration var data = $("#facebookConnectRegisterForm").serialize(); $.ajax({ url: "/pu_retter/scripts/facebookConnect.php?action=user_register", data: data, type: "POST", success: function(data) { switch(data) { case 'true': //new_connected alert(textAccountConnected); setTimeout(function(){ window.location.reload(); }, 3000); break; default: $("#facebookConnectRegisterForm").html(data); } } //target: "#fb_connect_register_login" }); return false; }; /** old and buggy function sendFacebookConnectRegisterForm(){ $("#facebookConnectRegisterForm").ajaxSubmit({ beforeSubmit : function(data){ if (data) { var pass; var email; //console.log(data); jQuery.each(data, function(index, value) { switch(value.name) { case 'email': email = value.value; break; case 'pass': pass = value.value; break; } }); $.post("/pu_retter/scripts/facebookConnect.php?action=user_register", data, function(returndata){ switch(returndata) { case 'true': //new_connected alert(textAccountConnected); setTimeout(function(){ window.location.reload(); }, 3000); return false; break; default: //console.log(returndata); } }); return true; } }, target: "#fb_connect_register_login" }); return false; }; */ function sendFacebookConnectLoginForm(){ $("#facebookConnectLoginForm").ajaxSubmit({ beforeSubmit : function(data){ if (data) { var pass; var email; jQuery.each(data, function(index, value) { switch(value.name) { case 'email': email = value.value; break; case 'pass': pass = value.value; break; } }); $.post("/pu_retter/scripts/facebookConnect.php?action=user_login", { email: email, pass: pass }, function(data){ switch(data) { case 'true': //new_connected alert(textAccountConnected); setTimeout(function(){ window.location.reload(); }, 3000); break; case 'false': alert(textWrongUserPass); break; } }); return false; } }, target: "#fb_connect_register_login" }); return false; }; function checkFbRegisterForm(formData, jqForm, options){ for (var i=0; i < formData.length; i++) { if (!formData[i].value && formData[i].name.search(/_qf_.+/) == -1 && formData[i].name != "agb" ) { alert('Bitte alle Felder ausf'+unescape("%FC")+'llen!'); return false; } } }; function disconnectDialog(jObj){ var alert_dialog = $('
').attr('id', 'confirmDialog'); var title = $(jObj).attr('title'); alert_dialog.appendTo(document.body); $('#confirmDialog').text(title); $('#confirmDialog').dialog( { open: function(){ $('.ui-dialog-titlebar').corner("top 5px"); }, buttons: { Abbrechen: function(){ $(this).dialog('close').remove(); }, Ja: function(){ $(this).dialog('close'); jQuery.get('/pu_retter/scripts/facebookConnect.php?action=disconnect', function(data) { window.location.reload(); }); } }, close: function(){ $(this).dialog("destroy"); } }); return false; } window.fbAsyncInit = function() { FB.init({ appId : "106700862735100", session : null, // don't refetch the session when PHP already has it status : true, // check login status cookie : true, // enable cookies to allow the server to access the session xfbml : true, // parse XFBML oauth : true }); // whenever the user logs in, we refresh the page FB.Event.subscribe('auth.login', function() { //window.location = '/index.php?pageid=12&action=facebookConnect'; //facebookDoLogin(); }); /* ToDo check once ? FB.getLoginStatus(function(response) { if (response.session) { // logged in and connected user, someone you know console.log(response); } else { // no user session available, someone you dont know console.log("else"); console.log(response); } });*/ }; (function() { var e = document.createElement('script'); e.src = document.location.protocol + '//connect.facebook.net/de_DE/all.js'; e.async = true; document.getElementById('fb-root').appendChild(e); }());