<?php
/**
 * Screen nfppublish\index
 * @version 1.0.1
 * @package Backend\DataRecords
 * 
*/
require_once 'app/class-lov-manager.php';

$list = $this->data['list'];
$navurl = $this->data['navkey'];

$lovmanager = new LovManager();
$recordstatuslist = $lovmanager->getLov_RecordStatus();
$pubstatuslist = $lovmanager->getLov_PublishStatus();

$simpleStatusList = array();
foreach ($recordstatuslist as $lc){
	$simpleStatusList[$lc->id] = $lc->descriptioncode;
}
$simplePStatusList = array();
foreach ($pubstatuslist as $lc){
	$simplePStatusList[$lc->id] = $lc->descriptioncode;
}

//print_r($list);


?>
<div class="row" >
<div class="col-lg-12" >
            <h3><?= R('page_title_nfp_publishdata') ?></h3>
            <p>&nbsp;</p>
			<?php $this->load('common/message',$this) ?>
            
             <form class="form-inline" role="form" name="formpubnfp" id="formpubnfp" onsubmit="return validate_checks();" method="post" action="<?= __SITEBASE ?>/nfppublish/markpublishable">
             <input type="hidden" id="tainted" name="tainted" value="0"></input>
             <input type="hidden" id="retnav" name="retnav" value="nfppublish"></input>
             <input type="hidden" id="assistedset" name="assistedset" value="<?= $setString ?>"></input>
          
             
            <div class="panel" style="margin-top:20px;">
	             <div class="panel panel-default">
			         <div class="panel-body">
			           	 <div class="table-responsive" >
				              <table id="table1" class="table table-hover table-striped tablesorter">
				                <thead>
				                  <tr>
				                  	<th class=""></th>
				                    <th class="header"><?= R('label_UID') ?> <i class="fa fa-sort"></i></th>
				                    <th class="header"><?= R('label_type') ?> <i class="fa fa-sort"></i></th>
				                    <th class="header"><?= R('label_organization') ?> <i class="fa fa-sort"></i></th>
				                    <th class="header"><?= R('label_embargodate') ?> <i class="fa fa-sort"></i></th>
				                    <th class="header"><?= R('label_status') ?> <i class="fa fa-sort"></i></th>
				                    <th class="header"><?= R('label_publication') ?> <i class="fa fa-sort"></i></th>
				                  </tr>
				                </thead>
				                <tbody>
				                <?php foreach($list as $line) { ?>
				                 <tr class="annotation" title="<?=$line->annotation ?>">
				                    <td><input name="ck_<?= $line->uid ?>" type="checkbox" <?= ($_POST['ck_'.$line->uid] != null)? " checked " :"" ?> <?= (!isset($line->cluster) && $line->status == __RECORD_STATUS_VALID && $line->publication == __PUBLISHED_STATUS_UNPUBLISHED)? "" : " disabled " ?> ></td>
				                    <td><a href="<?= __SITEBASE ?>/recorddetail?uid=<?= $line->uid ?>&<?=$navurl ?>"><?= $line->uid ?></a></td>
				                    <td><?= ($line->type == __STATISTICAL_TYPE_TRAFFICKERS) ? D(__STATISTICAL_TYPE_TRAFFICKERS_DESCRITION) : D(__STATISTICAL_TYPE_VICTIMS_DESCRITION) ?></td>
				                    <td><?= $line->organisation ?></td>
				                     <td><?= $line->embargodate ?></td>
				                    <td><?= D($simpleStatusList[$line->status]) ?></td>
				                    <td><?= D($simplePStatusList[$line->publication]) ?></td>
				                 </tr>
				               <?php }?>
				                </tbody>
				              </table>
		            
			              </div>
			              
		              </div>
		              </div> 


						<button style="padding-left:20px;" type="submit" class="btn btn-default checkboxdependent"><?=R('mark_publishable') ?></button>
					<span class="pull-right">
						<?= R('label_publish_to_efp') ?> 
						<button permissions="true"onclick="location.href='<?= __SITEBASE ?>/nfppublish/publishvictims?<?=$navurl ?>'" class="btn btn-default checkboxdependent"><?=R('btn_publish_victims') ?></button>
						<button permissions="true" onclick="location.href='<?= __SITEBASE ?>/nfppublish/publishtraffickers?<?=$navurl ?>'" class="btn btn-default checkboxdependent"><?=R('btn_publish_traffickers') ?></button>
					</span>
						<br><br>				
						<a permissions="true" href="<?= __SITEBASE ?>/nfppublish/prereleasestats?<?=$navurl ?>" class="btn btn-default"><?=R('label_prerelease_statistics') ?></a>
						<a permissions="true" href="<?= __SITEBASE ?>/nfppublish/releasestats?<?=$navurl ?>" class="btn btn-default"><?=R('label_final_statistics') ?></a>
						
				</form>
            </div>
</div>
</div>

<script>
function validate_checks() {
	var numberOfChecked = $('input:checkbox:checked').length;

	if (numberOfChecked >0) {
		return true;
	} else {
	return false;
	}
}

//enable and disable buttons dependent off checkboxes
$(document).ready(function() {
	$(".checkboxdependent").prop('disabled', true);

	$("[type=checkbox]").bind("click",function(){
	
		if($("[type=checkbox]:checked").length == 0) {
			$(".checkboxdependent").prop('disabled', true);
		} else {
			$(".checkboxdependent").prop('disabled', false);;
		}
		
	});
});
//-----------------------------------------------------------

</script>
 