<?php
defined('BASEPATH') or exit('No direct script access allowed');

/*
Module Name: Real Estate & Tenant Management Module For Perfex CRM
Description: Simplify and streamline your property and tenant management processes by managing leases, payments, and tenant information all in one place. Save time, reduce administrative tasks, and enhance property oversight with powerful features designed to optimize your real estate operations.
Version: 1.0.0
Author: LenzCreative
Author URI: https://codecanyon.net/user/lenzcreativee/portfolio
Requires at least: 3.1.*
*/

define('PROPERTYBASE_MODULE_NAME', 'propertybase');
define('PROPERTYBASE_REVISION', 100);

define('PROPERTYBASE_PROPERTY_MAIN_IMAGE_PATH', FCPATH . 'modules/' . PROPERTYBASE_MODULE_NAME . '/uploads/property_images/main_image/');
define('PROPERTYBASE_PROPERTY_FLOOR_IMAGE_PATH', FCPATH . 'modules/' . PROPERTYBASE_MODULE_NAME . '/uploads/property_images/floor_image/');
define('PROPERTYBASE_PROPERTY_ATTACHMENTS_PATH', FCPATH . 'modules/' . PROPERTYBASE_MODULE_NAME . '/uploads/property_images/attachments/');
define('PROPERTYBASE_PROPERTY_MAINTENANCE_REQUESTS_PATH', FCPATH . 'modules/' . PROPERTYBASE_MODULE_NAME . '/uploads/property_images/maintenance_requests/');
define('PROPERTYBASE_CACHE_PATH', FCPATH . 'modules/' . PROPERTYBASE_MODULE_NAME . '/uploads/cache/');

hooks()->add_action('admin_init', 'propertybase_module_init_menu_items');
hooks()->add_action('admin_init', 'propertybase_permissions');
hooks()->add_action('propertybase_init', PROPERTYBASE_MODULE_NAME . '_appint');
hooks()->add_action('pre_activate_module', PROPERTYBASE_MODULE_NAME . '_preactivate');
hooks()->add_action('pre_deactivate_module', PROPERTYBASE_MODULE_NAME . '_predeactivate');
hooks()->add_action('pre_uninstall_module', PROPERTYBASE_MODULE_NAME . '_uninstall');

include(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/libraries/Import_properties.php');

/**
 * Load the module helper
 */
$CI = &get_instance();
$CI->load->helper(PROPERTYBASE_MODULE_NAME . '/propertybase');

if (is_admin()) {
    propertybase_fetch_modules();
}

function propertybase_permissions()
{
    $capabilities = [];

    $capabilities['capabilities'] = [
        'view' => _l('permission_view'),
        'create' => _l('permission_create'),
        'edit' => _l('permission_edit'),
        'delete' => _l('permission_delete')
    ];
    register_staff_capabilities('propertybase_properties', $capabilities, _l('propertybase_properties'));

    $capabilities['capabilities'] = [
        'view' => _l('permission_view'),
        'edit' => _l('permission_edit'),
        'delete' => _l('permission_delete')
    ];
    register_staff_capabilities('propertybase_maintenance_requests', $capabilities, _l('propertybase_properties'));

    $capabilities = [];
    $capabilities['capabilities'] = [
        'view' => _l('permission_view') . '(' . _l('permission_global') . ')',
    ];
    register_staff_capabilities('propertybase_themes', $capabilities, _l('propertybase_property') . ' ' . _l('propertybase_themes'));    $capabilities = [];

    $capabilities['capabilities'] = [
        'view' => _l('permission_view') . '(' . _l('permission_global') . ')',
    ];
    register_staff_capabilities('propertybase_reports', $capabilities, _l('propertybase_property') . ' ' . _l('propertybase_reports'));
}

/**
 * Register activation module hook
 */
register_activation_hook(PROPERTYBASE_MODULE_NAME, 'propertybase_module_activation_hook');

function propertybase_module_activation_hook()
{
    $CI = &get_instance();
    require_once(__DIR__ . '/install.php');
}

/**
 * Register language files, must be registered if the module is using languages
 */
register_language_files(PROPERTYBASE_MODULE_NAME, [PROPERTYBASE_MODULE_NAME]);

/**
 * Init module menu items in setup in admin_init hook
 * @return null
 */
function propertybase_module_init_menu_items()
{
    $CI = &get_instance();

    if (has_permission('propertybase_properties', '', 'view')) {
        $CI->app_menu->add_sidebar_menu_item('propertybase', [
            'slug' => 'propertybase',
            'name' => _l('propertybase'),
            'position' => 6,
            'icon' => 'fas fa-building'
        ]);
    }

    if (has_permission('propertybase_properties', '', 'create')) {
        $CI->app_menu->add_sidebar_children_item('propertybase', [
            'slug' => 'propertybase-properties-sub',
            'name' => _l('propertybase_properties'),
            'position' => 6,
            'icon' => 'fas fa-plus-circle',
            'href' => admin_url(PROPERTYBASE_MODULE_NAME . '/manage')
        ]);
    }

    if (has_permission('propertybase_maintenance_requests', '', 'view')) {
        $CI->app_menu->add_sidebar_children_item('propertybase', [
            'slug' => 'propertybase-properties-maintenance-requests',
            'name' => _l('propertybase_maintenance_requests'),
            'position' => 6,
            'icon' => 'fas fa-tools',
            'href' => admin_url(PROPERTYBASE_MODULE_NAME . '/maintenance_requests')
        ]);
    }

    if (has_permission('propertybase_reports', '', 'view')) {
        $CI->app_menu->add_sidebar_children_item('propertybase', [
            'slug' => 'propertybase-reports',
            'name' => _l('propertybase_reports'),
            'position' => 6,
            'icon' => 'fas fa-chart-line',
            'href' => admin_url(PROPERTYBASE_MODULE_NAME . '/propertybase_reports')
        ]);
    }

    $CI->app_menu->add_sidebar_children_item('propertybase', [
        'slug' => 'propertybase-qr-scanner',
        'name' => _l('propertybase_qr_scanner'),
        'position' => 6,
        'icon' => 'fas fa-qrcode',
        'href' => admin_url(PROPERTYBASE_MODULE_NAME . '/qr_scanner')
    ]);

    if (has_permission('propertybase_themes', '', 'view')) {
        $CI->app_menu->add_sidebar_children_item('propertybase', [
            'slug' => 'propertybase-themes',
            'name' => _l('propertybase_themes'),
            'position' => 6,
            'icon' => 'fas fa-paint-brush',
            'href' => admin_url(PROPERTYBASE_MODULE_NAME . '/themes')
        ]);
    }

    if (is_admin()) {
        $CI->app_menu->add_sidebar_children_item('propertybase', [
            'slug' => 'propertybase-settings-sub',
            'name' => _l('settings'),
            'position' => 6,
            'icon' => 'fas fa-cog',
            'href' => admin_url(PROPERTYBASE_MODULE_NAME . '/settings')
        ]);

        $CI->app_menu->add_sidebar_children_item('propertybase', [
            'slug' => 'propertybase-modules',
            'name' => _l('propertybase_modules') . propertybase_count_of_extensions(true),
            'position' => 6,
            'icon' => 'fas fa-cubes',
            'href' => admin_url(PROPERTYBASE_MODULE_NAME . '/propertybase_modules')
        ]);
    }
}

hooks()->add_action('clients_init', 'propertybase_clients_init_menu_items');
function propertybase_clients_init_menu_items()
{

    $CI = &get_instance();

    if (has_contact_permission('properties')) {
        $CI->app_menu->add_theme_item('propertybase', [
            'name' => _l('propertybase_properties'),
            'href' => site_url(PROPERTYBASE_MODULE_NAME . '/propertybase_client/properties'),
            'position' => 10,
        ]);
    }
}

hooks()->add_filter('get_contact_permissions', 'propertybase_add_contact_permission');
function propertybase_add_contact_permission($permissions)
{
    $new_permission = [
        'id' => 4921,
        'name' => _l('propertybase_properties'),
        'short_name' => 'properties',
    ];

    $permissions[] = $new_permission;
    return $permissions;
}

hooks()->add_action('after_custom_fields_select_options', 'propertybase_new_custom_field_type');
function propertybase_new_custom_field_type($custom_field)
{
    ?>
    <option value="propertybase_pr" <?php if (isset($custom_field) && $custom_field->fieldto == 'propertybase_pr') {
        echo 'selected';
    } ?>><?php echo _l('propertybase_property_custom_fields'); ?></option>
    <?php
}

hooks()->add_action('task_modal_rel_type_select', 'propertybase_property_rel_to_task');
function propertybase_property_rel_to_task($data)
{
    $selected = (isset($data['rel_type']) && $data['rel_type'] == 'properties') ? 'selected' : '';
    echo '<option value="properties" ' . $selected . '>' . _l('propertybase_properties') . '</option>';
}

hooks()->add_action('task_modal_rel_type_select', 'propertybase_maintenance_request_rel_to_task');
function propertybase_maintenance_request_rel_to_task($data)
{
    $selected = (isset($data['rel_type']) && $data['rel_type'] == 'maintenance_request') ? 'selected' : '';
    echo '<option value="maintenance_request" ' . $selected . '>' . _l('propertybase_maintenance_requests') . '</option>';
}

hooks()->add_filter('relation_values', 'propertybase_property_relation_values', 10, 1);
function propertybase_property_relation_values($values)
{
    $relation = $values['relation'];

    if ($values['type'] == 'properties') {
        if (is_array($relation)) {
            $values['id'] = $relation['id'];
            $values['name'] = propertybase_formatted_property_name($relation['id']);
            $values['addedfrom'] = $relation['selected_agent'];
        } else {
            $values['id'] = $relation->id;
            $values['name'] = propertybase_formatted_property_name($relation->id);
            $values['addedfrom'] = $relation->selected_agent;
        }
        $values['link'] = admin_url(PROPERTYBASE_MODULE_NAME . '/propertybase/view/' . $values['id']);
    }

    return $values;
}

hooks()->add_filter('relation_values', 'propertybase_maintenance_request_relation_values', 10, 1);
function propertybase_maintenance_request_relation_values($values)
{
    $relation = $values['relation'];

    if ($values['type'] == 'maintenance_request') {
        if (is_array($relation)) {
            $values['id'] = $relation['id'];
            $values['name'] = propertybase_formatted_maintenance_request_name($relation['id']);
        } else {
            $values['id'] = $relation->id;
            $values['name'] = propertybase_formatted_maintenance_request_name($relation->id);
        }
        $values['link'] = admin_url(PROPERTYBASE_MODULE_NAME . '/maintenance_requests/view/' . $values['id']);
    }

    return $values;
}

hooks()->add_filter('get_relation_data', 'propertybase_get_properties_relation_data', 10, 4);
function propertybase_get_properties_relation_data($data, $params)
{
    $CI = &get_instance();

    $type = $params['type'];
    $rel_id = $params['rel_id'];
    $customer_id = $CI->input->post('customer_id') ?? '';

    if ($type == 'properties') {
        $CI->load->model(PROPERTYBASE_MODULE_NAME . '/propertybase_model');

        if ($rel_id != '') {
            $data = $CI->propertybase_model->get($rel_id);
        } else {
            $search_query = isset($params['extra']['q']) ? $params['extra']['q'] : '';
            $data = $CI->propertybase_model->_search_properties(['q' => $search_query, 'customer_id' => $customer_id]);
        }
    }

    return $data;
}

hooks()->add_filter('get_relation_data', 'propertybase_get_maintenance_request_relation_data', 10, 4);
function propertybase_get_maintenance_request_relation_data($data, $params)
{
    $CI = &get_instance();

    $type = $params['type'];
    $rel_id = $params['rel_id'];
    $customer_id = $CI->input->post('customer_id') ?? '';

    if ($type == 'maintenance_request') {

        if ($rel_id != '') {
            $data = propertybase_get_property_maintenance($rel_id);
        } else {
            $search_query = isset($params['extra']['q']) ? $params['extra']['q'] : '';
            $data = propertybase_search_maintenance_requests(['q' => $search_query, 'customer_id' => $customer_id]);
        }
    }

    return $data;
}


hooks()->add_action('app_admin_head', 'propertybase_head_load_js');
function propertybase_head_load_js()
{
    $mainStyleLink = module_dir_url(PROPERTYBASE_MODULE_NAME, 'assets/css/admin_style.css');
    echo '<link rel="stylesheet" href="'.$mainStyleLink.'"/>';
}

hooks()->add_action('app_admin_footer', 'propertybase_load_js');
function propertybase_load_js()
{
    $viewuri = $_SERVER['REQUEST_URI'];

    if (!(strpos($viewuri, 'admin/invoices/invoice') === false) || !(strpos($viewuri, 'invoices/invoice') === false)) {
        echo '<script src="' . module_dir_url(PROPERTYBASE_MODULE_NAME, 'assets/js/admin/invoices/main.js') . '?v=' . PROPERTYBASE_REVISION . '"></script>';
    }

    if (!(strpos($viewuri, 'admin/propertybase/view') === false) || !(strpos($viewuri, 'propertybase/view') === false)) {
        echo '<script src="' . module_dir_url(PROPERTYBASE_MODULE_NAME, 'assets/js/admin/invoices/invoice_tab.js') . '?v=' . PROPERTYBASE_REVISION . '"></script>';
    }

    if (!(strpos($viewuri, 'admin/propertybase/view') === false) || !(strpos($viewuri, 'propertybase/view') === false)) {
        echo '<script src="' . module_dir_url(PROPERTYBASE_MODULE_NAME, 'assets/js/admin/expenses/main.js') . '?v=' . PROPERTYBASE_REVISION . '"></script>';
    }

    if (!(strpos($viewuri, 'admin/leads') === false) || !(strpos($viewuri, 'leads') === false)) {
        echo '<script src="' . module_dir_url(PROPERTYBASE_MODULE_NAME, 'assets/js/admin/expenses/main.js') . '?v=' . PROPERTYBASE_REVISION . '"></script>';
    }

    if (!(strpos($viewuri, PROPERTYBASE_MODULE_NAME . '/settings?group=property_categories') === false) || !(strpos($viewuri, PROPERTYBASE_MODULE_NAME . '/settings') === false)) {
        echo '<script src="' . module_dir_url(PROPERTYBASE_MODULE_NAME, 'assets/js/admin/settings/property_categories.js') . '?v=' . PROPERTYBASE_REVISION . '"></script>';
    }

    if (!(strpos($viewuri, PROPERTYBASE_MODULE_NAME . '/settings?group=property_amenities_types') === false) || !(strpos($viewuri, PROPERTYBASE_MODULE_NAME . '/settings') === false)) {
        echo '<script src="' . module_dir_url(PROPERTYBASE_MODULE_NAME, 'assets/js/admin/settings/property_amenities_types.js') . '?v=' . PROPERTYBASE_REVISION . '"></script>';
    }

    if (!(strpos($viewuri, PROPERTYBASE_MODULE_NAME . '/settings?group=property_amenities') === false) || !(strpos($viewuri, PROPERTYBASE_MODULE_NAME . '/settings') === false)) {
        echo '<script src="' . module_dir_url(PROPERTYBASE_MODULE_NAME, 'assets/js/admin/settings/property_amenities.js') . '?v=' . PROPERTYBASE_REVISION . '"></script>';
    }

    if (!(strpos($viewuri, PROPERTYBASE_MODULE_NAME . '/settings?group=property_area_types') === false) || !(strpos($viewuri, PROPERTYBASE_MODULE_NAME . '/settings') === false)) {
        echo '<script src="' . module_dir_url(PROPERTYBASE_MODULE_NAME, 'assets/js/admin/settings/property_area_types.js') . '?v=' . PROPERTYBASE_REVISION . '"></script>';
    }

    if (!(strpos($viewuri, PROPERTYBASE_MODULE_NAME . '/settings?group=property_ownership_types') === false) || !(strpos($viewuri, PROPERTYBASE_MODULE_NAME . '/settings') === false)) {
        echo '<script src="' . module_dir_url(PROPERTYBASE_MODULE_NAME, 'assets/js/admin/settings/property_ownership_types.js') . '?v=' . PROPERTYBASE_REVISION . '"></script>';
    }

    if (!(strpos($viewuri, PROPERTYBASE_MODULE_NAME . '/settings?group=energy_efficiency_types') === false) || !(strpos($viewuri, PROPERTYBASE_MODULE_NAME . '/settings') === false)) {
        echo '<script src="' . module_dir_url(PROPERTYBASE_MODULE_NAME, 'assets/js/admin/settings/property_energy_efficiency_types.js') . '?v=' . PROPERTYBASE_REVISION . '"></script>';
    }

    hooks()->do_action('propertybase_load_js', $viewuri);
}

hooks()->add_action('before_render_invoice_template', 'propertybase_render_properties_on_invoice');
function propertybase_render_properties_on_invoice($invoice)
{

    if (is_null($invoice)) {
        $propertyID = $_GET['property_id'] ?? '';
        ?>
        <div class="form-group select-placeholder properties-wrapper<?php
        echo (!isset($invoice) || (isset($invoice) && !propertybase_customer_has_properties($invoice->clientid))) ?
            (!isset($propertyID) && $propertyID === 0) ? ' hide' : '' : '';
        ?>">
            <label for="property_id"><?php echo _l('propertybase_properties'); ?></label>
            <div id="property_ajax_search_wrapper">
                <select name="property_id" id="property_id" class="properties ajax-search" data-live-search="true"
                        data-width="100%" data-none-selected-text="<?php echo _l('dropdown_non_selected_tex'); ?>">
                    <?php
                    if ($propertyID) {
                        echo '<option value="' . $propertyID . '" selected>' . propertybase_formatted_property_name($propertyID) . '</option>';
                    }
                    ?>
                </select>
            </div>
        </div>
        <?php
    } else if ($invoice) {
        $propertyIsSet = $invoice->property_id;
        ?>
        <div class="form-group select-placeholder projects-wrapper<?php
        echo (!isset($invoice) || (isset($invoice) && !propertybase_customer_has_properties($invoice->clientid))) ?
            (!isset($propertyIsSet) && $propertyIsSet === 0) ? ' hide' : '' : '';
        ?>">
            <label for="property_id"><?php echo _l('propertybase_properties'); ?></label>
            <div id="property_ajax_search_wrapper">
                <select name="property_id" id="property_id" class="properties ajax-search" data-live-search="true"
                        data-width="100%" data-none-selected-text="<?php echo _l('dropdown_non_selected_tex'); ?>">
                    <?php
                    $propertyIsSet = $_GET['property_id'] ?? $propertyIsSet;
                    if (isset($invoice) && $propertyIsSet != 0) {
                        $propertyIsSet = $propertyIsSet;
                    }
                    if ($propertyIsSet) {
                        echo '<option value="' . $propertyIsSet . '" selected>' . propertybase_formatted_property_name($propertyIsSet) . '</option>';
                    }
                    ?>
                </select>
            </div>
        </div>
        <?php
    }
}

hooks()->add_action('before_expense_form_name', 'propertybase_render_properties_on_expenses');
function propertybase_render_properties_on_expenses($expense)
{
    $CI = &get_instance();

    $CI->load->model(PROPERTYBASE_MODULE_NAME . '/propertybase_model');
    $propertiesList = $CI->propertybase_model->get_all();

    if (is_null($expense)) {
        $propertyID = $_GET['property_id'] ?? '';
        echo render_select('property_id', $propertiesList, ['id', 'name'], 'propertybase_properties', $propertyID ?? '');

    } else if ($expense) {
        $propertyIsSet = $expense->property_id;
        if ($propertyIsSet == 0) {
            $propertyIsSet = '';
        }
        echo render_select('property_id', $propertiesList, ['id', 'name'], 'propertybase_properties', $propertyIsSet ?? '');
    }
}

hooks()->add_filter('before_invoice_added', 'propertybase_add_property_id_to_recurring_invoice_data');
function propertybase_add_property_id_to_recurring_invoice_data($data)
{
    if (isset($data['data']['is_recurring_from']) && !empty($data['data']['is_recurring_from'])) {
        $recurring_from_id = $data['data']['is_recurring_from'];

        $CI = &get_instance();

        $CI->db->select('property_id');
        $CI->db->from(db_prefix() . 'invoices');
        $CI->db->where('id', $recurring_from_id);
        $query = $CI->db->get();

        if ($query->num_rows() > 0) {
            $invoice = $query->row();

            $data['data']['property_id'] = $invoice->property_id;
        }
    }

    return $data;
}

hooks()->add_action('after_right_panel_invoice_preview_template', 'propertybase_show_invoice_property_name');
function propertybase_show_invoice_property_name($invoice)
{
    if (!is_null($invoice) && isset($invoice->property_id) && $invoice->property_id !== 0) {

        $CI = &get_instance();
        $CI->load->model(PROPERTYBASE_MODULE_NAME . '/propertybase_model');
        $data = $CI->propertybase_model->get($invoice->property_id);

        if (is_null($data)) {
            return;
        }

        echo '
        <p class="no-mbot">
                <span class="bold">' . _l("propertybase_property") . ':</span>
                <a target="_blank" href="' . admin_url(PROPERTYBASE_MODULE_NAME . '/view/' . $invoice->property_id) . '">' . propertybase_formatted_property_name($invoice->property_id) . '</a>            
        </p>
        ';
    }
}

hooks()->add_filter('invoice_pdf_header_before_custom_fields', 'propertybase_add_property_name_to_pdf_header', 10, 2);
function propertybase_add_property_name_to_pdf_header($invoice_info, $invoice)
{
    if (!is_null($invoice) && isset($invoice->property_id) && $invoice->property_id !== 0) {

        $CI = &get_instance();
        $CI->load->model(PROPERTYBASE_MODULE_NAME . '/propertybase_model');
        $data = $CI->propertybase_model->get($invoice->property_id);

        if (is_null($data)) {
            return $invoice_info;
        }

        $property_name = propertybase_formatted_property_name($invoice->property_id);
        $dynamicStyle = "margin-bottom: 0;";
        $invoice_info .= '<p style="'.$dynamicStyle.'">
                            <strong>' . _l("propertybase_property") . ':</strong> ' . $property_name . '
                          </p>';
    }

    return $invoice_info;
}

hooks()->add_action('after_lead_lead_tabs', 'propertybase_add_lead_properties_tab');
function propertybase_add_lead_properties_tab()
{
    if (has_permission('propertybase', '', 'view')) {
        ?>
        <li role="presentation">
            <a href="#propertybase_lead_properties" aria-controls="propertybase_lead_properties" role="tab"
               data-toggle="tab">
                <?php echo _l('propertybase_properties'); ?>
            </a>
        </li>
        <?php
    }
}

hooks()->add_action('after_lead_tabs_content', 'propertybase_lead_properties_tab_content');
function propertybase_lead_properties_tab_content($lead)
{
    if (has_permission('propertybase', '', 'view')) {
        ?>
        <div role="tabpanel" class="tab-pane" id="propertybase_lead_properties">
            <div class="col-md-12 mtop15">
                <?php
                propertybase_load_view(module_views_path(PROPERTYBASE_MODULE_NAME, '/admin/properties/tabs/leads/lead_properties_html.php'));
                ?>
            </div>
        </div>
        <script>
            $(document).ready(function () {
                initDataTable(
                    ".table-lead-properties",
                    admin_url + "propertybase/propertybase/lead_properties/<?php echo $lead->id ?>",
                    "undefined",
                    "undefined",
                    {},
                    [0, "desc"]
                );
            });
        </script>
        <?php
    }
}

function propertybase_appint()
{
    $CI = &get_instance();
    require_once 'libraries/leclib.php';
    $module_api = new PropertybaseLic();
    $module_leclib = $module_api->verify_license(true);
    if (!$module_leclib || ($module_leclib && isset($module_leclib['status']) && !$module_leclib['status'])) {
        $CI->app_modules->deactivate(PROPERTYBASE_MODULE_NAME);
        set_alert('danger', "One of your modules failed its verification and got deactivated. Please reactivate or contact support.");
        redirect(admin_url('modules'));
    }
}

function propertybase_preactivate($module_name)
{
    if ($module_name['system_name'] == PROPERTYBASE_MODULE_NAME) {
        require_once 'libraries/leclib.php';
        $module_api = new PropertybaseLic();
        $module_leclib = $module_api->verify_license();
        if (!$module_leclib || ($module_leclib && isset($module_leclib['status']) && !$module_leclib['status'])) {
            $CI = &get_instance();
            $data['submit_url'] = $module_name['system_name'] . '/lecverify/activate';
            $data['original_url'] = admin_url('modules/activate/' . PROPERTYBASE_MODULE_NAME);
            $data['module_name'] = PROPERTYBASE_MODULE_NAME;
            $data['title'] = "Module License Activation";
            echo $CI->load->view($module_name['system_name'] . '/activate', $data, true);
            exit();
        }
    }
}

function propertybase_predeactivate($module_name)
{
    if ($module_name['system_name'] == PROPERTYBASE_MODULE_NAME) {
        require_once 'libraries/leclib.php';
        $propertybase_api = new PropertybaseLic();
        $propertybase_api->deactivate_license();
    }
}

function propertybase_uninstall($module_name)
{
    if ($module_name['system_name'] == PROPERTYBASE_MODULE_NAME) {
        require_once 'libraries/leclib.php';
        $propertybase_api = new PropertybaseLic();
        $propertybase_api->deactivate_license();
    }
}