1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
<?php
include_once( 'orddd-common.php' );
class orddd_class_view_deliveries {
public static function orddd_view_calendar_orders_page() {
?>
<div class="wrap">
<h2><?php _e( 'Delivery Calendar', 'order-delivery-date' ); ?></h2>
<table>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<th><?php _e( 'Filter Deliveries by: ', 'order-delivery-date' ); ?></th>
<td>
<select class="orddd_filter_delivery_calendar" id="orddd_filter_delivery_calendar" name="orddd_filter_delivery_calendar" >
<option name="product" value="product"><?php _e( 'Products', 'order-delivery-date' ); ?></option>
<option name="order" value="order"><?php _e( 'Orders', 'order-delivery-date' ); ?></option>
</select>
<input type="hidden" id="prev_event_type" value="product"/>
</td>
<th><?php _e( 'Order Status: ', 'order-delivery-date' ); ?></th>
<td>
<?php $order_status = wc_get_order_statuses();
$default_order_status = ""; ?>
<select class="orddd_filter_by_order_status" id="orddd_filter_by_order_status" name="orddd_filter_by_order_status[]" multiple="multiple">
<?php foreach ( $order_status as $order_status_key => $order_status_name ) {
if ( $order_status_key == 'wc-pending' || $order_status_key == 'wc-processing' || $order_status_key == 'wc-on-hold' || $order_status_key == 'wc-completed' ) {?>
<option name="<?php echo $order_status_name;?>" value="<?php echo $order_status_key;?>" selected><?php echo $order_status_name; ?></option>
<?php
$default_order_status .= $order_status_key . ",";
} else if( $order_status_key != 'wc-cancelled' && $order_status_key != 'wc-refunded' && $order_status_key != 'wc-failed' ) {?>
<option name="<?php echo $order_status_name;?>" value="<?php echo $order_status_key;?>" selected><?php echo $order_status_name; ?></option>
<?php
$default_order_status .= $order_status_key . ",";
}
}
?>
</select>
<?php $default_order_status = substr( $default_order_status, 0, strlen($default_order_status)-1 );?>
<input type="hidden" id="prev_order_status" value="<?php echo $default_order_status;?>"/>
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</table>
<div id="orddd_events_loader">Loading Calendar Events....<img src=<?php echo plugins_url() . "/order-delivery-date/images/ajax-loader.gif"; ?>></div>
<div id='calendar'></div>
</br>
<div><?php _e( '* Orders that are imported from the ICS feed URL will not be displayed on the calendar under "Products" view until the products are added for those orders. Such orders will however continue to show on the calendar in the "Orders" view.', 'order-delivery-date' );?></div>
</br><?php
$gcal = new OrdddGcal();
if( $gcal->get_api_mode() == "directly" && get_option( 'orddd_admin_add_to_calendar_delivery_calendar' ) == 'on' ) {
$total_orders_to_export = orddd_common::orddd_get_total_orders_to_export();
?>
<div id="orddd_add_to_calendar">
<input type="button" id="orddd_admin_add_to_calendar_delivery" value="<?php _e( 'Add to Google Calendar', 'order-delivery-date' ); ?>">
<div id="orddd_update_event_message"></div>
</div>
<script type="text/javascript">
jQuery( document ).ready( function(){
jQuery( "#orddd_admin_add_to_calendar_delivery" ).on( 'click', function() {
var orders_to_export = "<?php echo count( $total_orders_to_export ); ?>";
jQuery( "#orddd_update_event_message" ).html( "Total orders to export " + orders_to_export + " ... " );
var data = {
action: "orddd_admin_delivery_calendar_events"
};
jQuery.post( "<?php echo get_admin_url(); ?>/admin-ajax.php", data, function( response ) {
jQuery( "#orddd_update_event_message" ).html( "All events are added to the Google calendar. Please refresh your Google Calendar." );
});
});
});
</script>
<?php } ?>
</div>
<?php
}
public static function orddd_delivery_enqueue_css( $hook ) {
if ( $hook == 'order-delivery-date_page_orddd_view_orders' ) {
$calendar_theme = get_option( 'orddd_calendar_theme' );
if ( $calendar_theme == '' ) {
$calendar_theme = 'base';
}
wp_register_style( 'jquery-ui-style', "//code.jquery.com/ui/1.9.2/themes/$calendar_theme/jquery-ui.css", '', '', false );
wp_enqueue_style( 'jquery-ui-style' );
wp_enqueue_style( 'fullcalendar-orddd', plugins_url( '/css/fullcalendar.min.css', __FILE__ ) );
wp_enqueue_style( 'qtip-orddd-css', plugins_url( '/css/jquery.qtip.min.css', __FILE__ ), array() );
wp_enqueue_style( 'order-delivery-date', plugins_url( '/css/order-delivery-date.css', __FILE__ ) , '', '', false );
wp_enqueue_style( 'woocommerce_admin_styles-orddd', plugins_url() . '/woocommerce/assets/css/admin.css' );
} else {
return;
}
}
public static function orddd_delivery_enqueue_js( $hook ) {
if( $hook == 'order-delivery-date_page_orddd_view_orders' ) {
wp_register_script( 'select2', plugins_url() . '/woocommerce/assets/js/select2/select2.min.js', array( 'jquery', 'jquery-ui-widget', 'jquery-ui-core' ) );
wp_enqueue_script( 'select2' );
wp_enqueue_script( 'jquery' );
wp_register_script( 'moment-orddd-js', plugins_url( '/js/moment.min.js', __FILE__ ) );
wp_register_script( 'full-orddd-js', plugins_url( '/js/fullcalendar.min.js', __FILE__ ) );
wp_register_script( 'orddd-images-loaded', plugins_url( '/js/imagesloaded.pkg.min.js', __FILE__ ) );
wp_register_script( 'orddd-qtip', plugins_url( '/js/jquery.qtip.min.js', __FILE__ ), array( 'jquery', 'orddd-images-loaded' ) );
wp_enqueue_script( 'orddd-calendar-js', plugins_url( '/js/orddd-view-calendar.js', __FILE__ ), array( 'jquery', 'orddd-qtip' , 'moment-orddd-js', 'full-orddd-js', 'orddd-images-loaded', 'jquery-ui-position', 'jquery-ui-selectmenu' ) );
orddd_class_view_deliveries::localize_script();
}
}
public static function localize_script() {
$js_vars = array();
$schema = is_ssl() ? 'https':'http';
$js_vars[ 'ajaxurl' ] = admin_url( 'admin-ajax.php', $schema );
$js_vars[ 'pluginurl' ] = plugins_url( '/includes/adminend-events-jsons.php', __FILE__ );
wp_localize_script( 'orddd-calendar-js', 'orddd', $js_vars );
}
public static function orddd_order_calendar_content() {
global $orddd_date_formats, $wpdb;
$content = $delivery_date_timestamp = '';
if( !empty( $_REQUEST[ 'order_id' ] ) && ! empty( $_REQUEST[ 'event_value' ] ) ) {
$order = new WC_Order( $_REQUEST[ 'order_id' ] );
$order_items = $order->get_items();
$billing_first_name = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_billing_first_name() : $order->billing_first_name;
$billing_last_name = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_billing_last_name() : $order->billing_last_name;
if ( $_REQUEST[ 'event_type' ] == 'product' ) {
$value[] = $_REQUEST[ 'event_value' ];
$product_name = get_the_title( $_REQUEST[ 'event_product_id' ] );
$product_id = $_REQUEST[ 'event_product_id' ];
$product_quantity = $_REQUEST[ 'event_product_qty' ];
$delivery_date_formatted = orddd_common::orddd_get_order_delivery_date( $order->id );
$order_page_time_slot = orddd_common::orddd_get_order_timeslot( $order->id );
$content = "<table>
<tr><td> <strong>Order:</strong></td><td><a href=\"post.php?post=" . $order->id . "&action=edit\">#" . $order->get_order_number() . " </a></td></tr>
<tr><td> <strong>Product Name:</strong></td><td> " . $product_name . " x" . $product_quantity . "</td></tr>
<tr><td> <strong>Customer Name:</strong></td><td> " . $billing_first_name . " " . $billing_last_name . "</td></tr>" ;
if( isset( $delivery_date_formatted ) && $delivery_date_formatted != '0000-00-00' && isset( $_REQUEST[ 'event_date' ] ) && $_REQUEST[ 'event_date' ] == "" ) {
$content .= "<tr> <td> <strong>Delivery Date:</strong></td><td> " . $delivery_date_formatted . "</td></tr>";
} else if( isset( $_REQUEST[ 'event_date' ] ) && $_REQUEST[ 'event_date' ] != "" ) {
$content .= "<tr> <td> <strong>Delivery Date:</strong></td><td> " . $_REQUEST[ 'event_date' ] . "</td></tr>";
}
if( isset( $order_page_time_slot ) && $order_page_time_slot != '' && isset( $_REQUEST[ 'event_date' ] ) && $_REQUEST[ 'event_date' ] == "" ) {
$content .= "<tr> <td> <strong>Time Slot:</strong></td><td> " . $order_page_time_slot . "</td></tr>";
} else if ( isset( $_REQUEST[ 'event_timeslot' ] ) && $_REQUEST[ 'event_timeslot' ] != "" ) {
$content .= "<tr> <td> <strong>Time Slot:</strong></td><td> " . $_REQUEST[ 'event_timeslot' ] . "</td></tr>";
}
$custom_fields = '';
if ( has_filter( 'orddd_add_custom_field_value_to_qtip' ) ) {
$custom_fields = apply_filters( 'orddd_add_custom_field_value_to_qtip', $order->id );
}
if( $custom_fields != '' ){
$content .= $custom_fields;
}
$content .= '</table>';
if( $product_id ) {
$post_image = get_the_post_thumbnail( $product_id, array( 100, 100 ) );
if( !empty( $post_image ) ) {
$content = '<div class="orddd_product_image">' . $post_image . '</div>' . $content;
}
}
} else if ( $_REQUEST[ 'event_type' ] == 'order' ) {
$delivery_date_formatted = orddd_common::orddd_get_order_delivery_date( $order->id );
$order_page_time_slot = orddd_common::orddd_get_order_timeslot( $order->id );
$value[] = $_REQUEST[ 'event_value' ];
$content = "<table>
<tr> <td> <strong>Order:</strong></td><td><a href=\"post.php?post=" . $order->id . "&action=edit\">#" . $order->get_order_number() . " </a> </td> </tr>
<tr> <td> <strong>Customer Name:</strong></td><td> " . $billing_first_name . " " . $billing_last_name . "</td> </tr>" ;
if( isset( $delivery_date_formatted ) && $delivery_date_formatted != '0000-00-00' && isset( $_REQUEST[ 'event_date' ] ) && $_REQUEST[ 'event_date' ] == "" ) {
$content .= "<tr> <td> <strong>Delivery Date:</strong></td><td> " . $delivery_date_formatted . "</td></tr>";
} else if( isset( $_REQUEST[ 'event_date' ] ) && $_REQUEST[ 'event_date' ] != "" ) {
$content .= "<tr> <td> <strong>Delivery Date:</strong></td><td> " . $_REQUEST[ 'event_date' ] . "</td></tr>";
}
if( isset( $order_page_time_slot ) && $order_page_time_slot != '' && isset( $_REQUEST[ 'event_date' ] ) && $_REQUEST[ 'event_date' ] == "" ) {
$content .= "<tr> <td> <strong>Time Slot:</strong></td><td> " . $order_page_time_slot . "</td></tr>";
} else if ( isset( $_REQUEST[ 'event_timeslot' ] ) && $_REQUEST[ 'event_timeslot' ] != "" ) {
$content .= "<tr> <td> <strong>Time Slot:</strong></td><td> " . $_REQUEST[ 'event_timeslot' ] . "</td></tr>";
}
$custom_fields = '';
if ( has_filter( 'orddd_add_custom_field_value_to_qtip' ) ) {
$custom_fields = apply_filters( 'orddd_add_custom_field_value_to_qtip', $order->id );
}
if( $custom_fields != '' ){
$content .= $custom_fields;
}
$product_name = "";
if( isset( $_REQUEST[ 'event_product_id' ] ) && $_REQUEST[ 'event_product_id' ] != "" ) {
$product_name = get_the_title( $_REQUEST[ 'event_product_id' ] );
} else {
foreach ( $order_items as $item ) {
$product_name .= $item['name'] . " x" . $item['quantity'] . ",";
}
$product_name = substr( $product_name, 0, -1 );
}
$content .= '<tr> <td> <strong>Product Name:</strong></td><td> ' . $product_name . '</td> </tr>';
$content .= '</table>';
}
}
echo $content;
die();
}
}