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/AjaxController.php
<?php

include_once "Controller.php";
include_once __DIR__ . "/../controllers/TypeunityController.php";

class AjaxController extends Controller {

    /**
     * @param $ui
     * @param array $_L
     * @param array $config
     * @param $_pd
     */
    public function __construct($ui, $_L, $config, $_pd) {
        parent::__construct($ui, $_L, $config, $_pd);
    }

    public function custommer() {

        $contacts = ORM::for_table('crm_accounts')
                ->table_alias('c')
                ->select_expr('c.id, c.account,c.phone')
                ->order_by_asc('c.account');

        $contacts->join('crm_accounts_groups', array('c.id', '=', 'ag.crm_accounts_id'), 'ag')
                ->join('crm_groups', array('g.id', '=', 'ag.crm_group_id'), 'g')
                ->where_raw("UPPER(g.gname)='CUSTOMER'");


        $term = _post('term');
        if ($term != "") {
            if (@$this->routes[3] == true) {
                $contacts->where_raw("c.account LIKE '%" . $term . "%' OR  c.phone LIKE '%" . $term . "%' ");
            } else {
                $contacts->where_raw("c.account LIKE '%" . $term . "%'");
            }
        }
        $result = $contacts->find_many();
        $data = array();
        foreach ($result as $c) {
            $data[] = array(
                'id' => $c->id,
                'text' => mb_strtoupper($c->account),
            );
        }
        echo json_encode($data);
    }

    public function accounts() {

        $contacts = ORM::for_table('crm_accounts')
                ->table_alias('c')
                ->select_expr('c.id, c.account,c.phone');

        if (@$this->routes[3] == true) {
            $contacts->right_outer_join('module_imobles_hubspot_contacts', array('c.id', '=', 'd.crm_account_id'), 'd');
        }
        $contacts->group_by('c.id');
        $contacts->order_by_asc('c.account');

        $term = _post('term');
        if ($term != "") {
            if (@$this->routes[3] == true) {
                $contacts->where_raw("c.account LIKE '%" . $term . "%' OR  c.phone LIKE '%" . $term . "%' ");
            } else {
                $contacts->where_raw("c.account LIKE '%" . $term . "%'");
            }
        }
        $result = $contacts->find_many();
        $data = array();
        if (@$this->routes[3] == true) {
            foreach ($result as $c) {
                $data[] = array(
                    'id' => $c->id,
                    'text' => mb_strtoupper($c->account) . " " . (!empty($c->phone) ? " | " . $c->phone . "" : ""),
                );
            }
        } else {
            foreach ($result as $c) {
                $data[] = array(
                    'id' => $c->id,
                    'text' => mb_strtoupper($c->account),
                );
            }
        }
        echo json_encode($data);
    }

    public function crm_groups() {

        $groups = ORM::for_table('crm_groups')
                ->select_expr('id, gname')
                ->order_by_asc('gname');

        $term = _post('term');
        if ($term != "") {
            $groups->where_raw("gname LIKE '%" . $term . "%'");
        }

        $result = $groups->find_many();
        $data = array();

        foreach ($result as $g) {
            $data[] = array(
                'id' => $g->id,
                'text' => $g->gname,
            );
        }

        echo json_encode($data);
    }

    public function sellers() {
        $obj = ORM::for_table('sys_users')
                ->table_alias('s')
                ->select_expr('s.id, s.fullname, s.user_type')
                ->order_by_asc('s.fullname');

        $term = _post('term');
        if (!empty($term)) {
            $obj->where_raw("s.fullname LIKE '%" . $term . "%'");
        }
        $obj->where_not_null('username');
        $result = $obj->find_many();
        $data = array();
        $arr_role = ["SELLER SC", "SELLER GO", "SDR SC", "SDR GO"];
        foreach ($result as $c) {
            if(!in_array($c->user_type, $arr_role)){
                continue;
            }
            $data[] = array(
                'id' => $c->id,
                'text' => $c->fullname,
            );
        }
        echo json_encode($data);
    }

    public function task_category() {


        $obj = ORM::for_table('module_imobles_task_category')
                ->table_alias('s')
                ->select_expr('s.id, s.name')
                ->where_null('deleted_at')
                ->order_by_asc('s.sorder');

        $term = _post('term');
        if (!empty($term)) {
            $obj->where_raw("s.name LIKE '%" . $term . "%'");
        }

        $andIND = _post('type');
        if (!empty($andIND)) {
            $obj->where_in('s.type', explode(',', $andIND));
        }

        $result = $obj->find_many();
        $data = array();
        if (@$this->routes[3] == 'Selecione') {
            $data[] = array(
                'id' => '0',
                'text' => 'Selecione',
            );
        }
        foreach ($result as $c) {
            $data[] = array(
                'id' => $c->id,
                'text' => $c->name,
            );
        }
        echo json_encode($data);
    }

    public function task($option = '') {


        $obj = ORM::for_table('module_imobles_tasks')
                ->table_alias('s')
                ->select_expr('s.id, s.title')
                ->where_null('deleted_at')
                ->order_by_asc('s.title');

        $term = _post('term');
        if (!empty($term)) {
            $obj->where_raw("s.title LIKE '%" . $term . "%'  )");
        }

        $andIND = _post('module_imobles_task_category_id');
        if (!empty($andIND)) {
            $obj->where_in('s.module_imobles_task_category_id', explode(',', $andIND));
        }

        $result = $obj->find_many();
        $data = array();
        if (@$this->routes[3] == 'Selecione') {
            $data[] = array(
                'id' => '0',
                'text' => 'Selecione',
            );
        }

        foreach ($result as $c) {
            $data[] = array(
                'id' => $c->id,
                'text' => $c->title,
            );
        }
        echo json_encode($data);
    }

    public function neighborhood() {
        $neighborhood = ORM::for_table('module_imobles_neighborhoods')
                ->table_alias('s')
                ->select_expr('s.id, s.name')
                ->order_by_asc('s.name');

        $term = _post('term');
        if (!empty($term)) {
            $neighborhood->where_raw("s.name LIKE '%" . $term . "%'");
        }
        $notIN = _post('notin');
        $neighborhood->where_not_in('s.id', explode(',', $notIN));

        $result = $neighborhood->find_many();
        $data = array();
        foreach ($result as $c) {
            $data[] = array(
                'id' => $c->id,
                'text' => $c->name,
            );
        }
        echo json_encode($data);
    }

    public function reorder_post() {
        $action = $_POST['action'];
        $updateRecordsArray = $_POST['recordsArray'];

        $listingCounter = 1;
        foreach ($updateRecordsArray as $recordIDValue) {
            $d = ORM::for_table($action)->find_one($recordIDValue);
            $d->sorder = $listingCounter;
            $d->save();
            $listingCounter = $listingCounter + 1;
        }

        echo '<div class="alert alert-success alert-dismissible" role="alert">
  <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
 ' . $this->_L[' <strong>Success!</strong> New Positions are updated in database'] . '
</div>';
    }

    public function enterprise_standard() {
        $term = _post('term');
        $specie = ORM::for_table('module_imobles_enterprise_standard')
                ->table_alias('s');
        $specie->where_any_is(array(array("s.name" => '%' . $term . '%')
                ), 'like');
        $especies = $specie->find_many();
        $data = array();
        foreach ($especies as $p) {
            $data[] = array(
                'id' => $p->id,
                'text' => $p->name
            );
        }

        echo json_encode($data);
    }

    public function enterprises() {
        $term = _post('term');
        $specie = ORM::for_table('module_imobles_enterprise')
                ->table_alias('s')
                ->left_outer_join('city', array('s.address_city_id', '=', 'c.id'), 'c');
        $specie->select_expr("s.alias, s.id, s.name, s.address_neightborhood, c.city_name");
        $specie->where_any_is(array(array("s.name" => '%' . $term . '%'),
            array("s.alias" => '%' . $term . '%')
                ), 'like');
        $specie->where_raw("s.delete_at IS NULL");
        $especies = $specie->find_many();
        $data = array();
        foreach ($especies as $p) {
            $data[] = array(
                'id' => $p->id,
                'text' => "$p->name ( $p->city_name - $p->address_neightborhood )"
            );
        }
        echo json_encode($data);
    }

    public function unity_types() {
        if (@$this->routes[3] == true) {
            $enterprise_id = @$this->routes[3];
        }
        $term = _post('term');
        $specie = ORM::for_table('module_imobles_enterprise_units_type')
                ->table_alias('s');
        $specie->select_expr("s.id, s.title");
        $specie->where_any_is(array(array("s.title" => '%' . $term . '%')), 'like');
        $specie->where_raw("s.delete_at IS NULL");
        if ($enterprise_id != 'null') {
            $specie->where('module_imobles_enterprise_id', $enterprise_id);
        }
        $especies = $specie->find_many();
        $data = array();
        foreach ($especies as $p) {
            $data[] = array(
                'id' => $p->id,
                'text' => $p->title
            );
        }
        echo json_encode($data);
    }

    public function crawler() {
        $term = _post('term');
        $specie = ORM::for_table('module_imobles_crawler_types')
                ->table_alias('s');
        $specie->select_expr("s.id, s.name");
        $specie->where_any_is(array(array("s.name" => '%' . $term . '%'),
                ), 'like');
        $specie->where_raw("s.deleted_at IS NULL");
        $especies = $specie->find_many();
        $data = array();
        foreach ($especies as $p) {
            $data[] = array(
                'id' => $p->id,
                'text' => $p->name
            );
        }
        echo json_encode($data);
    }

    public function enterprises_address_listing() {
        $term = _post('term');
        $form = ($_POST['form']);
        $haveListing = @$this->routes[3];
        $specie = ORM::for_table('module_imobles_enterprise')
                ->table_alias('s');
        $specie->select_expr("s.alias, s.id, s.name, s.address_neightborhood, c.city_name");
        if ($haveListing) {
            $specie->where_raw(' EXISTS (select sub_w.id from module_imobles_listings  sub_w where  sub_w.entreprise_id=s.id) ');
        }

        $specie->where_any_is(array(array("s.name" => '%' . $term . '%'),
            array("s.alias" => '%' . $term . '%')
                ), 'like');
        $specie->where_raw("s.delete_at IS NULL");

        $specie->where_raw("s.has_listing IS NOT NULL");

        if (!empty(@$form['address_neighborhood'])) {
            $specie->where_like('s.address_neightborhood', "%" . $form['address_neighborhood'] . "%");
        }

        if (!empty(@$form['address_number'])) {
            $specie->where_like('s.address_number', "%" . $form['address_number'] . "%");
        }

        if (!empty(@$form['address_state'])) {
            $specie->left_outer_join('state', array('s.address_state_id', '=', 'st.id'), 'st')
                    ->where_like('st.uf_state', "%" . $form['address_state'] . "%");
        }

        // Always JOIN with City to get City Name
        $specie->left_outer_join('city', array('s.address_city_id', '=', 'c.id'), 'c');

        if (isset($_POST['cities']) && !empty($_POST['cities'])) {
            $specie->where_in('s.address_city_id', $_POST['cities']);
        }

        if (!empty(@$form['address_city'])) {
            $specie->where_like('c.city_name', "%" . $form['address_city'] . "%");
        }

//        if (!empty(@$form['address_zip'])) {
//            $specie->where('s.address_zip', preg_replace('/\D/', '', $form['address_zip']));
//        }

        if (!empty(@$form['address_log'])) {
            $cr = new TypeunityController($this->ui, $this->_L, $this->_pd, $this->config);

            $specie->raw_query("(ent.address_log  LIKE '%" . htmlentities($form['address_log']) . "%' "
                    . " OR ent.address_log_sanitized LIKE '%" . $cr->sanitizaLogradouro(htmlentities($form['address_log'])) . "%'  "
                    . ")");
        }



        $especies = $specie->find_many();
        $data = array();
        foreach ($especies as $p) {
            $data[] = array(
                'id' => $p->id,
                'text' => "$p->name ( $p->city_name - $p->address_neightborhood )"
            );
        }

        echo json_encode($data);
    }

    public function enterprises_address() {
        $term = _post('term');
        $form = ($_POST['form']);
        $haveListing = @$this->routes[3];
        $specie = ORM::for_table('module_imobles_enterprise')
                ->table_alias('s');
        $specie->select_expr("s.alias, s.id, s.name, s.address_neightborhood");
        if ($haveListing) {
            $specie->where_raw(' EXISTS (select sub_w.id from module_imobles_listings  sub_w where  sub_w.entreprise_id=s.id) ');
        }

        $specie->where_any_is(array(array("s.name" => '%' . $term . '%'),
            array("s.alias" => '%' . $term . '%')
                ), 'like');
        $specie->where_raw("s.delete_at IS NULL");


        if (!empty(@$form['address_neighborhood'])) {
            $specie->where_like('s.address_neightborhood', "%" . $form['address_neighborhood'] . "%");
        }

        if (!empty(@$form['address_number'])) {
            $specie->where_like('s.address_number', "%" . $form['address_number'] . "%");
        }

        if (!empty(@$form['address_state'])) {
            $specie->left_outer_join('state', array('s.address_state_id', '=', 'st.id'), 'st')
                    ->where_like('st.uf_state', "%" . $form['address_state'] . "%");
        }
        if (!empty(@$form['address_city'])) {
            $specie->left_outer_join('city', array('s.address_city_id', '=', 'c.id'), 'c')
                    ->where_like('c.city_name', "%" . $form['address_city'] . "%");
        }

//        if (!empty(@$form['address_zip'])) {
//            $specie->where('s.address_zip', preg_replace('/\D/', '', $form['address_zip']));
//        }

        if (!empty(@$form['address_log'])) {
            $cr = new TypeunityController($this->ui, $this->_L, $this->_pd, $this->config);

            $specie->raw_query("(ent.address_log  LIKE '%" . htmlentities($form['address_log']) . "%' "
                    . " OR ent.address_log_sanitized LIKE '%" . $cr->sanitizaLogradouro(htmlentities($form['address_log'])) . "%'  "
                    . ")");
        }



        $especies = $specie->find_many();
        $data = array();
        foreach ($especies as $p) {
            $data[] = array(
                'id' => $p->id,
                'text' => $p->name . " (" . $p->address_neightborhood . ")"
            );
        }

        echo json_encode($data);
    }

    public function enterprise_amenities() {
        $term = _post('term');
        $specie = ORM::for_table('module_imobles_enterprise_amenities')
                ->table_alias('s');
        $specie->where_any_is(array(array("s.name" => '%' . $term . '%')
                ), 'like');
        $especies = $specie->find_many();
        $data = array();
        foreach ($especies as $p) {
            $data[] = array(
                'id' => $p->id,
                'text' => $p->name
            );
        }

        echo json_encode($data);
    }

    public function units_amenities() {
        $term = _post('term');
        $specie = ORM::for_table('module_imobles_units_amenities')
                ->table_alias('s');
        $specie->where_any_is(array(array("s.name" => '%' . $term . '%')
                ), 'like');
        $especies = $specie->find_many();
        $data = array();
        foreach ($especies as $p) {
            $data[] = array(
                'id' => $p->id,
                'text' => $p->name
            );
        }

        echo json_encode($data);
    }

    public function type_units_amenities() {
        $term = _post('term');
        $specie = ORM::for_table('module_imobles_type_units_amenities')
                ->table_alias('s');
        $specie->where_any_is(array(array("s.name" => '%' . $term . '%')
                ), 'like');
        $especies = $specie->find_many();
        $data = array();
        foreach ($especies as $p) {
            $data[] = array(
                'id' => $p->id,
                'text' => $p->name
            );
        }

        echo json_encode($data);
    }

    public function listAllamenities() {
        $term = _post('term');
        $specie = ORM::for_table('module_imobles_enterprise_amenities')
                ->raw_query("SELECT name,id,'ENTERPRISE' as tabela from module_imobles_enterprise_amenities where name like '%" . htmlentities($term) . "%'"
                . " UNION ALL SELECT name,id, 'TYPEUNITY' as tabela from module_imobles_type_units_amenities where name like '%" . htmlentities($term) . "%'"
                . " UNION ALL SELECT name,id, 'UNITY' as tabela  from module_imobles_units_amenities where name like '%" . htmlentities($term) . "%' order by name"
        );

        $especies = $specie->find_many();
        $data = array();

        foreach ($especies as $p) {
            $origin = '';
            switch ($p->tabela) {
                case 'ENTERPRISE':
                    $origin = $this->_L['module imobles enterprise'];
                    break;
                case 'TYPEUNITY':
                    $origin = $this->_L['module imobles typeunity'];
                    break;
                case 'UNITY':
                    $origin = $this->_L['module imobles unity'];
                    break;
            }
            $data[] = array(
                'id' => $p->tabela . '_' . $p->id,
                'text' => $p->name . ' | ' . $origin
            );
        }

        echo json_encode($data);
    }

    public function type_unity() {
        $term = _post('term');
        $specie = ORM::for_table('module_imobles_enterprise_units_type')
                ->table_alias('s');
        $specie->where_any_is(array(array("s.title" => '%' . $term . '%')
                ), 'like');
        $especies = $specie->find_many();
        $data = array();
        foreach ($especies as $p) {
            $data[] = array(
                'id' => $p->id,
                'text' => $p->title
            );
        }

        echo json_encode($data);
    }

    public function company_construction() {
        $term = _post('term');
        $specie = ORM::for_table('module_imobles_company_construction')
                ->table_alias('s');
        $specie->select_expr("s.name, s.id as id, c.city_name");
        $specie->left_outer_join('city', array('s.city_id', '=', 'c.id'), 'c');
        $specie->order_by_expr("s.name asc");

        $specie->where_any_is(array(array("s.name" => '%' . $term . '%')
                ), 'like');
        $especies = $specie->find_many();
        $data = array();

        foreach ($especies as $p) {
            $data[] = array(
                'id' => $p->id,
                'text' => $p->name . (!empty($p->city_name) ? " ($p->city_name)" : "")
            );
        }

        echo json_encode($data);
    }

    public function tags_backend() {
        $term = _post('term');
        $specie = ORM::for_table('module_imobles_enterprise_img_backend_tags')
                ->table_alias('s');
        $specie->where_any_is(array(array("s.name" => '%' . $term . '%')
                ), 'like');
        $especies = $specie->find_many();
        $data = array();
        foreach ($especies as $p) {
            $data[] = array(
                'id' => $p->id,
                'text' => $p->name
            );
        }

        echo json_encode($data);
    }

    public function tags_listing() {
        $term = _post('term');
        $specie = ORM::for_table('module_imobles_enterprise_img_listing_tags')
                ->table_alias('s');
        $specie->where_any_is(array(array("s.name" => '%' . $term . '%')
                ), 'like');
        $especies = $specie->find_many();
        $data = array();
        foreach ($especies as $p) {
            $data[] = array(
                'id' => $p->id,
                'text' => $p->name
            );
        }

        echo json_encode($data);
    }

    public function tags_neighborhood() {
        $term = _post('term');
        $specie = ORM::for_table('module_imobles_enterprise_img_neighborhood_tags')
                ->table_alias('s');
        $specie->where_any_is(array(array("s.name" => '%' . $term . '%')
                ), 'like');
        $especies = $specie->find_many();
        $data = array();
        foreach ($especies as $p) {
            $data[] = array(
                'id' => $p->id,
                'text' => $p->name
            );
        }

        echo json_encode($data);
    }

    public function module_imobles_docs_category($sale = false) {
        if (@$this->routes[3] == 'sale') {
            $sale = true;
        }
        $term = _post('term');
        $specie = ORM::for_table('module_imobles_docs_category')
                ->table_alias('s');

        if($sale === true){
            $specie->where_any_is(array(array("s.name" => 'VENDAS %' . $term . '%')
                ), 'like');
        } else {
            $specie->where_any_is(array(array("s.name" => '%' . $term . '%')
                ), 'like');
        }
        
        $especies = $specie->find_many();
        $data = array();
        foreach ($especies as $p) {
            $data[] = array(
                'id' => $p->id,
                'text' => $p->name
            );
        }

        echo json_encode($data);
    }

    public function view() {
        
    }

    public function getGooglePlace() {
        $term = _post('term');

        if (strlen($term) < 10) {
            return false;
        }

        $url = "https://maps.googleapis.com/maps/api/place/findplacefromtext/json?"
                . "key=AIzaSyDV8EiKB-3-jeqoB9qGR7oeQb-y9kLHoCU&"
                . "input=" . urlencode($term) . "&"
                . "inputtype=textquery&fields=geometry,formatted_address,name,place_id,plus_code,type";
        $json_google = curl_init($url);
        curl_setopt($json_google, CURLOPT_RETURNTRANSFER, true);
        $json_response = curl_exec($json_google);
        $result = json_decode($json_response);
        foreach ($result->candidates as $p) {
            $data[] = array(
                'id' => $p->place_id,
                'text' => $p->name . " | " . $p->formatted_address
            );
        }

        echo json_encode($data);
    }

    public function getGooglePlaceDetails() {
        $google_place_id = _post('google_place_id');
        $url = 'https://maps.googleapis.com/maps/api/place/details/json?'
                . 'key=AIzaSyDV8EiKB-3-jeqoB9qGR7oeQb-y9kLHoCU'
                . '&place_id=' . $google_place_id . '&language=pt-BR&reviews_no_translations=true';
        $json_google = curl_init($url);
        curl_setopt($json_google, CURLOPT_RETURNTRANSFER, true);
        $json_response = curl_exec($json_google);
        echo $json_response;
    }

    public function advertisers() {
        $term = _post('term');
        $specie = ORM::for_table('module_imobles_advertisers')
                ->table_alias('s');
        $specie->select_expr("s.phones, s.id, s.name");
        $specie->where_any_is(array(array("s.name" => '%' . $term . '%'),
            array("s.phones" => '%' . $term . '%')
                ), 'like');
        $specie->where_raw("s.delete_at IS NULL");
        $especies = $specie->find_many();
        $data = array();
        foreach ($especies as $p) {
            $data[] = array(
                'id' => $p->id,
                'text' => $p->name . (!empty($p->phones) ? " - ($p->phones)" : "")
            );
        }
        echo json_encode($data);
    }

    public function unitTypes() {
        $term = _post('term');
        $specie = ORM::for_table('module_imobles_enterprise_units_type')
                ->table_alias('s');
        $specie->select_expr("s.id, s.title");

        if (isset($this->routes[3])) {
            $specie->where('s.module_imobles_enterprise_id', $this->routes[3]);
        }
        $specie->where_raw("s.delete_at IS NULL");
        $especies = $specie->find_many();
        $data = array();
        foreach ($especies as $p) {
            $data[] = array(
                'id' => $p->id,
                'text' => $p->title
            );
        }
        echo json_encode($data);
    }

    public function units() {
        $term = _post('term');
        $specie = ORM::for_table('module_imobles_enterprise_units')
                ->table_alias('s');
        $specie->select_expr("s.id, s.number_unity");

        if (isset($this->routes[3])) {
            $specie->where('s.module_imobles_enterprise_units_type_id', $this->routes[3]);
            $specie->where_not('s.number_unity');
        }
        $specie->where_raw("s.delete_at IS NULL");
        $especies = $specie->find_many();
        $data = array();
        foreach ($especies as $p) {
            $data[] = array(
                'id' => $p->id,
                'text' => $p->number_unity
            );
        }
        echo json_encode($data);
    }

    public function deals() {
        $term = _post('term');
        // $specie = ORM::for_table('module_imobles_deals')
        //         ->table_alias('s');

        // if (!empty(_post('andIn'))) {
        //     $specie->where_in('s.crm_account_id', explode(",",_post('andIn')));
        // }
        // $specie->where_raw("s.deleted_at IS NULL");
        // $especies = $specie->find_many();
        // $data = array();
        // foreach ($especies as $p) {
        //     $data[] = array(
        //         'id' => $p->id,
        //         'text' => $p->title
        //     );
        // }
        // echo json_encode($data);

        $obj = ORM::for_table('module_imobles_deals')
                ->table_alias('s')
                ->select_expr('s.id, s.title')
                ->order_by_asc('s.title');

        $term = _post('term');
        if (!empty($term)) {
            $obj->where_raw("s.title LIKE '%" . $term . "%'");
        }
        $result = $obj->find_many();
        $data = array();
        foreach ($result as $c) {
            $data[] = array(
                'id' => $c->id,
                'text' => $c->title,
            );
        }
        echo json_encode($data);
    }

    public function getUserNotifications(){
        $user = User::_info();
        $role = $user->user_type;
        $articles = null;

        // var_dump($user);
        if(!empty($role)){
            $articles = ORM::for_table("module_cms_article")
                ->table_alias("a")
                ->select_expr("a.*, i.path as image_path")
                ->left_outer_join("module_cms_category", "c.id = a.cms_category_id", "c")
                ->left_outer_join("module_imobles_notifications_history", "h.article_id = a.id AND h.user_id = $user->id", "h")
                ->left_outer_join("module_cms_image", "a.cms_image_id = i.id", "i")
                ->where("status", 1)
                ->where_like("c.title", "%$role")
                ->where_gt("a.created_at", $user->creationdate)
                ->where_null("h.id")
                ->order_by_desc("a.id")
                ->limit(1) // show only the last unseen notification
                ->find_many();
        }

        if( count($articles) > 0){

            $a = array();
            foreach($articles as $article){
                $notificationHistory = ORM::for_table("module_imobles_notifications_history")->create();
                $notificationHistory->user_id    = $user->id;
                $notificationHistory->article_id = $article->id;                
                $notificationHistory->save();

                $a[] = [
                    "title" => $article->title,
                    "text" => $article->text,
                    "created_at" => $article->created_at
                ];
            }

            $this->ui->assign('notifications', $articles);
            $this->ui->display($this->_pd . '/views/accounts/notifications_modal.tpl');
        }        
    }

}

Anon7 - 2022
AnonSec Team