Reputation: 95
The code below is a Codeigniter Event Calendar feature from here.
The calendar is click-able and you can enter data into the date field through a 'prompt' box. The data is then shown on the calendar date field.
The calender event function is working fine as expected for all the dates except for the first 10 days or so of each month. Data is being stored in the database for those specific dates (i.e. the first 10days dates) however the data is not displayed out on the calendar.
I am not sure why this is happening, while the rest of the dates in the month is working perfectly. Could anyone please help?
//CONTROLLER
class Mycal extends CI_Controller {
public function index() {
$this->display();
}
function display($year = null, $month = null){
if (!$year) {
$year = date('Y');
}
if (!$month) {
$month = date('m');
}
$this->load->model('Mycal_model');
if($day = $this->input->post('day')){
$this->Mycal_model->add_calendar_data(
"$year-$month-$day",
$this->input->post('data')
);
}
$data['calendar'] = $this->Mycal_model->generate($year, $month);
$this->load->view('mycal_view', $data);
}
}
//MODEL
class Mycal_model extends CI_Model{
var $conf;
function __construct(){
parent::__construct();
$this->conf = array(
'start_day' => 'monday',
'show_next_prev' => true,
'next_prev_url' => base_url() . 'index.php/mycal/display'
);
$this->conf['template'] = '
{table_open}<table border="0" cellpadding="0" cellspacing="0" class="calendar">{/table_open}
{heading_row_start}<tr>{/heading_row_start}
{heading_previous_cell}<th><a href="{previous_url}"><<</a></th>{/heading_previous_cell}
{heading_title_cell}<th colspan="{colspan}">{heading}</th>{/heading_title_cell}
{heading_next_cell}<th><a href="{next_url}">>></a></th>{/heading_next_cell}
{heading_row_end}</tr>{/heading_row_end}
{week_row_start}<tr>{/week_row_start}
{week_day_cell}<td>{week_day}</td>{/week_day_cell}
{week_row_end}</tr>{/week_row_end}
{cal_row_start}<tr class="days">{/cal_row_start}
{cal_cell_start}<td class="day">{/cal_cell_start}
{cal_cell_content}
<div class="day_num">{day}</div>
<div class="content">{content}</div>
{/cal_cell_content}
{cal_cell_content_today}
<div class="day_num highlight">{day}</div>
<div class="content">{content}</div>
{/cal_cell_content_today}
{cal_cell_no_content}<div class="day_num">{day}</div>{/cal_cell_no_content}
{cal_cell_no_content_today}<div class="day_num highlight">{day}</div>{/cal_cell_no_content_today}
{cal_cell_blank} {/cal_cell_blank}
{cal_cell_end}</td>{/cal_cell_end}
{cal_row_end}</tr>{/cal_row_end}
{table_close}</table>{/table_close}
';
}
function get_calendar_data($year, $month){
$query = $this->db->select('date, data')->from('calendar')
->like('date', "$year-$month", 'after')->get();
$cal_data = array();
foreach ($query->result() as $row){
$cal_data[substr($row->date,8,2)] = $row->data;
}
return $cal_data;
}
function add_calendar_data($date, $data){
if($this->db->select('date')->from('calendar')
->where('date', $date)->count_all_results()) {
$this->db->where('date', $date)->update('calendar', array(
'date'=>$date,
'data'=>$data
));
}else{
$this->db->insert('calendar', array(
'date'=>$date,
'data'=>$data
));
}
}
function generate ($year, $month){
$this->load->library('calendar', $this->conf);
$cal_data = $this->get_calendar_data($year, $month);
return $this->calendar->generate($year, $month, $cal_data)
}
//VIEW
<?php echo $calendar; ?>
<script type="text/javascript">
$(document).ready(function() {
$('.calendar .day').click(function() {
day_num = $(this).find('.day_num').html();
day_data = prompt('Enter Stuff', $(this).find('.content').html());
if(day_data !=null){
$.ajax({
url: window.location,
type: 'POST',
data: {
day: day_num,
data: day_data
},
success: function(msg){
location.reload();
}
});
}
});
});
</script>
Upvotes: 0
Views: 1344
Reputation: 1
This is the exact solution for the above problem. Follow this coding you will get the solution. Please modify the code according to your requirement.
if($this->uri->segment(3)){
$year=$this->uri->segment(3);
} else{
$year=date("Y");
}
if($this->uri->segment(4)){
$month=$this->uri->segment(4);
} else{
$month=date("m");
}
$data=array(
'year'=>$year,
'month'=>$month
);
$prefs = array(
'month_type' => 'long',
'day_type' => 'short',
'show_next_prev' => TRUE,
'next_prev_url' => base_url().'welcome/news/'
);
$prefs['template'] = '
{table_open}<style>table{border-collapse:collapse; color: #f6f6f6;} td{ width: 40px; height: 40px; text-align: center; border: 1px solid #e2e0e0; font-size: 18px; font-weight: bold; } th{ height: 68px; padding-bottom: 12px; text-align: center; font-size: 20px; } .prev_sign a, .next_sign a{ color:white; text-decoration: none; } tr.week_name{ font-size: 16px; font-weight:400; color:red; width: 10px; background-color: #efe8e8; } .highlight{background-color: #25BAE4; color:#e6f0e9; height: 39px; padding-top: 7px;}</style><table class="col-lg-12 col-md-12 col-sm-12 col-xs-12" border="0" cellpadding="0" cellspacing="0">{/table_open}
{heading_row_start}<tr>{/heading_row_start}
{heading_previous_cell}<th><a href="{previous_url}"><<</a></th>{/heading_previous_cell}
{heading_title_cell}<th colspan="{colspan}">{heading}</th>{/heading_title_cell}
{heading_next_cell}<th><a href="{next_url}">>></a></th>{/heading_next_cell}
{heading_row_end}</tr>{/heading_row_end}
{week_row_start}<tr>{/week_row_start}
{week_day_cell}<td>{week_day}</td>{/week_day_cell}
{week_row_end}</tr>{/week_row_end}
{cal_row_start}<tr>{/cal_row_start}
{cal_cell_start}<td>{/cal_cell_start}
{cal_cell_start_today}<td>{/cal_cell_start_today}
{cal_cell_start_other}<td class="other-month">{/cal_cell_start_other}
{cal_cell_content}<a href="{content}">{day}</a>{/cal_cell_content}
{cal_cell_content_today}<div class="highlight"><a href="{content}">{day}</a></div>{/cal_cell_content_today}
{cal_cell_no_content}{day}{/cal_cell_no_content}
{cal_cell_no_content_today}<div class="highlight">{day}</div>{/cal_cell_no_content_today}
{cal_cell_blank} {/cal_cell_blank}
{cal_cell_other}{day}{/cal_cel_other}
{cal_cell_end}</td>{/cal_cell_end}
{cal_cell_end_today}</td>{/cal_cell_end_today}
{cal_cell_end_other}</td>{/cal_cell_end_other}
{cal_row_end}</tr>{/cal_row_end}
{table_close}</table>{/table_close}
';
$this->load->library('calendar',$prefs);
$data2=$data1=array();
foreach($event as $d) {
$date=date_create($d['date']);
$date_f= date_format($date,"Y/m/d");
$y=date_format($date,"Y");
$m=date_format($date,"m");
$d1= strval(intval(date_format($date,"d")));
if($y==$year && $m==$month){
$data1[$d1] = base_url().'welcome/alleventbydate/'.$date_f;
}
}
//$data[]=$data1;
echo $this->calendar->generate($year,$month,$data1);
Upvotes: -2
Reputation: 1
The problem is with the date format you are passing in the events. Please note that
$data= array('day'=>01,'day_data'=>'abcd');
is not the same as
$data= array('day'=>1,'day_data'=>'abcd');
hence the problem with all dates below 10. Update your code to maintain a uniform date format
Upvotes: 0
Reputation: 1
This is the exact solution for the above problem.
if($this->uri->segment(3)){
$year=$this->uri->segment(3);
} else{
$year=date("Y");
}
if($this->uri->segment(4)){
$month=$this->uri->segment(4);
} else{
$month=date("m");
}
$data=array(
'year'=>$year,
'month'=>$month
);
$prefs = array(
'month_type' => 'long',
'day_type' => 'short',
'show_next_prev' => TRUE,
'next_prev_url' => base_url().'welcome/news/'
);
$prefs['template'] = '
{table_open}table{border-collapse:collapse; color: #f6f6f6;} td{ width: 40px; height: 40px; text-align: center; border: 1px solid #e2e0e0; font-size: 18px; font-weight: bold; } th{ height: 68px; padding-bottom: 12px; text-align: center; font-size: 20px; } .prev_sign a, .next_sign a{ color:white; text-decoration: none; } tr.week_name{ font-size: 16px; font-weight:400; color:red; width: 10px; background-color: #efe8e8; } .highlight{background-color: #25BAE4; color:#e6f0e9; height: 39px; padding-top: 7px;}{/table_open}
{heading_row_start}{/heading_row_start}
{heading_previous_cell}<<{/heading_previous_cell}
{heading_title_cell}{heading}{/heading_title_cell}
{heading_next_cell}>>{/heading_next_cell}
{heading_row_end}{/heading_row_end}
{week_row_start}{/week_row_start}
{week_day_cell}{week_day}{/week_day_cell}
{week_row_end}{/week_row_end}
{cal_row_start}{/cal_row_start}
{cal_cell_start}{/cal_cell_start}
{cal_cell_start_today}{/cal_cell_start_today}
{cal_cell_start_other}{/cal_cell_start_other}
{cal_cell_content}{day}{/cal_cell_content}
{cal_cell_content_today}{day}{/cal_cell_content_today}
{cal_cell_no_content}{day}{/cal_cell_no_content}
{cal_cell_no_content_today}{day}{/cal_cell_no_content_today}
{cal_cell_blank} {/cal_cell_blank}
{cal_cell_other}{day}{/cal_cel_other}
{cal_cell_end}{/cal_cell_end}
{cal_cell_end_today}{/cal_cell_end_today}
{cal_cell_end_other}{/cal_cell_end_other}
{cal_row_end}{/cal_row_end}
{table_close}{/table_close}
';
$this->load->library('calendar',$prefs);
$data2=$data1=array();
foreach($event as $d) {
$date=date_create($d['date']);
$date_f= date_format($date,"Y/m/d");
$y=date_format($date,"Y");
$m=date_format($date,"m");
$d1= strval(intval(date_format($date,"d")));
if($y==$year && $m==$month){
$data1[$d1] = base_url().'welcome/alleventbydate/'.$date_f;
}
}
//$data[]=$data1;
echo $this->calendar->generate($year,$month,$data1);
Upvotes: 0