' . esc_attr__( 'Click here', 'supportcandy' ) . '' ); ?>
array( 'relation' => 'AND', array( 'slug' => 'agent', 'compare' => '>', 'val' => 0, ), array( 'slug' => 'is_recurring', 'compare' => '=', 'val' => 0, ), array( 'slug' => 'holiday', 'compare' => 'BETWEEN', 'val' => array( $start_date->format( 'Y-m-d H:i:s' ), $end_date->format( 'Y-m-d H:i:s' ), ), ), ), ) )['results']; foreach ( $holidays as $holiday ) { $response[] = array( 'id' => $holiday->id, 'title' => $holiday->agent->name, 'start' => $holiday->holiday->format( 'Y-m-d' ), 'color' => '#f0932b', 'textColor' => '#ffffff', ); } // recurring. $sql = 'SELECT * FROM ' . $wpdb->prefix . 'psmsc_holidays WHERE '; $sql .= 'is_recurring=1 AND agent > 0 AND '; $sql .= "DATE_FORMAT(holiday, '%m-%d') BETWEEN '" . $start_date->format( 'm-d' ) . "' and '" . $end_date->format( 'm-d' ) . "'"; $results = $wpdb->get_results( $sql ); foreach ( $results as $holiday ) { $holiday = new WPSC_Holiday( $holiday->id ); $start = ''; if ( intval( $start_date->format( 'Y' ) ) == intval( $end_date->format( 'Y' ) ) ) { $start .= $start_date->format( 'Y' ) . '-' . $holiday->holiday->format( 'm-d' ); } elseif ( $holiday->holiday->format( 'm' ) == '12' ) { $start .= $start_date->format( 'Y' ) . '-' . $holiday->holiday->format( 'm-d' ); } else { $start .= $end_date->format( 'Y' ) . '-' . $holiday->holiday->format( 'm-d' ); } $response[] = array( 'id' => $holiday->id, 'title' => $holiday->agent->name, 'start' => $start, 'color' => '#eb4d4b', 'textColor' => '#ffffff', ); } wp_send_json( $response, 200 ); } /** * Add agent leaves modal * * @return void */ public static function get_add_agent_leaves() { if ( check_ajax_referer( 'wpsc_get_add_agent_leaves', '_ajax_nonce', false ) != 1 ) { wp_send_json_error( 'Unauthorised request!', 401 ); } if ( ! WPSC_Functions::is_site_admin() ) { wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); } $date_selected = isset( $_POST['dateSelected'] ) ? array_filter( array_map( 'sanitize_text_field', wp_unslash( $_POST['dateSelected'] ) ) ) : array(); if ( ! $date_selected ) { wp_send_json_error( 'Bad Request', 401 ); } $title = esc_attr( wpsc__( 'Add new', 'supportcandy' ) ); $unique_id = uniqid( 'wpsc_' ); ob_start(); ?>
$title, 'body' => $body, 'footer' => $footer, ); wp_send_json( $response, 200 ); } /** * Set add agent leaves * * @return void */ public static function set_add_agent_leaves() { if ( check_ajax_referer( 'wpsc_set_add_agent_leaves', '_ajax_nonce', false ) != 1 ) { wp_send_json_error( 'Unauthorised request!', 401 ); } global $wpdb; if ( ! WPSC_Functions::is_site_admin() ) { wp_send_json_error( 'Unauthorized', 400 ); } $date_selected = isset( $_POST['dateSelected'] ) ? sanitize_text_field( wp_unslash( $_POST['dateSelected'] ) ) : ''; $date_selected = $date_selected ? array_filter( array_map( 'sanitize_text_field', explode( ',', $date_selected ) ) ) : array(); if ( ! $date_selected ) { wp_send_json_error( 'Bad Request', 401 ); } $agents = isset( $_POST['agents'] ) ? array_filter( array_map( 'intval', wp_unslash( $_POST['agents'] ) ) ) : array(); if ( ! $agents ) { wp_send_json_error( 'Bad Request', 401 ); } $is_recurring = isset( $_POST['is-recurring'] ) ? intval( $_POST['is-recurring'] ) : ''; if ( ! is_numeric( $is_recurring ) ) { wp_send_json_error( 'Bad Request', 401 ); } foreach ( $date_selected as $date ) { $date = new DateTime( $date . ' 00:00:00' ); // delete non-recurring record if exists. $sql = "DELETE FROM {$wpdb->prefix}psmsc_holidays WHERE "; $sql .= 'agent IN(' . implode( ',', $agents ) . ') AND '; $sql .= 'is_recurring = 0 AND '; $sql .= "holiday = '" . $date->format( 'Y-m-d H:i:s' ) . "'"; $wpdb->query( $sql ); // delete recurring record if exists. $sql = "DELETE FROM {$wpdb->prefix}psmsc_holidays WHERE "; $sql .= 'agent IN(' . implode( ',', $agents ) . ') AND '; $sql .= 'is_recurring = 1 AND '; $sql .= "DATE_FORMAT(holiday, '%m-%d') = '" . $date->format( 'm-d' ) . "'"; $wpdb->query( $sql ); // add record. foreach ( $agents as $agent ) { WPSC_Holiday::insert( array( 'agent' => $agent, 'holiday' => $date->format( 'Y-m-d H:i:s' ), 'is_recurring' => $is_recurring, ) ); } } wp_die(); } /** * Delete agent leave * * @return void */ public static function delete_agent_leave() { if ( check_ajax_referer( 'wpsc_delete_agent_leave', '_ajax_nonce', false ) != 1 ) { wp_send_json_error( 'Unauthorised request!', 401 ); } if ( ! WPSC_Functions::is_site_admin() ) { wp_send_json_error( 'Unauthorized', 400 ); } $holiday_id = isset( $_POST['holidayId'] ) ? intval( $_POST['holidayId'] ) : 0; if ( ! $holiday_id ) { wp_send_json_error( 'Bad Request', 401 ); } $holiday = new WPSC_Holiday( $holiday_id ); if ( ! $holiday->id ) { wp_send_json_error( 'Bad Request', 401 ); } WPSC_Holiday::destroy( $holiday ); wp_die(); } } endif; WPSC_Agent_Leaves::init();