Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SERVICE CREATE VPN REMOTE
- public function Create_VPN()
- {
- $data['title'] = 'Create VPN Remote';
- $data['user'] = $this->db->get_where('user', ['email' => $this->session->userdata('email')])->row_array();
- $this->form_validation->set_rules('username', 'Username', 'required|alpha_numeric|max_length[10]|is_unique[user_vpn.username]', ['is_unique' => 'username ini sudah terdaftar, gunakan username lain']);
- $this->form_validation->set_rules('password', 'Password', 'required|trim|min_length[3]');
- if ($this->form_validation->run() == false) {
- $this->load->view('templates/header', $data);
- $this->load->view('templates/sidebar', $data);
- $this->load->view('templates/topbar', $data);
- $this->load->view('service/create-vpn', $data);
- $this->load->view('templates/footer');
- } else {
- $userid = $data['user']['email'];
- //$saldo = $data['user']['email'];
- $saldo = $data['user']['saldo'];
- $hargavpn = '2000';
- $data['content'] = $this->db->order_by('id', 'DESC')->get_where('user_saldo', ['user_id' => $userid])->row_array();
- // CEK SALDO
- if ($saldo >= $hargavpn) {
- $username = $this->input->post('username');
- $password = $this->input->post('password');
- $vpnserver = $this->input->post('vpnserver');
- $port = $this->input->post('port');
- $renew = $this->input->post('renew');
- $user_id = $data['user']['email'];
- $saldo = $data['user']['saldo'];
- $mysaldo = $saldo - $hargavpn;
- $data = [
- 'username' => $username,
- 'password' => $password,
- 'server' => $vpnserver,
- 'port' => $port,
- 'renew' => $renew,
- 'price' => '2000',
- 'user_id' => $user_id,
- 'date_created' => time()
- ];
- // insert data ke "user_vpn"
- $this->db->insert('user_vpn', $data);
- // insert to "user_saldo"
- $data = [
- //'saldo_awal' => $saldo,
- //'saldo_akhir' => $mysaldo,
- 'beli' => $hargavpn,
- 'user_id' => $user_id,
- 'date_created' => time()
- ];
- $this->db->insert('user_saldo', $data);
- // update kolom saldo pada table user
- $this->db->set('saldo', $mysaldo);
- // ini untuk mencari session ID yang ingin di update
- $this->db->where('email', $this->session->userdata('email'));
- // update prameter
- $this->db->update('user');
- /***
- // update saldo
- //$uid = $data['user']['email'];
- $this->db->set('saldo_akhir', $saldo - "2000");
- //$this->db->get_where('user_saldo', array('id' => $user_id), 1, 1);
- $this->db->get_where('user_saldo', ['user_id' => $userid]);
- $this->db->order_by('id', 'DESC');
- $this->db->update('user_saldo');
- */
- $this->session->set_flashdata('message', '<div class="alert alert-success" role="alert">VPN berhasil dibuat...</div>');
- redirect('service/create_vpn');
- } else {
- // ketika sakdo gak cukup
- $this->session->set_flashdata('message', '<div class="alert alert-danger" role="alert">Saldo gak cukup...</div>');
- redirect('service/create_vpn');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement