Skip to content

Commit

Permalink
Q&A board system tested but cannot answer
Browse files Browse the repository at this point in the history
  • Loading branch information
annibuliful committed Jan 7, 2017
1 parent 0e56717 commit 879234f
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 18 deletions.
46 changes: 30 additions & 16 deletions backend/DB/feature/co_module.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);
class co_func
{
Expand All @@ -15,11 +16,12 @@ public function __construct()
}
public function list_preview(string $id_playlist)
{
$sql = $this->sql->prepare('SELECT id_video,description FROM course
$sql = $this->sql->prepare('SELECT id_video,description FROM course
WHERE id_playlist = :id_playlist AND flag_num =2 ;');
$sql->bindParam(':id_playlist',$id_playlist,PDO::PARAM_STR);
$sql->execute();
return (array)$sql->fetchAll(PDO::FETCH_ASSOC);
$sql->bindParam(':id_playlist', $id_playlist, PDO::PARAM_STR);
$sql->execute();

return (array) $sql->fetchAll(PDO::FETCH_ASSOC);
}
public function list_comment(string $id_post)
{
Expand Down Expand Up @@ -70,46 +72,58 @@ public function comment_course(string $id_user, string $comment = null, string $

return false;
}
public function comment_board(int $id_user, string $comment, string $id_post)
public function comment_board(int $id_user, string $head, string $comment, string $id_post)
{
$sql = $this->sql->prepare('SELECT image,name FROM user WHERE id = :id_user');
$sql->bindParam(':id_user', $id_user, PDO::PARAM_STR);
$sql->execute();
$fetch = $sql->fetch(PDO::FETCH_ASSOC);
if ($fetch) {
$sql = $this->sql->prepare('SELECT id_post,id_N,flag FROM comment WHERE id_post = :id_post ;');
$fetch1 = $sql->fetch(PDO::FETCH_ASSOC);
if ($fetch1) {
$sql = $this->sql->prepare('SELECT id_playlist,id_N FROM qanda WHERE id_playlist = :id_playlist ;');
$sql->bindParam(':id_playlist', $id_post, PDO::PARAM_STR);
$sql->execute();
$fetch = $sql->fetch(PDO::FETCH_ASSOC);
if ($fetch) {
$id_N = (int) $fetch['id_N'] + 1;
$sql = $this->sql->prepare('INSERT INTO comment VALUES (:id_post ,:id_N ,:comment ,
:id_user,:name,:image ,2 ) ;');
$sql = $this->sql->prepare('INSERT INTO qanda VALUES (:id_post ,:id_N ,:id_user ,:head
,:comment,:name,:image ) ;');
$sql->bindParam(':id_post', $id_post, PDO::PARAM_STR);
$sql->bindParam(':id_N', $id_N, PDO::PARAM_INT);
$sql->bindParam(':head', $head, PDO::PARAM_STR);
$sql->bindParam(':comment', $comment, PDO::PARAM_STR);
$sql->bindParam(':id_user', $id_user, PDO::PARAM_INT);
$sql->bindParam(':name', $fetch['name'], PDO::PARAM_STR);
$sql->bindParam(':image', $fetch['image'], PDO::PARAM_STR);
$sql->bindParam(':name', $fetch1['name'], PDO::PARAM_STR);
$sql->bindParam(':image', $fetch1['image'], PDO::PARAM_STR);
$sql->execute();

return true;
} else {
$sql = $this->sql->prepare('INSERT INTO comment VALUES (:id_post ,1,:comment ,
:id_user ,:name,:image ,2 ) ;');
$sql = $this->sql->prepare('INSERT INTO qanda VALUES (:id_post ,1 ,:id_user ,:head
,:comment ,:name,:image ) ;');
$sql->bindParam(':id_post', $id_post, PDO::PARAM_STR);
$sql->bindParam(':head', $head, PDO::PARAM_STR);
$sql->bindParam(':comment', $comment, PDO::PARAM_STR);
$sql->bindParam(':id_user', $id_user, PDO::PARAM_INT);
$sql->bindParam(':name', $fetch['name'], PDO::PARAM_STR);
$sql->bindParam(':image', $fetch['image'], PDO::PARAM_STR);
$sql->bindParam(':name', $fetch1['name'], PDO::PARAM_STR);
$sql->bindParam(':image', $fetch1['image'], PDO::PARAM_STR);
$sql->execute();


return true;
}
}

return false;
}
public function list_comment_board(string $id_playlist)
{
$sql = $this->sql->prepare('SELECT name,image,comment,head FROM qanda WHERE id_playlist = :id_playlist
AND id_N = 1;');
$sql->bindParam(':id_playlist', $id_playlist, PDO::PARAM_STR);
$sql->execute();

return $sql->fetchAll(PDO::FETCH_ASSOC);
}
public function rating(int $id_user, string $id_question = null, string $id_playlist = null)
{
if ($id_question != null) {
Expand Down
18 changes: 18 additions & 0 deletions backend/util/controller/co_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@ public function __construct()
$this->co = new co_func();
$this->view = new co_view();
}
public function comment_board(int $id_user, string $head ,string $comment, string $id_post)
{
$check = $this->co->comment_board($id_user,$head,$comment,$id_post);
if ($check == true) {
echo "สร้างข้อสงสัยเรียบร้อย";
}elseif ($check == false) {
echo "<h1 style=\"color:red;\">เกิดปัญหาการสร้างข้อสงสัยโปรดลองใหม่ภายหลัง</h1>";
}
}
public function list_comment_board(string $id_playlist)
{
$check = $this->co->list_comment_board($id_playlist);
if ($check != null && gettype($check) == 'array') {
$this->view->list_comment_board($check);
}else {
echo "";
}
}
public function list_preview(string $id_playlist)
{
$check = $this->co->list_preview($id_playlist);
Expand Down
14 changes: 14 additions & 0 deletions backend/util/view/co_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,18 @@ public function list_preview(array $detail)
";
}
}
public function list_comment_board(array $data)
{
for ($i=0; $i <count($data) ; $i++) {
echo "<div class=\"media\">
<a class=\"pull-left\" href=\"#\"><img class=\"img-circle\" src=\"store/pictures/{$data[$i]['image']}\" style=\"width:80px;height:80px\"></a>
<div class=\"media-body\">
<font size=\"5\" style=\"font-weight:bold\">{$data[$i]['name']}</font>
<font size=\"8\" style=\"font-weight:bold;margin-left:50px\">{$data[$i]['head']}</font>
<font style=\"font-size:18;background-color:#25c0d0\">{$data[$i]['comment']}</font>
</div>
<button class=\"btn btn-info btn-lg\" style=\"maring-left: 70%\">ตอบข้อสงสัย</button>
</div><br><br>";
}
}
}
1 change: 1 addition & 0 deletions backend/util/view/student_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function list_course(array $list, $id_user)
<a href=\"video.php?id_course={$list[$i]['course_id']}&id_user={$id_user}\"><img src=\"button/video.png\" width=\"50\"></a>
<a href=\"exercise.php?id_course={$list[$i]['course_id']}\"><img src=\"button/exercise.png\" width=\"50\"></a>
<a href=\"exam.php?id_course={$list[$i]['course_id']}\"><img src=\"button/quiz.png\" width=\"50\"></a>
<a href=\"board.php?id_course={$list[$i]['course_id']}\"><img src=\"button/board.png\" width=\"50\"></a>
</div>
</div>
</li>";
Expand Down
Binary file added frontend/Button/board.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 95 additions & 0 deletions frontend/board.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php session_start();
require 'C:/Users/Dell/Documents/GitHub/robruu/backend/util/controller/co_controller.php';
$comment = new co_controller();
if (isset($_POST['head'])) {
$comment->comment_board($_SESSION['id'], $_POST['head'] ,$_POST['comment'], $_POST['id_playlist']);
}
?>
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<link rel="stylesheet" href="lib/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="lib/bootstrap/css/bootstrap.min.css">
<script type="text/javascript" src="lib/jquery.js"></script>
<script type="text/javascript" src="lib/bootstrap/js/bootstrap.min.js"></script>
<link href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<script src="http://cdn.ckeditor.com/4.6.0/standard-all/ckeditor.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});
</script>
<script type="text/javascript" async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML">
</script>

<style>
@font-face {
font-family: thaisan;
src: url(thaisanslite_r1.ttf);
}

* {
font-family: thaisan;
!important;
}
</style>
</head>

<body>
<script src="http://cdn.ckeditor.com/4.6.0/standard-all/ckeditor.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});
</script>
<div class="navbar navbar-default navbar-static-top" style="background-color:#ff630a">
<div class="navbar-header"></div>
<div class="collapse navbar-collapse" id="navbar-ex-collapse">
<div class="container">

<div class="col-md-12">
<form class="navbar-form" action="buy.php" method="post">
<div class="input-group">
<input type="text" name="course_name" class="form-control" placeholder="ค้นหาบทเรียน">
<div class="input-group-btn">
<button class="btn btn" type="button">
<span class="glyphicon glyphicon-search"></span>
<i class="icon-search"></i>
</button>
</div>
</div>
</form>

</div>
</div>
</div>
</div>
<div class="container">
<form class="" action="" method="post">
<div class="form-group">
<label for=""><h3>หัวข้อ</h3></label>
<input type="text" class="form-control" name="head" value="">
</div>
<input type="hidden" name="id_playlist" value="<?php echo $_GET['id_course'];?>">
<textarea rows="4" cols="8" id="editor1" name="comment">
</textarea>
<input type="submit" class="btn btn-primary btn-default" name="submit" value="สร้าง">
</div>

<script>
var editor = CKEDITOR.replace('editor1', {
extraPlugins: 'mathjax',
mathJaxLib: 'http://cdn.mathjax.org/mathjax/2.6-latest/MathJax.js?config=TeX-AMS_HTML',
height: 100,
width: 1000
});
</script>
</form>
<?php
if (isset($_GET['id_course'])) {
$comment->list_comment_board($_GET['id_course']);
}else {
header('location: main.php');
}
?>
</body>

</html>
5 changes: 3 additions & 2 deletions frontend/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
<script type="text/javascript" src="lib/jquery.js"></script>
<script type="text/javascript" src="lib/bootstrap/js/bootstrap.min.js"></script>
<link href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<script type="text/javascript" async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML">
</script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});
</script>
<script type="text/javascript" async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML">
</script>

<style>
@font-face {
font-family: thaisan;
Expand Down

0 comments on commit 879234f

Please sign in to comment.