SHARE
TWEET

Untitled

a guest Oct 4th, 2017 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class Account extends CI_Controller {
  5.   public static $data_username;
  6.   public static $data_nama;
  7.   public static $data_email;
  8.   public static $status_email;
  9.   public static $data_password;
  10.  
  11.   public static $data_barang;
  12.   public static $data_harga;
  13.   public static $data_jumlah;
  14.   public function set_all_data($data_username,$data_nama,$data_email,$data_password,
  15.   $status_email,$data_barang,$data_harga,$data_jumlah)
  16.   {
  17.     $all_data = "";
  18.     if (isset($data_username))
  19.         $all_data .= form_hidden('data_username',$data_username);
  20.     if (isset($data_nama))
  21.         $all_data .= form_hidden('data_nama',$data_nama);
  22.     if (isset($data_email))
  23.         $all_data .= form_hidden('data_email',$data_email);
  24.     if (isset($data_password))
  25.         $all_data .= form_hidden('data_password',$data_password);
  26.     if (isset($status_email))
  27.         $all_data .= form_hidden('status_email',$status_email);
  28.     if (isset($data_barang))
  29.         $all_data .= form_hidden('data_barang',$data_barang);
  30.     if (isset($data_harga))
  31.         $all_data .= form_hidden('data_harga',$data_harga);
  32.     if (isset($data_jumlah))
  33.         $all_data .= form_hidden('data_jumlah',$data_jumlah);
  34.  
  35.     return $all_data;
  36.   }
  37.   public function help()
  38.   {
  39.     $this->load->library('form_validation');
  40.     $this->load->helper('url');
  41.     $this->load->helper('form');
  42.   }
  43.     public function index()
  44.     {$this->help();$this->load->view('login');
  45.     }
  46.   public function getalldata($view,$id=null)
  47.   {
  48.     $data['data_barang'] = $this->input->get_post('data_barang');
  49.     $data['data_harga'] = $this->input->get_post('data_harga');
  50.     $data['data_jumlah'] =$this->input->get_post('data_jumlah');
  51.     $data['data_username'] = $this->input->get_post('data_username');
  52.     $data['data_password'] = $this->input->get_post('data_password');
  53.     $data['data_nama'] = $this->input->get_post('data_nama');
  54.     $data['data_email'] = $this->input->get_post('data_email');
  55.     $data['status_email'] = $this->input->get_post('status_email');
  56.     $data['all_data'] = $this->set_all_data($data['data_username'],
  57.     $data['data_nama'],$data['data_email'],$data['data_password'],
  58.     $data['status_email'],
  59.     $data['data_barang'],$data['data_harga'] ,$data['data_jumlah']);
  60.     if (isset($id)) {
  61.       $nama = explode('-',$data['data_nama']); $data['namaku'] = $nama[$id];
  62.     }$this->load->view($view,$data);
  63.   }
  64.   public function login()
  65.     {
  66.     $this->help();
  67.     $login = $this->input->get_post('login');
  68.     $register = $this->input->get_post('register');
  69.     if (isset($login)) {
  70.       $us = $this->input->get_post('username');
  71.       $pass = $this->input->get_post('password');
  72.  
  73.       if($us=="admin" && $pass=="admin"){ $this->getalldata('admin');
  74.       }else{
  75.         $this->form_validation->set_rules('username', 'Username', 'required|callback_username_login');
  76.         $this->form_validation->set_rules('password', 'Password', 'required');
  77.  
  78.         if ($this->form_validation->run() == FALSE){ $this->getalldata('login');
  79.         }else{
  80.           $data['id'] = $this->get_id($us);
  81.           $this->getalldata('user',$data['id']);
  82.         }
  83.       }
  84.     }
  85.     if (isset($register)) {
  86.       $this->getalldata('register');
  87.     }
  88.     }
  89.   public function register()
  90.   {
  91.     $this->help();
  92.     $us = $this->input->get_post('username');
  93.     $pass = $this->input->get_post('password');
  94.  
  95.     $this->form_validation->set_rules('username', 'Username', 'required|min_length[8]
  96.     |callback_username_check_space|callback_username_check');
  97.     $this->form_validation->set_rules('email', 'Email', 'required|valid_email|callback_email_check');
  98.  
  99.     $this->form_validation->set_rules('password', 'Password', 'required|min_length[8]
  100.     |callback_pass_check_alphanum');
  101.  
  102.     $this->form_validation->set_rules('password1', 'Password Confirmation',
  103.     'required|matches[password]');
  104.     $this->form_validation->set_rules('nama', 'Name',
  105.     'required');
  106.     if ($this->form_validation->run() == FALSE){
  107.       $this->getalldata('register');
  108.     }else{
  109.            echo "Register berhasil";
  110.            $data['data_barang'] = $this->input->get_post('data_barang');
  111.            $data['data_harga'] = $this->input->get_post('data_harga');
  112.            $data['data_jumlah'] =$this->input->get_post('data_jumlah');
  113.  
  114.            self::$data_username .= $this->input->get_post('username')." ".$this->input->get_post('data_username');
  115.            self::$data_nama .= $this->input->get_post('nama')."-".$this->input->get_post('data_nama');
  116.            self::$data_password .= $this->input->get_post('password')." ".$this->input->get_post('data_password');
  117.            self::$data_email .= $this->input->get_post('email')." ".$this->input->get_post('data_email');
  118.            self::$status_email .= "1 ".$this->input->get_post('status_email');
  119.            $data['data_username'] = self::$data_username;
  120.            $data['data_password'] = self::$data_password;
  121.            $data['data_nama'] =self::$data_nama;
  122.            $data['data_email'] = self::$data_email;
  123.            $data['status_email'] = self::$status_email ;
  124.  
  125.            $data['all_data'] = $this->set_all_data($data['data_username'],
  126.            $data['data_nama'],$data['data_email'],$data['data_password'],
  127.            $data['status_email'],
  128.            $data['data_barang'],$data['data_harga'] ,$data['data_jumlah']);
  129.            $this->load->view('login',$data);
  130.      }
  131.  
  132.   }
  133.   public function get_id($str){
  134.     $data_username = explode(' ',$this->input->get_post('data_username'));
  135.     $data_email = explode(' ',$this->input->get_post('data_email'));
  136.     $cek = true;  $dt = "";
  137.     for ($i=0; $i < count($data_username); $i++) {
  138.          if($data_username[$i] == $str){
  139.            $cek = false; $dt = $i;
  140.          }
  141.     }
  142.     for ($i=0; $i < count($data_email); $i++) {
  143.          if($data_email[$i] == $str){
  144.            $cek = false; $dt = $i;
  145.          }
  146.     }
  147.     return $dt;
  148.   }
  149.   public function username_login($str){
  150.     $data_username = explode(' ',$this->input->get_post('data_username'));
  151.     $data_email = explode(' ',$this->input->get_post('data_email'));
  152.     $status_email = explode(' ',$this->input->get_post('status_email'));
  153.     $data_password = explode(' ',$this->input->get_post('data_password'));
  154.     $us = $this->input->get_post('username');
  155.     $pass = $this->input->get_post('password');
  156.     if(count($data_username) > 0 ){
  157.       $cek = true; $dt = "";
  158.       for ($i=0; $i < count($data_username); $i++) {
  159.            if($data_username[$i] == $us){
  160.              $cek = false; $dt = $i;
  161.            }
  162.       }
  163.       for ($i=0; $i < count($data_email); $i++) {
  164.            if($data_email[$i] == $us){
  165.              $cek = false; $dt = $i;
  166.            }
  167.       }
  168.       if($cek){
  169.         $this->form_validation->set_message('username_login', '
  170.         Username / Email tidak terdaftar');
  171.         return FALSE;
  172.       }else{
  173.         if($status_email[$dt] != "1" || $status_email[$dt] != 1){
  174.           $this->form_validation->set_message('username_login', '
  175.           Account anda dinonaktifkan');
  176.           return FALSE;
  177.         }else{
  178.           if($data_password[$dt] != $pass){
  179.             $this->form_validation->set_message('username_login', '
  180.             Password Salah');
  181.             return FALSE;
  182.           }else{
  183.             return TRUE;
  184.           }
  185.         }
  186.       }
  187.     }else{ return TRUE; }
  188.   }
  189.  
  190.   public function username_check($str){
  191.     $data_username = explode(' ',$this->input->get_post('data_username'));
  192.     $us = $this->input->get_post('username');
  193.     if($us!= null){
  194.       if(count($data_username) > 0 ){ $cek = true;
  195.         for ($i=0; $i < count($data_username); $i++) {
  196.           if($data_username[$i] == $us){ $cek = false; }
  197.         }
  198.         if($cek){ return TRUE;
  199.         }else{
  200.           $this->form_validation->set_message('username_check', '{field} sudah dipakai');
  201.           return FALSE;
  202.         }
  203.       }else{ return TRUE; }
  204.     }
  205.   }
  206.  
  207.   public function email_check($str){
  208.     $data_email = explode(' ',$this->input->get_post('data_email'));
  209.     $us = $this->input->get_post('email');
  210.     if($us!= null){
  211.       if(count($data_email) > 0 ){ $cek = true;
  212.         for ($i=0; $i < count($data_email); $i++) {
  213.              if($data_email[$i] == $us){ $cek = false; }
  214.         }
  215.         if($cek){ return TRUE;
  216.         }else{
  217.           $this->form_validation->set_message('email_check', '{field} sudah dipakai');
  218.             return FALSE;
  219.         }
  220.       }else{ return TRUE; }
  221.     }
  222.   }
  223.   public function username_check_space($str)
  224.    {
  225.      if($str!=null){
  226.        if (!preg_match('/[A-Za-z]/', $str[0]))
  227.        {  $this->form_validation->set_message('username_check_space',
  228.          '{field} Harus diawali dengan huruf');
  229.            return FALSE;
  230.        }else{
  231.          if (preg_match('/\s/',$str) != 0)
  232.          { $this->form_validation->set_message('username_check_space',
  233.            '{field} tidak boleh ada spasi nya');
  234.            return FALSE;
  235.          }else{return TRUE;}
  236.        }
  237.      }
  238.    }
  239.    public function pass_check_alphanum($str)
  240.     {
  241.        if($str!=null){
  242.         if (!preg_match('/[A-Za-z].*[0-9]|[0-9].*[A-Za-z]/', $str))
  243.         { $this->form_validation->set_message('pass_check_alphanum',
  244.          '{field} Harus mengandung huruf dan angka'); return FALSE;
  245.         }else{return TRUE;}
  246.       }
  247.     }
  248.     public function admin()
  249.     {
  250.       $this->help(); $logout = $this->input->get_post('logout');
  251.       $barang = $this->input->get_post('barang');
  252.       $user = $this->input->get_post('user');
  253.       $back = $this->input->get_post('back');
  254.       if(isset($logout)) $this->getalldata('login');
  255.       if(isset($user)) $this->getalldata('master_user');
  256.       if(isset($back)) $this->getalldata('admin');
  257.       if(isset($barang)) $this->getalldata('master_barang');
  258.     }
  259.     public function edit_status()
  260.     {
  261.       $this->help();
  262.       $data['data_barang'] = $this->input->get_post('data_barang');
  263.       $data['data_harga'] = $this->input->get_post('data_harga');
  264.       $data['data_jumlah'] =$this->input->get_post('data_jumlah');
  265.       $data['data_username'] = $this->input->get_post('data_username');
  266.       $data['data_password'] = $this->input->get_post('data_password');
  267.       $data['data_nama'] = $this->input->get_post('data_nama');
  268.       $data['data_email'] = $this->input->get_post('data_email');
  269.       $data['status_email'] = $this->input->get_post('status_email');
  270.  
  271.       $id = $this->input->get_post('id');
  272.  
  273.       $status_email = explode(' ',$data['status_email'] );
  274.       $new_status="";
  275.       if($status_email[$id] == 0){$status_email[$id] = 1;}
  276.       else{$status_email[$id] = 0;}
  277.       for ($i=0; $i < count($status_email); $i++) {
  278.         $new_status .= $status_email[$i]." ";
  279.       }
  280.       $data['status_email'] = $new_status;
  281.  
  282.       $data['all_data'] = $this->set_all_data($data['data_username'],
  283.       $data['data_nama'],$data['data_email'],$data['data_password'],
  284.       $data['status_email'],
  285.       $data['data_barang'],$data['data_harga'] ,$data['data_jumlah']);
  286.  
  287.       $this->load->view('master_user',$data);
  288.     }
  289.     public function insert_update_barang()
  290.     {
  291.       $this->help();
  292.       $data['data_username'] = $this->input->get_post('data_username');
  293.       $data['data_password'] = $this->input->get_post('data_password');
  294.       $data['data_nama'] = $this->input->get_post('data_nama');
  295.       $data['data_email'] = $this->input->get_post('data_email');
  296.       $data['status_email'] = $this->input->get_post('status_email');
  297.  
  298.       $tambah = $this->input->get_post('tambah');
  299.       $edit = $this->input->get_post('edit');
  300.       if (isset($tambah)) {
  301.         $id=$this->input->get_post('id_');
  302.         if ($id != null) {
  303.         } else {
  304.           self::$data_barang .= $this->input->get_post('barang')."-".$this->input->get_post('data_barang');
  305.           self::$data_harga .= $this->input->get_post('harga')." ".$this->input->get_post('data_harga');
  306.           self::$data_jumlah .= $this->input->get_post('jumlah')." ".$this->input->get_post('data_jumlah');
  307.           $data['data_barang'] = self::$data_barang;
  308.           $data['data_harga'] = self::$data_harga;
  309.           $data['data_jumlah'] =self::$data_jumlah;
  310.  
  311.           $data['all_data'] = $this->set_all_data($data['data_username'],
  312.           $data['data_nama'],$data['data_email'],$data['data_password'],
  313.           $data['status_email'],
  314.           $data['data_barang'],$data['data_harga'] ,$data['data_jumlah']);
  315.  
  316.           $this->load->view('master_barang',$data);
  317.         }
  318.       }else
  319.       if (isset($edit)) {
  320.         $barang=$this->input->get_post('barang');
  321.         $harga=$this->input->get_post('harga');
  322.         $jumlah=$this->input->get_post('jumlah');
  323.         $id=$this->input->get_post('id_');
  324.         self::$data_barang = $this->input->get_post('data_barang');
  325.         self::$data_harga  = $this->input->get_post('data_harga');
  326.         self::$data_jumlah = $this->input->get_post('data_jumlah');
  327.         $data_barang1 = explode('-',self::$data_barang);
  328.         $data_harga1 = explode(' ',self::$data_harga);
  329.         $data_jumlah1 = explode(' ',self::$data_jumlah);
  330.         $data_barang1[$id] = $barang;
  331.         $data_harga1[$id] = $harga;
  332.         $data_jumlah1[$id] = $jumlah;
  333.  
  334.         $data['data_barang'] = "";
  335.         $data['data_harga']  = "";
  336.         $data['data_jumlah'] = "";
  337.         for ($i=0; $i < count($data_barang1); $i++) {
  338.           if(isset($data_barang1[$i])){
  339.             if($data_barang1[$i] != null){
  340.               $data['data_barang'] .= $data_barang1[$i]."-";
  341.               $data['data_harga'] .= $data_harga1[$i]." ";
  342.               $data['data_jumlah'] .= $data_jumlah1[$i]." ";
  343.             }
  344.           }
  345.         }
  346.         $data['all_data'] = $this->set_all_data($data['data_username'],
  347.         $data['data_nama'],$data['data_email'],$data['data_password'],
  348.         $data['status_email'],
  349.         $data['data_barang'],$data['data_harga'] ,$data['data_jumlah']);
  350.  
  351.           $this->load->view('master_barang',$data);
  352.       }else{
  353.         $id=$this->input->get_post('id_del');
  354.         self::$data_barang = $this->input->get_post('data_barang');
  355.         self::$data_harga  = $this->input->get_post('data_harga');
  356.         self::$data_jumlah = $this->input->get_post('data_jumlah');
  357.         $data_barang1 = explode('-',self::$data_barang);
  358.         $data_harga1 = explode(' ',self::$data_harga);
  359.         $data_jumlah1 = explode(' ',self::$data_jumlah);
  360.         $data_barang1[$id] = "";
  361.         $data_harga1[$id] = "";
  362.         $data_jumlah1[$id] = "";
  363.  
  364.         $data['data_barang'] = "";
  365.         $data['data_harga']  = "";
  366.         $data['data_jumlah'] = "";
  367.         for ($i=0; $i < count($data_barang1); $i++) {
  368.           if(isset($data_barang1[$i])){
  369.             if($data_barang1[$i] != null){
  370.               $data['data_barang'] .= $data_barang1[$i]."-";
  371.               $data['data_harga'] .= $data_harga1[$i]." ";
  372.               $data['data_jumlah'] .= $data_jumlah1[$i]." ";
  373.             }
  374.           }
  375.         }
  376.  
  377.         $data['all_data'] = $this->set_all_data($data['data_username'],
  378.         $data['data_nama'],$data['data_email'],$data['data_password'],
  379.         $data['status_email'],
  380.         $data['data_barang'],$data['data_harga'] ,$data['data_jumlah']);
  381.  
  382.           $this->load->view('master_barang',$data);
  383.       }
  384.  
  385.     }
  386. }
  387. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top