Mini Shell
<?php
include("../config.php");
$conn = dbconnect();
// error_reporting(0);
error_reporting(E_ALL); // Show all errors
ini_set('display_errors', 1); // Display errors on the screen
date_default_timezone_set('Asia/Kolkata');
session_start();
$admin_id = $_SESSION['admin_id'];
$today = date('Y-m-d H:i:s');
$type = $_POST['type'];
if ($type == 'add') {
// Check if all required POST variables are set
$course_name = isset($_POST['course_name']) ? mysqli_real_escape_string($conn, $_POST['course_name']) : '';
$status = isset($_POST['status']) ? $_POST['status'] : '';
$duration = isset($_POST['duration']) ? mysqli_real_escape_string($conn, $_POST['duration']) : '';
$para1 = isset($_POST['para1']) ? mysqli_real_escape_string($conn, $_POST['para1']) : '';
$para2 = isset($_POST['para2']) ? mysqli_real_escape_string($conn, $_POST['para2']) : '';
$career_prospect_para = isset($_POST['career_prospect_para']) ? mysqli_real_escape_string($conn, $_POST['career_prospect_para']) : '';
$career_prospect_content = isset($_POST['career_prospect_content']) ? mysqli_real_escape_string($conn, $_POST['career_prospect_content']) : '';
$study_post_para = isset($_POST['study_post_para']) ? mysqli_real_escape_string($conn, $_POST['study_post_para']) : '';
$study_post_content = isset($_POST['study_post_content']) ? mysqli_real_escape_string($conn, $_POST['study_post_content']) : '';
$short_name = isset($_POST['short_name']) ? mysqli_real_escape_string($conn, $_POST['short_name']) : '';
$new_file_name1 = isset($_FILES["files"]["name"]) ? $_FILES["files"]["name"] : '';
$new_file_name2 = isset($_FILES["syllabus"]["name"]) ? $_FILES["syllabus"]["name"] : '';
$new_file_name3 = isset($_FILES["labimage"]["name"]) ? $_FILES["labimage"]["name"] : '';
$url_query = "SELECT * FROM tb1_url WHERE url_title='courses'";
$res_url = mysqli_query($conn, $url_query);
$fetch_url = mysqli_fetch_object($res_url);
$url_path = $fetch_url->url_path;
$filepath = '../' . $url_path;
if (!empty($new_file_name3)) {
// Get the original file name
$new_file_name3 = $_FILES["labimage"]["name"];
// Remove spaces from the file name
$new_file_name3 = str_replace(' ', '_', $new_file_name3);
// Add current date and time to the file name
$date_time = date('Ymd_His');
$file_extension = pathinfo($new_file_name3, PATHINFO_EXTENSION);
$file_name_without_extension = pathinfo($new_file_name3, PATHINFO_FILENAME);
$new_file_name3 = $file_name_without_extension . '_' . $date_time . '.' . $file_extension;
// Generate the target path
$target_path3 = $filepath . '/' . basename($new_file_name3);
// Move the uploaded file
move_uploaded_file($_FILES['labimage']['tmp_name'], $target_path3);
} else {
$new_file_name3 = '';
}
if (!empty($new_file_name2)) {
$new_file_name2 = $_FILES["syllabus"]["name"];
$target_path2 = $filepath . '/' . basename($new_file_name2);
move_uploaded_file($_FILES['syllabus']['tmp_name'], $target_path2);
}
if (!empty($new_file_name1)) {
$new_file_name1 = $_FILES["files"]["name"];
$lname1 = "course";
$emrand1 = $lname1 . rand(1000, 2000);
$fileType1 = $_FILES["files"]["type"];
$str1 = explode("/", $fileType1);
$new_file_name1 = $emrand1 . '.' . $str1[1];
$target_path1 = $filepath . '/' . basename($new_file_name1);
move_uploaded_file($_FILES['files']['tmp_name'], $target_path1);
$sql = "INSERT INTO tb1_pgcourses(course_name,short_name,course_img,lab_image,para1,para2,career_prospect_para,career_prospect_content,study_post_para,study_post_content,duration,syllabus,status,crm_id,updated_log,created_log) VALUES ('$course_name','$short_name','$new_file_name1','$new_file_name3','$para1','$para2','$career_prospect_para','$career_prospect_content','$study_post_para','$study_post_content','$duration','$new_file_name2','$status','$admin_id','$today','$today')";
$content_res = mysqli_query($conn, $sql);
$code = 'done';
} else {
$sql = "INSERT INTO tb1_pgcourses(course_name,course_img,lab_image,short_name,para1,para2,career_prospect_para,career_prospect_content,study_post_para,study_post_content,duration,syllabus,status,crm_id,updated_log,created_log) VALUES ('$course_name','$short_name','','$new_file_name3','$para1','$para2','$career_prospect_para','$career_prospect_content','$study_post_para','$study_post_content','$duration','$new_file_name2','$status','$admin_id','$today','$today')";
$content_res = mysqli_query($conn, $sql);
$code = 'done';
}
} else if ($type == 'update') {
$subcourse_id = $_POST['subcourse_id'];
$course_name = isset($_POST['course_name']) ? mysqli_real_escape_string($conn, $_POST['course_name']) : '';
$status = isset($_POST['status']) ? $_POST['status'] : '';
$duration = isset($_POST['duration']) ? mysqli_real_escape_string($conn, $_POST['duration']) : '';
$para1 = isset($_POST['para1']) ? mysqli_real_escape_string($conn, $_POST['para1']) : '';
$para2 = isset($_POST['para2']) ? mysqli_real_escape_string($conn, $_POST['para2']) : '';
$career_prospect_para = isset($_POST['career_prospect_para']) ? mysqli_real_escape_string($conn, $_POST['career_prospect_para']) : '';
$career_prospect_content = isset($_POST['career_prospect_content']) ? mysqli_real_escape_string($conn, $_POST['career_prospect_content']) : '';
$study_post_para = isset($_POST['study_post_para']) ? mysqli_real_escape_string($conn, $_POST['study_post_para']) : '';
$study_post_content = isset($_POST['study_post_content']) ? mysqli_real_escape_string($conn, $_POST['study_post_content']) : '';
$new_file_name1 = isset($_FILES["files"]["name"]) ? $_FILES["files"]["name"] : '';
$short_name = isset($_POST['short_name']) ? mysqli_real_escape_string($conn, $_POST['short_name']) : '';
$new_file_name2 = isset($_FILES["syllabus"]["name"]) ? $_FILES["syllabus"]["name"] : '';
$new_file_name3 = isset($_FILES["labimage"]["name"]) ? $_FILES["labimage"]["name"] : '';
$url_query = "SELECT * FROM tb1_url WHERE url_title='courses'";
$res_url = mysqli_query($conn, $url_query);
$fetch_url = mysqli_fetch_object($res_url);
$url_path = $fetch_url->url_path;
$filepath = '../' . $url_path;
if (!empty($new_file_name3)) {
$new_file_name3 = $_FILES["labimage"]["name"];
$target_path3 = $filepath . '/' . basename($new_file_name3);
move_uploaded_file($_FILES['labimage']['tmp_name'], $target_path3);
} else {
$new_file_name3 = '';
}
if (!empty($new_file_name2)) {
$new_file_name2 = $_FILES["syllabus"]["name"];
$target_path2 = $filepath . '/' . basename($new_file_name2);
move_uploaded_file($_FILES['syllabus']['tmp_name'], $target_path2);
} else {
$new_file_name2 = '';
}
if (!empty($new_file_name1)) {
$new_file_name1 = $_FILES["files"]["name"];
$lname1 = "course";
$emrand1 = $lname1 . rand(1000, 2000);
$fileType1 = $_FILES["files"]["type"];
$str1 = explode("/", $fileType1);
$new_file_name1 = $emrand1 . '.' . $str1[1];
$target_path1 = $filepath . '/' . basename($new_file_name1);
move_uploaded_file($_FILES['files']['tmp_name'], $target_path1);
$sql = "UPDATE tb1_pgcourses SET course_name='$course_name',short_name='$short_name',course_img='$new_file_name1',para1='$para1',para2='$para2',career_prospect_para='$career_prospect_para',career_prospect_content='$career_prospect_content',study_post_para='$study_post_para',study_post_content='$study_post_content',duration='$duration',syllabus='$new_file_name2',status='$status',crm_id='$admin_id',updated_log='$today' WHERE course_id='$subcourse_id'";
$content_res = mysqli_query($conn, $sql);
if (!empty($new_file_name3)) {
$sql = "UPDATE tb1_pgcourses SET course_name='$course_name',short_name='$short_name',course_img='$new_file_name1',lab_image='$new_file_name3',para1='$para1',para2='$para2',career_prospect_para='$career_prospect_para',career_prospect_content='$career_prospect_content',study_post_para='$study_post_para',study_post_content='$study_post_content',duration='$duration',syllabus='$new_file_name2',status='$status',crm_id='$admin_id',updated_log='$today' WHERE course_id='$subcourse_id'";
$content_res = mysqli_query($conn, $sql);
}
$code = 'done';
} else {
$sql = "UPDATE tb1_pgcourses SET course_name='$course_name',short_name='$short_name',para1='$para1',para2='$para2',career_prospect_para='$career_prospect_para',career_prospect_content='$career_prospect_content',study_post_para='$study_post_para',study_post_content='$study_post_content',duration='$duration',syllabus='$new_file_name2',status='$status',crm_id='$admin_id',updated_log='$today' WHERE course_id='$subcourse_id'";
$content_res = mysqli_query($conn, $sql);
$code = 'done';
}
}
echo json_encode($code);
Zerion Mini Shell 1.0