Created
June 13, 2011 15:24
-
-
Save zaksoup/1022981 to your computer and use it in GitHub Desktop.
Playability stuff!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
$dbConnection = new Mongo(); | |
$users = $dbConnection->playability->users; | |
$unplayed = $dbConnection->playability->unplayed; | |
$unbeaten = $dbConnection->playability->unbeaten; | |
$beaten = $dbConnection->playability->beaten; | |
$abandoned = $dbConnection->playability->abandoned; | |
$quips = $dbConnection->playability->quips; | |
$action = $_POST['action']; | |
session_start(); | |
function getGames($type, $category) { | |
$games = ''; | |
foreach ($type as $game) { | |
$name = $game['name']; | |
$platform = $game['platform']; | |
$note = $game['note']; | |
$games .= " <li>" . $name . " <a href=\"remove.php?id=" . $game['_id'] . "&category=" . $category . "\"><span class='deleteButton'>✖</span></a> <span>" . $platform . "</span><span>" . $note . "</span></li>"; | |
echo $games; | |
} | |
} | |
if($action == 'add'){ | |
if(addGame()){ | |
echo "success"; | |
}else{ | |
echo "fail"; | |
}; | |
}; | |
if($action == 'remove'){ | |
if(removeGame()){ | |
echo "success"; | |
}else{ | |
echo "fail"; | |
}; | |
}; | |
if($action == 'read'){ | |
getGames($_POST['type'], $_POST['category']); | |
}; | |
function addGame(){ | |
global $dbConnection; | |
$name = Trim(stripslashes($_POST['name'])); | |
$platform = Trim(stripslashes($_POST['platform'])); | |
$note = Trim(stripslashes($_POST['note'])); | |
$category = $_POST['category']; | |
$user = $_SESSION['username']; | |
$game = iterator_to_array($dbConnection->playability->$category->find(array('name'=>$name))); | |
if(!empty($game)){ | |
return false; | |
}; | |
$dbConnection->playability->$category->insert(array('name' => $name, 'platform' => $platform, 'note' => $note, 'user' => $user)); | |
return true; | |
}; | |
function removeGame(){ | |
global $dbConnection; | |
$name = Trim(stripslashes($_POST['name'])); | |
$category = $_POST['category']; | |
$user = $_SESSION['username']; | |
$dbConnection->playability->$category->remove(array('name' => $name, 'user' => $user)); | |
return true; | |
}; | |
function moveGame(){ | |
global $dbconnection; | |
$dbConnection->playability->$origCategory->remove(array('name' => $name, 'user' => $user)); | |
$dbConnection->playability->$newCategory->insert(array('name' => $name, 'platform' => $platform, 'note' => $note, 'user' => $user)); | |
}; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Load required lib files. */ | |
session_start(); | |
/* If access tokens are not available redirect to connect page. */ | |
if (empty($_SESSION['username']) || empty($_SESSION['password'])) { | |
header('Location: ./logout.php'); | |
} | |
$userName = $_SESSION['username']; | |
//$dbConnection = new Mongo("mongodb://zaksoup:m545b;FedorA@flame.mongohq.com:27097/playability"); | |
$dbConnection = new Mongo(); | |
$unplayed = $dbConnection->playability->unplayed; | |
$unbeaten = $dbConnection->playability->unbeaten; | |
$beaten = $dbConnection->playability->beaten; | |
$abandoned = $dbConnection->playability->abandoned; | |
$quips = $dbConnection->playability->quips; | |
$unplayedGames = $unplayed->find(array('user' => $userName)); | |
$unbeatenGames = $unbeaten->find(array('user' => $userName)); | |
$beatenGames = $beaten->find(array('user' => $userName)); | |
$abandonedGames = $abandoned->find(array('user' => $userName)); | |
$quipsList = $quips->find(); | |
//$dbConnection->playability->abandoned->insert(array('name' => 'New Game', 'platform' => 'Xbox 360', 'note' => 'A test note for a test game')); | |
function getQuips($type) { | |
global $quipsList; | |
foreach ($quipsList as $quip){ | |
$unplayedQuip = $quip[$type]; | |
echo ' <p></p>'; | |
} | |
} | |
function getGames($type, $category) { | |
foreach ($type as $game) { | |
$name = $game['name']; | |
$platform = $game['platform']; | |
$note = $game['note']; | |
echo " <li title=\"".$name."\">" . $name . " <a class=\"delete_link\" href=\"#\"><span class='deleteButton'>✖</span></a> <span class=\"platform\">" . $platform . "</span><span class=\"note\">" . $note . "</span></li>"; | |
} | |
} | |
?><!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Playability</title> | |
<meta name="viewport" content="width=320, initial-scale=1, minimum-scale=0.45" /> | |
<link rel="stylesheet" type="text/css" media="screen" href="styles/style.css" > | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js" type="text/javascript"></script> | |
<script src="scripts/scripts.js" type="text/javascript"></script> | |
</head> | |
<body> | |
<a class="editLink" href="#">edit</a><a class="login" href="logout.php">log out</a> | |
<div class="category" id="unplayed"> | |
<h1>Unplayed<span class="unplayed new"><a href="#">+</a></span></h1> | |
<form method="post" action="add.php" id="addUnplayed" class="add"> | |
<input type="text" name="category" value="unplayed" /> | |
<input type="text" name="name" placeholder="Name" /> | |
<input type="text" name="platform" placeholder="Platform" /> | |
<textarea name="note"></textarea><br /> | |
<input type="submit" name="submit" value="+" /> | |
</form> | |
<?php getGames($unplayedGames, 'unplayed');?> | |
</div> | |
<div class="category" id="unbeaten"> | |
<h1>Unbeaten<span class="unbeaten new"><a href="#">+</a></span></h1> | |
<form method="post" action="add.php" id="addUnbeaten" class="add"> | |
<input type="text" name="user" value="<?php echo $userName;?>" style="display:none" /> | |
<input type="text" name="category" value="unbeaten" /> | |
<input type="text" name="name" placeholder="Name" /> | |
<input type="text" name="platform" placeholder="Platform" /> | |
<textarea name="note"></textarea><br /> | |
<input type="submit" name="submit" value="+" /> | |
</form> | |
<?php getGames($unbeatenGames, 'unbeaten');?> | |
</div> | |
<div class="category" id="beaten"> | |
<h1>Beaten<span class="beaten new"><a href="#">+</a></span></h1> | |
<form method="post" action="add.php" id="addBeaten" class="add"> | |
<input type="text" name="user" value="<?php echo $userName;?>" style="display:none" /> | |
<input type="text" name="category" value="beaten" /> | |
<input type="text" name="name" placeholder="Name" /> | |
<input type="text" name="platform" placeholder="Platform" /> | |
<textarea name="note"></textarea><br /> | |
<input type="submit" name="submit" value="+" /> | |
</form> | |
<?php getGames($beatenGames, 'beaten');?> | |
</div> | |
<div class="category" id="abandoned"> | |
<h1>Abandoned<span class="abandoned new"><a href="#">+</a></span></h1> | |
<form method="post" action="add.php" id="addAbandoned" class="add"> | |
<input type="text" name="user" value="<?php echo $userName;?>" style="display:none" /> | |
<input type="text" name="category" value="abandoned" /> | |
<input type="text" name="name" placeholder="Name" /> | |
<input type="text" name="platform" placeholder="Platform" /> | |
<textarea name="note"></textarea><br /> | |
<input type="submit" name="submit" value="+" /> | |
</form> | |
<?php getGames($abandonedGames, 'abandoned');?> | |
</div> | |
<div id="footer"><a href="http://shauninman.com/">Shaun Inman</a> gave me this idea. Designed by <a href="http://rickiesherman.com/">Rickie Sherman</a>. Powered by <a href="http://www.google.com/search?q=love">♥</a> , <a href="http://www.mongodb.org/"><img style="width : 7px; height : 14px; position: relative; top: 2px;" src="images/mongoleaf.png" /></a> , <a href="http://mongohq.com"><img style="width : 12px; height : 12px; position: relative; top: 1px;" src="images/mongohq.png" /></a> , <a href="http://zaksoup.com"><img style="width:15px;height:11px;" src="images/cupa.png" /></a> , and a <a href="http://support.apple.com/kb/sp13"><img style="position:relative;top:3px;" src="images/mbp.png" /></a> . <a href="http://shauninman.com/archive/2011/04/18/unplayed">More info</a></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function () { | |
var $editing = false; | |
$('.unplayed.new').click(function () { | |
if($editing == true){ | |
editToggle(); | |
}; | |
$('form#addUnplayed').slideToggle('slow', function () { | |
// Animation complete. | |
}); | |
}); | |
$('.unbeaten.new').click(function () { | |
$('form#addUnbeaten').slideToggle('slow', function () { | |
// Animation complete. | |
}); | |
}); | |
$('.beaten.new').click(function () { | |
$('form#addBeaten').slideToggle('slow', function () { | |
// Animation complete. | |
}); | |
}); | |
$('.abandoned.new').click(function () { | |
$('form#addAbandoned').slideToggle('slow', function () { | |
// Animation complete. | |
}); | |
}); | |
$('#addUnplayed').submit(function (event) { | |
event.preventDefault(); | |
$.post("api.php", { | |
action: 'add', | |
category: 'unplayed', | |
name: $('#addUnplayed input[name="name"]').val(), | |
platform: $('#addUnplayed input[name="platform"]').val(), | |
note: $('#addUnplayed textarea').val() | |
}, function (data) { | |
if (data == "success") { | |
$('#unplayed').append(" <li title=\"" + $('#addUnplayed input[name="name"]').val() + "\">" + $('#addUnplayed input[name="name"]').val() + " <a href=\"#\"><span class='deleteButton'>✖</span></a> <span>" + $('#addUnplayed input[name="platform"]').val() + "</span><span>" + $('#addUnplayed textarea').val() + "</span></li>"); | |
$(':input', '#addUnplayed').not(':button, :submit, :reset, :hidden').val('').removeAttr('checked').removeAttr('selected'); | |
//hideForm(); | |
} else { | |
alert(data); | |
}; | |
//alert(data); | |
}); | |
}); | |
$('#addAbandoned').submit(function (event) { | |
event.preventDefault(); | |
$.post("api.php", { | |
action: 'add', | |
category: 'abandoned', | |
name: $('#addAbandoned input[name="name"]').val(), | |
platform: $('#addAbandoned input[name="platform"]').val(), | |
note: $('#addAbandoned textarea').val() | |
}, function (data) { | |
if (data == "success") { | |
$('#abandoned').append(" <li title=\"" + $('#addAbandoned input[name="name"]').val() + "\">" + $('#addAbandoned input[name="name"]').val() + " <a href=\"#\"><span class='deleteButton'>✖</span></a> <span>" + $('#addAbandoned input[name="platform"]').val() + "</span><span>" + $('#addAbandoned textarea').val() + "</span></li>"); | |
$(':input', '#addAbandoned').not(':button, :submit, :reset, :hidden').val('').removeAttr('checked').removeAttr('selected'); | |
//hideForm(); | |
} else { | |
alert(data); | |
}; | |
//alert(data); | |
}); | |
}); | |
$('#addUnbeaten').submit(function (event) { | |
event.preventDefault(); | |
$.post("api.php", { | |
action: 'add', | |
category: 'unbeaten', | |
name: $('#addUnbeaten input[name="name"]').val(), | |
platform: $('#addUnbeaten input[name="platform"]').val(), | |
note: $('#addUnbeaten textarea').val() | |
}, function (data) { | |
if (data == "success") { | |
$('#unbeaten').append(" <li title=\"" + $('#addUnbeaten input[name="name"]').val() + "\">" + $('#addUnbeaten input[name="name"]').val() + " <a href=\"#\"><span class='deleteButton'>✖</span></a> <span class=\"platform\">" + $('#addUnbeaten input[name="platform"]').val() + "</span><span class=\"note\">" + $('#addUnbeaten textarea').val() + "</span></li>"); | |
$(':input', '#addUnbeaten').not(':button, :submit, :reset, :hidden').val('').removeAttr('checked').removeAttr('selected'); | |
//hideForm(); | |
} else { | |
alert(data); | |
}; | |
//alert(data); | |
}); | |
}); | |
$('#addBeaten').submit(function (event) { | |
event.preventDefault(); | |
$.post("api.php", { | |
action: 'add', | |
category: 'beaten', | |
name: $('#addBeaten input[name="name"]').val(), | |
platform: $('#addBeaten input[name="platform"]').val(), | |
note: $('#addBeaten textarea').val() | |
}, function (data) { | |
if (data == "success") { | |
$('#beaten').append(" <li title=\"" + $('#addBeaten input[name="name"]').val() + "\" >" + $('#addBeaten input[name="name"]').val() + " <a class=\"delete_link\" href=\"#\"><span class='deleteButton'>✖</span></a> <span>" + $('#addBeaten input[name="platform"]').val() + "</span><span>" + $('#addBeaten textarea').val() + "</span></li>"); | |
$(':input', '#addBeaten').not(':button, :submit, :reset, :hidden').val('').removeAttr('checked').removeAttr('selected'); | |
//hideForm(); | |
} else { | |
alert(data); | |
}; | |
//alert(data); | |
}); | |
}); | |
$('.editLink').click(function () { | |
editToggle(); | |
}); | |
$('span.deleteButton').live('click', function () { | |
var liThing = $(this).closest("li"); | |
$.post("api.php", { | |
action: 'remove', | |
category: $(this).closest("div").attr("id"), | |
name: $(this).closest("li").attr("title") | |
}, function (data) { | |
if (data == "success") { | |
liThing.fadeOut(); | |
} else { | |
alert('fail'); | |
alert(data); | |
}; | |
//alert(data); | |
}); | |
}); | |
function hideForm() { | |
$('form').slideUp(); | |
}; | |
function editToggle() { | |
$('.deleteButton').fadeToggle('fast', function () { | |
// Animation complete | |
}); | |
if($editing == false){ | |
$('li', 'div.category').draggable({ | |
cancel: "a.delete_button", | |
// clicking an icon won't initiate dragging | |
revert: "invalid", | |
// when not dropped, the item will revert back to its initial position | |
containment: $("#demo-frame").length ? "#demo-frame" : "document", | |
// stick to demo-frame if present | |
helper: "clone", | |
cursor: "move", | |
disabled: false | |
}); | |
$('div.category').droppable({ | |
accept: "div.category > li", | |
hoverClass: "drop_hover", | |
drop: function (event, ui) { | |
moveItem(ui.draggable, $(this)); | |
}, | |
disabled: false | |
}); | |
$editing = true; | |
}else{ | |
$('li', 'div.category').draggable({ disabled: true }); | |
$('div.category').droppable({ disabled: true }); | |
$editing = false; | |
}; | |
}; | |
}); | |
function moveItem($item, $category) { | |
$.post("api.php", { | |
action: 'remove', | |
category: $item.closest("div").attr("id"), | |
name: $item.closest("li").attr("title") | |
}, function (data) { | |
if (data == "success") { | |
//var $platform = $('span.deleteButton'); | |
$.post("api.php", { | |
action: 'add', | |
category: $category.attr('id'), | |
name: $item.closest("li").attr("title"), | |
platform: $item.closest("li").children('span.platform').html(), | |
note: $item.closest("li").children('span.note').html() | |
}, function (data) { | |
if (data == "success") { | |
$category.append($item); | |
} else { | |
alert(data); | |
}; | |
}); | |
} else { | |
alert('fail'); | |
alert(data); | |
}; | |
//alert(data); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment