Guest User

Untitled

a guest
Jan 19th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.34 KB | None | 0 0
  1. <?php
  2.  
  3. require_once '../vendor/autoload.php';
  4. include "../lib/Database.php";
  5. include "../config/config.php";
  6. include "../helpers/Format.php";
  7. $db = new Database();
  8. $fm = new Format();
  9. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  10. $name = mysqli_real_escape_string($db->link, $fm->validation($_POST['sender']));
  11. $postComment = mysqli_real_escape_string($db->link, $fm->validation($_POST['comment']));
  12. $commentId = mysqli_real_escape_string($db->link, $fm->validation($_POST['commentId']));
  13.  
  14. if (!empty($name) && !empty($postComment)) {
  15. $commentQuery = "INSERT INTO `comment`(parent_id,comment,sender) VALUES('$commentId','$postComment','$name')";
  16. $commentsResult = $db->insert($commentQuery);
  17. if ($commentsResult) {
  18. $msg = "<p class='alert alert-success'><span class='fa-layers fa-fw'><i class='fas fa-check-circle fa-2x'></i></span>success</p>";
  19.  
  20. $status = array(
  21.  
  22. 'error' => 0,
  23. 'message' => $msg
  24.  
  25. );
  26. } else {
  27. $msg = "<p class='alert alert-danger'><i class='fas fa-times-circle fa-2x'></i>deny</p>";
  28.  
  29. $status = array(
  30. 'error' => 1,
  31. 'message' => $msg
  32. );
  33. }
  34. } else {
  35. $msg = "<p class='alert alert-warning'><i class='fas fa-bell fa-2x'> </i>empty field</p>";
  36.  
  37. $status = array(
  38. 'error' => 2,
  39. 'message' => $msg
  40. );
  41. }
  42.  
  43. echo json_encode($status);
  44. }
  45.  
  46. <?php
  47.  
  48. ini_set('memory_limit', '1024M');
  49. require_once __DIR__.'/../vendor/autoload.php';
  50. include __DIR__.'/../lib/Database.php';
  51. include __DIR__.'/../config/config.php';
  52. include __DIR__.'/../lib/Session.php';
  53. include __DIR__.'/../helpers/Format.php';
  54.  
  55. $db = new Database();
  56. $fm = new Format();
  57. $commentQuery = "SELECT * FROM `comment` WHERE `parent_id`='0' ORDER BY `id` DESC";
  58. $result = $db->select($commentQuery);
  59. $commentReply = '';
  60. if ($result) {
  61. while ($cmResult = $result->fetch_assoc()) {
  62. $commentReply .= ' <div class="panel panel-default">
  63. <div class="panel-heading">
  64. <div class="fa-2x text-right" style="border: none;">
  65. <button class=" btn btn-default delClick" id=" '.$cmResult['id'].'">
  66. <span class="fa-layers fa-fw" style="background:Mistyrose; border: none;">
  67. <i class="fa-inverse fas fa-times-circle" style="color: black;" data-fa-transform="shrink-3"> </i>
  68. </span>
  69. </button>
  70. </div>
  71. <h4>
  72. <span class= "fa-layers fa-fw">
  73. <i class="fa-inverse fas fa-user-graduate fa-3x" style=" background:MistyRose" >
  74. </i> </span> ' . $cmResult["sender"] . '
  75. </h4>
  76. <p class="date">' . $fm->DateFormat($cmResult["date"]) . '</p>
  77. </div>
  78. <div class="panel-body">
  79. <p class="comment">' . $fm->textShorten($cmResult["comment"], 70) . '</p>
  80. <button type="button" class="btn btn-warning reply" id="' . $cmResult["id"] . '">REPLY</button>
  81. </div>
  82. </div>';
  83. $commentReply .= getReply($db, $fm, $cmResult['id']);
  84. }
  85. echo $commentReply;
  86. }
  87. function getReply($db, $fm, $parentId = 0, $margin = 0) {
  88. //$fm = new Format();
  89. //$db = new Database();
  90. $commentReply = '';
  91. $getQuery = "SELECT * FROM `comment` WHERE `parent_id`='$parentId'";
  92. $result = $db->select($getQuery);
  93. // $count = mysqli_num_rows($result);
  94. if ($parentId == 0) {
  95. $margin = 0;
  96. } else {
  97. $margin = $margin + 28;
  98. }
  99. if (!empty($result) || $result > 0) {
  100. while ($cmResult = $result->fetch_assoc()) {
  101. // $fm =new Format();
  102. $cmDate = $fm->DateFormat($cmResult['date']);
  103. $shorten = $fm->textShorten($cmResult['comment'], 70);
  104. $commentReply .= ' <div class="panel_wrapper">
  105. <div class="panel panel-default" style="margin-left: '. $margin. 'px">
  106. <div class="panel-heading">
  107. <div class="fa-2x text-right" style="border: none;">
  108. <button class=" btn btn-default delClick" id=" '.$cmResult['id'].'">
  109. <span class="fa-layers fa-fw" style="background:Mistyrose; border: none;">
  110. <i class="fa-inverse fas fa-times-circle" style="color: black;" data-fa-transform="shrink-3">
  111. </i>
  112. </span>
  113. </button>
  114. </div>
  115. <h4>
  116. <span class="fa-layers fa-fw">
  117. <i class="fa-inverse fas fa-user-graduate fa-3x"
  118. data-fa-transform="shrink-8"
  119. style="background:MistyRose">
  120. </i>
  121. </span>
  122. '. $cmResult["sender"].'
  123. </h4>
  124. <p class="date">'.$cmDate.'</p>
  125. </div>
  126. <div class="panel-body">
  127. <p class="comment">'. $shorten.'</p>
  128. <button type="button" class="btn btn-warning reply" id="'. $cmResult['id'].'">
  129. REPLY
  130. </button>
  131. </div>
  132. </div>
  133. </div>';
  134. $commentReply .= getReply($db, $fm, $cmResult['id'], $margin);
  135. }
  136. }
  137. return $commentReply;
  138. }
  139.  
  140. $(document).ready(function(){
  141. //$('#all-comments').hide();
  142. showComments();
  143. $('#commentForm').on('submit', function(e){
  144. e.preventDefault();
  145. //showComments().disable();
  146. var formData = $(this).serialize();
  147. // var message = $('#Messages').val();
  148. $.ajax({
  149. url: "../scripts/comment.php",
  150. method: "POST",
  151. data:
  152. formData,
  153. dataType: "JSON",
  154. success:function(response) {
  155. if(!response.error) {
  156. $('#commentForm')[0].reset();
  157. $('#commentId').val('0');
  158. showComments();
  159. $('#message').show().fadeIn('500').html(response.message);
  160. $('#message').show().fadeOut('500').html(response.message);
  161. $('#message').show().fadeIn('500').html(response.message);
  162. $('#message').show().fadeOut('500').html(response.message);
  163.  
  164. }else if (response.error) {
  165. $('#message').show().fadeIn("500").html(response.message);
  166. $('#message').show().fadeOut("500").html(response.message);
  167. $('#message').show().fadeIn("500").html(response.message);
  168. $('#message').show().fadeOut("500").html(response.message);
  169. }
  170. }
  171. });
  172.  
  173.  
  174. //return false;
  175. });
  176. $(document).on('click','.reply', function(){
  177. var commentId = $(this).attr('id');
  178. $('#commentId').val(commentId);
  179. $('#name').focus();
  180. });
  181.  
  182. });
  183.  
  184. function showComments() {
  185. $.ajax({
  186. url:"../scripts/disqus.php",
  187. type:"POST",
  188. //dataType: "JSON",
  189. success:function(response) {
  190. // $('#all-comments').show();
  191. $('#showComments').html(response);
  192. }
  193. })
  194. }
  195.  
  196. <?php
  197.  
  198. //include __DIR__.'/../lib/Session.php';
  199. include __DIR__.'/../vendor/autoload.php';
  200. include __DIR__.'/../config/config.php';
  201. include __DIR__.'/../lib/Database.php';
  202.  
  203. $db = new Database();
  204.  
  205. $delQuery = "DELETE FROM comment WHERE parent_id= 0";
  206. $dResult = $db->delete($delQuery);
  207. /*echo "<pre>";
  208. var_dump($dResult);
  209. echo "</pre>";
  210. die();*/
  211. if ($dResult) {
  212. $msg = "<p class='alert alert-success'>
  213. <i class='fas fa-times-circle fa-2x'>
  214. </i>Comment deleted Successfully!!
  215. </p>";
  216. $status = array(
  217. 'error' => 3,
  218. 'message' => $msg
  219. );
  220. } else {
  221. $msg = "<p class='alert alert-info'>
  222. <i class='fas fa-warning-circle fa-2x'>
  223. </i>Comment cannot delete.
  224. </p>";
  225. $status = array(
  226. 'error' => 4,
  227. 'message' => $msg
  228. );
  229. }
  230.  
  231. echo json_encode($status);
  232.  
  233. $(document).on('click','.delClick',function (e) {
  234. e.preventDefault();
  235. // var delId = $(this).attr('id');
  236. deleteComment();
  237. window.location='../Template/Excellent.php';
  238.  
  239.  
  240. });
  241. function deleteComment()
  242. {
  243. // var data = $(this).attr('id');
  244. $.ajax({
  245. url:"../scripts/disqus_template.php",
  246. type: "POST",
  247. // data: data,
  248. dataType: "JSON",
  249. success: function (response) {
  250. if(!response.error) {
  251. $('#delmessage').html(response);
  252. $('#delmessage').fadeIn('slow').html(response.message);
  253.  
  254. }
  255. }
  256.  
  257. });
  258. return false;
  259. }
Add Comment
Please, Sign In to add comment