<?php

function bara_navigare($id_meniu = 0)
{
    echo "<p id='breadcrumbs'>Vă aflați aici: <a href='index.php'>Prima pagină</a>";
    $q = mysql_query("SELECT m.*, p.denumire AS parinte FROM meniu m LEFT JOIN meniu p ON p.id = m.id_parinte WHERE m.id = $id_meniu");
    if ($r = mysql_fetch_assoc($q))
    {
        if ($r['id_parinte'])
        {
            $q1 = mysql_query("SELECT * FROM meniu WHERE id = {$r['id_parinte']}");
            if ($r1 = mysql_fetch_assoc($q1))
         //       if ($r1['denumire'] != $r['parinte'])
                    echo " &gt; <a href='index.php?id_meniu={$r1['id']}'>{$r1['denumire']}</a>";
        }
        if ($r['denumire'] != $r['parinte'])
            echo " &gt; <a href='index.php?id_meniu={$r['id']}'>{$r['denumire']}</a>";
    }
}

function meniu_sus()
{
	global $id_meniu, $margine;
    $q = mysql_query("SELECT * FROM meniu WHERE meniu = 1 AND (id_parinte = 0 OR id_parinte IS NULL) ORDER BY nrcrt");
    $i = 0;
    while ($r = mysql_fetch_assoc($q))
    {
    	if (!$id_meniu) $id_meniu = $r['id'];
    	echo "<a href='index.php?id_meniu={$r['id']}'";
    	$q1 = mysql_query("SELECT * FROM meniu WHERE id = $id_meniu");
    	$r1 = mysql_fetch_assoc($q1);
    	if ( ($id_meniu == $r['id']) || ($r1['id_parinte'] == $r['id']) )
		{ 
			echo " class='activ'>";
		    echo "<div class='stanga'></div>";
		    echo "<div class='centru'>{$r['denumire']}</div>";
		    echo "<div class='dreapta'></div>";
		    if ($r['margine'] != '') $margine = $r['margine'];
    	}
    	else echo ">{$r['denumire']}";
    	echo "</a>";
    	if (++$i != mysql_num_rows($q)) echo "<div class='separator'>|</div>";
    }
}

function submeniu_sus()
{
	global $id_meniu, $suprima_meniu_stanga, $arata_medici_colaboratori;
	$q = mysql_query("SELECT * FROM meniu WHERE id = $id_meniu");
	$r = mysql_fetch_assoc($q);
	if ($r['id_parinte'] > 0) { $id_parinte = $r['id_parinte']; $id = $id_meniu; }
	                     else { $id_parinte = $id_meniu; $id = 0; }
    $q = mysql_query("SELECT * FROM meniu WHERE meniu = 1 AND id_parinte = $id_parinte ORDER BY nrcrt");
    $i = 0;
    while ($r = mysql_fetch_assoc($q))
    {
    	echo "<a href='index.php?id_meniu={$r['id']}'";
    	if ( ($id == 0) || ($r['id'] == $id) )
    	{
			$id = $r['id'];
			echo " class='activ'";
			$suprima_meniu_stanga = !$r['butoane_cumparare'];
			$arata_medici_colaboratori = $r['medici_colaboratori'];
		}
		echo ">{$r['denumire']}</a>";
    	if (++$i != mysql_num_rows($q)) echo "<div class='separator'>|</div>";
    }
}

function meniu_stanga()
{
	global $imagesroot, $suprima_meniu_stanga;
	if ($suprima_meniu_stanga) return;
    $q = mysql_query("SELECT * FROM meniu WHERE meniu = 2 ORDER BY nrcrt");
    while ($r = mysql_fetch_assoc($q))
    {
        if ($r['link']) 
            echo "<a href='{$r['link']}' target='_blank'>";
        else
        {
            echo "<a href='index.php?";
            if ($r['id_meniu']) echo "id_meniu={$r['id_meniu']}";
            elseif ($r['id_articol']) echo "id_articol={$r['id_articol']}";
            elseif ($r['id_modul']) echo "id_modul={$r['id_modul']}";
            echo "'>";
        }
	    echo "<div class='stanga'></div>";
	    echo "<div class='centru'>{$r['denumire']}</div>";
	    echo "<div class='dreapta'></div>";
        echo "</a>";
	}
}

function meniu_colaboratori()
{
	global $imagesroot, $arata_medici_colaboratori;
	if (!$arata_medici_colaboratori) return;
	echo "<div style='font-weight: bold; clear: both; padding-top: 1.5em;'>Medici colaboratori:</div><div>&nbsp;</div>";
    $q = mysql_query("SELECT * FROM testimoniale WHERE IFNULL(imagine, '') <> '' ORDER BY nr_crt");
    while ($r = mysql_fetch_assoc($q))
    {
        echo "<div style='float: left; margin-right: 10px; width: 100px'><a href='index.php?id_meniu=9' style='display: block'>";
        echo "<center style='cursor: pointer'><img src='{$imagesroot}{$r['imagine']}' width='50' height='58' style='margin: 2px; padding: 0px'></center>";
        echo "<center style='font-size: 8pt; margin: 0px; padding: 0px; cursor: pointer'><b>{$r['medic']}</b></center>";
		echo "<center style='font-size: 8pt; margin: 0px; padding: 0px; cursor: pointer'>{$r['functia']}</center></a></div>";
	}
}

function meniu_dreapta()
{
	global $imagesroot;
    $q = mysql_query("SELECT * FROM meniu WHERE meniu = 3 ORDER BY nrcrt");
    while ($r = mysql_fetch_assoc($q))
    {
        if ($r['link']) 
            echo "<a href='{$r['link']}' target='_blank'>";
        else
        {
            echo "<a href='index.php?";
            if ($r['id_meniu']) echo "id_meniu={$r['id_meniu']}";
            elseif ($r['id_articol']) echo "id_articol={$r['id_articol']}";
            elseif ($r['id_modul']) echo "id_modul={$r['id_modul']}";
            echo "'>";
        }
        echo "<img src='{$imagesroot}{$r['imagine']}' align='left'>";
        echo "<div class='descriere'><div class='titlu'>{$r['denumire']}</div>";
        echo "<div class='subtitlu'>{$r['descriere']}</div></div>";
        echo "</a>";
	}
}

function meniu_jos()
{
	global $imagesroot;
    $q = mysql_query("SELECT * FROM meniu WHERE meniu = 4 ORDER BY nrcrt DESC");
    while ($r = mysql_fetch_assoc($q))
    {
        if ($r['link']) 
            echo "<a href='{$r['link']}' target='_blank'>";
        else
        {
            echo "<a href='index.php?";
            if ($r['id_meniu']) echo "id_meniu={$r['id_meniu']}";
            elseif ($r['id_articol']) echo "id_articol={$r['id_articol']}";
            elseif ($r['id_modul']) echo "id_modul={$r['id_modul']}";
            echo "'>";
        }
        echo "<img src='{$imagesroot}bullet_patrat.png'> {$r['denumire']}</a>";
	}
}





function meniu_stangaa(&$id_meniu = 0)
{
    global $id_articol, $imagine_meniu;
	$categorie = '';  
    $q = mysql_query("SELECT * FROM meniu WHERE id = $id_meniu");
    if ($r = mysql_fetch_assoc($q))
    {
        $mainmenu = ((int)($r['id_parinte']) == 0);
        if (!$mainmenu) $id_parinte = $r['id_parinte'];
                   else $id_parinte = $id_meniu;
    }
    else
    {
        $mainmenu = true;
        $id_parinte = 0;
    }
    $q = mysql_query("SELECT * FROM meniu WHERE meniu = 1 AND id_parinte = $id_parinte ORDER BY nrcrt");
    if (mysql_num_rows($q))
    {
  	    //echo "<ul id='category'>";
    	while ($r = mysql_fetch_assoc($q))
    	{
    	    if ($categorie != $r['categorie'])
    	    {
    	    	if ($categorie != '') echo "</ul><hr class='noscreen' />";
    		    $categorie = $r['categorie'];
		    	echo "<h3><span>{$r['categorie']}</span></h3>";
		    	echo "<ul id='category'>";
	    	}
        	echo "<li";
        	if ($mainmenu)
            {
                echo " id='category-active'";
                $mainmenu = false;
                $id_meniu = $r['id'];
                if ($r['imagine']) $imagine_meniu = $r['imagine'];
            }
            elseif ($r['id'] == $id_meniu)
            {
                echo " id='category-active'";
                if ($r['imagine']) $imagine_meniu = $r['imagine'];
            } 
        	echo "><a href='index.php?id_meniu={$r['id']}'>{$r['denumire']}</a></li>";
        }
	    echo "</ul><hr class='noscreen' />";
    }
}

function linkuri_stanga()
{
    echo "<ul>";
    $q = mysql_query("SELECT * FROM meniu WHERE meniu = 2 ORDER BY nrcrt");
    while ($r = mysql_fetch_assoc($q))
    {
        if (!$r['fundal']) $r['fundal'] = '000000';
        echo "<li style='background-color: #{$r['fundal']}'>";
        if ($r['link']) 
            echo "<a href='{$r['link']}' target='_blank'>{$r['denumire']}</a></li>";
        else
        {
            echo "<a href='index.php?";
            if ($r['id_meniu']) echo "id_meniu={$r['id_meniu']}";
            elseif ($r['id_articol']) echo "id_articol={$r['id_articol']}";
            elseif ($r['id_modul']) echo "id_modul={$r['id_modul']}";
            echo "'>{$r['denumire']}</a></li>";
        }
    }
    echo "</ul>";
}

function linkuri_dreapta()
{
    echo "<ul>";
    $q = mysql_query("SELECT * FROM meniu WHERE meniu = 3 ORDER BY nrcrt");
    while ($r = mysql_fetch_assoc($q))
    {
        echo "<li style='background-image: url(imagini/{$r['imagine']})'>";
        if ($r['link']) 
            echo "<a href='{$r['link']}' target='_blank'>{$r['denumire']}</a>";
        else
        {
            echo "<a href='index.php?";
            if ($r['id_meniu']) echo "id_meniu={$r['id_meniu']}";
            elseif ($r['id_articol']) echo "id_articol={$r['id_articol']}";
            elseif ($r['id_modul']) echo "id_modul={$r['id_modul']}";
            echo "'>{$r['denumire']}</a></li>";
        }
    }
    echo "</ul>";
}

function linkuri_jos($id_meniu = 0)
{
    echo "<p>";
    $q = mysql_query("SELECT * FROM meniu WHERE meniu = 1 AND (id_parinte = 0 OR id_parinte IS NULL) ORDER BY nrcrt");
    $i = 1;
    while ($r = mysql_fetch_assoc($q))
    {
        if ($r['link']) 
            echo "<a href='{$r['link']}' target='_blank'>{$r['denumire']}</a>";
        else
            echo "<a href='index.php?id_meniu={$r['id']}'>{$r['denumire']}</a>";
        if ($i < mysql_num_rows($q)) echo '|';
        $i++;
    }
    echo "</p>";
    $q = mysql_query("SELECT * FROM meniu WHERE id = $id_meniu");
    if ($r = mysql_fetch_assoc($q))
    {
        $mainmenu = ((int)($r['id_parinte']) == 0);
        if (!$mainmenu) $id_parinte = $r['id_parinte'];
                   else $id_parinte = $id_meniu;
    }
    else
    {
        $mainmenu = true;
        $id_parinte = 0;
    }
    $q = mysql_query("SELECT * FROM meniu WHERE meniu = 1 AND id_parinte = $id_parinte ORDER BY nrcrt");
    if (mysql_num_rows($q))
    {
	    echo "<p>";
    	$i = 1;
    	while ($r = mysql_fetch_assoc($q))
    	{
            if ($r['link']) 
                echo "<a href='{$r['link']}' target='_blank'>{$r['denumire']}</a>";
            else
                echo "<a href='index.php?id_meniu={$r['id']}'>{$r['denumire']}</a></li>";
        	if ($i < mysql_num_rows($q)) echo '|';
        	$i++;
        }
	    echo "</p>";
    }
    echo "<p>";
    $q = mysql_query("SELECT * FROM meniu WHERE meniu = 2 ORDER BY nrcrt");
    $i = 1;
    while ($r = mysql_fetch_assoc($q))
    {
        if ($r['link']) 
            echo "<a href='{$r['link']}' target='_blank'>{$r['denumire']}</a></li>";
        else
        {
            echo "<a href='index.php?";
            if ($r['id_meniu']) echo "id_meniu={$r['id_meniu']}";
            elseif ($r['id_articol']) echo "id_articol={$r['id_articol']}";
            elseif ($r['id_modul']) echo "id_modul={$r['id_modul']}";
            echo "'>{$r['denumire']}</a></li>";
        }
      	if ($i < mysql_num_rows($q)) echo '|';
      	$i++;
    }
    echo "</p>";
}

?>