I tried to make a search engine in order to search between 2 dates $dateFrom to $dateTo.
Here what i have tried.:
Index.php:
<?php
require_once 'Connection.simple.php';
$tutorialTitle = "Using Ajax to search a Record with PHP, MySQL and jQuery (Look and Feel by Bootstrap)";
$conn = dbConnect();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title><?php echo $tutorialTitle;?></title>
<meta http-equiv="X-UA-Compatible" content="IE=9" />
<meta name="copyright" content="BEHSTANT SOFTWARE | Datasoft Engineering 2013"/>
<meta name="author" content="Reedyseth"/>
<meta name="email" content="ibarragan at behstant dot com"/>
<meta name="description" content="<?php echo $tutorialTitle;?>" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel=stylesheet href="css/style01.css">
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="wrapper">
<div class="page-header ">
<div class="panel panel-default">
</div>
</div>
<div class="mainContent">
<form class="form-horizontal" role="form" method="get">
<div class="form-group">
<label class="col-sm-2 control-label" for="minimum date">employee_id</label>
<div class="input-group col-sm-9">
<input id="DateFrom" name="DateFrom" type="date" class="form-control" placeholder="Type the name" />
<input id="DateTo" name="DateTo" type="date" class="form-control" placeholder="Type the name" />
<span class="input-group-btn">
<button type="button" class="btn btn-default btnSearch">
<span class="glyphicon glyphicon-search"> Search</span>
</button>
</span>
</div>
</div>
</form>
<div class="col-sm-2"></div>
<div class="col-sm-8">
<!-- This table is where the data is display. -->
<table id="resultTable" class="table table-striped table-hover">
<tbody></tbody>
</table>
</div>
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="js/jquery-1.10.2.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('.btnSearch').click(function(){
makeAjaxRequest();
});
$('form').submit(function(e){
e.preventDefault();
makeAjaxRequest();
return false;
});
function makeAjaxRequest() {
$.ajax({
url: 'search.php',
type: 'get',
DateFrom: {DateFrom: $('input#DateFrom').val()},
DateTo: {DateTo: $('input#DateTo').val()},
success: function(response) {
$('table#resultTable tbody').html(response);
}
});
}
});
</script>
</body>
</html>
Search.php:
<?php
require_once 'Connection.simple.php';
$conn = dbConnect();
$OK = true;
if (isset($_GET['DateFrom']) && isset($_GET['DateTo'])) {
$dateFrom = $_GET['DateFrom'];
$dateTo = $_GET['DateTo'];
$sql = "SELECT * FROM attendance WHERE date >= '". $dateFrom ."' AND date <= '". $dateto ."' ";
}
if(empty($rows)) {
echo "<tr>";
echo "<td colspan='4'>There were not records</td>";
echo "</tr>";
}
else {
foreach ($rows as $row) {
echo "<tr>";
echo "<td>".$row['emp_id']."</td>";
echo "<td>".$row['Date']."</td>";
echo "<td>".$row['day']."</td>";
echo "<td>".$row['time_in']."</td>";
echo "<td>".$row['time_out']."</td>";
echo "<td>".$row['worked']."</td>";
echo "<td>".$row['overtime']."</td>";
echo "<td>".$row['less_hours']."</td>";
echo "<td>".$row['transport_in']."</td>";
echo "<td>".$row['Transport_out']."</td>";
echo "</tr>";
}
}
?>
EDIT 1:
$sql = "SELECT * FROM attendance WHERE date >= '". $dateFrom ."' AND date <= '". $dateto ."' ";
// we have to tell the PDO that we are going to send values to the query
$stmt = $conn->prepare($sql);
// Now we execute the query passing an array toe execute();
$results = $stmt->execute(array($dateFrom, $dateTo));
// Extract the values from $result
$rows = $stmt->fetchAll();
$error = $stmt->errorInfo();
******I added that to make execute the query but still not working******
<?php
function dbConnect (){
$conn = null;
$host = 'localhost';
$db = 'payroll';
$user = 'root';
$pwd = '';
try {
$conn = new PDO('mysql:host='.$host.';dbname='.$db, $user, $pwd);
//echo 'Connected succesfully.<br>';
}
catch (PDOException $e) {
echo '<p>Cannot connect to database !!</p>';
echo '<p>'.$e.'</p>';
exit;
}
return $conn;
}
?>
******* This is my code for DBconnection*******
My database name is payroll and the table is attendance.
You need to name the parameters inside SQL code.
Please, use the correct case for the columns names. You spelled "less_hours", while in your database this column is called "Less_Hours". And this gave a notice: "Undefined index: less_hours".
I put the output code inside the 1-st if, otherwise $rows will always be undefined for the first time.
This code worked for me:
if (isset($_GET['DateFrom']) && isset($_GET['DateTo'])) {
$dateFrom = $_GET['DateFrom'];
$dateTo = $_GET['DateTo'];
$sql = "SELECT * FROM attendance WHERE
date >= :date_from AND date <= :date_to ";
$stmt = $conn->prepare($sql);
// Now we execute the query passing an array toe execute();
$results = $stmt->execute(
array('date_from' => $dateFrom, 'date_to' => $dateTo));
// Extract the values from $result
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
if(empty($rows)) {
echo "<tr>";
echo "<td colspan='4'>There were not records</td>";
echo "</tr>";
}
else {
foreach ($rows as $row) {
echo "<tr>";
echo "<td>".$row['emp_id']."</td>";
echo "<td>".$row['Date']."</td>";
echo "<td>".$row['Day']."</td>";
echo "<td>".$row['Time_In']."</td>";
echo "<td>".$row['Time_Out']."</td>";
echo "<td>".$row['Worked']."</td>";
echo "<td>".$row['Overtime']."</td>";
echo "<td>".$row['Less_Hours']."</td>";
echo "<td>".$row['Transport_In']."</td>";
echo "<td>".$row['Transport_Out']."</td>";
echo "</tr>";
}
}
}
So I'm getting an error:
Parse error: syntax error, unexpected $end in C:\xampp\htdocs\CWoW\add.php on line 97 in my code.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf8">
<link rel="stylesheet" href="main.css">
<link rel="stylesheet" href="default.css">
<link rel="stylesheet" href="cms.css">
<title>ACP</title>
</head>
<body>
<?php
if(isset($_POST['add']))
{
$dbhost = 'localhost:3306';
$dbuser = 'root';
$dbpass = '';
$mysqli = new mysqli('localhost','root','','meh') or die("Error " . mysqli_error($mysqli));
if(empty($_POST['title'])) {
echo 'The title must not be empty!<br/>';
} else if(empty($_POST['message'])) {
echo 'The message field must not be empty!<br/>';
} else if(empty($_POST['author'])) {
echo 'A poster name is required!<br/>';
} else {
if(! get_magic_quotes_gpc() )
{
$title = addslashes ($_POST['title']);
$message = addslashes ($_POST['message']);
$author = addslashes ($_POST['author']);
}
else
{
$title = $_POST['title'];
$message = $_POST['message'];
$author = $_POST['author'];
}
if ($query = $mysqli->query("INSERT INTO etl_articles (title, message, author) VALUES ('{$title}', '{$message}', '{$author}');")) {
echo "The post has successfully been added! <a href='add.php'>Click Here</a> to go back.";
} else {
echo 'Failed to add the post!';
$query->close;
}
}
}
else
{
?>
<div id="logo_div">
<a id="logo_anch" href="#" title="Project Hysteria">Project Hysteria</a>
</div>
<ul id="top_menu">
<li>Home</li>
</ul>
<div id="main">
<aside id="right">
<div id="main_sep"></div>
<div id="content_ajax">
<form method="post" action="<?php $_PHP_SELF ?>" class="custom2">
<article>
<div class="top"><input name="title" type="text" placeholder="» Title" /></div>
<section class="body">
<div class="clear"></div>
<div class="news_bottom">
<textarea name="message" placeholder="» Message"></textarea><br><br>
<select name="author">
<option value="Admin">Admin</option>
<option value="Moderator">Global Moderator</option>
<option value="Developer">Developer</option>
</select><br><br>
<input name="add" type="submit" value="Submit News" />
</div>
<div class="comments" id="comments_17"></div>
</section>
</article>
</div>
</aside>
<div class="clear"></div>
</div>
</form>
<footer>
<p>© Copyright 2013 Caustic WoW</p>
<p id="design"> <a target="_new" href=""></a></p>
</footer>
</section>
</body>
</html>
I can't seem to find the problem really.
If any of you guys can help me that would be great.
You have a syntax error in your code : there is an opening brace { after else statement but the closing } is missing.
Replace
else
{
?>
with
else;
?>
or
else{}
?>
I uploaded my php application using Filezilla and when I checked it online, all of the images are missing and total site get break. I don't understand this because everything works fine offline but when I check through after publishing it online, all the images disapear. I also checked all my links and they're fine.
Here is my code
<html>
<head>
<title> Vatsal Technosoft Messanger </title>
<script type="text/javascript" src="../JavaScript/frmvalidation.js"></script>
<link href="../Stylesheet/style.css" media="all" type="text/css" rel="stylesheet" />
</head>
<body>
<?php include 'connect.php' ?>
<?php include 'functions.php' ?>
<?php include 'header.php' ?>
<div id="outer" style="margin-top:0px;">
<div class="container" style="color:#00C; z-index:1;">
<div class="subcontainer" >
<?php
if(loggedin())
{
?>
<a href='' onclick='addcontact();' id='noti' style='text- decoration:none;margin-bottom:0px;'>
<?php
$my_id = $_SESSION['user_id'];
$notifrnd = mysql_query("SELECT * FROM `frnd_req` WHERE `to` = '$my_id' ");
if(mysql_num_rows($notifrnd))
{
while($arr = mysql_fetch_array($notifrnd))
{
$fid = $arr[1];
$firstname = getfirstname($fid , 'firstname');
$lastname = getlastname($fid , 'lastname');
}
echo "<font style='color:#FFFF00; font-size:11px; margin-left:15px; margin-top:3px; margin-bottom:5px; float:left; font-weight:bold;'>You have Friend request</font>";
}
}
?>
</a>
<?php
?>
<iframe name ='uses' src='../indexus.php' width='185' height='140' style='max-width:185px; background-color:#ccc;'>
</iframe>
<?php
if(adminlogedin())
{
$admin_id = $_SESSION['admin_id'];
eader('location:admindex.php');
}
?>
</div>
</div>
<div class="footer">
<div class="online">
<?php
if(loggedin())
{
echo "<img src='../Images/ym1.png'>";
}
else
{
echo "<img src='../Images/ym2.png'>";
}
?>
</div>
<div class="footertext">
<?php
if(loggedin())
{
$my_id = $_SESSION['user_id'];
$firstname = getfirstname($my_id , 'firstname');
$lastname = getlastname($my_id , 'lastname');
echo " $firstname $lastname ";
}
else
{
}
?>
</div>
</div>
</div>
</body>
</html>
I'm using a CKEditor along with a CKFinder. Both work fine. When I browse (or copy directly) an image (or flash) to CKEditor, it's displayed within it and inserted into the MySql database.
Aafter inserting it into MySql database, I'm trying to display it in an HTML table where it isn't displayed and the alternate text is displayed.
The image path after browsing an image through the CKFinder is something like the following.
<img alt="" src="/ckfinder/userfiles/images/1243_SS_2502.jpg" style="width: 490px; height: 618px;" />
The contents inserted into the database is as follows.
<img alt="\"\"" data-cke-saved-src="\"
src="\"/ckfinder/userfiles/images/1243_SS_2502.jpg\"" st yle=&
quot;\"width:" 490px;="" height:="" 618px;\"= quot;">
Tried with htmlentities() still it doesn't work. While dealing the same with JSP using JSTL/EL, I had to do the following.
<c:out value="${str}" default="No content found." escapeXml="false"/>
escapeXml="false", where str written in EL was a java.lang.String holding the Oracle clob data after conversion.
What is the way to get around the situation in PHP? Both CKEditor and CKFinder work fine for me.
$ckeditor = new CKEditor();
$ckeditor->basePath = 'ckeditor/';
$ckeditor->config['filebrowserBrowseUrl'] = 'ckfinder/ckfinder.html';
$ckeditor->config['filebrowserImageBrowseUrl'] = 'ckfinder/ckfinder.html?type=Images';
$ckeditor->config['filebrowserFlashBrowseUrl'] = 'ckfinder/ckfinder.html?type=Flash';
$ckeditor->config['filebrowserUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files';
$ckeditor->config['filebrowserImageUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images';
$ckeditor->config['filebrowserFlashUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash';
$ckeditor->editor('description', $ed_about_us);
Edit:
<?php include_once("Lock.php");?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Wagafashion</title>
<link rel="stylesheet" href="css/validationEngine.jquery.css" type="text/css"/>
<link rel="stylesheet" href="css/template.css" type="text/css"/>
<!--<script type="text/javascript" language="javascript" src="ckeditor/ckeditor.js"></script>-->
<script src="js/jquery-1.6.min.js" type="text/javascript"></script>
<script src="js/languages/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script><script>
jQuery(document).ready(function(){
// binds form submission and fields to the validation engine
jQuery("#dataForm").validationEngine();
});
</script>
<script language="javascript" type="text/javascript">
function deleteSingle(id)
{
var delId=confirm("About us with the id "+id+" is about to be deleted permanently.\n\nAttention : This action will never be undone!\n\nAre you sure...???");
return(delId==true?true:false);
}
</script>
</head>
<body>
<?php
include_once("Connection.php");
include_once("ckeditor/ckeditor.php");
$con=new Connection();
$con->get_connection();
$ed_about_us="";
$flag=-1;
$msg="";
if(isset($_POST['btnSubmit']))
{
$act=trim($_POST['param_action']);
$about_us=$_POST['cms_description'];
if($act=="add")
{
$res=$con->get_data("select count(*) as cnt from cms");
$cnt_cmt=mysql_result($res, 'cnt');
if($cnt_cmt==0)
{
$flag=$con->iud("insert into cms (about_us)values('".mysql_real_escape_string(urlencode($about_us))."')");
}
else
{
$flag=$con->iud("update cms set about_us='".mysql_real_escape_string(urlencode($about_us))."'");
}
if($flag==1)
{
$msg="Insertion done successfully.";
}
else if($flag==0)
{
$msg="Insertion failed - reason : ".mysql_errno()." : ".mysql_error();
}
}
else if($act=="edit")
{
$cms_id=$_POST['cms_id'];
$flag=$con->iud("update cms set about_us='".mysql_real_escape_string(urlencode($about_us))."' where id=".$cms_id."");
if($flag==1)
{
$msg="About us has been updated successfully.";
}
else if($flag==0)
{
$msg="Updation failed - reason : ".mysql_errno()." : ".mysql_error();
}
}
}
else if(isset($_GET['ed_id']))
{
$ed_res=$con->get_data("select about_us from cms where id=".$_GET['ed_id']."");
while($row=mysql_fetch_assoc($ed_res))
{
$ed_about_us=$row['about_us'];
}
}
else if(isset($_GET['del_id']))
{
$flag=$con->iud("update cms set about_us='' where id=".$_GET['del_id']);
if($flag==1)
{
$msg="About us been deleted successfully.";
}
else if($flag==0)
{
$msg="Can not delete - reason : ".mysql_errno()." : ".mysql_error();
}
}
else if(isset($_POST['btnDelete']))
{
$set_del=$_POST['setDel'];
$flag=$con->iud("update cms set about_us='' where id in($set_del)");
$size=sizeof(split(",", $set_del));
if($flag==1)
{
if($size==1)
{
$msg="1 row deleted.";
}
else
{
$msg=$size." rows deleted.";
}
}
else if($flag==0)
{
$msg="Can not perform deletion - reason : ".mysql_errno()." : ".mysql_error();
}
}
?>
<?php include("tamplate/Template1.php");?>
<h2>About Us</h2>
<?php include("tamplate/NewTemplate.php");?>
<?php
if($flag==1)
{
echo "<p>";
?>
<!--[if !IE]>start system messages<![endif]-->
<ul class="system_messages">
<li class="green"><span class="ico"></span><strong class="system_title"><?php echo $msg; ?></strong></li>
</ul>
<!--[if !IE]>end system messages<![endif]-->
<?php
echo "</p>";
}
else if($flag==0)
{
echo "<p>";
?>
<!--[if !IE]>start system messages<![endif]-->
<ul class="system_messages">
<li class="red"><span class="ico"></span><strong class="system_title"><?php echo $msg; ?></strong></li>
</ul>
<!--[if !IE]>end system messages<![endif]-->
<?php
echo "</p>";
}
?>
<img alt=\"\" src="/ckfinder/userfiles/images/1243_SS_2502.jpg" style=\"width: 490px; height: 618px;\" />
<!--[if !IE]>start forms<![endif]-->
<form action="<?php $_SERVER['PHP_SELF']; ?>" id="dataForm" name="dataForm" method="post" class="search_form general_form">
<!--[if !IE]>start fieldset<![endif]-->
<fieldset>
<!--[if !IE]>start forms<![endif]-->
<div class="forms">
<!--[if !IE]>start row<![endif]-->
<div class="row">
<?php
$ckeditor = new CKEditor();
$ckeditor->basePath = 'ckeditor/';
$ckeditor->config['filebrowserBrowseUrl'] = 'ckfinder/ckfinder.html';
$ckeditor->config['filebrowserImageBrowseUrl'] = 'ckfinder/ckfinder.html?type=Images';
$ckeditor->config['filebrowserFlashBrowseUrl'] = 'ckfinder/ckfinder.html?type=Flash';
$ckeditor->config['filebrowserUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files';
$ckeditor->config['filebrowserImageUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images';
$ckeditor->config['filebrowserFlashUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash';
$ckeditor->editor('cms_description', urldecode($ed_about_us));
?>
<!--[if !IE]>start row<![endif]-->
<div class="row">
<div class="buttons">
<span class="button send_form_btn"><span><span>Submit</span></span><input type="submit" value="Submit" id="btnSubmit" name="btnSubmit" onclick="return validate();"></span>
</div>
</div>
<!--[if !IE]>end row<![endif]-->
</div>
</fieldset>
<!--[if !IE]>end fieldset<![endif]-->
<input type="hidden" id="param_action" name="param_action" value="
<?php
if(isset($_GET['ed_id']))
{
echo "edit";
}
else
{
echo "add";
}
?>
" />
<input type="hidden" id="cms_id" name="cms_id" value="<?php echo isset($_GET['ed_id'])?$_GET['ed_id']:"";?>" />
</form>
<?php include("tamplate/Template2.php");?>
<h2>About Us</h2>
<?php include("tamplate/NewTemplate1.php");?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" id="mainForm" name="mainForm" method="post">
<?php include("tamplate/ExtraTemplate.php");?>
<table cellpadding="0" cellspacing="0" width="100%">
<tbody>
<th style="width: 10px;">Check</th>
<th style="width: 450px;">About Us</th>
<th style="width: 10px;">Actions</th>
<?php
$get_data=$con->get_data("select id, about_us from cms order by id");
$cnt=1;$flag='';
while($data_row=mysql_fetch_assoc($get_data))
{
extract($data_row);
$cnt%2==0?$flag="second":$flag="first";
++$cnt;
echo "<tr class='$flag'>";
echo "<td><input type='checkbox' name='chk' value='$id'></td>";
echo "<td>".urldecode($about_us)."</td>";
echo "<td><div class='actions'><ul><li><a href='".$_SERVER['PHP_SELF']."?ed_id=$id' class='action2'></a></li>";
echo "<li><a href='".$_SERVER['PHP_SELF']."?del_id=$id&table_name=cms&pri=id' onclick='return deleteSingle($id);' class='action4'></a></li></ul></div></td>";
echo "</tr>";
}
?>
</tbody>
</table>
<input type='hidden' id='setDel' name='setDel'/>
<?php include("tamplate/Template3.php");?>
</form>
<?php include("tamplate/Template4.php");?>
</body>
</html>
Did you try to use html_entity_decode() to display the contents ? It will decode the encoded html for better output. Reference here
Edit
Change your query to the following
insert into cms (about_us) values ('".mysql_real_escape_string(urlecode(stripslashes($about_us)))."')
When you get it from database it use
urldecode($value)
Where $value is the block you got from database.
I started a new PHP app on Facebook using Heroku. They start you out with a sample webpage that you can modify. When you first visit the page, it looks like this.
Where in index.php is the code for that log in button that you see in the upper left?
If you press that button, then you get this next page.
As you see, the app gets permissions for only 3 things (basic info, likes, photos). I want to add more permissions, but I could not find where this happens in the code. Where is it?
Here is the full source code for index.php.
<?php
/**
* This sample app is provided to kickstart your experience using Facebook's
* resources for developers. This sample app provides examples of several
* key concepts, including authentication, the Graph API, and FQL (Facebook
* Query Language). Please visit the docs at 'developers.facebook.com/docs'
* to learn more about the resources available to you
*/
// Provides access to app specific values such as your app id and app secret.
// Defined in 'AppInfo.php'
require_once('AppInfo.php');
// Enforce https on production
if (substr(AppInfo::getUrl(), 0, 8) != 'https://' && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
header('Location: https://'. $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
exit();
}
// This provides access to helper functions defined in 'utils.php'
require_once('utils.php');
/*****************************************************************************
*
* The content below provides examples of how to fetch Facebook data using the
* Graph API and FQL. It uses the helper functions defined in 'utils.php' to
* do so. You should change this section so that it prepares all of the
* information that you want to display to the user.
*
****************************************************************************/
require_once('sdk/src/facebook.php');
$facebook = new Facebook(array(
'appId' => AppInfo::appID(),
'secret' => AppInfo::appSecret(),
));
$user_id = $facebook->getUser();
if ($user_id) {
try {
// Fetch the viewer's basic information
$basic = $facebook->api('/me');
} catch (FacebookApiException $e) {
// If the call fails we check if we still have a user. The user will be
// cleared if the error is because of an invalid accesstoken
if (!$facebook->getUser()) {
header('Location: '. AppInfo::getUrl($_SERVER['REQUEST_URI']));
exit();
}
}
// This fetches some things that you like . 'limit=*" only returns * values.
// To see the format of the data you are retrieving, use the "Graph API
// Explorer" which is at https://developers.facebook.com/tools/explorer/
$likes = idx($facebook->api('/me/likes?limit=4'), 'data', array());
// This fetches 4 of your friends.
$friends = idx($facebook->api('/me/friends?limit=4'), 'data', array());
// And this returns 16 of your photos.
$photos = idx($facebook->api('/me/photos?limit=16'), 'data', array());
// Here is an example of a FQL call that fetches all of your friends that are
// using this app
$app_using_friends = $facebook->api(array(
'method' => 'fql.query',
'query' => 'SELECT uid, name FROM user WHERE uid IN(SELECT uid2 FROM friend WHERE uid1 = me()) AND is_app_user = 1'
));
}
// Fetch the basic info of the app that they are using
$app_info = $facebook->api('/'. AppInfo::appID());
$app_name = idx($app_info, 'name', '');
?>
<!DOCTYPE html>
<html xmlns:fb="http://ogp.me/ns/fb#" lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=2.0, user-scalable=yes" />
<title><?php echo he($app_name); ?></title>
<link rel="stylesheet" href="stylesheets/screen.css" media="Screen" type="text/css" />
<link rel="stylesheet" href="stylesheets/mobile.css" media="handheld, only screen and (max-width: 480px), only screen and (max-device-width: 480px)" type="text/css" />
<!--[if IEMobile]>
<link rel="stylesheet" href="mobile.css" media="screen" type="text/css" />
<![endif]-->
<!-- These are Open Graph tags. They add meta data to your -->
<!-- site that facebook uses when your content is shared -->
<!-- over facebook. You should fill these tags in with -->
<!-- your data. To learn more about Open Graph, visit -->
<!-- 'https://developers.facebook.com/docs/opengraph/' -->
<meta property="og:title" content="<?php echo he($app_name); ?>" />
<meta property="og:type" content="website" />
<meta property="og:url" content="<?php echo AppInfo::getUrl(); ?>" />
<meta property="og:image" content="<?php echo AppInfo::getUrl('/logo.png'); ?>" />
<meta property="og:site_name" content="<?php echo he($app_name); ?>" />
<meta property="og:description" content="My first app" />
<meta property="fb:app_id" content="<?php echo AppInfo::appID(); ?>" />
<script type="text/javascript" src="/javascript/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
function logResponse(response) {
if (console && console.log) {
console.log('The response was', response);
}
}
$(function(){
// Set up so we handle click on the buttons
$('#postToWall').click(function() {
FB.ui(
{
method : 'feed',
link : $(this).attr('data-url')
},
function (response) {
// If response is null the user canceled the dialog
if (response != null) {
logResponse(response);
}
}
);
});
$('#sendToFriends').click(function() {
FB.ui(
{
method : 'send',
link : $(this).attr('data-url')
},
function (response) {
// If response is null the user canceled the dialog
if (response != null) {
logResponse(response);
}
}
);
});
$('#sendRequest').click(function() {
FB.ui(
{
method : 'apprequests',
message : $(this).attr('data-message')
},
function (response) {
// If response is null the user canceled the dialog
if (response != null) {
logResponse(response);
}
}
);
});
});
</script>
<!--[if IE]>
<script type="text/javascript">
var tags = ['header', 'section'];
while(tags.length)
document.createElement(tags.pop());
</script>
<![endif]-->
</head>
<body>
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId : '<?php echo AppInfo::appID(); ?>', // App ID
channelUrl : '//<?php echo $_SERVER["HTTP_HOST"]; ?>/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// Listen to the auth.login which will be called when the user logs in
// using the Login button
FB.Event.subscribe('auth.login', function(response) {
// We want to reload the page now so PHP can read the cookie that the
// Javascript SDK sat. But we don't want to use
// window.location.reload() because if this is in a canvas there was a
// post made to this page and a reload will trigger a message to the
// user asking if they want to send data again.
window.location = window.location;
});
FB.Canvas.setAutoGrow();
};
// Load the SDK Asynchronously
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<header class="clearfix">
<?php if (isset($basic)) { ?>
<p id="picture" style="background-image: url(https://graph.facebook.com/<?php echo he($user_id); ?>/picture?type=normal)"></p>
<div>
<h1>Welcome, <strong><?php echo he(idx($basic, 'name')); ?></strong></h1>
<p class="tagline">
This is your app
<?php echo he($app_name); ?>
</p>
<div id="share-app">
<p>Share your app:</p>
<ul>
<li>
<a href="#" class="facebook-button" id="postToWall" data-url="<?php echo AppInfo::getUrl(); ?>">
<span class="plus">Post to Wall</span>
</a>
</li>
<li>
<a href="#" class="facebook-button speech-bubble" id="sendToFriends" data-url="<?php echo AppInfo::getUrl(); ?>">
<span class="speech-bubble">Send Message</span>
</a>
</li>
<li>
<a href="#" class="facebook-button apprequests" id="sendRequest" data-message="Test this awesome app">
<span class="apprequests">Send Requests</span>
</a>
</li>
</ul>
</div>
</div>
<?php } else { ?>
<div>
<h1>Welcome</h1>
<div class="fb-login-button" data-scope="user_likes,user_photos"></div>
</div>
<?php } ?>
</header>
<section id="get-started">
<p>Welcome to your Facebook app, running on <span>heroku</span>!</p>
Learn How to Edit This App
</section>
<?php
if ($user_id) {
?>
<section id="samples" class="clearfix">
<h1>Examples of the Facebook Graph API</h1>
<div class="list">
<h3>A few of your friends</h3>
<ul class="friends">
<?php
foreach ($friends as $friend) {
// Extract the pieces of info we need from the requests above
$id = idx($friend, 'id');
$name = idx($friend, 'name');
?>
<li>
<a href="https://www.facebook.com/<?php echo he($id); ?>" target="_top">
<img src="https://graph.facebook.com/<?php echo he($id) ?>/picture?type=square" alt="<?php echo he($name); ?>">
<?php echo he($name); ?>
</a>
</li>
<?php
}
?>
</ul>
</div>
<div class="list inline">
<h3>Recent photos</h3>
<ul class="photos">
<?php
$i = 0;
foreach ($photos as $photo) {
// Extract the pieces of info we need from the requests above
$id = idx($photo, 'id');
$picture = idx($photo, 'picture');
$link = idx($photo, 'link');
$class = ($i++ % 4 === 0) ? 'first-column' : '';
?>
<li style="background-image: url(<?php echo he($picture); ?>);" class="<?php echo $class; ?>">
</li>
<?php
}
?>
</ul>
</div>
<div class="list">
<h3>Things you like</h3>
<ul class="things">
<?php
foreach ($likes as $like) {
// Extract the pieces of info we need from the requests above
$id = idx($like, 'id');
$item = idx($like, 'name');
// This display's the object that the user liked as a link to
// that object's page.
?>
<li>
<a href="https://www.facebook.com/<?php echo he($id); ?>" target="_top">
<img src="https://graph.facebook.com/<?php echo he($id) ?>/picture?type=square" alt="<?php echo he($item); ?>">
<?php echo he($item); ?>
</a>
</li>
<?php
}
?>
</ul>
</div>
<div class="list">
<h3>Friends using this app</h3>
<ul class="friends">
<?php
foreach ($app_using_friends as $auf) {
// Extract the pieces of info we need from the requests above
$id = idx($auf, 'uid');
$name = idx($auf, 'name');
?>
<li>
<a href="https://www.facebook.com/<?php echo he($id); ?>" target="_top">
<img src="https://graph.facebook.com/<?php echo he($id) ?>/picture?type=square" alt="<?php echo he($name); ?>">
<?php echo he($name); ?>
</a>
</li>
<?php
}
?>
</ul>
</div>
</section>
<?php
}
?>
<section id="guides" class="clearfix">
<h1>Learn More About Heroku & Facebook Apps</h1>
<ul>
<li>
Heroku
<p>Learn more about Heroku, or read developer docs in the Heroku Dev Center.</p>
</li>
<li>
Websites
<p>
Drive growth and engagement on your site with
Facebook Login and Social Plugins.
</p>
</li>
<li>
Mobile Apps
<p>
Integrate with our core experience by building apps
that operate within Facebook.
</p>
</li>
<li>
Apps on Facebook
<p>Let users find and connect to their friends in mobile apps and games.</p>
</li>
</ul>
</section>
</body>
</html>
The login button is created using javascript based on the attributes of the div below
<div class="fb-login-button" data-scope="user_likes,user_photos"></div>
you can add extra permissions to the comma separated list.