<?php
//print_r($_POST);
//$filter = ['id' => $_GET['econid']];
//print_r($user);
global $user;
if ($_POST != []) {
    $data = $_POST;
    $data['id'] = $_GET['id'];
    // echo json_encode($data,JSON_NUMERIC_CHECK);
    $partner = $auth->sendApiData("update/partner", $data);
}
if (isset($_GET['id'])) {
    $data = ['id' => $_GET['id']];
    $partner = $auth->getApiDataFilter("get/partner", $data);
    $partner = $partner[0];
}
if (($user->accesslevel > 1 && isset($partner->companySales) && $partner->companySales == $user->id) || $user->accesslevel < 2) {
    //$partners = $auth->getApiDataFilter("get/machine/full", $filter);
    $cities = $auth->getApiData("get/cities");
    $counties = $auth->getApiData("get/counties");
?>
    <form id="sendForm" class="row" method="POST">
        <div class="col-lg-6 col-sm-12">
            <div class="card">
                <div class="card-header">
                    <h4>Cég információk</h4>
                </div>
                <div class="card-body">
                    <div class="form-group row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Cégnév</h5>
                        </div>
                        <div class="col-lg-8 col-sm-6">
                            <?php echo (isset($partner->companyName)) ? $partner->companyName : ''; ?>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Telefonszám</h5>
                        </div>
                        <div class="col-lg-8 col-sm-6">
                            <?php echo (isset($partner->companyTel)) ? $partner->companyTel : ''; ?>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>E-mail</h5>
                        </div>
                        <div class="col-lg-8 col-sm-6">
                            <?php echo (isset($partner->companyEmail)) ? $partner->companyEmail : ''; ?> </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Fax</h5>
                        </div>
                        <div class="col-lg-8 col-sm-6">
                            <?php echo (isset($partner->companyFax)) ? $partner->companyFax : ''; ?>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Adószám</h5>
                        </div>
                        <div class="col-lg-8 col-sm-6">
                            <?php echo (isset($partner->companyVat)) ? $partner->companyVat : ''; ?>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>EU Adószám</h5>
                        </div>
                        <div class="col-lg-8 col-sm-6">
                            <?php echo (isset($partner->companyVatEU)) ? $partner->companyVatEU : ''; ?>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Fizetési határidő napokban</h5>
                        </div>
                        <div class="col-lg-8 col-sm-6">
                            <?php echo (isset($partner->companyPaymentDays)) ? $partner->companyPaymentDays : ''; ?>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Ársáv</h5>
                        </div>
                        <div class="col-lg-8 col-sm-6">
                            <?php
                            $priceranges = $auth->getApiData("get/priceranges");
                            //print_r($countries);
                            $selected = "Normál";
                            foreach ($priceranges as $pr) :
                                $selected = (isset($partner->companyPriceRange) && $partner->companyPriceRange == $pr->id && $selected == "Normál") ? $pr->name : $selected;
                            endforeach;
                            echo $selected;
                            ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-lg-6 col-sm-12">
            <div class="card">
                <div class="card-header">
                    <h4>Kapcsolt értékesítő</h4>
                </div>
                <div class="card-body">
                    <div class="form-group row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Értékesítő</h5>
                        </div>
                        <div class="col-lg-8 col-sm-6">
                            <?php
                            $sales = $auth->getApiData("get/user");
                            $selected = "";
                            foreach ($sales as $sale) :
                                $selected = (isset($partner->companySales) && $partner->companySales == $sale->id && $selected == '') ? $sale->lastName . " " . $sale->firstName : $selected;
                            endforeach;
                            echo $selected;
                            ?>
                        </div>
                    </div>
                </div>
            </div>
            <div class="card">
                <div class="card-header">
                    <h4>Kapcsolattartási adatok</h4>
                </div>
                <div class="card-body">
                    <div class="form-group row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Név</h5>
                        </div>
                        <div class="col-lg-8 col-sm-6">
                            <?php echo (isset($partner->contactName)) ? $partner->contactName : ''; ?>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Telefonszám</h5>
                        </div>
                        <div class="col-lg-8 col-sm-6">
                            <?php echo (isset($partner->contactTel)) ? $partner->contactTel : ''; ?>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>E-mail</h5>
                        </div>
                        <div class="col-lg-8 col-sm-6">
                            <?php echo (isset($partner->contactEmail)) ? $partner->contactEmail : ''; ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-lg-4 col-sm-12">
            <div class="card">
                <div class="card-header">
                    <h4>Székhely</h4>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Város</h5>
                        </div>
                        <div class="col-lg-8 col-sm-6 form-group">
                            <?php
                            $cities = $auth->getApiData("get/cities");
                            $counties = $auth->getApiData("get/counties");
                            $countries = $auth->getApiData("get/countries");
                            $address = ['zip' => 0, 'city' => '', 'address' => '', 'county' => '', 'country' => ''];
                            foreach ($cities as $city) :
                                $selected = (isset($partner->companyCity) && $partner->companyCity->{'$oid'} == $city->_id->{'$oid'}) ? "selected" : '';
                                if ($selected == "selected") {
                                    $address['zip'] = $city->zip;
                                    $address['city'] = $city->city;
                                }
                            endforeach;
                            foreach ($counties as $county) :
                                $selected = (isset($partner->companyCounty) && $partner->companyCounty == $county->id) ? "selected" : '';
                                if ($selected == "selected")
                                    $address['county'] = $county->name . ' megye';
                            endforeach;

                            foreach ($countries as $country) :
                                $selected = (isset($partner->companyCountry) && $partner->companyCountry == $country->id) ? "selected" : '';
                                if ($selected == 'selected')
                                    $address['country'] = $country->name;
                            endforeach;
                            $address['address'] = (isset($partner->companyAdressLocation2)) ? $partner->companyAdressLocation2 : '';
                            echo "{$address['country']}<br>{$address['county']}</br>{$address['zip']} {$address['city']}, {$address['address']}";
                            ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--SZÉKHELY VÉGE -->

        <!--TELEPHELY KEZDET -->
        <div class="col-lg-4 col-sm-12">
            <div class="card">
                <div class="card-header">
                    <h4>Telephely</h4>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Város</h5>
                        </div>
                        <div class="col-lg-8 col-sm-6 form-group">
                            <?php
                            foreach ($cities as $city) :
                                $selected = (isset($partner->companyLocationCity) && $partner->companyLocationCity->{'$oid'} == $city->_id->{'$oid'}) ? "selected" : '';
                                if ($selected == "selected") {
                                    $address['zip'] = $city->zip;
                                    $address['city'] = $city->city;
                                }
                            endforeach;
                            foreach ($counties as $county) :
                                $selected = (isset($partner->companyLocationCounty) && $partner->companyLocationCounty == $county->id) ? "selected" : '';
                                if ($selected == "selected")
                                    $address['county'] = $county->name . ' megye';
                            endforeach;

                            foreach ($countries as $country) :
                                $selected = (isset($partner->companyLocationCountry) && $partner->companyLocationCountry == $country->id) ? "selected" : '';
                                if ($selected == 'selected')
                                    $address['country'] = $country->name;
                            endforeach;
                            $address['address'] = (isset($partner->companyTLocation2)) ? $partner->companyTLocation2 : '';
                            echo "{$address['country']}<br>{$address['county']}</br>{$address['zip']} {$address['city']}, {$address['address']}";
                            ?>
                        </div>
                    </div>
                    <!--ITT VOLT AZ ORSZÁG -->
                </div>
            </div>
        </div>
        <!--TELEPHELY VÉGE -->

        <!--POSTÁZÁSI CÍM KEZDET -->
        <div class="col-lg-4 col-sm-12">
            <div class="card">
                <div class="card-header">
                    <h4>Postázási Cím</h4>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Város</h5>
                        </div>
                        <div class="col-lg-8 col-sm-6 form-group">
                            <?php
                            foreach ($cities as $city) :
                                $selected = (isset($partner->companyPostalCity) && $partner->companyPostalCity->{'$oid'} == $city->_id->{'$oid'}) ? "selected" : '';
                                if ($selected == "selected") {
                                    $address['zip'] = $city->zip;
                                    $address['city'] = $city->city;
                                }
                            endforeach;
                            foreach ($counties as $county) :
                                $selected = (isset($partner->companyPostalCounty) && $partner->companyPostalCounty == $county->id) ? "selected" : '';
                                if ($selected == "selected")
                                    $address['county'] = $county->name . ' megye';
                            endforeach;

                            foreach ($countries as $country) :
                                $selected = (isset($partner->companyPostalCountry) && $partner->companyPostalCountry == $country->id) ? "selected" : '';
                                if ($selected == 'selected')
                                    $address['country'] = $country->name;
                            endforeach;
                            $address['address'] = (isset($partner->companyPostalLocation2)) ? $partner->companyPostalLocation2 : '';
                            echo "{$address['country']}<br>{$address['county']}</br>{$address['zip']} {$address['city']}, {$address['address']}";
                            ?>
                        </div>


                    </div>
                </div>
            </div>
            <!--ITT VOLT AZ ORSZÁG -->
        </div>

        <!--SZÁMLÁZÁSI CÍM VÉGE -->

        <div class="col-lg-6 col-sm-12">
            <div class="card">
                <div class="card-header">
                    <h4>I. Növénytermesztési besorolás</h4>
                </div>
                <div class="card-body">
                    <div class="form-group row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Konvencionális növénytermesztő </h5>
                        </div>
                        <div class="col-lg-8 col-sm-6">
                            <?php echo (isset($partner->konvencionalis_novenytermeszto)) ? $partner->konvencionalis_novenytermeszto : ' - '; ?>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Ökológiai növénytermesztő</h5>
                        </div>
                        <div class="col-lg-8 col-sm-6">
                            <?php echo (isset($partner->okologiai_novenytermeszto)) ? $partner->okologiai_novenytermeszto : ' - '; ?>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Konvencionális és ökológiai növénytermesztő</h5>
                        </div>
                        <div class="col-lg-8 col-sm-6">

                            <?php echo (isset($partner->konvencionalis_es_okologiai_novenytermeszto)) ? $partner->konvencionalis_es_okologiai_novenytermeszto : ' - '; ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-lg-6 col-sm-12">
            <div class="card">
                <div class="card-header">
                    <h4>II. Növénytermesztési besorolás</h4>
                </div>
                <div class="card-body">
                    <div class="form-group row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Szántóföldi növénytermesztő </h5>
                        </div>
                        <div class="col-lg-8 col-sm-6">
                            <?php echo (isset($partner->szantofoldi_novenytermeszto)) ? $partner->szantofoldi_novenytermeszto : ' - '; ?>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Szabadföldi zöldségtermesztő</h5>
                        </div>
                        <div class="col-lg-8 col-sm-6">
                            <?php echo (isset($partner->szabadfoldi_zoldsegtermeszto)) ? $partner->szabadfoldi_zoldsegtermeszto : ' - '; ?>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Szőlőtermesztő </h5>
                        </div>
                        <div class="col-lg-8 col-sm-6">

                            <?php echo (isset($partner->szolotermeszto)) ? $partner->szolotermeszto : ' - '; ?>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Gyümölcstermesztő </h5>
                        </div>
                        <div class="col-lg-8 col-sm-6">

                            <?php echo (isset($partner->gyumolcstermeszto)) ? $partner->gyumolcstermeszto : ' - '; ?>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Fóliás vagy üvegházi kertészet</h5>
                        </div>
                        <div class="col-lg-8 col-sm-6">

                            <?php echo (isset($partner->folias_vagy_uveghazi_kerteszet)) ? $partner->folias_vagy_uveghazi_kerteszet : ' - '; ?>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Palántanevelés</h5>
                        </div>
                        <div class="col-lg-8 col-sm-6">

                            <?php echo (isset($partner->palantaneveles)) ? $partner->palantaneveles : ' - '; ?>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Dísznövény </h5>
                        </div>
                        <div class="col-lg-8 col-sm-6">
                            <?php echo (isset($partner->disznoveny)) ? $partner->disznoveny : ' - '; ?>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Egyéb</h5>
                        </div>
                        <div class="col-lg-8 col-sm-6">
                            <?php echo (isset($partner->egyeb)) ? $partner->egyeb : ' - '; ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
<?php
}
addJS("partner.js");
?>