Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php /* * @ https://EasyToYou.eu - IonCube v11 Decoder Online * @ PHP 7.2 & 7.3 * ..

Decoded Output download

<?php 
/* 
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online 
 * @ PHP 7.2 & 7.3 
 * @ Decoder version: 1.0.6 
 * @ Release: 10/08/2022 
 */ 
 
include "common.php"; 
update_run_flags(); 
$smarty->assign("edit_page", "addons"); 
$tmp_cnf_file = $config["site_path"] . "/temp/structure.json"; 
$tmp_dat_file = $config["site_path"] . "/temp/data.json"; 
$tmp_zip_file = $config["site_path"] . "/temp/addon.zip"; 
$config["curl_timeout"] = 5000; 
if ($config["type"] == "SAAS") { 
    $row = @sql_select_array("saas_config", "`key` = 'login'"); 
    $account = $row["value"]; 
} else { 
    $key_path = $config["site_path"] . "/runtime/key.php"; 
    $row["code"] = file_get_contents($key_path); 
    $account = substr(key_decrypt($row["code"]), 16, 14); 
} 
$shop_addons = json_decode(send_asterisk_curl("https://market." . CLIENTBASE_DOMAIN . "/get_addons_list.php?account=" . urlencode($account)), 1); 
if (isset($_POST["delete"])) { 
    $addon_id = intval($_POST["addon"]); 
    $addon = sql_select_array(ADDONS_TABLE, "id = ", $addon_id); 
    if ($addon["uninstall_code"]) { 
        eval($addon["uninstall_code"]); 
    } 
    $addon_parts = []; 
    $result = sql_select(ADDON_PARTS_TABLE, "addon_id = ", $addon_id); 
    while ($one_part = sql_fetch_assoc($result)) { 
        $addon_parts[$one_part["part_type"]][$one_part["part_id"]] = 1; 
    } 
    foreach ($addon_parts["table"] as $table_id => $value) { 
        $err_msg = test_delete_table($table_id, $addon_parts); 
        if ($err_msg) { 
            if ($err_msg) { 
                $table = get_table($table_id); 
                $err_msg = "<span style='color:red'><b>" . $lang["Table"] . " &laquo;" . $table["name_table"] . "&raquo; " . $lang["cant_removed"] . ".</b></span><br><br>" . $err_msg; 
                _obfuscated_0D24403B3238133B0B020A390C16062F042B3025233B22_($err_msg); 
            } else { 
                foreach ($shop_addons as $shop_addon_id => $shop_addon) { 
                    if ($addon["name"] == $shop_addon["name"] && $shop_addon["rented"]) { 
                        $result = json_decode(send_asterisk_curl("https://market." . CLIENTBASE_DOMAIN . "/del_rent_addon.php?account=" . urlencode($account) . "&addon=" . $shop_addon_id), 1); 
                        if (!$result["success"]) { 
                            _obfuscated_0D24403B3238133B0B020A390C16062F042B3025233B22_($lang["Delete_rent_addon_error"]); 
                        } 
                    } else { 
                        if ($addon["name"] == $shop_addon["name"] && !$shop_addon["bought"]) { 
                            send_asterisk_curl("https://market." . CLIENTBASE_DOMAIN . "/del_addon.php?account=" . urlencode($account) . "&addon=" . $shop_addon_id); 
                        } 
                    } 
                } 
                _obfuscated_0D255C3126152906151E181D1E0E29393E033F1E331532_($addon_id); 
                insert_log("admin", $lang["Administrator"] . " " . form_display($user["fio"]) . " " . $lang["log_delete_addon"] . " \"" . $addon["name"] . "\""); 
                if (!isset($_GET["ajax"])) { 
                    header("Location: edit_transfer.php"); 
                } 
                exit; 
            } 
        } 
    } 
} 
if (isset($_POST["unlock"])) { 
    $addon_id = intval($_POST["addon"]); 
    sql_delete(ADDONS_TABLE, "id = ", $addon_id); 
    sql_delete(ADDON_PARTS_TABLE, "addon_id = ", $addon_id); 
    header("Location: edit_transfer.php"); 
    exit; 
} 
if ($_POST["export"]) { 
    if (!$_POST["sel_cat"]) { 
        _obfuscated_0D24403B3238133B0B020A390C16062F042B3025233B22_($lang["No_select_for_export"]); 
    } 
    $exp_tables = []; 
    foreach ($_POST["sel_cat"] as $sel_elem) { 
        foreach ($sel_elem["tables"] as $table_id) { 
            $exp_tables[$table_id] = 1; 
        } 
    } 
    $export_conf = ["revision" => $config["revision"]]; 
    $link_fields = []; 
    foreach ($_POST["sel_cat"] as $cat_id => $sel_elem) { 
        $category["new_cat"] = $sel_elem["new_cat"] ? true : false; 
        $category["category"] = sql_select_array(CATS_TABLE, "id=", $cat_id); 
        $category["category"]["icon"] = base64_encode($category["category"]["icon"]); 
        $category["category"]["icon2"] = base64_encode($category["category"]["icon2"]); 
        $category["acc_cats"] = []; 
        $result = sql_select(ACC_CATS_TABLE, "cat_id = ", $cat_id); 
        while ($row = sql_fetch_assoc($result)) { 
            $category["acc_cats"][] = $row; 
        } 
        $category["tables"] = []; 
        foreach ($sel_elem["tables"] as $table_id) { 
            if (!($user["sub_admin"] && $user["sub_admin_rights"]["tables"][$table_id] != 2)) { 
                $category["tables"][] = export_table($table_id, $exp_tables); 
                $result = sql_select(FIELDS_TABLE, "table_id=", $table_id, " and type_field = 5"); 
                while ($impr_field = sql_fetch_assoc($result)) { 
                    list($link_table_id, $link_field_id) = explode("|", $impr_field["type_value"]); 
                    if (!$exp_tables[$link_table_id]) { 
                        $impr_table = sql_fetch_assoc(sql_select_field(TABLES_TABLE, "name_table", "id = ", $table_id)); 
                        $base_name = sql_select_array(BASE_NAMES_TABLE, "field_id = ", $link_field_id); 
                        if ($base_name) { 
                            $link_table["name_table"] = $base_name["name_table"]; 
                            $link_field["name_field"] = $base_name["name_field"]; 
                        } else { 
                            $link_table = sql_fetch_assoc(sql_select_field(TABLES_TABLE, "name_table", "id = ", $link_table_id)); 
                            $link_field = sql_fetch_assoc(sql_select_field(FIELDS_TABLE, "name_field", "id = ", $link_field_id)); 
                        } 
                        $link_fields[$impr_field["id"]]["impr_table"] = $impr_table["name_table"]; 
                        $link_fields[$impr_field["id"]]["impr_field"] = $impr_field["name_field"]; 
                        $link_fields[$impr_field["id"]]["impr_help"] = $impr_field["help"]; 
                        $link_fields[$impr_field["id"]]["link_table"] = $link_table["name_table"]; 
                        $link_fields[$impr_field["id"]]["link_field"] = $link_field["name_field"]; 
                    } 
                } 
            } 
        } 
        $category["reports"] = []; 
        foreach ($sel_elem["reports"] as $report_id) { 
            if (!($user["sub_admin"] && $user["sub_admin_rights"]["reports"][$report_id] != 2)) { 
                if (!($report_id == $_POST["addons_install_code"] || $report_id == $_POST["addons_uninstall_code"])) { 
                    $export_report["report"] = sql_select_array(REPORTS_TABLE, "id=", $report_id); 
                    $export_report["acc_reports"] = []; 
                    $result = sql_select(ACC_REPORTS_TABLE, "report_id=", $report_id); 
                    while ($row = sql_fetch_assoc($result)) { 
                        $export_report["acc_reports"][] = $row; 
                    } 
                    $category["reports"][] = $export_report; 
                } 
            } 
        } 
        $category["calendars"] = []; 
        foreach ($sel_elem["calendars"] as $calendar_id) { 
            if (!($user["sub_admin"] && $user["sub_admin_rights"]["calendars"][$calendar_id] != 2)) { 
                $export_calendar["calendar"] = sql_select_array(CALENDARS_TABLE, "id=", $calendar_id); 
                $export_calendar["acc_calendars"] = []; 
                $result = sql_select(ACC_CALENDARS_TABLE, "calendar_id=", $calendar_id); 
                while ($row = sql_fetch_assoc($result)) { 
                    $export_calendar["acc_calendars"][] = $row; 
                } 
                $export_calendar["events"] = []; 
                $export_calendar["fields"] = []; 
                $result = sql_select(CALENDAR_EVENTS, "calendar_id=", $calendar_id); 
                while ($row = sql_fetch_assoc($result)) { 
                    if ($exp_tables[$row["table_id"]]) { 
                        $export_calendar["events"][] = $row; 
                        $result2 = sql_select(CALENDAR_FIELDS, "event_id=", $row["id"]); 
                        while ($row2 = sql_fetch_assoc($result2)) { 
                            $export_calendar["fields"][] = $row2; 
                        } 
                    } 
                } 
                $category["calendars"][] = $export_calendar; 
            } 
        } 
        $export_conf["categories"][] = $category; 
    } 
    $export_conf["link_fields"] = $link_fields; 
    $wazzup_settings = CB\core()->SETTINGS_MANAGER->get("cbext.clientbase.wazzup"); 
    $tips = $wazzup_settings["tips"] ?? []; 
    foreach ($category["tables"] as $table) { 
        foreach ($table["tips"] as $tip) { 
            if (in_array($tip["id"], $tips)) { 
                $export_conf["wazzup_settings"]["tips"][] = $tip["id"]; 
            } 
        } 
    } 
    $result = sql_select(GROUPS_TABLE, "id != 1 AND id != 777"); 
    while ($row = sql_fetch_assoc($result)) { 
        $group_id = $row["id"]; 
        unset($row["id"]); 
        $export_conf["groups"][$group_id] = $row; 
    } 
    $export_conf["addons_settings"] = $_POST["addons_settings_report"] ?: ""; 
    if ($_POST["addons_install_code"]) { 
        $result = sql_select_field(REPORTS_TABLE, "code", "id = ", $_POST["addons_install_code"]); 
        $row = sql_fetch_assoc($result); 
        $export_conf["install_code"] = $row["code"]; 
    } 
    if ($_POST["addons_uninstall_code"]) { 
        $result = sql_select_field(REPORTS_TABLE, "code", "id = ", $_POST["addons_uninstall_code"]); 
        $row = sql_fetch_assoc($result); 
        $export_conf["uninstall_code"] = $row["code"]; 
    } 
    $json_export_conf = json_encode_visual($export_conf); 
    if (json_last_error()) { 
        _obfuscated_0D24403B3238133B0B020A390C16062F042B3025233B22_($lang["Error"] . ": " . _obfuscated_0D380316072234241A5C3707115C0F5B1B33343B393122_()); 
    } 
    file_put_contents($tmp_cnf_file, $json_export_conf); 
    $_SESSION[$ses_id]["export_conf_file_name"] = $_POST["file_name"]; 
    if ($_POST["table_data"]) { 
        $_SESSION[$ses_id]["export_conf_table_data"] = $_POST["table_data"]; 
    } else { 
        $_SESSION[$ses_id]["export_conf_complete"] = 1; 
    } 
    header("Location: edit_transfer.php"); 
    exit; 
} else { 
    if ($_SESSION[$ses_id]["export_conf_table_data"]) { 
        $start_time = time(); 
        $max_exec_time = $config["type"] == "SAAS" ? 240 : ini_get("max_execution_time"); 
        if (240 < $max_exec_time) { 
            $max_exec_time = 240; 
        } 
        if ($max_exec_time < 30) { 
            $max_exec_time = 30; 
        } 
        $tables = $_SESSION[$ses_id]["export_conf_table_data"]; 
        if ($_SESSION[$ses_id]["export_conf_num_rec"]) { 
            $start_rec = $_SESSION[$ses_id]["export_conf_start_rec"]; 
            $num_rec = $_SESSION[$ses_id]["export_conf_num_rec"]; 
            $cnt_rec = $_SESSION[$ses_id]["export_conf_cnt_rec"]; 
            $percent = round($num_rec / $cnt_rec * 100); 
            $file_mode = "a"; 
        } else { 
            $start_rec = 0; 
            $num_rec = 0; 
            $cnt_rec = 0; 
            $percent = 0; 
            foreach ($tables as $table_id) { 
                $result = data_select_field($table_id, "count(*) as cnt"); 
                $row = sql_fetch_assoc($result); 
                $cnt_rec += $row["cnt"]; 
            } 
            $file_mode = "w"; 
        } 
        $smarty->assign("progress_bar", 1); 
        $smarty->assign("progress_text", $lang["exex_data_export"]); 
        $smarty->assign("percent", $percent); 
        $smarty->assign("cur_title", $lang["Addons"]); 
        $smarty->display("templates/edit_transfer.tpl"); 
        include "index_bottom.php"; 
        $flush_str = str_repeat(" ", 5000); 
        echo $flush_str; 
        @ob_flush(); 
        flush(); 
        @mkdir("temp/files"); 
        $fp = fopen($tmp_dat_file, $file_mode); 
        foreach ($tables as $i => $table_id) { 
            $fields = []; 
            $result = sql_select(FIELDS_TABLE, "table_id=", $table_id, " ORDER BY field_num"); 
            while ($one_field = sql_fetch_assoc($result)) { 
                $one_field["int_name"] = form_int_name($one_field["id"]); 
                $fields[] = $one_field; 
            } 
            $result = data_select($table_id, "1=1 LIMIT 1000000000 OFFSET " . $start_rec); 
            while ($row = sql_fetch_assoc($result)) { 
                $num_rec++; 
                $start_rec++; 
                $c_part_done = round($num_rec / $cnt_rec * 100); 
                if ($part_done < $c_part_done) { 
                    $part_done = $c_part_done; 
                    echo "<script type='text/javascript'>document.getElementById('backup_bar').style.width = '" . $part_done . "%';</script>"; 
                    echo "<script type='text/javascript'>document.getElementById('backup_progress').innerHTML = '" . $part_done . "%';</script>"; 
                    echo $flush_str; 
                    @ob_flush(); 
                    flush(); 
                } 
                $num_col = 0; 
                $line = [$table_id]; 
                foreach ($fields as $one_field) { 
                    $num_col++; 
                    $line[] = $row[$one_field["int_name"]]; 
                    if (($one_field["type_field"] == 6 || $one_field["type_field"] == 9) && $row[$one_field["int_name"]]) { 
                        $files = explode("
", $row[$one_field["int_name"]]); 
                        foreach ($files as $num_file => $fname) { 
                            $fpath = get_file_path($one_field["id"], $row["id"], $fname); 
                            copy($fpath, "temp/files/" . $num_rec . "_" . $num_col . "_" . $num_file); 
                        } 
                    } 
                } 
                fputs($fp, json_encode($line, 50400 <= PHP_VERSION_ID ? JSON_UNESCAPED_UNICODE : 0) . "
"); 
                if ($max_exec_time - 20 < time() - $start_time) { 
                    $_SESSION[$ses_id]["export_conf_table_data"] = $tables; 
                    $_SESSION[$ses_id]["export_conf_start_rec"] = $start_rec; 
                    $_SESSION[$ses_id]["export_conf_num_rec"] = $num_rec; 
                    $_SESSION[$ses_id]["export_conf_cnt_rec"] = $cnt_rec; 
                    echo "<script>location.href='edit_transfer.php'</script>"; 
                    exit; 
                } 
            } 
            $start_rec = 0; 
            unset($tables[$i]); 
        } 
        fclose($fp); 
        $_SESSION[$ses_id]["export_conf_table_data"] = 0; 
        $_SESSION[$ses_id]["export_conf_start_rec"] = 0; 
        $_SESSION[$ses_id]["export_conf_num_rec"] = 0; 
        $_SESSION[$ses_id]["export_conf_cnt_rec"] = 0; 
        $_SESSION[$ses_id]["export_conf_complete"] = 1; 
        echo "<script>location.href='edit_transfer.php'</script>"; 
        exit; 
    } else { 
        if (isset($_GET["export_unload"])) { 
            $zip = new ZipArchive(); 
            $zip->open($tmp_zip_file, ZipArchive::CREATE); 
            $zip->addFile($tmp_cnf_file, "structure.json"); 
            if (file_exists($tmp_dat_file)) { 
                $zip->addFile($tmp_dat_file, "data.json"); 
            } 
            foreach (glob("temp/files/*") as $filename) { 
                $zip->addFile($filename, "files/" . basename($filename)); 
            } 
            $result = sql_select(EXT_FILES); 
            while ($row = sql_fetch_assoc($result)) { 
                if (substr($row["name"], 0, 7) == "addons/") { 
                    $file_path = form_path($row["name"]); 
                    if (file_exists($file_path) && is_file($file_path)) { 
                        $zip->addFile($file_path, "ext_files/" . substr($row["name"], 7)); 
                    } 
                } 
            } 
            $zip->close(); 
            $filename = $_SESSION[$ses_id]["export_conf_file_name"]; 
            if ($config["ie"]) { 
                $filename = rawurlencode($filename); 
            } 
            header("Content-Disposition: attachment; filename=\"" . $filename . ".add.zip\""); 
            header("Content-type: text/x-comma-separated-values"); 
            readfile($tmp_zip_file); 
            @unlink($tmp_cnf_file); 
            @unlink($tmp_dat_file); 
            @unlink($tmp_zip_file); 
            foreach (glob("temp/files/*") as $filename) { 
                unlink($filename); 
            } 
            @rmdir("temp/files"); 
            exit; 
        } else { 
            if (isset($_GET["install"]) || isset($_GET["reset"])) { 
                $_POST["import"] = 1; 
                $_POST["addon"] = $_GET["addon"]; 
            } 
            if (isset($_POST["import"]) || isset($_POST["reset"])) { 
                if ($_POST["addon"]) { 
                    if ($account) { 
                        $result = send_asterisk_curl("https://market." . CLIENTBASE_DOMAIN . "/add_addon.php?account=" . urlencode($account) . "&addon=" . $_POST["addon"]); 
                        if (!$result["success"]) { 
                            _obfuscated_0D24403B3238133B0B020A390C16062F042B3025233B22_($lang["Rent_addon_error"]); 
                        } 
                    } else { 
                        if ($shop_addons[$_POST["addon"]]["price"] < 0) { 
                            _obfuscated_0D24403B3238133B0B020A390C16062F042B3025233B22_($lang["Rent_addon_error"]); 
                        } 
                    } 
                    $addon_name = $shop_addons[$_POST["addon"]]["name"]; 
                    $content = send_asterisk_curl("https://market." . CLIENTBASE_DOMAIN . "/get_addon_file.php?id=" . $_POST["addon"]); 
                    file_put_contents($tmp_zip_file, $content); 
                    $_SESSION[$ses_id]["import_conf_market_addon"] = true; 
                } else { 
                    if ($_FILES["upload_file"]["name"]) { 
                        if (!$rGWthLqiHe && $config["can_add_table"] != "H7n8JFPWndue" && $config["can_add_table"] != "BkZUkaDiPOFw" && $config["can_add_table"] != "p4NgeRBauHwM") { 
                            _obfuscated_0D24403B3238133B0B020A390C16062F042B3025233B22_($lang["Add_table_free_limit"]); 
                        } 
                        $addon_name = substr($_FILES["upload_file"]["name"], 0, strpos($_FILES["upload_file"]["name"], ".")); 
                        rename($_FILES["upload_file"]["tmp_name"], $tmp_zip_file); 
                        $_SESSION[$ses_id]["import_conf_market_addon"] = false; 
                    } else { 
                        _obfuscated_0D24403B3238133B0B020A390C16062F042B3025233B22_($lang["Not_selected_file"]); 
                    } 
                } 
                $_SESSION[$ses_id]["import_conf_addon_name"] = $addon_name; 
                $addon = sql_select_array(ADDONS_TABLE, "name = '", $addon_name, "'"); 
                if ($addon) { 
                    $_SESSION[$ses_id]["import_conf_addon_id"] = $addon["id"]; 
                    if (!$config["no_auto_save_backup"] && !isset($_REQUEST["reset"])) { 
                        create_backup("backup/" . date("Y-m-d_H-i-s") . ".zip"); 
                    } 
                } 
                $result = import_addon_prepare($addon); 
                extract($result); 
                if ($error) { 
                    _obfuscated_0D24403B3238133B0B020A390C16062F042B3025233B22_($error); 
                } 
                $_SESSION[$ses_id]["import_conf_categories"] = $categories; 
                $_SESSION[$ses_id]["import_conf_old_cats"] = $old_cats; 
                $_SESSION[$ses_id]["import_conf_old_tables"] = $old_tables; 
                $_SESSION[$ses_id]["import_conf_old_fields"] = $old_fields; 
                $_SESSION[$ses_id]["import_conf_old_max_id"] = $old_max_id; 
                $_SESSION[$ses_id]["import_conf_link_fields"] = $link_fields; 
                $_SESSION[$ses_id]["import_conf_addon_groups"] = $addon_groups; 
                $_SESSION[$ses_id]["import_conf_addon_settings"] = $addon_settings; 
                $_SESSION[$ses_id]["import_conf_install_code"] = $install_code; 
                $_SESSION[$ses_id]["import_conf_uninstall_code"] = $uninstall_code; 
                $_SESSION[$ses_id]["import_conf_sel_groups"] = $old_sel_groups; 
                $_SESSION[$ses_id]["import_conf_wazzup_settings"] = $wazzup_settings; 
                if ($link_fields || $addon_groups) { 
                    if (!isset($_GET["ajax"])) { 
                        header("Location: edit_transfer.php?set"); 
                    } 
                    exit; 
                } 
                $_POST["import_continue"] = 1; 
                $_POST["sel_links"] = $old_sel_links; 
                $_POST["sel_groups"] = $old_sel_groups; 
            } 
            if (isset($_GET["set"])) { 
                $result = sql_select(TABLES_TABLE, "1=1 ORDER BY name_table"); 
                while ($one_table = sql_fetch_assoc($result)) { 
                    $result2 = sql_select(FIELDS_TABLE, "table_id = ", $one_table["id"], " ORDER BY field_num"); 
                    while ($one_field = sql_fetch_assoc($result2)) { 
                        $sel_fields[$one_field["id"]] = $one_table["name_table"] . "." . $one_field["name_field"]; 
                    } 
                } 
                $result = sql_select(GROUPS_TABLE, "id!=777 ORDER BY name"); 
                while ($row = sql_fetch_assoc($result)) { 
                    $sel_groups[$row["id"]] = $row["name"]; 
                } 
                $smarty->assign("sel_fields", $sel_fields); 
                $smarty->assign("sel_groups", $sel_groups); 
                $smarty->assign("link_fields", $_SESSION[$ses_id]["import_conf_link_fields"]); 
                $smarty->assign("addon_groups", $_SESSION[$ses_id]["import_conf_addon_groups"]); 
                $smarty->assign("addon_name", $_SESSION[$ses_id]["import_conf_addon_name"]); 
                $smarty->assign("cur_title", $lang["Addons"]); 
                $smarty->display("templates/edit_transfer.tpl"); 
                include "index_bottom.php"; 
                exit; 
            } 
            if ($_POST["import_continue"]) { 
                if ($_POST["install_addon_mode"] == "user") { 
                    header("Location: edit_transfer.php?set&mode=user"); 
                    exit; 
                } 
                if ($_SESSION[$ses_id]["import_conf_addon_id"]) { 
                    _obfuscated_0D255C3126152906151E181D1E0E29393E033F1E331532_($_SESSION[$ses_id]["import_conf_addon_id"], 0); 
                    insert_log("admin", $lang["System"] . " " . $lang["log_auto_delete_prev_addon"] . " \"" . $_SESSION[$ses_id]["import_conf_addon_name"] . "\""); 
                } 
                $addon_id = sql_insert(ADDONS_TABLE, ["name" => $_SESSION[$ses_id]["import_conf_addon_name"], "revision" => date("Y-m-d H:i:s")]); 
                $addon_groups = $_SESSION[$ses_id]["import_conf_addon_groups"]; 
                $new_groups = []; 
                $_POST["sel_groups"] = $_POST["sel_groups"] ?? $_SESSION[$ses_id]["import_conf_sel_groups"]; 
                foreach ($_POST["sel_groups"] as $old_group_id => $sel_groups) { 
                    foreach ($sel_groups as $new_group_id) { 
                        if ($new_group_id == -1) { 
                            $new_group_id = sql_insert(GROUPS_TABLE, $addon_groups[$old_group_id]); 
                            $ins_groups[] = $new_group_id; 
                        } 
                        if ($new_group_id) { 
                            $new_groups[$old_group_id][] = $new_group_id; 
                            sql_insert(ADDON_GROUPS_TABLE, ["addon_id" => $addon_id, "old_group_id" => $old_group_id, "new_group_id" => $new_group_id]); 
                            $mapped[$old_group_id] = 1; 
                        } 
                    } 
                    if (!$mapped[$old_group_id]) { 
                        sql_insert(ADDON_GROUPS_TABLE, ["addon_id" => $addon_id, "old_group_id" => $old_group_id, "new_group_id" => 0]); 
                    } 
                } 
                $new_groups[777][0] = 777; 
                $import_data = ["categories" => $_SESSION[$ses_id]["import_conf_categories"], "old_cats" => $_SESSION[$ses_id]["import_conf_old_cats"], "old_tables" => $_SESSION[$ses_id]["import_conf_old_tables"], "old_fields" => $_SESSION[$ses_id]["import_conf_old_fields"], "old_max_id" => $_SESSION[$ses_id]["import_conf_old_max_id"], "link_fields" => $_SESSION[$ses_id]["import_conf_link_fields"], "install_code" => $_SESSION[$ses_id]["import_conf_install_code"], "uninstall_code" => $_SESSION[$ses_id]["import_conf_uninstall_code"], "wazzup_settings" => $_SESSION[$ses_id]["import_conf_wazzup_settings"], "old_sel_links" => $_POST["sel_links"], "new_groups" => $new_groups, "ins_groups" => $ins_groups]; 
                $import_result = import_addon_install($addon_id, $import_data, $_SESSION[$ses_id]["import_conf_market_addon"]); 
                $addon_settings = $_SESSION[$ses_id]["import_conf_addon_settings"]; 
                if (file_exists($tmp_dat_file)) { 
                    $_SESSION[$ses_id]["import_conf_table_data"] = $import_result["new_tables"]; 
                    $_SESSION[$ses_id]["import_conf_addon_settings"] = $import_result["new_reports"][$addon_settings]; 
                } else { 
                    if ($_SESSION[$ses_id]["import_conf_addon_id"]) { 
                        insert_log("admin", $lang["Administrator"] . " " . form_display($user["fio"]) . " " . $lang["log_update_addon"] . " \"" . $_SESSION[$ses_id]["import_conf_addon_name"] . "\""); 
                    } else { 
                        insert_log("admin", $lang["Administrator"] . " " . form_display($user["fio"]) . " " . $lang["log_install_addon"] . " \"" . $_SESSION[$ses_id]["import_conf_addon_name"] . "\""); 
                    } 
                    if ($addon_settings) { 
                        $redirect = "report.php?id=" . $import_result["new_reports"][$addon_settings]; 
                    } else { 
                        $redirect = "edit_transfer.php"; 
                    } 
                    $_SESSION[$ses_id]["import_conf_table_data"] = 0; 
                    $_SESSION[$ses_id]["import_conf_file_pos"] = 0; 
                    $_SESSION[$ses_id]["import_conf_file_size"] = 0; 
                    $_SESSION[$ses_id]["import_conf_addon_settings"] = 0; 
                    $_SESSION[$ses_id]["import_conf_addon_id"] = 0; 
                    $_SESSION[$ses_id]["import_conf_addon_name"] = ""; 
                    echo "<script>location.href='" . $redirect . "'</script>"; 
                    exit; 
                } 
            } 
            if ($_SESSION[$ses_id]["import_conf_table_data"]) { 
                $start_time = time(); 
                $max_exec_time = $config["type"] == "SAAS" ? 240 : ini_get("max_execution_time"); 
                if (240 < $max_exec_time) { 
                    $max_exec_time = 240; 
                } 
                if ($max_exec_time < 30) { 
                    $max_exec_time = 30; 
                } 
                $new_tables = $_SESSION[$ses_id]["import_conf_table_data"]; 
                if ($_SESSION[$ses_id]["import_conf_file_pos"]) { 
                    $num_rec = $_SESSION[$ses_id]["import_conf_num_rec"]; 
                    $file_pos = $_SESSION[$ses_id]["import_conf_file_pos"]; 
                    $file_size = $_SESSION[$ses_id]["import_conf_file_size"]; 
                } else { 
                    $num_rec = 0; 
                    $file_pos = 0; 
                    $file_size = filesize($tmp_dat_file); 
                } 
                if (!isset($_GET["ajax"])) { 
                    $smarty->assign("progress_bar", 1); 
                    $smarty->assign("progress_text", $lang["exex_data_import"]); 
                    $smarty->assign("percent", round($file_pos / $file_size * 100)); 
                    $smarty->assign("cur_title", $lang["Addons"]); 
                    $smarty->display("templates/edit_transfer.tpl"); 
                    include "index_bottom.php"; 
                    $flush_str = str_repeat(" ", 5000); 
                    echo $flush_str; 
                    @ob_flush(); 
                    flush(); 
                } 
                if (($fp = fopen($tmp_dat_file, "r")) !== false) { 
                    fseek($fp, $file_pos); 
                    while (($line = fgets($fp)) !== false) { 
                        $num_rec++; 
                        $file_pos = ftell($fp); 
                        $c_part_done = round($file_pos / $file_size * 100); 
                        if ($part_done < $c_part_done && !isset($_GET["ajax"])) { 
                            $part_done = $c_part_done; 
                            echo "<script type='text/javascript'>document.getElementById('backup_bar').style.width = '" . $part_done . "%';</script>"; 
                            echo "<script type='text/javascript'>document.getElementById('backup_progress').innerHTML = '" . $part_done . "%';</script>"; 
                            echo $flush_str; 
                            @ob_flush(); 
                            flush(); 
                        } 
                        $line = json_decode($line); 
                        $new_table_id = $new_tables[$line[0]]; 
                        unset($line[0]); 
                        if (!$fields[$new_table_id]) { 
                            $result = sql_select_field(FIELDS_TABLE, "id", "table_id=", $new_table_id, " ORDER BY field_num"); 
                            while ($one_field = sql_fetch_assoc($result)) { 
                                $fields[$new_table_id][] = $one_field["id"]; 
                            } 
                        } 
                        $line["r"] = 0; 
                        $line["u"] = 0; 
                        foreach ($line as $num_col => &$value) { 
                            if (file_exists("temp/files/" . $num_rec . "_" . $num_col . "_0")) { 
                                $files = explode("
", $value); 
                                foreach ($files as $num_file => $fname) { 
                                    $content = file_get_contents("temp/files/" . $num_rec . "_" . $num_col . "_" . $num_file); 
                                    save_data_file($fields[$new_table_id][$num_col - 1], $line[1], $fname, $content); 
                                    unlink("temp/files/" . $num_rec . "_" . $num_col . "_" . $num_file); 
                                } 
                            } 
                            $value = form_sql($value); 
                        } 
                        @sql_query("INSERT INTO " . DATA_TABLE . $new_table_id . " VALUES ('" . @implode("','", $line) . "')"); 
                        if ($max_exec_time - 20 < time() - $start_time) { 
                            $_SESSION[$ses_id]["import_conf_num_rec"] = $num_rec; 
                            $_SESSION[$ses_id]["import_conf_file_pos"] = $file_pos; 
                            $_SESSION[$ses_id]["import_conf_file_size"] = $file_size; 
                            echo "<script>location.href='edit_transfer.php" . (isset($_GET["ajax"]) ? "&ajax" : "") . "'</script>"; 
                            exit; 
                        } 
                    } 
                    fclose($fp); 
                    unlink($tmp_dat_file); 
                    @rmdir("temp/files"); 
                } 
                if ($_SESSION[$ses_id]["import_conf_addon_id"]) { 
                    insert_log("admin", $lang["Administrator"] . " " . form_display($user["fio"]) . " " . $lang["log_update_addon"] . " \"" . $_SESSION[$ses_id]["import_conf_addon_name"] . "\""); 
                } else { 
                    insert_log("admin", $lang["Administrator"] . " " . form_display($user["fio"]) . " " . $lang["log_install_addon"] . " \"" . $_SESSION[$ses_id]["import_conf_addon_name"] . "\""); 
                } 
                if ($_SESSION[$ses_id]["import_conf_addon_settings"]) { 
                    $redirect = "report.php?id=" . $_SESSION[$ses_id]["import_conf_addon_settings"]; 
                } else { 
                    $redirect = "edit_transfer.php"; 
                } 
                $_SESSION[$ses_id]["import_conf_table_data"] = 0; 
                $_SESSION[$ses_id]["import_conf_num_rec"] = 0; 
                $_SESSION[$ses_id]["import_conf_file_pos"] = 0; 
                $_SESSION[$ses_id]["import_conf_file_size"] = 0; 
                $_SESSION[$ses_id]["import_conf_addon_settings"] = 0; 
                $_SESSION[$ses_id]["import_conf_addon_id"] = 0; 
                $_SESSION[$ses_id]["import_conf_addon_name"] = ""; 
                echo "<script>location.href='" . $redirect . "'</script>"; 
                exit; 
            } 
            if ($_POST["settings"]) { 
                sql_update(CONFIG_TABLE, ["value" => $_POST["autoupdate_addons"] ? 1 : 0], " name='autoupdate_addons'"); 
                $result = json_decode(send_asterisk_curl("https://market." . CLIENTBASE_DOMAIN . "/addons_set.php?account=" . urlencode($account) . "&autodelete=" . ($_POST["no_autodelete_addons"] ? 0 : 1)), 1); 
                if ($result["success"]) { 
                    sql_update(CONFIG_TABLE, ["value" => $_POST["no_autodelete_addons"] ? 1 : 0], " name='no_autodelete_addons'"); 
                } 
                update_run_flags("config"); 
                $_SESSION[$ses_id]["save_settings_complete"] = 1; 
                header("Location: edit_transfer.php"); 
                exit; 
            } 
            if ($_POST["base_names"]) { 
                foreach ($_POST["base_names"] as $id => $field_id) { 
                    sql_update(BASE_NAMES_TABLE, ["field_id" => $field_id], "id = ", $id); 
                } 
                header("Location: edit_transfer.php"); 
                exit; 
            } else { 
                $all_cats = []; 
                $sub_cats = []; 
                $sub_ccats = []; 
                $sub_tables = []; 
                $sub_ctables = []; 
                $result = sql_select(CATS_TABLE, "1=1 ORDER BY num"); 
                while ($one_cat = sql_fetch_assoc($result)) { 
                    $result2 = sql_select(TABLES_TABLE, "cat_id=", $one_cat["id"]); 
                    while ($one_table = sql_fetch_assoc($result2)) { 
                        if (!($user["sub_admin"] && $user["sub_admin_rights"]["tables"][$one_table["id"]] != 2)) { 
                            $result3 = sql_select(ADDON_PARTS_TABLE, "part_type = 'table' and part_id = ", $one_table["id"]); 
                            if (!sql_num_rows($result3)) { 
                                $one_cat["tables"][] = $one_table; 
                                $result3 = sql_select(SUBTABLES_TABLE, "table_id=", $one_table["id"]); 
                                while ($subtable = sql_fetch_assoc($result3)) { 
                                    $sub_table = sql_select_array(TABLES_TABLE, "id=", $subtable["link_table_id"]); 
                                    if ($sub_table["cat_id"] != $one_cat["id"]) { 
                                        $sub_cats[$sub_table["cat_id"]][] = $one_table["id"]; 
                                        $sub_ccats[$sub_table["cat_id"]][] = $one_cat["id"]; 
                                        $sub_ctables[$sub_table["id"]][] = $one_cat["id"]; 
                                    } 
                                    if ($sub_table["id"] != $one_table["id"]) { 
                                        $sub_tables[$sub_table["id"]][] = $one_table["id"]; 
                                    } 
                                } 
                            } 
                        } 
                    } 
                    $result2 = sql_select(REPORTS_TABLE, "cat_id=", $one_cat["id"]); 
                    while ($one_report = sql_fetch_assoc($result2)) { 
                        if (!($user["sub_admin"] && $user["sub_admin_rights"]["reports"][$one_report["id"]] != 2)) { 
                            $result3 = sql_select(ADDON_PARTS_TABLE, "part_type = 'report' and part_id = ", $one_report["id"]); 
                            if (!sql_num_rows($result3)) { 
                                $one_cat["reports"][] = $one_report; 
                            } 
                        } 
                    } 
                    $result2 = sql_select(CALENDARS_TABLE, "cat_id=", $one_cat["id"]); 
                    while ($one_calendar = sql_fetch_assoc($result2)) { 
                        if (!($user["sub_admin"] && $user["sub_admin_rights"]["calendars"][$one_calendar["id"]] != 2)) { 
                            $result3 = sql_select(ADDON_PARTS_TABLE, "part_type = 'calendar' and part_id = ", $one_calendar["id"]); 
                            if (!sql_num_rows($result3)) { 
                                $one_cat["calendars"][] = $one_calendar; 
                                $result3 = sql_select(CALENDAR_EVENTS, "calendar_id=", $one_calendar["id"]); 
                                while ($event = sql_fetch_assoc($result3)) { 
                                    $sub_table = sql_select_array(TABLES_TABLE, "id=", $event["table_id"]); 
                                    if ($sub_table["cat_id"] != $one_cat["id"]) { 
                                        $ev_cats[$sub_table["cat_id"]][] = $one_calendar["id"]; 
                                        $sub_ccats[$sub_table["cat_id"]][] = $one_cat["id"]; 
                                        $sub_ctables[$sub_table["id"]][] = $one_cat["id"]; 
                                    } 
                                    $ev_tables[$sub_table["id"]][] = $one_calendar["id"]; 
                                } 
                            } 
                        } 
                    } 
                    if ($one_cat["tables"] || $one_cat["reports"] || $one_cat["calendars"]) { 
                        $all_cats[] = $one_cat; 
                    } 
                } 
                foreach ($shop_addons as $shop_addon_id => $shop_addon) { 
                    $addon = sql_select_array(ADDONS_TABLE, "name = '", $shop_addon["name"], "'"); 
                    if (!$addon) { 
                        if ($shop_addon["rented"]) { 
                            $result = json_decode(send_asterisk_curl("https://market." . CLIENTBASE_DOMAIN . "/del_rent_addon.php?account=" . urlencode($account) . "&addon=" . $shop_addon_id), 1); 
                            if ($result["success"]) { 
                                $shop_addons[$shop_addon_id]["rented"] = 0; 
                            } 
                        } else { 
                            if ($shop_addon["added"] && !$shop_addon["bought"]) { 
                                $result = json_decode(send_asterisk_curl("https://market." . CLIENTBASE_DOMAIN . "/del_addon.php?account=" . urlencode($account) . "&addon=" . $shop_addon_id), 1); 
                                if ($result["success"]) { 
                                    $shop_addons[$shop_addon_id]["added"] = 0; 
                                } 
                            } 
                        } 
                    } 
                } 
                $cur_addons = sql_select_array(ADDONS_TABLE, "ALL_ROWS", "inactive = 0"); 
                foreach ($shop_addons as $shop_id => $shop_addon) { 
                    $shop_addon["shop_id"] = $shop_id; 
                    foreach ($cur_addons as $id => $cur_addon) { 
                        if ($shop_addon["name"] == $cur_addon["name"] && !$cur_addon["inactive"]) { 
                            $shop_addon["id"] = $cur_addon["id"]; 
                            $shop_addon["installed"] = 1; 
                            if ($cur_addon["revision"] < $shop_addon["revision"] && ($shop_addon["bought"] || $shop_addon["rented"] || !$shop_addon["price"] && !$shop_addon["rent_sum"])) { 
                                $shop_addon["new"] = 1; 
                            } 
                            if ($shop_addon["rented"]) { 
                                $total_rent_sum += $shop_addon["rent_sum"]; 
                            } 
                            unset($cur_addons[$id]); 
                        } 
                    } 
                    $all_addons[] = $shop_addon; 
                } 
                foreach ($cur_addons as $one_addon) { 
                    $one_addon["installed"] = 1; 
                    $all_addons[] = $one_addon; 
                } 
                foreach ($all_addons as &$one_addon) { 
                    if ($one_addon["installed"]) { 
                        $row = sql_select_array(ADDON_PARTS_TABLE, "addon_id = ", $one_addon["id"], " LIMIT 1"); 
                        if ($row["part_type"] == "table") { 
                            $one_addon["link"] = "fields.php?table=" . $row["part_id"]; 
                            list($one_addon["cat_id"]) = sql_fetch_row(sql_select_field(TABLES_TABLE, "cat_id", "id = ", $row["part_id"])); 
                        } else { 
                            if ($row["part_type"] == "report") { 
                                $one_addon["link"] = "report.php?id=" . $row["part_id"]; 
                                list($one_addon["cat_id"]) = sql_fetch_row(sql_select_field(REPORTS_TABLE, "cat_id", "id = ", $row["part_id"])); 
                            } else { 
                                if ($row["part_type"] == "calendar") { 
                                    $one_addon["link"] = "calendar.php?id=" . $row["part_id"]; 
                                    list($one_addon["cat_id"]) = sql_fetch_row(sql_select_field(CALENDARS_TABLE, "cat_id", "id = ", $row["part_id"])); 
                                } 
                            } 
                        } 
                    } 
                } 
                $base_names = sql_select_array(BASE_NAMES_TABLE, "ALL_ROWS"); 
                $result = sql_select(TABLES_TABLE, "1=1 ORDER BY name_table"); 
                while ($one_table = sql_fetch_assoc($result)) { 
                    $result2 = sql_select(FIELDS_TABLE, "table_id = ", $one_table["id"], " ORDER BY field_num"); 
                    while ($one_field = sql_fetch_assoc($result2)) { 
                        $sel_fields[$one_field["id"]] = $one_table["name_table"] . "." . $one_field["name_field"]; 
                    } 
                } 
                if ($config["type"] == "SAAS") { 
                    $config["maxfilesize"] = 188743680; 
                } else { 
                    $config["maxfilesize"] = ini_get("upload_max_filesize"); 
                } 
                if ($_SESSION[$ses_id]["addon_error"]) { 
                    $smarty->assign($_SESSION[$ses_id]["addon_error"]["type"] . "_message", $_SESSION[$ses_id]["addon_error"]["text"]); 
                    $smarty->assign($_SESSION[$ses_id]["addon_error"]["type"] . "_message_color", "red"); 
                    unset($_SESSION[$ses_id]["addon_error"]); 
                } 
                if ($_SESSION[$ses_id]["export_conf_complete"]) { 
                    $smarty->assign("export_message", $lang["export_complete"]); 
                    $smarty->assign("export_message_color", "green"); 
                } 
                if ($_SESSION[$ses_id]["save_settings_complete"]) { 
                    $smarty->assign("settings_message", $lang["succes_settings_save"]); 
                    unset($_SESSION[$ses_id]["save_settings_complete"]); 
                } 
                if (isset($_GET["test"])) { 
                    if (!$rGWthLqiHe) { 
                        $_GET["addon"] = "free_version"; 
                    } 
                    $smarty->assign("test_addon", $_GET["addon"]); 
                } 
                if (!$rGWthLqiHe) { 
                    $smarty->assign("test_addon2", "free_version"); 
                } 
                $smarty->assign("test_addon", $_GET["addon"]); 
                $smarty->assign("config", $config); 
                $smarty->assign("all_cats", $all_cats); 
                $smarty->assign("sub_cats", $sub_cats); 
                $smarty->assign("sub_ccats", $sub_ccats); 
                $smarty->assign("sub_tables", $sub_tables); 
                $smarty->assign("sub_ctables", $sub_ctables); 
                $smarty->assign("ev_cats", $ev_cats); 
                $smarty->assign("ev_tables", $ev_tables); 
                $smarty->assign("all_addons", $all_addons); 
                $smarty->assign("base_names", $base_names); 
                $smarty->assign("sel_fields", $sel_fields); 
                $smarty->assign("total_rent_sum", $total_rent_sum); 
                $smarty->assign("cur_title", $lang["Addons"]); 
                $smarty->display("templates/edit_transfer.tpl"); 
                include "index_bottom.php"; 
                if ($_SESSION[$ses_id]["export_conf_complete"]) { 
                    echo "<script>location.href='edit_transfer.php?export_unload'</script>"; 
                    unset($_SESSION[$ses_id]["export_conf_complete"]); 
                } 
            } 
        } 
    } 
} 
function _obfuscated_0D24403B3238133B0B020A390C16062F042B3025233B22_($text) 
{ 
    if (isset($_GET["ajax"])) { 
        echo $text; 
        exit; 
    } 
    global $ses_id; 
    if ($_POST["export"]) { 
        $type = "export"; 
    } 
    if ($_POST["import"]) { 
        $type = "import"; 
    } 
    if ($_POST["addon"]) { 
        $type = "shop"; 
    } 
    if (isset($_POST["delete"])) { 
        $type = "cur_addons"; 
    } 
    $_SESSION[$ses_id]["addon_error"]["type"] = $type; 
    $_SESSION[$ses_id]["addon_error"]["text"] = $text; 
    header("Location: edit_transfer.php"); 
    exit; 
} 
 
?>

Did this file decode correctly?

Original Code

<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.0.6
 * @ Release: 10/08/2022
 */

include "common.php";
update_run_flags();
$smarty->assign("edit_page", "addons");
$tmp_cnf_file = $config["site_path"] . "/temp/structure.json";
$tmp_dat_file = $config["site_path"] . "/temp/data.json";
$tmp_zip_file = $config["site_path"] . "/temp/addon.zip";
$config["curl_timeout"] = 5000;
if ($config["type"] == "SAAS") {
    $row = @sql_select_array("saas_config", "`key` = 'login'");
    $account = $row["value"];
} else {
    $key_path = $config["site_path"] . "/runtime/key.php";
    $row["code"] = file_get_contents($key_path);
    $account = substr(key_decrypt($row["code"]), 16, 14);
}
$shop_addons = json_decode(send_asterisk_curl("https://market." . CLIENTBASE_DOMAIN . "/get_addons_list.php?account=" . urlencode($account)), 1);
if (isset($_POST["delete"])) {
    $addon_id = intval($_POST["addon"]);
    $addon = sql_select_array(ADDONS_TABLE, "id = ", $addon_id);
    if ($addon["uninstall_code"]) {
        eval($addon["uninstall_code"]);
    }
    $addon_parts = [];
    $result = sql_select(ADDON_PARTS_TABLE, "addon_id = ", $addon_id);
    while ($one_part = sql_fetch_assoc($result)) {
        $addon_parts[$one_part["part_type"]][$one_part["part_id"]] = 1;
    }
    foreach ($addon_parts["table"] as $table_id => $value) {
        $err_msg = test_delete_table($table_id, $addon_parts);
        if ($err_msg) {
            if ($err_msg) {
                $table = get_table($table_id);
                $err_msg = "<span style='color:red'><b>" . $lang["Table"] . " &laquo;" . $table["name_table"] . "&raquo; " . $lang["cant_removed"] . ".</b></span><br><br>" . $err_msg;
                _obfuscated_0D24403B3238133B0B020A390C16062F042B3025233B22_($err_msg);
            } else {
                foreach ($shop_addons as $shop_addon_id => $shop_addon) {
                    if ($addon["name"] == $shop_addon["name"] && $shop_addon["rented"]) {
                        $result = json_decode(send_asterisk_curl("https://market." . CLIENTBASE_DOMAIN . "/del_rent_addon.php?account=" . urlencode($account) . "&addon=" . $shop_addon_id), 1);
                        if (!$result["success"]) {
                            _obfuscated_0D24403B3238133B0B020A390C16062F042B3025233B22_($lang["Delete_rent_addon_error"]);
                        }
                    } else {
                        if ($addon["name"] == $shop_addon["name"] && !$shop_addon["bought"]) {
                            send_asterisk_curl("https://market." . CLIENTBASE_DOMAIN . "/del_addon.php?account=" . urlencode($account) . "&addon=" . $shop_addon_id);
                        }
                    }
                }
                _obfuscated_0D255C3126152906151E181D1E0E29393E033F1E331532_($addon_id);
                insert_log("admin", $lang["Administrator"] . " " . form_display($user["fio"]) . " " . $lang["log_delete_addon"] . " \"" . $addon["name"] . "\"");
                if (!isset($_GET["ajax"])) {
                    header("Location: edit_transfer.php");
                }
                exit;
            }
        }
    }
}
if (isset($_POST["unlock"])) {
    $addon_id = intval($_POST["addon"]);
    sql_delete(ADDONS_TABLE, "id = ", $addon_id);
    sql_delete(ADDON_PARTS_TABLE, "addon_id = ", $addon_id);
    header("Location: edit_transfer.php");
    exit;
}
if ($_POST["export"]) {
    if (!$_POST["sel_cat"]) {
        _obfuscated_0D24403B3238133B0B020A390C16062F042B3025233B22_($lang["No_select_for_export"]);
    }
    $exp_tables = [];
    foreach ($_POST["sel_cat"] as $sel_elem) {
        foreach ($sel_elem["tables"] as $table_id) {
            $exp_tables[$table_id] = 1;
        }
    }
    $export_conf = ["revision" => $config["revision"]];
    $link_fields = [];
    foreach ($_POST["sel_cat"] as $cat_id => $sel_elem) {
        $category["new_cat"] = $sel_elem["new_cat"] ? true : false;
        $category["category"] = sql_select_array(CATS_TABLE, "id=", $cat_id);
        $category["category"]["icon"] = base64_encode($category["category"]["icon"]);
        $category["category"]["icon2"] = base64_encode($category["category"]["icon2"]);
        $category["acc_cats"] = [];
        $result = sql_select(ACC_CATS_TABLE, "cat_id = ", $cat_id);
        while ($row = sql_fetch_assoc($result)) {
            $category["acc_cats"][] = $row;
        }
        $category["tables"] = [];
        foreach ($sel_elem["tables"] as $table_id) {
            if (!($user["sub_admin"] && $user["sub_admin_rights"]["tables"][$table_id] != 2)) {
                $category["tables"][] = export_table($table_id, $exp_tables);
                $result = sql_select(FIELDS_TABLE, "table_id=", $table_id, " and type_field = 5");
                while ($impr_field = sql_fetch_assoc($result)) {
                    list($link_table_id, $link_field_id) = explode("|", $impr_field["type_value"]);
                    if (!$exp_tables[$link_table_id]) {
                        $impr_table = sql_fetch_assoc(sql_select_field(TABLES_TABLE, "name_table", "id = ", $table_id));
                        $base_name = sql_select_array(BASE_NAMES_TABLE, "field_id = ", $link_field_id);
                        if ($base_name) {
                            $link_table["name_table"] = $base_name["name_table"];
                            $link_field["name_field"] = $base_name["name_field"];
                        } else {
                            $link_table = sql_fetch_assoc(sql_select_field(TABLES_TABLE, "name_table", "id = ", $link_table_id));
                            $link_field = sql_fetch_assoc(sql_select_field(FIELDS_TABLE, "name_field", "id = ", $link_field_id));
                        }
                        $link_fields[$impr_field["id"]]["impr_table"] = $impr_table["name_table"];
                        $link_fields[$impr_field["id"]]["impr_field"] = $impr_field["name_field"];
                        $link_fields[$impr_field["id"]]["impr_help"] = $impr_field["help"];
                        $link_fields[$impr_field["id"]]["link_table"] = $link_table["name_table"];
                        $link_fields[$impr_field["id"]]["link_field"] = $link_field["name_field"];
                    }
                }
            }
        }
        $category["reports"] = [];
        foreach ($sel_elem["reports"] as $report_id) {
            if (!($user["sub_admin"] && $user["sub_admin_rights"]["reports"][$report_id] != 2)) {
                if (!($report_id == $_POST["addons_install_code"] || $report_id == $_POST["addons_uninstall_code"])) {
                    $export_report["report"] = sql_select_array(REPORTS_TABLE, "id=", $report_id);
                    $export_report["acc_reports"] = [];
                    $result = sql_select(ACC_REPORTS_TABLE, "report_id=", $report_id);
                    while ($row = sql_fetch_assoc($result)) {
                        $export_report["acc_reports"][] = $row;
                    }
                    $category["reports"][] = $export_report;
                }
            }
        }
        $category["calendars"] = [];
        foreach ($sel_elem["calendars"] as $calendar_id) {
            if (!($user["sub_admin"] && $user["sub_admin_rights"]["calendars"][$calendar_id] != 2)) {
                $export_calendar["calendar"] = sql_select_array(CALENDARS_TABLE, "id=", $calendar_id);
                $export_calendar["acc_calendars"] = [];
                $result = sql_select(ACC_CALENDARS_TABLE, "calendar_id=", $calendar_id);
                while ($row = sql_fetch_assoc($result)) {
                    $export_calendar["acc_calendars"][] = $row;
                }
                $export_calendar["events"] = [];
                $export_calendar["fields"] = [];
                $result = sql_select(CALENDAR_EVENTS, "calendar_id=", $calendar_id);
                while ($row = sql_fetch_assoc($result)) {
                    if ($exp_tables[$row["table_id"]]) {
                        $export_calendar["events"][] = $row;
                        $result2 = sql_select(CALENDAR_FIELDS, "event_id=", $row["id"]);
                        while ($row2 = sql_fetch_assoc($result2)) {
                            $export_calendar["fields"][] = $row2;
                        }
                    }
                }
                $category["calendars"][] = $export_calendar;
            }
        }
        $export_conf["categories"][] = $category;
    }
    $export_conf["link_fields"] = $link_fields;
    $wazzup_settings = CB\core()->SETTINGS_MANAGER->get("cbext.clientbase.wazzup");
    $tips = $wazzup_settings["tips"] ?? [];
    foreach ($category["tables"] as $table) {
        foreach ($table["tips"] as $tip) {
            if (in_array($tip["id"], $tips)) {
                $export_conf["wazzup_settings"]["tips"][] = $tip["id"];
            }
        }
    }
    $result = sql_select(GROUPS_TABLE, "id != 1 AND id != 777");
    while ($row = sql_fetch_assoc($result)) {
        $group_id = $row["id"];
        unset($row["id"]);
        $export_conf["groups"][$group_id] = $row;
    }
    $export_conf["addons_settings"] = $_POST["addons_settings_report"] ?: "";
    if ($_POST["addons_install_code"]) {
        $result = sql_select_field(REPORTS_TABLE, "code", "id = ", $_POST["addons_install_code"]);
        $row = sql_fetch_assoc($result);
        $export_conf["install_code"] = $row["code"];
    }
    if ($_POST["addons_uninstall_code"]) {
        $result = sql_select_field(REPORTS_TABLE, "code", "id = ", $_POST["addons_uninstall_code"]);
        $row = sql_fetch_assoc($result);
        $export_conf["uninstall_code"] = $row["code"];
    }
    $json_export_conf = json_encode_visual($export_conf);
    if (json_last_error()) {
        _obfuscated_0D24403B3238133B0B020A390C16062F042B3025233B22_($lang["Error"] . ": " . _obfuscated_0D380316072234241A5C3707115C0F5B1B33343B393122_());
    }
    file_put_contents($tmp_cnf_file, $json_export_conf);
    $_SESSION[$ses_id]["export_conf_file_name"] = $_POST["file_name"];
    if ($_POST["table_data"]) {
        $_SESSION[$ses_id]["export_conf_table_data"] = $_POST["table_data"];
    } else {
        $_SESSION[$ses_id]["export_conf_complete"] = 1;
    }
    header("Location: edit_transfer.php");
    exit;
} else {
    if ($_SESSION[$ses_id]["export_conf_table_data"]) {
        $start_time = time();
        $max_exec_time = $config["type"] == "SAAS" ? 240 : ini_get("max_execution_time");
        if (240 < $max_exec_time) {
            $max_exec_time = 240;
        }
        if ($max_exec_time < 30) {
            $max_exec_time = 30;
        }
        $tables = $_SESSION[$ses_id]["export_conf_table_data"];
        if ($_SESSION[$ses_id]["export_conf_num_rec"]) {
            $start_rec = $_SESSION[$ses_id]["export_conf_start_rec"];
            $num_rec = $_SESSION[$ses_id]["export_conf_num_rec"];
            $cnt_rec = $_SESSION[$ses_id]["export_conf_cnt_rec"];
            $percent = round($num_rec / $cnt_rec * 100);
            $file_mode = "a";
        } else {
            $start_rec = 0;
            $num_rec = 0;
            $cnt_rec = 0;
            $percent = 0;
            foreach ($tables as $table_id) {
                $result = data_select_field($table_id, "count(*) as cnt");
                $row = sql_fetch_assoc($result);
                $cnt_rec += $row["cnt"];
            }
            $file_mode = "w";
        }
        $smarty->assign("progress_bar", 1);
        $smarty->assign("progress_text", $lang["exex_data_export"]);
        $smarty->assign("percent", $percent);
        $smarty->assign("cur_title", $lang["Addons"]);
        $smarty->display("templates/edit_transfer.tpl");
        include "index_bottom.php";
        $flush_str = str_repeat(" ", 5000);
        echo $flush_str;
        @ob_flush();
        flush();
        @mkdir("temp/files");
        $fp = fopen($tmp_dat_file, $file_mode);
        foreach ($tables as $i => $table_id) {
            $fields = [];
            $result = sql_select(FIELDS_TABLE, "table_id=", $table_id, " ORDER BY field_num");
            while ($one_field = sql_fetch_assoc($result)) {
                $one_field["int_name"] = form_int_name($one_field["id"]);
                $fields[] = $one_field;
            }
            $result = data_select($table_id, "1=1 LIMIT 1000000000 OFFSET " . $start_rec);
            while ($row = sql_fetch_assoc($result)) {
                $num_rec++;
                $start_rec++;
                $c_part_done = round($num_rec / $cnt_rec * 100);
                if ($part_done < $c_part_done) {
                    $part_done = $c_part_done;
                    echo "<script type='text/javascript'>document.getElementById('backup_bar').style.width = '" . $part_done . "%';</script>";
                    echo "<script type='text/javascript'>document.getElementById('backup_progress').innerHTML = '" . $part_done . "%';</script>";
                    echo $flush_str;
                    @ob_flush();
                    flush();
                }
                $num_col = 0;
                $line = [$table_id];
                foreach ($fields as $one_field) {
                    $num_col++;
                    $line[] = $row[$one_field["int_name"]];
                    if (($one_field["type_field"] == 6 || $one_field["type_field"] == 9) && $row[$one_field["int_name"]]) {
                        $files = explode("\r\n", $row[$one_field["int_name"]]);
                        foreach ($files as $num_file => $fname) {
                            $fpath = get_file_path($one_field["id"], $row["id"], $fname);
                            copy($fpath, "temp/files/" . $num_rec . "_" . $num_col . "_" . $num_file);
                        }
                    }
                }
                fputs($fp, json_encode($line, 50400 <= PHP_VERSION_ID ? JSON_UNESCAPED_UNICODE : 0) . "\n");
                if ($max_exec_time - 20 < time() - $start_time) {
                    $_SESSION[$ses_id]["export_conf_table_data"] = $tables;
                    $_SESSION[$ses_id]["export_conf_start_rec"] = $start_rec;
                    $_SESSION[$ses_id]["export_conf_num_rec"] = $num_rec;
                    $_SESSION[$ses_id]["export_conf_cnt_rec"] = $cnt_rec;
                    echo "<script>location.href='edit_transfer.php'</script>";
                    exit;
                }
            }
            $start_rec = 0;
            unset($tables[$i]);
        }
        fclose($fp);
        $_SESSION[$ses_id]["export_conf_table_data"] = 0;
        $_SESSION[$ses_id]["export_conf_start_rec"] = 0;
        $_SESSION[$ses_id]["export_conf_num_rec"] = 0;
        $_SESSION[$ses_id]["export_conf_cnt_rec"] = 0;
        $_SESSION[$ses_id]["export_conf_complete"] = 1;
        echo "<script>location.href='edit_transfer.php'</script>";
        exit;
    } else {
        if (isset($_GET["export_unload"])) {
            $zip = new ZipArchive();
            $zip->open($tmp_zip_file, ZipArchive::CREATE);
            $zip->addFile($tmp_cnf_file, "structure.json");
            if (file_exists($tmp_dat_file)) {
                $zip->addFile($tmp_dat_file, "data.json");
            }
            foreach (glob("temp/files/*") as $filename) {
                $zip->addFile($filename, "files/" . basename($filename));
            }
            $result = sql_select(EXT_FILES);
            while ($row = sql_fetch_assoc($result)) {
                if (substr($row["name"], 0, 7) == "addons/") {
                    $file_path = form_path($row["name"]);
                    if (file_exists($file_path) && is_file($file_path)) {
                        $zip->addFile($file_path, "ext_files/" . substr($row["name"], 7));
                    }
                }
            }
            $zip->close();
            $filename = $_SESSION[$ses_id]["export_conf_file_name"];
            if ($config["ie"]) {
                $filename = rawurlencode($filename);
            }
            header("Content-Disposition: attachment; filename=\"" . $filename . ".add.zip\"");
            header("Content-type: text/x-comma-separated-values");
            readfile($tmp_zip_file);
            @unlink($tmp_cnf_file);
            @unlink($tmp_dat_file);
            @unlink($tmp_zip_file);
            foreach (glob("temp/files/*") as $filename) {
                unlink($filename);
            }
            @rmdir("temp/files");
            exit;
        } else {
            if (isset($_GET["install"]) || isset($_GET["reset"])) {
                $_POST["import"] = 1;
                $_POST["addon"] = $_GET["addon"];
            }
            if (isset($_POST["import"]) || isset($_POST["reset"])) {
                if ($_POST["addon"]) {
                    if ($account) {
                        $result = send_asterisk_curl("https://market." . CLIENTBASE_DOMAIN . "/add_addon.php?account=" . urlencode($account) . "&addon=" . $_POST["addon"]);
                        if (!$result["success"]) {
                            _obfuscated_0D24403B3238133B0B020A390C16062F042B3025233B22_($lang["Rent_addon_error"]);
                        }
                    } else {
                        if ($shop_addons[$_POST["addon"]]["price"] < 0) {
                            _obfuscated_0D24403B3238133B0B020A390C16062F042B3025233B22_($lang["Rent_addon_error"]);
                        }
                    }
                    $addon_name = $shop_addons[$_POST["addon"]]["name"];
                    $content = send_asterisk_curl("https://market." . CLIENTBASE_DOMAIN . "/get_addon_file.php?id=" . $_POST["addon"]);
                    file_put_contents($tmp_zip_file, $content);
                    $_SESSION[$ses_id]["import_conf_market_addon"] = true;
                } else {
                    if ($_FILES["upload_file"]["name"]) {
                        if (!$rGWthLqiHe && $config["can_add_table"] != "H7n8JFPWndue" && $config["can_add_table"] != "BkZUkaDiPOFw" && $config["can_add_table"] != "p4NgeRBauHwM") {
                            _obfuscated_0D24403B3238133B0B020A390C16062F042B3025233B22_($lang["Add_table_free_limit"]);
                        }
                        $addon_name = substr($_FILES["upload_file"]["name"], 0, strpos($_FILES["upload_file"]["name"], "."));
                        rename($_FILES["upload_file"]["tmp_name"], $tmp_zip_file);
                        $_SESSION[$ses_id]["import_conf_market_addon"] = false;
                    } else {
                        _obfuscated_0D24403B3238133B0B020A390C16062F042B3025233B22_($lang["Not_selected_file"]);
                    }
                }
                $_SESSION[$ses_id]["import_conf_addon_name"] = $addon_name;
                $addon = sql_select_array(ADDONS_TABLE, "name = '", $addon_name, "'");
                if ($addon) {
                    $_SESSION[$ses_id]["import_conf_addon_id"] = $addon["id"];
                    if (!$config["no_auto_save_backup"] && !isset($_REQUEST["reset"])) {
                        create_backup("backup/" . date("Y-m-d_H-i-s") . ".zip");
                    }
                }
                $result = import_addon_prepare($addon);
                extract($result);
                if ($error) {
                    _obfuscated_0D24403B3238133B0B020A390C16062F042B3025233B22_($error);
                }
                $_SESSION[$ses_id]["import_conf_categories"] = $categories;
                $_SESSION[$ses_id]["import_conf_old_cats"] = $old_cats;
                $_SESSION[$ses_id]["import_conf_old_tables"] = $old_tables;
                $_SESSION[$ses_id]["import_conf_old_fields"] = $old_fields;
                $_SESSION[$ses_id]["import_conf_old_max_id"] = $old_max_id;
                $_SESSION[$ses_id]["import_conf_link_fields"] = $link_fields;
                $_SESSION[$ses_id]["import_conf_addon_groups"] = $addon_groups;
                $_SESSION[$ses_id]["import_conf_addon_settings"] = $addon_settings;
                $_SESSION[$ses_id]["import_conf_install_code"] = $install_code;
                $_SESSION[$ses_id]["import_conf_uninstall_code"] = $uninstall_code;
                $_SESSION[$ses_id]["import_conf_sel_groups"] = $old_sel_groups;
                $_SESSION[$ses_id]["import_conf_wazzup_settings"] = $wazzup_settings;
                if ($link_fields || $addon_groups) {
                    if (!isset($_GET["ajax"])) {
                        header("Location: edit_transfer.php?set");
                    }
                    exit;
                }
                $_POST["import_continue"] = 1;
                $_POST["sel_links"] = $old_sel_links;
                $_POST["sel_groups"] = $old_sel_groups;
            }
            if (isset($_GET["set"])) {
                $result = sql_select(TABLES_TABLE, "1=1 ORDER BY name_table");
                while ($one_table = sql_fetch_assoc($result)) {
                    $result2 = sql_select(FIELDS_TABLE, "table_id = ", $one_table["id"], " ORDER BY field_num");
                    while ($one_field = sql_fetch_assoc($result2)) {
                        $sel_fields[$one_field["id"]] = $one_table["name_table"] . "." . $one_field["name_field"];
                    }
                }
                $result = sql_select(GROUPS_TABLE, "id!=777 ORDER BY name");
                while ($row = sql_fetch_assoc($result)) {
                    $sel_groups[$row["id"]] = $row["name"];
                }
                $smarty->assign("sel_fields", $sel_fields);
                $smarty->assign("sel_groups", $sel_groups);
                $smarty->assign("link_fields", $_SESSION[$ses_id]["import_conf_link_fields"]);
                $smarty->assign("addon_groups", $_SESSION[$ses_id]["import_conf_addon_groups"]);
                $smarty->assign("addon_name", $_SESSION[$ses_id]["import_conf_addon_name"]);
                $smarty->assign("cur_title", $lang["Addons"]);
                $smarty->display("templates/edit_transfer.tpl");
                include "index_bottom.php";
                exit;
            }
            if ($_POST["import_continue"]) {
                if ($_POST["install_addon_mode"] == "user") {
                    header("Location: edit_transfer.php?set&mode=user");
                    exit;
                }
                if ($_SESSION[$ses_id]["import_conf_addon_id"]) {
                    _obfuscated_0D255C3126152906151E181D1E0E29393E033F1E331532_($_SESSION[$ses_id]["import_conf_addon_id"], 0);
                    insert_log("admin", $lang["System"] . " " . $lang["log_auto_delete_prev_addon"] . " \"" . $_SESSION[$ses_id]["import_conf_addon_name"] . "\"");
                }
                $addon_id = sql_insert(ADDONS_TABLE, ["name" => $_SESSION[$ses_id]["import_conf_addon_name"], "revision" => date("Y-m-d H:i:s")]);
                $addon_groups = $_SESSION[$ses_id]["import_conf_addon_groups"];
                $new_groups = [];
                $_POST["sel_groups"] = $_POST["sel_groups"] ?? $_SESSION[$ses_id]["import_conf_sel_groups"];
                foreach ($_POST["sel_groups"] as $old_group_id => $sel_groups) {
                    foreach ($sel_groups as $new_group_id) {
                        if ($new_group_id == -1) {
                            $new_group_id = sql_insert(GROUPS_TABLE, $addon_groups[$old_group_id]);
                            $ins_groups[] = $new_group_id;
                        }
                        if ($new_group_id) {
                            $new_groups[$old_group_id][] = $new_group_id;
                            sql_insert(ADDON_GROUPS_TABLE, ["addon_id" => $addon_id, "old_group_id" => $old_group_id, "new_group_id" => $new_group_id]);
                            $mapped[$old_group_id] = 1;
                        }
                    }
                    if (!$mapped[$old_group_id]) {
                        sql_insert(ADDON_GROUPS_TABLE, ["addon_id" => $addon_id, "old_group_id" => $old_group_id, "new_group_id" => 0]);
                    }
                }
                $new_groups[777][0] = 777;
                $import_data = ["categories" => $_SESSION[$ses_id]["import_conf_categories"], "old_cats" => $_SESSION[$ses_id]["import_conf_old_cats"], "old_tables" => $_SESSION[$ses_id]["import_conf_old_tables"], "old_fields" => $_SESSION[$ses_id]["import_conf_old_fields"], "old_max_id" => $_SESSION[$ses_id]["import_conf_old_max_id"], "link_fields" => $_SESSION[$ses_id]["import_conf_link_fields"], "install_code" => $_SESSION[$ses_id]["import_conf_install_code"], "uninstall_code" => $_SESSION[$ses_id]["import_conf_uninstall_code"], "wazzup_settings" => $_SESSION[$ses_id]["import_conf_wazzup_settings"], "old_sel_links" => $_POST["sel_links"], "new_groups" => $new_groups, "ins_groups" => $ins_groups];
                $import_result = import_addon_install($addon_id, $import_data, $_SESSION[$ses_id]["import_conf_market_addon"]);
                $addon_settings = $_SESSION[$ses_id]["import_conf_addon_settings"];
                if (file_exists($tmp_dat_file)) {
                    $_SESSION[$ses_id]["import_conf_table_data"] = $import_result["new_tables"];
                    $_SESSION[$ses_id]["import_conf_addon_settings"] = $import_result["new_reports"][$addon_settings];
                } else {
                    if ($_SESSION[$ses_id]["import_conf_addon_id"]) {
                        insert_log("admin", $lang["Administrator"] . " " . form_display($user["fio"]) . " " . $lang["log_update_addon"] . " \"" . $_SESSION[$ses_id]["import_conf_addon_name"] . "\"");
                    } else {
                        insert_log("admin", $lang["Administrator"] . " " . form_display($user["fio"]) . " " . $lang["log_install_addon"] . " \"" . $_SESSION[$ses_id]["import_conf_addon_name"] . "\"");
                    }
                    if ($addon_settings) {
                        $redirect = "report.php?id=" . $import_result["new_reports"][$addon_settings];
                    } else {
                        $redirect = "edit_transfer.php";
                    }
                    $_SESSION[$ses_id]["import_conf_table_data"] = 0;
                    $_SESSION[$ses_id]["import_conf_file_pos"] = 0;
                    $_SESSION[$ses_id]["import_conf_file_size"] = 0;
                    $_SESSION[$ses_id]["import_conf_addon_settings"] = 0;
                    $_SESSION[$ses_id]["import_conf_addon_id"] = 0;
                    $_SESSION[$ses_id]["import_conf_addon_name"] = "";
                    echo "<script>location.href='" . $redirect . "'</script>";
                    exit;
                }
            }
            if ($_SESSION[$ses_id]["import_conf_table_data"]) {
                $start_time = time();
                $max_exec_time = $config["type"] == "SAAS" ? 240 : ini_get("max_execution_time");
                if (240 < $max_exec_time) {
                    $max_exec_time = 240;
                }
                if ($max_exec_time < 30) {
                    $max_exec_time = 30;
                }
                $new_tables = $_SESSION[$ses_id]["import_conf_table_data"];
                if ($_SESSION[$ses_id]["import_conf_file_pos"]) {
                    $num_rec = $_SESSION[$ses_id]["import_conf_num_rec"];
                    $file_pos = $_SESSION[$ses_id]["import_conf_file_pos"];
                    $file_size = $_SESSION[$ses_id]["import_conf_file_size"];
                } else {
                    $num_rec = 0;
                    $file_pos = 0;
                    $file_size = filesize($tmp_dat_file);
                }
                if (!isset($_GET["ajax"])) {
                    $smarty->assign("progress_bar", 1);
                    $smarty->assign("progress_text", $lang["exex_data_import"]);
                    $smarty->assign("percent", round($file_pos / $file_size * 100));
                    $smarty->assign("cur_title", $lang["Addons"]);
                    $smarty->display("templates/edit_transfer.tpl");
                    include "index_bottom.php";
                    $flush_str = str_repeat(" ", 5000);
                    echo $flush_str;
                    @ob_flush();
                    flush();
                }
                if (($fp = fopen($tmp_dat_file, "r")) !== false) {
                    fseek($fp, $file_pos);
                    while (($line = fgets($fp)) !== false) {
                        $num_rec++;
                        $file_pos = ftell($fp);
                        $c_part_done = round($file_pos / $file_size * 100);
                        if ($part_done < $c_part_done && !isset($_GET["ajax"])) {
                            $part_done = $c_part_done;
                            echo "<script type='text/javascript'>document.getElementById('backup_bar').style.width = '" . $part_done . "%';</script>";
                            echo "<script type='text/javascript'>document.getElementById('backup_progress').innerHTML = '" . $part_done . "%';</script>";
                            echo $flush_str;
                            @ob_flush();
                            flush();
                        }
                        $line = json_decode($line);
                        $new_table_id = $new_tables[$line[0]];
                        unset($line[0]);
                        if (!$fields[$new_table_id]) {
                            $result = sql_select_field(FIELDS_TABLE, "id", "table_id=", $new_table_id, " ORDER BY field_num");
                            while ($one_field = sql_fetch_assoc($result)) {
                                $fields[$new_table_id][] = $one_field["id"];
                            }
                        }
                        $line["r"] = 0;
                        $line["u"] = 0;
                        foreach ($line as $num_col => &$value) {
                            if (file_exists("temp/files/" . $num_rec . "_" . $num_col . "_0")) {
                                $files = explode("\r\n", $value);
                                foreach ($files as $num_file => $fname) {
                                    $content = file_get_contents("temp/files/" . $num_rec . "_" . $num_col . "_" . $num_file);
                                    save_data_file($fields[$new_table_id][$num_col - 1], $line[1], $fname, $content);
                                    unlink("temp/files/" . $num_rec . "_" . $num_col . "_" . $num_file);
                                }
                            }
                            $value = form_sql($value);
                        }
                        @sql_query("INSERT INTO " . DATA_TABLE . $new_table_id . " VALUES ('" . @implode("','", $line) . "')");
                        if ($max_exec_time - 20 < time() - $start_time) {
                            $_SESSION[$ses_id]["import_conf_num_rec"] = $num_rec;
                            $_SESSION[$ses_id]["import_conf_file_pos"] = $file_pos;
                            $_SESSION[$ses_id]["import_conf_file_size"] = $file_size;
                            echo "<script>location.href='edit_transfer.php" . (isset($_GET["ajax"]) ? "&ajax" : "") . "'</script>";
                            exit;
                        }
                    }
                    fclose($fp);
                    unlink($tmp_dat_file);
                    @rmdir("temp/files");
                }
                if ($_SESSION[$ses_id]["import_conf_addon_id"]) {
                    insert_log("admin", $lang["Administrator"] . " " . form_display($user["fio"]) . " " . $lang["log_update_addon"] . " \"" . $_SESSION[$ses_id]["import_conf_addon_name"] . "\"");
                } else {
                    insert_log("admin", $lang["Administrator"] . " " . form_display($user["fio"]) . " " . $lang["log_install_addon"] . " \"" . $_SESSION[$ses_id]["import_conf_addon_name"] . "\"");
                }
                if ($_SESSION[$ses_id]["import_conf_addon_settings"]) {
                    $redirect = "report.php?id=" . $_SESSION[$ses_id]["import_conf_addon_settings"];
                } else {
                    $redirect = "edit_transfer.php";
                }
                $_SESSION[$ses_id]["import_conf_table_data"] = 0;
                $_SESSION[$ses_id]["import_conf_num_rec"] = 0;
                $_SESSION[$ses_id]["import_conf_file_pos"] = 0;
                $_SESSION[$ses_id]["import_conf_file_size"] = 0;
                $_SESSION[$ses_id]["import_conf_addon_settings"] = 0;
                $_SESSION[$ses_id]["import_conf_addon_id"] = 0;
                $_SESSION[$ses_id]["import_conf_addon_name"] = "";
                echo "<script>location.href='" . $redirect . "'</script>";
                exit;
            }
            if ($_POST["settings"]) {
                sql_update(CONFIG_TABLE, ["value" => $_POST["autoupdate_addons"] ? 1 : 0], " name='autoupdate_addons'");
                $result = json_decode(send_asterisk_curl("https://market." . CLIENTBASE_DOMAIN . "/addons_set.php?account=" . urlencode($account) . "&autodelete=" . ($_POST["no_autodelete_addons"] ? 0 : 1)), 1);
                if ($result["success"]) {
                    sql_update(CONFIG_TABLE, ["value" => $_POST["no_autodelete_addons"] ? 1 : 0], " name='no_autodelete_addons'");
                }
                update_run_flags("config");
                $_SESSION[$ses_id]["save_settings_complete"] = 1;
                header("Location: edit_transfer.php");
                exit;
            }
            if ($_POST["base_names"]) {
                foreach ($_POST["base_names"] as $id => $field_id) {
                    sql_update(BASE_NAMES_TABLE, ["field_id" => $field_id], "id = ", $id);
                }
                header("Location: edit_transfer.php");
                exit;
            } else {
                $all_cats = [];
                $sub_cats = [];
                $sub_ccats = [];
                $sub_tables = [];
                $sub_ctables = [];
                $result = sql_select(CATS_TABLE, "1=1 ORDER BY num");
                while ($one_cat = sql_fetch_assoc($result)) {
                    $result2 = sql_select(TABLES_TABLE, "cat_id=", $one_cat["id"]);
                    while ($one_table = sql_fetch_assoc($result2)) {
                        if (!($user["sub_admin"] && $user["sub_admin_rights"]["tables"][$one_table["id"]] != 2)) {
                            $result3 = sql_select(ADDON_PARTS_TABLE, "part_type = 'table' and part_id = ", $one_table["id"]);
                            if (!sql_num_rows($result3)) {
                                $one_cat["tables"][] = $one_table;
                                $result3 = sql_select(SUBTABLES_TABLE, "table_id=", $one_table["id"]);
                                while ($subtable = sql_fetch_assoc($result3)) {
                                    $sub_table = sql_select_array(TABLES_TABLE, "id=", $subtable["link_table_id"]);
                                    if ($sub_table["cat_id"] != $one_cat["id"]) {
                                        $sub_cats[$sub_table["cat_id"]][] = $one_table["id"];
                                        $sub_ccats[$sub_table["cat_id"]][] = $one_cat["id"];
                                        $sub_ctables[$sub_table["id"]][] = $one_cat["id"];
                                    }
                                    if ($sub_table["id"] != $one_table["id"]) {
                                        $sub_tables[$sub_table["id"]][] = $one_table["id"];
                                    }
                                }
                            }
                        }
                    }
                    $result2 = sql_select(REPORTS_TABLE, "cat_id=", $one_cat["id"]);
                    while ($one_report = sql_fetch_assoc($result2)) {
                        if (!($user["sub_admin"] && $user["sub_admin_rights"]["reports"][$one_report["id"]] != 2)) {
                            $result3 = sql_select(ADDON_PARTS_TABLE, "part_type = 'report' and part_id = ", $one_report["id"]);
                            if (!sql_num_rows($result3)) {
                                $one_cat["reports"][] = $one_report;
                            }
                        }
                    }
                    $result2 = sql_select(CALENDARS_TABLE, "cat_id=", $one_cat["id"]);
                    while ($one_calendar = sql_fetch_assoc($result2)) {
                        if (!($user["sub_admin"] && $user["sub_admin_rights"]["calendars"][$one_calendar["id"]] != 2)) {
                            $result3 = sql_select(ADDON_PARTS_TABLE, "part_type = 'calendar' and part_id = ", $one_calendar["id"]);
                            if (!sql_num_rows($result3)) {
                                $one_cat["calendars"][] = $one_calendar;
                                $result3 = sql_select(CALENDAR_EVENTS, "calendar_id=", $one_calendar["id"]);
                                while ($event = sql_fetch_assoc($result3)) {
                                    $sub_table = sql_select_array(TABLES_TABLE, "id=", $event["table_id"]);
                                    if ($sub_table["cat_id"] != $one_cat["id"]) {
                                        $ev_cats[$sub_table["cat_id"]][] = $one_calendar["id"];
                                        $sub_ccats[$sub_table["cat_id"]][] = $one_cat["id"];
                                        $sub_ctables[$sub_table["id"]][] = $one_cat["id"];
                                    }
                                    $ev_tables[$sub_table["id"]][] = $one_calendar["id"];
                                }
                            }
                        }
                    }
                    if ($one_cat["tables"] || $one_cat["reports"] || $one_cat["calendars"]) {
                        $all_cats[] = $one_cat;
                    }
                }
                foreach ($shop_addons as $shop_addon_id => $shop_addon) {
                    $addon = sql_select_array(ADDONS_TABLE, "name = '", $shop_addon["name"], "'");
                    if (!$addon) {
                        if ($shop_addon["rented"]) {
                            $result = json_decode(send_asterisk_curl("https://market." . CLIENTBASE_DOMAIN . "/del_rent_addon.php?account=" . urlencode($account) . "&addon=" . $shop_addon_id), 1);
                            if ($result["success"]) {
                                $shop_addons[$shop_addon_id]["rented"] = 0;
                            }
                        } else {
                            if ($shop_addon["added"] && !$shop_addon["bought"]) {
                                $result = json_decode(send_asterisk_curl("https://market." . CLIENTBASE_DOMAIN . "/del_addon.php?account=" . urlencode($account) . "&addon=" . $shop_addon_id), 1);
                                if ($result["success"]) {
                                    $shop_addons[$shop_addon_id]["added"] = 0;
                                }
                            }
                        }
                    }
                }
                $cur_addons = sql_select_array(ADDONS_TABLE, "ALL_ROWS", "inactive = 0");
                foreach ($shop_addons as $shop_id => $shop_addon) {
                    $shop_addon["shop_id"] = $shop_id;
                    foreach ($cur_addons as $id => $cur_addon) {
                        if ($shop_addon["name"] == $cur_addon["name"] && !$cur_addon["inactive"]) {
                            $shop_addon["id"] = $cur_addon["id"];
                            $shop_addon["installed"] = 1;
                            if ($cur_addon["revision"] < $shop_addon["revision"] && ($shop_addon["bought"] || $shop_addon["rented"] || !$shop_addon["price"] && !$shop_addon["rent_sum"])) {
                                $shop_addon["new"] = 1;
                            }
                            if ($shop_addon["rented"]) {
                                $total_rent_sum += $shop_addon["rent_sum"];
                            }
                            unset($cur_addons[$id]);
                        }
                    }
                    $all_addons[] = $shop_addon;
                }
                foreach ($cur_addons as $one_addon) {
                    $one_addon["installed"] = 1;
                    $all_addons[] = $one_addon;
                }
                foreach ($all_addons as &$one_addon) {
                    if ($one_addon["installed"]) {
                        $row = sql_select_array(ADDON_PARTS_TABLE, "addon_id = ", $one_addon["id"], " LIMIT 1");
                        if ($row["part_type"] == "table") {
                            $one_addon["link"] = "fields.php?table=" . $row["part_id"];
                            list($one_addon["cat_id"]) = sql_fetch_row(sql_select_field(TABLES_TABLE, "cat_id", "id = ", $row["part_id"]));
                        } else {
                            if ($row["part_type"] == "report") {
                                $one_addon["link"] = "report.php?id=" . $row["part_id"];
                                list($one_addon["cat_id"]) = sql_fetch_row(sql_select_field(REPORTS_TABLE, "cat_id", "id = ", $row["part_id"]));
                            } else {
                                if ($row["part_type"] == "calendar") {
                                    $one_addon["link"] = "calendar.php?id=" . $row["part_id"];
                                    list($one_addon["cat_id"]) = sql_fetch_row(sql_select_field(CALENDARS_TABLE, "cat_id", "id = ", $row["part_id"]));
                                }
                            }
                        }
                    }
                }
                $base_names = sql_select_array(BASE_NAMES_TABLE, "ALL_ROWS");
                $result = sql_select(TABLES_TABLE, "1=1 ORDER BY name_table");
                while ($one_table = sql_fetch_assoc($result)) {
                    $result2 = sql_select(FIELDS_TABLE, "table_id = ", $one_table["id"], " ORDER BY field_num");
                    while ($one_field = sql_fetch_assoc($result2)) {
                        $sel_fields[$one_field["id"]] = $one_table["name_table"] . "." . $one_field["name_field"];
                    }
                }
                if ($config["type"] == "SAAS") {
                    $config["maxfilesize"] = 188743680;
                } else {
                    $config["maxfilesize"] = ini_get("upload_max_filesize");
                }
                if ($_SESSION[$ses_id]["addon_error"]) {
                    $smarty->assign($_SESSION[$ses_id]["addon_error"]["type"] . "_message", $_SESSION[$ses_id]["addon_error"]["text"]);
                    $smarty->assign($_SESSION[$ses_id]["addon_error"]["type"] . "_message_color", "red");
                    unset($_SESSION[$ses_id]["addon_error"]);
                }
                if ($_SESSION[$ses_id]["export_conf_complete"]) {
                    $smarty->assign("export_message", $lang["export_complete"]);
                    $smarty->assign("export_message_color", "green");
                }
                if ($_SESSION[$ses_id]["save_settings_complete"]) {
                    $smarty->assign("settings_message", $lang["succes_settings_save"]);
                    unset($_SESSION[$ses_id]["save_settings_complete"]);
                }
                if (isset($_GET["test"])) {
                    if (!$rGWthLqiHe) {
                        $_GET["addon"] = "free_version";
                    }
                    $smarty->assign("test_addon", $_GET["addon"]);
                }
                if (!$rGWthLqiHe) {
                    $smarty->assign("test_addon2", "free_version");
                }
                $smarty->assign("test_addon", $_GET["addon"]);
                $smarty->assign("config", $config);
                $smarty->assign("all_cats", $all_cats);
                $smarty->assign("sub_cats", $sub_cats);
                $smarty->assign("sub_ccats", $sub_ccats);
                $smarty->assign("sub_tables", $sub_tables);
                $smarty->assign("sub_ctables", $sub_ctables);
                $smarty->assign("ev_cats", $ev_cats);
                $smarty->assign("ev_tables", $ev_tables);
                $smarty->assign("all_addons", $all_addons);
                $smarty->assign("base_names", $base_names);
                $smarty->assign("sel_fields", $sel_fields);
                $smarty->assign("total_rent_sum", $total_rent_sum);
                $smarty->assign("cur_title", $lang["Addons"]);
                $smarty->display("templates/edit_transfer.tpl");
                include "index_bottom.php";
                if ($_SESSION[$ses_id]["export_conf_complete"]) {
                    echo "<script>location.href='edit_transfer.php?export_unload'</script>";
                    unset($_SESSION[$ses_id]["export_conf_complete"]);
                }
            }
        }
    }
}
function _obfuscated_0D24403B3238133B0B020A390C16062F042B3025233B22_($text)
{
    if (isset($_GET["ajax"])) {
        echo $text;
        exit;
    }
    global $ses_id;
    if ($_POST["export"]) {
        $type = "export";
    }
    if ($_POST["import"]) {
        $type = "import";
    }
    if ($_POST["addon"]) {
        $type = "shop";
    }
    if (isset($_POST["delete"])) {
        $type = "cur_addons";
    }
    $_SESSION[$ses_id]["addon_error"]["type"] = $type;
    $_SESSION[$ses_id]["addon_error"]["text"] = $text;
    header("Location: edit_transfer.php");
    exit;
}

?>

Function Calls

None

Variables

None

Stats

MD5 86cf94c60e37889e9f64b1184e3c68e4
Eval Count 0
Decode Time 162 ms