|
| 1 | +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
| 2 | + |
| 3 | +/* |
| 4 | + Controller for SSTV Images |
| 5 | +*/ |
| 6 | + |
| 7 | +class Sstv extends CI_Controller { |
| 8 | + |
| 9 | + function __construct() { |
| 10 | + parent::__construct(); |
| 11 | + $this->lang->load('sstv'); |
| 12 | + $this->load->model('user_model'); |
| 13 | + if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } |
| 14 | + } |
| 15 | + |
| 16 | + public function index() { |
| 17 | + $this->load->helper('storage'); |
| 18 | + $folder_name = "assets/sstvimages"; |
| 19 | + $data['storage_used'] = sizeFormat(folderSize($folder_name)); |
| 20 | + |
| 21 | + // Render Page |
| 22 | + $data['page_title'] = "SSTV Images"; |
| 23 | + |
| 24 | + $this->load->model('sstv_model'); |
| 25 | + $data['sstvArray'] = $this->sstv_model->getQsoWithSstvImageList(); |
| 26 | + |
| 27 | + $this->load->view('interface_assets/header', $data); |
| 28 | + $this->load->view('sstv/index'); |
| 29 | + $this->load->view('interface_assets/footer'); |
| 30 | + } |
| 31 | + |
| 32 | + public function uploadSSTV() { |
| 33 | + $this->load->model('user_model'); |
| 34 | + if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } |
| 35 | + |
| 36 | + if (!file_exists('./assets/sstvimages')) { |
| 37 | + mkdir('./assets/sstvimages', 0755, true); |
| 38 | + } |
| 39 | + $qsoid = $this->input->post('qsoid'); |
| 40 | + |
| 41 | + $results = array(); |
| 42 | + if (isset($_FILES['sstvimages']) && $_FILES['sstvimages']['error'][0] == 0) |
| 43 | + { |
| 44 | + for($i=0; $i<count($_FILES['sstvimages']['name']); $i++) { |
| 45 | + $file = array( |
| 46 | + 'name' => $_FILES['sstvimages']['name'][$i], |
| 47 | + 'type' => $_FILES['sstvimages']['type'][$i], |
| 48 | + 'tmp_name' => $_FILES['sstvimages']['tmp_name'][$i], |
| 49 | + 'error' => $_FILES['sstvimages']['error'][$i], |
| 50 | + 'size' => $_FILES['sstvimages']['size'][$i] |
| 51 | + ); |
| 52 | + $result = $this->uploadSSTVImage($qsoid, $file); |
| 53 | + array_push($results, $result); |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + header("Content-type: application/json"); |
| 58 | + echo json_encode($results); |
| 59 | + } |
| 60 | + |
| 61 | + function uploadSSTVImage($qsoid, $file) { |
| 62 | + $config['upload_path'] = './assets/sstvimages'; |
| 63 | + $config['allowed_types'] = 'jpg|gif|png|jpeg|JPG|PNG|bmp'; |
| 64 | + $array = explode(".", $file['name']); |
| 65 | + $ext = end($array); |
| 66 | + $config['file_name'] = $qsoid . '.sstv.' . '_' . time() . '.' . $ext; |
| 67 | + |
| 68 | + $this->load->library('upload', $config); |
| 69 | + |
| 70 | + $_FILES['sstvimage'] = $file; |
| 71 | + if ( ! $this->upload->do_upload('sstvimage')) { |
| 72 | + // Upload of SSTV image Failed |
| 73 | + $error = array('error' => $this->upload->display_errors()); |
| 74 | + |
| 75 | + return $error; |
| 76 | + } |
| 77 | + else { |
| 78 | + // Load database queries |
| 79 | + $this->load->model('Sstv_model'); |
| 80 | + |
| 81 | + //Upload of SSTV image was successful |
| 82 | + $data = $this->upload->data(); |
| 83 | + |
| 84 | + // Now we need to insert info into database about file |
| 85 | + $filename = $data['file_name']; |
| 86 | + $insertid = $this->Sstv_model->saveSstvImages($qsoid, $filename); |
| 87 | + |
| 88 | + $result['status'] = 'Success'; |
| 89 | + $result['insertid'] = $insertid; |
| 90 | + $result['filename'] = $filename; |
| 91 | + return $result; |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + |
| 96 | + // Deletes SSTV Image |
| 97 | + public function delete() { |
| 98 | + $this->load->model('user_model'); |
| 99 | + if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } |
| 100 | + |
| 101 | + $id = $this->input->post('id'); |
| 102 | + $this->load->model('Sstv_model'); |
| 103 | + |
| 104 | + $path = './assets/sstvimages/'; |
| 105 | + $file = $this->Sstv_model->getSSTVFilename($id)->row(); |
| 106 | + $filename = $file->filename; |
| 107 | + unlink($path.$filename); |
| 108 | + |
| 109 | + $this->Sstv_model->deleteSstv($id); |
| 110 | + } |
| 111 | +} |
0 commit comments