<?php
/**
* Rejestratorka Theme functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package Rejestratorka
* @since 1.0.0
*/
/**
* Define Constants
*/
define( 'CHILD_THEME_REJESTRATORKA_VERSION', '1.0.0' );
/**
* Enqueue styles
*/
function child_enqueue_styles() {
wp_enqueue_style( 'rejestratorka-theme-css', get_stylesheet_directory_uri() . '/style.css', array('astra-theme-css'), CHILD_THEME_REJESTRATORKA_VERSION, 'all' );
}
function sorbase_hook_javascript() {
?>
<script>
function addDays(date, days) {
let result = new Date(date);
result.setDate(result.getDate() + days);
return result;
}
function getSor() {
let sorDate = new Date();
let sorHours = "";
let time = sorDate.toLocaleTimeString("pl-PL", {
hour: "2-digit",
minute: "2-digit",
});
let date = sorDate.toLocaleDateString("pl-PL", {
day: "2-digit",
month: "2-digit",
});
let weekday = sorDate.toLocaleDateString("pl-PL", { weekday: "long" });
switch (weekday) {
case "sobota":
if (time > "11:45" && time <= "23:59") {
sorHours = "9-12";
sorDate = addDays(sorDate, 2);
} else if (time >= "00:00" && time <= "05:45") {
sorHours = "9-12";
} else if (time >= "05:46" && time <= "08:45") {
sorHours = "12-15";
} else if (time >= "08:46" && time <= "11:45") {
sorHours = "9-12";
sorDate = addDays(sorDate, 2);
}
break;
case "niedziela":
sorHours = "9-12";
sorDate = addDays(sorDate, 1);
break;
default:
if (time > "11:45" && time <= "23:59") {
sorHours = "9-12";
sorDate = addDays(sorDate, 1);
} else if (time >= "00:00" && time <= "05:45") {
sorHours = "9-12";
} else if (time >= "05:46" && time <= "08:45") {
sorHours = "12-15";
} else if (time >= "08:46" && time <= "11:45") {
sorHours = "15-18";
}
break;
}
let dateShort = sorDate.toLocaleDateString("pl-PL", {
day: "2-digit",
month: "2-digit",
});
let note = `<b>Data SOR: <font color='red'>${dateShort} </font>| Godziny SOR: <font color='red'>${sorHours}</font></b>`;
// console.log(note);
return note;
}
function sorTimer() {
allParagraphs = document.querySelectorAll(".sorNotes > p");
for (let i = 0; i < allParagraphs.length; i++) {
allParagraphs[i].innerHTML = getSor();
}
}
setInterval(sorTimer, 180000);
</script>
<?php
}
add_action( 'wp_enqueue_scripts', 'child_enqueue_styles', 15 );
add_action('wp_head', 'sorbase_hook_javascript');
/**
* Rest API
*
*/
add_action( 'rest_api_init' , function () {
register_rest_route(
'api/v2'
,'notatki'
,array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => 'handle_post_tripetto_webhook',
'permission_callback' => '__return_true'
) );
} );
function handle_post_tripetto_webhook( $request ) {
$body = $request->get_body();
$data = json_decode( $body );
import_data( $data );
return new WP_REST_Response( $data , 200 );
}
function import_data( $data ) {
global $wpdb;
$table_name = $wpdb->prefix . "notatki_ctt";
$wpdb->insert($table_name, array(
"cupii" => $data->cupii,
"notatka" => $data->Notatka,
"tripettoId" => $data->tripettoId,
"tripettoCreateDate" => date ('Y-m-d H:i:s', strtotime($data->tripettoCreateDate)),
"tripettoFingerprint" => $data->tripettoId
));
}
add_filter('https_ssl_verify', '__return_false');
?>