<?php	
$abso = str_replace("\\","/", FCPATH);
$virt = str_replace("\\","/", base_url());											
$banner = $virt."dist/img/_sys/banner.png";
if($project && $project['banner'] && file_exists($abso."img/project/".$project['banner'])) $banner = $virt."img/project/".$project['banner'];
?>
<div class="content-wrapper" <?php echo ($project['color']) ? "style=\"background-color: #".$project['color'].";\"" : NULL; ?>>
	<section class="content-header" style="background-image: url('<?php echo $banner; ?>');">
		<div class="content-header-overlay p-5-x p-2-y p-xs-1-x text-center text-white">
			<h1 class="oswald"><?php echo ($project) ? $project['title'] : NULL; ?></h1>
			<span class="droid-serif">
				<?php echo ($project) ? date('d/m/Y h:i A', strtotime($project['startDT'])) : NULL; ?>				
				<?php echo ($project && $project['endDT']) ? "&nbsp;&nbsp;-&nbsp;&nbsp;".(date('d/m/Y h:i A', strtotime($project['endDT']))) : NULL; ?>
				<?php echo ($project && $project['venue']) ? "<br /><small>".$project['venue']."</small>" : NULL; ?>
			</span>
		</div>
	</section>
	
	<input type="hidden" id="projectID" value="<?php echo ($project) ? $project['ID'] : NULL; ?>" />
	
	<div class="content main-content p-2 p-xs-1" id="main_content_wrapper">
		<?php
		if(!$error && $project['showResultToVoter']) {
			?>
			<a href="javascript:void(0);" class="circle circle-success show-result" id="show_result" onclick="return loadResult();"
					data-toggle="tooltip" title="Show Result"><i class="fa fa-bar-chart"></i></a>
			<a href="javascript:void(0);" class="circle circle-danger show-result hidden" id="close_result" onclick="return cancelVoting();"
					data-toggle="tooltip" title="Close Result"><i class="fa fa-times"></i></a>
			<?php
		}
		?>
		
		<div id="main_content">
		<?php
		if(!$error) {
			$this->load->view('voting/login',$this->templates->getData());
		} else {
			?>
			<div class="row p-5-x p-xs-1-x">
				<div class="col-md-2 text-center">
					<img class="img-responsive m-auto-x" src="<?php echo base_url(); ?>dist/img/_sys/sad.png" />
				</div>
				<div class="col-md-10 p-1-x">
					<div class="jumbotron bg-white text-xs-center">
						<h3>
						<?php
						switch($error) {
							case 1:
								echo $this->lang->line('case1');
								break;
							case 2:
								echo $this->lang->line('case2');
								break;
							case 3:
								echo $this->lang->line('case3');
								break;
							case 4:
								echo $this->lang->line('case4');
								break;
							case 5:
								echo $this->lang->line('case5');
								break;
							default:
								echo $this->lang->line('caseDefault');
								break;
						}
						?>
						</h3>
					</div>
				</div>
			</div>
			<?php
		}
		?>
		</div>
	</div>
</div>
	
<!-- RETAKE VOTE MODAL -->		
<div class="modal fade" id="retake_voting_modal" role="dialog">
	<div class="modal-dialog modal-lg">			
		<div class="modal-content">
			<div class="modal-header" >
				<button type="button" class="modal-close" data-dismiss="modal"><span></span><span></span></button>
				<h3 class="modal-title text-center"><?php echo $lines['retake_vote_prompt']; ?></h3>
			</div>
			
			<div class="modal-body">
				<div class="row">
					<div class="col-md-offset-4 col-md-4">
						<div class="flex-btn-group">
							<button class="btn btn-success" onclick="return retakeVoting(this);"><i class="fa fa-check"></i>&nbsp;<?php echo $this->lang->line('y'); ?></button>
							<button class="btn btn-danger" data-dismiss="modal"><i class="fa fa-times"></i>&nbsp;<?php echo $this->lang->line('n'); ?></button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
	
<!-- CONFIRM VOTE MODAL -->		
<div class="modal fade" id="confirm_voting_modal" role="dialog">
	<div class="modal-dialog modal-lg">			
		<div class="modal-content">
			<div class="modal-header" >
				<button type="button" class="modal-close" data-dismiss="modal"><span></span><span></span></button>
				<h3 class="modal-title text-center"><?php echo $lines['confirm_vote_prompt']; ?></h3>
			</div>
			
			<div class="modal-body">
				<div class="row">
					<div class="col-md-offset-4 col-md-4">
						<div class="flex-btn-group">
							<button class="btn btn-success" onclick="return confirmVoting(this);"><i class="fa fa-check"></i>&nbsp;<?php echo $this->lang->line('y'); ?></button>
							<button class="btn btn-danger" data-dismiss="modal"><i class="fa fa-times"></i>&nbsp;<?php echo $this->lang->line('n'); ?></button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

<script>
var lines = JSON.parse('<?php echo json_encode($lines); ?>');
var data = {
	projectID : Number('<?php echo ($project) ? $project['ID'] : 0; ?>'),
	userID : 0,
	voterID : 0,
	lang : 'EN',
	step : 0,
	pos : 0
}

function loadSegment(i,p) {
	data.step = i;
	data.pos = (p) ? p : 0;
	$('#main_content').slideUp();

	$('#main_content').html('');
	
	openLoader();
	delete data['key'];
	$.post('<?php echo base_url(); ?>v/loadsegmentajax', data, function(r) {
		if($.trim(r)) {
			$('#main_content').html(r);	
			
			if(	$('#candidate_list').length ) {
				var t = $('#candidate_list').position().top + 100;
			} else {
				var t = $('#main_content').position().top + 100;
			}
		
			$('html,body').animate({scrollTop:t}, 'slow');
			
			data.userID = Number($('#userID').val());
		}
		closeLoader();
	});
		
	$('#main_content').slideDown();
}

function loadResult() {
	$('#main_content').slideUp(function() { $(this).html(''); });
	$('#show_result').addClass('hidden');
	$('#close_result').removeClass('hidden');
	
	openLoader();
	delete data['key'];
	delete data['step'];
	delete data['pos'];
	$.post('<?php echo base_url(); ?>v/loadresultajax', data, function(r) {
		if($.trim(r)) $('#main_content').html(r);
		closeLoader();
	});
		
	$('#main_content').slideDown();
}

function submitLogin() {
	openLoader();
	$('#login_msg').html('');
	$('#voter_id').parents('.form-group').eq(0).removeClass('has-error');
	$('#voter_key').parents('.form-group').eq(0).removeClass('has-error');
	
	var p = Number($('#projectID').val());
	var id = $.trim( $('#voter_id').val() );
	var key = $.trim( $('#voter_key').val() );
	var lang = $.trim( $('[id*="language_"]:checked').val() );
			lang = (lang == "") ? "EN" : lang;
	
	if(id == "") {
		$('#login_msg').html(lines['voter_key_empty']);
		$('#voter_id').parents('.form-group').eq(0).addClass('has-error');
		closeLoader();
		return false;
	}	

	if(key == "") {
		$('#login_msg').html(lines['voter_key_empty']);
		$('#voter_key').parents('.form-group').eq(0).addClass('has-error');
		closeLoader();
		return false;
	}
	
	data.voterID = id;
	data.lang = lang;
	var d = data;
			d.key = key;
	
	$.post('<?php echo base_url(); ?>v/checkloginajax', d, function(r) {
		if(r.toUpperCase() == "SUCCESS") {
			loadSegment(0,0);
		} else {
			$('#login_msg').html(r);
			closeLoader();
		}
	});
}

function cancelVoting() {
	openLoader();
	window.location.reload();
}

function retakeVoting() {
	$('#retake_voting_modal').modal('hide');
	loadSegment(0,0);
}

function confirmVoting() {
	$('#confirm_voting_modal').modal('hide');
	openLoader();
	delete data['key'];
	delete data['positionID'];
	delete data['chosen'];
	delete data['limit'];
	delete data['selected'];
	$.post('<?php echo base_url(); ?>v/confirmvoteajax', data, function(r) {
		var obj = (	$.trim(r)	) ? JSON.parse(r) : null;
		if(obj) {
			if(obj['status'].toUpperCase() == "SUCCESS") {
				if(	Number(obj['showResult']) ) {
					loadResult();
				} else {
					cancelVoting();
				}
			} else {
				$('#message').html('<?php echo $lines['cannot_save_confirm']; ?>');
			}
		}
		
		closeLoader();
	});
}

function selectLanguage(me) {
	var l = 'EN';
	if($(me).is(':checked')) {
		l = $(me).val();
	}
	data.lang = l.toUpperCase();
	loadLang();
}

function loadLang() {	
	openLoader();
	
	$('#login_msg').html('');
	$('#voter_id').parents('.form-group').eq(0).removeClass('has-error');
	$('#voter_key').parents('.form-group').eq(0).removeClass('has-error');
	
	$.post('<?php echo base_url(); ?>v/loadlangajax', { lang : data.lang }, function(r) {
		var obj = (	$.trim(r)	) ? JSON.parse(r) : null;
		if(obj) lines = obj;
		
		// LOGIN
		$('#login_inst').html(lines['login_inst']);
		$('#line_voter_id').html(lines['line_voter_id']);
		$('#line_voter_key').html(lines['line_voter_key']);
		$('#line_language').html(lines['line_language']);
		$('#line_login').html(lines['line_login']);
		
		// HEADER
		$('#header_voter_id').html(lines['line_voter_id']+':&nbsp;&nbsp;&nbsp;');
		$('#header_language').html(lines['line_language']+':&nbsp;&nbsp;&nbsp;');
		$('#header_voter_name').html(lines['line_voter_name']+':&nbsp;&nbsp;&nbsp;');
		$('#header_company_name').html(lines['line_company_name']+':&nbsp;&nbsp;&nbsp;');
		$('#header_start_dt').html(lines['line_start_dt']+':&nbsp;&nbsp;&nbsp;');
		$('#header_end_dt').html(lines['line_end_dt']+':&nbsp;&nbsp;&nbsp;');
		
		$('#show_result').attr('title',lines['show_result']).attr('data-original-title',lines['show_result']);
		$('#close_result').attr('title',lines['close_result']).attr('data-original-title',lines['close_result']);
		
		closeLoader();
	});
}

</script>




























