Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class AmPlanning extends CI_Controller
- {
- function __construct()
- {
- parent::__construct();
- $this->load->model('M_planning');
- // $this->load->library('uuid');
- }
- public function index()
- {
- $this->form_validation->set_rules('date', 'Date', 'required');
- $this->form_validation->set_rules('cust_segment', 'Customer Segment', 'required');
- $this->form_validation->set_rules('cust_name[]', 'Customer Name', 'required');
- $this->form_validation->set_rules('date[]', 'Date Meeting', 'required');
- $this->form_validation->set_rules('location[]', 'Location Meeting', 'required');
- $this->form_validation->set_rules('status[]', 'Status', 'required');
- if ($this->form_validation->run() == false) {
- $pageId = 'am_planning'; /*Change_this*/
- $pagePath = 'pages/' . $pageId;
- $data['pageId'] = $pageId;
- $data['pageTitle'] = "AM Planning"; /*Change_this*/
- $data['pageContent'] = $this->load->view($pagePath . '/view', '', TRUE);
- $data['pageStyle'] = $this->load->view($pagePath . '/style', '', TRUE);
- $data['pageScript'] = $this->load->view($pagePath . '/script', '', TRUE);
- $this->load->view('layout/v_layout', $data);
- } else {
- $this->insert();
- }
- }
- private function insert()
- {
- // $data_customer = [
- // "cust_name" => $this->input->post('cust_name[]', true),
- // "date_meet" => date('Y-m-d', strtotime($this->input->post('date[]', true))),
- // "meet_location" => $this->input->post('location[]', true),
- // "status" => $this->input->post('status[]', true),
- // ];
- if ($this->input->post()) {
- $data_planning = [
- "date_created_am" => date('Y-m-d', strtotime($this->input->post('date', true))),
- "cust_segment" => $this->input->post('cust_segment', true),
- ];
- $data_planning['id_planning'] = $this->uuid->v4();
- $customer['id_customer'] = $this->uuid->v4();
- $this->db->insert('planning', $data_planning);
- // $planning_id = $this->db->insert_id();
- $data_customer = $this->input->post();
- // echo '<pre>';
- foreach ($data_customer['cust_name'] as $k => $v) {
- $cus['date'] = $data_customer['date'][$k];
- $cus['cust_name'] = $data_customer['cust_name'][$k];
- $cus['location'] = $data_customer['location'][$k];
- $cus['id_planning'] = $data_planning['id_planning'];
- // $this->db->insert('customer', $cus);
- // print_r($cus);
- // $insert = $this->M_planning->insert_table($data_planning, $data_customer);
- $this->db->insert('customer', $cus);
- }
- echo"berhasil";
- // if ($insert) {
- // // // $uuid_customer = $this->db->set('id_customer','UUID()',FALSE);
- // // // $id = $uuid_planning;
- // // // var_dump($uuid_planning);
- // // // echo $uuid_planning;
- // // // $this->db->set('id_planning', $uuid_planning);
- // // $insert1 = $this->M_planning->create('customer',$data_customer);
- // // if($insert1){
- // // $this->session->set_flashdata('message', '<div class="alert alert-success" style="text-align:center;">Success</div>');
- // // // redirect('index.php/PagesRoute/am_planning');
- // // echo "berhasil";
- // // }
- // // $this->session->set_flashdata('message', '<div class="alert alert-success" style="text-align:center;">Success</div>');
- // // redirect('PagesRoute/am_planning');
- // echo "berhasil";
- // } else {
- // $this->session->set_flashdata('message', '<div class="alert alert-danger" style="text-align:center;">Fail to save data</div>');
- // // redirect('index.php/PagesRoute/am_planning');
- // echo "gagal";
- // }
- // print_r($data);
- // exit();
- }else{
- echo "gagal";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement