<?php

/* Testfälle
 *
 * für Zeitschriftenartikel
 * $typeArray =  [
       		[ 'fieldId' => 'zeitschriftenartikel', 'fieldValue' => 'Zeitschriftenartikel',  'fieldType' => 'input',  'inputType' => 'radio', 'isSelected' => 1] , 
		[ 'fieldId' => 'review_mongraph_select1', 'fieldValue' => 'Nein', 'fieldType' => 'select', 'inputType' => 'text', 'isSelected' => 1 ] , 
		[ 'fieldId' => 'revieweditedvolume1', 'fieldValue' => 'Nein', 'fieldType' => 'select', 'inputType' => 'text', 'isSelected' => 1 ] , 
		[ 'fieldId' => 'publishedinjournalinput1', 'fieldValue' => 'ZS', 'fieldType' => 'input', 'inputType' => 'text', 'isSelected' => 1 ] , 
		[ 'fieldId' => 'publishedinvolumeinput1', 'fieldValue' => 'JG', 'fieldType' => 'input', 'inputType' => 'text', 'isSelected' => 1 ] , 
		[ 'fieldId' => 'publishedinissueinput1', 'fieldValue' => 'Heft', 'fieldType' => 'input', 'inputType' => 'text', 'isSelected' => 1 ],  
		[ 'fieldId' => 'publishedinyearinput1', 'fieldValue' => '2020', 'fieldType' => 'input', 'inputType' => 'text', 'isSelected' => 1 ], 
		[ 'fieldId' => 'pagesfromarticleinput1', 'fieldValue' => '1', 'fieldType' => 'input', 'inputType' => 'text',  'isSelected' => 1 ], 
		[ 'fieldId' => 'pagestoarticleinput1',  'fieldValue' => '2', 'fieldType' => 'input', 'inputType' => 'text', 'isSelected' => 1 ], 
		[ 'fieldId' => 'review_article_select1', 'fieldValue' => 'Nein', 'fieldType' => 'select', 'inputType' => 'text', 'isSelected' => 1 ], 
		[ 'fieldId' => 'review_conference_select1', 'fieldValue' => 'Nein', 'fieldType' => 'select', 'inputType' => 'text', 'isSelected' => 1 ], 
		[ 'fieldId' => 'qualificationtype_select1', 'fieldValue' => 'Habilitation', 'fieldType' => 'select', 'inputType' => 'text', 'isSelected' => 1 ] 
]; 
 */ 

// Für Monografien

/*$typeArray =  [
	[ 'fieldId' => 'monografie', 'fieldValue' => 'Monografie',  'fieldType' => 'input',  'inputType' => 'radio', 'isSelected' => 1] ,
	[ 'fieldId' => 'publishedinmonographinput1', 'fieldValue' => 'Reihe', 'fieldType' => 'textarea', 'inputType' => 'text', 'isSelected' => 1 ], 
	[ 'fieldId' => 'publisherinmonographinput1', 'fieldValue' => 'Verlag', 'fieldType' => 'textarea', 'inputType' => 'text', 'isSelected' => 1 ], 
	[ 'fieldId' => 'publisherplaceinmonographinput1', 'fieldValue' => 'Verlagsort', 'fieldType' => 'textarea', 'inputType' => 'text', 'isSelected' => 1 ], 
	[ 'fieldId' => 'pagesmonographinput1', 'fieldValue' => '128 S.', 'fieldType' => 'input', 'inputType' => 'text', 'isSelected' => 1 ], 
	[ 'fieldId' => 'review_mongraph_select1', 'fieldValue' => 'Nein', 'fieldType' => 'select', 'inputType' => 'text', 'isSelected' => 1 ], 
	[ 'fieldId' => 'revieweditedvolume1', 'fieldValue' => 'Nein', 'fieldType' => 'select', 'inputType' => 'text', 'isSelected' => 1 ], 
	[ 'fieldId' => 'review_article_select1', 'fieldValue' => 'Nein', 'fieldType' => 'select', 'inputType' => 'text', 'isSelected' => 1 ], 
	[ 'fieldId' => 'review_conference_select1', 'fieldValue' => 'Nein', 'fieldType' => 'select', 'inputType' => 'text', 'isSelected' => 1 ], 
	[ 'fieldId' => 'qualificationtype_select1', 'fieldValue' => 'Habilitation', 'fieldType' => 'select', 'inputType' => 'text', 'isSelected' => 1 ]
	]; 
/*
foreach($typeArray as $entry)  {
	echo $entry['fieldId'] ."\n"; 
}
exit;
*/

// print_r($typeArray) ; exit; 


$typeDataHTML = '<div class="container mt-4">
			      <h4>Dokumenttyp und andere Daten</h4>
                              <table class="table table-striped table-bordered" >
                                  <thead style="background-color:#14416b;">
                                      <tr>
                                          <th style="width: 20%;"><h5>Feldbezeichnung</h5></th>
                                          <th style="width: 80%;"><h5>Inhalt</h5></th>
                                      </tr>
                                 </thead>
                                 <tbody>
		';

// im ersten Array steht die Auswahl 
switch ($typeArray[0]['fieldValue'])   {
	case "Zeitschriftenartikel"	: $typeDataHTML = prepareArticle($typeDataHTML, $typeArray);  break;
	case "Sammelbandbeitrag" 	: $typeDataHTML = prepareEditedVolume($typeDataHTML, $typeArray); break;
	case "Monografie"		: $typeDataHTML = prepareMonograph($typeDataHTML, $typeArray); break;
	case "Qualifikationsarbeit"	: $typeDataHTML = prepareQualified($typeDataHTML, $typeArray); break;
	// default: $typeDataHTML .= "ERROR"; 
}

$typeDataHTML .= '      </tbody>
                             </table>
                           </div>';


function prepareArticle($typeDataHTML, $typeArray)  {

	$resArray = []; 
	foreach($typeArray as $entry)  {
		$resArray[$entry['fieldId']] = $entry['fieldValue']; 
	}

	$labelArray = [	'zeitschriftenartikel' => 'Dokumenttyp',
			'publishedinjournalinput1' => 'Titel der Zeitschrift',
			'publishedinvolumeinput1' => 'Jahrgang',
			'publishedinissueinput1' => 'Heft',
			'publishedinyearinput1' => 'Jahr',
			'pagesfromarticleinput1' => 'Seite von',
			'pagestoarticleinput1' => 'Seite bis',
			'review_article_select1' => 'Begutachtet'
	]; 

	foreach ($labelArray as $key => $label)  {
		$typeDataHTML .= '   <tr>
                                         <td>' .$label .'</td>
                                         <td> ' .$resArray[$key] .'</td>
                                     </tr>';
	}

	return $typeDataHTML;  

}

function prepareEditedVolume($typeDataHTML, $typeArray)  {

        $resArray = [];
        foreach($typeArray as $entry)  {
                $resArray[$entry['fieldId']] = $entry['fieldValue'];
        }

        $labelArray = [ 'sammelbandbeitrag' => 'Dokumenttyp',
                        'publishedineditedvolumeinput1' => 'Titel des Sammelbands',
			'publisherineditedvolumeinput1' => 'Herausgebende',
                        'pagesfromeditedvolumeinput1' => 'Seite von',
                        'pagestoeditedvolumeinput1' => 'Seite bis',
                        'revieweditedvolume1' => 'Begutachtet',
			'conferencenameineditedvolumeinput1' => 'Titel der Konferenz',
			'conferenceineditedvolumedetail1' => 'Details zur Konferenz'
        ];

        foreach ($labelArray as $key => $label)  {
		if (strlen(trim($resArray[$key])) > 0)  {
                	$typeDataHTML .= '   <tr>
                                         <td>' .$label .'</td>
                                         <td> ' .$resArray[$key] .'</td>
                                     </tr>';
		}
        }

        return $typeDataHTML;

}

function prepareMonograph($typeDataHTML, $typeArray)  {

        $resArray = [];
        foreach($typeArray as $entry)  {
                $resArray[$entry['fieldId']] = $entry['fieldValue'];
        }

        $labelArray = [ 'monografie' => 'Dokumenttyp',
                        'publishedinmonographinput1' => 'Titel der Reihe',
                        'publisherinmonographinput1' => 'Verlag',
                        'publisherplaceinmonographinput1' => 'Verlagsort',
                        'pagesmonographinput1' => 'Seitenangabe',
                        'review_mongraph_select1' => 'Begutachtet'
        ];

        foreach ($labelArray as $key => $label)  {
                if (strlen(trim($resArray[$key])) > 0)  {
                        $typeDataHTML .= '   <tr>
                                         <td>' .$label .'</td>
                                         <td> ' .$resArray[$key] .'</td>
                                     </tr>';
                }
        }

        return $typeDataHTML;

}

function prepareQualified($typeDataHTML, $typeArray)  {

        $resArray = [];
        foreach($typeArray as $entry)  {
                $resArray[$entry['fieldId']] = $entry['fieldValue'];
        }

        $labelArray = [ 'qualifikationssarbeit'	 	=> 'Dokumenttyp',
			'qualificationtype_select1'	=> 'Art der Qualifikationsarbeit',
                        'qualifiedinstitutioninput1' 	=> 'Titelverleihende Institution',
                        'qualifiedyearinput1' 		=> 'Prüfungsjahr'
        ];

        foreach ($labelArray as $key => $label)  {
                if (strlen(trim($resArray[$key])) > 0)  {
                        $typeDataHTML .= '   <tr>
                                         <td>' .$label .'</td>
                                         <td> ' .$resArray[$key] .'</td>
                                     </tr>';
                }
        }

        return $typeDataHTML;

}

?>
