-
Notifications
You must be signed in to change notification settings - Fork 0
/
postMessage (Brian-PC's conflicted copy 2013-11-06).php
executable file
·156 lines (126 loc) · 4.52 KB
/
postMessage (Brian-PC's conflicted copy 2013-11-06).php
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Post Message</title>
<link rel="stylesheet" type="text/css" href="SiteStyle.css" />
<meta http-equiv="Content-Type"
content="text/html; charset = ISO-8859-1" />
</head>
<script language = "javascript">
// credits to http://www.smartwebby.com/DHTML/textbox_characters_counter.asp
var MAX_MESSAGE_LENGTH = 400;
var bName = navigator.appName;
function taCount(taObj, cnt) {
objCnt = createObject(cnt);
objVal = taObj.value;
//if (objVal.length > MAX_MESSAGE_LENGTH) {
//objVal = objVal.substring(0, MAX_MESSAGE_LENGTH);
//}
if (objCnt) {
if (bName == "Netscape") {
objCnt.textContent = MAX_MESSAGE_LENGTH - objVal.length;
}
else {
objCnt.innerText = MAX_MESSAGE_LENGTH - objVal.length;
}
}
return true;
}
function createObject(objId) {
if (document.getElementById) {
return document.getElementById(objId);
}
else if (document.layers) {
return eval("document." + objId);
}
else if (document.all) {
return eval("document.all." + objId);
}
else {
return eval("document." + objId);
}
}
function process() {
var toUser = document.getElementsByName('toUser')[0].value;
var request;
if (window.XMLHttpRequest) {
request = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
alert("Stop using Internet Explorer dammit");
self.location = "profile.php?user=" + toUser;
}
}
}
else {
alert("Your browser must be as old as you are");
self.location = "profile.php?user=" + toUser;
}
var msg = document.getElementById("message");
var msgData = encodeURIComponent(msg.value);
var formData = "toUser=" + toUser + "&" + msg.name + "=" + msgData; // "name=value"
//var formData = document.getElementById("postMessage").serialize();
//var formData = new FormData(document.getElementById("postMessage")); // apparently unsupported by Z
//var formData = new FormData(document.forms.namedItem("postMessage"));
request.open('POST', 'postMessageHandler.php', true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.send(formData);
var oOutput = document.getElementById("output");
request.onreadystatechange = function() {
if (request.status !== 200) {
alert("Error " + request.status + "; please try again.");
//oOutput.innerHTML = "Error " + request.status + "; please try again.";
}
else if (msg.length <= 0 && request.readyState === 4) {
alert("Yo dawg you gots to enter a message");
}
else if (msg.length > MAX_MESSAGE_LENGTH && request.readyState === 4) { // will handle worst case scenario when all chars need to be encoded
alert("Not sure if illiterate or just stupid...");
}
else if (request.readyState === 4 && request.status === 200) {
alert("Message posted! Click OK to continue.");
self.location = "profile.php?user=" + toUser;
//oOutput.innerHTML = "Message posted! Response text is " + request.responseText + ".";
}
}
return false;
}
</script>
<body>
<?php
session_start();
require "class_lib_test.php";
// get op from session var
$op = $_SESSION['username'];
printToolbar($op, false);
echo "</br>";
if (!isEmptyString($op)) {
?>
<!--<form id="postMessage" action="postMessageHandler.php" enctype="multipart/form-data" method="POST">-->
<form id = "postMessage" name="postMessage" method="POST" onsubmit="process(); return false;">
Enter a message (<?php echo $MAX_MESSAGE_LENGTH; ?> character limit):</br></br>
<textarea onKeyPress="return taLimit(this)" onKeyUp="return taCount(this, 'counter')" id="message" name="message" value="msgVal" cols="60" rows="7"></textarea></br>
<input type = "hidden" name = "toUser" value = "<?php echo $_GET['toUser']; ?>">
</br>You have <B><SPAN id=counter><?php echo $MAX_MESSAGE_LENGTH; ?></SPAN></B> characters remaining.</br></br>
<input type="submit" value="Submit">
</form>
</br>
<div id="output"></div>
<?php
}
else {
echo "You must be logged in to do that. Click <a href=login.php>here</a> to log in. Click <a href=signup1.php>here</a>
to sign up for an account.</br>";
}
?>
</body>
</html>