HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ip-172-31-18-78 6.17.0-1017-aws #17~24.04.1-Ubuntu SMP Tue May 26 21:09:53 UTC 2026 aarch64
User: ubuntu (1000)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: /var/www/nclive/technc/add_exam_category.php
<?php include 'header.php';

include '../wp-config.php';

// domain for creating post page
$host = $_SERVER['SERVER_NAME'];

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

$curDateTime = date('Y-m-d H:i:s');
$user_id = 1;
$message = '';  // for displaying error and success msgs

// table names
$POST_TABLE = 'naukri_wp_posts';
$TABLE_POSTMETA = 'naukri_wp_postmeta';
$TABLE_YOAST_INDEXABLE = 'naukri_wp_yoast_indexable';
$EXAM_CATEGORY = "sp_exam_category";

include('function.php');  // to make new post page

// function yoastCall($obj_id, $title)
// {
//     $yoast_indexables_update = $GLOBALS['wpdb']->update(
//         $GLOBALS['wpdb']->prefix . 'yoast_indexable',
//         array('title' => $title),
//         array(
//             'object_id'       => $obj_id,
//             'object_sub_type' => 'page',
//         )
//     );
// }


// to get extension of uploaded image
function getExtension($str)
{
    $i = strrpos($str, ".");
    if (!$i) {
        return "";
    }
    $l = strlen($str) - $i;
    $ext = substr($str, $i + 1, $l);
    return $ext;
}

// submit data to add exam category
if (isset($_REQUEST['submit'])) {
    // print_r($_REQUEST);  print_r($_FILES);echo "<br/>";
    $exm = $_REQUEST['exm_name'];
    $heading = $_REQUEST['heading'];
    $slug = $_REQUEST['post_slug'];
    $shortcode = $_REQUEST['shortcode'];
    $order = $_REQUEST['num'];
    $full = $_REQUEST['full'];
    $stat = $_REQUEST['status'];
    $type = $_REQUEST['type'];
    $post_parent = 0;

    $meta_title = $_REQUEST['metaTitle'];
    $meta_key = $_REQUEST['metafkeyword'];
    $meta_keyword = $_REQUEST['metaKeyword'];
    $meta_desc = $_REQUEST['metaDesc'];

    $post_title = $exm;
    $post_content = $shortcode;
    $post_name = $slug;

    if (empty($exm)) {
        $message = '<div class="alert alert-danger "><strong>Category Name Required.</strong></div>';
    } else if (empty($slug)) {
        $message = '<div class="alert alert-danger "><strong>Url SLug Email Required.</strong></div>';
    } else if (empty($shortcode)) {
        $message = '<div class="alert alert-danger "><strong>Shortcode Required.</strong></div>';
    } else if (empty($order)) {
        $message = '<div class="alert alert-danger "><strong>Order Required.</strong></div>';
    } elseif (empty($full)) {
        $message = '<div class="alert alert-danger "><strong>Exams Full Name Required.</strong></div>';
    } else if (empty($stat)) {
        $message = '<div class="alert alert-danger "><strong>Select Status.</strong></div>';
    } else if (empty($type)) {
        $message = '<div class="alert alert-danger "><strong>Select Exam Type.</strong></div>';
    } else if ($_FILES['exam_img']['name'] == '') {
        $message = '<div class="alert alert-danger "><strong>Select Image Icon.</strong></div>';
    } else {
        if (($_FILES["exam_img"]["size"] > 0)) {
            $fileName = $_FILES['exam_img']['name'];
            $fileSize = $_FILES['exam_img']['size'];
            $ext = strtolower(getExtension($fileName));
            $allowed_ext = ['jpg', 'jpeg', 'png','JPG', 'JPEG', 'PNG'];

            if (in_array($ext, $allowed_ext) === false) {
                $message = '<div class="alert alert-danger"><strong><h5>Please choose JPG,JPEG,PNG file,hence error on this file upload: '.$fileName.' </h5></strong></div>';
            } else if ($fileSize > 204800) {
                $message = '<div class="alert alert-danger"><strong>Please upload file upto 200 KB only.</strong></div>';
            } else {
                // to check whether post name exist or not
                $exist_page = $db->prepare("SELECT count(ID) as countId FROM $POST_TABLE WHERE post_name = '" . $post_name . "' AND post_status='publish'");
                $exist_page->execute();
                $check_page = $exist_page->fetch(PDO::FETCH_ASSOC);

                if ($check_page['countId'] == 0) {
                    $post_id = createPostPages($post_title, $post_content, $post_name, $user_id, $post_parent, $host);

                    // yoast seo data table and post meta
                    if ($post_id != '') {
                        update_post_meta($post_id, '_yoast_wpseo_title', $meta_title);
                        update_post_meta($post_id, '_yoast_wpseo_focuskw', $meta_key);
                        update_post_meta($post_id, '_yoast_wpseo_metadesc', $meta_desc);
                        update_post_meta($post_id, '_yoast_wpseo_metakeywords', $meta_keyword);
                    }

                    $icon_name = 'category_' . time() . "." . $ext;
                    $target_dir = ABSPATH . "images/";  // =/opt/naukriwp/images/
                    $target_file = $target_dir . $icon_name;

                    // upload image to folder
                    if (move_uploaded_file($_FILES['exam_img']['tmp_name'], $target_file)) {
                        $insertQry = "INSERT INTO $EXAM_CATEGORY set name='$post_title',url_slug='$post_name',img_icon='$icon_name', h1_title='$heading', full_name='$full',display_order='$order',status='$stat',type='$type', add_date='$curDateTime'";
                        // echo $insertQry; echo "<br/>";
                        $sql1 = $db->prepare($insertQry);
                        $successResult = $sql1->execute();
                        if ($successResult) {
                            $message = '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">x</button> <strong>Data submit successfully</strong></div>';
                        } else {
                            $message = '<div class="alert alert-danger"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">x</button> <strong>Error in page creation </strong></div>';
                        }
                    } else {
                        $error = '<div class="alert alert-danger "><strong> Image Upload unsuccessfull ! </strong></div>';
                    }
                } else {
                    $message = '<div class="alert alert-danger"> <strong>Page Already Exist. Enter other name. </strong></div>';
                }
            }
        } else {
            $msg = '<div class="alert alert-danger"><strong> Image size exceeds 200 KB </strong></div>';
        }
    }
}

?>
<style>
    #form .form-group label.error {
        color: #FB3A3A;
        display: inline-block;
        margin: 0px 0 0px 0px;
        padding: 0;
        text-align: left;
    }
</style>

<main id="main-container">
    <div class="content content-narrow">
        <div class="row">
            <div class="col-lg-12">
                <h2 class="content-heading">Exam category</h2>
                <?php echo $message; ?>
                <div class="block">
                    <div class="block-header">
                        <ul class="block-options">
                            <li>
                                <button type="button"><i class="si si-settings"></i></button>
                            </li>
                        </ul>
                        <h3 class="block-title"></h3>
                    </div>
                    <div class="block-content block-content-narrow">
                        <form class="js-validation-bootstrap form-horizontal" action="add_exam_category.php" method="post" enctype="multipart/form-data" id="form">
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="val-username">Name<span class="text-danger">*</span></label>
                                <div class="col-md-9">
                                    <input class="form-control" type="text" name="exm_name" placeholder="" onkeyup="convertToSlug(this.value)" onload="convertToSlug(this.value)">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="val-email">Url Slug<span class="text-danger">*</span></label>
                                <div class="col-md-9">
                                    <input class="form-control" type="text" name="post_slug" id="post_slug" placeholder="" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="val-shortcode">Shortcode<span class="text-danger">*</span></label>
                                <div class="col-md-9">
                                    <input class="form-control" type="text" name="shortcode" value="[shortcode_exam_category]" placeholder="" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="val-email">FUll Name<span class="text-danger">*</span></label>
                                <div class="col-md-9">
                                    <input class="form-control" type="text" name="full" placeholder="Full Name">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="heading"> Hi Title</label>
                                <div class="col-md-9">
                                    <span class="text-danger"> Write Title upto 200 words only.</span>
                                    <input class="form-control" type="text" name="heading" placeholder="Enter H1 Title" maxlength="200">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="metaTitle"> Meta Title</label>
                                <div class="col-md-9">
                                    <input class="form-control" type="text" name="metaTitle" placeholder="Enter Meta Title">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="metafkeyword">Meta Focus Keyword</label>
                                <div class="col-md-9">
                                    <input class="form-control" type="text" name="metafkeyword" placeholder="Enter Meta Focus Keyword">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="metaKeyword">Meta Keyword</label>
                                <div class="col-md-9">
                                    <input class="form-control" type="text" name="metaKeyword" placeholder="Enter Meta Keyword">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="metaDesc">Meta Description</label>
                                <div class="col-md-9">
                                    <input class="form-control" type="text" name="metaDesc" placeholder="Enter Meta Description">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="val-password">Image icon</label>
                                <div class="col-md-9">
                                    <span class="text-danger"> (Select file upto 200 Kb size with png file extension only.)</span>
                                    <input class="form-control" type="file" name="exam_img" id="exam_img" placeholder="" accept=".png, .jpg, .jpeg">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-3 control-label" for="val-password">Type<span class="text-danger">*</span></label>
                                <div class="col-md-9">
                                    <select name="type" class="form-control">
                                        <option value="1">Government Exam</option>
                                        <option value="2">Entrance Exam</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="val-confirm-password">Display order<span class="text-danger">*</span></label>
                                <div class="col-md-9">
                                    <input class="form-control" type="number" name="num" placeholder="">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="val-email">Status<span class="text-danger">*</span></label>
                                <div class="col-md-9">
                                    <select name="status" class="form-control">
                                        <option value="1">Active</option>
                                        <option value="0">Deactive</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-md-8 col-md-offset-4">
                                    <button class="btn btn-sm btn-primary" type="submit" name="submit">Submit</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>

        </div>
    </div>
    </div>
</main>

<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>

<script type="text/javascript">
    (function($, W, D) {
        var JQUERY4U = {};
        JQUERY4U.UTIL = {
            setupFormValidation: function() {
                //form validation rules
                $("#form").validate({
                    rules: {
                        exm_name: {
                            required: true,
                        },
                        post_slug: {
                            required: true,
                        },
                        shortcode: {
                            required: true,
                        },
                        exam_img: {
                            required: true,
                        },
                        num: {
                            required: true,
                        }
                    },
                    messages: {
                        exm_name: "Please Enter exam name",
                        post_slug: "Please Enter slug name",
                        shortcode: "Please Enter shortcode",
                        exam_img: "Please upload an image icon",
                        num: "Please Enter order number",
                    },
                    submitHandler: function(form) {
                        form.submit();
                    }
                });
            }
        }
        //when the dom has loaded setup form validation rules
        $(D).ready(function($) {
            JQUERY4U.UTIL.setupFormValidation();
        });
    })(jQuery, window, document);
</script>

<script>
    //  to make slug from post name
    function convertToSlug(str) {
        str = str.replace(/[`~!@#$%^&*()_\-+=\[\]{};:'"\\|\/,.<>?\sā€˜ā€™//]/g, ' ').toLowerCase(); //replace all special characters | symbols with a space     
        str = str.replace(/^\s+|\s+$/gm, ''); // trim spaces at start and end of string
        str = str.replace(/\s+/g, '-'); // replace space with dash/hyphen
        document.getElementById("post_slug").value = str;
    }
</script>
<?php include 'footer.php'; ?>