JezK
Edit File: functions.php
<?php // Include database connection file require_once 'db_connection.php'; // Function to insert complaint into database function insertComplaint($grievanceCategory, $studentRollNumber, $name, $email, $message) { global $conn; // Assuming $conn is your database connection variable // Prepare SQL statement to insert data $sql = "INSERT INTO complaints (grievanceCategory, studentRollNumber, name, email, message) VALUES (?, ?, ?, ?, ?)"; $stmt = $conn->prepare($sql); // Bind parameters and execute the statement $stmt->bind_param("sssss", $grievanceCategory, $studentRollNumber, $name, $email, $message); $result = $stmt->execute(); if ($result) { // Send email notification to admin $adminEmail = 'nagesh@krify.com'; // Admin's email address $subject = 'New Complaint Submitted'; $body = "A new complaint has been submitted:\n\nCategory: $grievanceCategory\nRoll Number: $studentRollNumber\nName: $name\nEmail: $email\nMessage: $message"; // Send email using Sendinblue API sendEmail($adminEmail, $subject, $body); return $result; } else { return false; } } function saveStudentData($studentName, $rollNo, $email, $programmeName, $academicYear) { global $conn; // Assuming $conn is your database connection variable // Prepare SQL statement to insert data $sql = "INSERT INTO studentcomplaint (studentName, rollNo, email, programmeName, academicYear, created_time) VALUES (?, ?, ?, ?, ?, NOW())"; // NOW() will insert the current timestamp $stmt = $conn->prepare($sql); // Bind parameters and execute the statement $stmt->bind_param("sssss", $studentName, $rollNo, $email, $programmeName, $academicYear); $result = $stmt->execute(); // Return true if data saving was successful, false otherwise return $result; } // function sendEmail($to, $subject, $body) { // $apiKey = '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'; // Your Sendinblue API key // $url = 'https://api.sendinblue.com/v3/smtp/email'; // // Prepare email data // $data = array( // 'sender' => array('email' => 'nagesh@krify.com'), // 'to' => array(array('email' => $to)), // 'subject' => $subject, // 'htmlContent' => nl2br($body) // ); // // Convert data to JSON // $jsonData = json_encode($data); // // Send request to Sendinblue API // $ch = curl_init($url); // curl_setopt($ch, CURLOPT_POST, true); // curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); // curl_setopt($ch, CURLOPT_HTTPHEADER, array( // 'Content-Type: application/json', // 'api-key: ' . $apiKey // )); // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // $response = curl_exec($ch); // curl_close($ch); // // Check if email was sent successfully // if ($response) { // return true; // } else { // return false; // } // } function saveTeacherComplaintData($teacherName, $department, $email, $programmeName, $academicYear) { global $conn; // Assuming $conn is your database connection variable // Prepare SQL statement to insert data $sql = "INSERT INTO teacher_complaints (teacherName, department, email, programmeName, academicYear, created_time) VALUES (?, ?, ?, ?, ?, NOW())"; // NOW() will insert the current timestamp $stmt = $conn->prepare($sql); // Bind parameters and execute the statement $stmt->bind_param("sssss", $teacherName, $department, $email, $programmeName, $academicYear); $result = $stmt->execute(); // Return true if data saving was successful, false otherwise return $result; } ?>