<?php
/**
 * Screen setdetail\index
 * @version 1.0.1
 * @package Backend\DataSets
 * 
*/
require_once 'app/class-lov-manager.php';
$detail = $this->data ['item'];
$list = $this->data ['list'];
$listdataindicator = $this->data ['listindicator'];
$bakurl = $this->data ['bakkey'];
$navurl = $this->data ['navkey'];
$listStates = $this->data ['states'];
$idInd= $this->data ['idIndicator'];
$fileok = $this->data['fileok'];

if (isset($idInd)) {
	$lovmanager = new LovManager();
	$aindicator = array_filter(
				$listdataindicator,
				function ($e) use (&$idInd) { return $e->id ==$idInd ; }
		);

	$indicator = array_pop($aindicator);
	
	$sexlist = $lovmanager->getLov_Sex();
	
	$simpleSexList = array ();
	foreach ( $sexlist as $lc ) {
		$simpleSexList [$lc->id] = $lc->descriptioncode;
	}
	
	$AgeGrouplist = $lovmanager->getLov_AgeGroup();
	
	$simple_AgeGroupList = array ();
	foreach ( $AgeGrouplist as $lc ) {
		$simple_AgeGroupList [$lc->id] = $lc->descriptioncode;
	}
		
	$simpleListX = array ();
	$simpleListY = array ();
	if (isset($indicator->dimcodelistx)) {
		$dimxdescritioncode = $lovmanager->getLov_DescriptionCode($indicator->dimcodelistx);
		$listx = $lovmanager->getLov($indicator->dimcodelistx);
		foreach ( $listx as $lc ) {
			$simpleListX [$lc->id] = $lc->descriptioncode;
		}
		
	}
	if (isset($indicator->dimcodelisty)) {
		$dimydescritioncode = $lovmanager->getLov_DescriptionCode($indicator->dimcodelisty);
		$listy = $lovmanager->getLov($indicator->dimcodelisty);
		
		foreach ( $listy as $lc ) {
			$simpleListY [$lc->id] = $lc->descriptioncode;
		}
	}
}


?>

<div class="row" >
<div class="col-lg-12" >
            <h3><?= R('page_title_efp_setdetail') ?></h3>
            <p>&nbsp;</p>
			<?php $this->load('common/message',$this) ?>
                        
             <form class="form-inline" role="form" id="formset"
			name="formset" onsubmit="" method="post"
			action="<?= __SITEBASE ?>/setdetail">
			<input type="hidden" id="nav_backpost" name="nav_backpost" value="1"></input>
			<input type="hidden" id="retnav" name="retnav" value="efpcollect"></input>
			<input type="hidden" id="uid" name="uid" value="<?=$detail->id ?>"></input>
			<div class="panel panel-default">
				<div class="panel-body">
					<div class="form-group">
			          	<?= R('label_set') ?>:
			          	<b>
			          	<?php if ($fileok) { ?>
			          	<a href="" onclick="window.open('<?= __SITEBASE ?>/setdetail/downloadfile?id=<?= $detail->id ?>');return false;"><i
								class="fa fa-paperclip"></i></a>
						<?php } ?>
								</b> <?= $detail->id ?></b>
					</div>
					<div class="form-group">
			          	<?= R('label_organisation') ?>:
			          	<b><?= $detail->organisationintname ?></b>
					</div>
					<div class="form-group">
			          	<?= R('label_date') ?>:
			          	<b><?= date('Y-m-d H:m:s',$detail->creationdate)    ?></b>
					</div>
					<div class="form-group">
			          	<?= R('label_period') ?>:
			          	<b><?= $detail->fromyear.'-'.$detail->toyear   ?></b>
					</div>
					<div class="form-group">
					  <?= R('label_status') ?>:
					  <select name="setstatus" class="form-control">
					  	  <?php  foreach($listStates as $status) { ?>
					   		<option value="<?= $status->to_statecode_id ?>" <?= $detail->statuscodeid == $status->to_statecode_id ? 'selected':''?>><?= D($status->to_statecode__description) ?></option>
					   <?php  } ?>
					   </select>
					</div>
					<div class="form-group">
					   <?= R('label_description')?>
					   <textarea id="annotation" name="annotation" class="form-control"
							cols="80" rows="2"><?= $detail->annotation ?></textarea>
					</div>
				</div>
			</div>

			<div class="form-group">
					  <?= R('label_indicator') ?>:
					  <select permissions="false"  name="indicator" class="form-control">
					  <option value="" style="display: none;"><?= R("label_please_select_dropdown") ?>
					  <?php  foreach($listdataindicator as $item) { ?>
					   		<option value="<?= $item->id ?>"
						<?= ($_POST['indicator'] == $item->id) ? "selected" : "" ?>><?= D($item->descriptioncode) ?></option>
					   <?php  } ?>
					   </select>
				<button permissions="false" style="padding-left: 20px;" type="submit"
				 class="btn btn-default"><?=R('label_view') ?></button>
			</div>

	<div class="panel" style="margin-top: 10px;">
		<div class="panel panel-default">
			<div class="panel-body">

				<div class="table-responsive">
					<table class="table table-hover table-striped tablesorter">
						<thead>
							<tr>
								<th><?= R('label_year') ?></th>
								<th><?= R('label_gender') ?></th>
								<th><?= R('label_agegroup') ?></th>
								<th><?= (!isset($dimxdescritioncode))? R('label_dimension') : D($dimxdescritioncode) ?></th>
								<th><?= (!isset($dimydescritioncode))? R('label_dimension') : D($dimydescritioncode)  ?></th>
								<th><?= R('label_indicatorvalue') ?></th>
								<th><?= R('label_embargo') ?></th>
							</tr>
						</thead>
						<tbody>
				                <?php foreach($list as $line) { ?>
				                 <tr >
									<td><?= $line->valueyear ?></td>
									<td><?=  D($simpleSexList[$line->genderid]) ?></td>
									<td><?=  D($simple_AgeGroupList[$line->agegroupid]) ?></td>
									<td><?= (isset($line->xdimensionid ))? D($simpleListX[$line->xdimensionid]) : ' - ' ?></td>
									<td><?= (isset($line->ydimensionid ))? D($simpleListY[$line->ydimensionid]) : ' - ' ?></td>
									<td><?= ($indicator->unitcodeid == __INDICATOR_FORMAT_PERCENT) ? $line->agregvalue.' &#37;' : (($indicator->unitcodeid == __INDICATOR_FORMAT_NUMBER) ? floatval($line->agregvalue): (($indicator->unitcodeid == __INDICATOR_FORMAT_MONEY) ? $line->agregvalue.' EUR' : $line->agregvalue)) ?></td>
									<td><?= $line->embargodate ?></td>
							</tr>
				               <?php } ?>
				                </tbody>
					</table>
				</div>
			</div>
		</div>
	</div>
	<div class="form-group">
		<button style="margin-left: 20px;" type="submit" onclick="toggleAction('save');"
			class="btn btn-default"><?=R('label_save') ?></button>
				<?php if (isset($bakurl)) { ?>
					<a href="<?= __SITEBASE ?>/<?= $bakurl ?>" class="btn btn-default"><?=R('label_cancel') ?></a>
					<?php } ?>

			</div>
	</form>
</div>
</div>
<script>
function toggleAction(action) {

	if (action == 'save')
	{
		$('#formset').attr('action','<?= __SITEBASE ?>/setdetail/save');
	}
}
 </script>
