ok

Mini Shell

Direktori : /home2/selectio/www/tnpsctestbatch.com/api/
Upload File :
Current File : /home2/selectio/www/tnpsctestbatch.com/api/comment.php

<?php 
ob_start();
session_start();
include "../config/config.php";
$session_id = $_SESSION['user_exam']['id'];
    
    
    if($_POST['type']=="comment"){
        
        
        
     $exam_type =  $_POST['exam_type'];
     $user_comment =  $_POST['user_commet'];
     $user_id =  $_POST['user_id']; 
     $question_id =  $_POST['questions_id'];


        $statements = $pdo->prepare("INSERT INTO `tbl_mock_test_comment` (`user_id`, `question_id`, `exam_type`, `comment`) VALUES (?,?,?,?)");
        $results=$statements->execute(array($user_id,$question_id,$exam_type,$user_comment)); 


		if($results){
		    $response['message']='Your Comment added Successfully';
		    $response['status']=100;
		}else{
		    $response['message']=300;
		    $response['status']='Somethign went wrong try again';
		}
		
		echo json_encode($response);
 
}




 if($_POST['type']=="fetch_comments"){
     
     $dats='';
     
        $comment_sql = $pdo->prepare("SELECT tbl_mock_test_comment.*,tbl_mock_test_comment.id AS comment_id,tbl_students.* FROM tbl_mock_test_comment INNER 
        JOIN tbl_students ON tbl_mock_test_comment.user_id = tbl_students.id WHERE tbl_mock_test_comment.status=1 ORDER BY tbl_mock_test_comment.id DESC");
		$comment_sql->execute(array());
		$comment_result = $comment_sql->fetchAll(PDO::FETCH_ASSOC);
		$comment_total=$comment_sql->rowCount();
		
		if($comment_total>0){
		    
		    foreach($comment_result as $comment_datas){
		        $comment_datas['created_at'];
		        
		        $dats.='<div class="commented-section mt-2" style="border-bottom: 2px solid red;">
                    <div class="d-flex flex-row align-items-center commented-user">
                        <h5 class="mr-2">'.$comment_datas["name"] . ' </h5><span class="dot mb-1"></span><span class="mb-1 ml-2" style="margin-left: 10px;"> '.date('d-m-Y', strtotime($comment_datas["created_at"])).'</span></div>
                    <div class="comment-text-sm"><span>'.$comment_datas["comment"] . '</span></div>
                    <span style="padding: 3px;font-size: 12px;margin-bottom: 10px;background-color: red;border: red;" title="Delete Comment" class="btn btn-primary btn-xs active" onclick="deletecommet('.$comment_datas["comment_id"] . ')"> <i class="bi bi-trash"></i> </span>                </div>';
		        
		    }
		   
		}else{
		    $dats.='<span> No Comments </span>';
		}
     

		if($dats){
		    $response['comments_list']=$dats;
		    $response['error']=1;
		}else{
		    $response['error']=0;
		    $response['correct_ans']='correct_answer';
		}
		
		echo json_encode($response);
 
}

if($_POST['type']=="questions_with_comment"){
    
    $question_id = $_POST['question_id'];
    
    
     
     $dats='';
     
     error_log("SELECT tbl_mock_test_comment.*,tbl_mock_test_comment.id AS comment_id,tbl_students.* FROM tbl_mock_test_comment INNER 
            JOIN tbl_students ON tbl_mock_test_comment.user_id = tbl_students.id WHERE tbl_mock_test_comment.exam_type=3 AND tbl_mock_test_comment.status=1 and tbl_mock_test_comment.question_id=$question_id ORDER BY tbl_mock_test_comment.id DESC");
     
        $comment_sql = $pdo->prepare("SELECT tbl_mock_test_comment.*,tbl_mock_test_comment.id AS comment_id,tbl_students.* FROM tbl_mock_test_comment INNER 
            JOIN tbl_students ON tbl_mock_test_comment.user_id = tbl_students.id WHERE tbl_mock_test_comment.exam_type=3 AND tbl_mock_test_comment.status=1 and tbl_mock_test_comment.question_id=? ORDER BY tbl_mock_test_comment.id DESC");
		$comment_sql->execute(array($question_id));
		$comment_result = $comment_sql->fetchAll(PDO::FETCH_ASSOC);
		$comment_total=$comment_sql->rowCount();
		
		if($comment_total>0){
		    
		    foreach($comment_result as $comment_datas){
		        $comment_datas['created_at'];

                 $dats.='<div class="commented-section mt-2" style="border-bottom: 2px solid red;">
                    <div class="d-flex flex-row align-items-center commented-user">
                        <h5 class="mr-2">'.$comment_datas["name"] . ' </h5><span class="dot mb-1"></span><span class="mb-1 ml-2" style="margin-left: 10px;"> '.date('d-m-Y', strtotime($comment_datas["created_at"])).'</span></div>
                    <div  class="comment-text-sm"><span>'.$comment_datas["comment"] . '</span></div>';
               
                    if(isset($session_id) && $session_id==$comment_datas['user_id']){
                        
                $dats.='<span style="padding: 3px;font-size: 12px;margin-bottom: 10px;background-color: red;border: red;" title="Delete Comments" class="btn btn-primary btn-xs active" onclick="deletecommet('.$comment_datas["comment_id"] . ', '.$question_id.')"> <i class="bi bi-trash"></i> </span>  ';
                    }
                $dats.='</div>';
		        
		    }
		   
		}else{
		    $dats.='<span> No Comments </span>';
		}
     

        echo $dats;
 
}


   
    if($_POST['type']=="delete_commet"){
        
        
        
     $id =  $_POST['id'];


        $statements = $pdo->prepare("DELETE FROM `tbl_mock_test_comment` WHERE id=?");
        $results=$statements->execute(array($id)); 


		if($results){
		    $response['message']='Your Comment Deleted Successfully';
		    $response['status']=100;
		}else{
		    $response['message']=300;
		    $response['status']='Somethign went wrong try again';
		}
		
		echo json_encode($response);
 
}


?>

Zerion Mini Shell 1.0