<?php

    // einmal die stunde ausführen
    
    $mysq_host = "185.79.202.55";
    $mysql_user = "nauprod_v2";
    $mysql_db = "nauprod_v2";
    $mysql_password = "8ZQM5fzSW3gQS8Lo";

    // connect to the database

    $mysqli_con = mysqli_connect($mysq_host,$mysql_user,$mysql_password,$mysql_db);
    if ($mysqli_con == "FALSE") { print "cannot connect"; die; }

    $api = "https://api.nau.ch";
    define('API_URL', $api);
    $bearer = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL2FwaS5uYXUuY2gvdG9rZW4iLCJpYXQiOjE1Mzc3ODM1MzksImV4cCI6MjU2OTMxOTUzOSwibmJmIjoxNTM3NzgzNTM5LCJqdGkiOiJuSm9RejNUT21ickhXRm5IIiwic3ViIjo4MDQsInBydiI6Ijg3ZTBhZjFlZjlmZDE1ODEyZmRlYzk3MTUzYTE0ZTBiMDQ3NTQ2YWEifQ.hXPNxqdKwHZ4g-t4q1BaZMPmwSuUyo1kKXEjEl6OwgQ";

    $article_array = array_to_id();
    

    $seek_magazines = array(3,4,5,6,7,8,9,11,12);
    // remove techtrends 11
    // $seek_magazines = array(3,4,5,6,7,8,9,12);
    $sql = "SELECT * FROM `magazines` WHERE `id` IN (".implode(",", $seek_magazines).")";
    $result = $mysqli_con->query($sql);
    $magazines = [];
    while ($row = $result->fetch_assoc()) {
        $magazines[$row['id']] = $row;
    }

    foreach ($seek_magazines as $mag_id) {
        $min_age = 24*60*60; // 24h
        $min_age = 100 * $min_age;
        print $mag_id . "\n";
        $articles = getLatestFromMagToRepublish($mag_id);
        if (count($articles) > 0) {
            foreach($articles as $article) {
                $published_at = strtotime($article['published_at']);

                if($published_at - $min_age > time()) {
                    // zu jung
                    print "mag_id: " . $mag_id . ": " .  $article['published_at'] . " - " . date('Y-m-d H:i:s', $published_at) . " zu jung\n";
                    continue;
                }
                $publihsed_at_hour = date('H', $published_at);

                if($publihsed_at_hour != date('H')) {
                    // muss gleich ezeit haben
                    print "mag_id: " . $mag_id . ": " .  $article['published_at'] . " != " . date('H') . "\n";
                    continue;
                }

                if($article['status_id'] != 11) {
                    // muss status 11 haben
                    print "mag_id: " . $mag_id . ": " .  $article['published_at'] . " status != 11\n";
                    continue;
                }

                print "Respulish mag_id: " . $mag_id . ": " .  $article['published_at'] . "\n";
                [$ret, $httpCode] = republishArticle($article['id']);
                
                $article = json_decode($ret, true);
                $ret = publishArticle($article['id']);
                print $ret[1] . " - " . $article['id'] . " - " . $article['title'] . "\n";
            }
        }
    }

    // functions from here

    function getTheString() {
        $string = "x;5;6;3;12;9;7;4;8;11
01.02.25;66664455;;;;66665970;66655990;66676312;66659766;66653953
02.02.25;66664455;;;;66666331;66657076;66673908;66659753;66654832
03.02.25;66664200;;;;66666430;66650370;66676302;66659670;66655368
04.02.25;66664239;;;;66666623;66650333;66673898;66659495;66653954
05.02.25;66664886;;;;66666449;66651252;66673718;66659547;66654801
06.02.25;66664482;;;;66666506;66651206;66671627;66659507;66653777
07.02.25;66664908;;;;66668137;66650281;66676270;66659222;66655408
08.02.25;66670424;;;;66668124;66650332;66673795;66659178;66653965
09.02.25;66664912;;;;66666987;66657708;66675410;66659166;66654495
10.02.25;66664947;;;;66668092;66650489;66671609;66658973;66653779
11.02.25;66664497;;;;66668064;66657062;66674472;66658863;66655432
12.02.25;66665110;;;;66668033;66658046;66671591;66660028;66653955
13.02.25;66665253;;;;66668306;66661826;66676358;66660016;66653778
14.02.25;66664957;;;;66668771;66656301;66673928;66659990;66651069
15.02.25;66665002;;;;66668738;66650722;66678268;66660004;66654691
16.02.25;66666282;;;;66667007;66657878;66675376;66659973;66656115
17.02.25;66667238;;;;66668812;66650412;66677745;66660779;66655250
18.02.25;66667268;;;;66668873;66650410;66678263;66660757;66653624
19.02.25;66665255;;;;66668251;66651369;66679033;66660247;66655935
20.02.25;66665828;;;;66670303;66651276;66678322;66660235;66655241
21.02.25;66665250;;;;66666995;66650368;66678538;66660155;66653581
22.02.25;66665244;;;;66668716;66650398;66679062;66660137;66653952
23.02.25;66669674;;;;66668182;66657150;66678270;66660098;66654833
24.02.25;66669269;;;;66668169;66650721;66674880;66660067;66653852
25.02.25;66669637;;;;66669529;66663384;66679040;66660885;66652015
26.02.25;66669094;;;;66669568;66650611;66678306;66660507;66655235
27.02.25;66669732;;;;66669341;66650465;66674859;66660360;66656105
28.02.25;66669267;;;;66667114;66657910;66678249;66660348;66655261
01.03.25;66669272;;;;66669617;66658100;66678267;66663497;66653665
02.03.25;66668325;;;;66668898;66654268;66678578;66663630;66653847
03.03.25;66668469;;;;66671327;66650547;66678178;66663483;66656786
04.03.25;66668482;;;;66669397;66658134;66679102;66663430;66656163
05.03.25;66669270;;;;66667024;66656579;66677763;66663419;66655277
06.03.25;66669277;;;;66670683;66657113;66690358;66663257;66656752
07.03.25;66668079;;;;66669040;66650638;66696747;66661711;66656194
08.03.25;66669271;;;;66668961;66650506;66677731;66662964;66655267
09.03.25;66669112;;;;66670024;66657962;66695328;66660986;66653805
10.03.25;66668289;;;;66669526;66656577;66692580;66661284;66656675
11.03.25;6668264;;;;66669809;66657083;66695320;66660976;66656140
12.03.25;66668233;;;;66670339;66653554;66687774;66661000;66655266
13.03.25;66667162;;;;66669993;66650477;66675232;66660829;66653760
14.03.25;66667549;;;;66657522;66657923;66701478;66671146;66654265
15.03.25;66667213;;;;66657697;66656559;66692510;66670986;66655603
16.03.25;66669924;;;;66670352;66663384;66686020;66671202;66656838
17.03.25;66668161;;;;66669777;66650611;66697661;66671007;66656840
18.03.25;66667273;;;;66658840;66650465;66694615;66670868;66656219
19.03.25;66667274;;;;66669055;66657910;66694575;66670846;66655602
20.03.25;66668133;;;;66670710;66656576;66697228;66670803;66653935
21.03.25;66667277;;;;66671181;66656852;66678196;66670544;66653901
22.03.25;66667200;;;;66669646;66658164;66698352;66670524;66656208
23.03.25;66667517;;;;66670652;66650755;66698349;66670425;66656822
24.03.25;66667181;;;;66667126;66657944;66693019;66670371;66656824
25.03.25;66666542;;;;66669350;66658032;66697226;66671367;66656179
26.03.25;66667212;;;;66669754;66642355;66678278;66671305;66655308
27.03.25;66669931;;;;66669717;66650742;66693008;66671285;66653868
28.03.25;66668115;;;;66669582;66658153;66697124;66671260;66654571
29.02.25;66667276;;;;66669567;66649651;66678179;66671262;6656322
30.03.25;66667221;;;;66669536;66658172;66696008;66671229;66656993
31.03.25;66667262;;;;66674861;66656847;66676881;66671774;66656941
01.04.25;66667279;66673045;66672853;66673831;66675231;66658226;66695990;66672435;66656277
02.04.25;66667198;66672968;66672837;66673847;66675210;66657985;66690402;66672449;66655629
03.04.25;66666512;66683752;66671990;66673856;66675081;66659169;66703491;66672193;66654431
04.04.25;66667190;66671674;66672823;66657386;66675083;66652116;66703279;66672166;66654384
05.04.25;66666439;66671657;66672803;66673565;66675081;66658208;66699641;66672383;66655606
06.04.25;66666470;66671713;66671721;66673540;66675016;66657719;66703461;66672368;66656280
07.04.25;66666525;66672204;66670784;6673637;66674933;66652098;66702811;66672079;66656881
08.04.25;66665903;66671709;66673800;66672364;66674888;66657950;66701441;66672064;66656251
09.04.25;66667264;66671706;66673511;66672066;66676289;66654383;66699154;66672396;66654338
10.04.25;66667219;66672940;66673590;66652992;66676350;66652076;66701525;66671689;66657382
11.04.25;66667220;66673221;66673423;66672050;66675940;66659468;66702112;66671672;66656570
12.04.25;66667266;66673169;66673166;66672022;66676010;66659354;66699152;66674715;66655843
13.04.25;66669991;66673171;66673153;66676437;66675905;66659307;66701518;66673652;66655167
14.04.25;66666495;66673566;66673055;66676403;66679010;66659402;66701514;66674556;66655116
15.04.25;66665848;66683830;66673166;66676120;66675766;66659235;66701351;66672836;66655905
16.04.25;66665827;66671655;66673153;66676314;66675964;66659469;66701350;66672666;66656545
17.04.25;66672154;66671654;66696285;66676497;66675749;66654500;66694580;66672661;66657380
18.04.25;66672164;66673867;66695537;66676313;66683031;66670645;66717544;66672644;66657369
19.04.25;66672400;66675575;66694073;66676125;66675894;66659259;66716879;66672584;66656503
20.04.25;66673246;66675613;66695527;66676496;66675730;66659206;66717651;66672544;66655019
21.04.25;66672399;66675604;66694296;66676509;66675625;66659977;66718350;66672517;66657404
22.04.25;66672379;66673595;66698110;66676754;66675611;66659968;66717495;66672557;66656619
23.04.25;66672152;66676090;66692812;66676978;66675560;66659963;66716834;66672485;66656080
24.04.25;66672122;66676621;66693269;66676311;66677357;66660059;66717641;66675697;66655295
25.04.25;66684690;66676459;66692754;66680443;66677200;66659895;66717626;66675216;66655226
26.04.25;66680959;66682601;66694875;66676309;66676266;66659587;66717463;66675020;66657397
27.04.25;66673244;66676443;66692942;66687820;66677558;66659570;66716778;66673627;66656599
28.04.25;66672381;66675552;66694214;66686211;66681808;66659562;66703312;66674724;66655968
29.02.25;66672119;66676582;66694709;66687611;66677191;66659935;66699863;66675457;66657416
30.04.25;66681028;66675954;66697979;66686805;66676927;66659378;66701461;66675216;66656734
01.04.25;66684773;66676752,66675954;66698021;66700317;66685676;66661148;66713509;66698413;66666971
02.04.25;66684448;66675972,66677219;66701615;66700354;66682623;66665688;66713608;66697734;66665214
03.04.25;66683749;66677155,66676769;66700397;66700463;66685056;66665558;66717664;66697651;66667731
04.04.25;66681974;66676740,66677232;66698906;66703830;66684916;66662819;66699919;66698467;66666924
05.04.25;66683696;66676787,66676568;66702950;66701289;66678985;66666593;66694589;66699243;66667152
06.04.25;66684459;66678095,66676696;66698056;66703684;66678676;66665864;66713676;66698985;66665242
07.04.25;66684263;66702175,66702349;66701665;66703698;66682167;66662798;66717679;66699556;66667159
08.04.25;66683625;66702181,66706296;66702256;66703867;66680709;66665590;66713646;66699056;66667169
09.04.25;66684296;66702181,66702420;66700501;66703943;66683050;66661164;66713551;66699293;66667395
10.04.25;66685670;66702389,66703313;66700519;66703978;66683081;66668750;66715258;66701554;66665573
11.04.25;66684918;66704376,66705897;66701756;66704065;66684987;66665777;66715319;66699351;66661222
12.04.25;66683745;66705799,66705423;66706622;66703739;66680727;66665604;66715287;66701560;66665204
13.04.25;66682582;66703549,66703583;66700764;66698200;66679125;66665834;66687756;66699228;66667446
14.04.25;66684170;66705370,66705820;66701935;66698252;66677615;66661244;66676258;66696520;66662214
15.04.25;66685194;66705901,66705693;66702371;66698680;66679031;66665626;66697123;66696625;66662622
16.04.25;66684387;66703592,66699979;66697116;66698502;66679104;66665792;66704269;66696798;66664994
17.04.25;66682646;66698944,66700377;66700078;66698507;66676927;66664928;66678105;66696614;66665047
18.04.25;66682658;66701737,66699910;66697251;66698838;66677651;66668679;66689772;66696634;66665205
19.04.25;66682944;66701686,66701822;66700122;66698738;66681016;66667697;66690428;66696636;66666677
20.04.25;66683646;66701852,66701938;66697128;66698937;66680958;66665182;66676886;66696908;66667076
21.04.25;66681964;66701762,66702154;66698881;66699356;66681068;66665026;66700879;66696916;66665700
22.04.25;66682958;66702012,66701957;66698569;66699768;66681104;66661105;66703454;66697041;66665818
23.04.25;66684749;66697062,66697385;66698610;66699736;66677728;66661122;66701485;66697758;66665145
24.04.25;66684063;66697063,66695757;66698950;66699517;66677708;66665644;66696859;66697049;66666670
25.04.25;66683395;66699472,66697534;66697836;66699420;66702721;66665197;66693043;66697712;66667675
26.04.25;66681963;66697447,66697762;66697879;66697913;66704522;66668736;66695973;66694095;66665180
27.04.25;66681966;66697683,66698694;66700176;66697885;66705918;66668708;66678313;66696074;66659392
28.04.25;66682179;66700238,66698772;66697218;66698095;66694340;66665880;66695950;66696114;66661764
29.04.25;66682581;66698293,66698471;66698840;66697949;66705918;66665802;66678259;66696115;66664632
30.04.25;66682199;66697342,66693161;66697306;66693363;66706802;66665479;66692548;66695695;66664979
01.05.25;66681049;66686884;66697369;66687234;66688571;66660446;66692568;66675258;66661607
02.05.25;66681105;66686931;66717280;66688696;66692345;66661177;66671635;66675847;66659509
03.05.25;66681166;66687595;66694724;66688375;66705747;66664725;66673761;66676277;66659371
04.05.25;66681963;66689428;66697163;66689482;66692044;66661207;66671572;66675453;66661801
05.05.25;66681966;66690241;66698550;66688707;66705769;66661274;66671583;66688641;66661208
06.05.25;66682179;66692490;66698800;66687639;66704204;66661280;66673814;66688259;66658440
07.05.25;66683395;66696995;66697819;66687682;66702653;66661213;66671642;66688684;66657586
08.05.25;66682199;66697271;66701636;66688141;66689597;66664763;66675408;66688666;66661171
09.05.25;66681790;66695405;66717297;66689691;66700255;66661199;66676281;66689808;66661217
10.05.25;66703127;66693826;66715110;66688512;66692492;66660458;66674486;66689843;66659450
11.05.25;66705675;66697342;66715143;66688540;66705907;66660914;66673912;66692081;66659463
12.05.25;66705941;66693161;66717366;66689577;66700298;66661281;66671617;66689870;66661203
13.05.25;66704977;66704370;66716582;66689541;66729331;66664809;66673731;66692119;66658980
14.05.25;66705278;66699820;66702280;66687746;66702696;66661218;66674827;66692083;66660168
15.05.25;66697340;66701888;66715807;66689668;66689627;66664694;66677176;66692133;66657990
16.05.25;66700040;66704068;66715819;66694853;66700230;66668625;66676316;66692095;66658236
17.05.25;66703772;66704341;66715240;66688671;66704049;66661224;66678597;66692952;66657480
18.05.25;66705410;66702162;66716604;66694896;66690446;66665051;66678073;66694154;66657503
19.05.25;66700105;66705406;66719900;66692611;66729671;66661616;66674899;66694597;66660292
20.05.25;66697376;66702511;66715790;66687942;66691976;66661142;66678266;66695368;66658183
21.05.25;66705991;66702040;66688979;66698708;66704082;66660432;66717544;66693793;66657435
22.05.25;66706000;66705874;66696315;66703765;66700252;66660431;66716879;66695408;66657454
23.05.25;66703819;66705898;66692883;66699674;66688570;66660759;66725544;66695451;66657531
24.05.25;66702965;66705768;66694783;66698858;66687879;66660527;66726809;66686647;66657558
25.05.25;66698705;66705443;66689462;66699397;66703970;66670660;66727372;66686666;66661020
26.05.25;66704794;66729624;66694019;66701280;66701240;66661174;66724306;66687858;66675364
27.05.25;66704845;66704347;66695555;66700418;66691897;66660518;66727412;66686703;66670514
28.05.25;66704873;66700215;66693292;66703908;66691904;66664079;66726814;66687635;66673250
29.05.25;66696331;66697564;66715882;66703910;66701244;66660700;66726425;66687881;66678236
30.05.25;66698733;66698852;66693997;66700203;66690421;66660440;66727041;66688034;66677714
31.05.25;66703024;66702289;66672038;66688834;66687899;66660423;66727435;66687913;66672105
01.06.25;66703165;66685522;66677772;66694975;66687730;66659587;66725258;66698175;66675432
02.06.25;66698541;66677182;66676404;66694762;66706971;66659570;66725750;66696471;66675447
03.06.25;66695689;66676764;66677229;66689779;66716370;66659562;66726492;66696587;66678115
04.06.25;66703864;66697034;66677532;66688569;66700734;66659935;66721730;66699408;66673743
05.06.25;66704384;66675975;66676106;66698169;66690462;66659895;66725272;66696939;66675441
06.06.25;66696083;66688350;66677805;66698020;66690353;66660092;66726050;66696960;66678139
07.06.25;66705632;66687009;66677354;66698628;66703343;66660122;66726550;66725533;66671340
08.06.25;66702914;66692531;66677958;66698984;66687828;66660151;66721754;66697056;66674040
09.06.25;66702575;66697773;66685680;66687724;66687800;66660401;66725281;66698479;66669384
10.06.25;66698029;66686722;66677196;66687803;66690106;66661159;66726790;66726979;66675339
11.06.25;66699705;66695433;66677825;66687264;66687166;66660322;66727033;66699259;66673544
12.06.25;66703266;66692848;66677672;66687910;66690256;66660739;66721775;66699172;66674113
13.06.25;66703275;66697483;66687844;66688410;66705445;66660302;66725302;66686637;66677729
14.06.25;66703207;66699989;66694261;66688801;66690266;66659993;66726803;66687473;66674046
16.06.25;66695384;66671373;66677478;66689459;66692274;66681566;66727299;66686340;66677738
16.06.25;66700225;66676557;66676338;66689605;66686882;66681772;66721795;66685832;66674138
17.06.25;66695351;66676472;66674506;66676750;66686928;66681633;66727001;66695312;66674074
18.06.25;66694578;66673782;66674567;66676495;66687599;66682057;66725714;66692063;66678109
19.06.25;66697959;66676749;66677295;66676310;66697986;66681614;66720849;66692074;66671446
20.06.25;66699588;66673904;66674176;66676372;66690327;66681590;66720718;66696167;66677694
21.06.25;66698535;66677197;66677772;66676654;66701227;66681642;66724868;66693752;66672445
22.06.25;66705771;66676790;66676404;66677153;66690315;66682200;66725750;66693170;66671936
23.06.25;66700798;66676503;66677229;66682833;66687662;66683485;66724333;66697748;66677707
24.06.25;66696106;66690302;66677532;66686885;66687340;66682057;66720802;66695438;66672116
26.06.25;66694578;66675927;66676106;66676991;66692809;66681837;66725245;66695852;66674096
26.06.25;66697959;66676062;66674354;66675967;66720777;66681235;66725768;66686687;66677720
27.06.25;66699588;66671716;66673560;66676458;66692359;66681192;66725219;66686714;66669910
28.06.25;66698535;66672884;66673755;66676429;66714541;66681183;66721713;66692446;66673516
29.06.25;66705771;66676706;66674467;66676511;66702671;66681172;66717044;66688055;66670495
30.06.25;66695351;66673048;66673071;66676686;66688609;66681228;66711483;66689374;66673575
01.07.25;66685667;66670412;66710566;66671495;66688342;66680956;66711435;66672571;66669150
02.07.25;66694978;66671447;66716568;66672058;66702639;66680890;66701478;66672475;66673231
03.07.25;66684196;66670322;66711285;66673493;66704482;66680899;66716863;66674470;66672089
04.07.25;66693906;66672875;66708432;66671511;66692328;66680920;66716889;66672598;66669358
05.07.25;66695116;66671527;66711077;66676424;66716366;66681024;66716919;66672656;66673242
06.07.25;66695024;66685472;66711081;66671909;66692028;66680987;66722623;66675527;66672429
07.07.25;66694379;66671417;66729473;66667552;66692809;66681059;66716828;66674719;66673256
08.07.25;66694523;66671727;66717281;66675968;66720777;66681087;66711450;66674723;66672439
09.07.25;66695266;66671668;66717514;66676208;66692359;66681112;66717027;66675878;66667458
10.07.25;66695055;66676062;66710579;66673693;66714541;66681235;66717008;66675139;66670641
11.07.25;66682558;66671716;66710593;66676512;66702671;66681192;66717170;66675345;66670245
12.07.25;66705955;66672884;66717556;66673789;66688609;66681183;66717060;66687791;66670294
13.07.25;66695199;66676706;66717311;66724484;66690368;66681172;66716995;66675437;66668463
14.07.25;66697732;66673048;66708444;66724764;66700783;66681228;66714767;66675436;66671880
16.07.25;66699508;66714318;66712665;66724854;66689681;66676465;66701383;66688053;66672117
16.07.25;66702417;66714571;66717624;66724559;66692011;66680514;66703297;66686337;66670729
17.07.25;66705660;66711371;66707990;66724107;66686831;66678350;66714673;66686586;66669145
18.07.25;66698782;66714981;66715085;66724862;66687320;66674428;66714778;66670854;66672085
19.07.25;66696376;66719992;66711255;66720576;66687754;66680524;66714723;66670409;66672133
20.07.25;66729628;66719910;66711040;66720633;66698839;66680615;66701449;66670497;66667211
21.07.25;66705309;66718146;66711060;66721278;66690333;66680537;66699165;66671179;66670485
22.07.25;66729732;66711580;66707846;66724149;66705716;66680662;66740585;66670887;66669744
23.07.25;66729746;66714988;66711265;66724741;66691851;66680624;66740963;66670982;66667425
24.07.25;66729512;66714348;66715093;66724211;66691942;66676469;66740804;66671765;66667685
26.07.25;66700141;66714501;66707996;66769951;66705905;66678319;66740854;66671203;66670567
26.07.25;66706013;66717878;66707348;66720149;66690376;66671431;66744451;66671118;66667179
27.07.25;66703800;66720099;66711013;66724750;66704026;66671375;66741001;66671784;66669672
28.07.25;66696289;66705848;66707830;66724405;66688299;66680437;66742954;66671325;66667207
29.07.25;66698688;66705942;66710701;66722215;66687843;66680457;66744485;66671648;66670393
30.07.25;66705645;66722031;66714210;66720204;66678730;66671449;66743763;66672197;66669604
31.07.25;66700172;66718006;66707985;66720535;66680654;66676467;66740870;66672090;66667419
01.08.25;66686993;66714034;66706708;66720149;66676934;66680488;66740316;66672099;66667179
02.08.25;66700770;66721677;66708065;66720244;66678695;66674406;66740399;66717955;66667207
03.08.25;66697418;66709138;66708931;66720266;66680696;66705909;66740940;66717970;66670393
04.08.25;66695277;66712246;66707717;66724630;66679058;66705413;66740991;66718411;66669604
05.08.25;66694440;66712292;66708809;66724750;66684898;66705418;66740994;66718446;66667419
06.08.25;66698528;66722114;66708820;66724405;66680989;66705899;66740958;66718009;66688480
07.08.25;66700491;66714961;66707728;66722215;66683122;66704982;66740906;66717984;66688529
08.08.25;66699652;66710830;66708993;66720204;66701228;66705751;66740305;66718526;66687714
09.08.25;66695360;66714535;66714110;66720535;66684025;66705312;66740367;66720061;66688372
10.08.25;66698061;66714275;66706769;66719811;66682154;66705752;66740446;66719732;66688409
11.08.25;66702593;66721598;66714120;66717479;66680654;66705288;66740815;66719725;66687695
12.08.25;66694566;66708650;66709852;66717812;66678730;66705701;66740989;66719706;66688323
13.08.25;66684094;66708702;66707815;66717857;66675661;66705798;66740833;66717221;66684141
14.08.25;66685178;66709034;66709022;66724238;66676336;66705733;66740382;66717214;66684273
16.08.25;66684828;66708909;66709835;66724257;66675791;66705401;66740310;66717199;66686422
16.08.25;66684828;66710766;66707824;66719942;66675779;66705264;66740080;66717732;66686442
17.08.25;66683731;66712160;66710637;66719978;66677606;66705281;66740322;66717703;66686243
18.08.25;66681970;66709080;66714133;66720056;66675917;66704851;66740123;66717239;66684950
19.08.25;66694420;66712068;66707338;66719833;66677228;66704315;66740132;66717833;66684086
20.08.25;66699545;66713989;66706637;66711942;66675861;66705346;66740458;66717791;66685048
21.08.25;66695128;66707642;66708005;66716182;66677356;66705682;66740425;66723821;66686173
22.08.25;66684857;66707678;66707018;66716856;66677480;66705447;66740342;66716471;66681683
23.08.25;66693862;66707739;66707358;66716999;66677460;66705756;66740292;66716419;66680641
24.08.25;66684326;66707778;66708447;66722188;66676355;66705363;66743635;66716387;66680679
26.08.25;66681807;66708666;66707706;66724232;66675655;66704946;66739886;66717166;66686413
26.08.25;66681079;66708684;66708271;66717452;66675949;66704521;66740093;66717121;66686185
27.08.25;66680917;66708634;66708022;66717361;66674904;66701953;66740048;66716727;66681703
28.08.25;66682166;66708652;66706678;66716687;66675595;66704199;66740067;66715415;66682083
29.08.25;66681223;66707684;66741066;66711043;66674825;66706982;66740106;66715453;66684403
30.08.25;66681965;66708638;66737952;66711933;66727022;66704945;66740118;66713815;66684905
31.08.25;66672118;66708638;66673486;66711922;66716334;66705422;66739141;66716044;66680541
01.09.25;66683662;66707678;66745443;66710923;66715989;66704303;66743635;66710743;66678584
02.09.25;66682637;66707739;66741730;66710805;66714514;66704333;66739886;66712471;66672123
03.09.25;66684728;66707778;66743480;66710783;66713190;66701837;66740093;66710890;66684342
04.09.25;66684432;66708666;66741759;66711616;66713195;66696352;66740048;66713156;66684444
05.09.25;66682187;66708684;66741725;66699557;66716068;66703229;66740067;66712638;66668470
06.09.25;66716767;66708634;66741745;66710964;66715989;66703334;66740106;66713044;66680454
07.09.25;66725409;66708652;66737600;66710996;66711312;66696906;66740118;66713113;66679032
08.09.25;66725935;66707684;66738203;66711019;66726109;66701915;66739141;66713081;66680503
09.09.25;66725888;66707642;66738209;66719889;66726014;66703340;66738807;66713744;66684235
10.09.25;66755395;66706345;66737615;66716787;66716053;66697008;66739162;66713927;66684711
11.09.25;66727552;66706376;66745429;66716728;66726412;66704450;66739426;66713881;66684757
12.09.25;66673997;66706897;66743575;66745366;66727154;66704106;66739039;66710470;66680714
13.09.25;66672380;66706770;66739474;66745510;66726618;66706887;66739969;66710497;66679037
14.09.25;66672398;66707015;66741351;66733398;66716342;66702075;66743679;66710518;66682099
15.09.25;66672165;66707079;66741074;66737422;66726130;66696365;66739460;66710705;66678576
16.09.25;66672149;66706848;66737525;66736199;66714495;66694286;66739111;66710836;66678227
17.09.25;66720000;66707123;66733869;66738734;66713164;66679473;66737075;66710770;66678595
18.09.25;66716562;66706737;66733892;66733476;66710957;66693312;66738453;66709880;66680561
19.09.25;66721975;66707131;66737531;66745560;66714301;66693373;66738481;66709857;66678664
20.09.25;66718781;66707592;66741093;66734439;66714532;66693165;66738705;66709809;66681725
21.09.25;66727185;66707619;66741378;66734446;66716002;66693637;66738774;66710438;66681003
22.09.25;66720820;66707529;66741753;66745594;66726943;66693624;66738754;66710010;66678713
23.09.25;66718846;66707572;66733603;66733496;66726967;66693504;66738747;66709961;66678151
24.09.25;66725409;66707154;66741255;66737003;66725966;66693671;66738730;66710454;66678102
26.09.25;66716591;66735200;66738550;66734394;66714327;66693726;66755876;66710360;66678680
26.09.25;66720059;66733525;66737143;66739747;66710972;66694217;66754433;66709379;66678560
27.09.25;66710971;66737067;66733684;66733299;66710928;66705915;66749773;66699376;66679008
28.09.25;66711946;66739296;66733861;66737307;66711519;66694406;66748461;66699211;66678167
29.09.25;66714641;66739308;66737170;66736185;66711575;66694378;66748470;66699376;66673724
30.09.25;66713846;66739411;66740319;66737408;66713208;66694078;66749790;66709379;66708453
01.10.25;66710866;66739393;66739458;66733318;66716019;66707651;66754458;66709782;66710239
02.10.25;66710885;66737097;66741300;66739770;66719554;66704924;66754536;66709475;66707582
03.10.25;66711973;66735938;66727350;66734403;66720734;66697048;66754479;66709402;66704136
04.10.25;66711148;66735928;66733603;66734424;66716332;66705297;66748726;66699211;66710395
05.10.25;66711157;66731431;66741255;66745507;66726162;66703369;66786060;66699376;66708559
06.10.25;66711926;66731454;66738550;66733335;66714518;66704816;66753455;66709379;66689469
07.10.25;66714300;66735336;66737143;66737417;66714299;66705301;66749722;66709782;66707691
08.10.25;66713878;66737567;66733684;66735809;66710925;66704981;66749114;66709475;66708268
09.10.25;66711163;66737742;66733861;66737007;66707027;66705687;66748444;66709402;66696002
10.10.25;66711034;66738422;66737170;66731521;66707362;66705766;66749741;66738068;66699590
11.10.25;66710837;66739267;66740319;66738739;66707535;66705908;66753422;66737010;66699721
12.10.25;66707437;66735595;66741300;66733556;66711416;66705748;66755469;66736837;66699794
13.10.25;66707912;66731554;66739458;66734380;66716795;66729759;66755473;66738337;66701273
14.10.25;66708146;66734878;66733156;66739718;66716840;66705322;66753439;66737021;66701844
16.10.25;66708771;66730858;66737134;66733270;66711488;66704975;66774797;66736861;66701876
16.10.25;66708426;66730858;66733168;66737094;66700300;66693410;66748451;66736914;66703880
17.10.25;66709588;66731133;66738514;66735818;66711395;66694158;66755450;66737034;66703105
18.10.25;66707325;66733964;66728787;66735793;66711361;66705397;66753367;66744057;66694407
19.10.25;66708795;66734263;66734933;66731478;66689646;66703353;66749179;66744381;66703260
20.10.25;66707472;66734292;66731676;66729200;66711486;66693428;66748765;66737047;66697448
21.10.25;66707855;66735056;66730176;66731504;66707575;66694046;66748343;66736931;66695087
22.10.25;66707670;66734963;66730190;66733467;66707382;66704214;66749184;66737104;66695101
23.10.25;66707636;66734860;66733144;66733532;66707344;66702025;66753380;66736711;66694955
24.10.25;66707591;66731174;66737123;66739189;66719828;66703305;66755458;66735949;66689705
26.10.25;66707331;66731216;66731704;66734338;66690228;66704952;66755463;66737116;66687772
26.10.25;66741652;66730686;66738471;66737084;66748493;66704147;66753389;66737354;66685649
27.10.25;66746035;66730763;66728872;66735795;66744079;66696378;66751946;66736280;66693611
28.10.25;66744338;66729661;66734933;66728927;66749480;66704311;66748397;66737697;66693720
29.10.25;66744500;66729850;66731676;66728964;66752552;66702094;66754620;66736965;66694377
30.10.25;66744252;66731244;66730176;66729137;66748721;66681131;66751758;66736292;66693749
31.10.25;66745786;66733564;66730190;66729241;66752690;66681000;66749716;66738066;66689364
01.11.25;66739922;66734142;66733144;66729255;66753036;66680646;66748295;66736979;66694433
02.11.25;66743662;66733157;66737123;66733397;66748727;66681345;66748314;66736302;66717416
03.11.25;66744630;66730849;66731704;66745372;66749629;66680691;66749144;66738067;66703972
04.11.25;66740683;66730841;66738471;66729198;66747222;66681881;66751829;66737004;66716972
05.11.25;66744495;66728492;66728872;66731472;66747180;66681098;66754647;66736714;66717454
06.11.25;66745622;66729752;66657072;66734481;66748920;66681162;66755442;66733060;66704015
07.11.25;66744294;66728996;66729265;66771123;66748453;66681669;66753354;66733373;66699648
08.11.25;66745919;66729041;66729783;66721299;66740767;66682227;66749151;66735578;66716949
09.11.25;66743700;66729872;66729480;66770827;66739812;66683532;66748339;66735709;66716963
10.11.25;66741539;66729913;66729571;66768990;66751139;66682503;66755953;66734837;66703060
11.11.25;66742994;66729087;66730030;66756638;66745057;66681596;66748287;66733501;66716901
12.11.25;66739845;66729134;66732664;66756608;66739846;66694358;66748149;66733984;66703914
13.11.25;66735066;66729784;66733663;66771132;66752590;66681608;66747782;66735531;66708120
14.11.25;66740785;66728519;66728770;66771123;66747208;66685582;66748173;66753810;66717056
16.11.25;66741939;66727685;66771239;66721299;66752220;66671954;66748317;66737099;66712986
16.11.25;66740041;66727707;66771786;66770827;66747161;66670777;66754562;66737655;66695161
17.11.25;66736396;66727719;66771800;66768990;66740791;66676489;66754598;66734741;66713166
18.11.25;66736438;66727929;66754254;66756638;66748475;66674452;66751808;66734018;66699476
19.11.25;66740675;66727957;66769359;66756608;66738949;66670777;66749135;66732698;66701263
20.11.25;66743345;66733246;66771793;66767882;66735450;66675285;66748264;66732678;66694952
21.11.25;66739974;66728428;66771618;66768812;66745109;66682560;66786050;66734061;66710428
22.11.25;66734243;66728190;66771194;66767786;66735323;66671384;66786003;66732924;66712800
23.11.25;66734419;66728163;66771777;66755952;66735188;66679485;66785407;66732916;66689745
24.11.25;66734469;66728075;66771527;66756529;66735364;66676466;66784607;66735490;66712142
26.11.25;66737829;66755898;66753619;66756538;66745025;66680684;66755468;66733005;66712205
26.11.25;66735889;66756682;66769339;66756622;66739932;66680544;66785471;66733030;66695166
27.11.25;66736355;66770007;66769344;66767994;66739029;66671466;66749338;66735493;66694451
28.11.25;66736368;66770800;66753680;66768901;66740745;66680974;66748227;66733334;66694503
29.11.25;66739916;66771062;66771792;66755952;66745646;66680474;66748109;66733041;66695278
30.11.25;66735657;66757156;66771783;66767726;66735051;66724286;66747713;66733444;66712249
01.12.25;66735175;66770920;66771212;66768394;66735147;66723447;66786018;66732658;66695138
02.12.25;66775357;66755397;66757559;66756084;66732425;66725030;66782534;66732649;66710248
03.12.25;66773134;66784666;66750774;66755339;66731907;66724886;66785364;66728543;66694469
04.12.25;66757639;66768967;66771232;66764381;66732051;66723996;66787201;66728574;66695022
05.12.25;66727629;66770401;66781202;66759836;66731449;66723039;66784142;66733078;66688884
06.12.25;66728663;66770960;66771155;66765918;66730958;66722582;66785382;66733080;66703378
07.12.25;66732568;66770985;66771170;66766185;66731566;66722586;66785972;66728948;66707630
08.12.25;66732582;66770438;66771760;66760369;66731552;66723433;66786041;66732641;66689132
09.12.25;66733721;66768995;66771329;66765235;66733380;66724042;66786050;66753272;66702604
10.12.25;66735875;66756674;66753605;66755354;66730625;66724101;66786003;66753157;66748731
11.12.25;66733677;66755413;66757566;66756088;66734917;66725137;66785407;66757868;66745068
12.12.25;66728118;66751720;66769335;66771186;66734870;66725181;66784607;66757886;66748915
13.12.25;66774753;66756636;66753612;66755938;66732422;66724346;66784077;66753164;66745108
14.12.25;66771325;66745792;66771482;66767698;66731861;66724279;66784026;66753325;66748822
16.12.25;66774744;66770221;66771769;66760780;66731399;66723443;66782517;66753392;66748908
16.12.25;66774863;66745944;66771190;66766750;66732405;66722587;66786237;66757108;66750850
17.12.25;66762862;66746932;66754261;66762605;66771937;66722237;66785785;66757913;66750897
18.12.25;66773590;66770390;66746762;66748924;66773091;66723028;66782526;66757125;66751048
19.12.25;66774403;66768950;66771221;66756032;66773611;66722398;66784781;66753418;66739739
20.12.25;66770120;66756653;66770772;66756074;66774382;66722438;66784133;66757761;66738576
21.12.25;66770300;66751740;66769943;66749332;66773122;66724909;66784009;66749709;66748266
22.12.25;66773892;66757909;66769947;66763055;66773657;66724919;66784011;66753124;66739793
23.12.25;66774334;66770136;66770812;66759479;66775072;66723247;66782502;66757818;66748331
24.12.25;66771003;66757502;66771225;66754258;66771959;66723460;66785337;66750930;66748216
26.12.25;66774700;66757082;66749751;66761763;66773201;66723038;66785563;66753134;66745046
26.12.25;66773636;66751369;66754282;66747055;66772850;66722273;66782511;66757828;66745058
27.12.25;66763497;66751373;66757550;66756019;66772123;66724901;66784017;66750959;66738454
28.12.25;66773738;66755379;66750103;66756023;66772515;66724872;66784028;66753141;66745024
29.12.25;66769503;66757506;66771231;66747078;66773879;66722348;66782463;66757841;66739311
30.12.25;66775442;66770160;66770950;66762053;66773340;66722976;66783999;66751921;66738496
31.12.25;66773518;66757978;66769959;66758843;66772152;66722235;66783704;66753155;66738323";
        return $string;
    }

    function getLatestFromMagToRepublish($mag_id) {
        global $mysqli_con, $article_array;
        $today = date('Y-m-d');
        if(!isset($article_array[$today][$mag_id])) {
            return [];
        }
        $article = $article_array[$today][$mag_id];
        //print_r($article_array[$mag_id]);
        if ($article == "") {
            return [];
        }
        if ($article < 10000) {
            return [];
        }
        $sql = "SELECT *  FROM articles WHERE id IN (".$article.");";
        //$sql = "SELECT *  FROM articles WHERE status_id = 11 AND magazine_id = ".$mag_id." AND published_at < '2023-12-21 00:00:00' ORDER BY published_at ASC LIMIT 1;";
        $result = $mysqli_con->query($sql);
        $articles = [];
        while ($row = $result->fetch_assoc()) {
            $articles[] = $row;
        }
        return $articles;
    }

    function array_to_id() {
        $string = getTheString();
        $lines = explode("\n", $string);
        $first_line = array_shift($lines);
        $index = explode(";", $first_line);
        $mag_to_index = array();
        foreach($index as $key => $mag_id) {
            $mag_to_index[$mag_id] = $key;
        }
        $ret = [];
        foreach ($lines as $line) {
            $line = explode(";", $line);
            $date = "20" . substr($line[0], 6, 2) . "-" . substr($line[0], 3, 2) . "-" . substr($line[0], 0, 2);
            foreach($mag_to_index as $mag_id => $index) {
                $ret[$date][$mag_id] = $line[$index];
            }
        }
        return $ret;
    }

    function republishArticle($id) {
        global $bearer;
        $url = API_URL . "/articles/".$id."/copy-redirect";
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Authorization: Bearer ' . $bearer,
            'Content-Type: application/json'
        ));
        $response = curl_exec($ch);
        $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        return [$response, $httpcode];
    }

    function publishArticle($id) {
        global $bearer;
        $url = API_URL . "/articles/".$id."/publish";
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Authorization: Bearer ' . $bearer,
            'Content-Type: application/json'
        ));
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
        $response = curl_exec($ch);
        $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        return [$response, $httpcode];
    }

?>
