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/selfanalyse/wp-content/plugins/psychometrics/psy_profile_sidebar.php
<?php
if (is_user_logged_in()) {
global $current_user;
global $wpdb;
$PSY_USERS_DETAILS = $wpdb->prefix . PSY_USERS_DETAILS;
$PSY_USER_DETAILS_LOG = $wpdb->prefix . PSY_USER_DETAILS_LOG;
$PSY_STATES = $wpdb->prefix . PSY_STATES;
$PSY_CITY = $wpdb->prefix . PSY_CITY;
$PSY_ABILITY_CLASS = $wpdb->prefix . PSY_ABILITY_CLASS;
$PSY_STUDY_AREA = $wpdb->prefix . PSY_STUDY_AREA;
$PSY_USERS_HOBBY = $wpdb->prefix . PSY_USERS_HOBBY;
$PSY_SOCIAL_LINKS = $wpdb->prefix . PSY_SOCIAL_LINKS;
$PSY_SUBSCRIPTION = $wpdb->prefix . PSY_SUBSCRIPTION;
$PSY_PLANS = $wpdb->prefix . PSY_PLANS;
$PSY_EXAMS = $wpdb->prefix . PSY_EXAMS;
$PSY_TEST_GEN_TEST_TAKEN = $wpdb->prefix . PSY_TEST_GEN_TEST_TAKEN;
$user_id = $current_user->ID;
$user_password = $current_user->user_pass;

$curDate = date('Y-m-d H:i:s');

$oldData = array();
$newData = array();
//update user details
if (isset($_REQUEST['update-details'])) {
    
    $e_state_id = $_POST['e_state_id'];
    $e_city_id = $_POST['e_city_id'];
    $e_pin = $_POST['e_pin'];
    $e_address = $_POST['e_address'];
    $e_edu_level = $_POST['e_edu_level'];
    $e_study_area = $_POST['e_study_area'];
    $e_working = $_POST['e_working'];
    $e_job = $_POST['e_job'];
    $e_work_nature = $_POST['e_work_nature'];
    $e_org = $_POST['e_org'];
    $e_given_exam = $_POST['e_given_exam'];
    $e_exam_name = $_POST['e_exam_name'];
    $e_year_pre = $_POST['e_year_pre'];
    $e_about = $_POST['e_about'];

    if($_REQUEST['e_gender'])
    {   
        $e_gender = $_POST['e_gender'];
        $subquery1 = "gender_id='$e_gender',";
        $newData['gender_id'] = $e_gender;
    }
    else{
        $subquery1 = "";
        $newData['gender_id'] = 'No change or no update';
    }

    if($_REQUEST['e_birthday'])
    {   
        $e_birthday = date('Y-m-d', strtotime($_POST['e_birthday']));
        $subquery2 = "date_of_birth='$e_birthday',";
        $newData['date_of_birth'] = $_POST['e_birthday'];
    }
    else{
        $subquery2 = "";
        $newData['date_of_birth'] = 'No change or no update';
    }

    $newData['profile_details'] = $e_about;
    $newData['state_id'] = $e_state_id;
    $newData['city_id'] = $e_city_id;
    $newData['pincode'] = $e_pin;
    $newData['address'] = $e_address;
    $newData['class_id'] = $e_edu_level;
    $newData['sty_ar'] = $e_study_area;
    $newData['working'] = $e_working;
    $newData['job'] = $e_job;
    $newData['nature'] = $e_work_nature;
    $newData['org'] = $e_org;
    $newData['given_ex'] = $e_given_exam;
    $newData['exam'] = $e_exam_name;
    $newData['pre_p'] = $e_year_pre;
    $newDataString = json_encode($newData,JSON_UNESCAPED_UNICODE);

    $oldDataSession = $_SESSION['OLD_DATA'];

    $updateUser = "UPDATE $PSY_USERS_DETAILS SET profile_details='$e_about',$subquery1 $subquery2 state_id='$e_state_id',city_id='$e_city_id',pincode='$e_pin',address='$e_address',current_education_level='$e_edu_level',study_area='$e_study_area',working='$e_working',job_title='$e_job',nature_of_work='$e_work_nature',organization_name='$e_org',given_any_exam='$e_given_exam',exam_name='$e_exam_name',prepairing_from='$e_year_pre',last_update='$curDate' WHERE user_id='$user_id'";

    if ($wpdb->query($updateUser)) {

        $insertLog = $wpdb->query("INSERT into $PSY_USER_DETAILS_LOG set user_id='$user_id', last_data='$oldDataSession', new_data='$newDataString', add_date='$curDate'");
?>
        <script>
            jQuery(document).ready(function() {
                toastr.success("Success:profile update")
            });
        </script>
    <?php
    } else {
    ?>
        <script>
            jQuery(document).ready(function() {
                toastr.error("Error:while updating")
            });
        </script>
        <?php
    }
}


//update user profile pic
if (isset($_REQUEST['upload-image'])) {
    /*---------------------Function for S3---------------------*/
    //include '/var/www/selfanalyse/awsS3/upload_function.php';
    include '/var/www/selfanalyse/awsS3/upload_function.php';
    /*---------------------Function for S3---------------------*/
	
    $exist_image = $_REQUEST['exist_image'];
    $profile_image = $_FILES['fileToUpload'];
    $key = '/profile-img/';
    $type = 'image';

    $allowed =  array('png', 'jpg', 'jpeg');
    if (!empty($_FILES['fileToUpload']['name'])) {
        $filename1 = stripslashes($_FILES['fileToUpload']['name']);
        $extension1 = strtolower(getExtension($filename1));
        if (!in_array($extension1, $allowed)) { ?>
            <script>
                jQuery(document).ready(function() {
                    toastr.error("Error:Please only upload png,jpg and jpeg format ")
                });
            </script>
            <?php
        } else {
            $image_name1 = $user_id . '-' . time() . '.' . $extension1;
            $temp_file_name1 = $_FILES['fileToUpload']['tmp_name'];

            // upload image to aws s3 folder
			//echo $user_id."-".$key."-".$image_name1."-".$temp_file_name1."-".$type;
            $copied = uploadToS3($user_id, $key, $image_name1, $temp_file_name1, $type);
            if ($copied == 200) {

                $deleteExist = deleteToS3($user_id, $key, $exist_image);

                $updatePic = $wpdb->query("UPDATE $PSY_USERS_DETAILS set profile_image='$image_name1' WHERE user_id='$user_id'");
            ?>
                <script>
                    jQuery(document).ready(function() {
                        toastr.success("Success:profile image update")
                    });
                </script>
            <?php
            } else {
            ?>
                <script>
                    jQuery(document).ready(function() {
                        toastr.error("Error:while updating")
                    });
                </script>
            <?php
            }
        }
    }
}

//add user hobbies
if (isset($_REQUEST['add-hobby'])) {
    $a_hobby = $_REQUEST['a_hobby'];

    if ($a_hobby != '') {
        $checkHobby = $wpdb->get_var("SELECT count(id) FROM $PSY_USERS_HOBBY where user_id='$user_id'");
        if ($checkHobby < 6) {
            $insertHobby = "INSERT INTO $PSY_USERS_HOBBY set user_id='$user_id', hobby_name='$a_hobby', status='1', add_date='$curDate'";
            if ($wpdb->query($insertHobby)) {
            ?>
                <script>
                    jQuery(document).ready(function() {
                        toastr.success("Success:hobby added")
                    });
                </script>
            <?php
            } else {
            ?>
                <script>
                    jQuery(document).ready(function() {
                        toastr.error("Error:while adding")
                    });
                </script>
            <?php
            }
        } else {
            ?>
            <script>
                jQuery(document).ready(function() {
                    toastr.error("Error:You cant add more than six hobby")
                });
            </script>
        <?php
        }
    } else {
        ?>
        <script>
            jQuery(document).ready(function() {
                toastr.error("Error:Please fill hobby name")
            });
        </script>
<?php
    }
}

//add socila links
if(isset($_REQUEST['add-social']))
{
    $social_platform = $_REQUEST['social_platform'];
    $a_social_link = $_REQUEST['a_social_link'];

    if($social_platform !='')
    {
        $social_var = explode("/",$social_platform);
        $social_name = $social_var[0];
        $icon_class = $social_var[1];

        $insertLinks = "INSERT into $PSY_SOCIAL_LINKS set user_id='$user_id', social_name='$social_name', icon_class='$icon_class', social_link='$a_social_link', status='1', add_date='$curDate'";
        if($wpdb->query($insertLinks))
        {
            ?>
            <script>jQuery(document).ready(function() {toastr.success("Success:social link added")});</script>
            <?php
        }
        else{
            ?>
            <script>jQuery(document).ready(function() {toastr.error("Error:while adding")});</script>
            <?php
        }
    }
}

//delete social link
if(isset($_REQUEST['delete_social']))
{
    $d_social_id = $_REQUEST['d_social_id'];

    $deleteSocial = "DELETE FROM $PSY_SOCIAL_LINKS where id='$d_social_id'";
    if($wpdb->query($deleteSocial))
    {
    ?>
        <script>
            jQuery(document).ready(function() {
                toastr.success("Success:social link delete")
            });
        </script>
    <?php
    } 
    else 
    {
    ?>
        <script>
            jQuery(document).ready(function() {
                toastr.error("Error:while deleting")
            });
        </script>
    <?php
    }
}

//delete hobby
if(isset($_REQUEST['delete_hobby']))
{
    $d_hobby = $_REQUEST['d_hobby'];

    $deleteHobby = "DELETE FROM $PSY_USERS_HOBBY where id='$d_hobby'";
    if($wpdb->query($deleteHobby))
    {
    ?>
        <script>
            jQuery(document).ready(function() {
                toastr.success("Success:hobby delete")
            });
        </script>
    <?php
    } 
    else 
    {
    ?>
        <script>
            jQuery(document).ready(function() {
                toastr.error("Error:while deleting")
            });
        </script>
    <?php
    }
}

//change password form
if(isset($_REQUEST['change_password'])){

    $c_new_pwd = $_REQUEST['c_new_pwd'];
    if($c_new_pwd != ''){

        if ( $current_user && wp_check_password( $c_new_pwd, $user_password, $user_id ) ) {
            ?>
            <script>jQuery(document).ready(function() { toastr.error("You enter new password same as old password") })</script>
            <?php
        } else {
            $user_data["ID"] = $user_id;
            $user_data["user_pass"] = $c_new_pwd;
            $passwordUpdate = wp_update_user($user_data);
            if(is_wp_error($passwordUpdate)){
                $error = $passwordUpdate->get_error_message();
                ?>
                <script>jQuery(document).ready(function() { toastr.error('<?php echo $error; ?>') })</script>
                <?php
            }
            else{
                $sessions = WP_Session_Tokens::get_instance($user_id);
                $sessions->destroy_all();
                wp_clear_auth_cookie();
                ?>
                <script>alert("Your password change succesfully.Please Login again to continue")</script>
                <script>window.location.href='/login'</script>
                <?php
            }
        }

    }
    else{
        ?>
        <script>toastr.error("Please fill new password")</script>
        <?php
    }
}

$getUserDetails = $wpdb->get_row("SELECT ud.first_name,ud.last_name,ud.profile_image,ud.profile_details,ud.mobile_number,ud.email_address,ud.gender_id,ud.date_of_birth,ud.state_id,ud.city_id,ud.pincode,ud.address,ud.current_education_level,ud.study_area,ud.working,ud.job_title,ud.nature_of_work,ud.organization_name,ud.given_any_exam,ud.exam_name,ud.prepairing_from,ud.email_verified,ud.mobile_verified,s.state_name,c.city_name,cl.class_name,sd.study_area_name FROM $PSY_USERS_DETAILS as ud LEFT JOIN $PSY_STATES as s on s.state_id=ud.state_id LEFT JOIN $PSY_CITY as c on c.city_id=ud.city_id LEFT JOIN $PSY_ABILITY_CLASS as cl on cl.class_id=ud.current_education_level LEFT JOIN $PSY_STUDY_AREA as sd on sd.study_area_id=ud.study_area WHERE ud.user_id='$user_id'");

$getStates = $wpdb->get_results("SELECT state_id,state_name FROM $PSY_STATES");

$name = $getUserDetails->first_name . ' ' . $getUserDetails->last_name;
$profile_image = $getUserDetails->profile_image;
$profile_details = $getUserDetails->profile_details;
$gender_id = $getUserDetails->gender_id;
$dob_value = $getUserDetails->date_of_birth;
$dob_show = date('d F, Y', strtotime($getUserDetails->date_of_birth));
$email = $getUserDetails->email_address;
$mobile = $getUserDetails->mobile_number;
$state_name = $getUserDetails->state_name;
$state_id = $getUserDetails->state_id;
$city = $getUserDetails->city_name;
$city_id = $getUserDetails->city_id;
$pincode = $getUserDetails->pincode;
$address = $getUserDetails->address;
$class_id = $getUserDetails->current_education_level;
$class_name = $getUserDetails->class_name;
$study_area = $getUserDetails->study_area;
$study_area_name = $getUserDetails->study_area_name;
$working = $getUserDetails->working;
$job_title = $getUserDetails->job_title;
$nature_of_work = $getUserDetails->nature_of_work;
$organization_name = $getUserDetails->organization_name;
$given_any_exam = $getUserDetails->given_any_exam;
$exam_name = $getUserDetails->exam_name;
$prepairing_from = $getUserDetails->prepairing_from;
$email_verified = $getUserDetails->email_verified;
$mobile_verified = $getUserDetails->mobile_verified;

if($getUserDetails->date_of_birth == '' || $state_id == '' || $state_id == '0' || $class_id == '' || $class_id == '0'){
    $testStatus = 0;
}
else{
    $testStatus = 1;
}

$oldData['profile_details'] = $profile_details;
$oldData['gender_id'] = $gender_id;
$oldData['date_of_birth'] = $getUserDetails->date_of_birth;
$oldData['state_id'] = $state_id;
$oldData['city_id'] = $city_id;
$oldData['pincode'] = $pincode;
$oldData['address'] = $address;
$oldData['class_id'] = $class_id;
$oldData['sty_ar'] = $study_area;
$oldData['working'] = $working;
$oldData['job'] = $job_title;
$oldData['nature'] = $nature_of_work;
$oldData['org'] = $organization_name;
$oldData['given_ex'] = $given_any_exam;
$oldData['exam'] = $exam_name;
$oldData['pre_p'] = $prepairing_from;
$oldDataString = json_encode($oldData,JSON_UNESCAPED_UNICODE);

$_SESSION['OLD_DATA'] = $oldDataString;

$getStates = $wpdb->get_results("SELECT state_id,state_name FROM $PSY_STATES");
$cities = $wpdb->get_results("SELECT city_id,city_name FROM $PSY_CITY where state_id='$state_id'");
$classes = $wpdb->get_results("SELECT class_id,class_name FROM $PSY_ABILITY_CLASS");
$streams = $wpdb->get_results("SELECT study_area_id,study_area_name FROM $PSY_STUDY_AREA");
$getHobbies = $wpdb->get_results("SELECT id,hobby_name FROM $PSY_USERS_HOBBY where user_id='$user_id'");
$getSocialLinks = $wpdb->get_results("SELECT id,social_name,icon_class,social_link FROM $PSY_SOCIAL_LINKS where user_id='$user_id' and status='1'");

/******** check uri *** */
$uri = $_SERVER['REQUEST_URI'];
$link = str_replace("/", "", $uri);
/******************** */
?>
<div class="dashboard-side-bar">

    <div class="dashboard-bg-content">
        <div class="dp-img-logo-box">
            <?php if($profile_image != ''){ ?>
            <img src="https://selfanalyse.s3.ap-south-1.amazonaws.com/<?php echo $user_id ?>/profile-img/<?php echo $profile_image ?>" alt="<?php echo $name ?>">
            <?php } else { ?>
            <img src="<?php echo ROOT_LINK.'wp-content/plugins/psychometrics/images/default.svg' ?>" alt="Change Profile Image">
            <?php } ?>

            <?php if($link == 'profile'){ ?>
            <span><a href="#" data-toggle="modal" data-target="#imglogo-modal"><i class="fas fa-camera"></i></a></span>
            <?php } ?>
        </div>
        <h4 class="dp-name"><?php echo $name ?></h4>
        <p class="dp-class"><?php echo $class_name ?></p>

        <h6 class="left-bar-head">Contact <span> <a <?php if($link == 'profile'){ ?> href="#" data-toggle="modal" data-target="#edit-modal" <?php } else { ?>href="/profile"<?php } ?>> <i class="far fa-edit"></i> edit</a></span></h6>
        <ul class="contact-list-ul">
            <li>
                <i class="fas fa-phone"></i> +91-<?php echo $mobile ?>
            </li>
            <li>
                <i class="far fa-envelope"></i> <?php echo $email ?>
            </li>
            <li>
                <i class="fas fa-map-marker-alt"></i> <?php echo $city . ' ,' . $state_name ?>
            </li>
        </ul>

        <h6 class="left-bar-head">Social Links
        <span><a <?php if($link == 'profile'){ ?> href="#" data-toggle="modal" data-target="#social-modal"<?php } else { ?>href="/profile"<?php } ?>><i class="far fa-edit"></i> add</a></span>
        </h6>
        <ul class="sociallink-list-ul">
            <?php foreach($getSocialLinks as $sc){ ?>
            <li>
                <a href="<?php echo $sc->social_link ?>" target="_blank"><i class="fab <?php echo $sc->icon_class ?>"></i></a>
            </li>
            <?php } ?>
        </ul>


        <h6 class="left-bar-head">Hobbies
            <?php //if (sizeof($getHobbies) < 6) { ?>
                <span><a <?php if($link == 'profile'){ ?> href="#" data-toggle="modal" data-target="#hobby-modal" <?php } else { ?> href="/profile"<?php } ?>><i class="far fa-edit"></i> add</a></span>
            <?php //} ?>
        </h6>
        <div class="hobbies-div">
            <ul>
                <?php foreach ($getHobbies as $hb) { ?>
                    <li><?php echo $hb->hobby_name; ?></li>
                <?php } ?>
            </ul>
        </div>


        <!-- <h6 class="left-bar-head">Digi Locker </h6>
        <ul class="digi-ul">
            <li><i class="fas fa-link"></i> Link</li>
        </ul>

        <h6 class="left-bar-head">Friends <span> <i class="far fa-edit"></i> add</span></h6>
        <div class="row hobbies-div">
            <div class="col-md-4">
                <h4>Sam</h4>
            </div>
            <div class="col-md-4">
                <h4>Smith</h4>
            </div>
            <div class="col-md-4">
                <h4>Adam</h4>
            </div>
            <div class="col-md-4">
                <h4>Steve</h4>
            </div>
            <div class="col-md-4">
                <h4>Tony</h4>
            </div>
            <div class="col-md-4">
                <h4>Tom</h4>
            </div>
        </div> -->
    </div>
</div>
<?php
}
else{
  ?>
  <script>window.location.href='/login'</script>
  <?php
}
?>