HEX
Server: Apache
System: Linux sg2plmcpnl492417.prod.sin2.secureserver.net 4.18.0-553.58.1.lve.el8.x86_64 #1 SMP Fri Jul 4 12:07:06 UTC 2025 x86_64
User: nyiet8349bzl (9207396)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: /home/nyiet8349bzl/www/oldwebsite.sbsc.in/faculty/dashboard/save.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

include "../config/database.php";

/* ======================
   TEACHER SESSION CHECK
====================== */
if (
    !isset($_SESSION['teacher_logged_in']) ||
    $_SESSION['teacher_logged_in'] !== true ||
    !isset($_SESSION['teacher_id'])
) {
    header("Location: ../login");
    exit;
}

$teacher_id = $_SESSION['teacher_id'];

/* ======================
   BASIC PROFILE UPDATE
====================== */
$name        = trim($_POST['name']);
$designation = trim($_POST['designation']);
$department  = trim($_POST['department']);
$phone       = trim($_POST['phone']);

$slug      = strtolower(preg_replace('/[^a-z0-9]+/i', '-', $name));
$dept_slug = strtolower(preg_replace('/[^a-z0-9]+/i', '-', $department));

/* ======================
   PHOTO UPLOAD
====================== */
$photo_path = null;

if (!empty($_FILES['photo']['name'])) {
    $ext = pathinfo($_FILES['photo']['name'], PATHINFO_EXTENSION);
    $photo_path = "uploads/photos/" . $slug . "." . $ext;
    move_uploaded_file(
        $_FILES['photo']['tmp_name'],
        "../" . $photo_path
    );
}

/* ======================
   UPDATE TEACHER TABLE
====================== */
if ($photo_path) {
    $stmt = $conn->prepare("
        UPDATE teachers
        SET name=?, slug=?, designation=?, department=?, dept_slug=?, phone=?, photo=?
        WHERE id=?
    ");
    $stmt->bind_param(
        "sssssssi",
        $name, $slug, $designation, $department, $dept_slug, $phone, $photo_path, $teacher_id
    );
} else {
    $stmt = $conn->prepare("
        UPDATE teachers
        SET name=?, slug=?, designation=?, department=?, dept_slug=?, phone=?
        WHERE id=?
    ");
    $stmt->bind_param(
        "ssssssi",
        $name, $slug, $designation, $department, $dept_slug, $phone, $teacher_id
    );
}

$stmt->execute();
$stmt->close();

/* ======================
   EDUCATION SAVE
====================== */
$conn->query("DELETE FROM teacher_education WHERE teacher_id = $teacher_id");

if (!empty($_POST['degree'])) {
    foreach ($_POST['degree'] as $i => $deg) {

        if (empty($deg)) continue;

        $inst = $_POST['institution'][$i];
        $year = $_POST['year'][$i];

        $stmt = $conn->prepare("
            INSERT INTO teacher_education
            (teacher_id, degree, institution, year)
            VALUES (?,?,?,?)
        ");
        $stmt->bind_param(
            "isss",
            $teacher_id, $deg, $inst, $year
        );
        $stmt->execute();
        $stmt->close();
    }
}

/* ======================
   FELLOWSHIP SAVE
====================== */
$conn->query("DELETE FROM teacher_fellowship WHERE teacher_id = $teacher_id");

if (!empty($_POST['title'])) {
    foreach ($_POST['title'] as $i => $title) {

        if (empty($title)) continue;

        $body  = $_POST['body'][$i];
        $level = $_POST['level'][$i];

        $stmt = $conn->prepare("
            INSERT INTO teacher_fellowship
            (teacher_id, title, body, level)
            VALUES (?,?,?,?)
        ");
        $stmt->bind_param(
            "isss",
            $teacher_id, $title, $body, $level
        );
        $stmt->execute();
        $stmt->close();
    }
}

/* ======================
   REDIRECT BACK
====================== */
header("Location: index.php?saved=1");
exit;