Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
13 kB
3
Indexable
Never
<?php

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

class Sedekah extends CI_Controller
{
	public $count_visitor;
	function __construct()
	{
		parent::__construct();
		$this->load->model('Sedekah_model', 'hm');
		$this->load->helper('counter');
		$this->load->helper('text');
        $this->count_visitor = count_visitor();
        
        require APPPATH.'libraries/phpmailer/src/Exception.php';
        require APPPATH.'libraries/phpmailer/src/PHPMailer.php';
        require APPPATH.'libraries/phpmailer/src/SMTP.php';
	}


	public function detail($id,$slug){
		date_default_timezone_set('Asia/Jakarta');
		$data['awal'] = date_create(date('Y-m-d'));
		$data['kat_program'] =  $this->hm->get_kategori_program();
		$data['kat_kerja'] =  $this->hm->get_kategori_donasi();
		$data['last_donasi'] =  $this->hm->get_donasi_last();
		$data['dt'] =  $this->hm->get_donasi_detail($id);
		$data['kat_donasi'] =  $this->hm->get_kategori_donasi();
		$data['id'] =  $id;
		//var_dump($s);die();
		$this->load->view('view_halaman/layout/header',$data);
		$this->load->view('view_halaman/donasi-single',$data);
		$this->load->view('view_halaman/layout/footer',$data);
	}

	public function report($id){
		date_default_timezone_set('Asia/Jakarta');
		$data['awal'] = date_create(date('Y-m-d'));
		$data['kat_program'] =  $this->hm->get_kategori_program();
		$data['kat_kerja'] =  $this->hm->get_kategori_donasi();
		$data['last_donasi'] =  $this->hm->get_donasi_last();
		$data['dt'] =  $this->hm->get_donasi_detail($id);
		$data['report'] =  $this->hm->get_donasi_report($id);
		$data['kat_donasi'] =  $this->hm->get_kategori_donasi();
		$data['id'] =  $id;
		//var_dump($s);die();
		$this->load->view('view_halaman/layout/header',$data);
		$this->load->view('view_halaman/donasi-report',$data);
		$this->load->view('view_halaman/layout/footer',$data);
	}


	public function konfirm(){
		$data['kat_program'] =  $this->hm->get_kategori_program();
		$data['kat_kerja'] =  $this->hm->get_kategori_program2();
	
		$this->load->view('view_halaman/layout/header',$data);
		$this->load->view('view_halaman/konfirm',$data);
		$this->load->view('view_halaman/layout/footer',$data);
	}

	public function pay($id){
		$data['kat_program'] =  $this->hm->get_kategori_program();
		$data['kat_kerja'] =  $this->hm->get_kategori_program2();
		$data['id'] =  $id;
		$this->load->view('view_halaman/layout/header',$data);
		$this->load->view('view_halaman/donasi-payment',$data);
		$this->load->view('view_halaman/layout/footer',$data);
	}


	public function zakat(){
		$data['kat_program'] =  $this->hm->get_kategori_program();
		$data['kat_kerja'] =  $this->hm->get_kategori_program2();
		
		$this->load->view('view_halaman/layout/header',$data);
		$this->load->view('view_halaman/zakat',$data);
		$this->load->view('view_halaman/layout/footer',$data);
	}

	public function zakat_konfirm(){
		$data['kat_program'] =  $this->hm->get_kategori_program();
		$data['kat_kerja'] =  $this->hm->get_kategori_program2();
		
		$this->load->view('view_halaman/layout/header',$data);
		$this->load->view('view_halaman/zakatkonfirm',$data);
		$this->load->view('view_halaman/layout/footer',$data);
	}

	public function donasi_konfirm(){
		$data['kat_program'] =  $this->hm->get_kategori_program();
		$data['kat_kerja'] =  $this->hm->get_kategori_program2();
		
		$this->load->view('view_halaman/layout/header',$data);
		$this->load->view('view_halaman/donasikonfim',$data);
		$this->load->view('view_halaman/layout/footer',$data);
	}


	public function donasi(){
		date_default_timezone_set('Asia/Jakarta');
		$data['awal'] = date_create(date('Y-m-d'));
		$year = date("Y");
		$jumlah_data = $this->hm->jumlah_data2();
		$s = $this->input->post('s');
		$this->load->library('pagination');
		$data['kat_kerja'] =  $this->hm->get_kategori_program2();
		$data['kat_program'] =  $this->hm->get_kategori_program();
		$data['last_donasi'] =  $this->hm->get_donasi_last();
		$data['kat_donasi'] =  $this->hm->get_kategori_donasi();
		$config['base_url'] = base_url().'Sedekah/donasi/';
		$config['total_rows'] = $jumlah_data;
		$config['per_page'] = 5;
		$from = $this->uri->segment(3);
		$this->pagination->initialize($config);
		if ($s != NULL || $s != '') {
			$data['donasis'] = $this->hm->semuadata2($s,$config['per_page'],$from);
		} else {
			$data['donasis'] = $this->hm->semuadata($config['per_page'],$from);
		}
		//var_dump($s);die();
		$this->load->view('view_halaman/layout/header',$data);
		$this->load->view('view_halaman/donasi',$data);
		$this->load->view('view_halaman/layout/footer',$data);
	}


	public function donasi2($id){
		date_default_timezone_set('Asia/Jakarta');
		$data['awal'] = date_create(date('Y-m-d'));
		$year = date("Y");
		$jumlah_data = $this->hm->jumlah_data($id);
		$s = $this->input->post('s');
		$this->load->library('pagination');
		$data['kat_kerja'] =  $this->hm->get_kategori_program2();
		$data['kat_program'] =  $this->hm->get_kategori_program();
		$data['last_donasi'] =  $this->hm->get_donasi_last($id);
		$data['kat_donasi'] =  $this->hm->get_kategori_donasi();
		$data['id'] =  $id;
		$config['base_url'] = base_url().'Sedekah/donasi/';
		$config['total_rows'] = $jumlah_data;
		$config['per_page'] = 5;
		$from = $this->uri->segment(3);
		$this->pagination->initialize($config);
		if ($s != NULL || $s != '') {
			$data['donasis'] = $this->hm->data2($s,$id,$config['per_page'],$from);
		} else {
			$data['donasis'] = $this->hm->data($id,$config['per_page'],$from);
		}
		//var_dump($s);die();
		$this->load->view('view_halaman/layout/header',$data);
		$this->load->view('view_halaman/donasi',$data);
		$this->load->view('view_halaman/layout/footer',$data);
	}

	function simpandonasi()
    {
        $nama		= $this->input->post('nama');
        $jumlah     = $this->input->post('jumlah');
        $email		= $this->input->post('email');
        $wa		= $this->input->post('wa');
		$donasi_id		= $this->input->post('donasi_id');
		$message		= $this->input->post('message');
		$invoice = 'YBMPLN'.rand();

        $data_jemput['nama'] = $nama;
        // $data_jemput['alamat'] = $alamat;
        $data_jemput['email'] = $email;
		$data_jemput['wa'] = $wa;
		$data_jemput['jumlah'] = $jumlah;
        $data_jemput['invoice'] = $invoice;
        $data_jemput['donasi_id'] = $donasi_id;
        $data_jemput['message'] = $message;
        $data_jemput['status'] = 0;
				   
	    // PHPMailer object
			  $response = false;
			  $mail = new PHPMailer();
			 //$mail = $this->PHPMailer_Lib->load();
	 	 // SMTP configuration
		   $mail->SMTPDebug = 0;

			$mail->isSMTP();
			 $mail->Host     = 'mail.ybmpln.org';
			 $mail->SMTPAuth = true;
			 $mail->Username = 'demo@ybmpln.org';
			 $mail->Password = 'ybmasyik91';
		     $mail->SMTPSecure = 'ssl';
             $mail->Port     = 465;
	 
			 $mail->setFrom('demo@ybmpln.org', 'Admin YBM PLN');
			 $mail->addReplyTo('demo@ybmpln.org', 'Admin YBM PLN');
			 // Add a recipient
			 $mail->addAddress($email);
			 
			 // $mail->isSMTP();
			 //$mail->Host     = 'ssl://smtp.gmail.com:465';
			 //$mail->SMTPAuth = true;
			 //$mail->Username = 'ybmplnpusat@gmail.com';
			 //$mail->Password = 'Ybmp!npus4t';
		  //  $mail->addAddress($email);
	 
			 //$mail->setFrom('ybmplnpusat@gmail.com', 'Admin YBM PLN');
			 //$mail->addReplyTo('ybmplnpusat@gmail.com', 'Admin YBM PLN');
	 
			 // Email subject
			 $mail->Subject = 'Konfirmasi No Invoice Pembayaran Donasi';
	 
			 // Set email format to HTML
			 $mail->isHTML(true);

			 $data = array(
				'jumlah'=> $jumlah,
				'invoice'=> $invoice
			);
	 
			 // Email body content
			 $mailContent = "<h1>Terima Kasih Telah Melakukan Pembayaran Donasi Pada Kami</h1>
				 <p>No Invoice Anda : ".$invoice.".</p>";
			 $mail->Body = $this->load->view('emails/sedekah.php',$data,TRUE);
	 

			 // Send email
			 if(!$mail->send()){
				 echo 'Message could not be sent.';
				 echo 'Mailer Error: ' . $mail->ErrorInfo;
			 }else{
				 echo 'Message has been sent';
			 }
			 
			 if(!$mail->send()){
			
			     $this->session->set_flashdata('error',"Message could not sent. Mailer Error: " . $mail->ErrorInfo); redirect('Sedekah/donasi_konfirm');}  else{
		
		
        // simpan ke table user_role
        $this->hm->save_donasi($data_jemput);
        $this->session->set_flashdata('info',"Data Terkirim");
        redirect('Sedekah/donasi_konfirm');}
        
	}


	function simpanzakat()
    {
        $nama		= $this->input->post('nama');
        $jumlah     = $this->input->post('jumlah');
        $email		= $this->input->post('email');
        $wa		= $this->input->post('wa');
		$message		= $this->input->post('message');
		$jenis		= $this->input->post('jenis');
		$invoice = 'YBMPLN'.rand();

        $data_jemput['nama'] = $nama;
        // $data_jemput['alamat'] = $alamat;
        $data_jemput['email'] = $email;
		$data_jemput['wa'] = $wa;
		$data_jemput['jumlah'] = $jumlah;
        $data_jemput['invoice'] = $invoice;
		$data_jemput['message'] = $message;
		$data_jemput['jenis_pembayaran'] = $jenis;
        $data_jemput['status'] = 0;
				   
	
		      // PHPMailer object
			  $response = false;
			  $mail = new PHPMailer();
			 //$mail = $this->PHPMailer_Lib->load();
	 
			 // SMTP configuration
		   $mail->SMTPDebug = 0;

			$mail->isSMTP();
			 $mail->Host     = 'mail.ybmpln.org';
			 $mail->SMTPAuth = true;
			 $mail->Username = 'demo@ybmpln.org';
			 $mail->Password = 'ybmasyik91';
		     $mail->SMTPSecure = 'ssl';
             $mail->Port     = 465;
	 
			 $mail->setFrom('demo@ybmpln.org', 'Admin YBM PLN');
			 $mail->addReplyTo('demo@ybmpln.org', 'Admin YBM PLN');
			 // Add a recipient
			 $mail->addAddress($email);
			 
			 // $mail->isSMTP();
			 //$mail->Host     = 'ssl://smtp.gmail.com:465';
			 //$mail->SMTPAuth = true;
			 //$mail->Username = 'ybmplnpusat@gmail.com';
			 //$mail->Password = 'Ybmp!npus4t';
		  //  $mail->addAddress($email);
	 
			 //$mail->setFrom('ybmplnpusat@gmail.com', 'Admin YBM PLN');
			 //$mail->addReplyTo('ybmplnpusat@gmail.com', 'Admin YBM PLN');
	 
			 // Email subject
			 $mail->Subject = 'Konfirmasi No Invoice Pembayaran ZISWAF';
	 
			 // Set email format to HTML
			 $mail->isHTML(true);


			 $data = array(
				'jumlah'=> $jumlah,
				'invoice'=> $invoice
			);
	 
	 
			 // Email body content
			 $mailContent = "<body background='".base_url()."'/assets/img/Donasi YBM.jpg'><h1>Terima Kasih Telah Melakukan Pembayaran ZISWAF Pada Kami</h1>
				 <p>No Invoice Anda : ".$invoice.".</p></body>";
			 $mail->Body = $this->load->view('emails/zakat.php',$data,TRUE);
	 
	    //var_dump($mail->ErrorInfo);die();
		
			 // Send email
			 if(!$mail->send()){
			   
			echo $mail->ErrorInfo;
    			   $this->session->set_flashdata('error',"Message could not sent. Mailer Error: " . $mail->ErrorInfo); redirect('Sedekah/zakat');
    			  }  else{

     //   simpan ke table user_role
        $this->hm->save_zakat($data_jemput);
        $this->session->set_flashdata('info',"Data Terkirim");
        redirect('Sedekah/zakat_konfirm');
      // echo '<script type="text/javascript">window.location = "http://demo.ybmpln.org/Sedekah/zakat_konfirm"</script>';
			     }
        
	}



	function updatekonfirm()
    {
        $nama		= $this->input->post('nama');
        $invoice     = $this->input->post('invoice');
		$jenis		= $this->input->post('jenis');

        $data_jemput['nama'] = $nama;
        $data_jemput['invoice'] = $invoice;
		$data_jemput['jenis_pembayaran'] = $jenis;
		//$data_jemput['status'] = 1;
		$data_jemput['created_at'] = date('Y-m-d');
		//var_dump(date('Y-m-d'));die();
		if ($jenis ==  1) {
			$t = $this->hm->get_konfirm_donasi($invoice);
		} else {
			$t = $this->hm->get_konfirm_ziswaf($invoice);
		}
		
		
		//var_dump($t);die();
		if($_FILES['file']['name'] != ""){

			if ($t->file != "" || $t->file != NULL) {
				unlink("assets/images/konfirm/".$t->file);
			}

			$config['upload_path']          = 'assets/images/konfirm';
			$config['allowed_types']        = 'jpeg|jpg|png|PNG';
			$config['max_size']             = '500000';
			$config['remove_space']			= true;
			$config['overwrite']			= false;
			$config['encrypt_name']			= true;
			$config['max_width'] 			= '';
			$config['max_height']			= '';
			
			$this->load->library('upload',$config);
			$this->upload->initialize($config);
			if(!$this->upload->do_upload('file'))
			{
				//print_r('');
				$this->session->set_flashdata('error',"Ukuran file terlalu besar. Maksimal 500 MB"); 
			}
			else
			{
				$file = $this->upload->data();
				if($file['file_name'])
				{
					$data['file'] = $file['file_name'];
				}
				$img_header = $data['file'];
				$data_jemput['file'] = $img_header;

			}
		}
	  
		
		// simpan ke table user_role
		if ($jenis == 1) {
		//	$this->hm->update_jumlah_donasi($t->donasi_id,$t->jumlah);
			$this->hm->update_donasi($invoice,$data_jemput);
		} else {
			$this->hm->update_ziswaf($invoice,$data_jemput);
		}
        $this->session->set_flashdata('info',"Data Terkirim");
        redirect('Sedekah/konfirm');
        
	}
	
}

?>