Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.35 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.         // $data_customer = [
  40.         //     "cust_name" => $this->input->post('cust_name[]', true),
  41.         //     "date_meet" => date('Y-m-d', strtotime($this->input->post('date[]', true))),
  42.         //     "meet_location" => $this->input->post('location[]', true),
  43.         //     "status" => $this->input->post('status[]', true),
  44.         // ];
  45.         if ($this->input->post()) {
  46.  
  47.             $data_planning = [
  48.                 "date_created_am" => date('Y-m-d', strtotime($this->input->post('date', true))),
  49.                 "cust_segment" => $this->input->post('cust_segment', true),
  50.             ];
  51.  
  52.             $data_planning['id_planning'] = $this->uuid->v4();
  53.             $customer['id_customer'] = $this->uuid->v4();
  54.  
  55.             $this->db->insert('planning', $data_planning);
  56.             // $planning_id = $this->db->insert_id();
  57.  
  58.            
  59.             $data_customer = $this->input->post();
  60.            
  61.             // echo '<pre>';
  62.             foreach ($data_customer['cust_name'] as $k => $v) {
  63.                 $cus['date'] = $data_customer['date'][$k];
  64.                 $cus['cust_name'] = $data_customer['cust_name'][$k];
  65.                 $cus['location'] = $data_customer['location'][$k];
  66.                
  67.                 $cus['id_planning'] = $data_planning['id_planning'];
  68.  
  69.                 // $this->db->insert('customer', $cus);
  70.                 // print_r($cus);
  71.                 // $insert = $this->M_planning->insert_table($data_planning, $data_customer);
  72.                 $this->db->insert('customer', $cus);
  73.             }
  74.  
  75.             echo"berhasil";
  76.  
  77.             // if ($insert) {
  78.             //     // // $uuid_customer = $this->db->set('id_customer','UUID()',FALSE);
  79.             //     // // $id = $uuid_planning;
  80.             //     // // var_dump($uuid_planning);
  81.             //     // // echo $uuid_planning;
  82.  
  83.             //     // // $this->db->set('id_planning', $uuid_planning);
  84.             //     // $insert1 = $this->M_planning->create('customer',$data_customer);
  85.             //     // if($insert1){
  86.             //     //     $this->session->set_flashdata('message', '<div class="alert alert-success" style="text-align:center;">Success</div>');
  87.             //     // // redirect('index.php/PagesRoute/am_planning');
  88.             //     // echo "berhasil";
  89.             //     // }
  90.             //     // $this->session->set_flashdata('message', '<div class="alert alert-success" style="text-align:center;">Success</div>');
  91.             //     // redirect('PagesRoute/am_planning');
  92.             //     echo "berhasil";
  93.             // } else {
  94.             //     $this->session->set_flashdata('message', '<div class="alert alert-danger" style="text-align:center;">Fail to save data</div>');
  95.             //     // redirect('index.php/PagesRoute/am_planning');
  96.             //     echo "gagal";
  97.             // }
  98.             // print_r($data);
  99.             // exit();
  100.         }else{
  101.             echo "gagal";
  102.         }
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement