master
campi 2 years ago
parent 04305b554d
commit 3cf1b73f5a

@ -47,7 +47,7 @@ function orari_dirette_input($post)
$broadcast = term_exists('Podcast', 'category', 0);
$old_term = term_exists($post->post_title, 'category', $broadcast);
?>
<input type="hidden" name="taxonomy_id" value="<?php echo $old_term['term_id'] ?>" />
<input type="hidden" name="taxonomy_id" value="<?php echo $old_term['term_id'] ?>" /> // non funziona dioporcolo
<?php
for ($x=0;$x<7;$x++) :
$onair_day[$x] = isset($values['on_air_day_'.$x]) ? esc_attr($values['on_air_day_'.$x][0]) : '';
@ -58,6 +58,9 @@ function orari_dirette_input($post)
$broadcast[$x] = term_exists('Podcast', 'category', 0);
$old_term[$x] = term_exists($post->post_title, 'category', $broadcast); ?>
<div style='width:100%;float:left;'>
<h3>Diretta n. <?php echo $x+1; ?></h3>
</div>
<div style='width:20%;float:left;'>
<select name="on_air_day_<?php echo $x; ?>" id="on_air_day_<?php echo $x; ?>">
<option <?php echo ($onair_day[$x]=='') ? 'selected' : ''; ?> value="">Seleziona un giorno</option>
@ -95,7 +98,7 @@ function orari_dirette_input($post)
<div style="clear:both;"></div>
<?php
endfor;
wp_enqueue_script('add_onchange_listener', plugin_dir_url(__FILE__).'js/add_onchange_listener.js', array(), '1.0', true);
wp_enqueue_script('add_onchange_listener', plugin_dir_url(__FILE__).'js/add_onchange_listener.js', array(), '1.2', true);
}

@ -1,27 +1,27 @@
// change the date field consistently with day field
function add_change_day_handler(elem, day_field_id, date_field_id) {
function add_change_day_handler(elem, day_input_id, startdate_input_id) {
elem.addEventListener('change', function(e) {
const setted_weekday = document.getElementById(day_field_id).value;
const date_input = document.getElementById(date_field_id);
if (date_input.value.length !== 0 && setted_weekday.length !== 0){
const date = new Date(date_input.value);
const setted_weekday = document.getElementById(day_input_id).value;
const startdate_input = document.getElementById(startdate_input_id);
if (startdate_input.value.length !== 0 && setted_weekday.length !== 0){
const date = new Date(startdate_input.value);
let weekday = date.getDay();
weekday = (weekday == 0) ? 7 : weekday;
if (weekday != setted_weekday ) {
let weekday_diff = setted_weekday - weekday;
date.setDate(date.getDate() + weekday_diff);
date_input.value = date.toISOString().split('T')[0];
startdate_input.value = date.toISOString().split('T')[0];
}
}
});
}
// change the day field consistently with date field
function add_change_date_handler(elem, day_field_id, date_field_id) {
// change the day field consistently with date field - unused!
function add_change_date_handler(elem, day_input_id, startdate_input_id) {
elem.addEventListener('change', function(e) {
const setted_date = document.getElementById(date_field_id).value;
const setted_date = document.getElementById(startdate_input_id).value;
if (setted_date.length !== 0) {
const day_input = document.getElementById(day_field_id);
const day_input = document.getElementById(day_input_id);
let setted_weekday = day_input.value;
let date_weekday = new Date(setted_date).getDay();
date_weekday = (date_weekday == 0) ? 7 : date_weekday;
@ -32,17 +32,51 @@ function add_change_date_handler(elem, day_field_id, date_field_id) {
});
}
function add_required_date_handler(elem, prefix, input_number) {
elem.addEventListener('change', function(e){
set_date_as_required_if_cadence_is_set(prefix, input_number);
});
}
function set_date_as_required_if_cadence_is_set(prefix, input_number) {
const cadence = document.getElementById(prefix + "_cadence_" + input_number);
const startdate = document.getElementById(prefix + "_startdate_" + input_number);
const msg = document.getElementById(prefix +"_message_" + input_number);
if (cadence.value != 1 && startdate.value == "") {
if (!msg){
const textAlert = document.createElement("p");
const text = document.createTextNode("attenzione: se non viene inserita la data di inizio la cadenza sarà interpretata come settimanale");
textAlert.appendChild(text);
textAlert.id = prefix + "_message_" + input_number;
textAlert.style = "color:red;font-size:12px;width:90%;";
startdate.parentNode.appendChild(textAlert);
}
} else {
if (msg) {
startdate.parentNode.removeChild(msg);
}
}
}
for (var i = 0; i < 7 ; i++) {
let onair_day_input = document.getElementById("on_air_day_" + i);
let rerun_day_input = document.getElementById("rerun_day_" + i);
let onair_date_input = document.getElementById("on_air_start_date_" + i);
let rerun_date_input = document.getElementById("rerun_start_date_" + i);
add_change_day_handler(onair_day_input, "on_air_day_" + i, "on_air_start_date_" + i);
add_change_day_handler(rerun_day_input, "rerun_day_" + i, "rerun_start_date_" + i);
add_change_day_handler(onair_date_input, "on_air_day_" + i, "on_air_start_date_" + i);
add_change_day_handler(rerun_date_input, "rerun_day_" + i, "rerun_start_date_" + i);
// add_change_date_handler(onair_date_input, "on_air_day_" + i, "on_air_start_date_" + i);
// add_change_date_handler(rerun_date_input, "rerun_day_" + i, "rerun_start_date_" + i);
let onair_date_input = document.getElementById("on_air_startdate_" + i);
let rerun_date_input = document.getElementById("rerun_startdate_" + i);
let onair_cadence_input = document.getElementById("on_air_cadence_" + i);
let rerun_cadence_input = document.getElementById("rerun_cadence_" + i);
add_change_day_handler(onair_day_input, "on_air_day_" + i, "on_air_startdate_" + i);
add_change_day_handler(rerun_day_input, "rerun_day_" + i, "rerun_startdate_" + i);
add_change_day_handler(onair_date_input, "on_air_day_" + i, "on_air_startdate_" + i);
add_change_day_handler(rerun_date_input, "rerun_day_" + i, "rerun_startdate_" + i);
set_date_as_required_if_cadence_is_set("on_air", i);
set_date_as_required_if_cadence_is_set("rerun", i);
add_required_date_handler(onair_cadence_input, "on_air", i);
add_required_date_handler(rerun_cadence_input, "rerun", i);
add_required_date_handler(onair_date_input, "on_air", i);
add_required_date_handler(rerun_date_input, "rerun", i);
}

@ -3,15 +3,14 @@
function have_to_run_this_week($startdate_s, $cadence_i)
{
$today = (new DateTime())->setTime(0,0,0);
$cadence = empty($cadence_i) ? 1 : $cadence_i;
if (!empty($startdate_s)) {
$startdate = new DateTime($startdate_s);
if ($startdate > $today)
return false;
} else {
$cadence_i = 1;
}
}
$return_value;
switch($cadence_i) {
switch($cadence) {
case 1: //settimanale
$return_value = true;
break;
@ -29,7 +28,6 @@ function have_to_run_this_week($startdate_s, $cadence_i)
$return_value = false;
break;
case 5: //una volta al mese
print_r($startdate);
if (which_day_of_the_month($startdate) == which_day_of_the_month($today)) {
$return_value = true;
break;

Loading…
Cancel
Save