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/leo/application/plugins/module_imobles/controllers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/lrsys/www/lrsys_apps/leo/application/plugins/module_imobles/controllers/UnityController.php
<?php

include_once "Controller.php";
include_once __DIR__ . "/../models/UnityModel.php";
include_once __DIR__ . "/../models/TypeunityModel.php";
include_once __DIR__ . "/../models/EnterprisesModel.php";
include_once __DIR__ . "/../assets/libs/Helper.php";
include_once __DIR__ . "/../helpers/console/UnitTypeUpdate.php";

class UnityController extends Controller {

    protected $id;
    protected $model;

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

        $this->ui->assign('_title', $this->_L['module imobles unity'] . ' - ' . $this->config['CompanyName']);
        $this->ui->assign('_st', $_L['module imobles']);

        $this->model = new UnityModel();

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

    public function listAll() 
    {
        @ini_set('memory_limit', '40095M');
        @ini_set('max_execution_time', 0);
        @set_time_limit(0);
        $where = '';
        $filter['items_per_page'] = 10;
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            $filter['search'] = filter_var(_post('search'), FILTER_SANITIZE_STRING);
            $filter['module_imobles_enterprise_id'] = filter_var(_post('module_imobles_enterprise_id'), FILTER_SANITIZE_STRING);
            $filter['module_imobles_unity_type_id'] = filter_var(_post('module_imobles_unity_type_id'), FILTER_SANITIZE_STRING);
            $filter['unavailable'] = filter_var(_post('unavailable'), FILTER_SANITIZE_STRING);
//            $amenities = empty($_POST['module_imobles_units_amenities']) ? "" : implode(",", $_POST['module_imobles_units_amenities']);
//            $filter['module_imobles_units_amenities'] = filter_var($amenities, FILTER_SANITIZE_STRING);
//
//            $filter['city_id'] = filter_var(_post('city_id'), FILTER_SANITIZE_STRING);
//            $filter['neighborhoods'] = filter_var(_post('neighborhoods'), FILTER_SANITIZE_STRING);
//            $filter['module_imobles_enterprise_unity_standard_id'] = filter_var(_post('module_imobles_enterprise_unity_standard_id'), FILTER_SANITIZE_STRING);
            $filter['items_per_page'] = filter_var(_post('items_per_page'), FILTER_SANITIZE_STRING);
            if (isset($_SESSION['filter']['module_imobles/unity/listAll'])) {
                $filter['module_imobles_unity_type_id'] = $_SESSION['filter']['module_imobles/unity/listAll'];
            }
        } else {
            unset($_SESSION['filter']['module_imobles/unity/listAll']);
            if ($i = array_search('enterprise_id', $this->routes))
                $filter['module_imobles_enterprise_id'] = filter_var($this->routes[$i + 1], FILTER_SANITIZE_STRING);
//            if ($i = array_search('module_imobles_units_amenities', $this->routes))
//                $filter['module_imobles_units_amenities'] = filter_var($this->routes[$i + 1], FILTER_SANITIZE_STRING);
            if ($i = array_search('unavailable', $this->routes))
                $filter['unavailable'] = filter_var($this->routes[$i + 1], FILTER_SANITIZE_STRING);

//            if ($i = array_search('status', $this->routes))
//                $filter['status'] = filter_var($this->routes[$i + 1], FILTER_SANITIZE_STRING);
//            if ($i = array_search('city_id', $this->routes))
//                $filter['city_id'] = filter_var($this->routes[$i + 1], FILTER_SANITIZE_STRING);
//            if ($i = array_search('neighborhoods', $this->routes))
//                $filter['neighborhoods'] = filter_var($this->routes[$i + 1], FILTER_SANITIZE_STRING);
//            if ($i = array_search('module_imobles_enterprise_unity_standard_id', $this->routes))
//                $filter['module_imobles_enterprise_unity_standard_id'] = filter_var($this->routes[$i + 1], FILTER_SANITIZE_STRING);
            if ($i = array_search('items_per_page', $this->routes))
                $filter['items_per_page'] = filter_var($this->routes[$i + 1], FILTER_SANITIZE_STRING);

            if ($i = array_search('unity_type_id', $this->routes)) {
                $filter['module_imobles_unity_type_id'] = filter_var($this->routes[$i + 1], FILTER_SANITIZE_STRING);
                $_SESSION['filter']['module_imobles/unity/listAll'] = $filter['module_imobles_unity_type_id'];
            }
        }

        if (!empty($this->routes[3]) && (!isset($this->routes[4]) || empty($this->routes[4]))) {
            $filter['module_imobles_unity_type_id'] = $this->routes[3];
            $_SESSION['filter']['module_imobles/unity/listAll'] = $this->routes[3];
            $this->routes[3] = 0;
        }        
        if (!empty($filter['module_imobles_unity_type_id'])) {
            $where .= " AND u.module_imobles_enterprise_units_type_id =" . htmlentities($filter['module_imobles_unity_type_id']);
            $stModel = new TypeunityModel();
            $c = $stModel->getOne($filter['module_imobles_unity_type_id']);
            $this->ui->assign('module_imobles_typeunit', $c);
        }

//        if (!empty($filter['search'])) {
//            $where .= " AND (e.name  LIKE '%" . ($filter['search']) . "%' or "
//                    . " co.name  LIKE '%" . ($filter['search']) . "%' )";
//        }
//        $idEnterprise = isset($this->routes[3]) ? $this->routes[3] : "";
//        if (!empty($idEnterprise)) {
//            $filter['module_imobles_enterprise_id'] = $idEnterprise;
//        }
//        if (!empty($filter['city_id'])) {
//            $where .= " AND     e.address_city_id ='" . htmlentities($filter['city_id']) . "'";
//            $city = ORM::for_table('city')
//                            ->table_alias('s')
//                            ->select("st.uf_state")
//                            ->select("s.city_name")
//                            ->select("s.id")
//                            ->join('state', 's.id_state = st.id', 'st')
//                            ->where('s.id', $filter['city_id'])
//                            ->find_many()->limit(1);
//            $this->ui->assign('city', $city[0]);
//        }
//
//        if (!empty($filter['neighborhoods'])) {
//            $where .= " AND e.address_neightborhood like '%" . htmlentities($filter['neighborhoods']) . "%'";
//            $this->ui->assign('neighborhood', $filter['neighborhoods']);
//        }
//
//        if (!empty($filter['module_imobles_enterprise_standard_id'])) {
//            $where .= " AND e.module_imobles_enterprise_standard_id ='" . htmlentities($filter['module_imobles_enterprise_standard_id']) . "'";
//
//            $stModel = new Enterprise_standardModel();
//            $c = $stModel->getOne($filter['module_imobles_enterprise_standard_id']);
//            $this->ui->assign('enterprise_unity_standard', $c);
//        }
        if (!isset($filter['unavailable'])) {
            $filter['unavailable'] = 'all';
        }

        if (@$filter['unavailable'] != 'all') {
            if ($filter['unavailable'] == 1) {
                $where .= " AND (u.unavailable  =" . ($filter['unavailable']) . " )";
            } else if ($filter['unavailable'] == 2) {
                $where .= " AND (u.unavailable  = 0 or u.unavailable is null )";
            }
        }
        
        // Pego apenas as unidades dos NOVOS
        $where .= " AND u.verified = 1 ";
        
        if (!empty($filter['module_imobles_enterprise_id'])) {
            $where .= " AND e.id ='" . htmlentities($filter['module_imobles_enterprise_id']) . "'";

            $stModel = new EnterprisesModel();
            $c = $stModel->getOne($filter['module_imobles_enterprise_id']);
            $this->ui->assign('module_imobles_enterprise', $c);
        }

        $module_imobles_units_amenities = '';
        if (isset($filter['module_imobles_units_amenities']) && $filter['module_imobles_units_amenities'] != '') {
            $where .= " AND u.id in (select sub.module_imobles_enterprise_units_id from module_imobles_enterprise_units_amenities sub where sub.module_imobles_units_amenities_id IN (" . $filter['module_imobles_units_amenities'] . "))";
            $amen = ORM::for_table('module_imobles_units_amenities')->where_raw("id IN (" . $filter['module_imobles_units_amenities'] . ")")->find_many();
            if (count($amen) > 0) {
                foreach ($amen as $c) {
                    $module_imobles_units_amenities .= '<option value="' . $c->id . '" selected >' . $c->name . '</option>';
                }
            }
        }
        $this->ui->assign('module_imobles_units_amenities', $module_imobles_units_amenities);


        $sql = ' FROM module_imobles_enterprise e'
                . ' JOIN module_imobles_enterprise_units_type ut ON (ut.module_imobles_enterprise_id=e.id)'
                . ' JOIN module_imobles_enterprise_units u ON (u.module_imobles_enterprise_units_type_id=ut.id)'
                . ' JOIN module_imobles_listings lt ON (u.id=lt.unit_id)'
                . ' LEFT JOIN city c ON(e.address_city_id=c.id)'
                . ' LEFT JOIN module_imobles_company_construction co ON(co.id=e.module_imobles_company_construction_id)'
                . ' LEFT JOIN module_imobles_enterprise_standard s ON(s.id=e.module_imobles_enterprise_standard_id)'
                . ' LEFT JOIN module_imobles_enterprise_towers et ON(et.id=u.module_imobles_enterprise_towers_id)'
                . ' WHERE u.delete_at IS NULL AND e.delete_at IS NULL AND u.crawler_type_id = 4 ' . $where;

        $order = ' order by et.date_delivery desc';
        if ($filter['items_per_page'] != 'all')
            $filter['items_per_page'] = ($filter['items_per_page'] > 0) ? $filter['items_per_page'] : 10;

        $page = isset($this->routes['3']) ? $this->routes['3'] : 1;
        
        $sqlTotal = "select count(e.id) as total, SUM(IF(u.unavailable=1, 1, 0)) as unavailable " . $sql;
        $dg = ORM::for_table('module_imobles_enterprise_unity')->raw_query($sqlTotal)->find_many();
        $bottomBar = array(
            array('type' => 'int', 'info' => $this->_L['module imobles unity_Qty'], 'value' => $dg[0]['total'] ),
            array('type' => 'int', 'info' => $this->_L['module imobles unity_Qty disponible'], 'value' => $dg[0]['total'] - $dg[0]['unavailable']),
            array('type' => 'int', 'info' => $this->_L['module imobles unity_Qty indisponible'], 'value' => $dg[0]['unavailable']),
        );

        $paginator = new ModulePaginator('module_imobles_enterprise_unity', "Select ut.area, ut.number_rooms, ut.number_garage, ut.number_bathroom, ut.number_suite, u.garage_covered, "
                                    . "lt.crawler_price as unit_price, e.* ,u.amount,u.unavailable,ut.title as title_unity_type, c.city_name,"
                                    . "s.name as desc_entreprise_standard,u.floor,u.number_unity,u.id as unity_id,et.date_delivery" . $sql . $order, $filter);
        $records = $paginator->setItemsPerPage($filter['items_per_page'])
                ->setCurrentPageNumber($page)
                ->setTotalItems($dg[0]['total'])
                ->run();

        $css_arr = array('/../../../application/plugins/module_imobles/assets/css/default', 's2/css/select2.min');

        $js_arr = array(
            '/../../../application/plugins/module_imobles/assets/js/unity-list', 's2/js/select2.min'
        );

        $assets_css = Asset::css($css_arr, date("Y-m-d"));
        $assets_js = Asset::js($js_arr, date("Y-m-d"));

        $this->ui->assign('xheader', $assets_css);
        $this->ui->assign('xfooter', $assets_js);
        $this->ui->assign('unity', $records);
        $this->ui->assign('paginator', $paginator);
        $this->ui->assign('filter', $filter);
        $this->ui->assign('bottomBar', $bottomBar);
        $this->ui->assign('_st', $this->_L['module imobles unity']);
        $this->ui->assign('_include', 'unity/list');
        $this->ui->display('wrapper.tpl');
    }

    public function add() {
        // CARREGA CSS E JS'S
        $css_arr = array('s2/css/select2.min', 'dp/dist/datepicker.min',
            'ibilling/clockpicker/clockpicker', 'modal');

        $js_arr = array('modal',
            'dp/dist/datepicker.min',
            '/../../theme/lrsys/lib/jquery.maskMoney.min',
            'ibilling/clockpicker/clockpicker',
            's2/js/select2.min', 's2/js/i18n/' . lan(),
            '/../../../application/plugins/module_imobles/assets/js/unity-form',
        );
//
        $assets_css = Asset::css($css_arr, date("Y-m-d"));
        $assets_js = Asset::js($js_arr, date("Y-m-d"));
        $this->ui->assign('xheader', $assets_css);
        $this->ui->assign('xfooter', $assets_js);
        $this->ui->assign('xfooter', $assets_js);
        $this->ui->assign('rowNumTowers', 0);
        $this->ui->assign('enterprise_unityTorers', array());

        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            $helper = new Helper();
            $enterpriseID = filter_var(_post('enterprise_id'), FILTER_SANITIZE_STRING);
            $towerAlias = $helper->replaceAscii(mb_strtoupper(filter_var(_post('tower'), FILTER_SANITIZE_STRING), 'UTF-8'));
            $unitNumber = filter_var(_post('unit_number'), FILTER_SANITIZE_STRING);
            $available = filter_var(_post('available'), FILTER_SANITIZE_STRING);
            $floor = filter_var(_post('floor'), FILTER_SANITIZE_STRING);
            $value = Finance::amount_fix(filter_var(_post('value'), FILTER_SANITIZE_STRING));
            $unitTypeID = filter_var(_post('unit_type_id'), FILTER_SANITIZE_STRING);

            $unit = array(
                "name" => "",
                "alias" => "",
                "desc" => "",
                "amount" => number_format($value, 2, ',', '.') ,
                "disponible" => $available,
                "floor" => $floor,
                "number_unity" => $unitNumber,
                "dwv_id" => ""
            );

            if($unitTypeID != ''){
                $modelTypeUnit = new TypeunityModel();
                $typeunitys = ORM::for_table($modelTypeUnit->table)
                    ->where('module_imobles_enterprise_id', $enterpriseID)
                    ->where('id', $unitTypeID)
                    ->find_one();
                $this->ui->assign('module_imobles_enterprise_units_type', $typeunitys);
            }

            if ($towerAlias != ''){
                $c = ORM::for_table('module_imobles_enterprise_towers')
                    ->table_alias('s')
                    ->where('module_imobles_enterprise_id', $enterpriseID)
                    ->where('alias', $towerAlias)
                    ->find_one();
                $this->ui->assign('module_imobles_enterprise_towers', $c);
            }

        } else {
            $unit = array(
                "name" => "",
                "alias" => "",
                "desc" => "",
                "amount" => "",
                "disponible" => "0",
                "floor" => "",
                "number_unity" => "",
                "dwv_id" => ""
            );
        }
        $this->ui->assign('unity', json_decode(json_encode($unit)));

        

        $this->ui->assign('typeForm', 'window');

        $this->ui->assign('_st', $this->_L['module imobles unity']);
        $this->ui->assign('_include', 'unity/add');
        $this->ui->display('wrapper.tpl');
    }

    /**
     * Insert add to status diary
     */
    public function post() {
        try {
            $data = $_POST;
            $msg = '';
            if (empty(_post('module_imobles_enterprise_units_type_id'))) {
                $msg .= $this->_L['module imobles typeunity'] . $this->_L['is required'];
            }
            if (empty(_post('number_unity'))) {
                $msg .= $this->_L['module imobles unity number_unity'] . $this->_L['is required'];
            }

            if(!empty($data['disponible']) && $data['disponible'] == 1){
                $data['unavailable'] = 0;
            } else {
                $data['unavailable'] = 1;
            }

            if (empty($msg)) {
                $modelTypeUnit = new TypeunityModel();
                $helper = new Helper();
                $typeunitys = $modelTypeUnit->getOne($data['module_imobles_enterprise_units_type_id']);
                $data['alias'] = mb_strtoupper($helper->replaceAscii(@$typeunitys['alias'] . $data['number_unity']), 'UTF-8');
                $updateTypeUnit = false;
                if (isset($data['id']) && $data['id'] > 0) {
                    $unity = $this->model->getOne($data['id']);

                    if ($unity->amount != $data['amount'] || $unity->unavailable != $data['unavailable']){
                        $updateTypeUnit = true;
                    }

                    $unity = $this->model->updateEnterprise_unity($data, $unity);
                    $this->model->updateListingPrice($unity, $data['amount']);
                    _notify($this->_L['module imobles unity'] . " " . $this->_L['Edited Successfull'], 's');
                } else {
                    $data['crawler_type_id'] = 4;
                    $unity = $this->model->createEnterprise_unity($data);
                    $unity->verified = true;
                    $unity->save();
                    $this->model->createUnityListing($unity, $data['amount']);
                    _notify($this->_L['module imobles unity'] . " " . $this->_L['Add Successfull'], 's');
                    $updateTypeUnit = true;
                }
                $msg = "OK";
                if ($updateTypeUnit){
                    $unitTypeUpdate = new UnitTypeUpdate();
                    ob_start();
                    $unitTypeUpdate->SetSearchablesUnitTypes([$typeunitys->id]);                    
                    $response = ob_get_contents();
                    ob_end_clean();
                }
            }
        } catch (Exception $ex) {
            echo ($ex->getMessage());
        }
        echo $msg;
    }

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

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

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

        if (!$unity) {
            die($this->_L['Not_Found']);
        }

        if($unity->unavailable == 0){
            $unity->disponible = 1;
        } else {
            $unity->disponible = 0;
        }

        $sql = "SELECT lp.price FROM module_imobles_listings l "
             . "LEFT JOIN module_imobles_listings_prices lp on l.id = lp.listing_id "
             . "WHERE l.crawler_type_id = 4 and l.unit_id = " .$unity->id . " "
             . "ORDER by lp.date desc LIMIT 1";

        $listingPrice = ORM::for_table('module_imobles_listings_price')->raw_query($sql)->find_one();
        
        if (!empty($listingPrice->price)) {
            $unity->amount = $listingPrice->price;
        }

        $css_arr = array('s2/css/select2.min', 'dp/dist/datepicker.min',
            'ibilling/clockpicker/clockpicker', 'modal');

        $js_arr = array('modal',
            'dp/dist/datepicker.min',
            '/../../theme/lrsys/lib/jquery.maskMoney.min',
            'ibilling/clockpicker/clockpicker',
            's2/js/select2.min', 's2/js/i18n/' . lan(),
            '/../../../application/plugins/module_imobles/assets/js/unity-form',
        );
//
        $assets_css = Asset::css($css_arr, "20201204");
        $assets_js = Asset::js($js_arr, "20201204");
        $this->ui->assign('xheader', $assets_css);
        $this->ui->assign('xfooter', $assets_js);


        $this->ui->assign('unity', $unity);




        //
        $modelTypeUnit = new TypeunityModel();
        $typeunitys = $modelTypeUnit->getOne($unity->module_imobles_enterprise_units_type_id);
        $this->ui->assign('module_imobles_enterprise_units_type', $typeunitys);


        $c = ORM::for_table('module_imobles_enterprise_towers')
                ->table_alias('s')
                ->find_one($unity->module_imobles_enterprise_towers_id);
        $this->ui->assign('module_imobles_enterprise_towers', $c);


        $c = ORM::for_table('module_imobles_enterprise_units_amenities')
                ->table_alias('s')
                ->select("sub.*")
                ->join('module_imobles_units_amenities', 's.module_imobles_units_amenities_id = sub.id', 'sub')
                ->where('s.module_imobles_enterprise_units_id', $unity->id)
                ->find_many();
        $this->ui->assign('module_imobles_enterprise_units_amenities', $c);



        $this->ui->assign('typeForm', 'window');

        $this->ui->assign('_include', 'unity/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']);
        }

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

        if (!$unity) {
            die($this->_L['Not_Found']);
        }

        $this->ui->assign('unity', $unity);


        $modelTypeUnit = new TypeunityModel();
        $typeunitys = $modelTypeUnit->getOne($unity->module_imobles_enterprise_units_type_id);
        $this->ui->assign('module_imobles_enterprise_units_type', $typeunitys);


        $c = ORM::for_table('module_imobles_enterprise_towers')
                ->table_alias('s')
                ->find_one($unity->module_imobles_enterprise_towers_id);
        $this->ui->assign('module_imobles_enterprise_towers', $c);


        $c = ORM::for_table('module_imobles_enterprise_units_amenities')
                ->table_alias('s')
                ->select("sub.*")
                ->join('module_imobles_units_amenities', 's.module_imobles_units_amenities_id = sub.id', 'sub')
                ->where('s.module_imobles_enterprise_units_id', $unity->id)
                ->find_many();
        $this->ui->assign('module_imobles_enterprise_units_amenities', $c);



        $this->ui->assign('typeForm', 'window');

        $this->ui->assign('_include', 'unity/view');
        $this->ui->display('wrapper.tpl');
    }

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

        $this->model->deleteEnterprise_unity($status);
        r2(U . 'module_imobles/unity/listall', 's', $this->_L['delete_successful']);
    }

    public function import_csv() {
        $css_arr = array('dropzone/dropzone');
        $js_arr = array('dropzone/dropzone',
            '/../../../application/plugins/module_imobles/assets/js/import-unity',
        );

        $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('_st', $this->_L['Import'] . " " . $this->_L['module imobles unity']);
        $this->ui->assign('_include', 'unity/import');
        $this->ui->display('wrapper.tpl');
    }

    public function csv_upload() {

        $uploader = new Uploader();
        $uploader->setDir('application/storage/temp/');
        // $uploader->sameName(true);
        $uploader->setExtensions(array('csv'));  //allowed extensions list//
        if ($uploader->uploadFile('file')) {   //txtFile is the filebrowse element name //
            $uploaded = $uploader->getUploadName(); //get uploaded file name, renames on upload//

            $_SESSION['uploaded'] = $uploaded;
        } else {//upload failed
            _msglog('e', $uploader->getMessage()); //get upload error message
        }
    }

    public function csv_uploaded() {
        @ini_set('memory_limit', -1);
        @ini_set('max_execution_time', 0);
        @set_time_limit(0);
        
        if (isset($_SESSION['uploaded'])) {
            $uploaded = $_SESSION['uploaded'];
            $csv = new parseCSV();
            $csv->auto('application/storage/temp/' . $uploaded);
            $enterps = $csv->data;
            $cn = 0;
            $tipoUnidade = '';
            foreach ($enterps as $enterp) {
                $data = array();
                //solução para bug da primeira colna que não reconhece no array a posição
                foreach ($enterp as $value) {
                    $tipoUnidade = $value;
                    break;
                }


                $stModel = new TypeunityModel();
                $c = $stModel->getOneCollum('title', mb_strtoupper(trim($tipoUnidade), 'UTF-8'));

                if ($c) {
                    $helper = new Helper();
                    $data['module_imobles_enterprise_units_type_id'] = $c->id;
                    $data['number_unity'] = (isset($enterp['Número da Unidade'])) ? $enterp['Número da Unidade'] : '';
                    $data['alias'] = mb_strtoupper($helper->replaceAscii($c->alias . $data['number_unity']), 'UTF-8');
                    $data['desc'] = @$enterp['Descrição Unidade'];
                    $data['floor'] = (isset($enterp['Andar'])) ? $enterp['Andar'] : '';
                    $data['amount'] = (isset($enterp['Valor'])) ? $enterp['Valor'] : '';

                    if (isset($enterp['Torre']) && !empty(trim($enterp['Torre']))) {
                        $specie = ORM::for_table('module_imobles_enterprise_towers')
                                ->table_alias('s')
                                ->select("s.*")
                                ->join('module_imobles_enterprise', 's.module_imobles_enterprise_id = e.id', 'e')
                                ->join('module_imobles_enterprise_units_type', 'tu.module_imobles_enterprise_id = e.id', 'tu');

                        $specie->where_any_is(array(array("s.title" => '' . $enterp['Torre'] . '')
                                ), 'like');
                        $specie->where_in("tu.id", explode(",", $data['module_imobles_enterprise_unity_standard_id']));
                        $especies = $specie->find_many();
                        if (count($especies) > 0) {
                            $data['module_imobles_enterprise_towers_id'] = $especies[0]->id;
                        }
                    }

                    $save = $this->model->createEnterprise_unity($data);
                    if (is_numeric($save->id)) {
                        $cn++;
                    }
                }
            }
            _msglog('s', $cn . " " . $this->_L['module imobles unity Imported']);
        } else {
            _msglog('e', $this->_L['module imobles unity Imported error']);
        }
    }

    public function towers() {
        $term = _post('term');
        $typeUnity = _post('and_in');

        $specie = ORM::for_table('module_imobles_enterprise_towers')
                ->table_alias('s')
                ->select("s.*")
                ->join('module_imobles_enterprise', 's.module_imobles_enterprise_id = e.id', 'e')
                ->join('module_imobles_enterprise_units_type', 'tu.module_imobles_enterprise_id = e.id', 'tu');

        $specie->where_any_is(array(array("s.title" => '%' . $term . '%')
                ), 'like');
        $specie->where_in("tu.id", explode(",", $typeUnity));
        $especies = $specie->find_many();
        $data = array();
        foreach ($especies as $p) {
            $data[] = array(
                'id' => $p->id,
                'text' => $p->title
            );
        }

        echo json_encode($data);
    }

    public function towersUnity() {
        $id = $this->routes[3];
        $towers = ORM::for_table('module_imobles_enterprise_towers')
            ->table_alias('t')
            ->select("t.id")
            ->select("t.title")
            ->join('module_imobles_enterprise_units_type', 'ut.module_imobles_enterprise_id = t.module_imobles_enterprise_id', 'ut')
            ->where('ut.id', $id)
            ->find_many();
            $data = array();
        foreach ($towers as $t) {
            $data[] = array(
                'id' => $t->id,
                'text' => $t->title
            );
        }
        echo json_encode($data);
    }


    public function alterdisponible() {
        $status = $this->model->getOne(_post('id'));
        $status->unavailable = _post('value');
        if ($status->save()) {
            ob_start();
            $unitTypeUpdate = new UnitTypeUpdate();
            $unitTypeUpdate->SetSearchablesUnitTypes([$status->module_imobles_enterprise_units_type_id]);
            $response = ob_get_contents();
            ob_end_clean();
            echo json_encode(array("status" => "OK", 'msg' => $this->_L['Edited Successfull']));
        } else {
            echo json_encode(array("status" => "OK", 'msg' => $this->_L['module imobles error operation']));
        }
    }

}

Anon7 - 2022
AnonSec Team