CodeIgniter Forums

Full Version: Stuck data does not update.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
On my calendar controller I can insert data in to each calendar date then on to database, which works fine.

My issue is for some reason will not update?

Not sure what is wrong with my code. Any ideas would be great thanks. I have attached controller file and a couple of images.

Thanks for your time.


Controller


PHP Code:
<?php

class Calendar extends MX_Controller {

 
   public function __construct() {
 
       parent::__construct();
 
       $this->load->model('dashboard/model_calendar');
 
       $this->load->library('calendar');
 
   }

 
   public function index() {

 
       if ($this->uri->segment(3) == FALSE) {
 
           $year date('Y');
 
       } else {
 
           $year $this->uri->segment(3);
 
       }

 
       if ($this->uri->segment(4) == FALSE) {
 
           $month date('m');
 
       } else {
 
           $month $this->uri->segment(4);
 
       }

 
       var_dump($this->get_calendar_event_data($year$month));

 
       var_dump($this->check_calendar_event($year$month));

 
       var_dump($this->input->post('day'));

 
       $prefs = array(
 
           'start_day' => 'monday',
 
           'show_next_prev' => true,
 
           'day_type' => 'long',
 
           'next_prev_url' => base_url('dashboard/calendar')
 
       );

 
       $prefs['template'] = '
            {table_open}<table border="0" cellpadding="0" cellspacing="0" class="table table-striped table-bordered calendar">{/table_open}
            
            {heading_row_start}<tr>{/heading_row_start}
            
            {heading_previous_cell}<th><a href="{previous_url}"><i class="fa fa-chevron-left fa-2x "></i></a></th>{/heading_previous_cell}
            {heading_title_cell}<th class="text-center" colspan="{colspan}">{heading}</th>{/heading_title_cell}
            {heading_next_cell}<th class="text-right"><a href="{next_url}"><i class="fa fa-chevron-right fa-2x"></i></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}<span class="label label-danger" style="margin-left: 10px;">Notice</span></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} <span class="label label-success">Current Day</span></div>{/cal_cell_no_content_today}
            
            {cal_cell_blank}&nbsp;{/cal_cell_blank}
            
            {cal_cell_end}</td>{/cal_cell_end}
            {cal_row_end}</tr>{/cal_row_end}
            
            {table_close}</table>{/table_close}
        '
;

 
       $this->calendar->initialize($prefs);

 
       if ($day $this->input->post('day')) {
 
           if ($this->check_calendar_event($year$month) > 0) {
 
               $this->update_calendar_event($year$month$day$this->input->post('event_data'));
 
           } else {
 
               $this->add_calendar_event($year$month$day$this->input->post('event_data'));
 
           }
 
       }

 
       $event_data $this->get_calendar_event_data($year$month);

 
       $data['calendar'] = $this->calendar->generate($year$month$event_data);

 
       $this->load->view('dashboard/calender_view'$data);
 
   }

 
   public function add_calendar_event($year$month$day$event_post) {
 
      $data = array(
 
           'year' => $year,
 
           'month' => $month,
 
           'day' => $this->input->post('day'),
 
           'date' => '',
 
           'data' => $event_post
        
);

 
       $this->db->insert('calendar'$data);
 
   }

 
   public function update_calendar_event($year$month$day$event_post) {
 
       $calendar = array(
 
           'date' => '',
 
           'data' => $event_post
        
);

 
       $calendar_where = array(
 
           'year' => $year,
 
           'month' => $month,
 
           'day' => $day
        
);

 
       $this->db->where($calendar_where);
 
       $this->db->update('calendar'$calendar);
 
   }

 
   public function get_calendar_event_data($year$month) {
 
       $cell_data = array();
 
       $this->db->select('*');
 
       $this->db->from('calendar');
 
       $this->db->where('year'$year);
 
       $this->db->where('month'$month);
 
       $query $this->db->get();

 
       foreach ($query->result() as $result) {
 
           $cell_data[$result->day] = $result->data;
 
       }

 
       return $cell_data;
 
   }

 
   public function check_calendar_event($year$month) {
 
       $this->db->select('data');
 
       $this->db->from('calendar');
 
       $this->db->where('year'$year);
 
       $this->db->where('month'$month);
 
       $results $this->db->count_all_results();

 
       return $results;
 
   }



View

Code:
<div class="panel panel-default">
<div class="panel-heading">
<h1 class="panel-title">Calendar</h1>
</div>
<div class="panel-body">
<?php echo $calendar;?>
</div>
</div>

<script type="text/javascript">
$(document).ready(function() {
    
    $('.calendar .day').click(function() {
    
        day_num = $(this).find('.day_num').html();
        day_data = prompt('Enter Event', $(this).find('.content').html());
            
        //if (day_data != null) {
            $.ajax({
                url: window.location,
                type: 'POST',
                data: {
                    day: day_num,
                    event_data: day_data
                },
                success: function(msg) {
                    location.reload();
                }                        
            });
                
        //}
    });
        
});
        
</script>