master
campi 2 years ago
parent 437d5e1352
commit 4e97102c43

@ -30,8 +30,8 @@ function create_broadcast_post()
);
}
add_action('init', 'create_broadcast_post');
add_action('add_meta_boxes', 'live_meta_box_add');
function live_meta_box_add()
{
//give name of your input field
@ -60,14 +60,14 @@ function orari_dirette_input($post)
<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="selected"' : ''; ?> value="">Seleziona un giorno</option>
<option <?php echo ($onair_day[$x]==1) ? 'selected="selected"' : ''; ?> value="1">Luned&igrave;</option>
<option <?php echo ($onair_day[$x]==2) ? 'selected="selected"' : ''; ?> value="2">Marted&igrave;</option>
<option <?php echo ($onair_day[$x]==3) ? 'selected="selected"' : ''; ?> value="3">Mercoled&igrave;</option>
<option <?php echo ($onair_day[$x]==4) ? 'selected="selected"' : ''; ?> value="4">Gioved&igrave;</option>
<option <?php echo ($onair_day[$x]==5) ? 'selected="selected"' : ''; ?> value="5">Venerd&igrave;</option>
<option <?php echo ($onair_day[$x]==6) ? 'selected="selected"' : ''; ?> value="6">Sabato</option>
<option <?php echo ($onair_day[$x]==7) ? 'selected="selected"' : ''; ?> value="7">Domenica</option>
<option <?php echo ($onair_day[$x]=='') ? 'selected' : ''; ?> value="">Seleziona un giorno</option>
<option <?php echo ($onair_day[$x]==1) ? 'selected' : ''; ?> value="1">Luned&igrave;</option>
<option <?php echo ($onair_day[$x]==2) ? 'selected' : ''; ?> value="2">Marted&igrave;</option>
<option <?php echo ($onair_day[$x]==3) ? 'selected' : ''; ?> value="3">Mercoled&igrave;</option>
<option <?php echo ($onair_day[$x]==4) ? 'selected' : ''; ?> value="4">Gioved&igrave;</option>
<option <?php echo ($onair_day[$x]==5) ? 'selected' : ''; ?> value="5">Venerd&igrave;</option>
<option <?php echo ($onair_day[$x]==6) ? 'selected' : ''; ?> value="6">Sabato</option>
<option <?php echo ($onair_day[$x]==7) ? 'selected' : ''; ?> value="7">Domenica</option>
</select>
</div>
<div style='width:20%;float:left;'>
@ -77,9 +77,11 @@ function orari_dirette_input($post)
<div style='width:20%;float:left;'>
<select name="on_air_cadence_<?php echo $x; ?>" id="on_air_cadence_<?php echo $x; ?>">
<label for="on_air_cadence_<?php echo $x; ?>">Cadenza</label>
<option <?php echo ($onair_cadence[$x]==1) ? 'selected="selected"' : ''; ?> value="1">Una volta a settimana</option>
<option <?php echo ($onair_cadence[$x]==2) ? 'selected="selected"' : ''; ?> value="2">Una volta ogni 2 settimane</option>
<option <?php echo ($onair_cadence[$x]==4) ? 'selected="selected"' : ''; ?> value="4">Una volta ogni 4 settimane</option>
<option <?php echo ($onair_cadence[$x]==1) ? 'selected' : ''; ?> value="1">Una volta a settimana</option>
<option <?php echo ($onair_cadence[$x]==2) ? 'selected' : ''; ?> value="2">Una volta ogni 2 settimane</option>
<option <?php echo ($onair_cadence[$x]==3) ? 'selected' : ''; ?> value="3" type="hidden">Una volta ogni 3 settimane</option>
<option <?php echo ($onair_cadence[$x]==4) ? 'selected' : ''; ?> value="4">Una volta ogni 4 settimane</option>
<option <?php echo ($onair_cadence[$x]==5) ? 'selected' : ''; ?> value="5">Una volta al mese</option>
</select>
</div>
<div style='width:20%;float:left;'>
@ -93,6 +95,8 @@ function orari_dirette_input($post)
<div style="clear:both;"></div>
<?php
endfor;
wp_enqueue_script('add_onchange_listener', plugin_dir_url(__FILE__).'add_onchange_listener.js', array(), '1.0', true);
}
function orari_repliche_input($post)
@ -112,14 +116,14 @@ function orari_repliche_input($post)
</div>
<div style='width:20%;float:left;'>
<select name="rerun_day_<?php echo $x; ?>" id="rerun_day_<?php echo $x; ?>">
<option <?php echo ($rerun_day[$x]=='') ? 'selected="selected"' : ''; ?> value="">Seleziona un giorno</option>
<option <?php echo ($rerun_day[$x]==1) ? 'selected="selected"' : ''; ?> value="1">Luned&igrave;</option>
<option <?php echo ($rerun_day[$x]==2) ? 'selected="selected"' : ''; ?> value="2">Marted&igrave;</option>
<option <?php echo ($rerun_day[$x]==3) ? 'selected="selected"' : ''; ?> value="3">Mercoled&igrave;</option>
<option <?php echo ($rerun_day[$x]==4) ? 'selected="selected"' : ''; ?> value="4">Gioved&igrave;</option>
<option <?php echo ($rerun_day[$x]==5) ? 'selected="selected"' : ''; ?> value="5">Venerd&igrave;</option>
<option <?php echo ($rerun_day[$x]==6) ? 'selected="selected"' : ''; ?> value="6">Sabato</option>
<option <?php echo ($rerun_day[$x]==7) ? 'selected="selected"' : ''; ?> value="7">Domenica</option>
<option <?php echo ($rerun_day[$x]=='') ? 'selected' : ''; ?> value="">Seleziona un giorno</option>
<option <?php echo ($rerun_day[$x]==1) ? 'selected' : ''; ?> value="1">Luned&igrave;</option>
<option <?php echo ($rerun_day[$x]==2) ? 'selected' : ''; ?> value="2">Marted&igrave;</option>
<option <?php echo ($rerun_day[$x]==3) ? 'selected' : ''; ?> value="3">Mercoled&igrave;</option>
<option <?php echo ($rerun_day[$x]==4) ? 'selected' : ''; ?> value="4">Gioved&igrave;</option>
<option <?php echo ($rerun_day[$x]==5) ? 'selected' : ''; ?> value="5">Venerd&igrave;</option>
<option <?php echo ($rerun_day[$x]==6) ? 'selected' : ''; ?> value="6">Sabato</option>
<option <?php echo ($rerun_day[$x]==7) ? 'selected' : ''; ?> value="7">Domenica</option>
</select>
</div>
<div style='width:20%;float:left;'>
@ -129,9 +133,9 @@ function orari_repliche_input($post)
<div style='width:20%;float:left;'>
<select name="rerun_cadence_<?php echo $x; ?>" id="rerun_cadence_<?php echo $x; ?>">
<label for="rerun_cadence_<?php echo $x; ?>">Cadenza</label>
<option <?php echo ($rerun_cadence[$x]==1) ? 'selected="selected"' : ''; ?> value="1">Una volta a settimana</option>
<option <?php echo ($rerun_cadence[$x]==2) ? 'selected="selected"' : ''; ?> value="2">Una volta ogni 2 settimane</option>
<option <?php echo ($rerun_cadence[$x]==4) ? 'selected="selected"' : ''; ?> value="4">Una volta ogni 4 settimane</option>
<option <?php echo ($rerun_cadence[$x]==1) ? 'selected' : ''; ?> value="1">Una volta a settimana</option>
<option <?php echo ($rerun_cadence[$x]==2) ? 'selected' : ''; ?> value="2">Una volta ogni 2 settimane</option>
<option <?php echo ($rerun_cadence[$x]==4) ? 'selected' : ''; ?> value="4">Una volta ogni 4 settimane</option>
</select>
</div>
<div style='width:20%;float:left;'>
@ -166,12 +170,7 @@ function orari_dirette_save($post_id)
if (!current_user_can('edit_post', $post_id)) {
return;
}
/*
echo '<pre>';
print_r($_POST);
echo '</pre>';
exit();
*/
// now we can actually save the data
$allowed = array(
'a' => array( // on allow a tags
@ -199,17 +198,39 @@ function orari_dirette_save($post_id)
wp_insert_term($_POST['post_title'], 'category', $args);
}
update_post_meta($post_id, 'taxonomy_id', wp_kses($_POST['taxonomy_id'], $allowed));
for ($x=0;$x<7;$x++) {
update_post_meta($post_id, 'on_air_day_'.$x, wp_kses($_POST['on_air_day_'.$x], $allowed));
$onair_day_data = wp_kses($_POST['on_air_day_'.$x], $allowed);
$rerun_day_data = wp_kses($_POST['rerun_day_'.$x], $allowed);
$onair_start_date_data = wp_kses($_POST['on_air_start_date_'.$x], $allowed);
$rerun_start_date_data = wp_kses($_POST['rerun_start_date_'.$x], $allowed);
if (!empty($onair_day_data) && !empty($onair_start_date_data)) {
check_and_correct_start_date_flag($onair_start_date_data, $onair_day_data);
}
if (!empty($rerun_day_data) && !empty($rerun_start_date_data)) {
check_and_correct_start_date_flag($rerun_start_date_data, $rerun_day_data);
}
update_post_meta($post_id, 'on_air_day_'.$x, $onair_day_data);
update_post_meta($post_id, 'on_air_start_'.$x, wp_kses($_POST['on_air_start_'.$x], $allowed));
update_post_meta($post_id, 'on_air_end_'.$x, wp_kses($_POST['on_air_end_'.$x], $allowed));
update_post_meta($post_id, 'on_air_cadence_'.$x, wp_kses($_POST['on_air_cadence_'.$x], $allowed));
update_post_meta($post_id, 'on_air_start_date_'.$x, wp_kses($_POST['on_air_start_date_'.$x], $allowed));
update_post_meta($post_id, 'rerun_day_'.$x, wp_kses($_POST['rerun_day_'.$x], $allowed));
update_post_meta($post_id, 'rerun_day_'.$x, $rerun_day_data);
update_post_meta($post_id, 'rerun_start_'.$x, wp_kses($_POST['rerun_start_'.$x], $allowed));
update_post_meta($post_id, 'rerun_end_'.$x, wp_kses($_POST['rerun_end_'.$x], $allowed));
update_post_meta($post_id, 'rerun_cadence_'.$x, wp_kses($_POST['rerun_end_'.$x], $allowed));
update_post_meta($post_id, 'rerun_start_date_'.$x, wp_kses($_POST['rerun_start_date_'.$x], $allowed));
update_post_meta($post_id, 'rerun_cadence_'.$x, wp_kses($_POST['rerun_cadence_'.$x], $allowed));
update_post_meta($post_id, 'on_air_start_date_'.$x, $onair_start_date_data);
update_post_meta($post_id, 'rerun_start_date_'.$x, $rerun_start_date_data);
}
}
}
function check_and_correct_start_date_flag(&$start_date_ptr, $day) {
$start_date_dt = new DateTime($start_date_ptr);
$weekday_number = $start_date_dt->format("N");
if ($day != $weekday_number) {
$day_diff = $day - $weekday_number;
$start_date_dt->modify($day_diff." days");
$start_date_ptr = $start_date_dt->format("Y-m-d");
};
}

@ -0,0 +1,43 @@
// change, consistently with day field, the date field
function add_change_day_handler(elem, day_field_id, date_field_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){
const date = new Date(date_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.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
}
}
});
}
// change, consistently with date field, the day field
function add_change_date_handler(elem, day_field_id, date_field_id) {
elem.addEventListener('change', function(e) {
const setted_date = document.getElementById(date_field_id).value;
const day_input = document.getElementById(day_field_id);
let setted_weekday = day_input.value;
let date_weekday = new Date(setted_date).getDay();
date_weekday = (date_weekday == 0) ? 7 : date_weekday;
if (date_weekday != setted_weekday) {
day_input.value = date_weekday;
}
});
}
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_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);
}

@ -1,18 +1,20 @@
<?php
function have_to_run_this_week($start_date, $cadence)
//l'update deve impostare correttamente il valore della data per evitare inconsistenza sui dati
function have_to_run_this_week($start_date_s, $cadence_i)
{
$today = (new DateTime())->setTime(0,0,0);
$start_date = new DateTime($start_date_s);
$return_value;
switch($cadence) {
case 1:
switch($cadence_i) {
case 1: //settimanale
$return_value = true;
break;
case 2:
case 4:
$today = new DateTime();
$date = new DateTime($start_date);
$modulo = 7 * $cadence;
$date_difference = date_diff($today, $date);
case 2: //ogni 2 settimane
case 3:
case 4: //ogni 4 settimane
$modulo = 7 * $cadence_i;
$date_difference = date_diff($today, $start_date);
$days_difference = $date_difference->days;
if (($days_difference % $modulo) < 7) {
$return_value = true;
@ -20,11 +22,32 @@ function have_to_run_this_week($start_date, $cadence)
}
$return_value = false;
break;
case 5: //una volta al mese
if (which_day_of_the_month($start_date) == which_day_of_the_month($today)) {
$return_value = true;
break;
}
$return_value = false;
break;
}
return $return_value;
}
function which_day_of_the_month($datetime)
{
$weekday_literal = $datetime->format("l");
$weekday_iterator = clone($datetime);
$weekday_iterator->modify("first $weekday_literal of this month");
$count = 1;
while($datetime != $weekday_iterator && $count < 5) {
$weekday_iterator->modify("next $weekday_literal");
$count++;
}
return $count;
}
function show_palinsesto($args)
{
$week_days = ['Luned&igrave;','Marted&igrave;','Mercoled&igrave;','Gioved&igrave;','Venerd&igrave;','Sabato','Domenica'];
@ -77,12 +100,17 @@ function show_palinsesto($args)
$rerun_cadence = get_post_meta($post->ID, 'rerun_cadence_'.$d, true);
$rerun_start_date = get_post_meta($post->ID, 'rerun_start_date_'.$d, true);
/*
echo '<pre>';
print_r($post->ID . " - " . $rerun_day ." - " . $rerun_cadence);
echo '</pre>';
*/
if (!empty($rerun_day)&&!empty($rerun_start)&&!empty($rerun_end)) {
if (empty($rerun_cadence) || empty($rerun_start_date)) {
$rerun_cadence = "1"; //default settimanale
}
if (!empty($rerun_day)&&!empty($rerun_start)&&!empty($rerun_end)) {
if (have_to_run_this_week($rerun_start_date, (int)$rerun_cadence)) {
$palinsesto[(int)$rerun_day][(string)$rerun_start] =
array(
@ -102,17 +130,19 @@ function show_palinsesto($args)
ksort($palinsesto);
// echo '<pre>';
// print_r($palinsesto);
// echo '</pre>';
// echo '<pre>';
// print_r($palinsesto);
// echo '</pre>';
$today = date("N");
for ($x=1;$x<=7;$x++) {
/*echo '<pre>';
/*
echo '<pre>';
echo("$today,$x");
echo '</pre>';*/
echo '</pre>';
*/
if ($x == $today)
$tabs .= "<li class='default-gator-tab'>".$week_days[$x-1]."</li>";
@ -139,6 +169,7 @@ function show_palinsesto($args)
$content .= '</li>';
} ?>
<div class="gator-tabs-container">
<ul class="gator-tabs-header">
<?php echo $tabs; ?>

@ -69,7 +69,6 @@ function what_play_now($args)
echo "</pre>";
*/
foreach ($results as $t) {
$tocheck[0] = $i;
$tocheck[1] = $t->post_id;

Loading…
Cancel
Save