File: /mnt/data/dev/dev-doccure-wp/wp-content/plugins/doccure/init.php
<?php
/**
* The plugin bootstrap file
*
* This file is read by WordPress to generate the plugin information in the plugin
* admin area. This file also includes all of the dependencies used by the plugin,
* registers the activation and deactivation functions, and defines a function
* that starts the plugin.
*
* @link https://themeforest.net/user/dreamstechnologies/portfolio
* @since 1.0
* @package Doccure Core
*
* @wordpress-plugin
* Plugin Name: Doccure Core
* Plugin URI: https://themeforest.net/user/dreamstechnologies/portfolio
* Description: This plugin is used for creating custom post types and other functionality for doccure Theme
* Version: 1.5.4
* Author: Dreams Technologies
* Author URI: https://themeforest.net/user/dreamstechnologies
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: doccure_core
* Domain Path: /languages
*/
// If this file is called directly, abort.
if (!defined('WPINC')) {
die;
}
/**
* Load plugin textdomain.
*
* @since 1.0.0
*/
add_action('init', 'doccure_load_textdomain_plugin');
function doccure_load_textdomain_plugin()
{
load_plugin_textdomain('doccure_core', false, dirname(plugin_basename(__FILE__)) . '/languages');
}
if (!function_exists('doccure_core_load_last')) {
function doccure_core_load_last()
{
$wp_path_to_this_file = preg_replace('/(.*)plugins\/(.*)$/', WP_PLUGIN_DIR . "/$2", __FILE__);
$this_plugin = plugin_basename(trim($wp_path_to_this_file));
$active_plugins = get_option('active_plugins');
$this_plugin_key = array_search($this_plugin, $active_plugins);
array_splice($active_plugins, $this_plugin_key, 1);
array_push($active_plugins, $this_plugin);
update_option('active_plugins', $active_plugins);
}
add_action("activated_plugin", "doccure_core_load_last");
}
/**
* The code that runs during plugin activation.
* This action is documented in includes/class-elevator-activator.php
*/
if (!function_exists('activate_doccure')) {
function activate_doccure()
{
require_once plugin_dir_path(__FILE__) . 'includes/class-system-activator.php';
doccure_Activator::activate();
}
}
/**
* The code that runs during plugin deactivation.
* This action is documented in includes/class-elevator-deactivator.php
*/
if (!function_exists('deactivate_doccure')) {
function deactivate_doccure()
{
require_once plugin_dir_path(__FILE__) . 'includes/class-system-deactivator.php';
doccure_Deactivator::deactivate();
}
}
register_activation_hook(__FILE__, 'activate_doccure');
register_deactivation_hook(__FILE__, 'deactivate_doccure');
//register_deactivation_hook (__FILE__, 'doccure_cron_deactivate');
/**
* Plugin configuration file,
* It include getter & setter for global settings
*/
require plugin_dir_path(__FILE__) . 'config.php';
/**
* The core plugin class that is used to define internationalization,
* admin-specific hooks, and public-facing site hooks.
*/
require plugin_dir_path(__FILE__) . 'includes/doccurecpt.php';
require plugin_dir_path(__FILE__) . 'includes/doccure_cron.php';
require plugin_dir_path(__FILE__) . 'includes/class-system.php';
require plugin_dir_path(__FILE__) . 'chat/class-chat-system.php';
include doccure_template_exsits('hooks/hooks');
include doccure_template_exsits('helpers/EmailHelper');
include doccure_template_exsits('shortcodes/class-authentication');
include doccure_template_exsits('libraries/mailchimp/class-mailchimp');
//require plugin_dir_path( __FILE__ ) . 'widgets/config.php';
require plugin_dir_path(__FILE__) . 'elementor/base.php';
///require plugin_dir_path( __FILE__ ) . 'elementor/config.php';
require plugin_dir_path(__FILE__) . 'libraries/mailchimp/class-mailchimp-oath.php';
require plugin_dir_path(__FILE__) . 'helpers/register.php';
//require plugin_dir_path( __FILE__ ) . 'import-users/class-readcsv.php';
//require plugin_dir_path( __FILE__ ) . 'admin/settings/settings.php';
//include doccure_template_exsits( 'import-users/class-import-user' );
require plugin_dir_path(__FILE__) . 'admin/metaboxes/classes/class-metaboxes.php';
require plugin_dir_path(__FILE__) . 'admin/metaboxes/classes/class-form-attributes.php';
require plugin_dir_path(__FILE__) . 'demo-import/importer.php';
//require plugin_dir_path( __FILE__ ) . '/admin/theme-settings/init.php'; //Theme Settings
/**
* Get template from plugin or theme.
*
* @param string $file Template file name.
* @param array $param Params to add to template.
*
* @return string
*/
function doccure_template_exsits($file, $param = array())
{
extract($param);
if (is_dir(get_stylesheet_directory() . '/extend/')) {
if (file_exists(get_stylesheet_directory() . '/extend/' . $file . '.php')) {
$template_load = get_stylesheet_directory() . '/extend/' . $file . '.php';
} else {
$template_load = doccureGlobalSettings::get_plugin_path() . '/' . $file . '.php';
}
} else {
$template_load = doccureGlobalSettings::get_plugin_path() . '/' . $file . '.php';
}
return $template_load;
}
/**
* Begins execution of the plugin.
*
* Since everything within the plugin is registered via hooks,
* then kicking off the plugin from this point in the file does
* not affect the page life cycle.
*
* @since 1.0.0
*/
if (!function_exists('run_doccure')) {
function run_doccure()
{
$plugin = new doccure_Core();
$plugin->run();
}
run_doccure();
}
/**
* @init Save rewrite slugs
* @package Rewrite Slug
* @subpackage combo-wp-rewrite-slugs/admin/partials
* @since 1.0
* @desc This Function Will Produce All Tabs View.
*/
if (!function_exists('doccure_set_custom_rewrite_rule')) {
function doccure_set_custom_rewrite_rule()
{
global $wp_rewrite;
$settings = (array) doccure_get_doccure_options();
if (!empty($settings['post'])) {
foreach ($settings['post'] as $post_type => $slug) {
if (!empty($slug)) {
$args = get_post_type_object($post_type);
$args->rewrite["slug"] = $slug;
register_post_type($args->name, $args);
}
}
}
if (!empty($settings['term'])) {
foreach ($settings['term'] as $term => $slug) {
if (!empty($slug)) {
$tax = get_taxonomy($term);
$tax->rewrite["slug"] = $slug;
register_taxonomy($term, $tax->object_type[0], (array) $tax);
}
}
}
$wp_rewrite->flush_rules();
}
add_action('init', 'doccure_set_custom_rewrite_rule');
}
add_action('init', 'wpse_106269_remove_checkout_order_review', 11);
function wpse_106269_remove_checkout_order_review()
{
remove_action('woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 20);
}
/**
* Upload temp files to WordPress media
*
* @throws error
* @author Dreams Technologies<[email protected]>
* @return
*/
if (!function_exists('doccure_temp_upload_to_media')) {
function doccure_temp_upload_to_media($file_url, $post_id)
{
global $wp_filesystem;
if (empty($wp_filesystem)) {
require_once(ABSPATH . '/wp-admin/includes/file.php');
WP_Filesystem();
}
$json = array();
$upload_dir = wp_upload_dir();
$folderRalativePath = $upload_dir['baseurl'] . "/doccure-temp";
$folderAbsolutePath = $upload_dir['basedir'] . "/doccure-temp";
$args = array(
'timeout' => 15,
'headers' => array('Accept-Encoding' => ''),
'sslverify' => false
);
$response = wp_remote_get($file_url, $args);
$file_data = wp_remote_retrieve_body($response);
if (empty($file_data)) {
$json['attachment_id'] = '';
$json['url'] = '';
$json['name'] = '';
return $json;
}
$filename = basename($file_url);
if (wp_mkdir_p($upload_dir['path'])) {
$file = $upload_dir['path'] . '/' . $filename;
} else {
$file = $upload_dir['basedir'] . '/' . $filename;
}
// Rename file if exists
if (file_exists($file)) {
$i = 1;
$new_path = $file;
while (file_exists($new_path)) {
$extension = pathinfo($file, PATHINFO_EXTENSION);
$actual_filename = pathinfo($file, PATHINFO_FILENAME);
$new_filename = $actual_filename . '-' . $i . '.' . $extension;
$new_path = $upload_dir['path'] . '/' . $new_filename;
$i++;
}
$file = $new_path;
}
$filename = basename($file);
$actual_filename = pathinfo($file, PATHINFO_FILENAME);
// ✅ Validate file type before saving
$filetype = wp_check_filetype_and_ext($file, $filename);
if (!$filetype['type'] || !$filetype['ext']) {
wp_die(__('File type is not allowed.', 'doccure'));
}
// Save file
file_put_contents($file, $file_data);
$wp_filetype = wp_check_filetype($filename, null);
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => sanitize_file_name($actual_filename),
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment($attachment, $file, $post_id);
require_once(ABSPATH . 'wp-admin/includes/image.php');
$attach_data = wp_generate_attachment_metadata($attach_id, $file);
wp_update_attachment_metadata($attach_id, $attach_data);
$json['attachment_id'] = $attach_id;
$json['url'] = $upload_dir['url'] . '/' . basename($filename);
$json['name'] = $filename;
$target_path = $folderAbsolutePath . "/" . $filename;
if (file_exists($target_path)) {
unlink($target_path); // delete temp file
}
return $json;
}
}
function send_password_reset_email($email, $subject, $message)
{
$headers = array('Content-Type: text/html; charset=UTF-8');
wp_mail($email, $subject, $message, $headers);
}
function send_password_reset_email_func_util($email, $subject, $message, $headers)
{
wp_mail($email, $subject, $message, $headers);
}
function cc_mime_types($mimes)
{
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter('upload_mimes', 'cc_mime_types');
/**
* Add New User Roles
*
* @throws error
* @author Dreams Technologies<[email protected]>
* @return string
*/
if (!function_exists('doccure_add_user_roles')) {
function doccure_add_user_roles()
{
global $doccure_options;
add_role('doctors', esc_html__('Doctor', 'doccure_core'));
add_role('regular_users', esc_html__('Patients', 'doccure_core'));
add_role('doctors_staff', esc_html__('Doctors Staff', 'doccure_core'));
add_role('staff', esc_html__('Staff', 'doccure_core'));
}
add_action('admin_init', 'doccure_add_user_roles');
}
/**
* Get Booking meta
*
* @throws error
* @author Dreams Technologies<[email protected]>
* @return
*/
if (!function_exists('doccure_get_booking_value')) {
function doccure_get_booking_value($val = '', $key = '', $cart_data = '')
{
if (!empty($key) && $key === 'parentdoctor_id') {
$val_title = doccure_get_linked_profile_id($val);
$val = esc_html(get_the_title($val_title));
} else if (!empty($key) && $key === 'hospital') {
global $doccure_options;
$posttype = get_post_type($val);
if (!empty($posttype) && $posttype === 'hospitals_team') {
$hospital_id = get_post_meta($val, 'hospital_id', true);
$val = esc_html(get_the_title($hospital_id));
} else {
$val = esc_html(get_the_title($val));
}
} else if ($key === 'doctor_id') {
$val = doccure_full_name($val);
} else if ($key === 'slots') {
$time_format = get_option('time_format');
$slot_key_val = explode('-', $val);
$val = date($time_format, strtotime('2016-01-01' . $slot_key_val[0]));
} else if ($key === 'consultant_fee' || $key === 'price') {
$val = doccure_price_format($val, 'return');
} else if ($key === 'myself') {
$val = !empty($val) && $val === 'someelse' ? esc_html__('Other Person', 'doccure_core') : esc_html__('My Self', 'doccure_core');
}
return $val;
}
}
/**
* load booking
*
* @throws error
* @author Dreams Technologies<[email protected]>
* @return
*/
if (!function_exists('doccure_get_booking_byID')) {
function doccure_get_booking_byID()
{
global $current_user, $doccure_options;
$json = array();
$booking_id = !empty($_POST['id']) ? intval($_POST['id']) : '';
$is_dashboard = !empty($_POST['dashboard']) ? esc_html($_POST['dashboard']) : '';
$is_type = !empty($_POST['type']) ? esc_html($_POST['type']) : '';
$hide_prescription = !empty($doccure_options['hide_prescription']) ? esc_html($doccure_options['hide_prescription']) : 'no';
$url_identity = $current_user->ID;
if (function_exists('doccure_validate_user')) {
doccure_validate_user();
} //if user is logged in
if (!empty($is_type) && $is_type === 'patient') {
if (function_exists('doccure_validate_privileges')) {
doccure_validate_privileges($booking_id);
} //if user is logged in and have privileges
} else if (!empty($is_type) && $is_type === 'doctor') {
$doctor_id = get_post_meta($booking_id, '_doctor_id', true);
$doctor_user_id = doccure_get_linked_profile_id($doctor_id, 'post');
if (isset($doctor_user_id) && intval($doctor_user_id) !== $current_user->ID) {
$json['type'] = 'error';
$json['message'] = esc_html__('You are not authorized to view this booking details', 'doccure_core');
wp_send_json($json);
}
} else {
if (!is_admin()) {
$data = get_userdata($current_user->ID);
if (isset($data->roles) && is_array($data->roles) && in_array('administrator', $data->roles)) {
//do nothing
} else {
$json['type'] = 'error';
$json['message'] = esc_html__('You are not authorized to view this booking details', 'doccure_core');
wp_send_json($json);
}
}
}
//security check
$do_check = check_ajax_referer('ajax_nonce', 'security', false);
if ($do_check == false) {
$json['type'] = 'error';
$json['message'] = esc_html__('Security check failed, this could be because of your browser cache. Please clear the cache and check it againe', 'doccure_core');
wp_send_json($json);
}
$width = 100;
$height = 100;
$current_user_type = apply_filters('doccure_get_user_type', $url_identity);
if (!empty($booking_id)) {
ob_start();
$date_format = get_option('date_format');
$time_format = get_option('time_format');
$doctor_id = get_post_meta($booking_id, '_doctor_id', true);
$booking_date = get_post_meta($booking_id, '_am_booking', true);
$hospital_id = get_post_meta($booking_id, '_booking_hospitals', true);
$slots = get_post_meta($booking_id, '_booking_slot', true);
$slots = !empty($slots) ? explode('-', $slots) : '';
$tine_slot = $slots;
if (!empty($slots)) {
$slots = date($time_format, strtotime('2016-01-01' . $slots[0]));
}
$user_types = doccure_list_user_types();
$content = get_post_field('post_content', $booking_id);
$contents = !empty($content) ? $content : '';
$booking_slot = get_post_meta($booking_id, '_booking_slot', true);
$booking_slot = !empty($booking_slot) ? $booking_slot : '';
$services = get_post_meta($booking_id, '_booking_service', true);
$services = !empty($services) ? $services : array();
$post_auter = get_post_field('post_author', $booking_id);
$booking_user_type = get_post_meta($booking_id, '_user_type', true);
$thumbnail = '';
$booking_array = get_post_meta($booking_id, '_am_booking', true);
$total_price = !empty($booking_array['_price']) ? $booking_array['_price'] : 0;
$consultant_fee = !empty($booking_array['_consultant_fee']) ? $booking_array['_consultant_fee'] : 0;
if (empty($booking_user_type) || $booking_user_type === 'regular_users') {
$link_id = doccure_get_linked_profile_id($post_auter);
$thumbnail = doccure_prepare_thumbnail($link_id, $width, $height);
$user_type = apply_filters('doccure_get_user_type', $post_auter);
$user_type = $user_types[$user_type];
$user_type = !empty($user_type) ? $user_type : '';
$location = doccure_get_location($link_id);
$country = !empty($location['_country']) ? $location['_country'] : '';
} else {
$am_booking = get_post_meta($booking_id, '_am_booking', true);
$user_type = !empty($am_booking['_user_details']['user_type']) ? $am_booking['_user_details']['user_type'] : '';
}
$name = get_post_meta($booking_id, 'bk_username', true);
$email = get_post_meta($booking_id, 'bk_email', true);
$phone = get_post_meta($booking_id, 'bk_phone', true);
$name = !empty($name) ? $name : '';
$email = !empty($email) ? $email : '';
$phone = !empty($phone) ? $phone : '';
$post_status = get_post_status($booking_id);
$post_status_key = $post_status;
if ($post_status === 'pending') {
$post_status = esc_html__('Pending', 'doccure_core');
} elseif ($post_status === 'publish') {
$post_status = esc_html__('Confirmed', 'doccure_core');
} elseif ($post_status === 'draft') {
$post_status = esc_html__('Pending', 'doccure_core');
} elseif ($post_status === 'cancelled') {
$post_status = esc_html__('Cancelled', 'doccure_core');
}
$relation = doccure_patient_relationship();
$posttype = get_post_type($hospital_id);
if (!empty($posttype) && $posttype === 'hospitals_team') {
$hospital_id = get_post_meta($hospital_id, 'hospital_id', true);
$location_title = esc_html(get_the_title($hospital_id));
} else {
$location_title = esc_html(get_the_title($hospital_id));
}
// Append hospital address to the location title where available so that
// both the hospital name and its address are visible in appointment
// details and related views.
if (!empty($hospital_id)) {
$hospital_address = get_post_meta($hospital_id, '_address', true);
if (!empty($hospital_address)) {
$location_title = trim($location_title . ' - ' . esc_html($hospital_address));
}
}
$am_specialities = doccure_get_post_meta($doctor_id, 'am_specialities');
$am_specialities = !empty($am_specialities) ? $am_specialities : array();
$google_calender = '';
$yahoo_calender = '';
$appointment_date = get_post_meta($booking_id, '_appointment_date', true);
if (!empty($appointment_date) && !empty($tine_slot[0]) && !empty($tine_slot[1])) {
$startTime = new DateTime($appointment_date . ' ' . $tine_slot[0]);
$startTime = $startTime->format('Y-m-d H:i');
$endTime = new DateTime($appointment_date . ' ' . $tine_slot[1]);
$endTime = $endTime->format('Y-m-d H:i');
$google_calender = doccure_generate_GoogleLink($name, $startTime, $endTime, $contents, $location_title);
$yahoo_calender = doccure_generate_YahooLink($name, $startTime, $endTime, $contents, $location_title);
}
$doctor_user_id = doccure_get_linked_profile_id($doctor_id, 'post');
if (!empty($user_type) && $user_type === 'patients') {
$user_type_title = esc_html__('patient', 'doccure_core');
} else {
$user_type_title = $user_type;
}
$prescription_id = get_post_meta($booking_id, '_prescription_id', true);
$prescription_url = !empty($booking_id) ? doccure_Profile_Menu::doccure_profile_menu_link('prescription', $current_user->ID, true, 'view') . '&booking_id=' . $booking_id : '';
$user_type_access = apply_filters('doccure_get_user_type', $current_user->ID);
?>
<?php
$role = $current_user->roles[0];
?>
<?php
if ($role == 'doctors' || $role == 'doctors_staff' || $role == 'staff') { ?>
<div class="dc-user-header">
<div class="dc-user-header-inner">
<?php if (!empty($thumbnail)) { ?>
<figure class="dc-user-img">
<img src="<?php echo esc_url($thumbnail); ?>" alt="<?php echo esc_attr($name); ?>">
</figure>
<?php } ?>
<div class="dc-title pateintview-details">
<?php if (!empty($name)) { ?>
<h3>
<?php
echo esc_html($name);
if (!empty($post_auter) && $post_auter != 1) {
doccure_get_verification_check($post_auter);
}
?>
</h3>
<h5>
<?php if (!empty($email)) { ?>
<i class="far fa-envelope"></i> <?php echo esc_html($email); ?>
<?php } ?>
</h5>
<h5>
<?php if (!empty($phone)) { ?>
<i class="fas fa-phone"></i> <?php echo esc_html($phone); ?>
<?php } ?>
</h5>
<?php } ?>
<h5>
<?php if (!empty($country) && $country != 1) { ?>
<i class="feather-map-pin"></i> <?php echo esc_html($country); ?>
<?php } ?>
</h5>
</div>
</div>
<?php if (!empty($post_status)) { ?>
<div class="dc-status-test">
<div class="dc-rightarea dc-status">
<span><?php echo esc_html(ucwords($post_status)); ?></span>
<em><?php esc_html_e('Status', 'doccure_core'); ?></em>
<!-- status links -->
<?php if (is_user_logged_in() && ($user_type_access === 'doctors' || $user_type_access === 'doctors_staff' || $user_type_access === 'staff')) { ?>
<div class="dc-user-steps">
<div class="dc-btnarea toolip-wrapo dc-print-options">
<?php if (!empty($booking_id) && !empty($current_user_type)) {
if ($post_status_key === 'pending') { ?>
<a href="javascript:;" class="dc-btn dc-update-status btn btn-sm bg-success-light"
data-status="publish" data-id="<?php echo intval($booking_id); ?>"><i
class="fas fa-check"></i><?php esc_html_e('Accept', 'doccure_core'); ?></a>
<a href="javascript:;" class="dc-btn dc-deleteinfo dc-update-status btn btn-sm bg-danger-light"
data-status="cancelled" data-id="<?php echo intval($booking_id); ?>"><i
class="fas fa-times"></i><?php esc_html_e('Cancel', 'doccure_core'); ?></a>
<?php }
if ($post_status_key === 'publish' && !empty($hide_prescription) && $hide_prescription == 'no') { ?>
<a href="<?php echo esc_url($prescription_url); ?>"
class="dc-btn dc-filebtn add-new-btn generate-prescription"><?php esc_html_e('Add Prescription', 'doccure_core'); ?></a>
<?php if (!empty($prescription_id)) { ?>
<form method="post" name="download_pdf">
<input type="hidden" name="pdf_booking_id" value="<?php echo intval($booking_id); ?>">
<a href="javascript:;" onclick="document.forms['download_pdf'].submit(); return false;"
class="dc-btn add-new-btn dc-pdfbtn"><?php esc_html_e('Download Prescription', 'doccure_core'); ?></a>
</form>
<a href="javascript:;" class="dc-btn add-new-btn dc-viewbtn view-prescription-btn"
data-booking-id="<?php echo intval($booking_id); ?>"><?php esc_html_e('View Prescription', 'doccure_core'); ?></a>
<?php } ?>
<?php }
} else if ($is_dashboard === 'yes' && !empty($current_user_type)) {
?>
<?php
$base_url = get_site_url() . "/dashboard/";
$user_identity = $current_user->ID;
$full_url = $base_url . "?ref=chat&identity=" . $user_identity;
?>
<a href="javascript:;"
onclick="window.open('<?php echo esc_url($full_url); ?>', '_blank'); return false;"
class="dc-btn add-new-btn dc-chatbtn">
<?php esc_html_e('Chat', 'doccure_core'); ?>
</a>
<?php if (!empty($prescription_id)) { ?>
<form method="post" name="download_pdf">
<input type="hidden" name="pdf_booking_id" value="<?php echo intval($booking_id); ?>">
<a href="javascript:;" onclick="document.forms['download_pdf'].submit(); return false;"
class="dc-btn add-new-btn dc-pdfbtn"><?php esc_html_e('Download Prescription', 'doccure_core'); ?></a>
</form>
<?php } ?>
<?php } ?>
<?php
$get_order_id = get_post_meta($booking_id, '_order_id', true);
if (empty($get_order_id)) {
$get_order_id = get_post_meta($booking_id, '_product_rand_offline', true);
}
global $wpdb;
$table_name = $wpdb->prefix . 'zoom_links';
$meeting_link = $wpdb->get_row($wpdb->prepare("SELECT * FROM $table_name WHERE order_id = %d", $get_order_id));
?>
<?php
$post_status_reschedule = get_post_status($booking_id);
if ($post_status_reschedule == 'publish' && $meeting_link->meeting_id != '') { ?>
<a class="dc-btn meeting_button btn dc-btn-blocks dc-filebtn"
href="<?php echo esc_attr($meeting_link->meeting_id); ?>"
target="_blank"><?php esc_html_e('Join Meeting', 'doccure_core'); ?></a>
<?php } ?>
</div>
</div>
<?php } ?>
<!-- ends status links -->
</div>
</div>
<?php } ?>
</div>
<div class="dc-user-details">
<div class="dc-user-grid">
<?php if (!empty($booking_date['_with_patient']['other_name'])) { ?>
<div class="dc-user-info dc-person-patient">
<div class="dc-title">
<h4><?php esc_html_e('Person with patient', 'doccure_core'); ?> :</h4>
<span><?php echo esc_html($booking_date['_with_patient']['other_name']); ?></span>
</div>
</div>
<?php } ?>
<?php if (!empty($booking_date['_with_patient']['relation'])) { ?>
<div class="dc-user-info dc-person-relation">
<div class="dc-title">
<h4><?php esc_html_e('Relation with patient', 'doccure_core'); ?> :</h4>
<span><?php echo esc_html($relation[$booking_date['_with_patient']['relation']]); ?></span>
</div>
</div>
<?php } ?>
<?php if (!empty($location_title)) { ?>
<div class="dc-user-info dc-location-title">
<div class="dc-title">
<h4><?php esc_html_e('Appointment location', 'doccure_core'); ?> :</h4>
<span><?php echo esc_html($location_title); ?></span>
</div>
</div>
<?php } ?>
<?php if (!empty($appointment_date) && !empty($slots)) { ?>
<div class="dc-user-info dc-apt-detail-date">
<div class="dc-title">
<h4><?php esc_html_e('Appointment date', 'doccure_core'); ?> :</h4>
<span><?php echo date_i18n($date_format, strtotime($appointment_date)); ?> -
<?php echo esc_html($slots); ?> </span>
</div>
</div>
<?php } ?>
<?php if (!empty($services)) { ?>
<div class="dc-user-info dc-info-required dc-services-wrap">
<div class="dc-title">
<h4><?php esc_html_e('Services required', 'doccure_core'); ?>:</h4>
</div>
<?php
foreach ($services as $spe => $sers) {
if (!empty($spe)) { ?>
<div class="dc-spec-wrap">
<div class="dc-title">
<span><?php echo doccure_get_term_name($spe, 'specialities'); ?></span>
</div>
<?php if (!empty($sers)) { ?>
<ul class="dc-required-details">
<?php foreach ($sers as $k => $val) {
$single_price = 0;
if (!empty($k) && $k === $val) {
$am_specialities = !empty($doctor_id) ? doccure_get_post_meta($doctor_id, 'am_specialities') : array();
$am_specialities = !empty($am_specialities) ? $am_specialities : array();
$single_price = !empty($am_specialities[$spe][$k]['price']) ? $am_specialities[$spe][$k]['price'] : 0;
} else {
$single_price = $val;
}
?>
<li>
<span>
<?php
echo doccure_get_term_name($k, 'services');
if (!empty($single_price)) { ?>
<em>(<?php doccure_price_format($single_price); ?>)</em>
<?php } ?>
</span>
</li>
<?php } ?>
</ul>
<?php } ?>
</div>
<?php } ?>
<?php } ?>
</div>
<?php } ?>
<?php if (!empty($contents)) { ?>
<div class="dc-required-info dc-apt-comments">
<div class="dc-title">
<h4><?php esc_html_e('Comments', 'doccure_core'); ?></h4>
</div>
<div class="dc-description">
<p><?php echo esc_html($contents); ?></p>
</div>
</div>
<?php } ?>
<?php if (isset($consultant_fee)) { ?>
<div class="dc-user-info dc-apt-consult-fee">
<div class="dc-title">
<h4><?php esc_html_e('Consultant fee', 'doccure_core'); ?> :</h4>
<span><?php doccure_price_format($consultant_fee); ?></span>
</div>
</div>
<?php }
// Get insurance details
$reason_for_visit = get_post_meta($booking_id, '_reason_for_visit', true);
$insurance_discount = get_post_meta($booking_id, '_insurance_discount', true);
$insurance_details = get_post_meta($booking_id, '_insurance_details', true);
$insurance_status = get_post_meta($booking_id, '_insurance_status', true);
$insurance_status = !empty($insurance_status) ? $insurance_status : 'unverified';
$original_price = get_post_meta($booking_id, '_original_price', true);
$order_id = get_post_meta($booking_id, '_order_id', true);
// Calculate prices based on insurance status
$original_price = !empty($original_price) ? $original_price : $total_price;
$insurance_discount = !empty($insurance_discount) ? $insurance_discount : 0;
if ($insurance_status === 'verified' && $insurance_discount > 0) {
$display_price = max(0, $original_price - $insurance_discount);
$has_discount = true;
} else {
$display_price = $original_price;
$has_discount = false;
}
// Check if payment is pending and get payment link
$payment_pending = false;
$payment_url = '';
if (!empty($order_id)) {
$order = wc_get_order($order_id);
if ($order && $order->get_status() === 'pending' || $order->get_status() === 'failed') {
$payment_pending = true;
$payment_url = $order->get_checkout_payment_url();
}
}
if (!empty($reason_for_visit)) { ?>
<div class="dc-user-info dc-reason-for-visit">
<div class="dc-title">
<h4><?php esc_html_e('Reason for Visit', 'doccure_core'); ?>:</h4>
<span><?php echo esc_html($reason_for_visit); ?></span>
</div>
</div>
<?php }
// Display insurance information
if (!empty($insurance_details)) { ?>
<div class="dc-user-info dc-insurance-details">
<div class="dc-title">
<h4><?php esc_html_e('Insurance Details', 'doccure_core'); ?>:</h4>
<div class="insurance-info">
<?php
$discount_text = '';
$company_name = !empty($insurance_details['company_name']) ? $insurance_details['company_name'] : __('Insurance', 'doccure_core');
if ($insurance_details['type'] === 'percentage') {
$discount_text = $insurance_details['amount'] . '%';
} else {
$discount_text = doccure_price_format($insurance_details['amount'], 'return');
}
?>
<p><strong><?php esc_html_e('Company', 'doccure_core'); ?>:</strong>
<?php echo esc_html($company_name); ?></p>
<p><strong><?php esc_html_e('Discount', 'doccure_core'); ?>:</strong>
<?php echo esc_html($discount_text); ?></p>
<p><strong><?php esc_html_e('Status', 'doccure_core'); ?>:</strong>
<?php if (current_user_can('manage_options') || $user_type_access === 'doctors' || $user_type_access === 'administrator' || $user_type_access === 'staff') { ?>
<select id="insurance-status-dropdown" class="insurance-status-dropdown"
data-booking-id="<?php echo intval($booking_id); ?>">
<option value="unverified" <?php selected($insurance_status, 'unverified'); ?>>
<?php esc_html_e('Unverified', 'doccure_core'); ?>
</option>
<option value="verified" <?php selected($insurance_status, 'verified'); ?>>
<?php esc_html_e('Verified', 'doccure_core'); ?>
</option>
<option value="rejected" <?php selected($insurance_status, 'rejected'); ?>>
<?php esc_html_e('Rejected', 'doccure_core'); ?>
</option>
</select>
<?php } else { ?>
<span class="insurance-status-badge status-<?php echo esc_attr($insurance_status); ?>">
<?php echo esc_html(ucfirst($insurance_status)); ?>
</span>
<?php } ?>
</p>
<?php
// Preload existing notes and number for this booking
// Preload existing notes and number for this booking
$insurance_notes = get_post_meta($booking_id, '_insurance_notes', true);
$insurance_number = get_post_meta($booking_id, '_insurance_number', true);
?>
<div class="mt-2">
<label
for="insurance-number-input"><strong><?php esc_html_e('Insurance Number', 'doccure_core'); ?>:</strong></label>
<input type="text" id="insurance-number-input" class="form-control insurance-number-input"
data-booking-id="<?php echo intval($booking_id); ?>"
value="<?php echo esc_attr($insurance_number); ?>"
placeholder="<?php esc_attr_e('Enter insurance / policy number', 'doccure_core'); ?>" />
<label class="mt-2"
for="insurance-notes-textarea"><strong><?php esc_html_e('Insurance Notes', 'doccure_core'); ?>:</strong></label>
<textarea id="insurance-notes-textarea" class="form-control insurance-notes-input" rows="3"
data-booking-id="<?php echo intval($booking_id); ?>"
placeholder="<?php esc_attr_e('Add notes about insurance verification...', 'doccure_core'); ?>"><?php echo esc_textarea($insurance_notes); ?></textarea>
<button type="button" class="dc-btn btn btn-sm btn-primary mt-2 insurance-notes-save"
data-booking-id="<?php echo intval($booking_id); ?>">
<?php esc_html_e('Save Insurance Info', 'doccure_core'); ?>
</button>
</div>
</div>
</div>
</div>
<div class="dc-user-info dc-original-price">
<div class="dc-title">
<h4><?php esc_html_e('Original Price', 'doccure_core'); ?>:</h4>
<span><?php doccure_price_format($original_price); ?></span>
</div>
</div>
<?php if ($has_discount) { ?>
<div class="dc-user-info dc-insurance-discount">
<div class="dc-title">
<h4><?php esc_html_e('Insurance Discount', 'doccure_core'); ?>:</h4>
<span class="discount-amount">-<?php doccure_price_format($insurance_discount); ?></span>
</div>
</div>
<?php } ?>
<?php } ?>
<?php if (!empty($display_price)) { ?>
<div class="dc-user-info dc-total-fee">
<div class="dc-title">
<h4>
<?php if ($has_discount) {
esc_html_e('Final price after discount', 'doccure_core');
} else {
esc_html_e('Total price', 'doccure_core');
} ?>:
</h4>
<span class="final-price-amount <?php echo $has_discount ? 'discounted-price' : ''; ?>">
<?php doccure_price_format($display_price); ?>
<?php if ($has_discount) { ?>
<span class="discount-badge"><?php esc_html_e('Discounted', 'doccure_core'); ?></span>
<?php } ?>
</span>
</div>
</div>
<?php if ($payment_pending && !empty($payment_url)) { ?>
<div class="dc-user-info dc-payment-link">
<div class="dc-title">
<h4><?php esc_html_e('Payment Status', 'doccure_core'); ?>:</h4>
<div class="payment-action">
<span class="payment-status pending"><?php esc_html_e('Pending Payment', 'doccure_core'); ?></span>
<a href="<?php echo esc_url($payment_url); ?>" class="dc-btn btn-primary payment-btn"
target="_blank">
<?php esc_html_e('Complete Payment', 'doccure_core'); ?>
</a>
</div>
</div>
</div>
<?php } elseif (!empty($order_id)) {
$order = wc_get_order($order_id);
if ($order) {
$order_status = $order->get_status();
$can_manage_order = current_user_can('manage_options') || $user_type_access === 'doctors' || $user_type_access === 'doctors_staff' || $user_type_access === 'administrator' || $user_type_access === 'staff';
?>
<div class="dc-user-info dc-payment-status">
<div class="dc-title">
<h4><?php esc_html_e('Payment Status', 'doccure_core'); ?>:</h4>
<?php if ($can_manage_order) { ?>
<div class="order-status-editor">
<select id="order-status-dropdown" class="form-control form-select order-status-dropdown"
data-booking-id="<?php echo intval($booking_id); ?>"
data-order-id="<?php echo intval($order_id); ?>">
<?php
$allowed_statuses = array(
'pending' => __('Pending', 'doccure_core'),
'processing' => __('Processing', 'doccure_core'),
'on-hold' => __('On hold', 'doccure_core'),
'completed' => __('Completed', 'doccure_core'),
'cancelled' => __('Cancelled', 'doccure_core'),
'refunded' => __('Refunded', 'doccure_core'),
'failed' => __('Failed', 'doccure_core'),
);
foreach ($allowed_statuses as $key => $label) {
echo '<option value="' . esc_attr($key) . '" ' . selected($order_status, $key, false) . '>' . esc_html($label) . '</option>';
}
?>
</select>
<small
class="text-muted d-block mt-1"><?php esc_html_e('Change payment status', 'doccure_core'); ?></small>
</div>
<?php } else { ?>
<span class="payment-status <?php echo esc_attr($order_status); ?>">
<?php echo esc_html(ucfirst($order_status)); ?>
</span>
<?php } ?>
</div>
</div>
<?php if ($can_manage_order) { ?>
<script>
(function ($) {
var AJAX_URL = '<?php echo esc_js(admin_url('admin-ajax.php')); ?>';
var NONCE = '<?php echo esc_js(wp_create_nonce('ajax_nonce')); ?>';
$(document).off('change', '#order-status-dropdown').on('change', '#order-status-dropdown', function () {
var $el = $(this);
var orderId = $el.data('order-id');
var bookingId = $el.data('booking-id');
var newStatus = $el.val();
$el.prop('disabled', true);
$.post(AJAX_URL, {
action: 'doccure_update_order_status_in_booking',
security: NONCE,
order_id: orderId,
booking_id: bookingId,
status: newStatus
}).done(function (resp) {
// optionally show success toast
}).fail(function () {
alert('<?php echo esc_js(__('Failed to update status. Please try again.', 'doccure_core')); ?>');
}).always(function () {
$el.prop('disabled', false);
});
});
})(jQuery);
</script>
<?php } ?>
<?php }
} ?>
<?php } ?>
</div>
</div>
<?php } else {
$doctor_id = get_post_meta($booking_id, '_doctor_id', true);
$name = doccure_full_name($doctor_id);
$name = !empty($name) ? $name : '';
$thumbnail = doccure_prepare_thumbnail($doctor_id, $width, $height);
$email = get_post_meta($booking_id, 'bk_email', true);
$phone = get_post_meta($booking_id, 'bk_phone', true);
$location = doccure_get_location($doctor_id);
$country = !empty($location['_country']) ? $location['_country'] : ''; ?>
<div class="appointment-wrap appointment-detail-card">
<ul class="mb-0 p-0">
<li>
<div class="patinet-information">
<?php if (!empty($thumbnail)) { ?>
<a href="#">
<img src="<?php echo esc_url($thumbnail); ?>" alt="<?php echo esc_attr($name); ?>">
</a>
<?php } ?>
<div class="patient-info">
<p>#<?php echo intval($booking_id); ?></p>
<h6><a href="#"><?php if (!empty($name)) { ?><?php echo esc_html($name); ?><?php } ?></a></h6>
<div class="mail-info-patient">
<ul class="mb-0 ps-0">
<?php if (!empty($email)) { ?>
<li><i class="isax isax-sms5"></i> <?php echo esc_html($email); ?></li>
<?php } ?>
<?php if (!empty($phone)) { ?>
<li><i class="isax isax-call5"></i> <?php echo esc_html($phone); ?></li>
<?php } ?>
</ul>
</div>
</div>
</div>
</li>
<li class="appointment-action">
<?php if (!empty($post_status)) { ?>
<div class="detail-badge-info">
<span class="badge bg-secondary"><?php echo esc_html(ucwords($post_status)); ?></span>
</div>
<?php } ?>
<?php if (isset($consultant_fee)) { ?>
<div class="consult-fees">
<h6><?php esc_html_e('Consultation Fees', 'doccure_core'); ?> :
<?php doccure_price_format($consultant_fee); ?>
</h6>
</div>
<?php } ?>
</li>
</ul>
<ul class="detail-card-bottom-info mb-0 ps-0">
<?php if (!empty($appointment_date) && !empty($slots)) { ?>
<li>
<h6 class="mb-0"><?php esc_html_e('Appointment Date & Time', 'doccure_core'); ?></h6>
<span><?php echo date_i18n($date_format, strtotime($appointment_date)); ?> -
<?php echo esc_html($slots); ?></span>
</li>
<?php } ?>
<?php if (!empty($location_title)) { ?>
<li>
<h6 class="mb-0"><?php esc_html_e('Clinic Location', 'doccure_core'); ?></h6>
<span><?php echo esc_html($location_title); ?></span>
</li>
<?php } ?>
<?php if (!empty($location_title)) { ?>
<li>
<h6 class="mb-0"><?php esc_html_e('Location', 'doccure_core'); ?></h6>
<span><?php echo esc_html($location_title); ?></span>
</li>
<?php } ?>
<li>
<h6 class="mb-0"><?php esc_html_e('Visit Type', 'doccure_core'); ?></h6>
<span><?php esc_html_e('General', 'doccure_core'); ?></span>
</li>
<li>
<?php if (!empty($post_status)) { ?>
<div class="dc-status-test start-btn">
<div class="dc-rightarea dc-status">
<?php if (is_user_logged_in() && ($user_type_access === 'doctors' || $user_type_access === 'hospitals' || $user_type_access === 'regular_users' || $user_type_access === 'staff')) { ?>
<div class="dc-user-steps_old">
<div class="dc-btnarea toolip-wrapo dc-print-options_old">
<?php
if (!empty($booking_id) && !empty($current_user_type)) {
// Generate Chat URL (common for all users)
$base_url = get_site_url() . "/dashboard/";
$user_identity = $current_user->ID;
$full_url = $base_url . "?ref=chat&identity=" . $user_identity;
// Doctors & Hospitals - Full Access
if ($user_type_access === 'doctors' || $user_type_access === 'hospitals' || $user_type_access === 'staff') {
if ($post_status_key === 'pending') { ?>
<a href="javascript:;"
class="dc-btn_old btn btn-md rounded-pill btn-primary-gradient dc-update-status btn btn-sm bg-success-light"
data-status="publish" data-id="<?php echo intval($booking_id); ?>">
<i class="fas fa-check"></i><?php esc_html_e('Accept', 'doccure_core'); ?>
</a>
<a href="javascript:;"
class="dc-btn_old btn btn-md rounded-pill btn-primary-gradient dc-deleteinfo dc-update-status btn btn-sm bg-danger-light"
data-status="cancelled" data-id="<?php echo intval($booking_id); ?>">
<i class="fas fa-times"></i><?php esc_html_e('Cancel', 'doccure_core'); ?>
</a>
<?php }
// Add Prescription - only for Doctors/Hospitals
if ($post_status_key === 'publish' && !empty($hide_prescription) && $hide_prescription == 'no') { ?>
<a href="<?php echo esc_url($prescription_url); ?>"
class="dc-btn_old btn btn-md rounded-pill btn-primary-gradient dc-filebtn add-new-btn generate-prescription">
<?php esc_html_e('Add Prescription', 'doccure_core'); ?>
</a>
<?php }
// Common: View, Download, and Chat
if (!empty($prescription_id)) { ?>
<form method="post" name="download_pdf">
<input type="hidden" name="pdf_booking_id" value="<?php echo intval($booking_id); ?>">
<a href="javascript:;" onclick="document.forms['download_pdf'].submit(); return false;"
class="dc-btn_old btn btn-md rounded-pill btn-primary-gradient add-new-btn dc-pdfbtn">
<?php esc_html_e('Download Prescription', 'doccure_core'); ?>
</a>
</form>
<a href="javascript:;"
class="dc-btn_old btn btn-md rounded-pill btn-primary-gradient add-new-btn dc-viewbtn view-prescription-btn"
data-booking-id="<?php echo intval($booking_id); ?>">
<?php esc_html_e('View Prescription', 'doccure_core'); ?>
</a>
<?php } ?>
<a href="javascript:;"
onclick="window.open('<?php echo esc_url($full_url); ?>', '_blank'); return false;"
class="dc-btn_old btn btn-md rounded-pill btn-primary-gradient add-new-btn dc-chatbtn">
<?php esc_html_e('Chat', 'doccure_core'); ?>
</a>
<?php
// Staff - View, Download, and Chat
} elseif ($user_type_access === 'staff') {
if (!empty($prescription_id)) { ?>
<form method="post" name="download_pdf">
<input type="hidden" name="pdf_booking_id" value="<?php echo intval($booking_id); ?>">
<a href="javascript:;" onclick="document.forms['download_pdf'].submit(); return false;"
class="dc-btn_old btn btn-md rounded-pill btn-primary-gradient add-new-btn dc-pdfbtn">
<?php esc_html_e('Download Prescription', 'doccure_core'); ?>
</a>
</form>
<a href="javascript:;"
class="dc-btn_old btn btn-md rounded-pill btn-primary-gradient add-new-btn dc-viewbtn view-prescription-btn"
data-booking-id="<?php echo intval($booking_id); ?>">
<?php esc_html_e('View Prescription', 'doccure_core'); ?>
</a>
<?php } ?>
<a href="javascript:;"
onclick="window.open('<?php echo esc_url($full_url); ?>', '_blank'); return false;"
class="dc-btn_old btn btn-md rounded-pill btn-primary-gradient add-new-btn dc-chatbtn">
<?php esc_html_e('Chat', 'doccure_core'); ?>
</a>
<?php
// Regular Users - View, Download, Chat
} elseif ($user_type_access === 'regular_users' || $user_type_access === 'staff') { ?>
<a href="javascript:;"
onclick="window.open('<?php echo esc_url($full_url); ?>', '_blank'); return false;"
class="dc-btn_old btn btn-md rounded-pill btn-primary-gradient add-new-btn dc-chatbtn">
<?php esc_html_e('Chat', 'doccure_core'); ?>
</a>
<?php if (!empty($prescription_id)) { ?>
<form method="post" name="download_pdf">
<input type="hidden" name="pdf_booking_id" value="<?php echo intval($booking_id); ?>">
<a href="javascript:;" onclick="document.forms['download_pdf'].submit(); return false;"
class="dc-btn_old btn btn-md rounded-pill btn-primary-gradient add-new-btn dc-pdfbtn">
<?php esc_html_e('Download Prescription', 'doccure_core'); ?>
</a>
</form>
<a href="javascript:;"
class="dc-btn_old btn btn-md rounded-pill btn-primary-gradient add-new-btn dc-viewbtn view-prescription-btn"
data-booking-id="<?php echo intval($booking_id); ?>">
<?php esc_html_e('View Prescription', 'doccure_core'); ?>
</a>
<?php }
}
}
?>
<?php
// Meeting button - Available for all user types when conditions are met
$get_order_id = get_post_meta($booking_id, '_order_id', true);
if (empty($get_order_id)) {
$get_order_id = get_post_meta($booking_id, '_product_rand_offline', true);
}
global $wpdb;
$table_name = $wpdb->prefix . 'zoom_links';
$meeting_link = $wpdb->get_row($wpdb->prepare("SELECT * FROM $table_name WHERE order_id = %d", $get_order_id));
$post_status_reschedule = get_post_status($booking_id);
if ($post_status_reschedule == 'publish' && $meeting_link->meeting_id != '') { ?>
<a class="dc-btn_old meeting_button btn btn btn-md rounded-pill btn-primary-gradient dc-btn-blocks dc-filebtn"
href="<?php echo esc_attr($meeting_link->meeting_id); ?>"
target="_blank"><?php esc_html_e('Join Meeting', 'doccure_core'); ?></a>
<?php } ?>
</div>
</div>
<?php } ?>
</div>
</div>
<?php } ?>
</li>
</ul>
</div>
<?php } ?>
<!-- Modal -->
<div class="modal fade dc-appointmentpopup dc-feedbackpopup dc-bookappointment" role="dialog" id="send_message">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="dc-modalcontent modal-content">
<div class="dc-popuptitle">
<h3><?php esc_html_e('Send Message', 'doccure_core'); ?></h3>
<a href="javascript:;" class="dc-closebtn close dc-close" data-bs-dismiss="modal"
aria-label="<?php esc_attr_e('Close', 'doccure_core'); ?>"><i class="ti-close"></i></a>
</div>
<div class="dc-formtheme dc-vistingdocinfo">
<fieldset>
<div class="form-group">
<textarea id="dc-booking-msg" class="form-control"
placeholder="<?php esc_attr_e('Message', 'doccure_core'); ?>" name="message"></textarea>
</div>
</fieldset>
</div>
<div class="modal-footer dc-modal-footer">
<a href="javascript:;" class="btn dc-btn btn-primary dc-send_message-btn"
data-id="<?php echo intval($booking_id); ?>"><?php esc_html_e('Send', 'doccure_core'); ?></a>
</div>
</div>
</div>
</div>
<?php
$booking = ob_get_clean();
$json['type'] = 'success';
$json['booking_data'] = $booking;
} else {
$json['type'] = 'error';
$json['message'] = esc_html__('No more review', 'doccure_core');
$json['reviews'] = 'null';
}
wp_send_json($json);
}
add_action('wp_ajax_doccure_get_booking_byID', 'doccure_get_booking_byID');
add_action('wp_ajax_nopriv_doccure_get_booking_byID', 'doccure_get_booking_byID');
}
if (!function_exists('doccure_get_booking_byID_Admin')) {
function doccure_get_booking_byID_Admin()
{
global $current_user, $doccure_options;
$json = array();
$booking_id = !empty($_POST['id']) ? intval($_POST['id']) : '';
$is_dashboard = !empty($_POST['dashboard']) ? esc_html($_POST['dashboard']) : '';
$is_type = !empty($_POST['type']) ? esc_html($_POST['type']) : '';
$hide_prescription = !empty($doccure_options['hide_prescription']) ? esc_html($doccure_options['hide_prescription']) : 'no';
$url_identity = $current_user->ID;
if (function_exists('doccure_validate_user')) {
doccure_validate_user();
} //if user is logged in
if (!empty($is_type) && $is_type === 'patient') {
if (function_exists('doccure_validate_privileges')) {
doccure_validate_privileges($booking_id);
} //if user is logged in and have privileges
} else if (!empty($is_type) && $is_type === 'doctor') {
$doctor_id = get_post_meta($booking_id, '_doctor_id', true);
$doctor_user_id = doccure_get_linked_profile_id($doctor_id, 'post');
if (isset($doctor_user_id) && intval($doctor_user_id) !== $current_user->ID) {
$json['type'] = 'error';
$json['message'] = esc_html__('You are not authorized to view this booking details', 'doccure_core');
wp_send_json($json);
}
} else {
if (!is_admin()) {
$data = get_userdata($current_user->ID);
if (isset($data->roles) && is_array($data->roles) && in_array('administrator', $data->roles)) {
//do nothing
} else {
$json['type'] = 'error';
$json['message'] = esc_html__('You are not authorized to view this booking details', 'doccure_core');
wp_send_json($json);
}
}
}
//security check
$do_check = check_ajax_referer('ajax_nonce', 'security', false);
if ($do_check == false) {
$json['type'] = 'error';
$json['message'] = esc_html__('Security check failed, this could be because of your browser cache. Please clear the cache and check it againe', 'doccure_core');
wp_send_json($json);
}
$width = 100;
$height = 100;
$current_user_type = apply_filters('doccure_get_user_type', $url_identity);
if (!empty($booking_id)) {
ob_start();
$date_format = get_option('date_format');
$time_format = get_option('time_format');
$doctor_id = get_post_meta($booking_id, '_doctor_id', true);
$booking_date = get_post_meta($booking_id, '_am_booking', true);
$hospital_id = get_post_meta($booking_id, '_booking_hospitals', true);
$slots = get_post_meta($booking_id, '_booking_slot', true);
$slots = !empty($slots) ? explode('-', $slots) : '';
$tine_slot = $slots;
if (!empty($slots)) {
$slots = date($time_format, strtotime('2016-01-01' . $slots[0]));
}
$user_types = doccure_list_user_types();
$content = get_post_field('post_content', $booking_id);
$contents = !empty($content) ? $content : '';
$booking_slot = get_post_meta($booking_id, '_booking_slot', true);
$booking_slot = !empty($booking_slot) ? $booking_slot : '';
$services = get_post_meta($booking_id, '_booking_service', true);
$services = !empty($services) ? $services : array();
$post_auter = get_post_field('post_author', $booking_id);
$booking_user_type = get_post_meta($booking_id, '_user_type', true);
$thumbnail = '';
$booking_array = get_post_meta($booking_id, '_am_booking', true);
$total_price = !empty($booking_array['_price']) ? $booking_array['_price'] : 0;
$consultant_fee = !empty($booking_array['_consultant_fee']) ? $booking_array['_consultant_fee'] : 0;
if (empty($booking_user_type) || $booking_user_type === 'regular_users') {
$link_id = doccure_get_linked_profile_id($post_auter);
$thumbnail = doccure_prepare_thumbnail($link_id, $width, $height);
$user_type = apply_filters('doccure_get_user_type', $post_auter);
$user_type = $user_types[$user_type];
$user_type = !empty($user_type) ? $user_type : '';
$location = doccure_get_location($link_id);
$country = !empty($location['_country']) ? $location['_country'] : '';
} else {
$am_booking = get_post_meta($booking_id, '_am_booking', true);
$user_type = !empty($am_booking['_user_details']['user_type']) ? $am_booking['_user_details']['user_type'] : '';
}
$name = get_post_meta($booking_id, 'bk_username', true);
$email = get_post_meta($booking_id, 'bk_email', true);
$phone = get_post_meta($booking_id, 'bk_phone', true);
$name = !empty($name) ? $name : '';
$email = !empty($email) ? $email : '';
$phone = !empty($phone) ? $phone : '';
$post_status = get_post_status($booking_id);
$post_status_key = $post_status;
if ($post_status === 'pending') {
$post_status = esc_html__('Pending', 'doccure_core');
} elseif ($post_status === 'publish') {
$post_status = esc_html__('Confirmed', 'doccure_core');
} elseif ($post_status === 'draft') {
$post_status = esc_html__('Pending', 'doccure_core');
} elseif ($post_status === 'cancelled') {
$post_status = esc_html__('Cancelled', 'doccure_core');
}
$relation = doccure_patient_relationship();
$posttype = get_post_type($hospital_id);
if (!empty($posttype) && $posttype === 'hospitals_team') {
$hospital_id = get_post_meta($hospital_id, 'hospital_id', true);
$location_title = esc_html(get_the_title($hospital_id));
} else {
$location_title = esc_html(get_the_title($hospital_id));
}
$am_specialities = doccure_get_post_meta($doctor_id, 'am_specialities');
$am_specialities = !empty($am_specialities) ? $am_specialities : array();
$google_calender = '';
$yahoo_calender = '';
$appointment_date = get_post_meta($booking_id, '_appointment_date', true);
if (!empty($appointment_date) && !empty($tine_slot[0]) && !empty($tine_slot[1])) {
$startTime = new DateTime($appointment_date . ' ' . $tine_slot[0]);
$startTime = $startTime->format('Y-m-d H:i');
$endTime = new DateTime($appointment_date . ' ' . $tine_slot[1]);
$endTime = $endTime->format('Y-m-d H:i');
$google_calender = doccure_generate_GoogleLink($name, $startTime, $endTime, $contents, $location_title);
$yahoo_calender = doccure_generate_YahooLink($name, $startTime, $endTime, $contents, $location_title);
}
$doctor_user_id = doccure_get_linked_profile_id($doctor_id, 'post');
if (!empty($user_type) && $user_type === 'patients') {
$user_type_title = esc_html__('patient', 'doccure_core');
} else {
$user_type_title = $user_type;
}
$prescription_id = get_post_meta($booking_id, '_prescription_id', true);
$prescription_url = !empty($booking_id) ? doccure_Profile_Menu::doccure_profile_menu_link('prescription', $current_user->ID, true, 'view') . '&booking_id=' . $booking_id : '';
$user_type_access = apply_filters('doccure_get_user_type', $current_user->ID);
?>
<div class="dc-user-header">
<?php if (!empty($thumbnail)) { ?>
<div>
<figure class="dc-user-img">
<img src="<?php echo esc_url($thumbnail); ?>" alt="<?php echo esc_attr($name); ?>">
</figure>
</div>
<?php } ?>
<div class="dc-title pateintview-details">
<?php if (!empty($name)) { ?>
<h3>
<?php
echo esc_html($name);
if (!empty($post_auter) && $post_auter != 1) {
doccure_get_verification_check($post_auter);
}
?>
</h3>
<h5>
<?php if (!empty($email)) { ?>
<i class="far fa-envelope"></i> <?php echo esc_html($email); ?>
<?php } ?>
</h5>
<h5>
<?php if (!empty($phone)) { ?>
<i class="fas fa-phone"></i> <?php echo esc_html($phone); ?>
<?php } ?>
</h5>
<?php } ?>
<h5>
<?php if (!empty($post_auter) && $post_auter != 1) { ?>
<i class="feather-map-pin"></i> <?php echo esc_html($country); ?>
<?php } ?>
</h5>
</div>
<?php if (!empty($post_status)) { ?>
<div class="dc-status-test">
<div class="dc-rightarea dc-status">
<span><?php echo esc_html(ucwords($post_status)); ?></span>
<em><?php esc_html_e('Status', 'doccure_core'); ?></em>
<!-- status links -->
<?php if (is_user_logged_in() && ($user_type_access === 'doctors' || $user_type_access === 'hospitals' || $user_type_access === 'regular_users' || $user_type_access === 'staff')) { ?>
<div class="dc-user-steps">
<div class="dc-btnarea toolip-wrapo dc-print-options">
<?php if (!empty($booking_id) && !empty($current_user_type)) {
if ($post_status_key === 'pending') { ?>
<a href="javascript:;" class="dc-btn dc-update-status btn btn-sm bg-success-light"
data-status="publish" data-id="<?php echo intval($booking_id); ?>"><i
class="fas fa-check"></i><?php esc_html_e('Accept', 'doccure_core'); ?></a>
<a href="javascript:;" class="dc-btn dc-deleteinfo dc-update-status btn btn-sm bg-danger-light"
data-status="cancelled" data-id="<?php echo intval($booking_id); ?>"><i
class="fas fa-times"></i><?php esc_html_e('Cancel', 'doccure_core'); ?></a>
<?php }
if ($post_status_key === 'publish' && !empty($hide_prescription) && $hide_prescription == 'no') { ?>
<a href="<?php echo esc_url($prescription_url); ?>"
class="dc-btn dc-filebtn add-new-btn generate-prescription"><?php esc_html_e('Add Prescription', 'doccure_core'); ?></a>
<?php if (!empty($prescription_id)) { ?>
<form method="post" name="download_pdf">
<input type="hidden" name="pdf_booking_id" value="<?php echo intval($booking_id); ?>">
<a href="javascript:;" onclick="document.forms['download_pdf'].submit(); return false;"
class="dc-btn add-new-btn dc-pdfbtn"><?php esc_html_e('Download Prescription', 'doccure_core'); ?></a>
</form>
<a href="javascript:;" class="dc-btn add-new-btn dc-viewbtn view-prescription-btn"
data-booking-id="<?php echo intval($booking_id); ?>"><?php esc_html_e('View Prescription', 'doccure_core'); ?></a>
<?php } ?>
<?php }
} else if ($is_dashboard === 'yes' && !empty($current_user_type)) { ?>
<?php if (!empty($prescription_id)) { ?>
<form method="post" name="download_pdf">
<input type="hidden" name="pdf_booking_id" value="<?php echo intval($booking_id); ?>">
<a href="javascript:;" onclick="document.forms['download_pdf'].submit(); return false;"
class="dc-btn add-new-btn dc-pdfbtn"><?php esc_html_e('Download Prescription', 'doccure_core'); ?></a>
</form>
<?php } ?>
<?php } ?>
</div>
</div>
<?php } ?>
<!-- ends status links -->
</div>
</div>
<?php } ?>
</div>
<div class="dc-user-details">
<div class="dc-user-grid">
<?php if (!empty($booking_date['_with_patient']['other_name'])) { ?>
<div class="dc-user-info dc-person-patient">
<div class="dc-title">
<h4><?php esc_html_e('Person with patient', 'doccure_core'); ?> :</h4>
<span><?php echo esc_html($booking_date['_with_patient']['other_name']); ?></span>
</div>
</div>
<?php } ?>
<?php if (!empty($booking_date['_with_patient']['relation'])) { ?>
<div class="dc-user-info dc-person-relation">
<div class="dc-title">
<h4><?php esc_html_e('Relation with patient', 'doccure_core'); ?> :</h4>
<span><?php echo esc_html($relation[$booking_date['_with_patient']['relation']]); ?></span>
</div>
</div>
<?php } ?>
<?php if (!empty($location_title)) { ?>
<div class="dc-user-info dc-location-title">
<div class="dc-title">
<h4><?php esc_html_e('Appointment location', 'doccure_core'); ?> :</h4>
<span><?php echo esc_html($location_title); ?></span>
</div>
</div>
<?php } ?>
<?php if (!empty($appointment_date) && !empty($slots)) { ?>
<div class="dc-user-info dc-apt-detail-date">
<div class="dc-title">
<h4><?php esc_html_e('Appointment date', 'doccure_core'); ?> :</h4>
<span><?php echo date_i18n($date_format, strtotime($appointment_date)); ?> -
<?php echo esc_html($slots); ?> </span>
</div>
</div>
<?php } ?>
<?php if (!empty($services)) { ?>
<div class="dc-user-info dc-info-required dc-services-wrap">
<div class="dc-title">
<h4><?php esc_html_e('Services required', 'doccure_core'); ?>:</h4>
</div>
<?php
foreach ($services as $spe => $sers) {
if (!empty($spe)) { ?>
<div class="dc-spec-wrap">
<div class="dc-title">
<span><?php echo doccure_get_term_name($spe, 'specialities'); ?></span>
</div>
<?php if (!empty($sers)) { ?>
<ul class="dc-required-details">
<?php foreach ($sers as $k => $val) {
$single_price = 0;
if (!empty($k) && $k === $val) {
$am_specialities = !empty($doctor_id) ? doccure_get_post_meta($doctor_id, 'am_specialities') : array();
$am_specialities = !empty($am_specialities) ? $am_specialities : array();
$single_price = !empty($am_specialities[$spe][$k]['price']) ? $am_specialities[$spe][$k]['price'] : 0;
} else {
$single_price = $val;
}
?>
<li>
<span>
<?php
echo doccure_get_term_name($k, 'services');
if (!empty($single_price)) { ?>
<em>(<?php doccure_price_format($single_price); ?>)</em>
<?php } ?>
</span>
</li>
<?php } ?>
</ul>
<?php } ?>
</div>
<?php } ?>
<?php } ?>
</div>
<?php } ?>
<?php if (!empty($contents)) { ?>
<div class="dc-required-info dc-apt-comments">
<div class="dc-title">
<h4><?php esc_html_e('Comments', 'doccure_core'); ?></h4>
</div>
<div class="dc-description">
<p><?php echo esc_html($contents); ?></p>
</div>
</div>
<?php } ?>
<?php if (isset($consultant_fee)) { ?>
<div class="dc-user-info dc-apt-consult-fee">
<div class="dc-title">
<h4><?php esc_html_e('Consultant fee', 'doccure_core'); ?> :</h4>
<span><?php doccure_price_format($consultant_fee); ?></span>
</div>
</div>
<?php } ?>
<?php if (!empty($total_price)) { ?>
<div class="dc-user-info dc-total-fee">
<div class="dc-title">
<h4><?php esc_html_e('Total price', 'doccure_core'); ?>:</h4>
<span>
<?php doccure_price_format($total_price); ?>
</span>
</div>
</div>
<?php } ?>
</div>
</div>
<!-- Modal -->
<div class="modal fade dc-appointmentpopup dc-feedbackpopup dc-bookappointment" role="dialog" id="send_message">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="dc-modalcontent modal-content">
<div class="dc-popuptitle">
<h3><?php esc_html_e('Send Message', 'doccure_core'); ?></h3>
<a href="javascript:;" class="dc-closebtn close dc-close" data-bs-dismiss="modal"
aria-label="<?php esc_attr_e('Close', 'doccure_core'); ?>"><i class="ti-close"></i></a>
</div>
<div class="dc-formtheme dc-vistingdocinfo">
<fieldset>
<div class="form-group">
<textarea id="dc-booking-msg" class="form-control"
placeholder="<?php esc_attr_e('Message', 'doccure_core'); ?>" name="message"></textarea>
</div>
</fieldset>
</div>
<div class="modal-footer dc-modal-footer">
<a href="javascript:;" class="btn dc-btn btn-primary dc-send_message-btn"
data-id="<?php echo intval($booking_id); ?>"><?php esc_html_e('Send', 'doccure_core'); ?></a>
</div>
</div>
</div>
</div>
<?php
$booking = ob_get_clean();
$json['type'] = 'success';
$json['booking_data'] = $booking;
} else {
$json['type'] = 'error';
$json['message'] = esc_html__('No more review', 'doccure_core');
$json['reviews'] = 'null';
}
wp_send_json($json);
}
add_action('wp_ajax_doccure_get_booking_byID_Admin', 'doccure_get_booking_byID_Admin');
add_action('wp_ajax_nopriv_doccure_get_booking_byID_Admin', 'doccure_get_booking_byID_Admin');
}
// View Prescription Modal HTML
function doccure_view_prescription_modal_html()
{
?>
<!-- View Prescription Modal -->
<div class="modal fade dc-appointmentpopup dc-feedbackpopup dc-bookappointment" role="dialog"
id="view_prescription_modal">
<div class="modal-dialog modal-dialog-centered modal-lg" role="document">
<div class="dc-modalcontent modal-content">
<div class="dc-formtheme dc-vistingdocinfo">
<div class="prescription-view-content">
<div class="prescription-loading" style="display: none;">
<div class="text-center">
<i class="fas fa-spinner fa-spin fa-2x"></i>
<p><?php esc_html_e('Loading prescription details...', 'doccure_core'); ?></p>
</div>
</div>
<div class="prescription-content">
<div class="prescription-details">
<!-- Prescription details will be loaded here -->
</div>
</div>
</div>
</div>
<div class="dc-modal-footer">
<div class="prescription-actions">
<button type="button" class="dc-btn add-new-btn dc-printbtn print-prescription"
style="display: none;">
<i class="fas fa-print"></i> <?php esc_html_e('Print', 'doccure_core'); ?>
</button>
</div>
</div>
</div>
</div>
</div>
<?php
}
// Add modal to footer
add_action('wp_footer', 'doccure_view_prescription_modal_html');
add_action('admin_footer', 'doccure_view_prescription_modal_html');
// AJAX handler for view prescription modal
if (!function_exists('doccure_get_view_prescription_content')) {
function doccure_get_view_prescription_content()
{
// Security check
$do_check = check_ajax_referer('doccure_view_prescription_nonce', 'security', false);
if ($do_check == false) {
$json['type'] = 'error';
$json['message'] = esc_html__('Security check failed', 'doccure_core');
wp_send_json($json);
}
// User validation
if (function_exists('doccure_validate_user')) {
doccure_validate_user();
}
$booking_id = !empty($_POST['booking_id']) ? intval($_POST['booking_id']) : '';
if (empty($booking_id)) {
$json['type'] = 'error';
$json['message'] = esc_html__('Invalid booking ID', 'doccure_core');
wp_send_json($json);
}
// Check if prescription exists
$prescription_id = get_post_meta($booking_id, '_prescription_id', true);
if (empty($prescription_id)) {
$json['type'] = 'error';
$json['message'] = esc_html__('No prescription found for this booking', 'doccure_core');
wp_send_json($json);
}
// Get prescription details
$prescription_details = get_post_meta($prescription_id, '_detail', true);
$prescription_details = !empty($prescription_details) ? $prescription_details : array();
// Get doctor information
$doctor_id = get_post_meta($prescription_id, '_doctor_id', true);
$doctor_profile_id = !empty($doctor_id) ? doccure_get_linked_profile_id($doctor_id) : '';
$doctor_name = doccure_full_name($doctor_profile_id);
// Get patient information
$patient_name = !empty($prescription_details['_patient_name']) ? $prescription_details['_patient_name'] : '';
$patient_age = !empty($prescription_details['_age']) ? $prescription_details['_age'] : '';
$patient_gender = !empty($prescription_details['_gender']) ? $prescription_details['_gender'] : '';
$patient_phone = !empty($prescription_details['_phone']) ? $prescription_details['_phone'] : '';
$patient_address = !empty($prescription_details['_address']) ? $prescription_details['_address'] : '';
$marital_status = !empty($prescription_details['_marital_status']) ? $prescription_details['_marital_status'] : '';
// Get medical information
$diseases = !empty($prescription_details['_diseases']) ? $prescription_details['_diseases'] : '';
$diagnosis = !empty($prescription_details['_medical_history']) ? $prescription_details['_medical_history'] : '';
$child_illness = !empty($prescription_details['_childhood_illness']) ? $prescription_details['_childhood_illness'] : '';
$vital_signs = !empty($prescription_details['_vital_signs']) ? $prescription_details['_vital_signs'] : '';
// Get detailed medicines
$medicines = !empty($prescription_details['_medicine']) ? $prescription_details['_medicine'] : array();
// Get appointment details
$appointment_date = get_post_meta($booking_id, '_appointment_date', true);
$slots = get_post_meta($booking_id, '_slots', true);
// Generate prescription HTML
ob_start();
?>
<div class="prescription-view-details">
<div class="prescription-header">
<h4><?php esc_html_e('Prescription Details', 'doccure_core'); ?></h4>
</div>
<div class="prescription-info">
<!-- Doctor Information -->
<div class="row">
<div class="col-md-12">
<div class="info-group">
<label><strong><?php esc_html_e('Doctor:', 'doccure_core'); ?></strong></label>
<p><?php echo esc_html($doctor_name); ?></p>
</div>
</div>
</div>
<!-- Patient Demographics -->
<div class="patient-section">
<h5 class="section-title"><?php esc_html_e('Patient Information', 'doccure_core'); ?></h5>
<div class="row">
<div class="col-md-6">
<div class="info-group">
<label><strong><?php esc_html_e('Name:', 'doccure_core'); ?></strong></label>
<p><?php echo esc_html($patient_name); ?></p>
</div>
<div class="info-group">
<label><strong><?php esc_html_e('Gender:', 'doccure_core'); ?></strong></label>
<p><?php echo esc_html($patient_gender === 'female' ? __('Female', 'doccure_core') : __('Male', 'doccure_core')); ?>
</p>
</div>
<div class="info-group">
<label><strong><?php esc_html_e('Phone:', 'doccure_core'); ?></strong></label>
<p><?php echo esc_html($patient_phone); ?></p>
</div>
</div>
<div class="col-md-6">
<div class="info-group">
<label><strong><?php esc_html_e('Age:', 'doccure_core'); ?></strong></label>
<p><?php echo esc_html($patient_age); ?> <?php esc_html_e('year', 'doccure_core'); ?></p>
</div>
<div class="info-group">
<label><strong><?php esc_html_e('Marital status:', 'doccure_core'); ?></strong></label>
<p><?php echo esc_html($marital_status); ?></p>
</div>
<div class="info-group">
<label><strong><?php esc_html_e('Address:', 'doccure_core'); ?></strong></label>
<p><?php echo esc_html($patient_address); ?></p>
</div>
</div>
</div>
</div>
<!-- Medical Information -->
<div class="medical-section">
<h5 class="section-title"><?php esc_html_e('Medical Information', 'doccure_core'); ?></h5>
<div class="row">
<div class="col-md-6">
<div class="info-group">
<label><strong><?php esc_html_e('Diseases:', 'doccure_core'); ?></strong></label>
<p>
<?php
if (!empty($diseases) && is_array($diseases)) {
$diseases_names = array();
foreach ($diseases as $disease_id) {
$term = get_term_by('id', $disease_id, 'diseases');
if (!empty($term)) {
$diseases_names[] = $term->name;
}
}
echo esc_html(implode(', ', $diseases_names));
} else {
echo esc_html($diseases);
}
?>
</p>
</div>
<div class="info-group">
<label><strong><?php esc_html_e('Diagnosis:', 'doccure_core'); ?></strong></label>
<p><?php echo esc_html($diagnosis); ?></p>
</div>
</div>
<div class="col-md-6">
<div class="info-group">
<label><strong><?php esc_html_e('Child illness:', 'doccure_core'); ?></strong></label>
<p>
<?php
if (!empty($child_illness) && is_array($child_illness)) {
$illness_names = array();
foreach ($child_illness as $illness_id) {
$term = get_term_by('id', $illness_id, 'childhood_illness');
if (!empty($term)) {
$illness_names[] = $term->name;
}
}
echo esc_html(implode(', ', $illness_names));
} else {
echo esc_html($child_illness);
}
?>
</p>
</div>
<div class="info-group">
<label><strong><?php esc_html_e('Vital signs:', 'doccure_core'); ?></strong></label>
<p>
<?php
if (!empty($vital_signs) && is_array($vital_signs)) {
$vital_signs_names = array();
foreach ($vital_signs as $key => $val) {
if (!empty($val)) {
$term = get_term_by('id', $key, 'vital_signs');
$sign_value = !empty($val['value']) ? $val['value'] : '';
$sign_name = !empty($term->name) ? $term->name : '';
if (!empty($sign_name) && !empty($sign_value)) {
$vital_signs_names[] = $sign_name . ' (' . $sign_value . ')';
}
}
}
echo esc_html(implode(', ', $vital_signs_names));
} else {
echo esc_html($vital_signs);
}
?>
</p>
</div>
</div>
</div>
<!-- Appointment Date -->
<?php if (!empty($appointment_date) && !empty($slots)) { ?>
<div class="row">
<div class="col-md-12">
<div class="info-group">
<label><strong><?php esc_html_e('Appointment Date:', 'doccure_core'); ?></strong></label>
<p><?php echo date_i18n(get_option('date_format'), strtotime($appointment_date)); ?> -
<?php echo esc_html($slots); ?>
</p>
</div>
</div>
</div>
<?php } ?>
<!-- Medications Table -->
<?php if (!empty($medicines)) { ?>
<div class="medication-section">
<h5 class="section-title"><?php esc_html_e('Medications', 'doccure_core'); ?></h5>
<div class="row">
<div class="col-md-12">
<div class="info-group p-0 mb-0">
<div class="table-responsive">
<table class="table table-bordered medicine-table m-0">
<thead>
<tr>
<th><?php esc_html_e('Name', 'doccure_core'); ?></th>
<th><?php esc_html_e('Types', 'doccure_core'); ?></th>
<th><?php esc_html_e('Duration', 'doccure_core'); ?></th>
<th><?php esc_html_e('Usage', 'doccure_core'); ?></th>
<th><?php esc_html_e('Details', 'doccure_core'); ?></th>
</tr>
</thead>
<tbody>
<?php
if (!empty($medicines) && is_array($medicines)) {
foreach ($medicines as $medicine) {
// Check if medicine is an array (detailed medicine) or string (simple medicine)
if (is_array($medicine)) {
$name = !empty($medicine['name']) ? $medicine['name'] : '';
$types = !empty($medicine['medicine_types']) ? $medicine['medicine_types'] : '';
$duration = !empty($medicine['medicine_duration']) ? $medicine['medicine_duration'] : '';
$usage = !empty($medicine['medicine_usage']) ? $medicine['medicine_usage'] : '';
$detail = !empty($medicine['detail']) ? $medicine['detail'] : '';
// Get term names for taxonomy fields
$types = doccure_get_term_name_from_id($types, 'medicine_types');
$duration = doccure_get_term_name_from_id($duration, 'medicine_duration');
$usage = doccure_get_term_name_from_id($usage, 'medicine_usage');
?>
<tr>
<td><?php echo esc_html($name); ?></td>
<td><?php echo esc_html($types); ?></td>
<td><?php echo esc_html($duration); ?></td>
<td><?php echo esc_html($usage); ?></td>
<td><?php echo esc_html($detail); ?></td>
</tr>
<?php
} else {
// Simple medicine string
?>
<tr>
<td><?php echo esc_html($medicine); ?></td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
<?php
}
}
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
<?php
$prescription_html = ob_get_clean();
$json['type'] = 'success';
$json['prescription_html'] = $prescription_html;
wp_send_json($json);
}
add_action('wp_ajax_doccure_get_view_prescription_content', 'doccure_get_view_prescription_content');
add_action('wp_ajax_nopriv_doccure_get_view_prescription_content', 'doccure_get_view_prescription_content');
}
// Helper function to get term name from taxonomy
function doccure_get_term_name_from_id($term_id, $taxonomy)
{
if (empty($term_id) || empty($taxonomy)) {
return '';
}
$term = get_term_by('id', $term_id, $taxonomy);
return !empty($term) ? $term->name : $term_id;
}
// Enqueue view prescription modal scripts and styles
function doccure_enqueue_view_prescription_scripts()
{
// Enqueue CSS
wp_enqueue_style(
'doccure-view-prescription-modal',
plugin_dir_url(__FILE__) . 'assets/css/view-prescription-modal.css',
array(),
doccureGlobalSettings::get_plugin_verion()
);
// Enqueue JavaScript
wp_enqueue_script(
'doccure-view-prescription-modal',
plugin_dir_url(__FILE__) . 'assets/js/view-prescription-modal.js',
array('jquery'),
doccureGlobalSettings::get_plugin_verion(),
true
);
// Localize script with multilingual strings
wp_localize_script('doccure-view-prescription-modal', 'doccure_view_obj', array(
'ajax_url' => admin_url('admin-ajax.php'),
'ajax_nonce' => wp_create_nonce('doccure_view_prescription_nonce'),
'error_message' => esc_html__('Error loading prescription details', 'doccure_core'),
'loading_text' => esc_html__('Loading...', 'doccure_core'),
'print_text' => esc_html__('Print', 'doccure_core'),
'print_error' => esc_html__('No prescription content to print', 'doccure_core')
));
}
add_action('wp_enqueue_scripts', 'doccure_enqueue_view_prescription_scripts');
add_action('admin_enqueue_scripts', 'doccure_enqueue_view_prescription_scripts');