<?php

# Fuer debugging
#error_reporting(E_ALL);
#ini_set('display_errors', 1);
#echo __LINE__."<br>";


require_once("../config/datenbankanbindung.php"); // f&uuml;gt die Datenbankanbindung ein: Sys:\php\includes\kurs\datenbankanbindung.php
require('as_utf_class.php');
require_once("sitzung_pdf.inc");
define('FPDF_FONTPATH','font/');

$output = $_GET['output'];
$isid = $_GET['isid'];

class PDF extends fpdf_table
{

//Fusszeile
function Footer()
{
//! @return void
//! @desc The footer is printed in every page!
    //Position at 1.0 cm from bottom
    $this->SetY(-10);
    //Copyright //especial para esta versão
    $this->SetFont('Arial','B',8);
  	$this->SetTextColor(0);
    //Arial italic 9
    $this->SetFont('Arial','',8);
    //Page number
    $this->Cell(0,10,'Seite '.$this->PageNo().'/{nb}',0,0,'C');
    //Return Font to normal
    $this->SetFont('Arial','',11);
}
}

$pdf=new utfFPDF();
$pdf->AliasNbPages();  // Damit die Gesamt seitenzahl des Footers angezeigt wird: {nb}
$pagecount = $pdf->setSourceFile("idee_blanko.pdf");
$tplidx = $pdf->ImportPage(1);

// Seitenabstand definieren
$pdf->SetMargins(24, 40, 20); 
$pdf->SetAutoPageBreak(true,21); 
$pdf->AcceptPageBreak(true); 
$pdf->AddPage();
$pdf->useTemplate($tplidx,0,0,0);



# Datum setzen
$pdf->SetY(18.9);
#$pdf->SetTextColor(255,0,0);
$pdf->SetFont('Arial', '', 8);
$aend_dat = date("d.m.Y");
#$pdf->MultiCell(170.4, 5,"$aend_dat", 0, 'R');


# Ansprechpartner setzen
$pdf->SetY(23.6);
#$pdf->SetTextColor(255,0,0);
$pdf->SetFont('Arial', '', 8);
$aend_dat = date("d.m.Y");
#$pdf->MultiCell(170, 5,"$global_service_admin", 0, 'R');


# Ansprechpartner Mail setzen
$pdf->SetY(32.8);
#$pdf->SetTextColor(255,0,0);
$pdf->SetFont('Arial', '', 8);
$aend_dat = date("d.m.Y");
#$pdf->MultiCell(175.5, 5,"$global_service_mail", 0, 'R');





function linebreak($text){
  $text = strip_tags($text,'<br>,<li>,</li>');
  $text = str_replace('<br /> ', chr(10), $text);
  $text = str_replace('<br />', chr(10), $text);
  $text = str_replace('<li>', '-', $text);
  $text = str_replace('</li>', chr(10), $text);
  $text = str_replace('&euro;', chr(128), $text);
#  $text = utf8_decode($text);
  return $text;
}


$db = dbconnect();
$query = "SELECT vid
            FROM imt_sitzungen_vorschlag
           WHERE isid = '$isid'";

$result = $db->query ($query)
   or die ("Cannot execute query1");
   

$seite = 1;
while ($row = $result->fetch_array())
{
if($seite != 1){
  $pdf->AddPage();
  $pdf->SetAutoPageBreak(true,20); 
  $seite =$seite+1;
    $pdf->SetY(20);
}else{
  $seite =$seite+1;
  $pdf->SetY(60.8);
}



# Idee Block

$pdf->SetFont('Arial', 'BU', 12);
#$pdf->SetTextColor(255,0,0);
$pdf->MultiCell(160, 5,"IDEE ID: $row[vid]", 0, 'L');


$columns = 2; //two columns


$pos=$pdf->GetY()+4;


 $pdf->SetY($pos);
 
	//we initialize the table class
	$pdf->Table_Init($columns, true, true);

	$table_subtype = $table_default_table_type;
	$pdf->Set_Table_Type($table_subtype);
	
	//TABLE HEADER SETTINGS
	$header_subtype = $table_default_header_type;
        for($i=0; $i<$columns; $i++) $header_type[$i] = $table_default_header_type;

	$header_type[0]['WIDTH'] = 35.3;
	$header_type[1]['WIDTH'] = 128.4;

        //set the header type
        $pdf->Set_Header_Type($header_type);

	
#	$pdf->Draw_Header();


	//TABLE DATA SETTINGS
	$data_subtype = $table_default_data_type;
	

	$data_type = Array();//reset the array
	for ($i=0; $i<$columns; $i++) $data_type[$i] = $data_subtype;

	$pdf->Set_Data_Type($data_type);
	
        $result1 = $db->query("SELECT betreff, beschreibung, vorschlag, nutzen, date_format(erfass_dat, '%d.%m.%Y') datum
                                 FROM imt_vorschlag
                                WHERE vid = '$row[vid]'");
        $row1 = $result1->fetch_array();
  

        $betreff = linebreak(html_entity_decode($row1['betreff']));
        $beschreibung = linebreak(html_entity_decode($row1['beschreibung']));
        $vorschlag = linebreak(html_entity_decode($row1['vorschlag']));
        $nutzen = linebreak(html_entity_decode($row1['nutzen']));
        $datum = $row1['datum'];
#echo $beschreibung;
#echo "<hr>";
#echo $row1['beschreibung'];
	$data[0]['TEXT'] = "Betreff";
	$data[0]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$data[0]['V_ALIGN'] = "T"; //T=TOP, M=MIDDLE, B=BOTTOM
 	$data[0]['BG_COLOR'] = array(255,255,255);
 	$data[0]['T_TYPE'] = "B"; // B=BOLD, I=ITALIC
	
	$data[1]['TEXT'] = "$betreff";
	$data[1]['T_ALIGN'] = "L";
	$data[1]['V_ALIGN'] = "T";
	$data[1]['BG_COLOR'] = array(255,255,255);
			
        $pdf->Draw_Data($data);
	
	$data[0]['TEXT'] = "Eingangsdatum";
	$data[0]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$data[0]['V_ALIGN'] = "T"; //T=TOP, M=MIDDLE, B=BOTTOM
 	$data[0]['BG_COLOR'] = array(255,255,255);
 	$data[0]['T_TYPE'] = ""; // B=BOLD, I=ITALIC
	
	$data[1]['TEXT'] = "$datum";
	$data[1]['T_ALIGN'] = "L";
	$data[1]['V_ALIGN'] = "T";
	$data[1]['BG_COLOR'] = array(255,255,255);
			
        $pdf->Draw_Data($data);
        
	$data[0]['TEXT'] = "Situations- beschreibung";
	$data[0]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$data[0]['V_ALIGN'] = "T"; //T=TOP, M=MIDDLE, B=BOTTOM
 	$data[0]['BG_COLOR'] = array(255,255,255);
 	$data[0]['T_TYPE'] = ""; // B=BOLD, I=ITALIC
	
	$data[1]['TEXT'] = "$beschreibung";
	$data[1]['T_ALIGN'] = "L";
	$data[1]['V_ALIGN'] = "T";
	$data[1]['BG_COLOR'] = array(255,255,255);
			
        $pdf->Draw_Data($data);
			
	$data[0]['TEXT'] = "Verbesserungs- vorschlag und konkreter Umsetzungsplan";
	$data[0]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$data[0]['V_ALIGN'] = "T"; //T=TOP, M=MIDDLE, B=BOTTOM
 	$data[0]['BG_COLOR'] = array(255,255,255);
 	$data[0]['T_TYPE'] = ""; // B=BOLD, I=ITALIC
	
	$data[1]['TEXT'] = "$vorschlag";
	$data[1]['T_ALIGN'] = "L";
	$data[1]['V_ALIGN'] = "T";
	$data[1]['BG_COLOR'] = array(255,255,255);
			
        $pdf->Draw_Data($data);
			

	$data[0]['TEXT'] = "Nutzen des Verbesserungs- vorschlags";
	$data[0]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$data[0]['V_ALIGN'] = "T"; //T=TOP, M=MIDDLE, B=BOTTOM
 	$data[0]['BG_COLOR'] = array(255,255,255);
 	$data[0]['T_TYPE'] = ""; // B=BOLD, I=ITALIC
	
	$data[1]['TEXT'] = "$nutzen";
	$data[1]['T_ALIGN'] = "L";
	$data[1]['V_ALIGN'] = "T";
	$data[1]['BG_COLOR'] = array(255,255,255);
			
        $pdf->Draw_Data($data);
			
	//output the table data to the pdf
	#$pdf->tbOuputData();
	
	//draw the Table Border
	#$pdf->tbDrawBorder();	



	




# Gutachter Block
  $query_gut = "SELECT vorname, nachname, date_format(stellung_dat, '%d.%m.%Y') datum, zweck, umsetzung, nutzen, kosteneinsparung, arbeitszeiteinsparung, ideeneu, empfehlung
                  FROM imt_gutachter a, imt_user b
                 WHERE a.imtuid=b.imtuid
                   AND vid = '$row[vid]'
                   AND stellung_dat != '0000-00-00 00:00:00'";
                   
  $result_gut = $db->query ($query_gut)
     or die ("Cannot execute query Gutachter");
   
	
  $gutachter = 1;
  
  while ($row_gut = $result_gut->fetch_array()){

        $zweck = linebreak(html_entity_decode($row_gut['zweck']));
        $umsetzung = linebreak(html_entity_decode($row_gut['umsetzung']));
        $nutzen = linebreak(html_entity_decode($row_gut['nutzen']));
        $kosteneinsparung = linebreak(html_entity_decode($row_gut['kosteneinsparung']));
        $arbeitszeiteinsparung = linebreak(html_entity_decode($row_gut['arbeitszeiteinsparung']));
        $ideeneu = linebreak(html_entity_decode($row_gut['ideeneu']));
        $empfehlung = linebreak(html_entity_decode($row_gut['empfehlung']));
        $datum = $row1['datum'];

        $pos=$pdf->GetY()+4;
        $pdf->SetY($pos);
        $pdf->SetFont('Arial', 'BU', 12);
        #$pdf->SetTextColor(255,0,0);
        $pdf->MultiCell(160, 5,"Gutachter $gutachter", 0, 'L');
        $gutachter = $gutachter +1;
 
        $columns = 2; //two columns
       
 
        $pos=$pdf->GetY()+4;
        
        
        $pdf->SetY($pos);

	//we initialize the table class
	$pdf->Table_Init($columns, true, true);

	$table_subtype = $table_default_table_type;
	$pdf->Set_Table_Type($table_subtype);
	
	//TABLE HEADER SETTINGS
	$header_subtype = $table_default_header_type;
        for($i=0; $i<$columns; $i++) $header_type[$i] = $table_default_header_type;

	$header_type[0]['WIDTH'] = 35.3;
	$header_type[1]['WIDTH'] = 128.4;

	//set the header type
	$pdf->Set_Header_Type($header_type);
	
#	$pdf->Draw_Header();


	//TABLE DATA SETTINGS
	$data_subtype = $table_default_data_type;
	
	$data_type = Array();//reset the array
	for ($i=0; $i<$columns; $i++) $data_type[$i] = $data_subtype;

	$pdf->Set_Data_Type($data_type);
	


	$data[0]['TEXT'] = "Gutachter";
	$data[0]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$data[0]['V_ALIGN'] = "T"; //T=TOP, M=MIDDLE, B=BOTTOM
 	$data[0]['BG_COLOR'] = array(255,255,255);
 	#$data[0]['T_TYPE'] = "B"; // B=BOLD, I=ITALIC
	
	$data[1]['TEXT'] = "$row_gut[vorname] $row_gut[nachname]";
	$data[1]['T_ALIGN'] = "L";
	$data[1]['V_ALIGN'] = "T";
	$data[1]['BG_COLOR'] = array(255,255,255);
			
        $pdf->Draw_Data($data);

	$data[0]['TEXT'] = "Datum Gutachten";
	$data[0]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$data[0]['V_ALIGN'] = "T"; //T=TOP, M=MIDDLE, B=BOTTOM
 	$data[0]['BG_COLOR'] = array(255,255,255);
 	$data[0]['T_TYPE'] = ""; // B=BOLD, I=ITALIC
	
	$data[1]['TEXT'] = "$datum";
	$data[1]['T_ALIGN'] = "L";
	$data[0]['V_ALIGN'] = "T";
	$data[1]['BG_COLOR'] = array(255,255,255);
			
        $pdf->Draw_Data($data);
        
	$data[0]['TEXT'] = "Zweck";
	$data[0]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$data[0]['V_ALIGN'] = "T"; //T=TOP, M=MIDDLE, B=BOTTOM
 	$data[0]['BG_COLOR'] = array(255,255,255);
 	$data[0]['T_TYPE'] = ""; // B=BOLD, I=ITALIC
	
	$data[1]['TEXT'] = "$zweck";
	$data[1]['T_ALIGN'] = "L";
	$data[0]['V_ALIGN'] = "T";
	$data[1]['BG_COLOR'] = array(255,255,255);
			
        $pdf->Draw_Data($data);
			
	$data[0]['TEXT'] = "Umsetzung";
	$data[0]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$data[0]['V_ALIGN'] = "T"; //T=TOP, M=MIDDLE, B=BOTTOM
 	$data[0]['BG_COLOR'] = array(255,255,255);
 	$data[0]['T_TYPE'] = ""; // B=BOLD, I=ITALIC
	
	$data[1]['TEXT'] = "$umsetzung";
	$data[1]['T_ALIGN'] = "L";
	$data[0]['V_ALIGN'] = "T";
	$data[1]['BG_COLOR'] = array(255,255,255);
			
        $pdf->Draw_Data($data);
			

	$data[0]['TEXT'] = "Nutzen";
	$data[0]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$data[0]['V_ALIGN'] = "T"; //T=TOP, M=MIDDLE, B=BOTTOM
 	$data[0]['BG_COLOR'] = array(255,255,255);
 	$data[0]['T_TYPE'] = ""; // B=BOLD, I=ITALIC
	
	$data[1]['TEXT'] = "$nutzen";
	$data[1]['T_ALIGN'] = "L";
	$data[0]['V_ALIGN'] = "T";
	$data[1]['BG_COLOR'] = array(255,255,255);
			
        $pdf->Draw_Data($data);


	$data[0]['TEXT'] = "Kosteneinsparung";
	$data[0]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$data[0]['V_ALIGN'] = "T"; //T=TOP, M=MIDDLE, B=BOTTOM
 	$data[0]['BG_COLOR'] = array(255,255,255);
 	$data[0]['T_TYPE'] = ""; // B=BOLD, I=ITALIC
	
	$data[1]['TEXT'] = "$kosteneinsparung";
	$data[1]['T_ALIGN'] = "L";
	$data[0]['V_ALIGN'] = "T";
	$data[1]['BG_COLOR'] = array(255,255,255);
			
        $pdf->Draw_Data($data);
			

	$data[0]['TEXT'] = "Einsparung der Arbeitszeit";
	$data[0]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$data[0]['V_ALIGN'] = "T"; //T=TOP, M=MIDDLE, B=BOTTOM
 	$data[0]['BG_COLOR'] = array(255,255,255);
 	$data[0]['T_TYPE'] = ""; // B=BOLD, I=ITALIC
	
	$data[1]['TEXT'] = "$arbeitszeiteinsparung";
	$data[1]['T_ALIGN'] = "L";
	$data[0]['V_ALIGN'] = "T";
	$data[1]['BG_COLOR'] = array(255,255,255);
			
        $pdf->Draw_Data($data);

	$data[0]['TEXT'] = "Innovation";
	$data[0]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$data[0]['V_ALIGN'] = "T"; //T=TOP, M=MIDDLE, B=BOTTOM
 	$data[0]['BG_COLOR'] = array(255,255,255);
 	$data[0]['T_TYPE'] = ""; // B=BOLD, I=ITALIC
	
	$data[1]['TEXT'] = "$ideeneu";
	$data[1]['T_ALIGN'] = "L";
	$data[0]['V_ALIGN'] = "T";
	$data[1]['BG_COLOR'] = array(255,255,255);
			
        $pdf->Draw_Data($data);


	$data[0]['TEXT'] = "Empfehlung";
	$data[0]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$data[0]['V_ALIGN'] = "T"; //T=TOP, M=MIDDLE, B=BOTTOM
 	$data[0]['BG_COLOR'] = array(255,255,255);
 	$data[0]['T_TYPE'] = ""; // B=BOLD, I=ITALIC
	
	$data[1]['TEXT'] = "$empfehlung";
	$data[1]['T_ALIGN'] = "L";
	$data[0]['V_ALIGN'] = "T";
	$data[1]['BG_COLOR'] = array(255,255,255);
			
        $pdf->Draw_Data($data);
	
	
	//output the table data to the pdf
	#$pdf->tbOuputData();
	
	//draw the Table Border
	#$pdf->tbDrawBorder();
  } // Ende While Gutachterblock
  
	
	
	
	

  
  
# Beteiligten Block
  $query_bet = "SELECT vorname, nachname, date_format(stellung_dat, '%d.%m.%Y') datum, zweck, umsetzung, nutzen, kosteneinsparung, arbeitszeiteinsparung, ideeneu, empfehlung
                  FROM imt_beteiligte a, imt_user b
                 WHERE a.imtuid=b.imtuid
                   AND vid = '$row[vid]'
                   AND stellung_dat != '0000-00-00 00:00:00'";

                   
  $result_bet = $db->query ($query_bet)
     or die ("Cannot execute query Stellungnahme");
   

  $beteiligte = 1;
  
  while ($row_bet = $result_bet->fetch_array()){
        
        $zweck = linebreak(html_entity_decode($row_bet['zweck']));
        $umsetzung = linebreak(html_entity_decode($row_bet['umsetzung']));
        $nutzen = linebreak(html_entity_decode($row_bet['nutzen']));
        $kosteneinsparung = linebreak(html_entity_decode($row_bet['kosteneinsparung']));
        $arbeitszeiteinsparung = linebreak(html_entity_decode($row_bet['arbeitszeiteinsparung']));
        $ideeneu = linebreak(html_entity_decode($row_bet['ideeneu']));
        $empfehlung = linebreak(html_entity_decode($row_bet['empfehlung']));
        
        $datum = $row1['datum'];

        $pos=$pdf->GetY()+4;
        $pdf->SetY($pos);
        $pdf->SetFont('Arial', 'BU', 12);
        #$pdf->SetTextColor(255,0,0);
        $pdf->MultiCell(160, 5,"Stellungnahme Beteiligter $beteiligte", 0, 'L');
        $beteiligte = $beteiligte +1;

        $columns = 2; //two columns
        
        
        $pos=$pdf->GetY()+4;
        
        
        $pdf->SetY($pos);

	//we initialize the table class
	$pdf->Table_Init($columns, true, true);

	$table_subtype = $table_default_table_type;
	$pdf->Set_Table_Type($table_subtype);
	
	//TABLE HEADER SETTINGS
	$header_subtype = $table_default_header_type;
        for($i=0; $i<$columns; $i++) $header_type[$i] = $table_default_header_type;

	$header_type[0]['WIDTH'] = 35.3;
	$header_type[1]['WIDTH'] = 128.4;

	//set the header type
	$pdf->Set_Header_Type($header_type);

	

	//TABLE DATA SETTINGS
	$data_subtype = $table_default_data_type;
	
	$data_type = Array();//reset the array
	for ($i=0; $i<$columns; $i++) $data_type[$i] = $data_subtype;

	$pdf->Set_Data_Type($data_type);
	


	$data[0]['TEXT'] = "Beteiligter";
	$data[0]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$data[0]['V_ALIGN'] = "T"; //T=TOP, M=MIDDLE, B=BOTTOM
 	$data[0]['BG_COLOR'] = array(255,255,255);
 	$data[0]['T_TYPE'] = "B"; // B=BOLD, I=ITALIC
	
	$data[1]['TEXT'] = "$row_bet[vorname] $row_bet[nachname]";
	$data[1]['T_ALIGN'] = "L";
	$data[1]['V_ALIGN'] = "T";
	$data[1]['BG_COLOR'] = array(255,255,255);
			
        $pdf->Draw_Data($data);

	$data[0]['TEXT'] = "Datum Stellungnahme";
	$data[0]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$data[0]['V_ALIGN'] = "T"; //T=TOP, M=MIDDLE, B=BOTTOM
 	$data[0]['BG_COLOR'] = array(255,255,255);
 	$data[0]['T_TYPE'] = ""; // B=BOLD, I=ITALIC
	
	$data[1]['TEXT'] = "$datum";
	$data[1]['T_ALIGN'] = "L";
	$data[0]['V_ALIGN'] = "T";
	$data[1]['BG_COLOR'] = array(255,255,255);
			
        $pdf->Draw_Data($data);
        
	$data[0]['TEXT'] = "Stellungnahme";
	$data[0]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$data[0]['V_ALIGN'] = "T"; //T=TOP, M=MIDDLE, B=BOTTOM
 	$data[0]['BG_COLOR'] = array(255,255,255);
 	$data[0]['T_TYPE'] = ""; // B=BOLD, I=ITALIC
	
	$data[1]['TEXT'] = "Zweck:\n$zweck\n\nUmsetzung:\n$umsetzung\n\nNutzen:\n$nutzen\n\nKosteneinsparung:\n$kosteneinsparung\n\nEinsparung der Zeit:\n$arbeitszeiteinsparung\n\nInnovation:\n$ideeneu\n\nEmpfehlung:\n$empfehlung";
	$data[1]['T_ALIGN'] = "L";
	$data[0]['V_ALIGN'] = "T";
	$data[1]['BG_COLOR'] = array(255,255,255);
			
        $pdf->Draw_Data($data);
			
	//output the table data to the pdf
	#$pdf->tbOuputData();
	
	//draw the Table Border
	#$pdf->tbDrawBorder();
	
  } // Ende While Beteiligtenblock
  


  
  
  
  



# Bewertungsvorschlag Block
 
        $pos=$pdf->GetY()+4;
        
        if($pos >=260){
          # Neue Seite, wenn nur das Wort Statusdetails auf der vorherigen Seite stehen würde
          $pdf->AddPage();
          $pdf->SetY(20);
          $pos=$pdf->GetY();
        }
        $pdf->SetY($pos);
        $pdf->SetFont('Arial', 'BU', 12);
        #$pdf->SetTextColor(255,0,0);
        $pdf->MultiCell(160, 5,"Vorschlag Bewertung durch den Ausschuss", 0, 'L');
        $beteiligte = $beteiligte +1;

        $columns = 2; //two columns
        
        
        $pos=$pdf->GetY()+4;
        
        
        $pdf->SetY($pos);

	//we initialize the table class
	$pdf->Table_Init($columns, true, true);

	$table_subtype = $table_default_table_type;
	$pdf->Set_Table_Type($table_subtype);
	
	//TABLE HEADER SETTINGS
	$header_subtype = $table_default_header_type;
        for($i=0; $i<$columns; $i++) $header_type[$i] = $table_default_header_type;

	$header_type[0]['WIDTH'] = 35.3;
	
	$header_type[1]['WIDTH'] = 128.4;
	
	

	//set the header type
	$pdf->Set_Header_Type($header_type);
	
# 	$pdf->Draw_Header();
	
 $query4 = "SELECT annahme, date_format(datum, '%d.%m.%Y') datumform, ziel, begruendung, umsetzung, praemierung
              FROM imt_bew_vorschlag
             WHERE vid='$row[vid]'";
 
 $result4 = $db->query ($query4)
           or die ("Cannot execute query3");
 
 $row4 = $result4->fetch_array();
 	if($row4['annahme'] == 'J'){
 	  $annahme = "Annahme der Idee";
 	}else{
 	  $annahme = "Ablehnung";
	}
	$ziel = "";
    if(preg_match("/1/",$row4[ziel])){
      $ziel .= "Erhöhung der Wirtschaftlichkeit\n";
    }
    
    if(preg_match("/2/",$row4[ziel])){
     $ziel .= "Stärkung der Serviceorientierung\n";
    }
    
    if(preg_match("/3/",$row4[ziel])){
     $ziel .= "Verbesserung der allgemeinen Arbeits- und Lernbedingungen\n";
    }
    
    if(preg_match("/4/",$row4[ziel])){
     $ziel .= "Förderung der Arbeitssicherheit und des Arbeitsschutzes\n";
    }
    
    if(preg_match("/5/",$row4[ziel])){
     $ziel .= "Diese Idee trägt nicht zur Erreichung eines der definierten Ziele des Ideenmanagements bei";
    }
    
/*	
 $pdf->WriteHTML("
 <table width=\"100%\">
 <tr>
   <td>
     Datum
   </td>
   <td>
     $row4[datumform]
   </td>
</tr>

 <tr>
   <td>
     Annahme
   </td>
   <td>
     $annahme
   </td>
</tr>

 <tr>
   <td>
     Begründung
   </td>
   <td>
     $row4[begruendung]
   </td>
</tr>
</table>
");
 

 */
 
 $begruendung = linebreak(html_entity_decode($row4['begruendung']));
 $umsetzung = linebreak(html_entity_decode($row4['umsetzung']));
 $praemierung = linebreak(html_entity_decode($row4['praemierung']));

	//TABLE DATA SETTINGS
	$data_subtype = $table_default_data_type;
	
	$data_type = Array();//reset the array
	for ($i=0; $i<$columns; $i++) $data_type[$i] = $data_subtype;

	$pdf->Set_Data_Type($data_type);


	$data[0]['TEXT'] = "Datum:";
	$data[0]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$data[0]['V_ALIGN'] = "T"; //T=TOP, M=MIDDLE, B=BOTTOM
 	$data[0]['BG_COLOR'] = array(255,255,255);
 	$data[0]['T_TYPE'] = ""; // B=BOLD, I=ITALIC
	
	$data[1]['TEXT'] = "$row4[datumform]";
	$data[1]['T_ALIGN'] = "L";
	$data[1]['V_ALIGN'] = "T";
	$data[1]['BG_COLOR'] = array(255,255,255);
			
        $pdf->Draw_Data($data);
        
	$data[0]['TEXT'] = "Annahme:";
	$data[0]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$data[0]['V_ALIGN'] = "T"; //T=TOP, M=MIDDLE, B=BOTTOM
 	$data[0]['BG_COLOR'] = array(255,255,255);
 	$data[0]['T_TYPE'] = ""; // B=BOLD, I=ITALIC
	
	if($row4['annahme'] == 'J'){
	  $annahme = "Annahme der Idee";
	}else{
	  $annahme = "Ablehnung";
	}
	
	$data[1]['TEXT'] = "$annahme";
	$data[1]['T_ALIGN'] = "L";
	$data[1]['V_ALIGN'] = "T";
	$data[1]['BG_COLOR'] = array(255,255,255);
			
        $pdf->Draw_Data($data);
        
	$data[0]['TEXT'] = "Ziel:";
	$data[0]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$data[0]['V_ALIGN'] = "T"; //T=TOP, M=MIDDLE, B=BOTTOM
 	$data[0]['BG_COLOR'] = array(255,255,255);
 	$data[0]['T_TYPE'] = ""; // B=BOLD, I=ITALIC
	
	$data[1]['TEXT'] = "$ziel";
	$data[1]['T_ALIGN'] = "L";
	$data[1]['V_ALIGN'] = "T";
	$data[1]['BG_COLOR'] = array(255,255,255);
			
        $pdf->Draw_Data($data);
        
	$data[0]['TEXT'] = "Begründung:";
	$data[0]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$data[0]['V_ALIGN'] = "T"; //T=TOP, M=MIDDLE, B=BOTTOM
 	$data[0]['BG_COLOR'] = array(255,255,255);
 	$data[0]['T_TYPE'] = ""; // B=BOLD, I=ITALIC
	
	$data[1]['TEXT'] = "$begruendung";
	$data[1]['T_ALIGN'] = "L";
	$data[1]['V_ALIGN'] = "T";
	$data[1]['BG_COLOR'] = array(255,255,255);
			
        $pdf->Draw_Data($data);
        
	$data[0]['TEXT'] = "Umsetzung:";
	$data[0]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$data[0]['V_ALIGN'] = "T"; //T=TOP, M=MIDDLE, B=BOTTOM
 	$data[0]['BG_COLOR'] = array(255,255,255);
 	$data[0]['T_TYPE'] = ""; // B=BOLD, I=ITALIC
	
	$data[1]['TEXT'] = "$umsetzung";
	$data[1]['T_ALIGN'] = "L";
	$data[1]['V_ALIGN'] = "T";
	$data[1]['BG_COLOR'] = array(255,255,255);
			
        $pdf->Draw_Data($data);
        
	$data[0]['TEXT'] = "Prämierung:";
	$data[0]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$data[0]['V_ALIGN'] = "T"; //T=TOP, M=MIDDLE, B=BOTTOM
 	$data[0]['BG_COLOR'] = array(255,255,255);
 	$data[0]['T_TYPE'] = ""; // B=BOLD, I=ITALIC
	
	$data[1]['TEXT'] = "$praemierung";
	$data[1]['T_ALIGN'] = "L";
	$data[1]['V_ALIGN'] = "T";
	$data[1]['BG_COLOR'] = array(255,255,255);
			
        $pdf->Draw_Data($data);
			

	//output the table data to the pdf
	#$pdf->tbOuputData();
	
	//draw the Table Border
	#$pdf->tbDrawBorder();


# Statusdetails Block
 
        $pos=$pdf->GetY()+4;
        
        if($pos >=260){
          # Neue Seite, wenn nur das Wort Statusdetails auf der vorherigen Seite stehen würde
          $pdf->AddPage();
          $pdf->SetY(20);
          $pos=$pdf->GetY();
        }
        $pdf->SetY($pos);
        $pdf->SetFont('Arial', 'BU', 12);
        #$pdf->SetTextColor(255,0,0);
        $pdf->MultiCell(160, 5,"Statusdetails", 0, 'L');
        $beteiligte = $beteiligte +1;

        $columns = 2; //two columns
        
        
        $pos=$pdf->GetY()+4;
        
        
        $pdf->SetY($pos);

	//we initialize the table class
	$pdf->Table_Init($columns, true, true);

	$table_subtype = $table_default_table_type;
	$pdf->Set_Table_Type($table_subtype);
	
	//TABLE HEADER SETTINGS
	$header_subtype = $table_default_header_type;
        for($i=0; $i<$columns; $i++) $header_type[$i] = $table_default_header_type;


	$header_type[0]['WIDTH'] = 35.3;
	#$header_type[0]['BG_COLOR'] = array(255,0,0);
	$header_type[0]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$header_type[0]['V_ALIGN'] = "M"; //T=TOP, M=MIDDLE, B=BOTTOM
	$header_type[0]['TEXT'] = "Datum";

	
	
	$header_type[1]['WIDTH'] = 128.4;
	#$header_type[1]['BG_COLOR'] = array(0,0,0);
	$header_type[1]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$header_type[1]['V_ALIGN'] = "M"; //T=TOP, M=MIDDLE, B=BOTTOM
	$header_type[1]['TEXT'] = "Status";
	
	

	//set the header type
	$pdf->Set_Header_Type($header_type);
	
 	$pdf->Draw_Header();
	
 $query3 = "SELECT date_format(datum, '%d.%m.%Y (%H:%i)') datum1,b.sid, b.status, verlauf
              FROM imt_verlauf a, imt_stati b
             WHERE a.status = b.sid
               AND a.status != 0
               AND a.vid='$row[vid]'
            ORDER BY datum ASC";
 
 $result3 = $db->query ($query3)
           or die ("Cannot execute query3");
 
 $table_data3 = array();
 $verlauf_dup = array("");
 while ($row3 = $result3->fetch_array()){
  $status = linebreak(html_entity_decode($row3['status']));

  if($row3['sid'] == '103'){
    # Da jedes Ausschussmitglied informiert wird, reicht es aus, wenn bei den Statusdetails nur ein Hinweis pro Gutachter genannt wird, nicht 5x pro Person
    # Bei der Meldung "Ausschuss (Bernd Fuchsi) &uuml;ber Gutachter Wolf Wursti informiert. Frist: 25.06.2011" wird der Gutachter "Wolf Wursti" 
    # ausgeschnitten und in ein Array gepackt. Wird der gleiche Gutachter mit dem Status 103 nochamls durchgeschleift, wird in den else Bereich verwiesen
    # Im Template werden nur die Statis angezeigt die != "" sind
    $pos1 = strpos  ($row3['verlauf'], 'Gutachter')+9;
    $status_103 = trim(substr($row3['verlauf'], $pos1));
    $pos2 = strpos  ($status_103, 'informiert')-1;
    $status = trim(substr($status_103, 0,$pos2));

    if (!in_array($status, $verlauf_dup)) {
      $verlauf_dup[] = "$status";
      $status = linebreak(html_entity_decode($row3['status']));
    }else{
      $status = "";
    }
  
  }
  
  if($status != ""){

	//TABLE DATA SETTINGS
	$data_subtype = $table_default_data_type;
	
	$data_type = Array();//reset the array
	for ($i=0; $i<$columns; $i++) $data_type[$i] = $data_subtype;

	$pdf->Set_Data_Type($data_type);


	$data[0]['TEXT'] = "$row3[datum1]";
	$data[0]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$data[0]['V_ALIGN'] = "T"; //T=TOP, M=MIDDLE, B=BOTTOM
 	$data[0]['BG_COLOR'] = array(255,255,255);
 	$data[0]['T_TYPE'] = ""; // B=BOLD, I=ITALIC
	
	$data[1]['TEXT'] = "$status";
	$data[1]['T_ALIGN'] = "L";
	$data[1]['V_ALIGN'] = "T";
	$data[1]['BG_COLOR'] = array(255,255,255);
			
        $pdf->Draw_Data($data);
			
  }			
} // Ende While Statusdetails


	//output the table data to the pdf
	#$pdf->tbOuputData();
	
	//draw the Table Border
	#$pdf->tbDrawBorder();	

}


$pdf->Output("Sitzung.pdf","$output");
$pdf->closeParsers();


?> 
