<?php  
#Left_dynamic_menu_module ver.1.0
#last modification: 30.3.2010
# Zobrazeni nabídek levého menu na základě aktuálního formuláře. Struktura je 
# dána tabulkou pohledu...
   require "build/db_connect.inc.php" ;
     
    $query="SELECT nextFunction_ID,nextFunction_Name
            FROM user_function_view1
            WHERE Function_ID=".$_SESSION['ACTUALFORM']." 
            AND login=\"".$_SESSION['USER']."\"    
            AND submenu=0";
    $result = mysql_query($query);
    
    if (!$result) {
      die('Could not query1:' . mysql_error());
    }
    echo "<table align=\"center\">";
    while (list($nextFunction_ID,$nextFunction_Name) = mysql_fetch_row($result)){
        echo("<tr><td>
              <a href=\"".selfURL()."?NEXTFORM=".$nextFunction_ID."\">".$nextFunction_Name."</a>
                </td></tr>");
        include "build/db_connect.inc.php";
        $subquery="SELECT UFV.nextFunction_ID,UFV.nextFunction_Name
                   FROM user_function_view1 UFV
                   WHERE UFV.function_ID=".$nextFunction_ID."
                   AND EXISTS (SELECT 1 FROM user_function_view1 WHERE function_ID=".$_SESSION['ACTUALFORM']." AND nextfunction_ID=UFV.nextFunction_ID AND submenu=1
                               AND NOT ".$_SESSION['ACTUALFORM']."=".$nextFunction_ID."    )
                 
                 
                
                   AND submenu=1 
                   AND login=\"".$_SESSION['USER']."\" 
                  ";
                    # AND NOT nextFunction_Name=\"".$nextFunction_Name."\"
                  # WHERE function_name=\"".$nextFunction_Name."\"
        $subresult = mysql_query($subquery);
        if (!$subresult) {
          die('Could not query2:' . mysql_error());
        }
          
        while (list($subnextFunction_ID,$subnextFunction_Name) = mysql_fetch_row($subresult)){
    //    echo("<div class=\"submenu\" >");
            echo("<tr><td class=\"submenu\"><a href=\"".selfURL()."?NEXTFORM=".$subnextFunction_ID."\">".$subnextFunction_Name."</a></td></tr>");
     //   echo("</div>");
        }
        /*------------------------------------------------------------------------------------------------*/
        include "build/db_connect.inc.php";
        $subquery="SELECT UFV.nextFunction_ID,UFV.nextFunction_Name
                   FROM user_function_view1 UFV
                   WHERE UFV.function_ID=".$nextFunction_ID." 
                   AND EXISTS (SELECT 1 FROM user_function_view1 WHERE function_ID=".$_SESSION['ACTUALFORM']." AND submenu=2 and nextFunction_ID=UFV.nextFunction_ID)             
                   AND submenu=2 
                   AND login=\"".$_SESSION['USER']."\" 
                  ";
                    # AND NOT nextFunction_Name=\"".$nextFunction_Name."\"
                  # WHERE function_name=\"".$nextFunction_Name."\"
        $subresult = mysql_query($subquery);
        if (!$subresult) {
          die('Could not query:3' . mysql_error());
        }
          
        while (list($subnextFunction_ID,$subnextFunction_Name) = mysql_fetch_row($subresult)){
      //  echo("<div class=\"submenu\" >");
            echo("<tr><td class=\"submenu\"><a href=\"".selfURL()."?NEXTFORM=".$subnextFunction_ID."\">".$subnextFunction_Name."</a></tr></td>");
       // echo("</div>");
        }
        
    }
    echo "</table>" ; 
  
?>
