<?php
use yii\helpers\Html;

/* @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">';
?>
<style>
 .table{

 }
 
 </style>
 
<div class="institution-confirmation">
<?php 
// echo "<p><strong>".Html::encode($contactPerson['institutionFullName'])."</strong><br/>"
// .Html::encode($contactPerson['name'])."<br/>"
// .Html::encode($contactPerson['email'])."</p>"
// .Html::encode($contactPerson['phone'])."</p>";
?>

<?php if(sizeof($information)>1){
$samples = 'samples';
}
else{
$samples = 'sample';
}?>

<p><br/>Dear <?= Html::encode($contactPerson['name']) ?>, <br/>
The researcher <?= Html::encode($user->first_name)?> <?= Html::encode($user->name) ?> requested <strong><?= Html::encode(sizeof($information))?> <?= Html::encode($samples)?></strong> from your repository.
Please confirm the samples are available and send an e-mail including your MTA and any other applicable information, e.g. fees.<br/></p>
  
 <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>

 <?php
 $cites = false;
  foreach ($information as $info){
 	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'){
 				//nothing happens
 			}
 			elseif($key =='citesStatus'){
 				if($value!="N/A"){
 					$cites=true;
 				}
 			}
 			else{
 				echo '<td style="border: 1px solid black">'.$value.'</td>';
 			}
		}
		else{
			echo '<td style="border: 1px solid black">-----</td>';
		}	
 }
 echo "</tr>";
 }
 	?>

 </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>";
 }
 
 if($cites)
 	echo "<p style='color:red'>This request includes CITES material. Please check carefully whether the researcher is allowed to receive this material.
		</p>"
 ?>
 
 <div class="tab"><strong>ResearcherInformation</strong>
 <table style="cellpadding:20px;">
 <thead>
 <tr>
 <th align="left">Name</th>
 <td> <?= Html::encode($user->form_of_address)?> <?= Html::encode($user->first_name)?> <?= Html::encode($user->name) ?></td>
 </tr>
 <tr>
 <th align="left">Email</th>
 <td> <?= Html::encode($user->email) ?></td>
 </tr>
 <tr>
 <th align="left">CITES code</th>
  <td> <?= Html::encode($user->cites_code)?></td>
 </tr>
 <tr>
 <th align="left">Institution</th>
 <td> <?= Html::encode($user->institution)?></td>
 </tr>
 <tr>
 <th align="left">Division</th>
  <td> <?= Html::encode($user->division)?></td>
 </tr>
 <tr>
 <th align="left">Street</th>
  <td> <?= Html::encode($user->street_pobox) ?></td>
 </tr>
 <tr>
 <th align="left">Postal Code, Location</th>
  <td> <?= Html::encode($user->postal_code)?> <?= Html::encode($user->location_city) ?></td>
 </tr>
 <tr>
 <th align="left">State / Province</th>
  <td> <?= Html::encode($user->state_province)?></td>
 </tr>
 <tr>
 <th align="left">Country</th>
  <td> <?= Html::encode($user->country)?></td>
 </tr>
 </thead>
 <tbody>
 </tbody>
 </table>
</div>
 
 <?php if(isset($user->delivery_institution)){
 	echo "<p><br/></p>";
echo'
 <div class="tab"><strong>Delivery Adress (if different from billing adress)</strong>
 <table style="cellpadding:20px;">
 <thead>
 <tr>
 <th align="left">Institution</th>
 <td>';?>
  <?= Html::encode($user->delivery_institution)?>
  <?php
  echo '</td>
 </tr>
 <tr>
 <th align="left">Division</th>
  <td>';?>
   <?= Html::encode($user->delivery_division)?>
 <?php 
 echo'</td>
 </tr>
 <tr>
 <th align="left">Street</th>
  <td>';?>
   <?= Html::encode($user->delivery_street) ?>
   <?php 
   echo '</td>
 </tr>
 <tr>
 <th align="left">Postal Code, Location</th>
  <td>';?>
   <?= Html::encode($user->delivery_postal_code)?><?= Html::encode($user->delivery_location) ?>
   <?php 
   echo '</td>
 </tr>
		<tr>
 <th align="left">State / Province</th>
  <td>';?>
   <?= Html::encode($user->delivery_state)?>
   <?php 
   echo '</td>
 </tr>
 <tr>
 <th align="left">Country</th>
  <td>';?>
   <?= Html::encode($user->delivery_country)?>
   <?php 
   echo '</td>
 </tr>
 </thead>
 <tbody>
 </tbody>
 </table>
</div>';}?>


<p><br/>Yours sincerely, <br/> GGBN Data Portal Team </p>
 
</div>