1. <?php
  2. include('structure/config.php');
  3. include('structure/server.php');
  4. $server = new server($db_host, $db_name, $db_user, $db_password);
  5. $user = new user($server->returnDb());
  6. ?>
  7. <!DOCTYPE html>
  8. <html>
  9. <head>
  10. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  11. <link href="css/main.css" rel="stylesheet" type="text/css">
  12. <title><?php echo $data['wb_title']; ?> - Index</title>
  13. </head>
  14. <body>
  15. <noscript>
  16. <div class="notice major center">
  17. This site requires JavaScript.
  18. </div>
  19. </noscript>
  20. <div class="container">
  21. <div id="navbar">
  22. <ul>
  23. <li><a href="index.php">Home</a></li>
  24. <li><a href="news.php">News</a></li>
  25. <li><a href="about.php">Search</a></li>
  26. <?php
  27. if(!$user->loggedIn){
  28. ?>
  29. <li><a href="login.php">Login</a></li>
  30. <li><a href="register.php">Register</a></li>
  31. <?php
  32. }else{
  33. ?>
  34. <li><a href="login.php">My Account</a></li>
  35. <li><a href="register.php">My Threads</a></li>
  36. <li><a href="logout.php">Logout</a></li>
  37. <?php
  38. }
  39. ?>
  40. </ul>
  41. </div>
  42. <div id="main">
  43. <div class="content">
  44. <?php
  45. if(!$user->loggedIn){
  46. ?>
  47. <div class="notice center">
  48. It seems you're not logged in. Why not <a href="register.php">register</a> or <a href="login.php">login</a> now?
  49. </div>
  50. <div class="spacing"></div>
  51. Welcome to BImg! BImg is a graphics board; it allows users to share their graphics with everyone else and receive an overall rating which is decided by other fellow users of BImg. Want to share your graphics and see what the community thinks? <a href="">Get started now!</a>
  52. <?php
  53. }else{
  54. ?>
  55. <a href="#" id="new">Create new</a>
  56. <div id="add" class="light_yellow hidden center">
  57. Please fill out all the information.
  58. <table class="yellow_table">
  59. <tr><td id="title_td1">Title</td><td id="title_td2"><div class="light_yellow field_error center hidden" id="title_error"></div><input type="text" name="title" maxlength="30"></td></tr>
  60. <tr><td id="image_td1">Image</td><td id="image_td2"><div class="light_yellow field_error center hidden" id="image_error"></div><input type="file" name="file" /></td></tr>
  61. <tr><td id="content_td1">Content</td><td id="content_td2"><div class="light_yellow field_error center hidden" id="content_error"></div><textarea name="content" cols="65" rows="25" maxlength="1500"></textarea></td></tr>
  62. <tr><td id="submit_td1">Image</td><td id="image_td2"><div class="light_yellow field_error center hidden" id="submit_error"></div><input type="submit" value="Upload & Post" id="submit_button"> or <a href="#" id="cancel">cancel</a></td></tr>
  63. </table>
  64. </div>
  65. <?php
  66. }
  67. ?>
  68. <table class="posts" id="posts">
  69. <tr><th>Thread</th><th>Replies</th><th>Date</th><th>Action</th></tr>
  70. <tr><td><img src="img/new-message.png" width="15" height="15">&nbsp;<a href="#">My new signature..</a></td><td>0</td><td>Oct-27-2012</td><td><a href="#">Reply</a></td></tr>
  71. <tr><td><a href="#">My new signature..</a></td><td>0</td><td>Oct-27-2012</td><td><a href="#">Reply</a></td></tr>
  72. <tr><td><a href="#">My new signature..</a></td><td>0</td><td>Oct-27-2012</td><td><a href="#">Reply</a></td></tr>
  73. <tr><td><a href="#">My new signature..</a></td><td>0</td><td>Oct-27-2012</td><td><a href="#">Reply</a></td></tr>
  74. </table>
  75. </div>
  76. </div>
  77. </div>
  78. <script type="text/javascript" src="js/jquery.js"></script>
  79. <script type="text/javascript">
  80. $(document).ready(function(){
  81. var file;
  82. var title = $('input[name="title"]');
  83. var image = $('input[name="file"]');
  84. var content = $('textarea[name="content"]');
  85. var submit = $('#submit_button');
  86. var last_time = 0;
  87. var x = 0;
  88. $('#new').click(function(){
  89. //if (window.File && window.FileReader && window.FileList && window.Blob) {
  90. $('#add').fadeIn();
  91. $('#posts').fadeOut();
  92. $('#new').fadeOut(0);
  93. //} else {
  94. //alert('The necessary File APIs are not supported in your browser. Please use a modern browser like Google Chrome or FireFox.');
  95. //}
  96. });
  97. $('#cancel').click(function(){
  98. $('#add').fadeOut();
  99. $('#posts').fadeIn();
  100. $('#new').fadeIn(0);
  101. });
  102. image.change(function(){
  103. extension = image.val().split('.')[1];
  104. if(extension != 'png' && extension != 'jpeg' && extension != 'bmp' && extension != 'gif'){
  105. image.val('');
  106. displayError('#image', 'That file extension is not allowed.');
  107. }else{
  108. file = this;
  109. }
  110. });
  111. title.keypress(function(){
  112. validateTitle();
  113. });
  114. title.change(function(){
  115. validateTitle();
  116. });
  117. $('#submit_button').click(function(){
  118. if(x == 1){
  119. d = new Date();
  120. if(d.getTime() - last_time > 4000){
  121. x = 0;
  122. }
  123. }else{
  124. x++;
  125. d = new Date();
  126. last_time = d.getTime();
  127. if(title.val().length == 0){
  128. displayError('#title', 'Your title cannot be empty.');
  129. }else if(title.val().length < 3){
  130. displayError('#title', 'Your title has to be at least 3 characters.');
  131. }else if (content.val().length == 0){
  132. displayError('#content', 'Your content field cannot be empty.');
  133. }else if(content.val().length < 30){
  134. displayError('#content', 'Your content must be at least 30 characters.');
  135. }else{
  136. alert('attempting');
  137. $.ajax({
  138. type: "POST",
  139. url: "post.php",
  140. data: { t: title.val(), c: content.val(), image: file}
  141. }).done(function(msg) {
  142. alert(msg);
  143. if(msg != "success"){
  144. split = msg.split(',');
  145. displayError(split[0], split[1]);
  146. }else{
  147. alert(msg);
  148. }
  149. });
  150. }
  151. }
  152. });
  153. function setFile(file){
  154. file = file;
  155. }
  156. function validateTitle(){
  157. if(title.val().length > 30){
  158. displayError('#title', 'Your title cannot be greater than 30 characters.');
  159. title.val(title.val().substr(0,30));
  160. }
  161. }
  162. function displayError(id, message){
  163. $(id+'_error').text(message);
  164. $(id+'_error').fadeIn(1500);
  165. $(id+'_error').delay(2500).fadeOut(1500);
  166. }
  167. });
  168. </script>
  169. </body>
  170. </html>