Guest User

Untitled

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