Guest User

Untitled

a guest
Mar 7th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.69 KB | None | 0 0
  1. <?
  2. /*
  3. NeoNippon xajax server file
  4. v. 1
  5. **/
  6.  
  7. require('header.php');
  8.  
  9.  
  10.  
  11. $xajax->register(XAJAX_FUNCTION, login);
  12. $xajax->register(XAJAX_FUNCTION, logout);
  13. $xajax->register(XAJAX_FUNCTION, display);
  14. $xajax->register(XAJAX_FUNCTION, update);
  15. $xajax->register(XAJAX_FUNCTION, changeskin);
  16. $xajax->register(XAJAX_FUNCTION, add_notice);
  17. $xajax->register(XAJAX_FUNCTION, show_notice);
  18. $xajax->register(XAJAX_FUNCTION, mark_notice_read);
  19.  
  20. $notices_read = '';
  21.  
  22.  
  23. function login($aFormValues)
  24. {
  25. global $SDK;
  26. global $smarty;
  27. $objResponse = new xajaxResponse();
  28. // The form was submitted. Lets authenticate!
  29. if (trim($aFormValues['username']) == "" && trim($aFormValues['password']) == "")
  30. {
  31. $objResponse->Assign("alertMsg", "innerHTML", "Please fill in all of the form fields to login");
  32. $bError = true;
  33. }
  34.  
  35. else {
  36.  
  37. if (trim($aFormValues['username']) == "")
  38. {
  39.  
  40. $objResponse->Assign("alertMsg", "innerHTML", "Please enter your username");
  41. $bError = true;
  42.  
  43. }
  44. if (trim($aFormValues['password']) == "")
  45. {
  46.  
  47. $objResponse->Assign("alertMsg", "innerHTML", "Please enter your password");
  48. $bError = true;
  49.  
  50. }
  51.  
  52. }
  53. if(!$bError)
  54. {
  55. $username = trim($aFormValues['username']);
  56. $password = trim($aFormValues['password']);
  57. if ($SDK->login($username, $password))
  58. {
  59.  
  60. // The login worked.
  61. $html = $smarty->fetch("loginMsg/loggedin.tpl");
  62. $objResponse->Assign("alertMsg", "innerHTML", $html);
  63. $objResponse->Script("document.getElementById('alertMsg').style.display='block';
  64. document.getElementById('extra').style.display='block';
  65. document.getElementById('login').style.display='none';
  66. setTimeout(\"document.getElementById('alertMsg').style.display='none'\",3000);
  67. update('TRUE')");
  68.  
  69. }
  70. else
  71. {
  72. $objResponse->Assign("alertMsg", "innerHTML", "Your username or password was incorrect");
  73. $objResponse->Assign("loginButton", "value", "Login");
  74. $objResponse->Assign("loginButton", "disabled", false);
  75. $objResponse->Script("document.getElementById('alertMsg').style.display='block';
  76. setTimeout(\"document.getElementById('alertMsg').style.display='none'\",3000); ");
  77.  
  78. }
  79. }
  80. else
  81. {
  82.  
  83. $objResponse->Assign("loginButton", "disabled", false);
  84.  
  85. }
  86.  
  87. return $objResponse;
  88.  
  89. }
  90.  
  91. function logout()
  92. {
  93. global $SDK;
  94. global $smarty;
  95. $objResponse = new xajaxResponse();
  96.  
  97. $SDK->logout();
  98.  
  99.  
  100. $loginhtml = "You are currently a <b>Guest</b>.<form id=\"loginbox\" action=\"javascript:void(null);\" onsubmit=\"login();\">
  101. Username:<input type=\"text\" id=\"username\" name=\"username\">
  102. Password:<input type=\"password\" id=\"password\" name=\"password\">
  103. <input value=\"Login\" name=\"submit\" id=\"loginButton\" type=\"submit\">
  104. </form>";
  105. $objResponse->Assign("login", "innerHTML", $loginhtml);
  106. $html = $smarty->fetch("loginMsg/loggedout.tpl");
  107. $objResponse->Assign("alertMsg", "innerHTML", $html);
  108. $objResponse->Script("document.getElementById('alertMsg').style.display='block';
  109. document.getElementById('extra').style.display='none';
  110. document.getElementById('login').style.display='block';
  111. setTimeout(\"document.getElementById('alertMsg').style.display='none'\",3000);
  112. setTimeout(\"update('TRUE')\", 0);");
  113.  
  114.  
  115.  
  116. return $objResponse;
  117.  
  118. }
  119.  
  120. function display($page, $divID = "content")
  121. {
  122. global $SDK;
  123. global $smarty;
  124. $objResponse = new xajaxResponse();
  125. $pagehtml = $smarty->fetch($page . ".tpl");
  126.  
  127. $objResponse->Assign($divID, "innerHTML", $pagehtml);
  128.  
  129. return $objResponse;
  130. }
  131.  
  132. function update($page = "main", $divID = "content", $updatecontent, $noticesRead = NULL)
  133. {
  134. global $SDK;
  135. global $smarty;
  136.  
  137. $objResponse = new xajaxResponse();
  138.  
  139. // assign all the variables
  140.  
  141. $avatar = $SDK->get_avatar();
  142. $userinfo = $SDK->get_info();
  143. $name = $userinfo['name'];
  144. $postcount = "Posts: " . $userinfo['posts'];
  145. $group = $SDK->get_groupinfo();
  146. $grouphtml = "Group: " . $group['prefix'] . $group['g_title'] . $group['suffix'];
  147. $pms = $SDK->get_num_new_pms() . " Private Messages";
  148. $pips = $SDK->get_member_pips();
  149.  
  150. $pagehtml = $smarty->fetch($page . ".tpl");
  151.  
  152. // assign the variables to the proper ID
  153. $objResponse->Assign("avatar", "innerHTML", $avatar);
  154. $objResponse->Assign("name", "innerHTML", $name);
  155. $objResponse->Assign("pms", "innerHTML", $pms);
  156. $objResponse->Assign("postcount", "innerHTML", $postcount);
  157. $objResponse->Assign("membergroup", "innerHTML", $grouphtml);
  158. $objResponse->Assign("pips", "innerHTML", $pips);
  159. if ($updatecontent == "TRUE")
  160. {
  161. $objResponse->Assign($divID, "innerHTML", $pagehtml);
  162. }
  163.  
  164. /*if($SDK->is_loggedin() == "0")
  165. {
  166. $objResponse->Script("xajax_logout();");
  167.  
  168. }*/
  169.  
  170. $notice = show_notice($noticesRead);
  171. $title = $notice['title'];
  172. $msg = $notice['message'];
  173. $id = $notice['id'];
  174. $amount = $notice['amount'];
  175.  
  176. // $objResponse->Alert($id);
  177. // $objResponse->Alert($noticesRead);
  178. $noticesRead = $noticesRead ? $noticesRead : 0;
  179. if($amount != 0)
  180. {
  181. $objResponse->Script("noticebox('$id', $noticesRead);");
  182. $objResponse->Assign("noticeTitle", "innerHTML", $title);
  183. $objResponse->Assign("noticeMsg", "innerHTML", $msg);
  184. } else {
  185. $objResponse->Script("document.getElementById('noticeBox-litebox').style.display='none';
  186. document.getElementById('blackLitebox').style.display='none'");
  187. }
  188.  
  189. return $objResponse;
  190. }
  191.  
  192. function changeskin($skin, $currentpage)
  193. {
  194. global $SDK;
  195. global $smarty;
  196.  
  197. $objResponse = new xajaxResponse();
  198.  
  199. if($SDK->is_loggedin() == "1")
  200. {
  201. if (in_array($skin, $SDK->list_skins()))
  202. {
  203. if ($SDK->set_user_skin($skin))
  204. {
  205. $skin = $SDK->get_skin_info($skin);
  206. $skin['set_name'] = str_replace(" ", "_" ,$skin['set_name']);
  207. $objResponse->Assign("alertMsg", "innerHTML", "Your skin was changed!");
  208. $objResponse->includeCSS("./style//" . $skin['set_name'] . ".css");
  209. } else {
  210. $objResponse->Assign("alertMsg", "innerHTML", "Your skin could not be updated!");
  211. }
  212. } else {
  213. $objResponse->Assign("alertMsg", "innerHTML", "You must select a valid skin!");
  214. }
  215. } else {
  216. $objResponse->Assign("alertMsg", "innerHTML", "You are not logged in!");
  217. }
  218.  
  219.  
  220. $objResponse->Script("document.getElementById('alertMsg').style.display='block';
  221. setTimeout(\"document.getElementById('alertMsg').style.display='none'\",3000);");
  222. $objResponse->Assign("skinButton", "value", "Change Skin");
  223. $objResponse->Assign("skinButton", "disabled", false);
  224.  
  225. if($currentpage == "forum")
  226. {
  227. $URL = "/forum/index.php?act=idx&" . $skin['set_name'];
  228. $objResponse->Assign("forumframe", "src", $URL);
  229. }
  230. return $objResponse;
  231. }
  232.  
  233. function add_notice($msg, $title)
  234. {
  235. global $SDK;
  236. global $smarty;
  237.  
  238. $notice['msg'] = $msg;
  239. $notice['title'] = $title;
  240.  
  241. $query = "INSERT INTO `ibf_notices` title = " . $notice['title'] . ", `message` = " . $notice['msg'];
  242. }
  243.  
  244. function show_notice($noticesRead = NULL)
  245. {
  246. global $SDK;
  247. global $smarty;
  248. global $notices_read;
  249.  
  250. $AND = '';
  251. if($SDK->is_loggedin() == "1")
  252. {
  253. $member = $SDK->get_info();
  254. $id = $member['id'];
  255.  
  256. $query = "SELECT `notices_read` FROM `ibf_member_extra` WHERE `id` = ". $id;
  257.  
  258. $result = $SDK->DB->query($query);
  259.  
  260. $notices_read = $SDK->DB->fetch_row($result);
  261. $notices_read = $notices_read['notices_read'];
  262.  
  263. $loggedin = "1, 2";
  264. $AND .= " AND `mgroup` IN (".$member['mgroup'] .", NULL)";
  265. $AND .= " AND `memberID` IN (".$id.",NULL)";
  266. } else {
  267. $notices_read = $noticesRead;
  268. $notices_read = ltrim($notices_read, ",");
  269. $notices_read = rtrim($notices_read, ",");
  270. $loggedin = "0, 2";
  271. }
  272.  
  273.  
  274. if (!$notices_read)
  275. {
  276. $notices_read = 0;
  277. }
  278.  
  279. $notices_read = ltrim($notices_read, ",");
  280. $notices_read = rtrim($notices_read, ",");
  281.  
  282. $AND .= "AND `loggedin` IN (". $loggedin .")";
  283.  
  284. $ORDERBY = "ORDER BY `id` ASC";
  285.  
  286. $query = "SELECT * FROM ibf_notices WHERE `id` NOT IN (".$notices_read.") ". $AND ." ". $ORDERBY ." LIMIT 1";
  287.  
  288. $result = $SDK->DB->query($query);
  289.  
  290. $notice = $SDK->DB->fetch_row($result);
  291.  
  292. $notice['amount'] = $SDK->DB->get_num_rows($result);
  293.  
  294. return $notice;
  295.  
  296. }
  297.  
  298. function mark_notice_read($noticeID, $noticesRead = NULL) {
  299.  
  300. global $SDK;
  301. global $smarty;
  302. global $notices_read;
  303.  
  304. $objResponse = new xajaxResponse();
  305.  
  306. if($SDK->is_loggedin() == "1") {
  307.  
  308. $member = $SDK->get_info();
  309. $id = $member['id'];
  310.  
  311. $query = "SELECT `notices_read` FROM `ibf_member_extra` WHERE `id` = ". $id;
  312.  
  313. $result = $SDK->DB->query($query);
  314.  
  315. $notices_read = $SDK->DB->fetch_row($result);
  316. $notices_read = $notices_read['notices_read'];
  317. $notices_read .= ",$noticeID";
  318.  
  319.  
  320. $notices_read = ltrim($notices_read, ",");
  321. $notices_read = rtrim($notices_read, ",");
  322.  
  323. $query = "UPDATE `ibf_member_extra` SET `notices_read` = '" . $notices_read . "' WHERE `id` = " . $id;
  324. $result = $SDK->DB->query($query);
  325.  
  326. } else {
  327. $notices_read = $noticesRead;
  328. $notices_read .= ",$noticeID";
  329. $notices_read = ltrim($notices_read, ",");
  330. $notices_read = rtrim($notices_read, ",");
  331.  
  332. }
  333. $objResponse->Alert($notices_read . ", " . $noticesRead);
  334. $objResponse->Script("document.getElementById('noticeBox-litebox').style.display='none';
  335. document.getElementById('blackLitebox').style.display='none';
  336. noticesRead = '$notices_read';
  337. ");
  338. return $objResponse;
  339.  
  340. }
  341.  
  342. $xajax->processRequest();
  343.  
  344. ?>
Add Comment
Please, Sign In to add comment