[eluser]MarceloTM[/eluser]
Hello! I'm trying to make an event calendar for my site that needs to work as follows:
Initially the system get the current date and generate the calendar in the controller, at each day I call a function in the model passing the date (dd/mm/YYYY), to check if there are any events that day.
The initial call is working fine, this is the code:
Code:
$data['cal'] = $this->Cal_model->montaCalendario("", "");
The two empty params is to generate the actual month calendar.
So, i got two links in the calendar header, to switch months, Previous and Next.
When I click in these links, the calendar is generate ok, but the events are not searched,
the SQL always return 0 rows...
This is the jQuery ajax call to the controller:
Quote:function anterior(){
$('#event_info').html("");
var previous = $('.previous');
var month = anterior.attr('month');
var year = anterior.attr('year');
$.post("<?=base_url()?>calendario/buscarMes", { "month" : month, "year" : year },
function(data){
$('#cal_render').html(data);
});
}
This is the controller method:
Code:
function buscarMes(){
$mes = trim($this->input->post('mes'));
$ano = trim($this->input->post('ano'));
$result = $this->Cal_model->montaCalendario($mes, $ano);
echo $result;
}
This is the method to build the calendar:
Code:
function montaCalendario($mes, $ano){
$date = time();
$day = date('d', $date);
if($mes != "" && $ano != ""):
$month = (int)$mes;
$year = (int)$ano;
else:
$month = date('m', $date);
$year = date('Y', $date);
endif;
$first_day = mktime(0,0,0, $month, 1, $year);
$title = date('F', $first_day);
$day_of_week = date('D', $first_day);
switch($day_of_week){
case "Sun" : $blank = 0; break;
case "Mon" : $blank = 1; break;
case "Tue" : $blank = 2; break;
case "Wed" : $blank = 3; break;
case "Thu" : $blank = 4; break;
case "Fri" : $blank = 5; break;
case "Sat" : $blank = 6; break;
}
$days_in_month = cal_days_in_month(0, $month, $year);
if($month == '01'):
$mesAnterior = '12';
$anoAnterior = $year - 1;
$mesProximo = $month + 1;
$anoProximo = $year;
elseif($month == '12'):
$mesAnterior = $month - 1;
$anoAnterior = $year;
$mesProximo = '01';
$anoProximo = $year + 1;
else:
$mesAnterior = $month - 1;
$anoAnterior = $year;
$mesProximo = $month + 1;
$anoProximo = $year;
endif;
$cal = "[removed]
$(document).ready(function(){
$('#cal_table tr td.tip').tipsy({gravity: 'n'});
$('#cal_table tr td.active').hover(function(){
$(this).find('span').css('display','block');
}, function(){
$(this).find('span').css('display','none');
});
});
[removed]<br />";
$cal .= "<table id='cal_table' align='right' cellpadding='0' cellspacing='0'>";
$cal .= "<tr><th style='font-size: 40px;' mes='".$mesAnterior."' ano='".$anoAnterior."' class='anterior'><</th>";
$cal .= "<th colspan='5' style='font-size: 40px;'>".$this->retornaMes($month)." ".$year."</th>";
$cal .= "<th style='font-size: 40px;' mes='".$mesProximo."' ano='".$anoProximo."' class='proximo'>></th></tr>";
$cal .= "<tr><th style='width: 80px;'>Domingo</th>
<th style='width: 80px;'>Segunda</th>
<th style='width: 80px;'>Terça</th>
<th style='width: 80px;'>Quarta</th>
<th style='width: 80px;'>Quinta</th>
<th style='width: 80px;'>Sexta</th>
<th style='width: 80px;'>Sábado</th>";
$day_count = 1;
$cal .= "<tr>";
while($blank > 0){
$cal .= "<td class='blank'></td>";
$blank = $blank-1;
$day_count++;
}
$day_num = 1;
while($day_num <= $days_in_month){
$data = $day_num."/".$month."/".$year;
$cal .= $this->buscaEventoDia($data, $day_num);
$day_num++;
$day_count++;
if($day_count > 7){
$cal .= "</tr><tr>";
$day_count = 1;
}
}
while($day_count > 1 && $day_count <= 7){
$cal .= "<td class='blank'></td>";
$day_count++;
}
$cal .= "</tr></table>";
return $cal;
}