Advertisement
Faizal3696

controller

Apr 11th, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.54 KB | None | 0 0
  1. function postcabang(){
  2.             $this->loadModel('Province');
  3.             $this->loadmodel('Kecamatan');
  4.             $this->loadmodel('Kelurahan');
  5.             $this->loadmodel('Kabupaten');
  6.         $this->loadModel('User');  
  7.         $jml = $this->User->find('first',array(
  8.             'conditions' => array(
  9.                 "date_part('month',User.create_date)"=>date('n'),
  10.                 "date_part('year',User.create_date)"=>date('Y')
  11.             ),
  12.             'fields' => array('count("User"."id") as jml')
  13.         ));
  14.             $selProv = $this->Province->find('first',array('conditions' => array('Province.id' => $this->data['prov'])));
  15.             $selKab = $this->Kabupaten->find('first',array('conditions' => array('Kabupaten.id' => $this->data['kabs'])));
  16.             $selKec = $this->Kecamatan->find('first',array('conditions' => array('Kecamatan.id' => $this->data['kecs'])));
  17.             $selKel = $this->Kelurahan->find('first',array('conditions' => array('Kelurahan.id' => $this->data['kels'])));
  18.             $selKode = $this->Kecamatan->find('first',array('conditions' => array('Kecamatan.id' => $this->data['kodes'])));
  19.        
  20.         //$downline= $this->Session->read('Auth.User.id');
  21.         $sandi= substr( str_shuffle( 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$' ) , 0 , 6 );
  22.        
  23.         if (empty($this->data)) {
  24.             $this->render();   
  25.         } else {
  26.             // fetch kabupaten_code
  27.            
  28.  
  29.             $noktp = $this->data['no_ktp'];
  30.             $company = $this->data['company'];
  31.             $first_name = $this->data['first_name'];
  32.             //$last_name = $this->data['last_name'];
  33.             $alamat = $this->data['alamat'];
  34.             $email = $this->data['email'];
  35.             $phone = $this->data['phone'];
  36.             $mon = date('m');
  37.             $thn = date('y');
  38.             $username = $this->data['username'];
  39.             $password = $this->Auth->password($sandi);
  40.             $handphone = $this->data['handphone'];
  41.             $group_id = $this->data['group_id'];
  42.             $kodepos = $selKode['Kecamatan']['kode_pos'];
  43.             $kelurahan = $selKel['Kelurahan']['name'];
  44.             $kecamatan = $selKec['Kecamatan']['name'];
  45.             $kabkota = $selKab['Kabupaten']['name'];
  46.             $province = $selProv['Province']['name'];
  47.             $alamat = $this->data['alamat'];
  48.             $status =  true;
  49.             $kode_kab_kota = $selKab['Kabupaten']['kabupaten_code'];
  50.             $now = new DateTime();
  51.             $today = $now->format("Y-m-d H:i:s");
  52.             //$identitas = $this->data['identitas'];
  53.            
  54.             $this->loadModel('User');
  55.             $check_data = $this->User->find('first',array('conditions' => array("OR" => array('User.hp' => $handphone, 'User.email' => $email))));
  56.            
  57.  
  58.             if(isset($handphone) || isset($email)){
  59.                
  60.                 if($email==$check_data['User']['email']){
  61.                     $response = "Email sudah terdaftar";
  62.                 }else if($handphone==$check_data['User']['hp']){
  63.                     $response = "No Hp sudah terdaftar";
  64.                 }else{
  65.                     $query = $this->Register->query("insert into users (
  66.                                                                 company,
  67.                                                                 first_name,
  68.                                                                 last_name,
  69.                                                                 address,
  70.                                                                 email,
  71.                                                                 phone,
  72.                                                                 pks,
  73.                                                                 username,
  74.                                                                 password,
  75.                                                                 group_id,
  76.                                                                 create_by,
  77.                                                                 create_date,
  78.                                                                 identitas,
  79.                                                                 nomor_identitas,
  80.                                                                 kode_pos,
  81.                                                                 kecamatan,
  82.                                                                 kelurahan,
  83.                                                                 kab_kota,
  84.                                                                 propinsi,
  85.                                                                 hp,
  86.                                                                 upline,
  87.                                                                 status,
  88.                                                                 ran,
  89.                                                                 kode_kab_kota,
  90.                                                                 secret_key
  91.  
  92.                                                                 )
  93.                                     values
  94.                                         (
  95.                                             '".$company."',
  96.                                             '".$first_name."',
  97.                                             '".$first_name."',
  98.                                             '".$alamat."',
  99.                                             '".$email."',
  100.                                             '".$phone."',
  101.                                             'SLS',
  102.                                             '".$username."',
  103.                                             '".$password."',
  104.                                             ".$group_id.",
  105.                                             '".$this->Session->read('Auth.User.username')."',
  106.                                             '".$today."',
  107.                                             'KTP',
  108.                                             '".$noktp."',
  109.                                             '".$kodepos."',
  110.                                             '".$kecamatan."',
  111.                                             '".$kelurahan."',
  112.                                             '".$kabkota."',
  113.                                             '".$province."',
  114.                                             '".$handphone."',
  115.                                             '".$this->Session->read('Auth.User.id')."',
  116.                                             '".$status."',
  117.                                             '".$this->getRan()."',
  118.                                             '".$kode_kab_kota."',
  119.                                             '".$this->getSecretKey()."'
  120.                                            
  121.                                         )
  122.                     ");
  123.  
  124.                     $email = new CakeEmail();
  125.                     $email->config('gmailbaru');
  126.                     $email->subject('Regristrasi Data Cabang');
  127.                     $email->from('xxx');
  128.                     $email->emailFormat('html');
  129.                     $email->template('registrationcabang');
  130.                     $email->viewVars(array(
  131.                                 'nama' => $first_name,
  132.                                 'cabang' => $company,
  133.                                 'username' => $username,
  134.                                 'password' => $sandi,
  135.                                 'pin' => $this->getRan()
  136.                     ));
  137.                     $email->to('xxx');
  138.                
  139.                     //debug($email);
  140.                  
  141.                     if ($email->send()) {
  142.                            $this->Session->setFlash('Email sent');
  143.                            $response = "Berhasil menyimpan data";
  144.                     } else {
  145.                            $this->Session->setFlash('Email not sent');
  146.                     }
  147.  
  148.                     $this->set('smtp-errors', $this->Email->smtpError);
  149.  
  150.                 }
  151.  
  152.             }else{
  153.  
  154.                     $response = "Mohon isikan data dengan benar";
  155.             }
  156.  
  157.            
  158.             $this->set('response',$response);
  159.            
  160.          }
  161.  
  162.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement