<?php
include_once 'classes/TestProjektSmarty.class.php';
require_once("config.inc.php");
$templatename = substr(basename($_SERVER['PHP_SELF']),0,-3)."html";
$smarty = new Smarty();
require_once "language/german.inc.php";

$action = $_GET['action'];

if($action == ''){
  $db = dbconnect();
  
  $result_bearb = $db->query("SELECT count(*) Anz 
                                 FROM imt_rollen_user_zuord a, imt_rolle b, imt_rollen_rechte_zuord c, imt_rechte d
                                WHERE a.roid=b.roid
                                  AND b.roid=c.roid
                                  AND c.reid=d.reid
                                  AND a.imtuid = '$uid' 
                                  AND d.bereich='AS'");
  $row_bearb = $result_bearb->fetch_array();

  if($row_bearb['Anz'] > 0){
    $smarty->assign('menu_ausschuss_bearb', "1");
  }

  
/* # Gutachter müssen nicht mehr vom Ausschuss genehmigt werden
    $query = "SELECT beschreibung, dateiname, target
                FROM imt_rollen_user_zuord a, imt_rolle b, imt_rollen_rechte_zuord c, imt_rechte d
               WHERE a.roid=b.roid
                 AND b.roid=c.roid
                 AND c.reid=d.reid
                 AND a.imtuid = '$uid' 
                 AND d.bereich='AS'
               ORDER BY sort_order ASC";
  
    $result = $db->query ($query)
              or die ("Cannot execute query");
    
    $table_data1 = array();
      
    while ($row = $result->fetch_array()){

      array_push($table_data1, array(  
       'beschreibung' => $row[beschreibung],
       'dateiname' => $row[dateiname],
       'target' => $row[target]
      )
      );
    }
    
    $smarty->assign('table_data1', $table_data1);
    
*/
    
  $result_bearb2 = $db->query("SELECT count(*) Anz 
                                 FROM imt_rollen_user_zuord a, imt_rolle b, imt_rollen_rechte_zuord c, imt_rechte d
                                WHERE a.roid=b.roid
                                  AND b.roid=c.roid
                                  AND c.reid=d.reid
                                  AND a.imtuid = '$uid' 
                                  AND d.bereich='ASE'");
  $row_bearb2 = $result_bearb2->fetch_array();

  if($row_bearb2['Anz'] > 0){
    $smarty->assign('menu_ausschuss_bearb2', "1");
  }
    
    $query2 = "SELECT beschreibung, dateiname, target
                FROM imt_rollen_user_zuord a, imt_rolle b, imt_rollen_rechte_zuord c, imt_rechte d
               WHERE a.roid=b.roid
                 AND b.roid=c.roid
                 AND c.reid=d.reid
                 AND a.imtuid = '$uid' 
                 AND d.bereich='ASE'
               ORDER BY sort_order ASC";
  
    $result2 = $db->query ($query2)
              or die ("Cannot execute query2");
    
    $table_data2 = array();
      
    while ($row2 = $result2->fetch_array()){

      array_push($table_data2, array(  
       'beschreibung' => $row2['beschreibung'],
       'dateiname' => $row2['dateiname'],
       'target' => $row2['target']
      )
      );
    }
    
    $smarty->assign('table_data2', $table_data2);




  $result_bearb3 = $db->query("SELECT count(*) Anz 
                                 FROM imt_rollen_user_zuord a, imt_rolle b, imt_rollen_rechte_zuord c, imt_rechte d
                                WHERE a.roid=b.roid
                                  AND b.roid=c.roid
                                  AND c.reid=d.reid
                                  AND a.imtuid = '$uid' 
                                  AND d.bereich='ASS'");
  $row_bearb3 = $result_bearb3->fetch_array();

  if($row_bearb3['Anz'] > 0){
    $smarty->assign('menu_ausschuss_bearb3', "1");
  }
    
    $query3 = "SELECT beschreibung, dateiname, target
                FROM imt_rollen_user_zuord a, imt_rolle b, imt_rollen_rechte_zuord c, imt_rechte d
               WHERE a.roid=b.roid
                 AND b.roid=c.roid
                 AND c.reid=d.reid
                 AND a.imtuid = '$uid' 
                 AND d.bereich='ASS'
               ORDER BY sort_order ASC";
  
    $result3 = $db->query ($query3)
              or die ("Cannot execute query3");
    
    $table_data3 = array();
      
    while ($row3 = $result3->fetch_array()){

      array_push($table_data3, array(  
       'beschreibung' => $row3['beschreibung'],
       'dateiname' => $row3['dateiname'],
       'target' => $row3['target']
      )
      );
    }
    
    $smarty->assign('table_data3', $table_data3);

}


if($action == 'suche'){

  $suchid = $_POST['suchid']." ";
  $findMich   = ' ';
  $pos = strpos($suchid, $findMich);
  
  $vid = trim(substr($suchid,0,$pos));
  
  echo"
  <script type='text/javascript'>
   <!--
   parent.menu_ausschuss.location.href='".$_SERVER['PHP_SELF']."';
   parent.ausschuss_haupt.location.href='ausschuss_bearbeiten.php?id=$vid';
   //-->
  </script>
  ";
}




$smarty->assign('action', "$action");
$smarty->display("$template/$templatename");

?>
