Welcome Guest, Not a member yet? Register   Sign In
codeigniter calendar using ajax , problem
#1

[eluser]dinisptc[/eluser]
codeigniter calendar using ajax , problem

i am using firebug and everything looks good no errors

the post its good and the response its also good

the problem its that the data its not showing in the calendar

this is the view :

i am going to post the model and the controller in the next post

Code:
<div id="content">
&lt;style type="text/css"&gt;
  .calendar {
   font-family: Arial; font-size: 12px;
  }
  table.calendar {
   margin: auto; border-collapse: collapse;
  }
  .calendar .days td {
   width: 80px; height: 80px; padding: 4px;
   border: 1px solid #999;
   vertical-align: top;
   background-color: #DEF;
  }
  .calendar .days td:hover {
   background-color: #FFF;
  }
  .calendar .highlight {
   font-weight: bold; color: #00F;
  }
&lt;/style&gt;
[removed][removed]

        &lt;?php
  echo form_label('Project', 'projectUID');
  echo br(1);
               $js = 'id="shirts"';


   echo form_dropdown('projectUID', $projects, set_value('projectUID', $projects),$js);
        
  ?&gt;

  
<center>&lt;?php echo $calendar; ?&gt;</center>

[removed]

            $(document).ready(function() {

  $('.calendar .day').click(function() {




   day_num = $(this).find('.day_num').html();                                                            
   day_data = prompt('Enter Meeting', $(this).find('.content').html());
   if (day_data != null) {

                    


                             var select_x=document.getElementById("shirts").value;


                             if ((select_x != null)&&(select_x != '')) {

                          
    $.ajax({
     url: "&lt;?php echo site_url('meeting_cal/display'); ?&gt;",//[removed],
     type: 'POST',
     data: {
      day: day_num,
      data: day_data,
                                                proj:select_x,
                                                ajax: '1'
     },
                                      
     success: function(msg) {
      location.reload();
     }      
    });

                            


                                 }//shirts
                                 else{ alert("Must select a project");}
    //});//shirts
   }
  
  });

   return false;
  
});
  
[removed]

</div>


#2

[eluser]dinisptc[/eluser]

this is the model
Code:
&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed');



class Meetingcal_model extends CI_Model {


    function __construct() {
        // Call the Model constructor
        parent::__construct();

  



    }


        
function generate ($year, $month,$proj) {

            
                $confi = array(
   'start_day' => 'monday',
   'show_next_prev' => true,
   'next_prev_url' => site_url('meeting_cal/display')
  );
  
  $confi['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}">&lt;&lt;</a></th>{/heading_previous_cell}
   {heading_title_cell}<th colspan="{colspan}">{heading}</th>{/heading_title_cell}
   {heading_next_cell}<th><a href="{next_url}">&gt;&gt;</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}&nbsp;{/cal_cell_blank}
  
   {cal_cell_end}</td>{/cal_cell_end}
   {cal_row_end}</tr>{/cal_row_end}
  
   {table_close}</table>{/table_close}
  ';
  
  $this->load->library('calendar',$confi);//$this->conf);
  
  $cal_data = $this->get_calendar_data($year,$month,$proj);
  
  return $this->calendar->generate($year, $month, $cal_data);
  
}

function get_calendar_data($year, $month,$proj) {

         $user=$this->users_model->find_by_user_id_client_id($this->session->userdata('user_id'));
         $architect_id=$this->projects_model->check_user_id();
        if($this->meeting_model->checkifisarchitect_user($this->session->userdata('user_id')))
        {

         $this->db->select('dateMeeting, dayOrder');
         $this->db->from('meeting_8');
         $this->db->join('project','project.id=meeting_8.projectUID');
         $this->db->join('assignproject','assignproject.projectUID=meeting_8.projectUID');
         $this->db->where('assignproject.userarchitect',$this->session->userdata('user_id'));
  $this->db->where('assignproject.adminarchitect',$architect_id);
         $this->db->where('meeting_8.projectUID',$proj);
  $this->db->where('clientUID',$user['clientUID']);
  $this->db->like('dateMeeting', "$year-$month", 'after');

    $query = $this->db->get();
  
  $cal_data = array();
  
  foreach ($query->result() as $row) {
                        $index = ltrim(substr($row->dateMeeting,8,2), '0');   // this is the magic !!
                        $cal_data[$index] = $row->dayOrder;
   //$cal_data[substr($row->dateMeeting,8,2)] = $row->dayOrder;
  }

  return $cal_data;

           }else
           {

           $this->db->order_by('project.dateCreation', 'DESC');

           $this->db->select('dateMeeting, dayOrder');
           $this->db->from('meeting_8');
            $this->db->join('project','project.id=meeting_8.projectUID','left outer');
                       $this->db->where('meeting_8.projectUID',$proj);
     $this->db->where('clientUID',$user['clientUID']);
                    $this->db->like('dateMeeting', "$year-$month", 'after');
           $query = $this->db->get();

          $cal_data = array();
  
  foreach ($query->result() as $row) {
                        $index = ltrim(substr($row->dateMeeting,8,2), '0');   // this is the magic !!
                        $cal_data[$index] = $row->dayOrder;
   //$cal_data[substr($row->dateMeeting,8,2)] = $row->dayOrder;
  }

  return $cal_data;



            }
  
}

function add_calendar_data($date,$data,$proj) {

                  
  if ($this->db->select('dateMeeting')->from('meeting_8')
    ->where('dateMeeting', $date)->where('projectUID', $proj)->count_all_results()) {
  
   $this->db->where('dateMeeting', $date)->where('projectUID', $proj)
    ->update('meeting_8', array(
    'dateMeeting' => $date,
    'dayOrder' => $data,
                                'projectUID'=>$proj  
   ));
  
  } else {
  
   $this->db->insert('meeting_8', array(
    'dateMeeting' => $date,
    'dayOrder' => $data,
                                'projectUID'=>$proj  
   ));
  }

  
      
  
}




}//class
#3

[eluser]dinisptc[/eluser]
this the controller

in the firebug everything looks good


but the site its not working its not posting


i am following this tutorial
http://net.tutsplus.com/tutorials/php/co...ch_index=1

Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Meeting_cal extends CI_Controller {

   public function __construct()                                  
   {                                                              
        parent::__construct();
$this->load->library('ion_auth');                           // ^
$this->load->library('session');                            // ^
$this->load->library('form_validation');
        $this->load->helper('url');
        
        $this->load->helper('language');
        $this->load->helper('form');
$this->load->helper('ckeditor');
        $this->template->set_template('default');
   }




function display($year = null, $month = null) {



if ($this->input->post('ajax')) {
      echo "ola ajax";
}else
{
  echo "adeus ajax";
}

          $group = 'architect';
          $groupmember ='members';
          if(($this->ion_auth->in_group($group)) or ($this->ion_auth->in_group($groupmember)))
          {

  
  if (!$year) {
   $year = date('Y');
  }
  if (!$month) {
   $month = date('m');
  }






  print_r('post'.$this->input->post('proj'));

print_r('eeeeeeeeeee'.$this->input->post('data'));

  //$this->load->model('meetingcal_model');
  
  if ($day = $this->input->post('day')) {

                        print_r('postv1'.$this->input->post('proj'));

   $this->meetingcal_model->add_calendar_data(
    "$year-$month-$day",
    $this->input->post('data'),
                                $this->input->post('proj')
   );
  }




          //get projects for this client
          $projects=array();
          $user_id=$this->projects_model->check_user_id();
          $client_id=$this->users_model->find_by_user_id_client_id($this->session->userdata('user_id'));
          ////get user_id
          $group = 'architect';
          $groupmember ='members';
          if($this->ion_auth->in_group($group))
          {
           //get all projects for the admin architect
             $status=1; //open
           $data['projects']=$this->projects_model->get_projects_dropdown_admin();

          }elseif ($this->ion_auth->in_group($groupmember))
          {

           //get only assigned projects
           $status=1; //open

           $data['projects']=$this->projects_model->get_projects_dropdown_emp();

          }

          $projectuid=$this->input->post('proj');

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

                 // echo $data['calendar'];

        $Dheader = array();
           $Dsidebar = array();
           $Dfooter = array();
                        $Dmeta = array('meta_title'=>'Welcome to onplans','meta_descricao'=>'onplans');


                        $this->template->write_view('meta', 'html/meta',  $Dmeta, true);
           $this->template->write_view('header', 'html/header', $Dheader, true);
           $this->template->write_view('content', 'onplans/meeting_cal',$data,true);
           $this->template->write_view('sidebar', 'html/sidebar');
           $this->template->write_view('footer', 'html/footer');
           $this->template->render();
  
  
}

}


}
#4

[eluser]dinisptc[/eluser]
the input post its not working

if add hard coded 17 that’s a project uid everything works fine






Code:
$projectuid=$this->input->post('proj');

  
$data['calendar'] = $this->meetingcal_model->generate($year,$month,17);//$projectuid);
#5

[eluser]dinisptc[/eluser]

i have added this line on my controller ::
Code:
$this->output->enable_profiler(TRUE);

$projectuid=$this->input->post('proj');


SELECT `dateMeeting`, `dayOrder`
FROM (`meeting_8`)
LEFT OUTER JOIN `project` ON `project`.`id`=`meeting_8`.`projectUID`
WHERE `meeting_8`.`projectUID` =  0
AND `clientUID` =  '7'
AND  `dateMeeting`  LIKE '2013-03%'
ORDER BY `project`.`dateCreation` DESC

$this->input->post('proj'); its returning 0 and i dont know why
#6

[eluser]dinisptc[/eluser]
WHERE `meeting_8`.`projectUID` = 0

the projectUID should not be zero
#7

[eluser]TheFuzzy0ne[/eluser]
It's very hard to read your Javascript, since Ellislab have gone all Jean Claude Van Damme on the replacements. Have you tried accessing the URL directly from your address bar, and trying to emulate an AJAX call?

Also, do you realise that with that extra debugging code, it won't work anyway, since it's not sending a valid JSON array to the client?

Where are you passing the project ID to the app? Why not pass it as a parameter to the display() method instead of via POST?
#8

[eluser]dinisptc[/eluser]
its posting correctly and records in the database

the problem its that the $Post will be empty after the ajax call



POST http://localhost/onplans/index.php/meeting_cal/display

200 OK
140ms
jquery.min.js (line 130)
HeadersPostResponseHTMLCookies
Parametersapplication/x-www-form-urlencoded
ajax 1
data dd
day 6
proj 17
Source
day=6&data=dd&proj=17&ajax=1
#9

[eluser]TheFuzzy0ne[/eluser]
I don't think it's returning 0. It's returning false, which when cast to a string is 0. If it's returning false, it means that it doesn't exist in the $_POST array.

What does the profiler say about what $_POST data has been submitted to the server? Is 'proj' in there?
#10

[eluser]dinisptc[/eluser]
the $POST its empty


BENCHMARKS
Loading Time: Base Classes 0.0117
Controller Execution Time ( Meeting Calendar / Display ) 0.0439
Total Execution Time 0.0557
GET DATA
No GET data exists
MEMORY USAGE
8,070,496 bytes
POST DATA
No POST data exists
URI STRING
meeting_calendar/display
CLASS/METHOD
meeting_calendar/display
DATABASE: onplans QUERIES: 10 (Hide)
0.0003 SELECT `users_groups`.`group_id` as id, `groups`.`name`, `groups`.`description`
FROM (`users_groups`)
JOIN `groups` ON `users_groups`.`group_id`=`groups`.`id`
WHERE `users_groups`.`user_id` = '24'
0.0003 SELECT *
FROM (`users`)
WHERE `id` = '24'
0.0002 SELECT *
FROM (`users_groups`)
WHERE `user_id` = '24'
0.0002 SELECT *
FROM (`users_groups`)
WHERE `user_id` = '24'
0.0016 SELECT `dateMeeting`, `dayOrder`
FROM (`meeting_8`)
LEFT OUTER JOIN `project` ON `project`.`id`=`meeting_8`.`projectUID`
WHERE `meeting_8`.`projectUID` = 0
AND `clientUID` = '7'
AND `dateMeeting` LIKE '2013-03%'
ORDER BY `project`.`dateCreation` DESC
0.0002 SELECT *
FROM (`users_groups`)
WHERE `user_id` = '24'
0.0002 SELECT *
FROM (`users`)
WHERE `id` = '24'
0.0001 SELECT `users_groups`.`group_id` as id, `groups`.`name`, `groups`.`description`
FROM (`users_groups`)
JOIN `groups` ON `users_groups`.`group_id`=`groups`.`id`
WHERE `users_groups`.`user_id` = '24'
0.0000 SELECT *
FROM (`users`)
WHERE `id` = '24'
0.0002 SELECT *
FROM (`project`)
WHERE `clientUID` = '7'
AND `status` = 1
ORDER BY `project`.`dateCreation` DESC
HTTP HEADERS (Show)
SESSION DATA (Show)
CONFIG VARIABLES (Show)




Theme © iAndrew 2016 - Forum software by © MyBB