header.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <?php
  2. session_start();
  3. include 'config.php';
  4. $Pagetitle='Overview';
  5. if($_GET["Logout"]=="1")
  6. {
  7. session_unset();
  8. session_destroy();
  9. }
  10. if($_GET["Mod"]=="12")$Pagetitle='Help';
  11. if($_GET["Mod"]=="11")$Pagetitle='Rules and Impressum';
  12. if($_GET["Mod"]=="10")$Pagetitle='Image List';
  13. if($_GET["Mod"]=="9")$Pagetitle='User List';
  14. if($_GET["Mod"]=="8")$Pagetitle='Log';
  15. if($_GET["Mod"]=="7")$Pagetitle='Edit Images';
  16. if($_GET["Mod"]=="6")$Pagetitle='Edit Story';
  17. if($_GET["Mod"]=="5")$Pagetitle='Create Story';
  18. if($_GET["Mod"]=="4")$Pagetitle='Create Page';
  19. if($_GET["Mod"]=="3")$Pagetitle='Edit Links';
  20. if($_GET["Mod"]=="2")$Pagetitle='Edit Image';
  21. if($_GET["Mod"]=="1")$Pagetitle='Edit Page';
  22. if($_GET["Mod"]=="" && $_GET["ID"]!="" && is_numeric($_GET["ID"]))
  23. {
  24. $sql = "SELECT Name FROM stor WHERE RefID=?";
  25. $stmt = $conn->prepare($sql);
  26. $stmt->bind_param("i", $_GET["ID"]);
  27. $stmt->execute();
  28. $result = $stmt->get_result();
  29. if ($result->num_rows > 0)
  30. {
  31. // output data of each row
  32. while($row = $result->fetch_assoc())
  33. {
  34. $Pagetitle=$row["Name"];
  35. }
  36. }
  37. }
  38. if($_GET["Mod"]=="" && $_GET["ID"]=="" && $_GET["User"]!="" && is_numeric($_GET["User"]))
  39. {
  40. $Pagetitle="Userpage";
  41. }
  42. if($upload=="1")
  43. $Pagetitle="Upload Image";
  44. echo '<html lang="en">
  45. <head><title>'.$Pagetitle.'</title> <link rel="icon" type="image/x-icon" href="favicon.png">
  46. <style>
  47. #skip-to-main a{
  48. position: absolute;
  49. left: -10000px;
  50. top: auto;
  51. width: 1px;
  52. height: 1px;
  53. overflow: hidden;
  54. }
  55. #skip-to-main a:focus{
  56. position: static;
  57. width: auto;
  58. height: auto;
  59. }
  60. </style>
  61. </head><body><div id="nav" role="navigation"> <div id = "skip-to-main">
  62. <a href = "#main-content">Skip to main content</a>
  63. </div>';
  64. if(isset($_POST['Go']))
  65. {
  66. $submitbutton= $_POST['Go'];
  67. if($submitbutton=="Login")
  68. {
  69. if($_POST['uName']!="" && !isset($_SESSION['Name']))
  70. {
  71. echo "Login attempted!";
  72. $sql = "SELECT Password, Level, ID FROM Users WHERE Name=?";
  73. $stmt = $conn->prepare($sql);
  74. $stmt->bind_param("s", $_POST['uName']);
  75. $stmt->execute();
  76. $result = $stmt->get_result();
  77. if ($result->num_rows > 0)
  78. {
  79. $PW=bin2hex(random_bytes(5));
  80. while($row = $result->fetch_assoc())
  81. {
  82. $PW=$row["Password"];
  83. $tID=$row["ID"];
  84. $tLevel=$row["Level"];
  85. }
  86. if(password_verify($_POST['uPass'], $PW))
  87. {
  88. echo "Set Session!";
  89. $_SESSION['Name'] = $_POST['uName'];
  90. $_SESSION['ID'] = $tID;
  91. $_SESSION['Level'] = $tLevel;
  92. }
  93. else
  94. {
  95. echo "Wrong Password";
  96. }
  97. }
  98. else
  99. {
  100. echo "Wrong Name";
  101. }
  102. }
  103. }
  104. else
  105. {
  106. if($_POST['uName']!="" && $_POST['uPass']!="")
  107. {
  108. $sql = "SELECT Password, Level, ID FROM Users WHERE Name=?";
  109. $stmt = $conn->prepare($sql);
  110. $stmt->bind_param("s", $_POST['uName']);
  111. $stmt->execute();
  112. $result = $stmt->get_result();
  113. if ($result->num_rows > 0)
  114. {
  115. echo 'Error: Username allrdy taken!';
  116. }
  117. else
  118. {
  119. $sql = "INSERT INTO Users (Name, Password, Level) VALUES (?, ?, '0')";
  120. $stmt = $conn->prepare($sql);
  121. $in1=$_POST['uName'];
  122. $in2=password_hash($_POST['uPass'], PASSWORD_DEFAULT);
  123. $stmt->bind_param("ss", $in1, $in2);
  124. $stmt->execute();
  125. echo "Registered";
  126. }
  127. }
  128. else
  129. {
  130. echo "Error: No Username/Password set";
  131. }
  132. }
  133. }
  134. else if (!isset($_SESSION['Name']))
  135. {
  136. echo '<form action="index.php" method="post" title="login or register" enctype="multipart/form-data">
  137. Login:
  138. <input type="text" title="Name" name="uName" id="uName">
  139. <input type="password" title="Password" name="uPass" id="uPass">
  140. <input type="submit" title="Login" value="Login" name="Go">
  141. <input type="submit" title="Register" value="Register" name="Go">
  142. | <a href=index.php>Index</a>
  143. </form></div>';
  144. }
  145. if (isset($_SESSION['Name']))
  146. {
  147. echo "<center>Hi <a href=\"index.php?User=" . $_SESSION['ID']. "\">" . htmlentities($_SESSION['Name']) . "</a>";
  148. echo " <a href=\"index.php?Logout=1\">(logout)</a> | <a href=index.php>Index</a> ";
  149. if($_SESSION['Level']>=$CreateStoryPermissionLevel)
  150. {
  151. echo "| <a href=index.php?Mod=4>Create Page</a> ";
  152. }
  153. if($_SESSION['Level']>=$CreatePagePermissionLevel)
  154. {
  155. echo "| <a href=index.php?Mod=5>Create Story</a> ";
  156. }
  157. if($_SESSION['Level']>=$ImagePermissionLevel)
  158. {
  159. echo "| <a href=upload.php>Add Image</a> ";
  160. }
  161. if($_GET["ID"]!="" && is_numeric($_GET["ID"]))
  162. {
  163. $sql = "SELECT Owner, Open, OpenAddLinks, OpenRemoveLinks, OpenImage FROM stor WHERE RefID=?";
  164. $stmt = $conn->prepare($sql);
  165. $stmt->bind_param("i", $_GET["ID"]);
  166. $stmt->execute();
  167. $result = $stmt->get_result();
  168. if ($result->num_rows > 0)
  169. {
  170. echo "| Page ID: " . $_GET["ID"];
  171. // output data of each row
  172. while($row = $result->fetch_assoc())
  173. {
  174. if($row["Open"]=="1" || $row["Owner"]== $_SESSION['ID'])
  175. {
  176. echo " | <a href=index.php?Mod=1&ID=".$_GET["ID"].">Edit Page</a>";
  177. }
  178. else
  179. {
  180. if($_SESSION['Level']>=$ModPermissionLevel)
  181. {
  182. echo " | <a href=index.php?Mod=1&ID=".$_GET["ID"].">MOD Edit Page</a>";
  183. }
  184. }
  185. if(($row["OpenAddLinks"]=="1" || $row["OpenRemoveLinks"]=="1") || $row["Owner"]== $_SESSION['ID'])
  186. {
  187. echo " | <a href=index.php?Mod=3&ID=".$_GET["ID"].">Edit Links</a>";
  188. }
  189. else
  190. {
  191. if($_SESSION['Level']>=$ModPermissionLevel)
  192. {
  193. echo " | <a href=index.php?Mod=3&ID=".$_GET["ID"].">MOD Edit Links</a>";
  194. }
  195. }
  196. if($row["OpenImage"]=="1" || $row["Owner"]== $_SESSION['ID'])
  197. {
  198. echo " | <a href=index.php?Mod=2&ID=".$_GET["ID"].">Edit Image</a>";
  199. }
  200. else
  201. {
  202. if($_SESSION['Level']>=$ModPermissionLevel)
  203. {
  204. echo " | <a href=index.php?Mod=2&ID=".$_GET["ID"].">MOD Edit Image</a>";
  205. }
  206. }
  207. }
  208. }
  209. }
  210. if($_SESSION['Level']>=$ImageEditPermissionLevel)
  211. {
  212. $sql = "SELECT Link FROM Images WHERE Unlocked=0";
  213. $stmt = $conn->prepare($sql);
  214. $stmt->execute();
  215. $result = $stmt->get_result();
  216. if ($result->num_rows > 0)
  217. {
  218. echo " | <a href=index.php?Mod=7>Images waiting for approval</a>";
  219. }
  220. else
  221. {
  222. echo " | <a href=index.php?Mod=7>Edit Images</a>";
  223. }
  224. }
  225. if($_SESSION['Level']>=$LogPermissionLevel)
  226. {
  227. echo " | <a href=index.php?Mod=8>View Log</a>";
  228. }
  229. if($_SESSION['Level']>=$UserSettingPermissionLevel)
  230. {
  231. echo " | <a href=index.php?Mod=9>List Users</a>";
  232. }
  233. echo "</center></div>";
  234. }
  235. ?>