<?php
function CargarListaClientes($con, $busq)
{

    if (isset($busq) == "") {
        $sqlVerificandoLogin = ("SELECT cli_id, cli_nombre FROM clientes");
    } else {
        $sqlVerificandoLogin = ("SELECT cli_id, cli_nombre FROM clientes WHERE cli_nombre LIKE '" . $busq . "%' ORDER BY cli_nombre");

        echo '<form action="clientes.php" class="">        
              <button type="submit" class="btn boton-eliminar-busqueda">Eliminar Busqueda (' . $busq . ')</button>
              </form>';
    }

    $resultLogin = mysqli_query($con, $sqlVerificandoLogin) or die(mysqli_error($con));
    $numLogin = mysqli_num_rows($resultLogin);
    if ($numLogin > 0) {
        while ($rowData = mysqli_fetch_assoc($resultLogin)) {
            //$user['UserAdmin'] = $rowData['UserAdmin'];
            $cliente['cli_id'] = $rowData['cli_id'];
            $cliente['cli_nombre'] = $rowData['cli_nombre'];
            $url_cliente = 'clientes.php?id=' . $cliente['cli_id'];

            echo '<a href="' . $url_cliente . '" class="dashboard-nav-item">';
            echo '<i class="fas fa-users"></i>';            
            echo $cliente['cli_nombre'] . " (" . $cliente['cli_id'] . ')';
            echo '</a>';
        }
    }
}

function GetInfoCliente($con, $idcli)
{

    if (isset($idcli) == "") {
        return "";
    } else {
        $sqlVerificandoLogin = ('SELECT cli_id,
                                        cli_nombre,
                                        cli_direccion,
                                        cli_poblacion,
                                        cli_cp,
                                        cli_tfno
                                        FROM clientes WHERE cli_id = ' . $idcli);
        $resultLogin = mysqli_query($con, $sqlVerificandoLogin) or die(mysqli_error($con));
        $numLogin = mysqli_num_rows($resultLogin);
        //echo $numLogin;

        if ($numLogin > 0) {
            while ($rowData = mysqli_fetch_assoc($resultLogin)) {
                //$user['UserAdmin'] = $rowData['UserAdmin'];                   
                $cliente['cli_nombre'] = $rowData['cli_nombre'];
                $cliente['cli_id'] = $rowData['cli_id'];
                $cliente['cli_direccion'] = $rowData['cli_direccion'];
                $cliente['cli_poblacion'] = $rowData['cli_poblacion'];
                $cliente['cli_cp'] = $rowData['cli_cp'];
                $cliente['cli_tfno'] = $rowData['cli_tfno'];
                //echo $cliente['cli_nombre'];
                return $cliente;
            }
        }
    }

}

function PutInfoCliente($lab, $valor)
{
    echo '<p>' . $lab . ': ' . $valor . '</p>';
}

function GetContactosCliente($con, $idcli, $orden)
{

    if (isset($idcli) == "") {
        return "";
    } else {
        $sqlVerificandoLogin = ('SELECT con_id,
                                        con_nombre,
                                        con_movil,
                                        con_email
                                        FROM contactos WHERE con_idcli = ' . $idcli . ' AND con_orden = ' . $orden);
        $resultLogin = mysqli_query($con, $sqlVerificandoLogin) or die(mysqli_error($con));
        $numLogin = mysqli_num_rows($resultLogin);
        //echo $numLogin;

        if ($numLogin > 0) {
            while ($rowData = mysqli_fetch_assoc($resultLogin)) {
                //$user['UserAdmin'] = $rowData['UserAdmin'];                   
                $contacto['con_nombre'] = $rowData['con_nombre'];
                $contacto['con_id'] = $rowData['con_id'];
                $contacto['con_movil'] = $rowData['con_movil'];
                $contacto['con_email'] = $rowData['con_email'];
                //echo $cliente['cli_nombre'];
                return $contacto;
            }
        }
    }

}

function GetIDContactosCliente($con, $idcli)
{
    if (isset($idcli) == "") {
        echo '';
    } else {
        $sqlVerificandoLogin = ("SELECT con_id,con_nombre,con_movil,con_email FROM contactos WHERE con_idcli = " . $idcli);

        $resultLogin = mysqli_query($con, $sqlVerificandoLogin) or die(mysqli_error($con));
        $numLogin = mysqli_num_rows($resultLogin);
        $cont = 1;
        if ($numLogin > 0) {
            while ($rowData = mysqli_fetch_assoc($resultLogin)) {
                //$user['UserAdmin'] = $rowData['UserAdmin'];
                echo '<h2>Contacto ' . $cont . '</h2>';

                PutInfoCliente('Nombre', $rowData['con_nombre']);
                PutInfoCliente('Teléfono', $rowData['con_movil']);
                PutInfoCliente('Email', $rowData['con_email']);

                echo '<button class="open-button" onclick="openForm2(' . $cont . ')">Editar</button>';
                echo '<hr>';
                $cont = $cont + 1;
            }
        }
        echo '<button class="open-button" onclick="openForm3()">Añadir Contacto</button>';
    }
}

function PutFormContactoClientes($con, $idcli)
{
    if (isset($idcli) == "") {
        echo '';

    } else {
        $sqlVerificandoLogin = ("SELECT count(*) as num_con FROM contactos WHERE con_idcli = " . $idcli);

        $resultLogin = mysqli_query($con, $sqlVerificandoLogin) or die(mysqli_error($con));
        $numLogin = mysqli_num_rows($resultLogin);
        if ($numLogin > 0) {
            while ($rowData = mysqli_fetch_assoc($resultLogin)) {
                //$user['UserAdmin'] = $rowData['UserAdmin'];
                for ($i = 1; $i <= $rowData['num_con']; $i++) {

                    $contacto = GetContactosCliente($con, $idcli, $i);
                    echo '<div class="form-popup" id="myFormContacto' . $i . '">
                            <form action="editar_contacto.php" class="form-container">
                                <h1>Editar Contacto ' . $i . '</h1>                   
                                <input id="IdCli" name="IdCli" type="hidden" value="' . $idcli . '" />                 
                                <input id="Id" name="Id" type="hidden" value="' . $contacto['con_id'] . '" />                 

                                <label for="nombre"><b>Nombre</b></label>
                                <input type="text" placeholder="' . $contacto['con_nombre'] . '" name="nombre"
                                       value="' . $contacto['con_nombre'] . '" required>

                                <label for="movil"><b>Movil</b></label>
                                <input type="text" placeholder="' . $contacto['con_movil'] . '" name="movil"
                                              value="' . $contacto['con_movil'] . '" >
                                
                                <label for="email"><b>Email</b></label>
                                <input type="text" placeholder="' . $contacto['con_email'] . '" name="email"
                                              value="' . $contacto['con_email'] . '" >
                                
                                <button type="submit" class="btn">Editar</button>
                                <button type="button" class="btn cancel" onclick="closeForm2(' . $i . ')">Cerrar</button>
                            </form>
                         </div>';
                }

            }
        }

    }

}

function UltimoNumContacto($con, $idcli)
{
    if (isset($idcli) == "") {
        return 0;
    } else {
        $sqlVerificandoLogin = ("SELECT count(*) as num_con FROM contactos WHERE con_idcli = " . $idcli);
        $resultLogin = mysqli_query($con, $sqlVerificandoLogin) or die(mysqli_error($con));
        $numLogin = mysqli_num_rows($resultLogin);
        if ($numLogin > 0) {
            while ($rowData = mysqli_fetch_assoc($resultLogin)) {
                return $rowData['num_con'];
            }
        } else {
            return 0;
        }
    }
}

function UltimosIDCliente($con)
{
    $sqlVerificandoLogin = ("SELECT cli_id FROM clientes ORDER BY cli_id DESC LIMIT 1");
    $resultLogin = mysqli_query($con, $sqlVerificandoLogin) or die(mysqli_error($con));
    $numLogin = mysqli_num_rows($resultLogin);
    if ($numLogin > 0) {
        while ($rowData = mysqli_fetch_assoc($resultLogin)) {
            return $rowData['cli_id'];
        }
    } else {
        return 0;
    }
}

function MostrarLoremIpsum($num)
{
    for ($i = 1; $i <= $num; $i++) {
        echo '<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Nobis, tempore quia. Facilis, corrupti
        cupiditate magni vel fuga iusto ex temporibus.</p>';

    }
}

function MostrarTarjetaClientes($num)
{
    for ($i = 1; $i <= $num; $i++) {
        echo '
        <div class="tarjeta-cliente">
            <div class="clasif-cliente">
                <h2>12351</h2>
            </div>
            <div>
                <h3>Nombre del Producto</h3>
                <p>Referencia Web</p>
                </div>
        </div>
        '
        ;

    }
}

function MostrarTarjetaClientes2($num)
{
    for ($i = 1; $i <= $num; $i++) {
        echo '
        <div class="tarjeta-cliente">
            <div class="clasif-cliente">
                <h2>12351</h2>
            </div>
            <div>
                <h3>Nombre del Producto</h3>
                <p>Referencia Web</p>
            </div>
        </div>
        '
        ;

    }
}

function MostrarCabeceraTituloCliente()
{
    echo '
        <div class="tarjeta-cliente-cabecera">
            <div class="clasif-cliente-cabecera">
                <h2>12351</h2>
            </div>
            <div>
                <h3>Nombre del Producto</h3>
                <p>Referencia Web</p>
            </div>
        </div>
    ';
}

function MostrarDatosClienteContacto()
{
    echo '
        <div class="tarjeta-cliente-cuerpo2">  
        <div class="titulo-tarjeta">
        <h3>Datos de Producto</h3>
        </div>
            <div>
                <div class="titulo-tarjeta-cliente">
                
                </div>
                <h4>Descripción Corta</h4>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
                <h4>Descripción Larga</h4>
                <p>Sección 1.10.32 de "de Finibus Bonorum et Malorum", escrito por Cicero en el 45 antes de Cristo
                "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"
                
                Traducci�n hecha por H. Rackham en 1914
                "But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"
                
                Sección 1.10.33 de "de Finibus Bonorum et Malorum", escrito por Cicero en el 45 antes de Cristo
                "At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."
                
                Traducci�n hecha por H. Rackham en 1914
                "On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."</p>                
            </div>
        </div>
    ';
}

function MostrarDatosClienteContacto2()
{
    echo '
        
    <h1>Arlina Design</h1>
    <p>Arlina Design (specifically, the sweet orange) is the fruit of the citrus species Citrus ×
        sinensis in the family Rutaceae</p>
    <p>The fruit of the Citrus × sinensis is considered a sweet orange, whereas the fruit of the
        Citrus × aurantium is considered a bitter orange. The sweet orange reproduces asexually
        (apomixis through nucellar embryony); varieties of sweet orange arise through mutations.</p>
        <p>Arlina Design (specifically, the sweet orange) is the fruit of the citrus species Citrus ×
        sinensis in the family Rutaceae</p>
    <p>The fruit of the Citrus × sinensis is considered a sweet orange, whereas the fruit of the
        Citrus × aurantium is considered a bitter orange. The sweet orange reproduces asexually
        (apomixis through nucellar embryony); varieties of sweet orange arise through mutations.</p>
        <p>Arlina Design (specifically, the sweet orange) is the fruit of the citrus species Citrus ×
        sinensis in the family Rutaceae</p>
    <p>The fruit of the Citrus × sinensis is considered a sweet orange, whereas the fruit of the
        Citrus × aurantium is considered a bitter orange. The sweet orange reproduces asexually
        (apomixis through nucellar embryony); varieties of sweet orange arise through mutations.</p>ç
        <p>Arlina Design (specifically, the sweet orange) is the fruit of the citrus species Citrus ×
        sinensis in the family Rutaceae</p>
    <p>The fruit of the Citrus × sinensis is considered a sweet orange, whereas the fruit of the
        Citrus × aurantium is considered a bitter orange. The sweet orange reproduces asexually
        (apomixis through nucellar embryony); varieties of sweet orange arise through mutations.</p>
        <p>Arlina Design (specifically, the sweet orange) is the fruit of the citrus species Citrus ×
        sinensis in the family Rutaceae</p>
    <p>The fruit of the Citrus × sinensis is considered a sweet orange, whereas the fruit of the
        Citrus × aurantium is considered a bitter orange. The sweet orange reproduces asexually
        (apomixis through nucellar embryony); varieties of sweet orange arise through mutations.</p>
        <p>Arlina Design (specifically, the sweet orange) is the fruit of the citrus species Citrus ×
        sinensis in the family Rutaceae</p>
    <p>The fruit of the Citrus × sinensis is considered a sweet orange, whereas the fruit of the
        Citrus × aurantium is considered a bitter orange. The sweet orange reproduces asexually
        (apomixis through nucellar embryony); varieties of sweet orange arise through mutations.</p>
        <p>Arlina Design (specifically, the sweet orange) is the fruit of the citrus species Citrus ×
        sinensis in the family Rutaceae</p>
    <p>The fruit of the Citrus × sinensis is considered a sweet orange, whereas the fruit of the
        Citrus × aurantium is considered a bitter orange. The sweet orange reproduces asexually
        (apomixis through nucellar embryony); varieties of sweet orange arise through mutations.</p>
        <p>Arlina Design (specifically, the sweet orange) is the fruit of the citrus species Citrus ×
        sinensis in the family Rutaceae</p>
    <p>The fruit of the Citrus × sinensis is considered a sweet orange, whereas the fruit of the
        Citrus × aurantium is considered a bitter orange. The sweet orange reproduces asexually
        (apomixis through nucellar embryony); varieties of sweet orange arise through mutations.</p>
        <p>Arlina Design (specifically, the sweet orange) is the fruit of the citrus species Citrus ×
        sinensis in the family Rutaceae</p>
    <p>The fruit of the Citrus × sinensis is considered a sweet orange, whereas the fruit of the
        Citrus × aurantium is considered a bitter orange. The sweet orange reproduces asexually
        (apomixis through nucellar embryony); varieties of sweet orange arise through mutations.</p>
        <p>Arlina Design (specifically, the sweet orange) is the fruit of the citrus species Citrus ×
        sinensis in the family Rutaceae</p>
    <p>The fruit of the Citrus × sinensis is considered a sweet orange, whereas the fruit of the
        Citrus × aurantium is considered a bitter orange. The sweet orange reproduces asexually
        (apomixis through nucellar embryony); varieties of sweet orange arise through mutations.</p>
        <p>Arlina Design (specifically, the sweet orange) is the fruit of the citrus species Citrus ×
        sinensis in the family Rutaceae</p>
    <p>The fruit of the Citrus × sinensis is considered a sweet orange, whereas the fruit of the
        Citrus × aurantium is considered a bitter orange. The sweet orange reproduces asexually
        (apomixis through nucellar embryony); varieties of sweet orange arise through mutations.</p>
        <p>Arlina Design (specifically, the sweet orange) is the fruit of the citrus species Citrus ×
        sinensis in the family Rutaceae</p>
    <p>The fruit of the Citrus × sinensis is considered a sweet orange, whereas the fruit of the
        Citrus × aurantium is considered a bitter orange. The sweet orange reproduces asexually
        (apomixis through nucellar embryony); varieties of sweet orange arise through mutations.</p>
        <p>Arlina Design (specifically, the sweet orange) is the fruit of the citrus species Citrus ×
        sinensis in the family Rutaceae</p>
    <p>The fruit of the Citrus × sinensis is considered a sweet orange, whereas the fruit of the
        Citrus × aurantium is considered a bitter orange. The sweet orange reproduces asexually
        (apomixis through nucellar embryony); varieties of sweet orange arise through mutations.</p>
    
        '
    ;

}