Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function postcabang(){
- $this->loadModel('Province');
- $this->loadmodel('Kecamatan');
- $this->loadmodel('Kelurahan');
- $this->loadmodel('Kabupaten');
- $this->loadModel('User');
- $jml = $this->User->find('first',array(
- 'conditions' => array(
- "date_part('month',User.create_date)"=>date('n'),
- "date_part('year',User.create_date)"=>date('Y')
- ),
- 'fields' => array('count("User"."id") as jml')
- ));
- $selProv = $this->Province->find('first',array('conditions' => array('Province.id' => $this->data['prov'])));
- $selKab = $this->Kabupaten->find('first',array('conditions' => array('Kabupaten.id' => $this->data['kabs'])));
- $selKec = $this->Kecamatan->find('first',array('conditions' => array('Kecamatan.id' => $this->data['kecs'])));
- $selKel = $this->Kelurahan->find('first',array('conditions' => array('Kelurahan.id' => $this->data['kels'])));
- $selKode = $this->Kecamatan->find('first',array('conditions' => array('Kecamatan.id' => $this->data['kodes'])));
- //$downline= $this->Session->read('Auth.User.id');
- $sandi= substr( str_shuffle( 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$' ) , 0 , 6 );
- if (empty($this->data)) {
- $this->render();
- } else {
- // fetch kabupaten_code
- $noktp = $this->data['no_ktp'];
- $company = $this->data['company'];
- $first_name = $this->data['first_name'];
- //$last_name = $this->data['last_name'];
- $alamat = $this->data['alamat'];
- $email = $this->data['email'];
- $phone = $this->data['phone'];
- $mon = date('m');
- $thn = date('y');
- $username = $this->data['username'];
- $password = $this->Auth->password($sandi);
- $handphone = $this->data['handphone'];
- $group_id = $this->data['group_id'];
- $kodepos = $selKode['Kecamatan']['kode_pos'];
- $kelurahan = $selKel['Kelurahan']['name'];
- $kecamatan = $selKec['Kecamatan']['name'];
- $kabkota = $selKab['Kabupaten']['name'];
- $province = $selProv['Province']['name'];
- $alamat = $this->data['alamat'];
- $status = true;
- $kode_kab_kota = $selKab['Kabupaten']['kabupaten_code'];
- $now = new DateTime();
- $today = $now->format("Y-m-d H:i:s");
- //$identitas = $this->data['identitas'];
- $this->loadModel('User');
- $check_data = $this->User->find('first',array('conditions' => array("OR" => array('User.hp' => $handphone, 'User.email' => $email))));
- if(isset($handphone) || isset($email)){
- if($email==$check_data['User']['email']){
- $response = "Email sudah terdaftar";
- }else if($handphone==$check_data['User']['hp']){
- $response = "No Hp sudah terdaftar";
- }else{
- $query = $this->Register->query("insert into users (
- company,
- first_name,
- last_name,
- address,
- email,
- phone,
- pks,
- username,
- password,
- group_id,
- create_by,
- create_date,
- identitas,
- nomor_identitas,
- kode_pos,
- kecamatan,
- kelurahan,
- kab_kota,
- propinsi,
- hp,
- upline,
- status,
- ran,
- kode_kab_kota,
- secret_key
- )
- values
- (
- '".$company."',
- '".$first_name."',
- '".$first_name."',
- '".$alamat."',
- '".$email."',
- '".$phone."',
- 'SLS',
- '".$username."',
- '".$password."',
- ".$group_id.",
- '".$this->Session->read('Auth.User.username')."',
- '".$today."',
- 'KTP',
- '".$noktp."',
- '".$kodepos."',
- '".$kecamatan."',
- '".$kelurahan."',
- '".$kabkota."',
- '".$province."',
- '".$handphone."',
- '".$this->Session->read('Auth.User.id')."',
- '".$status."',
- '".$this->getRan()."',
- '".$kode_kab_kota."',
- '".$this->getSecretKey()."'
- )
- ");
- $email = new CakeEmail();
- $email->config('gmailbaru');
- $email->subject('Regristrasi Data Cabang');
- $email->from('xxx');
- $email->emailFormat('html');
- $email->template('registrationcabang');
- $email->viewVars(array(
- 'nama' => $first_name,
- 'cabang' => $company,
- 'username' => $username,
- 'password' => $sandi,
- 'pin' => $this->getRan()
- ));
- $email->to('xxx');
- //debug($email);
- if ($email->send()) {
- $this->Session->setFlash('Email sent');
- $response = "Berhasil menyimpan data";
- } else {
- $this->Session->setFlash('Email not sent');
- }
- $this->set('smtp-errors', $this->Email->smtpError);
- }
- }else{
- $response = "Mohon isikan data dengan benar";
- }
- $this->set('response',$response);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement