<?php
use yii\helpers\Html;
use common\controllers\CommonDBInterface as DBInterface;

/* @var $this yii\web\View */
/* @var $user common\models\User */
/* @var $comment  */
/* @var $contactPerson */
/* @var $information */


echo '<link href="'.Yii::$app->request->baseUrl.'/css/jquery.dataTables.css" rel="stylesheet">';
?>

<div class="customer-confirmation">
<!-- <p> -->
 <?php 
// echo Html::encode($user->form_of_address)." ".Html::encode($user->first_name)." ".Html::encode($user->name)."<br/>".Html::encode($user->email)." <br/>".Html::encode($user->institution)."<br/>".Html::encode($user->division)."<br/>".Html::encode($user->street_pobox)." <br/>".Html::encode($user->postal_code)." ".Html::encode($user->location_city)." <br/>".Html::encode($user->state_province)."</p>". Html::encode($user->country)."</p>";
?>
<?php if(sizeof($information)>1){
$samples = 'samples';
}
else{
$samples = 'sample';
}?>

<p>
		<br/>Dear <?= Html::encode($user->first_name)?> <?= Html::encode($user->name) ?> <br/>
		Thank you very much for your request of <strong><?= Html::encode(sizeof($information))?> <?= Html::encode($samples)?></strong>
		from the GGBN Data Portal. Your request is forwarded to the respective institution(s). The provider institution(s) will respond as soon as possible. You requested:<br/>
	</p>

 <?php 

 $curInst = '';
 $first = true;
	foreach ( $information as $info ) {
		$contact = DBInterface::getMail($info['tripleidstoreid'])[0];
		Yii::info("Institutionfullname :" .$contact['institutionFullName']. " vs. ".$curInst);
		if ($contact['institutionFullName'] != $curInst) {
			$curInst = $contact['institutionFullName'];
			if(!$first){
				echo ' </tbody></table><p><br/></p></div>';
			}
			echo ('<div><p>Contact: <strong>'.$curInst.'</strong><br/>'.$contact['name'].'<br/>'.$contact['email'].'<br/>'.$contact['phone'].'</p>');
			echo ' <table style="border: 1px solid black; cellpadding:20px; width:100%; border-collapse: collapse;">
 <thead> 
 <tr>
 <th align="left" style="border: 1px solid black">Species</th>
 <th align="left" style="border: 1px solid black" >Family</th>
 <th align="left" style="border: 1px solid black">Country</th>
<th align="left" style="border: 1px solid black">DNA No.</th>
 <th align="left" style="border: 1px solid black">Tissue No.</th>
 <th align="left" style="border: 1px solid black">Specimen No./CollectionCode</th>
 
 </tr>
 </thead>
 <tbody>';
			echo "<tr >";
			foreach($info as $key => $value){
				if(!empty($value)){
					if($key=='DNA_ID'||$key=='tissue_ID'){
						$ar = explode(";", $value);
						echo '<td style="border: 1px solid black">'.$ar[0].'</td>';
					}
					elseif ($key=='specimen_ID'){
						$ar = explode(";", $value);
						echo '<td style="border: 1px solid black">'.$ar[0].'/'.$ar[1].'</td>';
			
					}
					elseif($key=='tripleidstoreid'||$key=='citesStatus'){
						//nothing happens
					}
					else{
						echo '<td style="border: 1px solid black">'.$value.'</td>';
					}
				}
				else{
					echo '<td style="border: 1px solid black">-----</td>';
				}
			}
			echo "</tr>";
 	}
 	else{
 	echo "<tr >";
 	foreach($info as $key => $value){
 		if(!empty($value)){
 			if($key=='DNA_ID'||$key=='tissue_ID'){
 				$ar = explode(";", $value);
 				echo '<td style="border: 1px solid black">'.$ar[0].'</td>';
 			}
 			elseif ($key=='specimen_ID'){
 				$ar = explode(";", $value);
 				echo '<td style="border: 1px solid black">'.$ar[0].'/'.$ar[1].'</td>';
 					
 			}
 			elseif($key=='tripleidstoreid'|| $key =='citesStatus'){
 				//nothing happens
 			}
 			else{
 				echo '<td style="border: 1px solid black">'.$value.'</td>';
 			}
 		}
 		else{
 			echo '<td style="border: 1px solid black">-----</td>';
 		}
 	}
 echo "</tr>";
 	}
 	$first= false;
 }
 echo ' </tbody></table>';
 	?>
 
 <?php
 if($comment!=''){?>
 	<p><?= Html::encode($user->first_name)?> <?= Html::encode($user->name)?> left the following comment:<br/>
 	<?= Html::encode($comment);?>
 	<?php echo '</p>';
 }
 else{
 	echo "<p><br/></p>";
 }
 ?>
 
 <p>Yours sincerely, <br/> GGBN Data Portal Team </p>
 </div>