<?php

    class Ubicacion {

        private $con;

        public function __construct($con) {
            $this->con = $con;
        }


        public function provinciasCiudades($style = FALSE, $provincias = FALSE, $ciudades = FALSE) {
            $Schema = new Schema($this->con);
            global $provincias_lg;
            global $ciudades_lg;
            $style = $style ? $style : 'col-md-4 col-12 mb-3';
            

            $html = '<div class="' . $style . '">';
                $html .= '<div class="form-group">';
                    $html .= '<label for="ubicacion_provincias">' . $provincias_lg . '</label>';
                    $html .= '<select class="custom-select" id="ubicacion_provincias" name="ubicacion_provincias" required>';
                        $res = $this->con->query('SELECT * FROM COMUN_PROVINCIAS ORDER BY DESCRIPCION ASC');
                        $html .= '<option value="">' . $provincias_lg . '</option>';
                        while($row = $res->fetch_array()) {
                            $selected_1 = $provincias == $row['CODIGO'] ? 'selected': FALSE;
                            $html .= '<option value="' . $row['CODIGO'] . '" ' . $selected_1 . '>' . $row['DESCRIPCION'] . '</option>';
                        }
                    $html .= '</select>';
                    $html .= '</div>';
            $html .= '</div>';


            $html .= '<div class="' . $style . '">';
                $html .= '<div class="form-group">';
                    $html .= '<label for="ubicacion_ciudades">' . $ciudades_lg . '</label>';
                    $html .= '<select class="custom-select" id="ubicacion_ciudades" name="ubicacion_ciudades" required>';
                        if($ciudades) {
                            $c = $Schema->executeQuery('SELECT POBLACION FROM COMUN_CIUDADES WHERE CODIGO = ?', 'i', [$ciudades])->fetch_array();
                            $html .= '<option value="' . $ciudades . '">' . $c['POBLACION'] . '</option>';
                        } else {
                            $html .= '<option value="">' . $ciudades_lg . '</option>';
                        }
                        $html .= '</select>';
                    $html .= '</div>';
            $html .= '</div>';

            

            return $html;
            
        }

    }

?>