Advertisement
niammuddin

create vpn

Oct 12th, 2020
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. // SERVICE CREATE VPN REMOTE
  2. public function Create_VPN()
  3. {
  4. $data['title'] = 'Create VPN Remote';
  5. $data['user'] = $this->db->get_where('user', ['email' => $this->session->userdata('email')])->row_array();
  6.  
  7. $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']);
  8. $this->form_validation->set_rules('password', 'Password', 'required|trim|min_length[3]');
  9. if ($this->form_validation->run() == false) {
  10. $this->load->view('templates/header', $data);
  11. $this->load->view('templates/sidebar', $data);
  12. $this->load->view('templates/topbar', $data);
  13. $this->load->view('service/create-vpn', $data);
  14. $this->load->view('templates/footer');
  15. } else {
  16.  
  17. $userid = $data['user']['email'];
  18. //$saldo = $data['user']['email'];
  19. $saldo = $data['user']['saldo'];
  20. $hargavpn = '2000';
  21.  
  22. $data['content'] = $this->db->order_by('id', 'DESC')->get_where('user_saldo', ['user_id' => $userid])->row_array();
  23.  
  24.  
  25. // CEK SALDO
  26. if ($saldo >= $hargavpn) {
  27.  
  28. $username = $this->input->post('username');
  29. $password = $this->input->post('password');
  30. $vpnserver = $this->input->post('vpnserver');
  31. $port = $this->input->post('port');
  32. $renew = $this->input->post('renew');
  33. $user_id = $data['user']['email'];
  34.  
  35. $saldo = $data['user']['saldo'];
  36. $mysaldo = $saldo - $hargavpn;
  37.  
  38. $data = [
  39. 'username' => $username,
  40. 'password' => $password,
  41. 'server' => $vpnserver,
  42. 'port' => $port,
  43. 'renew' => $renew,
  44. 'price' => '2000',
  45. 'user_id' => $user_id,
  46. 'date_created' => time()
  47. ];
  48. // insert data ke "user_vpn"
  49. $this->db->insert('user_vpn', $data);
  50.  
  51. // insert to "user_saldo"
  52. $data = [
  53. //'saldo_awal' => $saldo,
  54. //'saldo_akhir' => $mysaldo,
  55. 'beli' => $hargavpn,
  56. 'user_id' => $user_id,
  57. 'date_created' => time()
  58. ];
  59. $this->db->insert('user_saldo', $data);
  60.  
  61.  
  62. // update kolom saldo pada table user
  63. $this->db->set('saldo', $mysaldo);
  64. // ini untuk mencari session ID yang ingin di update
  65. $this->db->where('email', $this->session->userdata('email'));
  66. // update prameter
  67. $this->db->update('user');
  68.  
  69. /***
  70. // update saldo
  71. //$uid = $data['user']['email'];
  72. $this->db->set('saldo_akhir', $saldo - "2000");
  73. //$this->db->get_where('user_saldo', array('id' => $user_id), 1, 1);
  74. $this->db->get_where('user_saldo', ['user_id' => $userid]);
  75. $this->db->order_by('id', 'DESC');
  76. $this->db->update('user_saldo');
  77. */
  78.  
  79. $this->session->set_flashdata('message', '<div class="alert alert-success" role="alert">VPN berhasil dibuat...</div>');
  80. redirect('service/create_vpn');
  81. } else {
  82. // ketika sakdo gak cukup
  83. $this->session->set_flashdata('message', '<div class="alert alert-danger" role="alert">Saldo gak cukup...</div>');
  84. redirect('service/create_vpn');
  85. }
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement