芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/www/breadwinnerv2/application/controllers/Export.php
load->library("Aauth"); $this->load->model('export_model', 'export'); if (!$this->aauth->is_loggedin()) { redirect('/user/', 'refresh'); exit; } if ($this->aauth->get_user()->roleid < 5) { exit('Not Allowed!'); } $this->date = 'backup_' . date('Y_m_d_H_i_s'); } function dbexport() { $head['title'] = "Backup Database"; $head['usernm'] = $this->aauth->get_user()->username; $this->load->view('fixed/header', $head); $this->load->view('export/db_back'); $this->load->view('fixed/footer'); } function dbexport_c() { $this->load->dbutil(); $backup =& $this->dbutil->backup(); $this->load->helper('file'); write_file('/downloads', $backup); $this->load->helper('download'); force_download($this->date . '.gz', $backup); } function crm() { $head['title'] = "Export CRM Data"; $head['usernm'] = $this->aauth->get_user()->username; $this->load->view('fixed/header', $head); $this->load->view('export/crm'); $this->load->view('fixed/footer'); } function crm_now() { $type = $this->input->post('type'); switch ($type) { case 1 : $this->customers(); break; case 2 : $this->suppliers(); break; } } private function customers() { $this->load->dbutil(); $this->load->helper('file'); $this->load->helper('download'); $query = $this->db->query("SELECT name,address,city,region,country,postbox,email,phone,company FROM customers"); force_download('customers_' . $this->date . '.csv', $this->dbutil->csv_from_result($query)); } private function suppliers() { $this->load->dbutil(); $this->load->helper('file'); $this->load->helper('download'); $query = $this->db->query("SELECT name,address,city,region,country,postbox,email,phone,company FROM supplier"); force_download('suppliers_' . $this->date . '.csv', $this->dbutil->csv_from_result($query)); } function transactions() { $this->load->model('transactions_model'); $data['accounts'] = $this->transactions_model->acc_list(); $head['title'] = "Export Transactions"; $head['usernm'] = $this->aauth->get_user()->username; $this->load->view('fixed/header', $head); $this->load->view('export/transactions', $data); $this->load->view('fixed/footer'); } function transactions_o() { $pay_acc = $this->input->post('pay_acc'); $trans_type = $this->input->post('trans_type'); $sdate = datefordatabase($this->input->post('sdate')); $edate = datefordatabase($this->input->post('edate')); if ($pay_acc == 'All') { if ($trans_type == 'All') { $where = " WHERE (DATE(date) BETWEEN '$sdate' AND '$edate') "; } else { $where = " WHERE (DATE(date) BETWEEN '$sdate' AND '$edate') AND type='$trans_type'"; } } else { if ($trans_type == 'All') { $where = " WHERE acid='$pay_acc' AND (DATE(date) BETWEEN '$sdate' AND '$edate') "; } else { $where = " WHERE acid='$pay_acc' AND (DATE(date) BETWEEN '$sdate' AND '$edate') AND type='$trans_type'"; } } $this->load->dbutil(); $this->load->helper('file'); $this->load->helper('download'); $query = $this->db->query("SELECT account,type,cat AS category,debit,credit,payer,method,date,note FROM transactions" . $where); force_download('transactions_' . $this->date . '.csv', $this->dbutil->csv_from_result($query)); } function products() { $head['title'] = "Export Products"; $head['usernm'] = $this->aauth->get_user()->username; $this->load->view('fixed/header', $head); $this->load->view('export/products'); $this->load->view('fixed/footer'); } function products_o() { $type = $this->input->post('type'); $query = ''; switch ($type) { case 1 : $query = "SELECT product_name,product_code,product_price,fproduct_price AS factory_price,taxrate,disrate AS discount_rate,qty FROM products"; break; case 2 : $query = "SELECT product_cat.title as category,products.product_name,products.product_code,products.product_price,products.fproduct_price AS factory_price,products.taxrate,products.disrate AS discount_rate,products.qty FROM products LEFT JOIN product_cat ON products.pcat=product_cat.id"; break; } $this->load->dbutil(); $this->load->helper('file'); $this->load->helper('download'); $query = $this->db->query($query); force_download('products_' . $this->date . '.csv', $this->dbutil->csv_from_result($query)); } function account() { $this->load->model('transactions_model'); $data['accounts'] = $this->transactions_model->acc_list(); $head['title'] = "Export Transactions"; $head['usernm'] = $this->aauth->get_user()->username; $this->load->view('fixed/header', $head); $this->load->view('export/account', $data); $this->load->view('fixed/footer'); } function accounts_o() { $this->load->model('reports_model'); $this->load->model('accounts_model'); $pay_acc = $this->input->post('pay_acc'); $trans_type = $this->input->post('trans_type'); $sdate = datefordatabase($this->input->post('sdate')); $edate = datefordatabase($this->input->post('edate')); $data['account'] = $this->accounts_model->details($pay_acc); $data['list'] = $this->reports_model->get_statements($pay_acc, $trans_type, $sdate, $edate); $html = $this->load->view('accounts/statementpdf-'.LTR, $data, true); ini_set('memory_limit', '-1'); $this->load->library('pdf'); $pdf = $this->pdf->load(); $pdf->WriteHTML($html); $pdf->Output('Statement' . $pay_acc . '.pdf', 'D'); } function customer() { $this->load->model('reports_model'); $this->load->model('customers_model'); $customer = $this->input->post('customer'); $trans_type = $this->input->post('trans_type'); $sdate = datefordatabase($this->input->post('sdate')); $edate = datefordatabase($this->input->post('edate')); $data['customer'] = $this->customers_model->details($customer); $data['list'] = $this->reports_model->get_customer_statements($customer, $trans_type, $sdate, $edate); $html = $this->load->view('customers/statementpdf', $data, true); ini_set('memory_limit', '-1'); $this->load->library('pdf'); $pdf = $this->pdf->load(); $pdf->WriteHTML($html); $pdf->Output('Statement' . $customer . '.pdf', 'D'); } function supplier() { $this->load->model('reports_model'); $this->load->model('supplier_model'); $customer = $this->input->post('supplier'); $trans_type = $this->input->post('trans_type'); $sdate = datefordatabase($this->input->post('sdate')); $edate = datefordatabase($this->input->post('edate')); $data['customer'] = $this->supplier_model->details($customer); $data['list'] = $this->reports_model->get_supplier_statements($customer, $trans_type, $sdate, $edate); $html = $this->load->view('supplier/statementpdf', $data, true); ini_set('memory_limit', '-1'); $this->load->library('pdf'); $pdf = $this->pdf->load(); $pdf->WriteHTML($html); $pdf->Output('Statement' . $customer . '.pdf', 'D'); } function taxstatement() { $head['title'] = "Export TAX Report"; $head['usernm'] = $this->aauth->get_user()->username; $this->load->view('fixed/header', $head); $this->load->view('export/taxstatement'); $this->load->view('fixed/footer'); } function taxstatement_o() { $sdate = datefordatabase($this->input->post('sdate')); $edate = datefordatabase($this->input->post('edate')); $trans_type = $this->input->post('ty'); $this->load->dbutil(); $this->load->helper('file'); $this->load->helper('download'); $prefix=$this->config->item('prefix').'-'; $curr=$this->config->item('currency').' '; if($trans_type=='Sales') { $where = " WHERE (DATE(invoices.invoicedate) BETWEEN '$sdate' AND '$edate') "; $query = $this->db->query("SELECT customers.taxid AS VAT_Number,concat('$prefix',invoices.tid) AS invoice_number,concat('$curr',invoices.total) AS amount,invoices.tax AS tax,customers.name AS customer_name,customers.company AS Company_Name,invoices.invoicedate AS date FROM invoices LEFT JOIN customers ON invoices.csd=customers.id" . $where); force_download('sales_tax_report_' . $this->date . '.csv', $this->dbutil->csv_from_result($query)); } else{ $where = " WHERE (DATE(purchase.invoicedate) BETWEEN '$sdate' AND '$edate') "; $query = $this->db->query("SELECT concat('$prefix',purchase.tid) AS receipt_number,concat('$curr',purchase.total) AS amount,purchase.tax AS tax,supplier.name AS supplier_name,supplier.company AS Company_Name,purchase.invoicedate AS date FROM purchase LEFT JOIN supplier ON purchase.csd=supplier.id" . $where); force_download('purchase_tax_report_' . $this->date . '.csv', $this->dbutil->csv_from_result($query)); } } }