forked from halbox/speak
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
96 lines (83 loc) · 3.58 KB
/
index.php
File metadata and controls
96 lines (83 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
// yeah... we know :-O This is a dummy app, cut some slack
$noDatabase = true;
if (isset($_SERVER['db_host']) && isset($_SERVER['db_user']) && isset($_SERVER['db_pass']) && isset($_SERVER['db_name'])) {
$con = mysql_connect($_SERVER['db_host'], $_SERVER['db_user'], $_SERVER['db_pass']);
if (!$con) {
$noDatabase = true;
die('Could not connect: ' . mysql_error());
}
$noDatabase = !mysql_select_db($_SERVER['db_name'], $con);
if (isset($_POST['Content'])) {
// Create Table if not exist
$sql = 'CREATE TABLE IF NOT EXISTS `Message` (`Content` text NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=utf8';
mysql_query($sql, $con);
if ($content = $_POST['Content']) {
$sql = "INSERT INTO Message (Content) VALUES ('" . mysql_real_escape_string($content, $con) . "')";
mysql_query($sql, $con);
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Pagoda Message App</title>
<link rel="stylesheet" type="text/css" href="css/layout.css" media="all" />
<script type="text/javascript" src="http://use.typekit.com/hai1jyh.js"></script>
<script type="text/javascript">try{Typekit.load();}catch(e){}</script>
</head>
<body>
<div class="wrapper">
<div class="content">
<? if ($noDatabase): ?>
<div class="moon"></div>
<div class="box">
<p>We were unable to locate your database. You can create one in your <a href="http://dashboard.pagodabox.com" target="_blank">admin panel</a>, then simply set the following global vars to your database’s credentials. You do so via the <a href="http://guides.pagodabox.com/images/misc-demos/global-vars.png" target="_blank">Global Vars</a> tab in the admin panel:</p>
<p class="indent">db_name = ‹your-db-name›</p>
<p class="indent">db_host = ‹your-db-host›</p>
<p class="indent">db_user = ‹your-db-user›</p>
<p class="indent">db_pass = ‹your-db-password›</p>
<p>No need to move in haste, the universe is patient.</p>
</div>
<? else: ?>
<form action="index.php" method="post">
<div class="border">
<input type="text" name="Content" class="textarea" />
</div>
<input class="btn" type="image" value="" src="images/btn.png" border="0" name="btn">
<div class="message-box">
<?
$count = 0;
$cssClass = array("yellow", "orange");
$result = mysql_query("SELECT * FROM `Message`", $con);
$valAr = array();
// Pull values out of db and put in array
while ($result and $row = mysql_fetch_array($result))
{
array_push($valAr, $row['Content']);
}
// Reverse array and print values as html
$valAr = array_reverse( $valAr );
$len = count($valAr);
for ($i = 0; $i < $len; $i++) {
echo "<div class='message " . $cssClass[$count] . "'>";
echo " <span class='top'></span>";
echo $valAr[$i];
echo " <span class='bottom'></span>";
echo "</div>";
$count++;
if ($count == (count($cssClass))){
$count = 0;
}
}
mysql_close($con);
?>
</div>
</form>
<? endif ?>
</div>
</div>
</body>
</html>