<?php
$this->load->view('voter/script',$this->templates->getData());
$this->load->view('voter/modal',$this->templates->getData());
$voted = hasVoterStarted();
$started = isProjectStarted();
$stopped = isProjectStopped();
?>
<div class="content-wrapper">
	<section class="content-header">
		<h1><?php echo $this->lang->line('voter'); ?></h1>
		<ol class="breadcrumb">
			<li style="color:#0C0"><a href="#"><i class="fa fa-home"></i> <?php echo $this->lang->line('home'); ?></a></li>
			<li style="color:#0C0"><a href="#"><?php echo $this->lang->line('voter'); ?></a></li>
			<li class="active" style="color:#0C0"><?php echo $this->lang->line('voterList'); ?></li>
		</ol>
	</section>

	<!-- Main content -->
	<section class="content">
	
		<div class="section-title p-5-x text-center">
			<h1 class="m-0-t font-weight-bold"><?php echo ($l = $this->lang->line('voter')) ? ucwords(strtolower($l)) : $this->lang->line('voter'); ?></h1>
			<p class="m-0-b"><?php echo $this->lang->line('listof'); ?></p>
		</div>
		
		<div class="row p-5-x m-1-b text-center">
			<div class="flex-btn-group m-1-y col-md-4 col-md-offset-4">
				<a href="<?php echo base_url(); ?>dashboard" class="btn btn-danger"><i class="fa fa-backward"></i>&nbsp;<?php echo $this->lang->line('back'); ?></a>
				<?php
				if(!$voted && !$started && !$stopped) {
					?>
					<a href="<?php echo base_url() ?>import" class="btn btn-primary btn-sm">
						<i class="fa fa-plus fa-fw"></i> <?php echo $this->lang->line('uploadvoter');?>
					</a>
					<button type="button" class="btn btn-sm btn-success" onclick="showDetail(this)">
						<i class="fa fa-plus fa-fw"></i> <?php echo $this->lang->line('addNew');?>
					</button>
					<?php
				}
				?>
				<a href="javascript:void(0);" onclick="printvoter()" id="print_btn" target="_blank" class="btn btn-warning btn-sm" title="Print"><span class="glyphicon glyphicon glyphicon-print"></span> <?php echo $this->lang->line('print');?></a>
			</div>
		</div>
		
		<div class="helper helper-center">
		<ul>
		<?php
		if($voted || $started || $stopped) {
			if($voted) {
				?><li><?php echo $this->lang->line('helperVotedAdd');?>.</li><?php
			} else {
				?>
				<li><?php echo ($started) ? $this->lang->line('helperStart') : $this->lang->line('helperStop'); ?></li>
				<?php
			}
		}
		?>
		<li><?php echo $this->lang->line('helperVotedEdit');?>.</li>
		</ul>
		</div>
			
		<div class="row m-1-b m-1-t p-0-y p-3-x p-xs-1-x">
			<div class="col message <?php echo (isset($respond) && $respond['type']) ? strtolower($respond['type']) : NULL; ?> text-center" id="message">
			<?php echo (isset($respond) && $respond['message']) ? $respond['message'] : ((strtolower($respond['type']) == 'success') ? 'Success' : NULL); ?>
			</div>
		</div>
		
		<div class="table-responsive p-1-x m-1-y" style="overflow: hidden;">
			<table id="datatable_voterlist" class="table table-bordered table-striped datatables">
				<thead>
					<tr>
						<th class="text-center"><?php echo $this->lang->line('no'); ?></th>
						<th class="text-center"><?php echo $this->lang->line('voterNo'); ?></th>
						<th class="text-left"><?php echo $this->lang->line('voterName'); ?></th>
						<th class="text-left"><?php echo $this->lang->line('companyName'); ?></th>
						<th class="text-center"><?php echo $this->lang->line('status'); ?></th>
						<?php
						if(!$voted && !$started && !$stopped) {
							?>
							<th class="text-center"><?php echo $this->lang->line('action'); ?></th>
							<?php
						}
						?>
					</tr>
				</thead>
					<tbody>
							<?php 
							if($voterList){
									$i = 1;
									foreach ($voterList as $row){
										$u = $row->userID;
										$c = ($row->companyID) ? $row->companyID : 0;
										$n = ($row->companyName) ? $row->companyName : '';
							?>
							<tr>
									<td class="text-center"><?php echo $i++; ?></td>
									<td class="text-center" id="noAhli_<?php echo $row->userID; ?>">
									<?php
									if(!$row->status) {
										?>
										<a href="javascript:void(0);" onclick="return showDetail2(<?php echo $u; ?>, <?php echo $c; ?>,'<?php echo $n; ?>')"><?php echo $row->noAhli; ?></a>
										<?php
									} else {
										echo $row->noAhli;
									}
									?>
									</td>
									<td class="text-left" id="voterName_<?php echo $row->userID; ?>"><?php echo $row->name; ?></td>
									<td class="text-left"><?php echo $row->companyName; ?></td>
									<td class="text-center"><?php if($row->status == 0){ echo $this->lang->line('noVote'); }else{echo $this->lang->line('voted');}?></td>
									<?php
									if(!$voted && !$started && !$stopped) {
										?>
										<td class="text-center">
											<?php
											if(!$row->status) {
												?>
												<button type="button" onClick="deleteConfirm(<?php echo $row->userID; ?>);" class="btn btn-danger btn-sm delete" title="Delete" <?php if($row->checkStatus == false){echo "disabled";} ?>>
													<span class="glyphicon glyphicon glyphicon-trash"></span> <?php echo $this->lang->line('delete'); ?>
												</button>
												<?php
											}
											?>
										</td>
										<?php
									}
									?>
							</tr>
							<?php 
									}
							}
							?>


					</tbody>
			</table>
		</div>
			
			
  </section>
</div>
