css
10 months ago
img
10 months ago
js
10 months ago
partials
10 months ago
class-adv-order-filter.php
10 months ago
class-analytics.php
10 months ago
class-order-tip-promotion.php
10 months ago
class-pi-dtt-labels.php
10 months ago
class-pi-dtt-order-table.php
10 months ago
conflict-fixer.php
10 months ago
menu.php
10 months ago
options-addons.php
10 months ago
options-date.php
10 months ago
options-limit.php
10 months ago
options-pickup.php
10 months ago
options-time-slot.php
10 months ago
options-time.php
10 months ago
options.php
10 months ago
options-time-slot.php
261 lines
| 1 | <?php |
| 2 | |
| 3 | class pisol_dtt_option_time_slot{ |
| 4 | |
| 5 | private $settings = array(); |
| 6 | |
| 7 | private $active_tab; |
| 8 | |
| 9 | private $this_tab = 'pi_time_slot'; |
| 10 | |
| 11 | private $tab_name = "Time Slot"; |
| 12 | |
| 13 | private $setting_key = 'pisol_time_slot'; |
| 14 | |
| 15 | private $pro_version = false; |
| 16 | |
| 17 | public $tab; |
| 18 | |
| 19 | |
| 20 | function __construct(){ |
| 21 | |
| 22 | $this->pro_version = pi_dtt_pro_check(); |
| 23 | |
| 24 | $this->tab = sanitize_text_field(filter_input( INPUT_GET, 'tab')); |
| 25 | $this->active_tab = $this->tab != "" ? $this->tab : 'default'; |
| 26 | |
| 27 | $this->settings = array( |
| 28 | |
| 29 | array('field'=>'pi_general_time_slot_delivery', 'sanitize_callback'=> [__CLASS__,'sanitize_time_slot']), |
| 30 | array('field'=>'pi_general_time_slot_pickup', 'sanitize_callback'=> [__CLASS__,'sanitize_time_slot']) |
| 31 | |
| 32 | ); |
| 33 | |
| 34 | |
| 35 | if($this->this_tab == $this->active_tab){ |
| 36 | add_action('pisol_dtt_tab_content', array($this,'tab_content')); |
| 37 | } |
| 38 | |
| 39 | add_action('pisol_dtt_tab', array($this,'tab'),3); |
| 40 | |
| 41 | $this->register_settings(); |
| 42 | |
| 43 | |
| 44 | } |
| 45 | |
| 46 | function register_settings(){ |
| 47 | |
| 48 | foreach($this->settings as $setting){ |
| 49 | pisol_class_form::register_setting( $this->setting_key, $setting); |
| 50 | } |
| 51 | |
| 52 | } |
| 53 | |
| 54 | function tab(){ |
| 55 | $page = sanitize_text_field(filter_input( INPUT_GET, 'page')); |
| 56 | $this->tab_name = __('Time Slot','pisol-dtt'); |
| 57 | ?> |
| 58 | <a class=" pi-side-menu <?php echo ($this->active_tab == $this->this_tab ? 'bg-primary' : 'bg-secondary'); ?> " href="<?php echo esc_url( admin_url( 'admin.php?page='.$page.'&tab='.$this->this_tab ) ); ?>"> |
| 59 | <span class="dashicons dashicons-dashboard"></span> <?php echo esc_html($this->tab_name); ?> |
| 60 | </a> |
| 61 | <?php |
| 62 | } |
| 63 | |
| 64 | function tab_content(){ |
| 65 | ?> |
| 66 | <form method="post" action="options.php" class="pisol-setting-form"> |
| 67 | <?php settings_fields( $this->setting_key ); ?> |
| 68 | <?php |
| 69 | echo '<script>'; |
| 70 | foreach($this->settings as $setting){ |
| 71 | $val = pisol_dtt_get_setting($setting['field'], array()); |
| 72 | if(!is_array($val) || count($val) < 1){ |
| 73 | $val = array(); |
| 74 | } |
| 75 | ?> |
| 76 | var <?php echo esc_js( $setting['field'] ); ?> = <?php echo json_encode(array_values($val)); ?>; |
| 77 | <?php |
| 78 | } |
| 79 | echo '</script>'; |
| 80 | ?> |
| 81 | <?php |
| 82 | foreach($this->settings as $setting){ |
| 83 | new pisol_class_form($setting, $this->setting_key); |
| 84 | } |
| 85 | |
| 86 | $this->timesForm(__('General Time Slot (this will be applied for all days of the week)', 'pisol-dtt' ), 'pi_general_time_slot_delivery', 'pi_general_time_slot_pickup'); |
| 87 | |
| 88 | $this->proFeatureRow(__('Monday (Set different time slot for Monday)', 'pisol-dtt' ), 'pi_monday_time_slot_delivery', 'pi_monday_time_slot_pickup','monday1'); |
| 89 | $this->proFeatureRow(__('Tuesday (Set different time slot for Tuesday)', 'pisol-dtt' ), 'pi_tuesday_time_slot_delivery', 'pi_tuesday_time_slot_pickup','tuesday1'); |
| 90 | $this->proFeatureRow(__('Wednesday (Set different time slot for Wednesday)', 'pisol-dtt' ), 'pi_wednesday_time_slot_delivery', 'pi_wednesday_time_slot_pickup','wednesday1'); |
| 91 | $this->proFeatureRow(__('Thursday (Set different time slot for Thursday)', 'pisol-dtt' ), 'pi_Thursday_time_slot_delivery', 'pi_Thursday_time_slot_pickup','Thursday1'); |
| 92 | $this->proFeatureRow(__('Friday (Set different time slot for Friday)', 'pisol-dtt' ), 'pi_Friday_time_slot_delivery', 'pi_Friday_time_slot_pickup','Friday1'); |
| 93 | $this->proFeatureRow(__('Saturday (Set different time slot for Saturday)', 'pisol-dtt' ), 'pi_Saturday_time_slot_delivery', 'pi_Saturday_time_slot_pickup','Saturday1'); |
| 94 | $this->proFeatureRow(__('Sunday (Set different time slot for Sunday)', 'pisol-dtt' ), 'pi_Sunday_time_slot_delivery', 'pi_Sunday_time_slot_pickup','Sunday1'); |
| 95 | |
| 96 | |
| 97 | ?> |
| 98 | <input type="submit" name="submit" id="submit" class="btn btn-primary btn-md my-3" value="<?php echo esc_attr__('Save Changes','pisol-dtt'); ?>"> |
| 99 | </form> |
| 100 | <?php |
| 101 | } |
| 102 | |
| 103 | function timesForm($label, $field_delivery, $field_pickup, $overwrite_day = ""){ |
| 104 | if(empty($overwrite_day)){ |
| 105 | $bg = 'bg-dark opacity-75'; |
| 106 | $hide=""; |
| 107 | }else{ |
| 108 | $bg = 'bg-dark opacity-75'; |
| 109 | $overwrite_value = pisol_dtt_get_setting('pi_different_slot_for_'.$overwrite_day, ""); |
| 110 | $checked = false; |
| 111 | $hide ='display:none;'; |
| 112 | if(!empty($overwrite_value)){ |
| 113 | $checked = true; |
| 114 | $hide=""; |
| 115 | } |
| 116 | } |
| 117 | ?> |
| 118 | <div id="row_sunday" class="row py-2 border-bottom align-items-center <?php echo esc_attr( $bg ); ?> text-light"> |
| 119 | <div class="col-9"> |
| 120 | <?php if(empty($overwrite_day)){ ?> |
| 121 | <h5 class="mt-0 mb-0 py-2 text-light font-weight-light h4"><label for="pi_different_slot_for_<?php echo esc_attr( $overwrite_day ); ?>" class="mb-0"><?php echo esc_html( $label ); ?></label></h5> |
| 122 | <a class="pi-info-links my-0 text-light" href="https://www.piwebsolution.com/user-documentation/#Time_Slot_Settings" target="_blank">Know more about this ? </a> |
| 123 | <?php }else{ ?> |
| 124 | <h5 class="mt-0 mb-0 text-light font-weight-light h5"><label for="pi_different_slot_for_<?php echo esc_attr( $overwrite_day ); ?>" class="mb-0"><?php echo esc_html( $label ); ?></label></h5> |
| 125 | <?php } ?> |
| 126 | </div> |
| 127 | <?php if(!empty($overwrite_day)): ?> |
| 128 | <div class="col-3 text-right"> |
| 129 | <div class="custom-control custom-switch"> |
| 130 | <input type="checkbox" class="custom-control-input" name="pi_different_slot_for_<?php echo esc_attr( $overwrite_day ); ?>" id="pi_different_slot_for_<?php echo esc_attr( $overwrite_day ); ?>" <?php checked(true, $checked); ?>> |
| 131 | <label class="custom-control-label" for="pi_different_slot_for_<?php echo esc_attr( $overwrite_day ); ?>"></label> |
| 132 | </div> |
| 133 | </div> |
| 134 | <?php endif; ?> |
| 135 | </div> |
| 136 | |
| 137 | <div class="row mb-2 pt-2" id="pi_slots_for_<?php echo esc_attr( $overwrite_day ); ?>" style="<?php echo esc_attr($hide); ?>"> |
| 138 | <div class="col-12 col-md-6"> |
| 139 | <div class="row align-items-center"> |
| 140 | <div class="col-7 mt-2"> |
| 141 | <strong><?php esc_html_e('Delivery Time slots', 'pisol-dtt' ); ?></strong> |
| 142 | </div> |
| 143 | <div class="col text-right"> |
| 144 | <a class="btn btn-primary btn-sm pi_add_time_slot text-light" data-slot="<?php echo esc_attr( $field_delivery ); ?>" ><?php esc_html_e('Add Time Slot', 'pisol-dtt' ); ?></a> |
| 145 | </div> |
| 146 | </div> |
| 147 | <div class="row align-items-center"> |
| 148 | <div class="col-12 mt-2"> |
| 149 | <div id="<?php echo esc_attr( $field_delivery ); ?>_container"></div> |
| 150 | </div> |
| 151 | </div> |
| 152 | </div> |
| 153 | |
| 154 | |
| 155 | <div class="col-12 col-md-6 border-left"> |
| 156 | <div class="row align-items-center"> |
| 157 | <div class="col-7 mt-2"> |
| 158 | <strong><?php esc_html_e('Pickup Time slots', 'pisol-dtt' ); ?></strong> |
| 159 | </div> |
| 160 | <div class="col text-right"> |
| 161 | <a class="btn btn-primary btn-sm pi_add_time_slot text-light" data-slot="<?php echo esc_attr( $field_pickup ); ?>" ><?php esc_html_e('Add Time Slot', 'pisol-dtt' ); ?></a> |
| 162 | </div> |
| 163 | </div> |
| 164 | <div class="row align-items-center"> |
| 165 | <div class="col-12 mt-2"> |
| 166 | <div id="<?php echo esc_attr( $field_pickup ); ?>_container"></div> |
| 167 | </div> |
| 168 | </div> |
| 169 | </div> |
| 170 | </div> |
| 171 | <?php |
| 172 | } |
| 173 | |
| 174 | function proFeatureRow($label, $field_delivery, $field_pickup, $overwrite_day = ""){ |
| 175 | if(empty($overwrite_day)){ |
| 176 | $bg = 'bg-dark opacity-75'; |
| 177 | $hide=""; |
| 178 | }else{ |
| 179 | $bg = 'bg-dark opacity-75'; |
| 180 | $overwrite_value = pisol_dtt_get_setting('pi_different_slot_for_'.$overwrite_day, ""); |
| 181 | $checked = false; |
| 182 | $hide =' style="display:none;" '; |
| 183 | if(!empty($overwrite_value)){ |
| 184 | $checked = true; |
| 185 | $hide=""; |
| 186 | } |
| 187 | } |
| 188 | ?> |
| 189 | <div id="row_sunday" class="row py-2 border-bottom align-items-center free-version <?php echo esc_attr($bg); ?> text-light"> |
| 190 | <div class="col-9"> |
| 191 | <?php if(empty($overwrite_day)){ ?> |
| 192 | <h5 class="mt-0 mb-0 py-2 text-light font-weight-light h4"><label for="pi_different_slot_for_<?php echo esc_attr($overwrite_day); ?>" class="mb-0"><?php echo esc_html($label); ?></label></h5> |
| 193 | <?php }else{ ?> |
| 194 | <h5 class="mt-0 mb-0 text-light font-weight-light h5"><label for="pi_different_slot_for_<?php echo esc_attr($overwrite_day); ?>" class="mb-0"><?php echo esc_html($label); ?></label></h5> |
| 195 | <?php } ?> |
| 196 | </div> |
| 197 | <?php if(!empty($overwrite_day)): ?> |
| 198 | <div class="col-3 text-right"> |
| 199 | <div class="custom-control custom-switch"> |
| 200 | <input type="checkbox" class="custom-control-input" name="pi_different_slot_for_<?php echo esc_attr($overwrite_day); ?>" id="pi_different_slot_for_<?php echo esc_attr($overwrite_day); ?>" <?php checked(true, $checked); ?>> |
| 201 | <label class="custom-control-label" for="pi_different_slot_for_<?php echo esc_attr($overwrite_day); ?>"></label> |
| 202 | </div> |
| 203 | </div> |
| 204 | <?php endif; ?> |
| 205 | </div> |
| 206 | <?php |
| 207 | } |
| 208 | |
| 209 | static function sanitize_time_slot($inputs){ |
| 210 | if(!is_array($inputs) || empty($inputs)){ |
| 211 | return array(); |
| 212 | } |
| 213 | |
| 214 | foreach($inputs as $key => $values){ |
| 215 | $inputs[$key]['from'] = isset($values['from']) ? sanitize_text_field($values['from']) : ""; |
| 216 | $inputs[$key]['to'] = isset($values['to']) ? sanitize_text_field($values['to']) : ""; |
| 217 | $inputs[$key]['order_limit'] = !empty($values['order_limit']) ? abs(intval($values['order_limit'])) : ""; |
| 218 | |
| 219 | if(empty($values['from']) && empty($values['to'])){ |
| 220 | unset($inputs[$key]); |
| 221 | } |
| 222 | |
| 223 | } |
| 224 | |
| 225 | return array_values($inputs); |
| 226 | } |
| 227 | |
| 228 | static function createDefaultTimeSlot(){ |
| 229 | $auto_slot_created = get_option('pi_dtt_auto_slot_created', false); |
| 230 | if($auto_slot_created){ |
| 231 | return; |
| 232 | } |
| 233 | update_option('pi_dtt_auto_slot_created', true); |
| 234 | |
| 235 | $default_time_slot = [ |
| 236 | ['from' => '09:00 AM', 'to' => '10:00 AM', 'order_limit' => '', 'quantity_limit' => ''], |
| 237 | ['from' => '10:00 AM', 'to' => '11:00 AM', 'order_limit' => '', 'quantity_limit' => ''], |
| 238 | ['from' => '11:00 AM', 'to' => '12:00 PM', 'order_limit' => '', 'quantity_limit' => ''], |
| 239 | ['from' => '12:00 PM', 'to' => '01:00 PM', 'order_limit' => '', 'quantity_limit' => ''], |
| 240 | ['from' => '01:00 PM', 'to' => '02:00 PM', 'order_limit' => '', 'quantity_limit' => ''], |
| 241 | ['from' => '02:00 PM', 'to' => '03:00 PM', 'order_limit' => '', 'quantity_limit' => ''], |
| 242 | ['from' => '03:00 PM', 'to' => '04:00 PM', 'order_limit' => '', 'quantity_limit' => ''], |
| 243 | ['from' => '04:00 PM', 'to' => '05:00 PM', 'order_limit' => '', 'quantity_limit' => ''], |
| 244 | ['from' => '05:00 PM', 'to' => '06:00 PM', 'order_limit' => '', 'quantity_limit' => ''], |
| 245 | ['from' => '06:00 PM', 'to' => '07:00 PM', 'order_limit' => '', 'quantity_limit' => ''], |
| 246 | ['from' => '07:00 PM', 'to' => '08:00 PM', 'order_limit' => '', 'quantity_limit' => ''], |
| 247 | ['from' => '08:00 PM', 'to' => '09:00 PM', 'order_limit' => '', 'quantity_limit' => ''], |
| 248 | ]; |
| 249 | |
| 250 | $present_delivery = get_option('pi_general_time_slot_delivery', array()); |
| 251 | $present_pickup = get_option('pi_general_time_slot_pickup', array()); |
| 252 | if(empty($present_delivery) && empty($present_pickup)){ |
| 253 | update_option('pi_general_time_slot_delivery', $default_time_slot); |
| 254 | update_option('pi_general_time_slot_pickup', $default_time_slot); |
| 255 | } |
| 256 | |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | new pisol_dtt_option_time_slot(); |
| 261 |