<?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");
?>
    <div class="row card">
        <div class="col-12 text-center">
            <button type="button" class="btn btn-block bg-gradient-success btn-lg savedata">Mentés</button>
        </div>
    </div>
    <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">
                            <input value="<?php echo (isset($partner->companyName)) ? $partner->companyName : ''; ?>" class="form-control" name="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">
                            <input value="<?php echo (isset($partner->companyTel)) ? $partner->companyTel : ''; ?>" class="form-control" name="companyTel" type="text" />
                        </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">
                            <input value="<?php echo (isset($partner->companyEmail)) ? $partner->companyEmail : ''; ?>" class="form-control" name="companyEmail" type="email" />
                        </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">
                            <input value="<?php echo (isset($partner->companyFax)) ? $partner->companyFax : ''; ?>" class="form-control" name="companyFax" type="email" />
                        </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">
                            <input value="<?php echo (isset($partner->companyVat)) ? $partner->companyVat : ''; ?>" class="form-control" name="companyVat" type="text" />
                        </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">
                            <input value="<?php echo (isset($partner->companyVatEU)) ? $partner->companyVatEU : ''; ?>" class="form-control" name="companyVatEU" type="text" />
                        </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">
                            <input value="<?php echo (isset($partner->companyPaymentDays)) ? $partner->companyPaymentDays : ''; ?>" class="form-control" name="companyPaymentDays" type="number" />
                        </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);
                            ?>
                            <select name="companyPriceRange" class="select2 companyPriceRange form-control">
                                <option value="null">Alapértelmezett</option>
                                <?php
                                foreach ($priceranges as $pr) :
                                    $selected = (isset($partner->companyPriceRange) && $partner->companyPriceRange == $pr->id) ? "selected" : '';
                                ?>
                                    <option value="<?php echo $pr->id; ?>" <?php echo $selected ?>><?php echo $pr->name; ?></option>
                                <?php
                                endforeach;
                                ?>
                            </select>
                        </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">
                            <select name="companySales" class="select2 companySale form-control">
                                <?php
                                $sales = $auth->getApiData("get/user");
                                foreach ($sales as $sale) :
                                    $selected = (isset($partner->companySales) && $partner->companySales == $sale->id) ? "selected" : '';
                                ?>
                                    <option value="<?php echo $sale->id; ?>" <?php echo $selected ?>><?php echo $sale->lastName . " " . $sale->firstName; ?></option>
                                <?php
                                endforeach;
                                ?>
                            </select>
                        </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">
                            <input value="<?php echo (isset($partner->contactName)) ? $partner->contactName : ''; ?>" class="form-control" name="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">
                            <input value="<?php echo (isset($partner->contactTel)) ? $partner->contactTel : ''; ?>" class="form-control" name="contactTel" type="text" />
                        </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">
                            <input value="<?php echo (isset($partner->contactEmail)) ? $partner->contactEmail : ''; ?>" class="form-control" name="contactEmail" type="email" />
                        </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">
                            <select name="companyCity" class="select2 companyCity form-control">
                                <?php
                                foreach ($cities as $city) :
                                    //print_r($city->_id->{'$oid'});
                                    //print_r($partner->companyCity->{'$oid'});
                                    $selected = (isset($partner->companyCity) && $partner->companyCity->{'$oid'} == $city->_id->{'$oid'}) ? "selected" : '';
                                    if ($selected == "selected") {
                                ?>
                                        <option value="<?php echo $city->_id->{'$oid'}; ?>" <?php echo $selected ?>><?php echo $city->city . " - " . $city->zip; ?></option>
                                <?php
                                    }
                                endforeach;
                                ?>
                            </select>
                        </div>
                    </div>
                    <!-- IDE JÖN A MEGYE -->
                    <!-- API CALL URL: get/counties -->
                    <div class="row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Megye</h5>
                        </div>
                        <div class="col-lg-8 col-sm-6 form-group">

                            <select name="companyCounty" class="select2 companyCounty form-control">
                                <?php

                                foreach ($counties as $county) :
                                    $selected = (isset($partner->companyCounty) && $partner->companyCounty == $county->id) ? "selected" : '';
                                    if ($selected == "selected") {
                                ?>
                                        <option value="<?php echo $county->id; ?>" <?php echo $selected ?>><?php echo $county->name; ?></option>
                                <?php
                                    }
                                endforeach;
                                ?>
                            </select>
                        </div>
                    </div>


                    <!-- IDE VOLT A MEGYE -->

                    <!--IDE JÖN AZ ORSZÁG -->
                    <div class="row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Ország</h5>
                        </div>
                        <div class="col-lg-8 col-sm-6 form-group">
                            <?php
                            $countries = $auth->getApiData("get/countries");
                            //print_r($countries);
                            ?>
                            <select name="companyCountry" class="select2 companyCountry form-control">
                                <?php

                                foreach ($countries as $country) :
                                    $selected = (isset($partner->companyCountry) && $partner->companyCountry == $country->id) ? "selected" : '';
                                ?>
                                    <option value="<?php echo $country->id; ?>" <?php echo $selected ?>><?php echo $country->name; ?></option>
                                <?php
                                endforeach;
                                ?>
                            </select>
                        </div>
                    </div>
                    <!--ITT VOLT AZ ORSZÁG -->
                    <div class="row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Cím</h5>
                        </div>
                        <div class="col-lg-8 col-sm-6">
                            <input value="<?php echo (isset($partner->companyAdressLocation2)) ? $partner->companyAdressLocation2 : ''; ?>" class="form-control" name="companyAdressLocation2" />
                        </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">
                            <select name="companyLocationCity" class="select2 companyLocationCity form-control">
                                <?php

                                foreach ($cities as $city) :
                                    $selected = (isset($partner->companyLocationCity) && $partner->companyLocationCity == $city->_id) ? "selected" : '';
                                ?>
                                    <option value="<?php echo $city->_id->{'$oid'}; ?>" <?php echo $selected ?>><?php echo $city->city . " - " . $city->zip; ?></option>
                                <?php
                                endforeach;
                                ?>
                            </select>
                        </div>
                    </div>
                    <!-- IDE JÖN A MEGYE -->
                    <!-- API CALL URL: get/counties -->
                    <div class="row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Megye</h5>
                        </div>
                        <div class="col-lg-8 col-sm-6 form-group">

                            <select name="companyLocationCounty" class="select2 companyLocationCounty form-control">
                                <?php

                                foreach ($counties as $county) :
                                    $selected = (isset($partner->companyLocationCounty) && $partner->companyLocationCounty == $county->id) ? "selected" : '';
                                ?>
                                    <option value="<?php echo $county->id; ?>" <?php echo $selected ?>><?php echo $county->name; ?></option>
                                <?php
                                endforeach;
                                ?>
                            </select>
                        </div>
                    </div>

                    <!-- IDE VOLT A MEGYE -->

                    <!--IDE JÖN AZ ORSZÁG -->
                    <div class="row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Ország</h5>
                        </div>
                        <div class="col-lg-8 col-sm-6 form-group">
                            <?php
                            $countries = $auth->getApiData("get/countries");
                            //print_r($countries);
                            ?>
                            <select name="companyLocationCountry" class="select2 companyLocationCountry form-control">
                                <?php

                                foreach ($countries as $country) :
                                    $selected = (isset($partner->companyLocationCountry) && $partner->companyLocationCountry == $country->id) ? "selected" : '';
                                ?>
                                    <option value="<?php echo $country->id; ?>" <?php echo $selected ?>><?php echo $country->name; ?></option>
                                <?php
                                endforeach;
                                ?>
                            </select>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Cím</h5>
                        </div>


                        <div class="col-lg-8 col-sm-6">
                            <input value="<?php echo (isset($partner->companyTLocation2)) ? $partner->companyTLocation2 : ''; ?>" class="form-control" name="companyTLocation2" />
                        </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">
                            <select name="companyPostalCity" class="select2 companyPostalCity form-control">
                                <?php
                                foreach ($cities as $city) :
                                    $selected = (isset($partner->companyPostalCity) && $partner->companyPostalCity->{'$oid'} == $city->_id->{'$oid'}) ? "selected" : '';
                                ?>
                                    <option value="<?php echo $city->_id->{'$oid'}; ?>" <?php echo $selected ?>><?php echo $city->city . " - " . $city->zip; ?></option>
                                <?php
                                endforeach;
                                ?>
                            </select>
                        </div>
                    </div>
                    <!-- IDE JÖN A MEGYE -->
                    <!-- API CALL URL: get/counties -->
                    <div class="row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Megye</h5>
                        </div>
                        <div class="col-lg-8 col-sm-6 form-group">
                            <?php
                            $counties = $auth->getApiData("get/counties");
                            //print_r($counties)
                            ?>
                            <select name="companyPostalCounty" class="select2 companyPostalCounty form-control">
                                <?php

                                foreach ($counties as $county) :
                                    $selected = (isset($partner->companyPostalCounty) && $partner->companyPostalCounty == $county->id) ? "selected" : '';
                                ?>
                                    <option value="<?php echo $county->id; ?>" <?php echo $selected ?>><?php echo $county->name; ?></option>
                                <?php
                                endforeach;
                                ?>
                            </select>
                        </div>
                    </div>

                    <!-- ITT VOLT A MEGYE -->

                    <!--IDE JÖN AZ ORSZÁG -->
                    <div class="row">
                        <div class="col-lg-4 col-sm-6">
                            <h5>Ország</h5>
                        </div>
                        <div class="col-lg-8 col-sm-6 form-group">

                            <select name="companyPostalCountry" class="select2 companyPostalCountry form-control">
                                <?php

                                foreach ($countries as $country) :
                                    $selected = (isset($partner->companyPostalCountry) && $partner->companyPostalCountry == $country->id) ? "selected" : '';
                                ?>
                                    <option value="<?php echo $country->id; ?>" <?php echo $selected ?>><?php echo $country->name; ?></option>
                                <?php
                                endforeach;
                                ?>
                            </select>
                        </div>

                        <div class="col-lg-4 col-sm-6">
                            <h5>Cím</h5>
                        </div>


                        <div class="col-lg-8 col-sm-6">
                            <input value="<?php echo (isset($partner->companyPostalLocation2)) ? $partner->companyPostalLocation2 : ''; ?>" class="form-control" name="companyPostalLocation2" />
                        </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">
                            <input value="<?php echo (isset($partner->konvencionalis_novenytermeszto)) ? $partner->konvencionalis_novenytermeszto : ''; ?>" class="form-control" name="konvencionalis_novenytermeszto" type="number" />
                        </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">
                            <input value="<?php echo (isset($partner->okologiai_novenytermeszto)) ? $partner->okologiai_novenytermeszto : ''; ?>" class="form-control" name="okologiai_novenytermeszto" type="number" />
                        </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">

                            <input value="<?php echo (isset($partner->konvencionalis_es_okologiai_novenytermeszto)) ? $partner->konvencionalis_es_okologiai_novenytermeszto : ''; ?>" class="form-control" name="konvencionalis_es_okologiai_novenytermeszto" type="number" />
                        </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">
                            <input value="<?php echo (isset($partner->szantofoldi_novenytermeszto)) ? $partner->szantofoldi_novenytermeszto : ''; ?>" class="form-control" name="szantofoldi_novenytermeszto" type="number" />
                        </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">
                            <input value="<?php echo (isset($partner->szabadfoldi_zoldsegtermeszto)) ? $partner->szabadfoldi_zoldsegtermeszto : ''; ?>" class="form-control" name="szabadfoldi_zoldsegtermeszto" type="number" />
                        </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">

                            <input value="<?php echo (isset($partner->szolotermeszto)) ? $partner->szolotermeszto : ''; ?>" class="form-control" name="szolotermeszto" type="number" />
                        </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">

                            <input value="<?php echo (isset($partner->gyumolcstermeszto)) ? $partner->gyumolcstermeszto : ''; ?>" class="form-control" name="gyumolcstermeszto" type="number" />
                        </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">

                            <input value="<?php echo (isset($partner->folias_vagy_uveghazi_kerteszet)) ? $partner->folias_vagy_uveghazi_kerteszet : ''; ?>" class="form-control" name="folias_vagy_uveghazi_kerteszet" type="number" />
                        </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">

                            <input value="<?php echo (isset($partner->palantaneveles)) ? $partner->palantaneveles : ''; ?>" class="form-control" name="palantaneveles" type="number" />
                        </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">

                            <input value="<?php echo (isset($partner->disznoveny)) ? $partner->disznoveny : ''; ?>" class="form-control" name="disznoveny" type="number" />
                        </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">

                            <input value="<?php echo (isset($partner->egyeb)) ? $partner->egyeb : ''; ?>" class="form-control" name="egyeb" type="number" />
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
<?php
}
addJS("partner.js");
?>