Ejemplo n.º 1
0
 function iva_business_hours_shortcode($atts)
 {
     extract(shortcode_atts(array('width' => '', 'name' => '', 'title' => 'true', 'grouping_hrs' => '', 'current_day_color' => ''), $atts));
     $out = $output = $today_output = $hrs_css = '';
     //stores the output
     global $wpdb;
     $iva_sh_name = strtolower(trim(str_replace(' ', '-', $name)));
     // Replaces all spaces with hyphens.
     $iva_shortcode = '[iva_bhrs_pro name="' . $iva_sh_name . '"]';
     $ivbh_title = $ivbh_day_open = $ivbh_day_close = '';
     $iva_bh_class = 'show' . rand('10', '100');
     $iva_bh_sql = "SELECT * FROM {$wpdb->iva_businesshours} where shortcode= '" . $iva_shortcode . "' ";
     $iva_bh_results = $wpdb->get_results($iva_bh_sql, ARRAY_A);
     if ($iva_bh_results) {
         $iva_bh_time_format = get_option('iva_bh_time_format') ? get_option('iva_bh_time_format') : 'H:i';
         $iva_see_more_text = get_option('iva_seemore_text') ? get_option('iva_seemore_text') : __('See more', 'iva_business_hours');
         $iva_today_text = get_option('iva_today_text') ? get_option('iva_today_text') : __('Today', 'iva_business_hours');
         $ivbh_today_hrs_array = array();
         foreach ($iva_bh_results as $iva_bh_data) {
             $iva_descripion_prefix = $iva_descripion_enable = $iva_descripion = $iva_todaydate_enable = $iva_grouping_enable = $iva_closed_bg_color = $iva_current_day_color = '';
             $iva_toggle_enable = $cssextras = $iva_open_image = $iva_close_image = $iva_oc_img = $today_color = $iva_bh_start_hrs = $iva_bh_end_hrs = $iva_oc_text = '';
             $iva_today_timings = $iva_bh_oc_timings = array();
             $iva_title = $iva_bh_data['title'];
             if ($iva_bh_data['closedtext']) {
                 $iva_closed_text = $iva_bh_data['closedtext'];
             } else {
                 $iva_closed_text = __('Closed', 'iva_business_hours');
             }
             if ($iva_bh_data['opentext']) {
                 $iva_open_text = $iva_bh_data['opentext'];
             } else {
                 $iva_open_text = __('Open', 'iva_business_hours');
             }
             if ($iva_bh_data['timeseparator']) {
                 $iva_time_separator = $iva_bh_data['timeseparator'];
             } else {
                 $iva_time_separator = '-';
             }
             if ($iva_bh_data['description']) {
                 $iva_descripion = $iva_bh_data['description'];
             }
             if ($iva_bh_data['descriptionprefix']) {
                 $iva_descripion_prefix = $iva_bh_data['descriptionprefix'];
             }
             if ($iva_bh_data['descriptionenable']) {
                 $iva_descripion_enable = $iva_bh_data['descriptionenable'];
             }
             if ($iva_bh_data['todaydate']) {
                 $iva_todaydate_enable = $iva_bh_data['todaydate'];
             }
             if (isset($iva_bh_data['grouping_enable'])) {
                 $iva_grouping_enable = $iva_bh_data['grouping_enable'];
             }
             if (isset($iva_bh_data['closed_bg_color'])) {
                 $iva_closed_bg_color = $iva_bh_data['closed_bg_color'];
             }
             if (isset($iva_bh_data['open_bg_color'])) {
                 $iva_open_bg_color = $iva_bh_data['open_bg_color'];
             }
             if (isset($iva_bh_data['current_day_color'])) {
                 $iva_current_day_color = $iva_bh_data['current_day_color'];
             }
             if (isset($iva_bh_data['toggle_enable'])) {
                 $iva_toggle_enable = $iva_bh_data['toggle_enable'];
             }
             if (isset($iva_bh_data['open_image'])) {
                 $iva_open_image = $iva_bh_data['open_image'];
             }
             if (isset($iva_bh_data['close_image'])) {
                 $iva_close_image = $iva_bh_data['close_image'];
             }
             // Open Close Image
             $iva_current_day = date_i18n('N', strtotime(date('N')));
             $iva_weekday = 'weekday' . $iva_current_day;
             $iva_today_data = json_decode($iva_bh_data[$iva_weekday]);
             if ($iva_today_data) {
                 foreach ($iva_today_data as $key => $value) {
                     $iva_today_timings = $value;
                 }
                 foreach ($iva_today_timings as $key => $value) {
                     $iva_bh_oc_timings['open'][] = $value->open;
                     $iva_bh_oc_timings['close'][] = $value->close;
                 }
                 $max_value = max($iva_bh_oc_timings['close']);
                 $min_value = min($iva_bh_oc_timings['open']);
                 $iva_curent_time = get_date_from_gmt(date('Y-m-d H:i:s', time()), 'H:i');
                 if (!empty($iva_bh_oc_timings)) {
                     // Open text and image
                     if (strtotime($iva_curent_time) >= strtotime($min_value) || strtotime($iva_curent_time) <= strtotime($max_value)) {
                         $iva_oc_text = $iva_open_text;
                         if ($iva_open_image != '') {
                             $iva_oc_img = '<figure><img class="ivabh_open_img" src="' . $iva_open_image . '" width="470" height="300"></figure>';
                         }
                     }
                     // Close text and image
                     if (strtotime($iva_curent_time) < strtotime($min_value) || strtotime($iva_curent_time) > strtotime($max_value)) {
                         $iva_oc_text = $iva_closed_text;
                         if ($iva_close_image != '') {
                             $iva_oc_img = '<figure><img class="ivabh_close_img" src="' . $iva_close_image . '" width="470" height="300"></figure>';
                         }
                     }
                 }
             }
             // Open Close Image
             if ($title == 'true') {
                 $today_output .= '<h3 class="ivabh-title">' . $iva_title . '</h3>';
             }
             if ($iva_oc_img != '') {
                 $today_output .= $iva_oc_img;
             }
             $j = $k = 0;
             $closed_bgcolor = isset($iva_closed_bg_color) ? 'background-color:' . $iva_closed_bg_color . ';' : '';
             $open_bgcolor = isset($iva_open_bg_color) ? 'background-color:' . $iva_open_bg_color . ';' : '';
             $cssextras = $closed_bgcolor != '' ? ' style="' . $closed_bgcolor . '"' : '';
             $open_css = $open_bgcolor != '' ? ' style="' . $open_bgcolor . '"' : '';
             if (isset($current_day_color) && $current_day_color != '') {
                 $iva_current_day_color = $current_day_color;
                 $today_color = 'color:' . $iva_current_day_color;
             } else {
                 $today_color = 'color:' . $iva_current_day_color;
             }
             $width = $width ? 'width:' . (int) $width . 'px;' : '';
             $hrs_css = $iva_toggle_enable == 'on' ? 'display:none;' : '';
             $iva_bh_style = $width != '' ? ' style="' . $width . '"' : '';
             $iva_bh_toggle = $hrs_css != '' ? ' style="' . $hrs_css . '"' : '';
             if (isset($grouping_hrs) && $grouping_hrs != '') {
                 $iva_grouping_enable = $grouping_hrs;
             }
             if ($iva_descripion_enable != 'on') {
                 if ($iva_descripion_prefix == 'on') {
                     $out .= '<div class="ivabh-desc">' . $iva_descripion . '</div>';
                 }
             }
             $out .= '<div class="ivabh-hours ' . $iva_bh_class . '" ' . $iva_bh_toggle . '>';
             foreach (iva_bh_getWeekdays() as $key => $day) {
                 $week_day_key = 'weekday' . $key;
                 $iva_bh_day = json_decode($iva_bh_data[$week_day_key]);
                 $iva_bh_hrs = array();
                 foreach ($iva_bh_day as $key => $value) {
                     $iva_row_count = count($value);
                     foreach ($value as $time) {
                         $ivbh_day_open = iva_bh_formatTime($time->open, $iva_bh_time_format);
                         $ivbh_day_close = iva_bh_formatTime($time->close, $iva_bh_time_format);
                         $ivbh_day_start = isset($time->starttime) ? $time->starttime : '';
                         $ivbh_day_end = isset($time->latetime) ? $time->latetime : '';
                         if ($ivbh_day_start != '') {
                             $ivbh_day_start = '<span class="iva-bh-stext">' . $ivbh_day_start . '</span>';
                         }
                         if ($ivbh_day_end != '') {
                             $ivbh_day_end = '<span class="iva-bh-etext">' . $ivbh_day_end . '</span>';
                         }
                         //	 Today hours array
                         if ($ivbh_day_open == '' && $ivbh_day_close == '' && $ivbh_day_end == '' && $ivbh_day_start == '') {
                             $ivbh_today_hrs_array[$day] = '<span class="closed" ' . $cssextras . '>' . $iva_closed_text . '</span>';
                         } elseif (($ivbh_day_open != '' || $ivbh_day_start != '') && ($ivbh_day_close != '' || $ivbh_day_end != '')) {
                             $ivbh_today_hrs_array[$day] = $ivbh_day_open . $ivbh_day_start . $iva_time_separator . $ivbh_day_close . $ivbh_day_end;
                         }
                         // with out group hours array
                         if ($ivbh_day_open == '' && $ivbh_day_close == '' && $ivbh_day_end == '' && $ivbh_day_start == '') {
                             $ivbh_arr[$day] = '<span class="closed" ' . $cssextras . '>' . $iva_closed_text . '</span>';
                         } elseif (($ivbh_day_open != '' || $ivbh_day_start != '') && ($ivbh_day_close != '' || $ivbh_day_end != '')) {
                             // Start hours
                             if ($ivbh_day_open && $ivbh_day_start) {
                                 $iva_bh_start_hrs = $ivbh_day_open . $ivbh_day_start;
                             } else {
                                 if ($ivbh_day_open != '') {
                                     $iva_bh_start_hrs = $ivbh_day_open;
                                 } elseif ($ivbh_day_start != '') {
                                     $iva_bh_start_hrs = $ivbh_day_start;
                                 }
                             }
                             // End hours
                             if ($ivbh_day_close && $ivbh_day_end) {
                                 $iva_bh_end_hrs = $ivbh_day_close . $ivbh_day_end;
                             } else {
                                 if ($ivbh_day_close != '') {
                                     $iva_bh_end_hrs = $ivbh_day_close;
                                 } elseif ($ivbh_day_end != '') {
                                     $iva_bh_end_hrs = $ivbh_day_end;
                                 }
                             }
                             $ivbh_arr[$day] = $iva_bh_start_hrs . $iva_time_separator . $iva_bh_end_hrs;
                         }
                         //
                         if ($iva_toggle_enable == 'on') {
                             // Today result
                             $iva_bh_today = date_i18n('l', strtotime(date('l')));
                             if ($iva_bh_today === $day) {
                                 if ($k == 0) {
                                     $today_output .= '<div class="today-result">';
                                     $today_output .= '<p><span class="days">' . $iva_today_text . '<span class="iva-bh-oc-text" ' . $open_css . '>' . $iva_oc_text . '</span></span>';
                                 }
                                 if ($ivbh_day_open == '' && $ivbh_day_close == '' && $ivbh_day_end == '' && $ivbh_day_start == '') {
                                     $today_output .= '<span class="hours"><span class="closed" ' . $cssextras . '>' . $iva_closed_text . '</span></span>';
                                 } else {
                                     $today_output .= '<span class="hours">' . $ivbh_today_hrs_array[$iva_bh_today] . '</span>';
                                     $k++;
                                     if ($iva_row_count == $k) {
                                         $k = 0;
                                         $today_output .= '</p>';
                                     }
                                 }
                                 if ($k == 0) {
                                     $today_output .= '<div id="' . $iva_bh_class . '" class="iva-bh-tg">';
                                     $today_output .= '<span class="ivbh-seemore">' . $iva_see_more_text . '<span class="arrow"></span></span>';
                                     $today_output .= '</div>';
                                     //iva-bh-tg
                                     $today_output .= '</div>';
                                     //.today-result
                                 }
                             }
                         }
                         if ($iva_grouping_enable != 'on') {
                             if ($j == '0') {
                                 $out .= '<p>';
                                 $iva_bh_day = '&nbsp;' . $day;
                             } else {
                                 $iva_bh_day = '';
                             }
                             // Get Current Day output
                             if ($iva_bh_day != '') {
                                 $iva_bh_today = date_i18n('l', strtotime(date('l')));
                                 if ($iva_bh_today === $day && $iva_todaydate_enable == 'on') {
                                     $select_today = 'select-today';
                                     $today_css = $today_color != '' ? ' style="' . $today_color . '"' : '';
                                 } else {
                                     $select_today = $today_css = '';
                                 }
                                 $out .= '<span class="days ' . $select_today . '" ' . $today_css . '>' . $iva_bh_day . '</span>';
                             }
                             // with out group hours array
                             $out .= '<span class="hours ' . $select_today . '" ' . $today_css . '>' . $ivbh_arr[$day] . '</span>';
                             $j++;
                             if ($iva_row_count == $j) {
                                 $j = 0;
                                 $out .= '</p>';
                             }
                         } else {
                             // grouping hours array
                             if ($ivbh_day_open == '' && $ivbh_day_close == '' && $ivbh_day_end == '' && $ivbh_day_start == '') {
                                 $iva_bh_hrs[] = '<span class="closed" ' . $cssextras . '>' . $iva_closed_text . '</span>';
                             } elseif (($ivbh_day_open != '' || $ivbh_day_start != '') && ($ivbh_day_close != '' || $ivbh_day_end != '')) {
                                 // Start hours
                                 if ($ivbh_day_open && $ivbh_day_start) {
                                     $iva_bh_start_hrs = $ivbh_day_open . '&nbsp;' . $ivbh_day_start;
                                 } else {
                                     if ($ivbh_day_open != '') {
                                         $iva_bh_start_hrs = $ivbh_day_open;
                                     } elseif ($ivbh_day_start != '') {
                                         $iva_bh_start_hrs = $ivbh_day_start;
                                     }
                                 }
                                 // End hours
                                 if ($ivbh_day_close && $ivbh_day_end) {
                                     $iva_bh_end_hrs = $ivbh_day_close . '&nbsp;' . $ivbh_day_end;
                                 } else {
                                     if ($ivbh_day_close != '') {
                                         $iva_bh_end_hrs = $ivbh_day_close;
                                     } elseif ($ivbh_day_end != '') {
                                         $iva_bh_end_hrs = $ivbh_day_end;
                                     }
                                 }
                                 $iva_bh_hrs[] = $iva_bh_start_hrs . $iva_time_separator . $iva_bh_end_hrs;
                             }
                             $ivbh_hours_array[$day] = $iva_bh_hrs;
                         }
                     }
                 }
             }
             if ($iva_grouping_enable == 'on') {
                 $out .= iva_bh_grouping_hours($ivbh_hours_array, $iva_todaydate_enable, $today_color);
             }
             $out .= '</div>';
             if ($iva_descripion_enable != 'on') {
                 if ($iva_descripion_prefix != 'on') {
                     $out .= '<div class="ivabh-desc">' . $iva_descripion . '</div>';
                 }
             }
         }
     }
     $output .= '<div class="iva_bh_shortcode" ' . $iva_bh_style . '>';
     $output .= $today_output;
     $output .= '<div class="ivabh-businesshours">';
     $output .= $out;
     $output .= '</div>';
     //ivabh-businesshours
     $output .= '</div>';
     //iva_bh_shortcode
     return $output;
 }
 function widget($args, $instance)
 {
     extract($args);
     /* Our variables from the widget settings. */
     $iva_bhrs_title = $instance['iva_bhrs_title'];
     $iva_bhrs_id = $instance['iva_bhrs_id'];
     $iva_bhrs_class = isset($instance['iva_bhrs_class']) ? $instance['iva_bhrs_class'] : '';
     $iva_grouping_hrs = isset($instance['iva_grouping_hrs']) ? $instance['iva_grouping_hrs'] : '';
     // Fetch Data
     global $wpdb;
     $ivbh_title = $ivbh_day_open = $ivbh_day_close = $output = $today_output = $out = $hrs_css = '';
     $iva_bh_class = 'show' . rand('10', '100');
     $iva_bh_sql = "SELECT * FROM {$wpdb->iva_businesshours} where id='" . $iva_bhrs_id . "'";
     $iva_bh_results = $wpdb->get_results($iva_bh_sql, ARRAY_A);
     $iva_bh_time_format = get_option('iva_bh_time_format') ? get_option('iva_bh_time_format') : 'H:i';
     $iva_see_more_text = get_option('iva_seemore_text') ? get_option('iva_seemore_text') : __('See more', 'iva_business_hours');
     $iva_today_text = get_option('iva_today_text') ? get_option('iva_today_text') : __('Today', 'iva_business_hours');
     $iva_oc_img = $iva_oc_text = '';
     if ($iva_bh_results) {
         foreach ($iva_bh_results as $iva_bh_data) {
             $iva_descripion_prefix = $iva_descripion_enable = $iva_descripion = $iva_todaydate_enable = $iva_grouping_enable = $iva_closed_bg_color = $iva_current_day_color = '';
             $iva_toggle_enable = $cssextras = $iva_open_image = $iva_close_image = $iva_oc_img = $iva_bh_start_hrs = $iva_bh_end_hrs = $iva_oc_text = '';
             $iva_today_timings = $iva_bh_oc_timings = array();
             $iva_bh_title = $iva_bh_data['title'];
             if ($iva_bh_data['closedtext']) {
                 $iva_closed_text = $iva_bh_data['closedtext'];
             } else {
                 $iva_closed_text = __('Closed', 'iva_business_hours');
             }
             if ($iva_bh_data['opentext']) {
                 $iva_open_text = $iva_bh_data['opentext'];
             } else {
                 $iva_open_text = __('Open', 'iva_business_hours');
             }
             if ($iva_bh_data['timeseparator']) {
                 $iva_time_separator = $iva_bh_data['timeseparator'];
             } else {
                 $iva_time_separator = '-';
             }
             if ($iva_bh_data['description']) {
                 $iva_descripion = $iva_bh_data['description'];
             }
             if ($iva_bh_data['descriptionprefix']) {
                 $iva_descripion_prefix = $iva_bh_data['descriptionprefix'];
             }
             if ($iva_bh_data['descriptionenable']) {
                 $iva_descripion_enable = $iva_bh_data['descriptionenable'];
             }
             if ($iva_bh_data['todaydate']) {
                 $iva_todaydate_enable = $iva_bh_data['todaydate'];
             }
             if (isset($iva_bh_data['grouping_enable'])) {
                 $iva_grouping_enable = $iva_bh_data['grouping_enable'];
             }
             if (isset($iva_bh_data['closed_bg_color'])) {
                 $iva_closed_bg_color = $iva_bh_data['closed_bg_color'];
             }
             if (isset($iva_bh_data['open_bg_color'])) {
                 $iva_open_bg_color = $iva_bh_data['open_bg_color'];
             }
             if (isset($iva_bh_data['current_day_color'])) {
                 $iva_current_day_color = $iva_bh_data['current_day_color'];
             }
             if (isset($iva_bh_data['toggle_enable'])) {
                 $iva_toggle_enable = $iva_bh_data['toggle_enable'];
             }
             if (isset($iva_bh_data['open_image'])) {
                 $iva_open_image = $iva_bh_data['open_image'];
             }
             if (isset($iva_bh_data['close_image'])) {
                 $iva_close_image = $iva_bh_data['close_image'];
             }
             // Open Close Image
             $iva_current_day = date_i18n('N', strtotime(date('N')));
             $iva_weekday = 'weekday' . $iva_current_day;
             $iva_today_data = json_decode($iva_bh_data[$iva_weekday]);
             if (!empty($iva_today_data)) {
                 foreach ($iva_today_data as $key => $value) {
                     $iva_today_timings = $value;
                 }
                 if (!empty($iva_today_data)) {
                     foreach ($iva_today_timings as $key => $value) {
                         $iva_bh_oc_timings['open'][] = $value->open;
                         $iva_bh_oc_timings['close'][] = $value->close;
                     }
                     $max_value = max($iva_bh_oc_timings['close']);
                     $min_value = min($iva_bh_oc_timings['open']);
                     $iva_curent_time = get_date_from_gmt(date('Y-m-d H:i:s', time()), 'H:i');
                     if (!empty($iva_bh_oc_timings)) {
                         // Open text and image
                         if (strtotime($iva_curent_time) >= strtotime($min_value) || strtotime($iva_curent_time) <= strtotime($max_value)) {
                             $iva_oc_text = $iva_open_text;
                             if ($iva_open_image != '') {
                                 $iva_oc_img = '<figure><img class="ivabh_open_img" src="' . $iva_open_image . '" width="470" height="300"></figure>';
                             }
                         }
                         // Close text and image
                         if (strtotime($iva_curent_time) < strtotime($min_value) || strtotime($iva_curent_time) > strtotime($max_value)) {
                             $iva_oc_text = $iva_closed_text;
                             if ($iva_close_image != '') {
                                 $iva_oc_img = '<figure><img class="ivabh_close_img" src="' . $iva_close_image . '" width="470" height="300"></figure>';
                             }
                         }
                     }
                 }
             }
             // Open Close Image
             $j = $k = 0;
             $select_today = $cssextras = '';
             $ivbh_hrs_array = array();
             $closed_bgcolor = isset($iva_closed_bg_color) ? 'background-color:' . $iva_closed_bg_color . ';' : '';
             $open_bgcolor = isset($iva_open_bg_color) ? 'background-color:' . $iva_open_bg_color . ';' : '';
             $cssextras = $closed_bgcolor != '' ? ' style="' . $closed_bgcolor . '"' : '';
             $open_css = $open_bgcolor != '' ? ' style="' . $open_bgcolor . '"' : '';
             $hrs_css = $iva_toggle_enable == 'on' ? 'style="display:none;"' : '';
             $today_color = isset($iva_current_day_color) ? 'color:' . $iva_current_day_color . ';' : '';
             if (isset($iva_grouping_hrs) && $iva_grouping_hrs != '') {
                 $iva_grouping_enable = $iva_grouping_hrs;
             }
             if ($iva_descripion_enable != 'on') {
                 if ($iva_descripion_prefix == 'on') {
                     $out .= '<div class="ivabh-desc">' . $iva_descripion . '</div>';
                 }
             }
             $out .= '<div class="ivabh-hours ' . $iva_bh_class . '" ' . $hrs_css . '>';
             foreach (iva_bh_getWeekdays() as $key => $day) {
                 $week_day_key = 'weekday' . $key;
                 $iva_bh_day = json_decode($iva_bh_data[$week_day_key]);
                 $iva_bh_hrs = array();
                 foreach ($iva_bh_day as $key => $value) {
                     $iva_row_count = count($value);
                     foreach ($value as $time) {
                         $ivbh_day_open = iva_bh_formatTime($time->open, $iva_bh_time_format);
                         $ivbh_day_close = iva_bh_formatTime($time->close, $iva_bh_time_format);
                         $ivbh_day_start = isset($time->starttime) ? $time->starttime : '';
                         $ivbh_day_end = isset($time->latetime) ? $time->latetime : '';
                         if ($ivbh_day_start != '') {
                             $ivbh_day_start = '<span class="iva-bh-stext">' . $ivbh_day_start . '</span>';
                         }
                         if ($ivbh_day_end != '') {
                             $ivbh_day_end = '<span class="iva-bh-etext">' . $ivbh_day_end . '</span>';
                         }
                         //	 Today hours array
                         if ($ivbh_day_open == '' && $ivbh_day_close == '' && $ivbh_day_end == '' && $ivbh_day_start == '') {
                             $ivbh_today_hrs_array[$day] = '<span class="closed" ' . $cssextras . '>' . $iva_closed_text . '</span>';
                         } elseif (($ivbh_day_open != '' || $ivbh_day_start != '') && ($ivbh_day_close != '' || $ivbh_day_end != '')) {
                             $ivbh_today_hrs_array[$day] = $ivbh_day_open . $ivbh_day_start . $iva_time_separator . $ivbh_day_close . $ivbh_day_end;
                         }
                         //
                         // with out group hours array
                         if ($ivbh_day_open == '' && $ivbh_day_close == '' && $ivbh_day_end == '' && $ivbh_day_start == '') {
                             $ivbh_arr[$day] = '<span class="closed" ' . $cssextras . '>' . $iva_closed_text . '</span>';
                         } elseif (($ivbh_day_open != '' || $ivbh_day_start != '') && ($ivbh_day_close != '' || $ivbh_day_end != '')) {
                             // Start hours
                             if ($ivbh_day_open && $ivbh_day_start) {
                                 $iva_bh_start_hrs = $ivbh_day_open . $ivbh_day_start;
                             } else {
                                 if ($ivbh_day_open != '') {
                                     $iva_bh_start_hrs = $ivbh_day_open;
                                 } elseif ($ivbh_day_start != '') {
                                     $iva_bh_start_hrs = $ivbh_day_start;
                                 }
                             }
                             // End hours
                             if ($ivbh_day_close && $ivbh_day_end) {
                                 $iva_bh_end_hrs = $ivbh_day_close . $ivbh_day_end;
                             } else {
                                 if ($ivbh_day_close != '') {
                                     $iva_bh_end_hrs = $ivbh_day_close;
                                 } elseif ($ivbh_day_end != '') {
                                     $iva_bh_end_hrs = $ivbh_day_end;
                                 }
                             }
                             $ivbh_arr[$day] = $iva_bh_start_hrs . $iva_time_separator . $iva_bh_end_hrs;
                         }
                         //
                         if ($iva_toggle_enable == 'on') {
                             // Today result
                             $iva_bh_today = date_i18n('l', strtotime(date('l')));
                             if ($iva_bh_today === $day) {
                                 if ($k == 0) {
                                     $today_output .= '<div class="today-result">';
                                     $today_output .= '<p><span class="days">' . $iva_today_text . '<span class="iva-bh-oc-text" ' . $open_css . '>' . $iva_oc_text . '</span></span>';
                                 }
                                 if ($ivbh_day_open == '' && $ivbh_day_close == '' && $ivbh_day_end == '' && $ivbh_day_start == '') {
                                     $today_output .= '<span class="hours"><span class="closed" ' . $cssextras . '>' . $iva_closed_text . '</span></span>';
                                 } else {
                                     $today_output .= '<span class="hours">' . $ivbh_today_hrs_array[$iva_bh_today] . '</span>';
                                     $k++;
                                     if ($iva_row_count == $k) {
                                         $k = 0;
                                         $today_output .= '</p>';
                                     }
                                 }
                                 if ($k == 0) {
                                     $today_output .= '<div id="' . $iva_bh_class . '" class="iva-bh-tg">';
                                     $today_output .= '<span class="ivbh-seemore"> ' . $iva_see_more_text . '<span class="arrow"></span></span>';
                                     $today_output .= '</div>';
                                     //iva-bh-tg
                                     $today_output .= '</div>';
                                     //.today-result
                                 }
                             }
                         }
                         if ($iva_grouping_enable != 'on') {
                             if ($j == '0') {
                                 $out .= '<p>';
                                 $iva_bh_day = '&nbsp;' . $day;
                             } else {
                                 $iva_bh_day = '';
                             }
                             if ($iva_bh_day != '') {
                                 // Get Current day
                                 $iva_bh_today = date_i18n('l', strtotime(date('l')));
                                 if ($iva_bh_today === $day && $iva_todaydate_enable == 'on') {
                                     $select_today = 'select-today';
                                     $today_css = $today_color != '' ? ' style="' . $today_color . '"' : '';
                                 } else {
                                     $select_today = $today_css = '';
                                 }
                                 $out .= '<span class="days ' . $select_today . '" ' . $today_css . '>' . $iva_bh_day . '</span>';
                             }
                             // with out group hours array
                             $out .= '<span class="hours ' . $select_today . '" ' . $today_css . '>' . $ivbh_arr[$day] . '</span>';
                             $j++;
                             if ($iva_row_count == $j) {
                                 $j = 0;
                                 $out .= '</p>';
                             }
                         } else {
                             // grouping hours array
                             if ($ivbh_day_open == '' && $ivbh_day_close == '' && $ivbh_day_end == '' && $ivbh_day_start == '') {
                                 $iva_bh_hrs[] = '<span class="closed" ' . $cssextras . '>' . $iva_closed_text . '</span>';
                             } elseif (($ivbh_day_open != '' || $ivbh_day_start != '') && ($ivbh_day_close != '' || $ivbh_day_end != '')) {
                                 // Start hours
                                 if ($ivbh_day_open && $ivbh_day_start) {
                                     $iva_bh_start_hrs = $ivbh_day_open . '&nbsp;' . $ivbh_day_start;
                                 } else {
                                     if ($ivbh_day_open != '') {
                                         $iva_bh_start_hrs = $ivbh_day_open;
                                     } elseif ($ivbh_day_start != '') {
                                         $iva_bh_start_hrs = $ivbh_day_start;
                                     }
                                 }
                                 // End hours
                                 if ($ivbh_day_close && $ivbh_day_end) {
                                     $iva_bh_end_hrs = $ivbh_day_close . '&nbsp;' . $ivbh_day_end;
                                 } else {
                                     if ($ivbh_day_close != '') {
                                         $iva_bh_end_hrs = $ivbh_day_close;
                                     } elseif ($ivbh_day_end != '') {
                                         $iva_bh_end_hrs = $ivbh_day_end;
                                     }
                                 }
                                 $iva_bh_hrs[] = $iva_bh_start_hrs . $iva_time_separator . $iva_bh_end_hrs;
                             }
                             $ivbh_hours_array[$day] = $iva_bh_hrs;
                         }
                     }
                 }
             }
             if ($iva_grouping_enable == 'on') {
                 $out .= iva_bh_grouping_hours($ivbh_hours_array, $iva_todaydate_enable, $today_color);
             }
             $out .= '</div>';
             if ($iva_descripion_enable != 'on') {
                 if ($iva_descripion_prefix != 'on') {
                     $out .= '<div class="ivabh-desc">' . $iva_descripion . '</div>';
                 }
             }
         }
     }
     $before_widget = preg_replace('/class="/', 'class="' . $iva_bhrs_class . ' ', $before_widget);
     echo $before_widget;
     if ($iva_bhrs_title != '') {
         echo $before_title . $iva_bhrs_title . $after_title;
     }
     if ($iva_oc_img != '') {
         echo $iva_oc_img;
     }
     echo $today_output;
     echo $out;
     echo $after_widget;
 }
function iva_bh_update()
{
    $iva_bh_id = isset($_POST['iva_bh_id']) ? esc_html($_POST['iva_bh_id']) : '';
    $postForm = isset($_POST['data']) ? $_POST['data'] : '';
    $error = $iva_bh_title = '';
    $error = $iva_bh_shortcode = $iva_desc_enable = $iva_desc_prefix = $iva_today_date = $iva_time_separator = '';
    $iva_bh_alias = $iva_description = $iva_closed_text = $iva_open_text = $iva_closed_bg_color = $iva_open_bg_color = $iva_current_day_color = $iva_grouping_enable = '';
    $iva_toggle_enable = $iva_oc_image = $iva_open_image = $iva_close_image = '';
    $post = !empty($_POST) ? true : false;
    /**
     * function parse_str
     * @param 'str' inpput string
     * @param 'arr' If the second parameter arr is present, variables are stored in this variable as array elements instead. 
     * @return No value is returned. 
     */
    parse_str($postForm, $formdata);
    // Name validation
    if ($formdata['iva_bh_title'] != '') {
        $iva_bh_title = $formdata['iva_bh_title'];
    } else {
        $error .= __('Enter Title', 'iva_business_hours');
    }
    if ($formdata['iva_bh_alias'] != '') {
        $alias_string = strtolower(trim(str_replace(' ', '-', $formdata['iva_bh_alias'])));
        // Replaces all spaces with hyphens.
        $iva_bh_alias = preg_replace('/[^A-Za-z0-9\\-\\(\\) ]/', '', $alias_string);
        // Removes special chars.
        global $wpdb;
        $iva_bh_alias_sql = "SELECT alias FROM {$wpdb->iva_businesshours} where id!= {$iva_bh_id}";
        $iva_bh_result_row = $wpdb->get_col($iva_bh_alias_sql);
        if (!empty($iva_bh_result_row)) {
            if (in_array($iva_bh_alias, $iva_bh_result_row)) {
                $error .= __('Alias Exist', 'iva_business_hours') . '<br>';
            }
        }
    } else {
        $error .= __('Enter Alias', 'iva_business_hours') . '<br>';
    }
    if (isset($formdata['iva_description']) && $formdata['iva_description'] != '') {
        $iva_description = $formdata['iva_description'];
    }
    if (isset($formdata['iva_closed_text']) && $formdata['iva_closed_text'] != '') {
        $iva_closed_text = $formdata['iva_closed_text'];
    }
    if (isset($formdata['iva_open_text']) && $formdata['iva_open_text'] != '') {
        $iva_open_text = $formdata['iva_open_text'];
    }
    if (isset($formdata['iva_bh_shortcode']) && $formdata['iva_bh_shortcode'] != '') {
        $iva_bh_shortcode = $formdata['iva_bh_shortcode'];
    }
    if (isset($formdata['iva_time_separator']) && $formdata['iva_time_separator'] != '') {
        $iva_time_separator = $formdata['iva_time_separator'];
    }
    if (isset($formdata['iva_desc_enable']) && $formdata['iva_desc_enable'] != '') {
        $iva_desc_enable = $formdata['iva_desc_enable'];
    }
    if (isset($formdata['iva_desc_prefix']) && $formdata['iva_desc_prefix'] != '') {
        $iva_desc_prefix = $formdata['iva_desc_prefix'];
    }
    if (isset($formdata['iva_today_date']) && $formdata['iva_today_date'] != '') {
        $iva_today_date = $formdata['iva_today_date'];
    }
    if (isset($formdata['iva_closed_bg_color']) && $formdata['iva_closed_bg_color'] != '') {
        $iva_closed_bg_color = $formdata['iva_closed_bg_color'];
    }
    if (isset($formdata['iva_open_bg_color']) && $formdata['iva_open_bg_color'] != '') {
        $iva_open_bg_color = $formdata['iva_open_bg_color'];
    }
    if (isset($formdata['iva_grouping_enable']) && $formdata['iva_grouping_enable'] != '') {
        $iva_grouping_enable = $formdata['iva_grouping_enable'];
    }
    if (isset($formdata['iva_toggle_enable']) && $formdata['iva_toggle_enable'] != '') {
        $iva_toggle_enable = $formdata['iva_toggle_enable'];
    }
    if (isset($formdata['iva_current_day_color']) && $formdata['iva_current_day_color'] != '') {
        $iva_current_day_color = $formdata['iva_current_day_color'];
    }
    if (isset($formdata['iva_open_image']) && $formdata['iva_open_image'] != '') {
        $iva_open_image = $formdata['iva_open_image'];
    }
    if (isset($formdata['iva_close_image']) && $formdata['iva_close_image'] != '') {
        $iva_close_image = $formdata['iva_close_image'];
    }
    global $wpdb;
    if (!$error) {
        foreach (iva_bh_getWeekdays() as $key => $day) {
            $week_day_key = 'weekday' . $key;
            $label_key = 'iva_' . $week_day_key . '_hrs';
            $iva_bh_time = $iva_bh_arr = '';
            $iva_bh_arr = $formdata['iva_bh'][$key];
            foreach ($iva_bh_arr as $iva_bh_arr_key => $test2) {
                $iva_late_time = isset($formdata['iva_bh'][$key][$iva_bh_arr_key]['latetime']) ? $formdata['iva_bh'][$key][$iva_bh_arr_key]['latetime'] : '';
                $iva_start_time = isset($formdata['iva_bh'][$key][$iva_bh_arr_key]['starttime']) ? $formdata['iva_bh'][$key][$iva_bh_arr_key]['starttime'] : '';
                $iva_bh_time[$key][$iva_bh_arr_key]['open'] = iva_bh_formatTime($formdata['iva_bh'][$key][$iva_bh_arr_key]['open'], 'H:i');
                $iva_bh_time[$key][$iva_bh_arr_key]['close'] = iva_bh_formatTime($formdata['iva_bh'][$key][$iva_bh_arr_key]['close'], 'H:i');
                $iva_bh_time[$key][$iva_bh_arr_key]['latetime'] = $iva_late_time;
                $iva_bh_time[$key][$iva_bh_arr_key]['starttime'] = $iva_start_time;
            }
            ${$label_key} = json_encode($iva_bh_time);
        }
        $iva_bh_shortcode = stripslashes($iva_bh_shortcode);
        $wpdb->update($wpdb->iva_businesshours, array('title' => $iva_bh_title, 'alias' => $iva_bh_alias, 'shortcode' => $iva_bh_shortcode, 'weekday0' => $iva_weekday0_hrs, 'weekday1' => $iva_weekday1_hrs, 'weekday2' => $iva_weekday2_hrs, 'weekday3' => $iva_weekday3_hrs, 'weekday4' => $iva_weekday4_hrs, 'weekday5' => $iva_weekday5_hrs, 'weekday6' => $iva_weekday6_hrs, 'closedtext' => $iva_closed_text, 'opentext' => $iva_open_text, 'timeseparator' => $iva_time_separator, 'description' => $iva_description, 'todaydate' => $iva_today_date, 'descriptionprefix' => $iva_desc_prefix, 'descriptionenable' => $iva_desc_enable, 'closed_bg_color' => $iva_closed_bg_color, 'open_bg_color' => $iva_open_bg_color, 'current_day_color' => $iva_current_day_color, 'grouping_enable' => $iva_grouping_enable, 'toggle_enable' => $iva_toggle_enable, 'open_image' => $iva_open_image, 'close_image' => $iva_close_image), array('id' => $iva_bh_id), array("%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s"), array('%d'));
        $response = '<div id="iva_bh_msg" class="updated success is-dismissible clearfix"><p>' . __('Updated Successfully', 'iva_business_hours') . '</p><button class="notice-dismiss" type="button"><span class="screen-reader-text">Dismiss this notice.</span></button></div>';
    } else {
        $response = '<div id="iva_bh_msg" class="updated error is-dismissible clearfix"><p>' . $error . '</p><button class="notice-dismiss" type="button"><span class="screen-reader-text">Dismiss this notice.</span></button></div>';
    }
    echo $response;
    exit;
}