css
2 years ago
img
2 years ago
js
2 years ago
class-adv-order-filter.php
2 years ago
class-pi-dtt-labels.php
2 years ago
class-pi-dtt-order-table.php
2 years ago
conflict-fixer.php
2 years ago
menu.php
2 years ago
options-addons.php
2 years ago
options-date.php
2 years ago
options-limit.php
2 years ago
options-pickup.php
2 years ago
options-time-slot.php
2 years ago
options-time.php
2 years ago
options.php
2 years ago
options-time-slot.php
232 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 | ?> |
| 57 | <a class=" pi-side-menu <?php echo ($this->active_tab == $this->this_tab ? 'bg-primary' : 'bg-secondary'); ?> " href="<?php echo admin_url( 'admin.php?page='.$page.'&tab='.$this->this_tab ); ?>"> |
| 58 | <span class="dashicons dashicons-dashboard"></span> <?php _e( $this->tab_name, 'pisol-dtt' ); ?> |
| 59 | </a> |
| 60 | <?php |
| 61 | } |
| 62 | |
| 63 | function tab_content(){ |
| 64 | ?> |
| 65 | <form method="post" action="options.php" class="pisol-setting-form"> |
| 66 | <?php settings_fields( $this->setting_key ); ?> |
| 67 | <?php |
| 68 | echo '<script>'; |
| 69 | foreach($this->settings as $setting){ |
| 70 | $val = pisol_dtt_get_setting($setting['field'], array()); |
| 71 | if(!is_array($val) || count($val) < 1){ |
| 72 | $val = array(); |
| 73 | } |
| 74 | ?> |
| 75 | var <?php echo $setting['field']; ?> = <?php echo json_encode(array_values($val)); ?>; |
| 76 | <?php |
| 77 | } |
| 78 | echo '</script>'; |
| 79 | ?> |
| 80 | <?php |
| 81 | foreach($this->settings as $setting){ |
| 82 | new pisol_class_form($setting, $this->setting_key); |
| 83 | } |
| 84 | |
| 85 | $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'); |
| 86 | |
| 87 | $this->proFeatureRow(__('Monday (Set different time slot for Monday)', 'pisol-dtt' ), 'pi_monday_time_slot_delivery', 'pi_monday_time_slot_pickup','monday1'); |
| 88 | $this->proFeatureRow(__('Tuesday (Set different time slot for Tuesday)', 'pisol-dtt' ), 'pi_tuesday_time_slot_delivery', 'pi_tuesday_time_slot_pickup','tuesday1'); |
| 89 | $this->proFeatureRow(__('Wednesday (Set different time slot for Wednesday)', 'pisol-dtt' ), 'pi_wednesday_time_slot_delivery', 'pi_wednesday_time_slot_pickup','wednesday1'); |
| 90 | $this->proFeatureRow(__('Thursday (Set different time slot for Thursday)', 'pisol-dtt' ), 'pi_Thursday_time_slot_delivery', 'pi_Thursday_time_slot_pickup','Thursday1'); |
| 91 | $this->proFeatureRow(__('Friday (Set different time slot for Friday)', 'pisol-dtt' ), 'pi_Friday_time_slot_delivery', 'pi_Friday_time_slot_pickup','Friday1'); |
| 92 | $this->proFeatureRow(__('Saturday (Set different time slot for Saturday)', 'pisol-dtt' ), 'pi_Saturday_time_slot_delivery', 'pi_Saturday_time_slot_pickup','Saturday1'); |
| 93 | $this->proFeatureRow(__('Sunday (Set different time slot for Sunday)', 'pisol-dtt' ), 'pi_Sunday_time_slot_delivery', 'pi_Sunday_time_slot_pickup','Sunday1'); |
| 94 | |
| 95 | |
| 96 | ?> |
| 97 | <input type="submit" name="submit" id="submit" class="btn btn-primary btn-md my-3" value="<?php echo __('Save Changes','pisol-dtt'); ?>"> |
| 98 | </form> |
| 99 | <?php |
| 100 | } |
| 101 | |
| 102 | function timesForm($label, $field_delivery, $field_pickup, $overwrite_day = ""){ |
| 103 | if(empty($overwrite_day)){ |
| 104 | $bg = 'bg-primary'; |
| 105 | $hide=""; |
| 106 | }else{ |
| 107 | $bg = 'bg-dark'; |
| 108 | $overwrite_value = pisol_dtt_get_setting('pi_different_slot_for_'.$overwrite_day, ""); |
| 109 | $checked =""; |
| 110 | $hide =' style="display:none;" '; |
| 111 | if(!empty($overwrite_value)){ |
| 112 | $checked = ' checked="checked" '; |
| 113 | $hide=""; |
| 114 | } |
| 115 | } |
| 116 | ?> |
| 117 | <div id="row_sunday" class="row py-2 border-bottom align-items-center <?php echo $bg; ?> text-light"> |
| 118 | <div class="col-9"> |
| 119 | <?php if(empty($overwrite_day)){ ?> |
| 120 | <h5 class="mt-0 mb-0 py-2 text-light font-weight-light h4"><label for="pi_different_slot_for_<?php echo $overwrite_day; ?>"><?php echo $label; ?></label></h5> |
| 121 | <?php }else{ ?> |
| 122 | <h5 class="mt-0 mb-0 text-light font-weight-light h5"><label for="pi_different_slot_for_<?php echo $overwrite_day; ?>"><?php echo $label; ?></label></h5> |
| 123 | <?php } ?> |
| 124 | </div> |
| 125 | <?php if(!empty($overwrite_day)): ?> |
| 126 | <div class="col-3 text-right"> |
| 127 | <div class="custom-control custom-switch"> |
| 128 | <input type="checkbox" class="custom-control-input" name="pi_different_slot_for_<?php echo $overwrite_day; ?>" id="pi_different_slot_for_<?php echo $overwrite_day; ?>" <?php echo $checked; ?>> |
| 129 | <label class="custom-control-label" for="pi_different_slot_for_<?php echo $overwrite_day; ?>"></label> |
| 130 | </div> |
| 131 | </div> |
| 132 | <?php endif; ?> |
| 133 | </div> |
| 134 | |
| 135 | <div class="row mb-2 pt-2" id="pi_slots_for_<?php echo $overwrite_day; ?>" <?php echo $hide; ?>> |
| 136 | <div class="col-12 col-md-6"> |
| 137 | <div class="row align-items-center"> |
| 138 | <div class="col-7 mt-2"> |
| 139 | <strong><?php _e('Delivery Time slots', 'pisol-dtt' ); ?></strong> |
| 140 | </div> |
| 141 | <div class="col"> |
| 142 | <a class="btn btn-primary btn-sm pi_add_time_slot text-light" data-slot="<?php echo $field_delivery; ?>" ><?php _e('Add Time Slot', 'pisol-dtt' ); ?></a> |
| 143 | </div> |
| 144 | </div> |
| 145 | <div class="row align-items-center"> |
| 146 | <div class="col-12 mt-2"> |
| 147 | <div id="<?php echo $field_delivery; ?>_container"> |
| 148 | |
| 149 | </div> |
| 150 | </div> |
| 151 | </div> |
| 152 | </div> |
| 153 | |
| 154 | |
| 155 | <div class="col-12 col-md-6"> |
| 156 | <div class="row align-items-center"> |
| 157 | <div class="col-7 mt-2"> |
| 158 | <strong><?php _e('Pickup Time slots', 'pisol-dtt' ); ?></strong> |
| 159 | </div> |
| 160 | <div class="col"> |
| 161 | <a class="btn btn-primary btn-sm pi_add_time_slot text-light" data-slot="<?php echo $field_pickup; ?>" ><?php _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 $field_pickup; ?>_container"> |
| 167 | |
| 168 | </div> |
| 169 | </div> |
| 170 | </div> |
| 171 | </div> |
| 172 | </div> |
| 173 | <?php |
| 174 | } |
| 175 | |
| 176 | function proFeatureRow($label, $field_delivery, $field_pickup, $overwrite_day = ""){ |
| 177 | if(empty($overwrite_day)){ |
| 178 | $bg = 'bg-primary'; |
| 179 | $hide=""; |
| 180 | }else{ |
| 181 | $bg = 'bg-dark'; |
| 182 | $overwrite_value = pisol_dtt_get_setting('pi_different_slot_for_'.$overwrite_day, ""); |
| 183 | $checked =""; |
| 184 | $hide =' style="display:none;" '; |
| 185 | if(!empty($overwrite_value)){ |
| 186 | $checked = ' checked="checked" '; |
| 187 | $hide=""; |
| 188 | } |
| 189 | } |
| 190 | ?> |
| 191 | <div id="row_sunday" class="row py-2 border-bottom align-items-center free-version <?php echo $bg; ?> text-light"> |
| 192 | <div class="col-9"> |
| 193 | <?php if(empty($overwrite_day)){ ?> |
| 194 | <h5 class="mt-0 mb-0 py-2 text-light font-weight-light h4"><label for="pi_different_slot_for_<?php echo $overwrite_day; ?>"><?php echo $label; ?></label></h5> |
| 195 | <?php }else{ ?> |
| 196 | <h5 class="mt-0 mb-0 text-light font-weight-light h5"><label for="pi_different_slot_for_<?php echo $overwrite_day; ?>"><?php echo $label; ?></label></h5> |
| 197 | <?php } ?> |
| 198 | </div> |
| 199 | <?php if(!empty($overwrite_day)): ?> |
| 200 | <div class="col-3 text-right"> |
| 201 | <div class="custom-control custom-switch"> |
| 202 | <input type="checkbox" class="custom-control-input" name="pi_different_slot_for_<?php echo $overwrite_day; ?>" id="pi_different_slot_for_<?php echo $overwrite_day; ?>" <?php echo $checked; ?>> |
| 203 | <label class="custom-control-label" for="pi_different_slot_for_<?php echo $overwrite_day; ?>"></label> |
| 204 | </div> |
| 205 | </div> |
| 206 | <?php endif; ?> |
| 207 | </div> |
| 208 | <?php |
| 209 | } |
| 210 | |
| 211 | static function sanitize_time_slot($inputs){ |
| 212 | if(!is_array($inputs) || empty($inputs)){ |
| 213 | return array(); |
| 214 | } |
| 215 | |
| 216 | foreach($inputs as $key => $values){ |
| 217 | $inputs[$key]['from'] = isset($values['from']) ? sanitize_text_field($values['from']) : ""; |
| 218 | $inputs[$key]['to'] = isset($values['to']) ? sanitize_text_field($values['to']) : ""; |
| 219 | $inputs[$key]['order_limit'] = !empty($values['order_limit']) ? abs(intval($values['order_limit'])) : ""; |
| 220 | |
| 221 | if(empty($values['from']) && empty($values['to'])){ |
| 222 | unset($inputs[$key]); |
| 223 | } |
| 224 | |
| 225 | } |
| 226 | |
| 227 | return array_values($inputs); |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | new pisol_dtt_option_time_slot(); |
| 232 |