日历问题PHP

时间:2016-03-14 15:45:27

标签: javascript php ajax

您好我在wordpress中遇到此日历的问题 http://extension.culinary.cl/calendario/

日历仅标记当月的活动天数我无法在较旧月份展示

完整代码:

的functions.php

add_filter( 'be_events_manager_metabox_override', '__return_true' );

function draw_calendar($month,$year,$link=0){

if(isset($_GET["mes"])) { 
        // Queremos todos los eventos del mes requerido
    $inicio = strtotime($_GET["mes"]."01");
    $fin = strtotime(date("Y-m-t", $inicio));       
} else {
    // Queremos todos los eventos del mes actual
    $inicio = strtotime(date("Ym01"));
    $fin = strtotime(date("Y-m-t", $inicio));       
}
$eventos = getPostsByFechas($inicio, $fin);

// echo "Draw calendar with $year - $month";
/* draw table */
$today = date("j"); 
$tmes = date("n");
$tano = date("Y");

$calendar = '<table class="table">';

/* table headings */
$headings = array('LUN','MAR','MIE','JUE','VIE','SAB','DOM');
$calendar.= '<thead><tr><th scope="row">'.implode('</th>    <th>',$headings).'</th></tr></thead>';

/* days and weeks vars now ... */
$init_day = date('w',$inicio - 60 * 60 * 24); // Dia de la semana que empieza el mes (menos uno.. PHP sucks) // (0,0,0,$month,1,$year)-1);
$days_in_month = date('t',mktime(0,0,0,$month,1,$year));//
$days_in_this_week = 1;
$day_counter = 0;
$dates_array = array();

/* row for week one */
$calendar.= '<tbody><tr class="calendar-row">';

/* print "blank" days until the first of the current week */
for($x = 0; $x < $init_day; $x++):
$calendar.= '<td><span>&nbsp;</span></td>';
$days_in_this_week++;
endfor;

/* keep going with days.... */

// print_r($eventos);

for($list_day = 1; $list_day <= $days_in_month; $list_day++):
$calendar.= '<td>';
  /* add in the day number */
$list_day2 = ( ($list_day<10) ? "0" : "" ) .$list_day  ;
$month2 = ( ($month<10) ? "0" : "" ) .$month  ;

$dayTieneEvento = hasEventInDay($year.$month2.$list_day2, $eventos);

if($dayTieneEvento){

         //if($dayTieneEvento){

            if($link==0){ 
                $calendar.="<a href=\"javascript:showEvents('$year$month2$list_day2');\" class='tieneeventos'>";
            } else {
                $calendar.="<a href=\"javascript:void(0);\" class='tieneeventos'>";
            }

        } else {
            $calendar.="<a href=\"javascript:void(0);\" class=''>";
        }

    $calendar.= $list_day;
        $calendar.="</a>";

$calendar.= '</td>';

if($init_day == 6):
  $calendar.= '</tr>';
  if(($day_counter+1) != $days_in_month):
    $calendar.= '<tr>';
  endif;
  $init_day = -1;
  $days_in_this_week = 0;
endif;
$days_in_this_week++; $init_day++; $day_counter++;
endfor;

/* finish the rest of the days in the week */
if($days_in_this_week < 8):
for($x = 1; $x <= (8 - $days_in_this_week); $x++):
$calendar.= '<td><span>&nbsp;</span></td>';
endfor;
endif;

/* final row */
$calendar.= '</tr></tbody>';

/* end the table */
$calendar.= '</table>';

/* all done, return result */
return $calendar;
}

function hasEventInDay($day, $eventos) {
foreach ($eventos as $date => $evento) {
    // echo $day . " vs " . $evento["inicio"] ."<br>";
    if($day == $evento["inicio"]) {
        return true;
    }       
}
// die();
// echo "<br><br>";
return false;
}

function head_calendar($mes_actual='',$ano_actual=''){
global $meses;
?>
<?php 


if(!isset($_GET["mes"])){

$mes = date("m");
$ano = date("Y");
} else {
$fecha = intval($_GET["mes"]);
$mes = substr($fecha,4,2);
$ano = substr($fecha,0,4);
}

if($mes_actual){
$mes = $mes_actual;
}

echo '<a href="javascript:getMes(\''.$ano.$mes.'    \')">'.$meses[intval($mes)].'</a>';

if($mes_actual){
echo " ".$ano_actual;
}

$mes_ant = $mes - 1;
$mes_next = $mes + 1;

if($mes_ant<10) $mes_ant = "0".$mes_ant;
if($mes_next<10) $mes_next = "0".$mes_next;

$ano_ant = $ano;
$ano_next = $ano;

if($mes_ant == "00"){
$mes_ant = "12";
$ano_ant = $ano - 1;
}
if($mes_next == 13){
$mes_next = "01";
$ano_next = $ano + 1;
}

$fecha1 = $ano_ant.$mes_ant;
$fecha2 = $ano_next.$mes_next;


if(!$mes_actual){
?>
<a class="pull-left" href="javascript:getMes('<?php echo $fecha1;?>');"><span class="glyphicon glyphicon-chevron-left"     aria-hidden="true"></span></a> 
<a class="pull-right" href="javascript:getMes('<?php echo $fecha2;?>');"><span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span></a>

<?php
}

}

function getEventos($dia,$mes,$ano){
global $fechas;
if($dia<10) $dia = "0".$dia;
if($mes<10) $mes = "0".$mes;
$fecha = $ano.$mes.$dia;
$tiene_eventos = 0;
foreach($fechas as $f){
    //if($f["inicio"]<=$fecha AND $f["fin"]>=$fecha){
    if($f["inicio"]==$fecha){
        $tiene_eventos = 1;
    }
}
return $tiene_eventos;
}

function getFechas(){
global $wpdb;
$fechas = Array();

if(is_single()){
    $more = " p.ID = $post->ID AND ";
} else {
    $more = " ";
}

页面calendar.php

在wp页面中显示

 <?php 
function print_my_inline_script() {

?>
<script type="text/javascript">
  (function($) {
    window.showEvents = function(dia, mes){
      var fecha = "";
      if ( dia !== null ) {
        fecha = "fecha=" + dia; 
      } else if (mes !== null) {
        fecha = "mes=" + mes;
      } 
      var url =  "../wp-admin/admin-ajax.php?action=get_eventos&"+fecha;
      $("#eventospordia").html("<div class='load'><img src='../wp-content/themes/culinary/assets/img/load.gif'></div>");
      $.ajax({
        type: "GET",
        url: url
      }).done(function(salidahtml) {

        if ($("#eventospordia").hasClass("slick-initialized")) {
          $("#eventospordia").slick('unslick');
        } else {
          // Iniciar Slider            
        }

        $("#eventospordia").html(salidahtml);

        $("#eventospordia").slick({
          vertical: true,
          slidesToShow: 3,
          slidesToScroll: 2,
          infinite: false
        });


        getInfoCurso($("#eventospordia").find("li:first-child").attr("data-curso-id"));
      });
    }

    window.getMes = function(fecha_mes){
      $("#calendarmonth").html("<div class='load'><img src='../wp-content/themes/culinary/assets/img/load.gif'></div>");
      $.ajax({
        type: "GET",
        url: "../wp-admin/admin-ajax.php?action=get_mes&mes="+fecha_mes
      }).done(function(salidahtml) {
        $("#calendarmonth").html(salidahtml);
        $("#year_calendar").html(fecha_mes.substr(0, 4));
      });
      showEvents(null, fecha_mes);
    }

    window.getInfoCurso = function(id){
      $("#getinfocurso").html("<div class='load'><img src='../wp-content/themes/culinary/assets/img/load.gif'></div>");
      $.ajax({
        type: "GET",
        url: "../wp-admin/admin-ajax.php?action=get_infocurso&id="+id
      }).done(function(salidahtml) {
        $("#getinfocurso").html(salidahtml);

      });
    }

    $(document).ready(function(){
      showEvents(null, null);   

    });
  })(jQuery);
</script>

谢谢!

0 个答案:

没有答案