function get_times_from_bk_form($sdform, $my_dates, $bktype) { $start_time = $end_time = '00:00:00'; if (class_exists('wpdev_bk_biz_s')) { if (strpos($sdform, 'rangetime' . $bktype) !== false) { // Get START TIME From form request // Example of $sdform content. // ~checkbox^mymultiple4^~checkbox^rangetime4^ ~checkbox^rangetime4^12:00 - 13:00~ checkbox^rangetime4^~checkbox^rangetime4^~text^name4^Jonny~ //debuge($sdform); // Types of the conditions $f_type = '[^\\^]*'; // Any Field types $f_name = 'rangetime[\\d]*[\\[\\]]{0,2}'; // Any Field types $f_value = '[\\s]*([0-9:]*)[\\s]*\\-[\\s]*([0-9:]*)[\\s]*[^~]*'; // Any Field types $pattern_to_search = '%[~]?' . $f_type . '\\^' . $f_name . '\\^' . $f_value . '[~]?%'; preg_match_all($pattern_to_search, $sdform, $matches, PREG_SET_ORDER); /* Exmaple of $matches: * * Array ( [0] => Array ( [0] => ~checkbox^rangetime4^13:00 - 14:00~ [1] => 13:00 [2] => 14:00 ) ) */ //debuge($matches); if (count($matches) > 0) { $start_time = get_time_array_checked_on_AMPM(trim($matches[0][1])); $start_time[2] = '01'; $end_time = get_time_array_checked_on_AMPM(trim($matches[0][2])); $end_time[2] = '02'; if (count($my_dates) == 1) { // add end date if someone select only 1 day with time range $my_dates[] = $my_dates[0]; } } else { $start_time = array('00', '00', '01'); $end_time = array('00', '00', '02'); } } else { if (strpos($sdform, 'starttime' . $bktype) !== false) { // Get START TIME From form request $pos1 = strpos($sdform, 'starttime' . $bktype); // Find start time pos $pos1 = strpos($sdform, '^', $pos1) + 1; // Find TIME pos $pos2 = strpos($sdform, '~', $pos1); // Find TIME length if ($pos2 === false) { $pos2 = strlen($sdform); } $pos2 = $pos2 - $pos1; $start_time = substr($sdform, $pos1, $pos2); $start_time = explode(':', $start_time); if ($start_time == '') { $start_time = '00:00'; } $start_time[2] = '01'; } else { $start_time = explode(':', $start_time); } if (strpos($sdform, 'endtime' . $bktype) !== false) { // Get END TIME From form request $pos1 = strpos($sdform, 'endtime' . $bktype); // Find start time pos $pos1 = strpos($sdform, '^', $pos1) + 1; // Find TIME pos $pos2 = strpos($sdform, '~', $pos1); // Find TIME length if ($pos2 === false) { $pos2 = strlen($sdform); } $pos2 = $pos2 - $pos1; $end_time = substr($sdform, $pos1, $pos2); if ($end_time == '') { $end_time = '00:00'; } if (count($my_dates) == 1) { // add end date if someone select only 1 day with time range $my_dates[] = $my_dates[0]; } $end_time = explode(':', $end_time); $end_time[2] = '02'; } else { $end_time = explode(':', $end_time); } if (strpos($sdform, 'durationtime' . $bktype) !== false) { // Get END TIME From form request $pos1 = strpos($sdform, 'durationtime' . $bktype); // Find start time pos $pos1 = strpos($sdform, '^', $pos1) + 1; // Find TIME pos $pos2 = strpos($sdform, '~', $pos1); // Find TIME length if ($pos2 === false) { $pos2 = strlen($sdform); } $pos2 = $pos2 - $pos1; $end_time = substr($sdform, $pos1, $pos2); if (count($my_dates) == 1) { // add end date if someone select only 1 day with time range $my_dates[] = $my_dates[0]; } $end_time = explode(':', $end_time); // Here we are get start time and add duration for end time $new_end_time = mktime(intval($start_time[0]), intval($start_time[1])); $new_end_time = $new_end_time + $end_time[0] * 60 * 60 + $end_time[1] * 60; $end_time = date('H:i', $new_end_time); if ($end_time == '00:00') { $end_time = '23:59'; } $end_time = explode(':', $end_time); $end_time[2] = '02'; } } } return array($start_time, $end_time, $my_dates); }
function get_times_from_bk_form($sdform, $my_dates, $bktype) { $start_time = $end_time = '00:00:00'; if (class_exists('wpdev_bk_biz_s')) { if (strpos($sdform, 'rangetime' . $bktype) !== false) { // Get START TIME From form request $pos1 = strpos($sdform, 'rangetime' . $bktype); // Find start time pos $pos1 = strpos($sdform, '^', $pos1) + 1; // Find TIME pos $pos2 = strpos($sdform, '~', $pos1); // Find TIME length if ($pos2 === false) { $pos2 = strlen($sdform); } $pos2 = $pos2 - $pos1; $range_time = substr($sdform, $pos1, $pos2); $range_time = explode('-', $range_time); $start_time = get_time_array_checked_on_AMPM(trim($range_time[0])); $start_time[2] = '01'; $end_time = get_time_array_checked_on_AMPM(trim($range_time[1])); $end_time[2] = '02'; //$start_time = explode(':',trim($range_time[0])); //$start_time[2]='01'; //$end_time = explode(':',trim($range_time[1])); //$end_time[2]='02'; if (count($my_dates) == 1) { // add end date if someone select only 1 day with time range $my_dates[] = $my_dates[0]; } } else { if (strpos($sdform, 'starttime' . $bktype) !== false) { // Get START TIME From form request $pos1 = strpos($sdform, 'starttime' . $bktype); // Find start time pos $pos1 = strpos($sdform, '^', $pos1) + 1; // Find TIME pos $pos2 = strpos($sdform, '~', $pos1); // Find TIME length if ($pos2 === false) { $pos2 = strlen($sdform); } $pos2 = $pos2 - $pos1; $start_time = substr($sdform, $pos1, $pos2); $start_time = explode(':', $start_time); if ($start_time == '') { $start_time = '00:00'; } $start_time[2] = '01'; } else { $start_time = explode(':', $start_time); } if (strpos($sdform, 'endtime' . $bktype) !== false) { // Get END TIME From form request $pos1 = strpos($sdform, 'endtime' . $bktype); // Find start time pos $pos1 = strpos($sdform, '^', $pos1) + 1; // Find TIME pos $pos2 = strpos($sdform, '~', $pos1); // Find TIME length if ($pos2 === false) { $pos2 = strlen($sdform); } $pos2 = $pos2 - $pos1; $end_time = substr($sdform, $pos1, $pos2); if ($end_time == '') { $end_time = '00:00'; } if (count($my_dates) == 1) { // add end date if someone select only 1 day with time range $my_dates[] = $my_dates[0]; } $end_time = explode(':', $end_time); $end_time[2] = '02'; } else { $end_time = explode(':', $end_time); } if (strpos($sdform, 'durationtime' . $bktype) !== false) { // Get END TIME From form request $pos1 = strpos($sdform, 'durationtime' . $bktype); // Find start time pos $pos1 = strpos($sdform, '^', $pos1) + 1; // Find TIME pos $pos2 = strpos($sdform, '~', $pos1); // Find TIME length if ($pos2 === false) { $pos2 = strlen($sdform); } $pos2 = $pos2 - $pos1; $end_time = substr($sdform, $pos1, $pos2); if (count($my_dates) == 1) { // add end date if someone select only 1 day with time range $my_dates[] = $my_dates[0]; } $end_time = explode(':', $end_time); // Here we are get start time and add duration for end time $new_end_time = mktime($start_time[0], $start_time[1]); $new_end_time = $new_end_time + $end_time[0] * 60 * 60 + $end_time[1] * 60; $end_time = date('H:i', $new_end_time); $end_time = explode(':', $end_time); $end_time[2] = '02'; } } } return array($start_time, $end_time, $my_dates); }