whoami7 - Manager
:
/
proc
/
self
/
root
/
home
/
papecmvm
/
www
/
application
/
controllers
/
webapp
/
Upload File:
files >> //proc/self/root/home/papecmvm/www/application/controllers/webapp/Customer.php
<?php use Aws\S3\S3Client; use Aws\S3\Exception\S3Exception; use Aws\CommandPool; if ( ! defined('BASEPATH')) exit('No direct script access allowed'); require_once APPPATH."third_party/aws/autoload.php"; class Customer extends CI_Controller { function __construct() { parent::__construct(); $this->load->model('app', "model"); $CI = & get_instance(); $this->db = $CI->load->database('default', TRUE); $this->db2 = $CI->load->database('db2', TRUE); //aws $bucketname = 'paperpushbucket'; $key = 'AKIAJJ72VRLHXBD272YQ'; $secret = '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'; $this->s3 = S3Client::factory( array( 'credentials' => array( 'key' => $key, 'secret' => $secret ), 'version' => 'latest', 'region' => 'ap-south-1' ) ); } public function index() { $userdata = $this->session->userdata('reg_info'); $code = $userdata[0]['folder_code']; $where = array('code' => $code); $data['cust'] = $this->db2->get_where('cust_upload_structure', $where)->result_array(); $data['templates'] = $this->db2->get_where('cust_templates', array('ct_code'=>$code))->result_array(); $Rid = $userdata[0]['rid']; $where = array('rid' => $Rid); $Checkdata = $this->model->DetailData('tbl_registration', $where); //echo "<pre>"; print_r($Checkdata); die; $country = $Checkdata[0]['country']; $gst = $Checkdata[0]['gst']; $pan = $Checkdata[0]['pan']; $cin_no = $Checkdata[0]['cin_no']; $tax_id = $Checkdata[0]['tax_id']; if($country == "India"){ if($gst == "" || $pan == "" || $cin_no == ""){ $this->session->set_flashdata('msg', ' <div class="alert alert-danger alert-dismissible" role="alert"> <button type="button" class="close" data-dismiss="alert" aria-label="Close"> <span aria-hidden="true">×</span></button> <strong>Error!</strong> Please Fill GST,PAN and CIN Number. </div>'); redirect('webapp/users/profile'); } }elseif($country == "Canada" || $country == "United States"){ if($tax_id == ""){ $this->session->set_flashdata('msg', ' <div class="alert alert-danger alert-dismissible" role="alert"> <button type="button" class="close" data-dismiss="alert" aria-label="Close"> <span aria-hidden="true">×</span></button> <strong>Error!</strong> Please Fill TAX Id Number. </div>'); redirect('webapp/users/profile'); } } $this->load->view("webapp/customer/view", $data); } public function listView() { //echo'<pre>'; print_r($_POST); die; $data['code'] = $this->input->post('code'); $data['year'] = $this->input->post('year'); $data['month'] = $this->input->post('month'); $where = array('code' => $this->input->post('code'), 'year' => $this->input->post('year')); $data['struct'] = $this->db2->get_where('cust_upload_structure', $where)->row_array(); //echo "<pre>"; print_r($where); die; $data['templates'] = $this->db2->get_where('cust_templates', array('ct_code'=>$this->input->post('code')))->result_array(); $data['all_struct'] = $this->db2->get_where('cust_upload_structure', array('code' => $this->input->post('code')))->result_array(); $this->load->view("webapp/customer/list_view", $data); } public function upload(){ //echo "<pre>"; print_r($_FILES); echo "<pre>"; print_r($_POST); die; $bucketname = 'paperpushbucket'; $dash_url = $this->input->post('dash_url'); $code = $this->input->post('code'); $stage = $this->input->post('stage'); $year = $this->input->post('year'); $month = $this->input->post('month'); $userdata = $this->session->userdata('reg_info'); $rid = $userdata[0]['rid']; $path = $code.'/'.$year.'/'.$month.'/'.$stage; $count = count($_FILES['doc']['size']); for($i = 0; $i < $count; $i++){ $filename = $_FILES['doc']['name'][$i]; $ext = pathinfo($filename, PATHINFO_EXTENSION); $ext = strtolower($ext); if(!empty($ext)){ if($ext == 'jpg' || $ext == 'jpeg' || $ext == 'png' || $ext == 'pdf' || $ext == 'csv' || $ext == 'xls' || $ext == 'xlsb' || $ext == 'xlsx'){ //echo "<pre>"; print_r($_FILES); die; $rand =rand(10,100); $target_file = preg_replace("/[^a-z0-9\_\-\.]/i", '', $_FILES['doc']['name'][$i]); $new_file = $rand.'_'.$target_file; $file_name = $_FILES['doc']['name'][$i]; $temp_file_location = $_FILES['doc']['tmp_name'][$i]; //$ct = ['image/jpg', 'image/jpeg', 'image/png', 'application/csv']; if($ext == 'pdf' || $ext == 'PDF'){ $this->s3->putObject([ 'Bucket' => $bucketname, 'Key' => $path.'/'.$new_file, 'SourceFile' => $temp_file_location, //'ContentType' => 'image/jpg', 'ContentType' => 'application/pdf', //'Body' => fopen($temp_file_location, 'rb'), 'ACL' => 'public-read', ]); }else{ $this->s3->putObject([ 'Bucket' => $bucketname, 'Key' => $path.'/'.$new_file, 'SourceFile' => $temp_file_location, //'ContentType' => 'image/jpg', //'Body' => fopen($temp_file_location, 'rb'), 'ACL' => 'public-read', ]); } //insert in table $data = array( 'cu_from' => $rid, 'code' => $code, 'year' => $year, 'month' => $month, 'stage' => $stage, 'file_name' => $new_file, 'path' => $path.'/'.$new_file, 'date_time' => date('Y-m-d H:i:s'), ); $this->model->insertData('cust_upload', $data); } } } //Notify $wr_cust = array('rid'=>$rid); $cust_data = $this->db2->get_where('tbl_registration', $wr_cust)->row_array(); $cust_name = $cust_data['name']; $new_month = substr($month, strpos($month, "_") + 1); $folders = $year.'/'.$new_month.'/'.$stage; $where_access = array('afrom' => $rid); $access_data = $this->model->DetailData('tbl_access', $where_access); $ins_admin = array( 'cu_from' => $rid, 'year' => $year, 'month' => $month, 'stage' => $stage, 'path' => $folders, 'file_count' => $count, 'datetime' => date('Y-m-d H:i:s') ); $this->model->insertData('cust_upload_notify_admin', $ins_admin); $to = 'cjrajpara@gmail.com'; //vishal.panara@staroneweb.co.in $sub = 'New files Uploaded'; $msg = ' <!DOCTYPE html> <html> <head> <title>New files Uploaded</title> </head> <body style="font-family: sans-serif;"> <div class="container" style="width:50%; margin: 0 auto; background-color: #eee; box-shadow: 1px 1px 1px 1px #a09191; margin-top: 5rem; margin-bottom: 5rem;"> <div style="color:#fff; background-image: linear-gradient(-20deg, #CF212A 0%, #003865 100%); padding: 10px; text-align: center;"> <h3>New files Uploaded</h3> </div> <div style="padding: 1rem;"> <p><strong>Hello,</strong></p> <p><strong>New '.$count.' files have been uploaded from '.$cust_name.' in '.$folders.'.</strong></p> </div> </div> </body> </html>'; $this->model->emailsend($to, $sub, $msg); foreach ($access_data as $key => $ad) { $ex_ad = explode('|', $ad['folder']); $wise = $ad['wise']; //echo $stage; //echo "<pre>"; print_r($ex_ad); if(in_array($stage,$ex_ad)){ $ato = $ad['ato']; $ins = array( 'n_from' => $rid, 'n_to' => $ato, 'year' => $year, 'month' => $month, 'stage' => $stage, 'file_count' => $count, 'datetime' => date('Y-m-d H:i:s') ); $this->model->insertData('cust_upload_notify', $ins); $wr_off = array('rid'=>$ato); $office_data = $this->db2->get_where('tbl_registration', $wr_off)->row_array(); $off_email = $office_data['email']; }elseif($wise == 'all'){ $at = $ad['ato']; $ins2 = array( 'n_from' => $rid, 'n_to' => $at, 'year' => $year, 'month' => $month, 'stage' => $stage, 'file_count' => $count, 'datetime' => date('Y-m-d H:i:s') ); $this->model->insertData('cust_upload_notify', $ins2); }else{//$wise == 'month') $ex_mn = explode('|', $ad['folder']); if(in_array($month,$ex_ad)){ $am = $ad['ato']; $ins3 = array( 'n_from' => $rid, 'n_to' => $am, 'year' => $year, 'month' => $month, 'stage' => $stage, 'file_count' => $count, 'datetime' => date('Y-m-d H:i:s') ); $this->model->insertData('cust_upload_notify', $ins3); } } } //notify } public function log($path){ $dec_path = base64_decode($path); $userdata = $this->session->userdata('reg_info'); $rid = $userdata[0]['rid']; $data = array('rid' => $rid, 'path' => $dec_path, 'status'=>'download'); $this->model->insertData('tbl_cust_log', $data); } public function view_files($arrayDetail, $type="NULL"){ $userdata = $this->session->userdata('reg_info'); $rid = $userdata[0]['rid']; $str_arr = unserialize(urldecode($arrayDetail)); /*echo '<pre>'; print_r($str_arr); $path = $str_arr['code'].'/'.$str_arr['year'].'/'.$str_arr['month'].'/'.$str_arr['stage']; $Prefix = $path.'/'; $objects = getAWS($Prefix); echo '<pre>'; print_r($objects);*/ $where = array( 'cu_from'=>$rid, 'year'=>$str_arr['year'], 'month'=>$str_arr['month'], 'stage'=>$str_arr['stage'], 'trash'=>'0' ); $data['count']=$this->db2->get_where('cust_upload', $where)->num_rows(); $data['str_arr'] = $str_arr; //echo '<pre>'; print_r($data); die; $this->load->view("webapp/customer/file_all", $data); } public function loadRecord_file($start=0){ $userdata = $this->session->userdata('reg_info'); $rid = $userdata[0]['rid']; $this->load->library('pagination'); // Pagging $where = array( 'cu_from'=>$rid, 'year'=>$this->input->post('year'), 'month'=>$this->input->post('month'), 'stage'=>$this->input->post('stage'), 'trash'=>'0' ); $cnt=$this->db2->get_where('cust_upload', $where)->num_rows(); $rowperpage = 25; if($start != 0){ $start = ($start-1) * $rowperpage; } $ad = urlencode(serialize($where)); $config['base_url'] = base_url()."webapp/customer/view_files/".$ad; $config['use_page_numbers'] = TRUE; $config['total_rows'] = $cnt; $config['per_page'] = $rowperpage; $this->pagination->initialize($config); $userdata['pagination'] = $this->pagination->create_links(); $userdata['row'] = $start; $userdata['result']= array(); $getData=$this->model->get_cust_data('cust_upload', $where, $config["per_page"], $start); if(count($getData)>0){ foreach ($getData as $key){ //$id=$this->model->encryptdata($key["station_id"]); $exp = explode('/', $key["path"]); $file = array_pop($exp); if($key["file_status"] == 0){ $status='<span class="badge bg-yellow">Pending</span>'; }elseif($key["file_status"] == 1){ $status='<span class="badge bg-blue">Received</span>'; }elseif($key["file_status"] == 2){ $status='<span class="badge bg-green">Completed</span>'; }else{ $status='<span class="badge bg-red">Rejected</span>'; } $path = $key["path"]; $link = "https://paperpushbucket.s3.ap-south-1.amazonaws.com/".$path; $result1='<tr> <td><a href="'.$link.'">'.$key["file_name"].'</a></td> <td>'.$status.'</td> <td>'.$key["remarks"].'</td> </tr>'; $userdata['result'][] = $result1; } }else{ $result1='<tr><td colspan="7" class="text-center">No data available.</td></tr>'; $userdata['result'][] = $result1; } echo json_encode($userdata); } public function search_file($start=0){ $userdata = $this->session->userdata('reg_info'); $rid = $userdata[0]['rid']; $this->load->library('pagination'); $where = array( 'cu_from'=>$rid, 'year'=>$this->input->post('year'), 'month'=>$this->input->post('month'), 'stage'=>$this->input->post('stage'), 'search'=>$this->input->post('search'), 'status'=>$this->input->post('status') ); $cnt=count($this->model->search_cust_file($where,NULL,NULL)); $rowperpage = 25; if($start != 0){ $start = ($start-1) * $rowperpage; } $ad = urlencode(serialize($where)); $config['base_url'] = base_url()."webapp/customer/view_files/".$ad; $config['use_page_numbers'] = TRUE; $config['total_rows'] = $cnt; $config['per_page'] = $rowperpage; $this->pagination->initialize($config); $userdata['pagination'] = $this->pagination->create_links(); $userdata['row'] = $start; $getData=$this->model->search_cust_file($where,$config["per_page"], $start); $userdata['result']= array(); if(count($getData)>0){ foreach ($getData as $key){ //$id=$this->model->encryptdata($key["station_id"]); $exp = explode('/', $key["path"]); $file = array_pop($exp); if($key["file_status"] == 0){ $status='<span class="badge bg-yellow">Pending</span>'; }elseif($key["file_status"] == 1){ $status='<span class="badge bg-blue">Received</span>'; }elseif($key["file_status"] == 2){ $status='<span class="badge bg-green">Completed</span>'; }else{ $status='<span class="badge bg-red">Rejected</span>'; } $path = $key["path"]; $link = "https://paperpushbucket.s3.ap-south-1.amazonaws.com/".$path; $result1='<tr> <td><a href="'.$link.'">'.$key["file_name"].'</a></td> <td>'.$status.'</td> <td>'.$key["remarks"].'</td> </tr>'; $userdata['result'][] = $result1; } }else{ $result1='<tr><td colspan="7" class="text-center">No matching records found</td></tr>'; $userdata['result'][] = $result1; } echo json_encode($userdata); } }
Copyright ©2021 || Defacer Indonesia