Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.03 KB | None | 0 0
  1. <?php
  2.  
  3. class AmPlanning extends CI_Controller
  4. {
  5.     function __construct()
  6.     {
  7.         parent::__construct();
  8.         $this->load->model('M_planning');
  9.         // $this->load->library('uuid');
  10.     }
  11.  
  12.     public function index()
  13.     {
  14.  
  15.         $this->form_validation->set_rules('date', 'Date', 'required');
  16.         $this->form_validation->set_rules('cust_segment', 'Customer Segment', 'required');
  17.         $this->form_validation->set_rules('cust_name[]', 'Customer Name', 'required');
  18.         $this->form_validation->set_rules('date[]', 'Date Meeting', 'required');
  19.         $this->form_validation->set_rules('location[]', 'Location Meeting', 'required');
  20.         $this->form_validation->set_rules('status[]', 'Status', 'required');
  21.  
  22.         if ($this->form_validation->run() == false) {
  23.             $pageId  = 'am_planning'; /*Change_this*/
  24.             $pagePath = 'pages/' . $pageId;
  25.             $data['pageId'] = $pageId;
  26.             $data['pageTitle'] = "AM Planning"; /*Change_this*/
  27.             $data['pageContent'] = $this->load->view($pagePath . '/view', '', TRUE);
  28.             $data['pageStyle'] = $this->load->view($pagePath . '/style', '', TRUE);
  29.             $data['pageScript'] = $this->load->view($pagePath . '/script', '', TRUE);
  30.             $this->load->view('layout/v_layout', $data);
  31.         } else {
  32.             $this->insert();
  33.         }
  34.     }
  35.  
  36.     private function insert()
  37.     {
  38.  
  39.         if ($this->input->post()) {
  40.  
  41.             $data_planning = [
  42.                 "date_created_am" => date('Y-m-d', strtotime($this->input->post('date', true))),
  43.                 "cust_segment" => $this->input->post('cust_segment', true),
  44.             ];
  45.  
  46.             $data_planning['id_planning'] = $this->uuid->v4();
  47.            
  48.             $this->db->insert('planning', $data_planning);        
  49.            
  50.             $data_customer = $this->input->post();
  51.             print_r($data_planning);
  52.            
  53.             // echo '<pre>';
  54.             foreach ($data_customer['cust_name'] as $k => $v) {
  55.                 $cus['date'] = $data_customer['date'][$k];
  56.                 $cus['cust_name'] = $data_customer['cust_name'][$k];
  57.                 $cus['location'] = $data_customer['location'][$k];
  58.                
  59.                 $cus['id_customer'] = $this->uuid->v4();
  60.                 $cus['id_planning'] = $data_planning['id_planning'];
  61.  
  62.                 // $this->db->insert('customer', $cus);
  63.                 // print_r($cus);
  64.                 // $insert = $this->M_planning->insert_table($data_planning, $data_customer);
  65.                 $this->db->insert('customer', $cus);
  66.             }
  67.             print_r($cus);
  68.             echo"berhasil";
  69.  
  70.             // if ($insert) {
  71.             //     // // $uuid_customer = $this->db->set('id_customer','UUID()',FALSE);
  72.             //     // // $id = $uuid_planning;
  73.             //     // // var_dump($uuid_planning);
  74.             //     // // echo $uuid_planning;
  75.  
  76.             //     // // $this->db->set('id_planning', $uuid_planning);
  77.             //     // $insert1 = $this->M_planning->create('customer',$data_customer);
  78.             //     // if($insert1){
  79.             //     //     $this->session->set_flashdata('message', '<div class="alert alert-success" style="text-align:center;">Success</div>');
  80.             //     // // redirect('index.php/PagesRoute/am_planning');
  81.             //     // echo "berhasil";
  82.             //     // }
  83.             //     // $this->session->set_flashdata('message', '<div class="alert alert-success" style="text-align:center;">Success</div>');
  84.             //     // redirect('PagesRoute/am_planning');
  85.             //     echo "berhasil";
  86.             // } else {
  87.             //     $this->session->set_flashdata('message', '<div class="alert alert-danger" style="text-align:center;">Fail to save data</div>');
  88.             //     // redirect('index.php/PagesRoute/am_planning');
  89.             //     echo "gagal";
  90.             // }
  91.             // print_r($data);
  92.             // exit();
  93.         }else{
  94.             echo "gagal";
  95.         }
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement