<?php
/*
http://www.archline.hu/version/aktivalasikod/9501802310377366/E9A2/0180-E9A2-A00-0439

Szia  Zsolt!
Kosz. Teszt lefut. Az maradjon is ott, az a teszt.php.
Illusion.hu
Lazar Imre
*/

if (!class_exists('crm_hardlock')) require_once("common_cadline_libraries/crm_hardlock.class.php");
if (!class_exists('crm_users')) require_once("common_cadline_libraries/crm_users.class.php");

$action = trim(strtolower($_GET['action']));

if (crm_hardlock::IsCalledFromMyIP() || $_SERVER['REMOTE_ADDR'] == '176.241.36.200') {
    switch ($action) {
        default:
            echo 'missing action parameter';
            break;

        case 'get_maintainer_programs':
            $sql = "SELECT p.prHlNum AS prHlNum 
                FROM cl_hlusers.h_programs p
                LEFT JOIN cl_hlusers.hardlock h ON h.hlNum = p.prHlNum
                WHERE (h.hlCtrID = 39 OR h.hlNum LIKE '39%') AND p.prStat = 0 AND h.hlStat = 1 AND p.prVerID = 23 AND p.prContact IN (1,11,0,3) GROUP BY p.prPass;";

            $sql = "SELECT DISTINCT(prID) prID, prHlNum, prStat, hlUser, strCompany, prTypeID, prVerID, prLan, strInvoiceName, prSellDate, prContact, prPass, prFizetve, prActCode, prPrice, prInfo, prOrdNum, prHiType, prDealer, prInvoiceDateFrom,prInvoiceDateTo,prInvoiceRecurrence 
                FROM h_programs p 
                LEFT JOIN hardlock h ON p.prHlNum=h.hlNum 
                LEFT JOIN users u ON h.hlUser=u.nUserID 
                LEFT JOIN u_emails e ON e.nUserID = h.hlUser 
                WHERE h.hlStat = 1 AND (h.hlCtrID = 43 OR h.hlNum LIKE '43%') AND p.prVerID IN (23) AND p.prContact IN (1,11,0,3) GROUP BY p.prPass ORDER BY prHlNum";
            crm_database::getInstance()->query($sql);
            $res = crm_database::getInstance()->fetchAssoc();

            $i = 1;

            echo '(';
            foreach ($res as $value) {
                $sql = "SELECT * FROM cl_hlusers.h_programs
                WHERE prHlNum = '" . $value['prHlNum'] . "' GROUP BY prPass;";
                crm_database::getInstance()->query($sql);
                $programs = crm_database::getInstance()->fetchAssoc();

                foreach ($programs as $program) {
                    echo "'" . $program['prPass'] . "', ";
                    $i++;
                }
            }
            //echo $i;
            echo ')';
            die();
            break;

        case 'delete_nonprofit_programs':
            $sql = "SELECT u.nUserID AS nUserID, h.hlNum AS hlNum, p.prPass AS prPass, p.prHlNum AS prHlNum
                FROM cl_hlusers.hardlock h
                LEFT JOIN cl_hlusers.users u ON u.nUserID = h.hlUser
                LEFT JOIN cl_hlusers.h_programs p  ON p.prHlNum = h.hlNum
                WHERE h.hlStat = 2 AND h.hlNum LIKE '99%' AND u.nUserType = 0 AND p.prVerID <= 22 GROUP BY p.prPass;";
            crm_database::getInstance()->query($sql);
            $res = crm_database::getInstance()->fetchAssoc();

            $i = 0;

            foreach ($res as $value) {
                $sql2 = "SELECT prID FROM cl_hlusers.h_programs
                    WHERE prHlNum = '" . $value['hlNum'] . "' AND prVerID > 22 LIMIT 1";
                crm_database::getInstance()->query($sql2);
                $res2 = crm_database::getInstance()->fetchNext();

                if (!empty($res2))
                    continue;

                /*$delete_sql3 = "DELETE FROM cl_hlusers.nonprofit WHERE hlID = '" . $value['prHlNum'] . "'";
                crm_database::getInstance()->query($delete_sql3);

                Database::getInstance()->query("DELETE FROM `" . CRMADATBAZIS . "`.`h_programs` WHERE prPass = ?", array('s', $value['prPass']));
                Database::getInstance()->query("DELETE FROM `" . CRMADATBAZIS . "`.`p_serial_isid` WHERE serial = ?", array('s', $value['prPass']));
                Database::getInstance()->query("DELETE FROM `" . CRMADATBAZIS . "`.`userstats2013` WHERE usPwd = ?", array('s', $value['prPass']));

                Database::getInstance()->query("SELECT * FROM `" . CRMADATBAZIS . "`.`h_programs` WHERE prHlNum = ?", array('s', $value['prHlNum']));
                $res3 = Database::getInstance()->fetchNext();

                if (empty($res3)) {
                    Database::getInstance()->query("DELETE FROM `" . CRMADATBAZIS . "`.`hardlock` WHERE hlNum = ?", array('s', $value['prHlNum']));
                    Database::getInstance()->query("DELETE FROM `" . CRMADATBAZIS . "`.`h_history` WHERE hiHlNum = ?", array('s', $value['prHlNum']));
                }*/

                $i++;

                echo '<a href="http://crm.cadline.hu/48/hardlock/show/' . $value['hlNum'] . '" target="_blank">' . $value['hlNum'] . '</a><br/>';
            }

            echo $i;
            die();
            break;

        case 'insert_test_programs':
            $hlNum      = 371004;
            $lan        = 15;
            $lan_sign   = crm_hardlock::GetLanSignFromLanUserNumber($lan);
            $password   = Codegen::GeneratePassword($hlNum, $lan_sign, 8, 80);

            for ($i = 0; $i < 15; $i++) {
                Database::getInstance()->insert(
                    CRMADATBAZIS . '.h_programs',
                    array(
                        "prPass" => $password,
                        "prVerID" => 23,
                        "prTypeID" => 8,
                        "prLan" => $lan,
                        "prSellDate" => date('Y-m-d'),
                        "prFizetve" => "2026-10-15",
                        "prContact" => 5,
                        "prHlNum"   => $hlNum,
                        "prPrice" => 0,
                        "prManID" => 36,
                        "prStat" => 0,
                        "prHiType" => 1
                    ),
                    'siiissisiiii'
                );
            }
            break;

        case 'custom_login_test':
            $url = 'https://www.archline.hu/maintenance/webform/custom_page_test.php';

            $jsonUser           = new stdClass();
            $jsonUser->serial   = 'test_serial';
            $jsonUser->email    = 'test@test.com';
            $jsonUser->crmID    = 'id';

            $jsonString     = json_encode($jsonUser);
            $encodedJson    = base64_encode($jsonString); // base64 encode-olt JSON

            $postData = [
                'data' => $encodedJson
            ];

            $cURLConnection = curl_init($url);
            curl_setopt($cURLConnection, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($cURLConnection, CURLOPT_POSTFIELDS, $postData);
            $result = curl_exec($cURLConnection);

            /*$msg = "Url: {$url} || Data: {$jsonString}";

            crm_hardlock::AddToDebugTable($msg, 'custom_login_test');*/

            var_dump($result);
            die();
            break;

        case 'change-namirial-and-bim-user':
            $sql = "SELECT u.nUserID AS nUserID
                FROM cl_hlusers.h_programs p
                LEFT JOIN cl_hlusers.hardlock h ON h.hlNum = p.prHlNum
                LEFT JOIN cl_hlusers.users u ON u.nUserID = h.hlUser
                WHERE p.prContact = 9 AND u.nUserType != 2;";

            crm_database::getInstance()->query($sql);
            $res = crm_database::getInstance()->fetchAssoc();

            $users = 0;

            foreach ($res as $value) {
                $sql2 = "SELECT count(*) AS hardlock_count FROM cl_hlusers.hardlock
                    WHERE hlUser = '" . $value['nUserID'] . "'";

                crm_database::getInstance()->query($sql2);
                $res2 = crm_database::getInstance()->fetchNext();

                $sql3 = "SELECT p.prID AS prID
                    FROM cl_hlusers.h_programs p
                    LEFT JOIN cl_hlusers.hardlock h ON h.hlNum = p.prHlNum
                    WHERE h.hlUser = '" . $value['nUserID'] . "' AND p.prContact = 9
                    GROUP BY p.prHlNum;";

                crm_database::getInstance()->query($sql3);
                $res3 = crm_database::getInstance()->fetchAssoc();

                $prg_count = count($res3);

                if ($res2['hardlock_count'] == $prg_count) {
                    /*$updateSql1 = "UPDATE cl_hlusers.users SET nUserType = 2
                        WHERE nUserID = '".$value['nUserID']."'";
                    crm_database::getInstance()->query($updateSql1);*/

                    $user++;
                }
            }

            echo $user;
            break;

        case 'update-live-programs':
            $liveKeys = array(480027, 480041, 480045, 480142, 480145, 480147, 480149, 480151, 480153, 480154, 480155, 480157, 480159, 480161, 480163, 480165, 480168, 480169, 480171, 480172, 480174, 480176, 480179, 480180, 480181, 480182, 480189, 480194, 480195, 480197, 480199, 480200, 480201, 480204, 480210, 480212, 480214, 480216, 480218, 480220, 480224, 480228, 480232, 480236, 480238, 480040, 480143, 480146, 480148, 480175, 480177, 480183, 480185, 480187, 480189, 480205, 480206, 480208, 480222, 480230, 480234, 480240, 480242, 480244, 480246, 480247, 480249, 480251, 480254, 480255, 480257, 480259, 480262, 480264, 480266, 480268, 480270, 480272, 480274, 480276, 480278, 480280, 480282, 480287, 480289, 480291, 480293, 480295, 480297, 480299, 480301, 480304, 480306, 480308, 480310, 480312, 480314, 480316, 480318, 480320, 480323, 480325, 480327, 480329, 480331, 480333, 480042, 480043, 480167, 480181, 480191, 480192, 480226, 480230, 480248, 480250, 480253, 480265, 480267, 480269, 480338, 480341, 480343, 480345, 480348, 480351, 480353, 480358, 480361, 480381, 480383, 480385, 480390, 480395, 480397, 480402, 480404, 480406, 480408, 480410, 480412, 480416, 480420, 480422, 480433, 480435, 480437, 480439, 480441, 480443, 480446, 480448, 480450, 480452, 480455, 480458, 480461, 480463, 480466, 480468, 480470, 480472, 480474, 480476, 480478, 480480, 480482, 480486, 480489, 480491, 480496, 480498, 480500, 480502, 480508, 480514, 480516, 480520, 480522, 480524, 480526, 480527, 480261, 480493, 480510, 480528, 480532, 480533, 480534, 480535, 480536, 480541, 480545, 480546, 480547, 330001, 330002, 330008, 330009, 330016, 330018, 330021, 330021, 330022, 330022, 330023, 330025, 330025, 330027, 330034, 330035, 330038, 330039, 330040, 330042, 330043, 330046, 330048, 330051, 330062, 330072, 330073, 330081, 330083, 330084, 330086, 330087, 330093, 330101, 330105, 330106, 330107, 330112, 330125, 330139, 330140, 330141, 330147, 330149, 330161, 330162, 330165, 330167, 330171, 330172, 330175, 330177, 330180, 330181, 330183, 330184, 330189, 330190, 330196, 330200, 330201, 330207, 330208, 390020, 390021, 390026, 390030, 390031, 390032, 390097, 390099, 390103, 390105, 390109, 390110, 390111, 390112, 390113, 390114, 390115, 390116, 390118, 390122, 390123, 390126, 390129, 390130, 390131, 390132, 390133, 390134, 390135, 390136, 390137, 390140, 390141, 390142, 390143, 390144, 390146, 390147, 390148, 390149, 390150, 390151, 390153, 390157, 390159, 390160, 390161, 390163, 390164, 390165, 390168, 390171, 390173, 390175, 390176, 390177, 390179, 390180, 390182, 390186, 390187, 390188, 390189, 390192, 390193, 390194, 390251, 390252, 390253, 390254, 390261, 390262, 390317, 390318, 390319, 390320, 390366, 390367, 390368, 390369, 390370, 390371, 390373, 390374, 390375, 398874, 398887, 398895, 398895, 398897, 398898, 398899, 398900, 398901, 398902, 398902, 398913, 398917, 398924, 398926, 398928, 398930, 398931, 398932, 398938, 398945, 398953, 398958, 398959, 398960, 398961, 398962, 398963, 398964, 398965, 398966, 398967, 398968, 398969, 398970, 398971, 398972, 398973, 398974, 398975, 398976, 398977, 398978, 398979, 398980, 398982, 398983, 398984, 398985, 398986, 398987, 398988, 398989, 398990, 398991, 398992, 398993, 398994, 398995, 398996, 398997, 398998, 398999, 399000, 399001, 399002, 399003, 399004, 399005, 399006, 399007, 399008, 399009, 399010, 399011, 399012, 399013, 399014, 399015, 399016, 399017, 399018, 399019, 399020, 399021, 399022, 399023, 399024, 399025, 399026, 399027, 399028, 399029, 399030, 399031, 399032, 399033, 399034, 399035, 399036, 399037, 399038, 399039, 399040, 399041, 399042, 399043, 399044, 399045, 399046, 399047, 399048, 399049, 399050, 399051, 399052, 399053, 399054, 399055, 399056, 399057, 399059, 399060, 399061, 399062, 399063, 399064, 399065, 399066, 399067, 399068, 399069, 399070, 399071, 399072, 399073, 399094, 399204, 399205, 399207, 399209, 399211, 399213, 399218, 399219, 399222, 399237, 399244, 399245, 399248, 399253, 399254, 399255, 399256, 420437, 420438, 420439, 420440, 420444, 420445, 420447, 420449, 420450, 420451, 420452, 420453, 420454, 420455, 420456, 420457, 420458, 420459, 420466, 420467, 420470, 432043, 432043, 432066, 432066, 432083, 432087, 432087, 432107, 432107, 432111, 432111, 432133, 432134, 432138, 432159, 432161, 432162, 432163, 432164, 432166, 432168, 432170, 432172, 432174, 432176, 432178, 432180, 432182, 432184, 432186, 432188, 432190, 432204, 432228, 432229, 432239, 432240, 432241, 432244, 432245, 432246, 432247, 432248, 432250, 432251, 490111, 490112, 490113, 490114, 490116, 490117, 490118, 490119, 490120, 490121, 490122, 490135, 490138, 490139, 490140, 490141, 490142, 490143, 490144, 490145, 490146, 490147, 490148, 490149, 490150, 490160, 490161);

            for ($i = 0; $i < count($liveKeys); $i++) {
                $hlNum = $liveKeys[$i];
                $newHlNum  = crm_hardlock::tryToAlloc(990010, 999999);

                if ($hlNum == 361296 || $hlNum == 361297)
                    continue;

                $sql = "SELECT hlUser, hlCtrID FROM cl_hlusers.hardlock WHERE hlNum = '{$hlNum}'";
                crm_database::getInstance()->query($sql);
                $res = crm_database::getInstance()->fetchNext();
                $hlUser = $res['hlUser'];
                $hlCtrID = $res['hlCtrID'];

                $sql2 = "SELECT p.prID FROM cl_hlusers.h_programs p
                    LEFT JOIN hardlock h ON h.hlNum = p.prHlNum 
                    WHERE h.hlNum LIKE '99%' AND h.hlUser = '{$hlUser}' AND h.product_id = 2 AND p.prVerID = 23";
                crm_database::getInstance()->query($sql2);
                $res2 = crm_database::getInstance()->fetchNext();

                if (empty($res2)) {
                    Database::getInstance()->insert(
                        CRMADATBAZIS . '.hardlock',
                        array(
                            "hlNum" => $newHlNum,
                            "hlLan" => 0,
                            "hlStat" => 1,
                            "hlManID" => 36,
                            "hlTime" => time(),
                            "bUjithato" => 1,
                            "product_id" => 2,
                            "hlUser" => $hlUser,
                            "hlCtrID" => $hlCtrID
                        ),
                        'siiiiiiii'
                    );

                    $password = Codegen::GeneratePassword($newHlNum, 0, 76, 80);

                    Database::getInstance()->insert(
                        CRMADATBAZIS . '.h_programs',
                        array(
                            "prPass" => $password,
                            "prVerID" => 23,
                            "prTypeID" => 76,
                            "prLan" => 0,
                            "prSellDate" => date('Y-m-d'),
                            "prFizetve" => "2023-05-31",
                            "prContact" => 5,
                            "prHlNum"   => $newHlNum,
                            "prPrice" => 0,
                            "prManID" => 36,
                            "prStat" => 0,
                            "prHiType" => 3
                        ),
                        'siiissisiiii'
                    );

                    echo $password . '<br/>';
                }
            }
            die();
            break;

        case 'delete-namirial-and-bim':
            /*
                2021 01 01 előtt bimladder programok törlése (2019-es vagy régebbi programok)
            	nonprofit táblából is, és a usert is törölni (kbl)
            	a userek átmennek a megkeresendőkhöz
            */
            $sql = "SELECT h.hlUser AS hlUser, p.prHlNum AS prHlNum, p.prPass AS prPass
                FROM cl_hlusers.h_programs p
                LEFT JOIN cl_hlusers.hardlock h ON h.hlNum = p.prHlNum
                WHERE p.prContact = 8 AND p.prHlNum != 940003 AND p.prHlNum != 940004 AND p.prHlNum != 940006 AND
                p.prHlNum != 940010 AND p.prVerID <= 19 AND p.prFizetve < '2021-01-01';";

            crm_database::getInstance()->query($sql);
            $res = crm_database::getInstance()->fetchAssoc();

            $users = 0;
            $programs = 0;

            foreach ($res as $value) {
                /*$delete_sql = "DELETE FROM cl_hlusers.h_programs WHERE prPass = '".$value['prPass']."'";
                crm_database::getInstance()->query($delete_sql);*/

                $sql2 = "SELECT count(*) AS program_count FROM cl_hlusers.h_programs
                    WHERE prHlNum = '" . $value['prHlNum'] . "'";

                crm_database::getInstance()->query($sql2);
                $res2 = crm_database::getInstance()->fetchNext();

                if ($res2['program_count'] < 1) {
                    /*$delete_sql2 = "DELETE FROM cl_hlusers.hardlock WHERE hlNum = '".$value['prHlNum']."'";
                    crm_database::getInstance()->query($delete_sql2);*/

                    /*$delete_sql3 = "DELETE FROM cl_hlusers.nonprofit WHERE hlID = '".$value['prHlNum']."'";
                    crm_database::getInstance()->query($delete_sql3);*/

                    $sql3 = "SELECT count(*) AS hardlock_count FROM cl_hlusers.hardlock
                        WHERE hlUser = '" . $value['hlUser'] . "'";

                    crm_database::getInstance()->query($sql3);
                    $res3 = crm_database::getInstance()->fetchNext();

                    if ($res3['hardlock_count'] < 1) {
                        /*$updateSql1 = "UPDATE cl_hlusers.users SET nUserType = 0
                            WHERE nUserID = '".$value['hlUser']."'";
                        crm_database::getInstance()->query($updateSql1);*/

                        $users++;
                    }
                }

                $programs++;
            }

            echo 'Users: ' . $users;
            echo '<br/>';
            echo 'Programs: ' . $programs;
            break;

        case 'readcsv':
            $queryMsg = '';

            if (($handle = fopen("2646560-6531045b1309938c0ae6778b-8jkwT4.csv", "r")) !== FALSE) {
                while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
                    $num = count($data);
                    for ($c = 0; $c < $num; $c++) {
                        if ($c == 0) {
                            $queryMsg .= "'" . $data[$c] . "', ";
                        }
                    }
                }
                fclose($handle);

                $trimmed = rtrim($queryMsg, ', ');

                $query = "SELECT * FROM cl_hlusers.u_emails WHERE email IN (" . $trimmed . ")";
                crm_database::getInstance()->query($query);
                $res = crm_database::getInstance()->fetchAssoc();

                var_dump($res);

                foreach ($res as $value) {
                    $updateSql1 = "UPDATE cl_hlusers.u_emails SET newsletter = 0 WHERE u_emails_id = " . $value['u_emails_id'];
                    crm_database::getInstance()->query($updateSql1);

                    Database::getInstance()->insert(
                        CRMADATBAZIS . '.u_history',
                        array(
                            "nUserID" => $value['nUserID'],
                            "nTopicID" => 54,
                            "dateEvent" => date('Y-m-d'),
                            "strPlace" => 'web',
                            "strInfo"   => $value['email'],
                            "nManagerID" => 36,
                            "insertDate" => date('Y-m-d H:i:s')
                        ),
                        'iisssis'
                    );
                }
            }
            die();
            break;

        case 'update-user-newsletter':
            $sql = "SELECT e.u_emails_id AS emailIDs FROM cl_hlusers.users u
                LEFT JOIN cl_hlusers.u_emails e ON e.nUserID = u.nUserID
                WHERE u.old_db = 'clusers_eng' AND u.nUserType = 0 AND e.newsletter != 1 AND
                u.nUserID NOT IN (SELECT nUserID FROM cl_hlusers.u_history WHERE nTopicID = 54 OR nTopicID = 219 OR nTopicID = 378 OR nTopicID = 339 OR strInfo LIKE 'Unsubscribe newsletter%') AND
                u.nUserID NOT IN (SELECT nUserID FROM cl_hlusers.u_emails WHERE newsletter = 1) GROUP BY u.nUserID LIMIT 5000;";

            crm_database::getInstance()->query($sql);
            $res = crm_database::getInstance()->fetchAssoc();

            $i = 0;

            foreach ($res as $value) {
                $i++;

                //$updateSql1 = "UPDATE cl_hlusers.u_emails SET newsletter = 1 WHERE u_emails_id = ".$value['emailIDs'];
                //crm_database::getInstance()->query($updateSql1);
            }

            echo $i;
            break;

        case 'update-test-2':
            /*Kesz tablak:
                - hun
                - ita
                - ger (Kata nezze at)
                - fr
                - pl
                - pt
                - cz
                - gre (hagyjuk...)
                - kor
                - esp
                - chn (nem lehet, mert sok a teves szoveg, raadasul angol!)
                - cr (nem lehet, mert sok a teves szoveg, raadasul angol!)
                - nor (nem lehet, mert sok a teves szoveg, raadasul angol!)



                kézi, ami nincs kész:
                    - Cseh
                    - Horvát
                    - Koreai
                    - Spanyol
            */
            $table = 'resourcemanager.text_table_esp';
            // Update-eli a kiselectalt adatokat
            $needToUpdate = $_GET['needToUpdate'] == '' ? false : $_GET['needToUpdate'];
            // Selecteli azokat a forditasokat, amelyek nem egyezik meg a szovege a referenciaeval, de needToTranslate-es
            $sql1 = "SELECT ref.id AS ref_id, res.id AS res_id, ref.text AS ref_text, res.text AS res_text, res.to_translate AS test_asd
                FROM resourcemanager.text_table_ref ref
                LEFT JOIN {$table} res ON res.ref_id = ref.id
                WHERE ref.text NOT LIKE '%://%' AND CHAR_LENGTH(ref.text) > 10 AND ((ref.text != res.text AND res.to_translate = 1)) AND ref.type_id < 4 LIMIT 10000;";

            $sql1A = "SELECT ref.id AS ref_id, res.id AS res_id, ref.text AS ref_text, res.text AS res_text, res.to_translate AS test_asd
                FROM resourcemanager.text_table_ref ref
                LEFT JOIN {$table} res ON res.ref_id = ref.id
                WHERE ref.text NOT LIKE '%://%' AND CHAR_LENGTH(ref.text) > 10 AND
                (((ref.text != res.text AND res.text != ref.key) AND res.to_translate = 1 )) AND ref.type_id > 4 LIMIT 10000;";

            $sql2 = "SELECT ref.id AS ref_id, res.id AS res_id, ref.text AS ref_text, res.text AS res_text, res.to_translate AS test_asd
                FROM resourcemanager.text_table_ref ref
                LEFT JOIN {$table} res ON res.ref_id = ref.id
                WHERE ref.text LIKE '%://%' AND res.to_translate = 1 AND ref.type_id < 4 LIMIT 10000;";

            $sql3 = "SELECT ref.id AS ref_id, res.id AS res_id, ref.text AS ref_text, res.text AS res_text, res.to_translate AS test_asd
                FROM resourcemanager.text_table_ref ref
                LEFT JOIN {$table} res ON res.ref_id = ref.id
                WHERE ref.text NOT LIKE '%://%' AND ((ref.text != res.text AND res.to_translate = 1)) AND ref.type_id < 4 LIMIT 10000;";

            $currentSql = $sql1A;

            crm_database::getInstance()->query($currentSql);
            $res = crm_database::getInstance()->fetchAssoc();

            echo count($res);
            echo '<br/><br/>';

            foreach ($res as $value) {
                if ($value['res_id'] == '282998' || $value['res_id'] == '276904' || $value['res_id'] == '158699')
                    continue;

                if ($needToUpdate) {
                    if ($currentSql == $sql1 || $currentSql == $sql1A || $currentSql == $sql2 || $currentSql == $sql3) {
                        $updateSql1 = "UPDATE {$table} SET to_translate = 0 WHERE id = " . $value['res_id'];
                        crm_database::getInstance()->query($updateSql1);
                    }
                }

                echo $value['res_id'] . '. ' . $value['ref_text'] . ' - ' . $value['res_text'] . ' - ' . $value['test_asd'] . '<br/>';
            }
            break;

        case 'test-reg':
            $url = 'http://archlineviewer.eastus.cloudapp.azure.com/users';
            $header = array('Content-Type: application/json', 'Authorization: df1dceb8e2d6f6b0894363b085801e36');
            $data = array(
                'password'  => 'CADLine123',
                'isAdmin'   => false,
                'userBrief' => array(
                    'userName'          => '',
                    'email'             => 'mate.nagy@cadline.hu',
                    'firstName'         => 'Máté',
                    'lastName'          => 'Nagy',
                    'projectsLimit'     => 10,
                    'canCreateProject'  => true,
                    'tokenInfo'         => array(
                        'token'     => '8888ddd1470c8f73cf6e59f39578c3f45',
                        'expires'   => '2021-12-30T00:00:00'
                    )
                ),
            );

            $ch = curl_init($url);
            # Setup request to send json via POST.
            $jsonData = json_encode($data);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
            curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
            # Return response instead of printing.
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            # Send request.
            $result = curl_exec($ch);
            curl_close($ch);
            # Print response.
            echo "<pre>$result</pre>";
            break;

        case 'update_actcode':
            $query = "SELECT * FROM cl_hlusers.h_programs WHERE prActCode = '' AND prVerID = 20 AND prTypeID != 76 AND prPass NOT LIKE '95%' AND prPass NOT LIKE '99%'
                AND prOrdNum IS NOT NULL AND prPass NOT LIKE '39%' AND prOrdNum != '' AND prPass LIKE '43%'";

            Database::getInstance()->query($query);
            $res = Database::getInstance()->fetchAssoc();

            die();

            foreach ($res as $value) {
                $isid = crm_hardlock::GetIsidFromPasswordForHardwareKeys($value['prPass']);
                $actCode = Codegen::GenerateTimeCode($value['prPass'], $isid, 3583);

                $query = "UPDATE `" . CRMADATBAZIS . "`.`h_programs` SET prActCode = ? WHERE prPass = ?";
                Database::getInstance()->query($query, array('ss', $actCode, $value['prPass']));
            }
            break;

        case 'insert_nonprofit':
            for ($i = 997951; $i < 999991; $i++) {
                Database::getInstance()->insert(
                    CRMADATBAZIS . '.hardlock',
                    array(
                        "hlNum" => $i,
                        "hlLan" => 0,
                        "hlStat" => 0,
                        "hlManID" => 36,
                        "hlTime" => time(),
                        "bUjithato" => 1,
                        "product_id" => 1
                    ),
                    'siiiiii'
                );
            }
            break;

        case 'change_to_non_contacted':
            $query = "SELECT u.nUserID AS nUserID 
                FROM cl_hlusers.users u
                WHERE u.nUserType = 2 GROUP BY u.nUserID";
            Database::getInstance()->query($query);
            $res = Database::getInstance()->fetchAssoc();

            $i = 0;

            foreach ($res as $value) {
                $query2 = "SELECT h.hlUser FROM cl_hlusers.hardlock h WHERE h.hlUser = ?";
                Database::getInstance()->query($query2, array('i', $value['nUserID']));
                $res2 = Database::getInstance()->fetchNext();

                if (!empty($res2))
                    continue;

                /*$query = "UPDATE `" . CRMADATBAZIS . "`.`users` SET nUserType = ? WHERE nUserID = ?";
                Database::getInstance()->query($query, array('ii', 0, $value['nUserID']));*/

                $i++;

                echo '<a href="https://crm.cadline.hu/hu/users/show/' . $value['nUserID'] . '" target="_blank">' . $value['nUserID'] . '</a><br/>';
            }

            echo $i;
            die();
            break;

        case 'change_bonus_trial_users':
            $query = "SELECT u.nUserID AS nUserID 
                FROM cl_hlusers.users u 
                LEFT JOIN cl_hlusers.hardlock h ON h.hlUser = u.nUserID
                WHERE u.nUserType != 0 AND h.hlNum LIKE '96%' AND u.nUserID != 85644 AND u.nUserID != 86182 GROUP BY u.nUserID";
            Database::getInstance()->query($query);
            $res = Database::getInstance()->fetchAssoc();

            $i = 0;
            foreach ($res as $value) {
                $query2 = "SELECT * FROM cl_hlusers.hardlock WHERE hlUser = ? AND hlNum NOT LIKE '96%'";
                Database::getInstance()->query($query2, array('i', $value['nUserID']));
                $res2 = Database::getInstance()->fetchNext();

                if (!empty($res2))
                    continue;

                /*$query = "UPDATE `" . CRMADATBAZIS . "`.`users` SET nUserType = ? WHERE nUserID = ?";
                Database::getInstance()->query($query, array('ii', 0, $value['nUserID']));*/

                $i++;

                echo '<a href="https://crm.cadline.hu/hu/users/show/' . $value['nUserID'] . '" target="_blank">' . $value['nUserID'] . '</a><br/>';
            }

            echo $i;

            die();
            break;

        case 'delete_bonus_trial':
            $query = "SELECT * FROM cl_hlusers.h_programs WHERE prContact = 10 AND prFizetve < '2023-06-02'";
            Database::getInstance()->query($query);
            $res = Database::getInstance()->fetchAssoc();

            $i = 0;
            $hun = 0;
            $eng = 0;

            foreach ($res as $value) {
                $query2 = "SELECT * FROM cl_hlusers.h_programs WHERE prPass = ? AND prFizetve >= '2023-06-02'";
                Database::getInstance()->query($query2, array('s', $value['prPass']));
                $res2 = Database::getInstance()->fetchNext();

                if (!empty($res2))
                    continue;

                echo '<a href="http://crm.cadline.hu/48/hardlock/show/' . $value['prHlNum'] . '" target="_blank">' . $value['prPass'] . ' - ' . $value['prFizetve'] . '</a><br/>';

                /*Database::getInstance()->query("DELETE FROM `" . CRMADATBAZIS . "`.`h_programs` WHERE prPass = ?", array('s', $value['prPass']));
                Database::getInstance()->query("DELETE FROM `" . CRMADATBAZIS . "`.`p_serial_isid` WHERE serial = ?", array('s', $value['prPass']));
                Database::getInstance()->query("DELETE FROM `" . CRMADATBAZIS . "`.`userstats2013` WHERE usPwd = ?", array('s', $value['prPass']));

                Database::getInstance()->query("SELECT * FROM `" . CRMADATBAZIS . "`.`h_programs` WHERE prHlNum = ?", array('s', $value['prHlNum']));
                $res3 = Database::getInstance()->fetchNext();

                if (empty($res3)) {
                    Database::getInstance()->query("DELETE FROM `" . CRMADATBAZIS . "`.`hardlock` WHERE hlNum = ?", array('s', $value['prHlNum']));
                    Database::getInstance()->query("DELETE FROM `" . CRMADATBAZIS . "`.`h_history` WHERE hiHlNum = ?", array('s', $value['prHlNum']));
                }*/

                /*Database::getInstance()->query("SELECT * FROM `" . CRMADATBAZIS . "`.`hardlock` WHERE hlNum = ?", array('s', $value['prHlNum']));
                $res4 = Database::getInstance()->fetchNext();

                if ($res4['hlCtrID'] == 36)
                    $hun++;
                else
                    $eng++;*/

                $i++;

                continue;

                Database::getInstance()->query("SELECT * FROM `" . CRMADATBAZIS . "`.`hardlock` WHERE hlNum = ?", array('s', $value['prHlNum']));
                $res4 = Database::getInstance()->fetchNext();

                Database::getInstance()->query("SELECT * FROM `" . CRMADATBAZIS . "`.`users` WHERE nUserID = ? AND nUserType = 1", array('s', $res4['hlUser']));
                $res5 = Database::getInstance()->fetchNext();

                if (!empty($res5)) {
                    echo '<a href="https://crm.cadline.hu/hu/users/show/' . $res5['nUserID'] . '" target="_blank">' . $res5['nUserID'] . '</a><br/>';

                    if ($res4['hlCtrID'] == 36)
                        $hun++;
                    else
                        $eng++;

                    $i++;

                    /*Database::getInstance()->query("DELETE FROM `" . CRMADATBAZIS . "`.`h_programs` WHERE prPass = ?", array('s', $value['prPass']));
                    Database::getInstance()->query("DELETE FROM `" . CRMADATBAZIS . "`.`p_serial_isid` WHERE serial = ?", array('s', $value['prPass']));
                    Database::getInstance()->query("DELETE FROM `" . CRMADATBAZIS . "`.`userstats2013` WHERE usPwd = ?", array('s', $value['prPass']));

                    Database::getInstance()->query("SELECT * FROM `" . CRMADATBAZIS . "`.`h_programs` WHERE prHlNum = ?", array('s', $value['prHlNum']));
                    $res3 = Database::getInstance()->fetchNext();

                    if (empty($res3)) {
                        Database::getInstance()->query("DELETE FROM `" . CRMADATBAZIS . "`.`hardlock` WHERE hlNum = ?", array('s', $value['prHlNum']));
                        Database::getInstance()->query("DELETE FROM `" . CRMADATBAZIS . "`.`h_history` WHERE hiHlNum = ?", array('s', $value['prHlNum']));
                    }*/
                }
            }

            echo 'Magyar: ' . $hun . '<br>';
            echo 'Angol: ' . $eng . '<br>';
            echo 'Összesen: ' . $i . '<br>';
            die();
            break;

        case 'bonus_trial':
            $query = "SELECT h.hlStat AS hlStat, h.hlNum AS hlNum, h.hlUser AS hlUser, p.prSellDate AS prSellDate, p.prTime AS prTime
                FROM cl_hlusers.hardlock h
                LEFT JOIN cl_hlusers.h_programs p ON p.prHlNUM = h.hlNum
                WHERE h.hlStat != 0 AND h.hlNum LIKE '96%' AND h.hlUser NOT IN (SELECT nUserID FROM cl_hlusers.u_history WHERE nTopicID = 106) 
                GROUP BY h.hlUser";
            Database::getInstance()->query($query);
            $res = Database::getInstance()->fetchAssoc();

            foreach ($res as $r) {
                Database::getInstance()->insert(
                    CRMADATBAZIS . '.u_history',
                    array(
                        "nUserID" => $r['hlUser'],
                        "nTopicID" => 106,
                        "dateEvent" => $r['prSellDate'],
                        "strPlace" => 'ARCHLine',
                        "strInfo" => 'Bónusz Trialt igényelt',
                        "nManagerID" => 36,
                        "insertDate" => $r['prTime']
                    ),
                    'iisssis'
                );
            }

            die();
            break;

        case 'web_product_insert':
            $query = "SELECT * FROM cl_hlusers.o_products where lang != 37 AND (termek = 'ARCHLine.XP PRO 2022 yearly subscription' OR termek = 'ARCHLine.XP PRO 2022 monthly subscription')";
            Database::getInstance()->query($query);
            $res = Database::getInstance()->fetchAssoc();

            foreach ($res as $r) {
                $prod_id = 74;

                if (
                    $r['lang'] == '11' || $r['lang'] == '55' || $r['lang'] == '65' || $r['lang'] == '60' || $r['lang'] == '52' || $r['lang'] == '84' || $r['lang'] == '44'
                    || $r['lang'] == '88' || $r['lang'] == '61' || $r['lang'] == '82'
                ) {
                    $prod_id = 73;
                }

                Database::getInstance()->insert(
                    'szamla_agent.web_product',
                    array(
                        "web_id" => $r['id'],
                        "product_id" => $prod_id
                    ),
                    'ii'
                );
            }

            echo 'done';
            die();

            break;

        case 'fill_test_weborder':
            $query = "SELECT * FROM cl_hlusers.o_products WHERE lang = 48";
            Database::getInstance()->query($query);
            $res = Database::getInstance()->fetchAssoc();

            foreach ($res as $value) {
                $prod = array(
                    "termek" => $value['termek'],
                    "kategoria" => $value['kategoria'],
                    "euro" => $value['euro'],
                    "usd" => 0,
                    "lang" => 37,
                    "seq" => 1,
                    "limit" => 51,
                    "email" => 'mate.nagy@cadline.hu',
                    "type" => $value['type'],
                    "sub_email" => '',
                    "o_type" => $value['o_type'],
                    "credit" => 0,
                    "incl_live" => $value['incl_live']
                );

                $id = Database::getInstance()->insert(CRMADATBAZIS . '.o_products', $prod, 'ssiiiiisisiii');

                $query = "SELECT * FROM szamla_agent.web_product WHERE web_id = ?";
                Database::getInstance()->query($query, array('i', $value['id']));
                $res2 = Database::getInstance()->fetchNext();

                if (!empty($res2)) {
                    Database::getInstance()->insert(
                        'szamla_agent.web_product',
                        array(
                            "web_id" => $id,
                            "product_id" => $res2['product_id']
                        ),
                        'ii'
                    );
                }
            }
            break;

        case 'product_insert':
            $query = "SELECT * FROM cl_hlusers.o_products WHERE lang NOT IN (36, 37, 371) GROUP BY lang";
            Database::getInstance()->query($query);
            $res = Database::getInstance()->fetchAssoc();

            $notEu = array(47, 61, 82, 60, 88, 11, 55, 65, 44, 54);

            foreach ($res as $value) {
                $invID = 39;
                $usd = 357;
                $eur = 357;

                if (in_array($value['lang'], $notEu)) {
                    $invID = 54;
                }

                $prod = array(
                    "termek" => 'Upgrade ARCHLine.XP Professional 2022 to 2023',
                    "kategoria" => 'upgrade',
                    "euro" => $eur,
                    "usd" => $usd,
                    "lang" => $value['lang'],
                    "seq" => 0,
                    "limit" => 51,
                    "email" => $value['email'],
                    "type" => '',
                    "sub_email" => $value['sub_email'],
                    "o_type" => 7,
                    "credit" => $value['credit'],
                    "incl_live" => 0
                );

                $id = Database::getInstance()->insert(CRMADATBAZIS . '.o_products', $prod, 'ssiiiiisisiii');

                $query = "SELECT * FROM szamla_agent.partnerek WHERE ország = ?";
                Database::getInstance()->query($query, array('i', $value['lang']));
                $res2 = Database::getInstance()->fetchNext();

                if (!empty($res2)) {
                    Database::getInstance()->insert(
                        'szamla_agent.web_product',
                        array(
                            "web_id" => $id,
                            "product_id" => $invID
                        ),
                        'ii'
                    );
                }
            }

            die();
            break;

        case 'partner_insert':
            $query = "SELECT * FROM cl_hlusers.o_products WHERE lang = ?";
            Database::getInstance()->query($query, array('i', 91));
            $res = Database::getInstance()->fetchAssoc();

            foreach ($res as $r) {
                $id = Database::getInstance()->insert(
                    CRMADATBAZIS . '.o_products',
                    array(
                        "termek" => $r['termek'],
                        "kategoria" => $r['kategoria'],
                        "euro" => $r['euro'],
                        "usd" => 0,
                        "lang" => 13,
                        "seq" => $r['seq'],
                        "limit" => 51,
                        "email" => 'administracion@a3dtec.com',
                        "type" => $r['type'],
                        "sub_email" => '',
                        "o_type" => $r['o_type'],
                        "credit" => 0,
                        "incl_live" => $r['incl_live'],
                        "module_id" => $r['module_id']
                    ),
                    'ssiiiiisisiiii'
                );

                /*$prod_id = 71;

                if (
                    $r['lang'] == '11' || $r['lang'] == '55' || $r['lang'] == '65' || $r['lang'] == '60' || $r['lang'] == '52' || $r['lang'] == '84' || $r['lang'] == '44'
                    || $r['lang'] == '88' || $r['lang'] == '61' || $r['lang'] == '82'
                ) {
                    $prod_id = 72;
                }

                Database::getInstance()->insert(
                    'szamla_agent.web_product',
                    array(
                        "web_id" => $id,
                        "product_id" => $prod_id
                    ),
                    'ii'
                );*/

                $query = "SELECT * FROM szamla_agent.web_product WHERE web_id = ?";
                Database::getInstance()->query($query, array('i', $r['id']));
                $res2 = Database::getInstance()->fetchNext();

                if (!empty($res2)) {
                    Database::getInstance()->insert(
                        'szamla_agent.web_product',
                        array(
                            "web_id" => $id,
                            "product_id" => $res2['product_id']
                        ),
                        'ii'
                    );
                }
            }


            echo 'done';
            die();

            /*$query = "SELECT * FROM `" . CRMADATBAZIS . "`.`o_products` WHERE lang = ?";
            Database::getInstance()->query($query, array('i', 492));
            $res = Database::getInstance()->fetchAssoc();

            foreach ($res as $r) {
                $id = Database::getInstance()->insert(
                    CRMADATBAZIS . '.o_products',
                    array(
                        "termek" => $r['termek'],
                        "kategoria" => $r['kategoria'],
                        "euro" => $r['euro'],
                        "usd" => 0,
                        "lang" => 44,
                        "seq" => $r['seq'],
                        "limit" => 51,
                        "email" => "",
                        "type" => $r['type']
                    ),
                    'ssiiiiisi'
                );

                $query = "SELECT * FROM szamla_agent.web_product WHERE web_id = ?";
                Database::getInstance()->query($query, array('i', $r['id']));
                $res2 = Database::getInstance()->fetchNext();

                if (!empty($res2)) {
                    Database::getInstance()->insert(
                        'szamla_agent.web_product',
                        array(
                            "web_id" => $id,
                            "product_id" => $res2['product_id']
                        ),
                        'ii'
                    );
                }
            }*/
            break;

        case 'check_p_serial_isid_active_all':
            $password = $_GET['password'];
            $active   = $_GET['active'];
            $all      = $_GET['all'];

            $db_all     = crm_hardlock::CountRegistration($password, 'all');
            $db_active  = crm_hardlock::CountRegistration($password, 'active');

            if ($active != $db_active) {
                echo 'error: nem egyeznek meg az active regisztraciok';
                die();
            }

            if ($all != $db_all) {
                echo 'error: a regisztraciok nem egyeznek meg';
                die();
            }

            echo 'ok';
            break;

        case 'clear_program':
            $userID = crm_hardlock::GetUserFromPassword($_GET['password']);

            if ($userID != 67960) {
                print "error: didn't allowed";
                die();
            }

            $result = crm_hardlock::ClearProgram($_GET['password']);
            if (!$result)
                print crm_hardlock::GetActivationError(crm_hardlock::CLEAR_FAILED);

            print 'ok';
            break;

        case 'unsubscribe_email':
            $query = "SELECT u.nUserID AS nUserID, MAX(h.dateEvent), u.strEducation AS strEducation, u.strEMail AS strEmail
                FROM cl_hlusers.users u
                LEFT JOIN cl_hlusers.u_history h ON h.nUserID = u.nUserID
                INNER JOIN cl_hlusers.u_emails e ON e.nUserID = u.nUserID
                WHERE u.nUserType = 1 AND e.newsletter = 1
                GROUP BY u.nUserID
                HAVING MAX(h.dateEvent) <= '2018-12-31'
                ORDER BY MAX(h.dateEvent)";
            Database::getInstance()->query($query);
            $res = Database::getInstance()->fetchAssoc();

            foreach ($res as $value) {
                $updateSql1 = "UPDATE cl_hlusers.u_emails SET newsletter = 0 WHERE nUserID = " . $value['nUserID'];
                crm_database::getInstance()->query($updateSql1);
            }
            die();
            break;

        case 'delete_contact_users':
            $query = "SELECT u.nUserID AS nUserID, MAX(h.dateEvent), u.strEducation AS strEducation, u.strEMail AS strEmail
                FROM cl_hlusers.users u
                LEFT JOIN cl_hlusers.u_history h ON h.nUserID = u.nUserID
                WHERE u.nUserType = 0 AND (u.strEducation = '' OR u.strEducation IS NULL) AND nUserProf != 9 AND nUserProf != 20
                GROUP BY u.nUserID
                HAVING MAX(h.dateEvent) <= '2021-12-31'
                ORDER BY MAX(h.dateEvent)";
            Database::getInstance()->query($query);
            $res = Database::getInstance()->fetchAssoc();

            //echo 'COUNT: ' . count($res) . '<br/><br/>';

            $i = 0;

            foreach ($res as $value) {
                if ($value['nUserID'] == 57343 || $value['nUserID'] == 56321 || $value['nUserID'] == 24001 || $value['nUserID'] == 18 || $value['nUserID'] == 14140)
                    continue;

                /*$query2 = "SELECT nUserID FROM `" . CRMADATBAZIS . "`.`u_emails` WHERE nUserID = ? AND email LIKE '%@freemail.hu' AND newsletter = ?";
                Database::getInstance()->query($query2, array('ii', $value['nUserID'], 1));
                $res2 = Database::getInstance()->fetchAssoc();

                if (empty($res2))
                    continue;*/

                $query2 = "SELECT nUserID FROM `" . CRMADATBAZIS . "`.`u_history` WHERE nUserID = ? AND nTopicID = ?";
                Database::getInstance()->query($query2, array('ii', $value['nUserID'], 33));
                $res2 = Database::getInstance()->fetchAssoc();

                if (!empty($res2))
                    continue;

                $query3 = "SELECT hlUser FROM `" . CRMADATBAZIS . "`.`hardlock` WHERE hlUser = ?";
                Database::getInstance()->query($query3, array('i', $value['nUserID']));
                $res3 = Database::getInstance()->fetchAssoc();

                if (!empty($res3))
                    continue;

                echo '<a href="https://crm.cadline.hu/hu/users/show/' . $value['nUserID'] . '" target="_blank">' . $value['nUserID'] . '</a><br/>';

                // crm_users::deleteUser($value['nUserID']);

                $i++;
            }

            echo '<br/> COUNT: ' . $i;

            die();
            break;

        case 'change_nonp_users':
            $query = "SELECT nUserID FROM `" . CRMADATBAZIS . "`.`users` WHERE nUserType = ? AND old_db = ?";
            Database::getInstance()->query($query, array('is', 2, 'clusers'));
            $res = Database::getInstance()->fetchAssoc();

            $stack = array();

            foreach ($res as $user) {
                $query = "SELECT * FROM `" . CRMADATBAZIS . "`.`hardlock` WHERE hlUser = ?";
                Database::getInstance()->query($query, array('i', $user['nUserID']));
                $res2 = Database::getInstance()->fetchNext();

                if (empty($res2)) array_push($stack, $user['nUserID']);
            }

            echo 'Összes: ' . count($stack);
            echo '<br/>';
            echo '<br/>';

            foreach ($stack as $value) {
                $query = "UPDATE `" . CRMADATBAZIS . "`.`users` SET nUserType = ? WHERE nUserID = ?";
                //Database::getInstance()->query($query, array('ii', 0, $value));
                echo "<a href='http://crm.cadline.hu/hu/users/show/" . $value . "' target='_blank'>" . $value . "</a><br/>";
            }

            break;

        case 'delete_nonp_from_users':
            $sql = "SELECT p.prHlNum AS prHlNum, p.prPass AS prPass, p.prFizetve AS prFizetve
                FROM h_programs p
                LEFT JOIN hardlock h ON h.hlNum = p.prHlNum
                LEFT JOIN users u ON u.nUserID = h.hlUser
                WHERE (p.prFizetve < '2023-09-01' OR p.prFizetve = '' OR p.prFizetve IS NULL) AND h.hlCtrID = 36 AND u.nUserType = 2 AND h.hlUser != 25407 
                AND h.hlNum LIKE '99%' AND u.nSchoolID = 0
                AND h.hlUser != 80109;";

            crm_database::getInstance()->query($sql);
            $res = crm_database::getInstance()->fetchAssoc();

            $i = 0;

            foreach ($res as $value) {
                $hlNum = "";
                $hlNum = $value['prHlNum'];

                $sql2 = "SELECT * FROM `" . CRMADATBAZIS . "`.`h_programs` WHERE prHlNum = ? AND prFizetve >= ?";
                Database::getInstance()->query($sql2, array('ss', $hlNum, '2023-09-01'));
                $res2 = Database::getInstance()->fetchAssoc();

                if (!empty($res2)) continue;

                /*Database::getInstance()->query("DELETE FROM `" . CRMADATBAZIS . "`.`h_programs` WHERE prPass = ?", array('s', $value['prPass']));
                Database::getInstance()->query("DELETE FROM `" . CRMADATBAZIS . "`.`p_serial_isid` WHERE serial = ?", array('s', $value['prPass']));
                Database::getInstance()->query("DELETE FROM `" . CRMADATBAZIS . "`.`userstats2013` WHERE usPwd = ?", array('s', $value['prPass']));

                Database::getInstance()->query("SELECT * FROM `" . CRMADATBAZIS . "`.`h_programs` WHERE prHlNum = ?", array('s', $hlNum));
                $res3 = Database::getInstance()->fetchNext();

                if (empty($res3)) {
                    Database::getInstance()->query("UPDATE `" . CRMADATBAZIS . "`.`hardlock` SET hlUser = '', hlStat = ? WHERE hlNum = ?", array('is', 0, $hlNum));
                    Database::getInstance()->query("DELETE FROM `" . CRMADATBAZIS . "`.`h_history` WHERE hiHlNum = ?", array('s', $hlNum));
                    Database::getInstance()->query("DELETE FROM `" . CRMADATBAZIS . "`.`nonprofit` WHERE hlID = ?", array('s', $hlNum));
                }*/

                $i++;

                echo '<a href="http://crm.cadline.hu/48/hardlock/show/' . $hlNum . '" target="_blank">' . $value['prPass'] . ' - ' . $value['prFizetve'] . '</a><br/>';
            }
            echo $i;
            break;

        case 'check_empty_users':
            $sql = "SELECT * FROM cl_hlusers.users WHERE strTel = '' AND strEMail = '' AND old_db = 'clusers_eng'";
            crm_database::getInstance()->query($sql);
            $res = crm_database::getInstance()->fetchAssoc();

            $i = 0;

            foreach ($res as $value) {
                $sql2 = "SELECT * FROM cl_hlusers.u_history WHERE nUserID = " . $value['nUserID'];
                crm_database::getInstance()->query($sql2);
                $res2 = crm_database::getInstance()->fetchNext();

                if (!empty($res2))
                    continue;

                $sql3 = "SELECT * FROM cl_hlusers.hardlock WHERE hlUser = " . $value['nUserID'];
                crm_database::getInstance()->query($sql3);
                $res3 = crm_database::getInstance()->fetchNext();

                if (!empty($res3))
                    continue;

                // crm_users::deleteUser($value['nUserID']);

                echo '<a href="https://crm.cadline.hu/hu/users/show/' . $value['nUserID'] . '" target="_blank">' . $value['nUserID'] . '</a><br/>';

                $i++;
            }

            echo '<br/> Count: ' . $i;
            die();
            break;

        case 'kill_empty_program':
            $query = "SELECT h.hlNum AS hlNum
                FROM cl_hlusers.hardlock h
                LEFT JOIN cl_hlusers.users u ON u.nUserID = h.hlUser
                WHERE u.old_db = 'clusers' AND u.nUserType = 2 AND h.hlNum LIKE '99%'";
            crm_database::getInstance()->query($query);
            $res = crm_database::getInstance()->fetchAssoc();

            $i = 0;
            foreach ($res as $value) {
                $hlNum = $value['hlNum'];

                $sql2 = "SELECT * FROM `" . CRMADATBAZIS . "`.`h_programs` WHERE prHlNum = ?";
                Database::getInstance()->query($sql2, array('s', $hlNum));
                $res2 = Database::getInstance()->fetchAssoc();

                if (!empty($res2)) continue;

                $i++;

                //Database::getInstance()->query("UPDATE `" . CRMADATBAZIS . "`.`hardlock` SET hlUser = '', hlStat = ? WHERE hlNum = ?", array('is', 0, $hlNum));

                echo '<a href="http://crm.cadline.hu/48/hardlock/show/' . $hlNum . '" target="_blank">' . $hlNum . '</a><br/>';
            }

            echo $i;
            die();
            break;

        case 'kill_nonp':
            $sql = "SELECT h.prHlNum AS prHlNum, h.prPass AS prPass, h.prFizetve AS prFizetve
                FROM `" . CRMADATBAZIS . "`.`h_programs` h 
                LEFT JOIN hardlock ho ON ho.hlNum = h.prHlNum
                LEFT JOIN users u ON u.nUserID = ho.hlUser
                WHERE h.prFizetve <= '2023-08-31' AND h.prPass LIKE '96%' AND u.old_db = 'clusers' 
                AND h.prHlNum != '990191' AND h.prHlNum != '993968'
                GROUP BY h.prPass";
            crm_database::getInstance()->query($sql);
            $res = crm_database::getInstance()->fetchAssoc();

            $i = 0;

            foreach ($res as $value) {
                $hlNum = $value['prHlNum'];

                $sql2 = "SELECT * FROM `" . CRMADATBAZIS . "`.`h_programs` WHERE prHlNum = ? AND prFizetve >= ?";
                Database::getInstance()->query($sql2, array('ss', $hlNum, '2022-08-31'));
                $res2 = Database::getInstance()->fetchAssoc();

                if (!empty($res2)) continue;

                /*Database::getInstance()->query("DELETE FROM `" . CRMADATBAZIS . "`.`h_programs` WHERE prPass = ?", array('s', $value['prPass']));
                Database::getInstance()->query("DELETE FROM `" . CRMADATBAZIS . "`.`p_serial_isid` WHERE serial = ?", array('s', $value['prPass']));
                Database::getInstance()->query("DELETE FROM `" . CRMADATBAZIS . "`.`userstats2013` WHERE usPwd = ?", array('s', $value['prPass']));

                Database::getInstance()->query("SELECT * FROM `" . CRMADATBAZIS . "`.`h_programs` WHERE prHlNum = ?", array('s', $hlNum));
                $res3 = Database::getInstance()->fetchNext();

                if (empty($res3)) {
                    Database::getInstance()->query("UPDATE `" . CRMADATBAZIS . "`.`hardlock` SET hlUser = '', hlStat = ? WHERE hlNum = ?", array('is', 0, $hlNum));
                    Database::getInstance()->query("DELETE FROM `" . CRMADATBAZIS . "`.`h_history` WHERE hiHlNum = ?", array('s', $hlNum));
                    Database::getInstance()->query("DELETE FROM `" . CRMADATBAZIS . "`.`nonprofit` WHERE hlID = ?", array('s', $hlNum));
                }*/

                $i++;

                echo '<a href="http://crm.cadline.hu/48/hardlock/show/' . $hlNum . '" target="_blank">' . $value['prPass'] . ' - ' . $value['prFizetve'] . '</a><br/>';
            }
            echo $i;
            break;

        case 'change_nonp_status':
            $sql = "SELECT nUserID FROM `" . CRMADATBAZIS . "`.`users` WHERE nUserType = ? AND nCtrID = ?";
            Database::getInstance()->query($sql, array('ii', 2, 36));
            $res = Database::getInstance()->fetchAssoc();

            $i = 0;

            foreach ($res as $value) {
                $sql2 = "SELECT * FROM `" . CRMADATBAZIS . "`.`hardlock` WHERE hlUser = ?";
                Database::getInstance()->query($sql2, array('s', $value['nUserID']));
                $res2 = Database::getInstance()->fetchAssoc();

                if (empty($res2)) {
                    $i++;
                    //Database::getInstance()->query("UPDATE `" . CRMADATBAZIS . "`.`users` SET nUserType = ? WHERE nUserID = ?", array('ii', 0, $value['nUserID']));
                    echo '<a href="https://crm.cadline.hu/hu/users/show/' . $value['nUserID'] . '" target="_blank">' . $value['nUserID'] . '</a><br/>';
                }
            }

            echo $i;
            break;

        case 'change_students_course':
            $sql = 'SELECT * FROM cl_hlusers.students WHERE course_id IN (72, 78, 82, 86, 105, 218, 247, 248)';
            Database::getInstance()->query($sql);
            $res = Database::getInstance()->fetchAssoc();

            foreach ($res as $value) {
                $sql2 = "SELECT * FROM `" . CRMADATBAZIS . "`.`hardlock` WHERE hlUser = ?";
                Database::getInstance()->query($sql2, array('s', $value['nUserID']));
                $res2 = Database::getInstance()->fetchAssoc();

                if (empty($res2)) {
                    $sql3 = 'SELECT * FROM cl_hlusers.courses WHERE school_id = ' . $value['school_id'] . ' AND is_archive = 1';
                    Database::getInstance()->query($sql3);
                    $res3 = Database::getInstance()->fetchNext();

                    if (!empty($res3)) {
                        //Database::getInstance()->query("UPDATE `" . CRMADATBAZIS . "`.`students` SET course_id = ? WHERE nUserID = ?", array('ii', $res3['id'], $value['nUserID']));
                        echo '<a href="https://crm.cadline.hu/hu/users/show/' . $value['nUserID'] . '" target="_blank">' . $value['nUserID'] . '</a><br/>';
                    }
                }
            }
            break;

        case 'delete_user_history':
            $sql = "SELECT nUserID FROM `" . CRMADATBAZIS . "`.`users` WHERE nUserType = ? AND old_db != ?";
            Database::getInstance()->query($sql, array('is', 0, 'clusers'));
            $res = Database::getInstance()->fetchAssoc();

            $i = 1;

            foreach ($res as $value) {
                $sql2 = "SELECT dateEvent FROM `" . CRMADATBAZIS . "`.`u_history` WHERE nUserID = ? ORDER BY dateEvent DESC";
                Database::getInstance()->query($sql2, array('i', $value['nUserID']));
                $res2 = Database::getInstance()->fetchNext();

                if ($res2['dateEvent'] > '2018-12-31')
                    continue;

                $sql3 = "SELECT * FROM `" . CRMADATBAZIS . "`.`hardlock` WHERE hlUser = ?";
                Database::getInstance()->query($sql3, array('i', $value['nUserID']));
                $res3 = Database::getInstance()->fetchAssoc();

                if (!empty($res3)) {
                    /*foreach ($res3 as $hl) {
                        if ($hl['hlNum'] == '394040')
                            continue;
                        echo '<a href="https://crm.cadline.hu/36/hardlock/show/'.$hl['hlNum'].'" target="_blank">'.$hl['hlNum'].'</a><br/>';
                        //Database::getInstance()->query("UPDATE `".CRMADATBAZIS."`.`hardlock` SET hlUser = ? WHERE hlNum = ?", array('ss', '', $hl['hlNum']));
                        //Database::getInstance()->query("DELETE FROM `".CRMADATBAZIS."`.`h_programs` WHERE prHlNum = ?", array('s', $hl['hlNum']));
                    }*/

                    continue;
                }

                Database::getInstance()->query("DELETE FROM `" . CRMADATBAZIS . "`.`u_history` WHERE nUserID = ?", array('i', $value['nUserID']));
                Database::getInstance()->query("DELETE FROM `" . CRMADATBAZIS . "`.`users` WHERE nUserID = ?", array('i', $value['nUserID']));

                $i++;

                echo '<a href="https://crm.cadline.hu/hu/users/show/' . $value['nUserID'] . '" target="_blank">' . $value['nUserID'] . '</a><br/>';
            }
            echo '<br/>';
            echo $i;
            break;

        case 'delete_inactive_users_new':
            $query = "SELECT h.nUserID AS nUserID, h.dateEvent AS dateEvent
                FROM `cl_hlusers`.`u_history` h
                LEFT JOIN cl_hlusers.users u ON u.nUserID = h.nUserID
                WHERE h.dateEvent < '2021-01-01' AND u.old_db = 'clusers' AND u.nUserType = 0
                GROUP BY h.nUserID;";

            /*$query = "SELECT h.nUserID AS nUserID
                FROM cl_hlusers.u_history h
                LEFT JOIN cl_hlusers.users u ON u.nUserID = h.nUserID
                WHERE (h.nTopicID = 366) AND u.nUserType = 0 AND u.old_db = 'clusers_eng' AND u.nUserType = 0 AND (u.strEducation = '' || u.strEducation IS NULL)
                GROUP BY u.nUserID;";*/
            Database::getInstance()->query($query);
            $res = Database::getInstance()->fetchAssoc();

            // 2021-01-01-et megnezni es Erikanak tovabbitani!
            // A Megkeresendőknél, "BIMLadder Non-profit aktiválás" vagy "Namirial Non-profit aktiválás"


            // 366 - Namirial
            // 368 - BIM Ladder

            $i = 0;

            foreach ($res as $value) {
                $sql3 = "SELECT * FROM `" . CRMADATBAZIS . "`.`u_history` WHERE dateEvent >= ? AND nUserID = ?";
                Database::getInstance()->query($sql3, array('si', '2021-01-01', $value['nUserID']));
                $res3 = Database::getInstance()->fetchNext();

                if (!empty($res3))
                    continue;

                $sql2 = "SELECT * FROM `" . CRMADATBAZIS . "`.`hardlock` WHERE hlUser = ?";
                Database::getInstance()->query($sql2, array('i', $value['nUserID']));
                $res2 = Database::getInstance()->fetchNext();

                if (!empty($res2))
                    continue;

                /*$sql4 = "SELECT * FROM `" . CRMADATBAZIS . "`.`u_history` WHERE nUserID = ? AND (nTopicID = ? OR nTopicID = ?)";
                Database::getInstance()->query($sql2, array('iii', $value['nUserID'], 366, 368));
                $res4 = Database::getInstance()->fetchNext();

                if (empty($res4))
                    continue;*/

                /*Database::getInstance()->query("DELETE FROM `" . CRMADATBAZIS . "`.`u_history` WHERE nUserID = ?", array('i', $value['nUserID']));
                Database::getInstance()->query("DELETE FROM `" . CRMADATBAZIS . "`.`users` WHERE nUserID = ?", array('i', $value['nUserID']));
                Database::getInstance()->query("DELETE FROM `" . JMLADATBAZIS . "`.`jml_users` WHERE nUserID = ?", array('i', $value['nUserID']));*/
                echo "<a href='http://crm.cadline.hu/hu/users/show/" . $value['nUserID'] . "' target='_blank'>" . $value['nUserID'] . "</a><br/>";

                $i++;
            }

            echo '<br/>';
            echo '<br/>';
            echo 'Összesen: ' . $i;
            break;

        case 'delete_inactive_users':
            $query = "SELECT history.dateEvent AS dateEvent, history.nUserID AS nUserID FROM
                (
                	SELECT * FROM `" . CRMADATBAZIS . "`.`u_history`
                    ORDER BY u_history.dateEvent DESC
                ) AS history
                LEFT JOIN cl_hlusers.users u ON u.nUserID = history.nUserID
                WHERE u.old_db = 'clusers'
                GROUP BY history.nUserID";
            Database::getInstance()->query($query);
            $res = Database::getInstance()->fetchAssoc();

            $stack = array();

            foreach ($res as $value) {
                if ($value['dateEvent'] < '2018-01-01') {
                    $sql2 = "SELECT * FROM `" . CRMADATBAZIS . "`.`hardlock` WHERE hlUser = ?";
                    Database::getInstance()->query($sql2, array('i', $value['nUserID']));
                    $res2 = Database::getInstance()->fetchNext();

                    if (empty($res2)) {
                        /*$sql3 = "SELECT * FROM `" . CRMADATBAZIS . "`.`u_history` WHERE nUserID = ? AND nTopicID = ?";
                        Database::getInstance()->query($sql3, array('ii', $value['nUserID'], 102));
                        $res3 = Database::getInstance()->fetchNext();*/

                        $sql3 = "SELECT * FROM `" . CRMADATBAZIS . "`.`u_history` WHERE dateEvent >= ?";
                        Database::getInstance()->query($sql3, array('s', '2018-01-01'));
                        $res3 = Database::getInstance()->fetchNext();

                        if (empty($res3)) array_push($stack, $value['nUserID']);
                    }
                }
            }

            echo count($stack);
            echo '<br/>';
            echo '<br/>';

            foreach ($stack as $value) {
                echo "<a href='http://crm.cadline.hu/hu/users/show/" . $value . "' target='_blank'>" . $value . "</a><br/>";
                //Database::getInstance()->query("DELETE FROM `".CRMADATBAZIS."`.`u_history` WHERE nUserID = ?", array('i', $value));
                //Database::getInstance()->query("DELETE FROM `".CRMADATBAZIS."`.`users` WHERE nUserID = ?", array('i', $value));
                //Database::getInstance()->query("DELETE FROM `".JMLADATBAZIS."`.`jml_users` WHERE nUserID = ?", array('i', $value));
            }
            break;

        case 'correct_emails':
            $query = "SELECT * FROM `" . CRMADATBAZIS . "`.`users` WHERE (strEMail = '' OR strEMail IS NULL) AND nUserID IN (SELECT nUserID FROM `" . CRMADATBAZIS . "`.`u_emails`)";
            Database::getInstance()->query($query);
            $res = Database::getInstance()->fetchAssoc();

            foreach ($res as $value) {
                $sql2 = "SELECT * FROM `" . CRMADATBAZIS . "`.`u_emails` WHERE nUserID = ?";
                Database::getInstance()->query($sql2, array('i', $value['nUserID']));
                $res2 = Database::getInstance()->fetchNext();

                if (!empty($res2)) {
                    Database::getInstance()->query("UPDATE `" . CRMADATBAZIS . "`.`users` SET strEMail = ? WHERE nUserID = ?", array('si', $res2['email'], $value['nUserID']));
                }
            }
            break;

        case 'reg_unreg_test':
            if (!class_exists('crm_test')) require_once("common_cadline_libraries/crm_test.class.php");

            $result = crm_test::launchTests();
            echo $result;
            break;

        case 'program_update':
            // prHiType = 3
            $query = "SELECT p.prTypeID AS prTypeID, h.hlNum AS hlNum, p.prManID AS manid, p.prVerID AS verID, p.prPass AS prPass
                FROM `" . CRMADATBAZIS . "`.`h_programs` p
                LEFT JOIN `" . CRMADATBAZIS . "`.`hardlock` h ON h.hlNum = p.prHlNum
                LEFT JOIN `" . CRMADATBAZIS . "`.`users` u ON u.nUserID = h.hlUser
                WHERE p.prVerID = 19 AND h.hlCtrID = 36 AND p.prTypeID = 76 AND p.prContact = 0 AND h.hlNum != 361251 AND h.hlNum != 361293";
            Database::getInstance()->query($query);
            $res = Database::getInstance()->fetchAssoc();

            foreach ($res as $value) {
                //$password   = Codegen::GeneratePassword($value['hlNum'], 0, 76, 77);
                /*Database::getInstance()->insert(CRMADATBAZIS.'.h_programs',array(
                    "prPass"=>$password,
                    "prVerID"=>20,
                    "prTypeID"=>76,
                    "prLan"=>0,
                    "prSellDate" => date('Y-m-d'),
                    "prFizetve" => "2050-01-01",
                    "prContact" => 0,
                    "prHlNum"   => $value['hlNum'],
                    "prPrice" => 0,
                    "prManID" => $value['manid'],
                    "prStat" => 0,
                    "prHiType" => 3),
                    'siiissisiiii'
                );*/
                //Database::getInstance()->query("UPDATE `".CRMADATBAZIS."`.`h_programs` SET prStat = ? WHERE prPass = ?", array('is', 1, $value['prPass']));
            }
            break;

        case 'update_maintainer_program_price':
            $query = 'SELECT p.prID AS prID, p.prPass AS password, p.prContact AS contact, h.hlNum AS hlNum, p.prManID AS manid,
                    p.prTypeID AS typeID, p.prHiType AS hiType, p.prLan AS lan, p.prPrice AS prPrice,
                    p.prInvoiceDateFrom AS invDateFrom, p.prInvoiceDateTo AS invDateTo, p.prInvoiceRecurrence AS ressurence
                FROM cl_hlusers.h_programs p
                LEFT JOIN cl_hlusers.hardlock h ON h.hlNum = p.prHlNum
                WHERE p.prContact = 6 AND p.prVerID = 24 AND h.hlCtrID = 36 AND p.prStat = 0 AND 
                    p.prPrice IN (31000) AND p.prTypeID = 2
                GROUP BY p.prPass';

            Database::getInstance()->query($query);
            $res = Database::getInstance()->fetchAssoc();

            var_dump($res);
            die();

            foreach ($res as $value) {
                /*if ($value['prPrice'] == 31500) $price = 33500;
                if ($value['prPrice'] == 28000) $price = 31000;
                if ($value['prPrice'] == 21000) $price = 23000;*/

                $price = 34000;

                Database::getInstance()->query("UPDATE `" . CRMADATBAZIS . "`.`h_programs` SET prPrice = ? WHERE prPass = ?", array('ss', $price, $value['password']));
            }

            die();
            break;

        case 'po_export_text':
            $json = file_get_contents('https://www.archline.hu/maintenance/pofiles/LiveLanguageResources_eng.json');
            $test = json_decode($json);

            foreach ($test as $key => $asd) {
                echo $key;
                echo '<br/>';
                var_dump($asd);
                die();
            }
            break;

        case 'delete_school_from_users':
            $query = "SELECT u.nUserID AS nUserID, u.strName, u.vegzes_ideje
                FROM cl_hlusers.users u 
                WHERE u.vegzes_ideje <= '2023-08-31' AND u.nSchoolID > 0 AND u.strEducation NOT LIKE '%Passziv%' AND old_db = 'clusers'
                order by u.nUserID";

            Database::getInstance()->query($query);
            $res = Database::getInstance()->fetchAssoc();

            $i = 0;

            foreach ($res as $value) {
                /*$query2 = "SELECT h.hlID, h.hlUser AS hlUser, p.prFizetve AS prFizetve
                    FROM cl_hlusers.hardlock h
                    LEFT JOIN cl_hlusers.h_programs p ON p.prHlNum = h.hlNum
                    WHERE h.hlNum LIKE '99%' AND p.prTypeID = 8 AND h.hlUser = '" . $value['nUserID'] . "'
                    ORDER BY p.prVerID DESC LIMIT 1";

                Database::getInstance()->query($query2);
                $res2 = Database::getInstance()->fetchNext();

                if ($res2['prFizetve'] > '2023-08-31')
                    continue;*/

                $i++;

                echo '<a href="https://crm.cadline.hu/hu/users/show/' . $value['nUserID'] . '" target="_blank">' . $value['nUserID'] . '</a><br/>';
                //$updateSql1 = "UPDATE cl_hlusers.users SET nSchoolID = 0 WHERE nUserID = " . $value['nUserID'];
                //crm_database::getInstance()->query($updateSql1);
                continue;

                if (count($res2) > 0) {
                    if ($res2['prFizetve'] > '2023-08-31')
                        continue;

                    echo '<a href="https://crm.cadline.hu/hu/users/show/' . $value['nUserID'] . '" target="_blank">' . $value['nUserID'] . '</a><br/>';

                    //$updateSql1 = "UPDATE cl_hlusers.users SET nSchoolID = 0 WHERE nUserID = " . $value['nUserID'];
                    //crm_database::getInstance()->query($updateSql1);
                }

                //var_dump(count($res2));
            }

            echo '<br>' . $i;

            //var_dump(count($res));
            die();
            break;

        case 'update_maintainer_programs':
            $query = 'SELECT p.prID AS prID, p.prPass AS password, p.prContact AS contact, h.hlNum AS hlNum, p.prManID AS manid,
                p.prTypeID AS typeID, p.prHiType AS hiType, p.prLan AS lan, p.prPrice AS prPrice, p.update_price AS update_price,
                p.prInvoiceDateFrom AS invDateFrom, p.prInvoiceDateTo AS invDateTo, p.prInvoiceRecurrence AS ressurence
                FROM cl_hlusers.h_programs p
                LEFT JOIN cl_hlusers.hardlock h ON h.hlNum = p.prHlNum
                WHERE p.prContact IN (2, 6, 7) AND p.prVerID = 25 AND h.hlCtrID = 36 AND p.prStat = 0
                GROUP BY p.prPass';

            Database::getInstance()->query($query);
            $res = Database::getInstance()->fetchAssoc();

            var_dump($res);
            die();

            foreach ($res as $value) {
                $password = Codegen::GeneratePassword($value['hlNum'], 0, $value['typeID'], 81);
                $price = $value['prPrice'];
                $updatePrice = 0;

                /*$command = PATH_CODEGEN . " -Module " . $password . " " . $nModNr;
                $ph = popen($command, "r")
                    or die("A 'codegen' paranccsal nem veheto fel kapcsolat");
                $modcode = fgets($ph, 1024);
                pclose($ph);*/

                /*if ($value['contact'] == 2) {
                    if ($value['prPrice'] == 126000) $price = 126000;
                    if ($value['prPrice'] == 122000) $price = 126000;
                    if ($value['prPrice'] == 118000) $price = 122000;
                    if ($value['prPrice'] == 104000) $price = 112000;
                    if ($value['prPrice'] == 80000) $price = 84000;
                    if ($value['prPrice'] == 63000) $price = 63000;
                }

                if ($value['contact'] == 6) {
                    if ($value['prPrice'] == 30500) $price = 31500;
                    if ($value['prPrice'] == 26000) $price = 28000;
                    if ($value['prPrice'] == 24500) $price = 25500;
                    if ($value['prPrice'] == 20000) $price = 21000;
                    if ($value['prPrice'] == 15250) $price = 16000;
                }
                    
                if ($value['contact'] == 7) {
                    $updatePrice = $value['update_price'];
                }
                */

                /*$newPrID = Database::getInstance()->insert(
                    CRMADATBAZIS . '.h_programs',
                    array(
                        "prPass"                => $password,
                        "prVerID"               => 26,
                        "prTypeID"              => $value['typeID'],
                        "prLan"                 => $value['lan'],
                        "prSellDate"            => date('Y-m-d'),
                        "prFizetve"             => "2026-01-31",
                        "update_price"          => $updatePrice,
                        "prContact"             => $value['contact'],
                        "prHlNum"               => $value['hlNum'],
                        "prPrice"               => $price,
                        "prManID"               => $value['manid'],
                        "prStat"                => 0,
                        "prHiType"              => $value['hiType'],
                        "prInvoiceDateFrom"     => $value['invDateFrom'],
                        "prInvoiceDateTo"       => $value['invDateTo'],
                        "prInvoiceRecurrence"   => $value['ressurence']
                    ),
                    'siiissisiiiissi'
                );

                $query2 = 'SELECT * FROM cl_hlusers.p_modules WHERE mdPrID = ' . $value['prID'];
                Database::getInstance()->query($query2);
                $modules = Database::getInstance()->fetchAssoc();

                if (!empty($modules)) {
                    foreach ($modules as $module) {
                        Database::getInstance()->insert(
                            CRMADATBAZIS . '.p_modules',
                            array(
                                "mdID"      => $module['mdID'],
                                "mdPrID"    => $newPrID,
                                "mdPrHlNum" => $value['hlNum'],
                                "mdCode"    => $module['mdCode'],
                                "mdDate"    => date('Y-m-d'),
                                "mdPrice"   => 0
                            ),
                            'iisssi'
                        );
                    }
                }

                Database::getInstance()->query("UPDATE `" . CRMADATBAZIS . "`.`h_programs` SET prStat = ? WHERE prPass = ?", array('is', 1, $value['password']));*/
            }
            break;
    }
}
