<?php

require("autentificare.php");
require("{$sitepath}pagecomponents.php");

if ($error) $errorMessage = $error;
       else $errorMessage = "";

$pagina = getuserdata('pagina', 'validare');

$data_lista = getuserdata('data_lista', '');
$text_cautat = getuserdata('text_cautat', '');

if (!$connected)
{
    writepagetitle();
    writepageheader();
    echo "<h3>Bun venit pe site-ul nostru!</h3><br><br>".
         "<p>Din pacate, site-ul nu este disponibil momentan datorita unor lucrari de intretinere.".
         " Va rugam sa reveniti mai tarziu si va multumim pentru intelegere.</p>";
    writepagefooter();
	exit;
}
else
{
    writepagetitle();
    writepageheader();

    /* Reteta */
    echo "\n<div id='reteta'>";
    require ("{$sitepath}scripts/getReteta.php");
    echo "\n</div>";
  
    /* Lista de compensari */

    echo "\n<div class='filtru'>";

    /* Cautare */
    echo "\n<div class='cautare'>";
    echo "\n    <label for='text_cautat'>Caută</label>";
    echo "\n    <input type='text' name='text_cautat' id='text_cautat' value='$text_cautat' onkeyup='cautaMedicament()'>";
    echo "\n</div>";

    /* Lista de compensari */
    echo "\n<div class='lista'>";
    $qListaCAS = $connMain->query("SELECT
                                       DISTINCT DataInceput 
                                   FROM cas_compensari
                                   ORDER BY DataInceput DESC");
    echo "\n    Lista CAS: <select name='data_lista' id='data_lista' onchange='cautaMedicament()'>";
    while ($rListaCAS = $qListaCAS->fetch_assoc())
    {
        echo "\n        <option value='{$rListaCAS['DataInceput']}'";
        if ($data_lista == $rListaCAS['DataInceput']) echo ' selected';
        if (!$data_lista) $data_lista = $rListaCAS['DataInceput'];
        echo ">Lista CAS din ".get_formatted_mysql_date($rListaCAS['DataInceput'])."</option>";
    }
    echo "\n    </select>";
    echo "\n</div>";     
    
    /* Sortare */
    echo "\n<div class='sortare'>";
    echo "\n    Rânduri pe pagină";
    echo "\n    <select id='nrmed' name='nrmed' onchange='cautaMedicament()' style='margin-right: 2em'>";
    echo "\n        <option value='10' selected>10</option>";
    echo "\n        <option value='20'>25</option>";
    echo "\n        <option value='50'>50</option>";
    echo "\n        <option value='100'>100</option>";
    echo "\n    </select>";

    echo "\n    Sortează după: ";
    echo "\n    <a href='#' onclick='sortare=1; cautaMedicament()' style='font-weight: bold' id='sortPret'>Preţ/UT</a>&nbsp;&nbsp|&nbsp;";
    echo "\n    <a href='#' onclick='sortare=2; cautaMedicament()' id='sortDenumire'>Denumire</a>";
    echo "\n</div>";

    echo "\n</div>";
    
    echo "\n<div class='filtru' style='display: none; margin-top: 0' id='msg_filtru'>";
    echo "\n    Se actualizează lista de medicamente...";
    echo "\n</div>";

    echo "\n<div id='lista_medicamente'>";
    
    require ("{$sitepath}scripts/getListaMedicamente.php");
    echo "\n</div>";
    
    writepagefooter();
}

?>