PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/staffbox.php

https://github.com/delete66/sikevux-s-tracker
PHP | 385 lines | 278 code | 85 blank | 22 comment | 47 complexity | 81ee184ad2ac056f5edf92f0223e787d MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. require_once("include/bittorrent.php");
  3. require_once("include/user_functions.php");
  4. require_once("include/bbcode_functions.php");
  5. dbconn(false);
  6. maxcoder();
  7. if(!logged_in())
  8. {
  9. header("HTTP/1.0 404 Not Found");
  10. // moddifed logginorreturn by retro//Remember to change the following line to match your server
  11. print("<html><h1>Not Found</h1><p>The requested URL /{$_SERVER['PHP_SELF']} was not found on this server.</p><hr /><address>Apache/1.1.11 (xxxxx) Server at ".$_SERVER['SERVER_NAME']." Port 80</address></body></html>\n");
  12. die();
  13. }
  14. if (get_user_class() < UC_MODERATOR)
  15. hacker_dork("Staff Messages - Nosey Cunt !");
  16. $action = $HTTP_GET_VARS["action"];
  17. ///////////////////////////
  18. // SHOW PM'S //
  19. /////////////////////////
  20. if (!$action) {
  21. if (get_user_class() < UC_MODERATOR)
  22. stderr("Error", "Permission denied.");
  23. stdhead("Staff PM's");
  24. $res = mysql_query("SELECT count(id) FROM staffmessages") or die(mysql_error());
  25. $row = mysql_fetch_array($res);
  26. $url = " .$_SERVER[PHP_SELF]?";
  27. $count = $row[0];
  28. $perpage = 20;
  29. list($pagertop, $pagerbottom, $limit) = pager($perpage, $count, $url);
  30. print("<h1 align=center>Staff PM's</h1>");
  31. if ($count == 0) {
  32. print("<h2>No messages yet!</h2>");
  33. }
  34. else {
  35. echo $pagertop;
  36. begin_main_frame();
  37. print("<table width=765 border=1 cellspacing=0 cellpadding=5 align=center>\n");
  38. print("
  39. <tr>
  40. <td class=colhead align=left>Subject</td>
  41. <td class=colhead align=left>Sender</td>
  42. <td class=colhead align=left>Added</td>
  43. <td class=colhead align=left>Answered</td>
  44. <td class=colhead align=center>Set Answered</td>
  45. <td class=colhead align=left>Del</td>
  46. </tr>
  47. ");
  48. print("<form method=post action=?action=takecontactanswered>");
  49. $res = mysql_query("SELECT staffmessages.id, staffmessages.added, staffmessages.subject, staffmessages.answered, staffmessages.answeredby, staffmessages.sender, staffmessages.answer, users.username FROM staffmessages INNER JOIN users on staffmessages.sender = users.id ORDER BY id desc $limit");
  50. while ($arr = mysql_fetch_assoc($res))
  51. {
  52. if ($arr[answered])
  53. {
  54. $res3 = mysql_query("SELECT username FROM users WHERE id=$arr[answeredby]");
  55. $arr3 = mysql_fetch_assoc($res3);
  56. $answered = "<font color=green><b>Yes - <a href=userdetails.php?id=$arr[answeredby]><b>$arr3[username]</b></a> (<a href=staffbox.php?action=viewanswer&pmid=$arr[id]>View Answer</a>)</b></font>";
  57. }
  58. else
  59. $answered = "<font color=red><b>No</b></font>";
  60. $pmid = $arr["id"];
  61. print("<tr>
  62. <td><a href=/staffbox.php?action=viewpm&pmid=$pmid><b>$arr[subject]</b></td>
  63. <td><a href=userdetails.php?id=$arr[sender]><b>$arr[username]</b></a></td>
  64. <td>$arr[added]</td><td align=left>$answered</td>
  65. <td><input type=\"checkbox\" name=\"setanswered[]\" value=\"" . $arr[id] . "\" /></td>
  66. <td><a href=/staffbox.php?action=deletestaffmessage&id=$arr[id]>Del</a></td>
  67. </tr>\n
  68. ");
  69. }
  70. print("</table>\n");
  71. print("<p align=right><input type=submit value=Confirm></p>");
  72. print("</form>");
  73. echo $pagerbottom;
  74. end_main_frame();
  75. }
  76. stdfoot();
  77. }
  78. //////////////////////////
  79. // VIEW PM'S //
  80. //////////////////////////
  81. if ($action == "viewpm")
  82. {
  83. if (get_user_class() < UC_MODERATOR)
  84. stderr("Error", "Permission denied.");
  85. $pmid = 0 + $_GET["pmid"];
  86. $ress4 = mysql_query("SELECT id, subject, sender, added, msg, answeredby, answered FROM staffmessages WHERE id=$pmid");
  87. $arr4 = mysql_fetch_assoc($ress4);
  88. $answeredby = $arr4["answeredby"];
  89. $rast = mysql_query("SELECT username FROM users WHERE id=$answeredby");
  90. $arr5 = mysql_fetch_assoc($rast);
  91. $senderr = "" . $arr4["sender"] . "";
  92. if (is_valid_id($arr4["sender"]))
  93. {
  94. $res2 = mysql_query("SELECT username FROM users WHERE id=" . $arr4["sender"]) or sqlerr();
  95. $arr2 = mysql_fetch_assoc($res2);
  96. $sender = "<a href='userdetails.php?id=$senderr'>" . ($arr2["username"] ? $arr2["username"]:"[Deleted]") . "</a>";
  97. }
  98. else
  99. $sender = "System";
  100. $subject = $arr4["subject"];
  101. if ($arr4["answered"] == '0') {
  102. $answered = "<font color=red><b>No</b></font>";
  103. }
  104. else {
  105. $answered = "<font color=blue><b>Yes</b></font> by <a href=userdetails.php?id=$answeredby>$arr5[username]</a> (<a href=staffbox.php?action=viewanswer&pmid=$pmid>Show Answer</a>)";
  106. }
  107. if ($arr4["answered"] == '0') {
  108. $setanswered = "[<a href=/staffbox.php?action=setanswered&id=$arr4[id]>Mark Answered</a>]";
  109. }
  110. else {
  111. $setanswered = "";
  112. }
  113. $iidee = $arr4["id"];
  114. stdhead("Staff PM's");
  115. print("<table class=bottom width=730 border=0 cellspacing=0 cellpadding=10><tr><td class=embedded width=700>\n");
  116. print("<h1 align=center>Messages to staff</h1>\n");
  117. $elapsed = get_elapsed_time(sql_timestamp_to_unix_timestamp($arr4["added"]));
  118. print("<table width=750 border=1 cellspacing=0 cellpadding=10 style='margin-bottom: 10px'><tr><td class=text>\n");
  119. print("From <b>$sender</b> at\n" . $arr4["added"] . " ($elapsed ago) GMT\n");
  120. print("<br><br style='margin-bottom: -10px'><div align=left><b>Subject: <font color=darkred>$subject</b></font>
  121. &nbsp;&nbsp;<br><b>Answered:</b> $answered&nbsp;&nbsp;$setanswered</div>
  122. <br><table class=main width=730 border=1 cellspacing=0 cellpadding=10><tr><td class=staffpms>\n");
  123. print(format_comment($arr4["msg"]));
  124. print("</td></tr></table>\n");
  125. print("<table width=730 border=0><tr><td class=embedded>\n");
  126. print(($arr4["sender"] ? "<a href=/staffbox.php?action=answermessage&receiver=" . $arr4["sender"] . "&answeringto=$iidee><b>Reply</b></a>" : "<font class=gray><b>Reply</b></font>") .
  127. " | <a href=/staffbox.php?action=deletestaffmessage&id=" . $arr4["id"] . "><b>Delete</b></a></td>");
  128. print("</table></table>\n");
  129. print("</table>\n");
  130. stdfoot();
  131. }
  132. //////////////////////////
  133. // VIEW ANSWERS //
  134. //////////////////////////
  135. if ($action == "viewanswer")
  136. {
  137. if (get_user_class() < UC_MODERATOR)
  138. stderr("Error", "Permission denied.");
  139. $pmid = 0 + $_GET["pmid"];
  140. $ress4 = mysql_query("SELECT id, subject, sender, added, msg, answeredby, answered, answer FROM staffmessages WHERE id=$pmid");
  141. $arr4 = mysql_fetch_assoc($ress4);
  142. $answeredby = $arr4["answeredby"];
  143. $rast = mysql_query("SELECT username FROM users WHERE id=$answeredby");
  144. $arr5 = mysql_fetch_assoc($rast);
  145. if (is_valid_id($arr4["sender"]))
  146. {
  147. $res2 = mysql_query("SELECT username FROM users WHERE id=" . $arr4["sender"]) or sqlerr();
  148. $arr2 = mysql_fetch_assoc($res2);
  149. $sender = "<a href=userdetails.php?id=" . $arr4["sender"] . ">" . ($arr2["username"]?$arr2["username"]:"[Deleted]") . "</a>";
  150. }
  151. else
  152. $sender = "System";
  153. if ($arr4['subject'] == "") {
  154. $subject = "No subject";
  155. }
  156. else {
  157. $subject = "<a style='color: darkred' href=staffbox.php?action=viewpm&pmid=$pmid>$arr4[subject]</a>";
  158. }
  159. $iidee = $arr4["id"];
  160. if ($arr4[answer] == "") {
  161. $answer = "This message has not been answered yet!";
  162. }
  163. else {
  164. $answer = $arr4["answer"];
  165. }
  166. stdhead("Staff PM's");
  167. print("<table class=bottom width=730 border=0 cellspacing=0 cellpadding=10><tr><td class=embedded width=700>\n");
  168. print("<h1 align=center>Viewing Answer</h1>\n");
  169. $elapsed = get_elapsed_time(sql_timestamp_to_unix_timestamp($arr4["added"]));
  170. print("<table width=750 border=1 cellspacing=0 cellpadding=10 style='margin-bottom: 10px'><tr><td class=text>\n");
  171. print("<b><a href=userdetails.php?id=$answeredby>$arr5[username]</a></b> answered this message sent by $sender");
  172. print("<br><br style='margin-bottom: -10px'><div align=left><b>Subject: $subject</b>
  173. &nbsp;&nbsp;<br><b>Answer:</b></div>
  174. <br><table class=main width=730 border=1 cellspacing=0 cellpadding=10><tr><td class=staffpms>\n");
  175. print(format_comment($answer));
  176. print("</td></tr></table>\n");
  177. print("</table>\n");
  178. print("</table>\n");
  179. stdfoot();
  180. }
  181. //////////////////////////
  182. // ANSWER MESSAGE //
  183. //////////////////////////
  184. if ($action == "answermessage") {
  185. if (get_user_class() < UC_MODERATOR)
  186. stderr("Error", "Permission denied");
  187. $answeringto = $_GET["answeringto"];
  188. $receiver = 0 + $_GET["receiver"];
  189. if (!is_valid_id($receiver))
  190. die;
  191. $res = mysql_query("SELECT * FROM users WHERE id=$receiver") or die(mysql_error());
  192. $user = mysql_fetch_assoc($res);
  193. if (!$user)
  194. stderr("Error", "No user with that ID.");
  195. $res2 = mysql_query("SELECT * FROM staffmessages WHERE id=$answeringto") or die(mysql_error());
  196. $array = mysql_fetch_assoc($res2);
  197. stdhead("Answer to Staff PM", false);
  198. ?>
  199. <table class=main width=450 border=0 cellspacing=0 cellpadding=0><tr><td class=embedded>
  200. <div align=center>
  201. <h2>Answering to <a href=/staffbox.php?action=viewpm&pmid=<?=$array['id']?>><i><?=$array["subject"]?></i></a> sent by <i><?=$user["username"]?></i></h2>
  202. <form method=post name=message action=?action=takeanswer>
  203. <? if ($_GET["returnto"] || $_SERVER["HTTP_REFERER"]) { ?>
  204. <? } ?>
  205. <table class=message cellspacing=0 cellpadding=5>
  206. <tr><td colspan=2>
  207. <?
  208. textbbcode("message","msg","$body");
  209. ?></td></tr>
  210. <tr>
  211. <tr><td<?=$replyto?" colspan=2":""?> align=center><input type=submit value="Send it!" class=btn></td></tr>
  212. </table>
  213. <input type=hidden name=receiver value=<?=$receiver?>>
  214. <input type=hidden name=answeringto value=<?=$answeringto?>>
  215. </form>
  216. </div></td></tr></table>
  217. <?
  218. stdfoot();
  219. }
  220. //////////////////////////
  221. // TAKE ANSWER //
  222. //////////////////////////
  223. if ($action == "takeanswer") {
  224. if ($HTTP_SERVER_VARS["REQUEST_METHOD"] != "POST")
  225. stderr("Error", "Method");
  226. if (get_user_class() < UC_MODERATOR)
  227. stderr("Error", "Permission denied");
  228. $receiver = 0 + $_POST["receiver"];
  229. $answeringto = $_POST["answeringto"];
  230. if (!is_valid_id($receiver))
  231. stderr("Error","Invalid ID");
  232. $userid = $CURUSER["id"];
  233. $msg = trim($_POST["msg"]);
  234. $message = sqlesc($msg);
  235. $added = "'" . get_date_time() . "'";
  236. if (!$msg)
  237. stderr("Error","Please enter something!");
  238. mysql_query("INSERT INTO messages (poster, sender, receiver, added, msg) VALUES($userid, $userid, $receiver, $added, $message)") or sqlerr(__FILE__, __LINE__);
  239. mysql_query("UPDATE staffmessages SET answer=$message WHERE id=$answeringto") or sqlerr(__FILE__, __LINE__);
  240. mysql_query("UPDATE staffmessages SET answered='1', answeredby='$userid' WHERE id=$answeringto") or sqlerr(__FILE__, __LINE__);
  241. header("Location: staffbox.php?action=viewpm&pmid=$answeringto");
  242. die;
  243. }
  244. //////////////////////////
  245. // DELETE STAFF MESSAGE //
  246. //////////////////////////
  247. if ($action == "deletestaffmessage") {
  248. $id = 0 + $_GET["id"];
  249. if (!is_numeric($id) || $id < 1 || floor($id) != $id)
  250. die;
  251. if (get_user_class() < UC_MODERATOR)
  252. stderr("Error", "Permission denied.");
  253. mysql_query("DELETE FROM staffmessages WHERE id=" . sqlesc($id)) or die();
  254. header("Location: $BASEURL/staffbox.php");
  255. }
  256. //////////////////////////
  257. // MARK AS ANSWERED //
  258. //////////////////////////
  259. if ($action == "setanswered") {
  260. if (get_user_class() < UC_MODERATOR)
  261. stderr("Error", "Permission denied.");
  262. $id = 0 + $_GET["id"];
  263. mysql_query ("UPDATE staffmessages SET answered=1, answeredby = $CURUSER[id] WHERE id = $id") or sqlerr();
  264. header("Refresh: 0; url=staffbox.php?action=viewpm&pmid=$id");
  265. }
  266. //////////////////////////
  267. // MARK AS ANSWERED #2 //
  268. //////////////////////////
  269. if ($action == "takecontactanswered") {
  270. if (get_user_class() < UC_MODERATOR)
  271. stderr("Error", "Permission denied.");
  272. $res = mysql_query ("SELECT id FROM staffmessages WHERE answered=0 AND id IN (" . implode(", ", $_POST[setanswered]) . ")");
  273. while ($arr = mysql_fetch_assoc($res))
  274. mysql_query ("UPDATE staffmessages SET answered=1, answeredby = $CURUSER[id] WHERE id = $arr[id]") or sqlerr();
  275. header("Refresh: 0; url=staffbox.php");
  276. }
  277. ?>