<?php
$abso = str_replace("\\","/", FCPATH);
$virt = str_replace("\\","/", base_url());
?>
<link rel="stylesheet" href="<?php echo base_url(); ?>dist/vendors/spectrum/spectrum.css">
<script src="<?php echo base_url(); ?>dist/vendors/spectrum/spectrum.js"></script>
<div class="content-wrapper">	
	<section class="content-header">
			<h1 style="font-family:roboto">
					<b><?php echo $this->lang->line('project'); ?></b>
			</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('project'); ?></a></li>
					<li class="active" style="color:#0C0"><?php echo $this->lang->line('projectlist'); ?></li>
			</ol>
	</section>
		
	<div class="content registration m-0-b">
		<div class="row section-title p-5-x p-1-y text-center">
			<div class="col">
				<h1 class="m-0-t font-weight-bold"><?php echo $this->lang->line('detail'); ?></h1>
				<p class="m-0-b"><?php echo $this->lang->line('setupDet'); ?></p>
			</div>
		</div>
		
		<?php
		$paid = ($project['paid']) ? TRUE : FALSE;
		$stopped = ($project['stopped']) ? TRUE : FALSE;
		$started = (strtotime($project['startDT']) <= strtotime('now')) ? TRUE : FALSE;
		$ended = ($project['endDT'] && strtotime($project['endDT']) <= strtotime('now')) ? TRUE : FALSE;
		?>
		
		<div class="row m-5-b m-2-t p-1-x">
			<div class="col-md-6">
				<form class="form-horizontal registration-form" method="post" enctype="multipart/form-data"
							action="<?php echo base_url(); ?>project/save" id="project_form">
					<input type="hidden" name="ID" id="ID" value="<?php echo ($project) ? $project['ID'] : 0; ?>" />
				
					<div class="box box-flat m-1-b">							
						<div class="box-header p-1-l p-1-r">
							<div class="flex-btn-group">
								<?php
								if(!$started) {
									?>
									<button type="submit" class="btn btn-block btn-success"><i class="fa fa-check"></i>&nbsp;<?php echo $this->lang->line('save'); ?></button>
									<?php
								}
								?>
								<a href="<?php echo base_url(); ?>project" class="btn btn-danger"><i class="fa fa-backward"></i>&nbsp;<?php echo $this->lang->line('back'); ?></a>
							</div>
						</div>
						
						<div class="box-body">
							<!-- MESSAGE -->
							<div class="row">
								<div class="col message <?php echo $respond['type'] ? strtolower($respond['type']) : NULL; ?> text-center" id="message">
								<?php echo ($respond['message']) ? $respond['message'] : ((strtolower($respond['type']) == 'success') ? 'Success' : NULL); ?>
								</div>
							</div>
							
							<!-- MENU -->
							<div class="row">
								<div class="col-md-<?php echo ($started && !$stopped && $paid) ? 6 : 12; ?>">
									<div class="row p-2-x">
										<div class="col-xs-6 text-center">
											<div class="project-info-icon"><i class="fa fa-users"></i></div>
											<div class="project-info-sts"><strong><?php echo $this->lang->line('voters'); ?> : </strong><?php echo ($project['voters']); ?></div>
										</div>
										
										<div class="col-xs-6 text-center">
											<div class="project-info-icon"><i class="fa fa-rocket"></i></div>
											<div class="project-info-sts">
												<strong><?php echo $this->lang->line('started'); ?> : </strong>
												<?php echo ($started) ? "<i class=\"fa fa-check text-green\"></i>" : "<i class=\"fa fa-times text-red\"></i>"; ?>
											</div>
										</div>
										
										<div class="col-xs-6 text-center">
											<div class="project-info-icon"><i class="fa fa-dollar"></i></div>
											<div class="project-info-sts">
												<strong><?php echo $this->lang->line('paid'); ?> : </strong>
												<?php echo ($project['paid']) ? "<i class=\"fa fa-check text-green\"></i>" : "<i class=\"fa fa-times text-red\"></i>"; ?>
											</div>
										</div>
										
										<div class="col-xs-6 text-center">
											<div class="project-info-icon bg-red"><i class="fa fa-bell-slash-o"></i></div>
											<div class="project-info-sts">
												<strong><?php echo $this->lang->line('ended'); ?> : </strong>
												<?php echo ($ended || $stopped) ? "<i class=\"fa fa-check text-green\"></i>" : "<i class=\"fa fa-times text-red\"></i>"; ?>
											</div>
										</div>
									</div>
								</div>
								
								<div class="col-md-6 m-xs-1-t text-center <?php echo ($started && !$stopped && $paid) ? NULL : "hidden"; ?>">
									<div class="row p-0">
										<div class="col-xs-6 p-0">
											<div class="helper helper-sm helper-right">
												<ul>
													<li><?php echo $this->lang->line('stopHelper1a'); ?> <strong><?php echo strtoupper($this->lang->line('stop')); ?></strong> <?php echo $this->lang->line('stopHelper1b'); ?></li>
													<li><?php echo $this->lang->line('stopHelper2'); ?></li>
												</ul>
											</div>
										</div>
										
										<div class="col-xs-6 p-0">
											<a href="javascript:void(0);" class="btn btn-xl btn-circle btn-danger" data-toggle="tooltip" title="Stop" onclick="return stopProject(this);">
												<i class="fa fa-hand-stop-o fa-5x"></i>
											</a>
											<div class="text-center"><strong>Stop</strong></div>
										</div>
									</div>
								</div>
							</div>
							
							<!-- VOTING URL -->
							<div class="row p-2-x p-1-t">
								<div class="col-xs-12 m-1-t font-24 font-xs-18 text-center">
									<strong><?php echo $this->lang->line('votingURL'); ?> : </strong>
									<a href="<?php echo base_url(); ?>v/p/<?php echo $project['ID']; ?>" target="_blank"><?php echo base_url(); ?>v/p/<?php echo $project['ID']; ?></a>
								</div>
							</div>		
						
							<!-- HELPER -->
							<div class="row m-2-t m-1-b p-2-x">
								<div class="col">
									<div class="helper">
										<ul>
											<li><?php echo $this->lang->line('required'); ?></li>
											<?php
											if($started) {
												?><li><?php echo $this->lang->line('ifStarted'); ?></li><?php
											}
											?>
										</ul>
									</div>
								</div>
							</div>
							
							<!-- TITLE -->
							<div class="form-group">
								<label class="col-xs-12 required registration-form-label"><?php echo $this->lang->line('title'); ?></label>
								<div class="col-xs-12">
									<?php
									if($started) {
										?><span class="form-control"><?php echo ($project) ? $project['title'] : NULL; ?></span><?php
									} else {
										?>
										<input type="text" class="form-control validate[required] registration-form-input" name="title" id="title"
											value="<?php echo ($project) ? $project['title'] : NULL; ?>" />
										<?php
									}
									?>
								</div>
							</div>				
							
							<!-- START AND END DATE -->
							<div class="row p-0">
								<div class="col-md-6">
									<div class="form-group">
										<label class="col-xs-12 required registration-form-label"><?php echo $this->lang->line('startDT'); ?></label>
										<div class="col-xs-12">
											<?php
											if($started) {
												?><span class="form-control"><?php echo ($project) ? (date("d-m-Y h:i a",strtotime($project['startDT']))) : NULL; ?></span><?php
											} else {
												?>
												<input type="text" class="form-control validate[required] datepick registration-form-input" name="startDT" id="startDT" 
													value="<?php echo ($project) ? (date("d-m-Y h:i a",strtotime($project['startDT']))) : NULL; ?>" style="position: relative;" />
												<?php
											}
											?>
											<div class="helper">
												<ul>
													<li><?php echo $this->lang->line('startDTHelper'); ?></li>
													<li><?php echo $this->lang->line('required2'); ?></li>
												</ul>
											</div>
										</div>
									</div>
								</div>
								<div class="col-md-6">
									<div class="form-group">
										<label class="col-xs-12 registration-form-label"><?php echo $this->lang->line('endDT'); ?></label>
										<div class="col-xs-12">
											<?php
											if($started) {
												?>
												<div class="form-control <?php echo ($stopped) ? "text-linethrough" : NULL; ?>">
													<?php echo ($project && $project['endDT']) ? (date("d-m-Y h:i a",strtotime($project['endDT']))) : NULL; ?>
												</div>
												<?php
												if($stopped) {
													?>
													<div class="form-control">
														<?php echo ($stopped && $project && $project['stoppedDT']) ? "Ended on ".(date("d-m-Y h:i a",strtotime($project['stoppedDT']))) : NULL; ?>
													</div>
													<?php
												}
											} else {
												?>
												<input type="text" class="form-control datepick registration-form-input" name="endDT" id="endDT" 
													value="<?php echo ($project && $project['endDT']) ? (date("d-m-Y h:i a",strtotime($project['endDT']))) : NULL; ?>" />
												<?php
											}
											?>
											<div class="helper">
												<ul>
													<li><?php echo $this->lang->line('endDTHelper1'); ?></li>
													<li><?php echo $this->lang->line('endDTendDTHelper2'); ?></li>
												</ul>
											</div>
										</div>
									</div>
								</div>
							</div>
							
							<!-- VENUE -->
							<div class="form-group">
								<label class="col-xs-12 registration-form-label"><?php echo $this->lang->line('venue'); ?></label>
								<div class="col-xs-12">
									<?php
									if($started) {
										?><span class="form-control"><?php echo ($project) ? $project['venue'] : NULL; ?></span><?php
									} else {
										?>
										<textarea class="form-control registration-form-input" rows="5" name="venue" id="venue"><?php echo ($project) ? $project['venue'] : NULL; ?></textarea>
										<?php
									}
									?>
								</div>
							</div>
							
							<!-- BANNER IMAGE -->
							<div class="form-group">
								<label class="col-xs-12 registration-form-label"><?php echo $this->lang->line('banner'); ?></label>
								<div class="col-xs-12">
									<?php																
									$image = $virt."dist/img/_sys/banner.png";
									if($project && $project['banner'] && file_exists($abso."img/profile/".$project['banner'])) {
										$image = $virt."img/project/".$project['banner'];
									}
									?>
									
									<div class="uploader">
										<?php
										if(!$started) {
											?>
											<input type="file" name="banner" accept="image/*" />
											<input type="hidden" name="resetBanner" value="0" />
											<?php
										}
										?>
										<img src="<?php echo $image; ?>" class="img-responsive" />
									</div>
									
									<?php
									if(!$started) {
										?>
										<div class="helper">
											<ul>
												<li><?php echo $this->lang->line('imgHelper'); ?></li>
												<li><?php echo $this->lang->line('imgOptSize'); ?></li>
												<li><a href="javascript:void(0);" onclick="return clearBannerImage(this);"><?php echo $this->lang->line('bannerReset'); ?></a></li>
											</ul>
										</div>
										<?php
									}
									?>
								</div>
							</div>
														
							<!-- BACKGROUND COLOR -->
							<div class="form-group">
								<label class="col-xs-12 registration-form-label"><?php echo $this->lang->line('bgColor'); ?>r</label>
								<div class="col-xs-12">
									<?php
									if(!$started) {
										?>
										<input type="text" name="color" id="color" value="#<?php echo ($project && $project['color']) ? str_replace('#','',$project['color']) : 'd4d8dc'; ?>" />
										<input type="hidden" name="resetColor" value="0" />
										<div class="helper">
											<ul>
												<li><?php echo $this->lang->line('bgColorHelper'); ?></li>
												<li><a href="javascript:void(0);" onclick="return clearColor(this);"><?php echo $this->lang->line('bgColorReset'); ?></a></li>
											</ul>
										</div>
										<?php
									} else {
										echo $project['color'];
									} //d6c29f
									?>
								</div>
							</div>
							
							<!-- LANGUAGE -->
							<div class="form-group">
								<label class="col-xs-12 registration-form-label"><?php echo $this->lang->line('lang'); ?></label>
								<div class="col-xs-12">									
									<div class="helper">
										<ul>
											<li><?php echo $this->lang->line('langHelper1'); ?></li>
											<li><?php echo $this->lang->line('langHelper2'); ?></li>
											<li><?php echo $this->lang->line('langHelper3'); ?></li>
										</ul>
									</div>
									
									<?php
									$lang = ($project && $project['language']) ? explode('|',$project['language']) : NULL;
									$languages = array('EN'=>'English','MS'=>'Bahasa Malaysia');
									foreach($languages as $code=>$name) {
										?>
										<div class="row p-0 m-0">
											<div class="col-md-4"><?php echo $name; ?> (<?php echo $code; ?>)</div>
											<div class="col-md-8">
												<div class="switch">
													<label>
														<span class="hidden-xs"></span>
														<input type="checkbox"
																name="language[<?php echo $code; ?>]"
																value="1" <?php echo ($lang && in_array($code,$lang)) ? "checked" : NULL; ?>
																<?php echo (!$started) ? NULL : "disabled"; ?> />
														<span class="lever"></span>
														<span class="hidden-xs"></span>
													</label>
												</div>
											</div>
										</div>
										<?php
									}
									?>
								</div>
							</div>
						
							<!-- SETTING -->
							<div class="form-group">
								<label class="col-xs-12 registration-form-label"><?php echo $this->lang->line('setting'); ?></label>
								<div class="col-xs-12">									
									<div class="helper">
										<ul>
											<li><?php echo $this->lang->line('settingHelper'); ?></li>
										</ul>
									</div>
									
									<div class="row p-0 m-0">
										<div class="col-md-4"><?php echo $this->lang->line('showRes'); ?></div>
										<div class="col-md-8">
											<div class="switch">
												<label>
													<span class="hidden-xs"><?php echo $this->lang->line('y'); ?></span>
													<input type="checkbox" name="showResultToVoter" <?php echo (!$started) ? NULL : "disabled"; ?>
																 value="1" <?php echo ($project && $project['showResultToVoter']) ? "checked" : NULL; ?> />
													<span class="lever"></span>
													<span class="hidden-xs"><?php echo $this->lang->line('n'); ?></span>
												</label>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
						
						<div class="box-footer p-1-l p-1-r">
							<div class="flex-btn-group">
								<?php
								if(!$started) {
									?>
									<button type="submit" class="btn btn-block btn-success"><i class="fa fa-check"></i>&nbsp;<?php echo $this->lang->line('save'); ?></button>
									<?php
								}
								?>
								<a href="<?php echo base_url(); ?>project" class="btn btn-danger"><i class="fa fa-backward"></i>&nbsp;<?php echo $this->lang->line('back'); ?></a>
							</div>
						</div>
					</div>		
				</form>
			</div>
			
			<div class="col-md-6">
			<?php $this->load->view('project/guide',NULL); ?>
			</div>
		</div>
	</div>
	
</div>
	
<!-- CONFIRMATION STOP PROJECT MODAL -->		
<div class="modal fade" id="confirm_stop_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 $this->lang->line('confStop'); ?></h3>
			</div>
			
			<div class="modal-body">
				<form class="form-horizontal" method="post" action="<?php echo base_url(); ?>project/stop" id="stop_project_form">
					<h4 class="m-1-y text-center"><?php echo $this->lang->line('confStopHelper1'); ?></h4>
					<h4 class="m-1-y text-center"><?php echo $this->lang->line('confStopHelper2'); ?></h4>
					<h4 class="m-1-y text-center"><?php echo $this->lang->line('confStopHelper3'); ?></h4>
					<input type="hidden" id="stop_project_id" name="projectID" value="" />
					
					<div class="row">
						<div class="col-md-offset-4 col-md-4">
							<div class="form-group">
								<label class="col-xs-12"><?php echo $this->lang->line('pwd'); ?></label>
								<input type="password" class="form-control validate[required]" name="userpass" id="userpass" value="" />
								<div class="helper helper-xs"><?php echo $this->lang->line('pwdHelper'); ?></div>
							</div>
							
							<div class="form-group">
								<label class="col-xs-12"><?php echo $this->lang->line('confPwd'); ?></label>
								<input type="password" class="form-control validate[required]" name="userpassconf" id="userpassconf" value="" />
								<div class="helper helper-xs"><?php echo $this->lang->line('confPwdHelper'); ?></div>
							</div>
						</div>
					</div>
					
					<div class="row">
						<div class="col-md-offset-4 col-md-4">
							<div class="flex-btn-group">
								<button type="submit" class="btn btn-success"><i class="fa fa-check"></i>&nbsp;<?php echo $this->lang->line('y'); ?></button>
								<button type="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>
				</form>
			</div>
		</div>
	</div>
</div>

<script>
$(function() {
	$('form#project_form').off('submit').on('submit',function() {
		if ($(this).validationEngine('validate')) {
			var proceed = true;
			
			var title = $.trim(	$('#title').val()	);
			if(title == "") { proceed =  false; $('#title').validationEngine('showPrompt', '<?php echo $this->lang->line('enterTitle'); ?>', 'load','bottomRight',1); }
			if(!proceed) return false;
			
			var startDT = $.trim(	$('#startDT').val()	);
			if(startDT == "") { proceed =  false; $('#startDT').validationEngine('showPrompt', '<?php echo $this->lang->line('enterStart'); ?>', 'load','bottomRight',1); }
			if(!proceed) return false;
			
			openLoader();
			return true;
		} else {
			return false;
		}
	});
	
	$('form#stop_project_form').off('submit').on('submit',function() {
		if ($(this).validationEngine('validate')) {
			var proceed = true;
			
			var userpass = $.trim(	$('#userpass').val()	);
			if(userpass == "") {
				proceed =  false;
				$('#userpass').validationEngine('showPrompt', '<?php echo $this->lang->line('enterPass'); ?>', 'load','bottomRight',1);
				$('#userpass').parents('.form-group').eq(0).addClass('has-error');
			}
			if(!proceed) return false;
			
			var userpassconf = $.trim(	$('#userpassconf').val()	);
			if(userpassconf == "") {
				proceed =  false;
				$('#userpassconf').validationEngine('showPrompt', '<?php echo $this->lang->line('enterPassConf'); ?>', 'load','bottomRight',1);
				$('#userpassconf').parents('.form-group').eq(0).addClass('has-error');
			}
			if(!proceed) return false;
			
			if(userpassconf != userpass) {
				proceed =  false;
				$('#userpass').validationEngine('showPrompt', '<?php echo $this->lang->line('passConfNotMatch'); ?>', 'load','bottomRight',1);
				$('#userpass').parents('.form-group').eq(0).addClass('has-error');
				$('#userpassconf').validationEngine('showPrompt', '<?php echo $this->lang->line('passConfNotMatch'); ?>', 'load','bottomRight',1);
				$('#userpassconf').parents('.form-group').eq(0).addClass('has-error');
			}
			if(!proceed) return false;
			
			openLoader();
			$('#confirm_stop_modal').modal('hide');
			return true;
		} else {
			return false;
		}
	});
	
	$('#userpass').off('change').on('change',function() {
		$('#userpass').parents('.form-group').eq(0).removeClass('has-error');
		var userpass = $.trim(	$('#userpass').val()	);
		
		if(userpass == "") {
			$('#userpass').validationEngine('showPrompt', '<?php echo $this->lang->line('enterPass'); ?>', 'load','bottomRight',1);
			$('#userpass').parents('.form-group').eq(0).addClass('has-error');
		}
	});
	
	$('#userpassconf').off('change').on('change',function() {
		$('#userpassconf').parents('.form-group').eq(0).removeClass('has-error');
		
		var userpass = $.trim(	$('#userpass').val()	);
		var userpassconf = $.trim(	$('#userpassconf').val()	);
		
		if(userpassconf == "") {
			$('#userpassconf').validationEngine('showPrompt', '<?php echo $this->lang->line('enterNewPassConf'); ?>', 'load','bottomRight',1);
			$('#userpassconf').parents('.form-group').eq(0).addClass('has-error');
		} else {		
			if(userpassconf != userpass) {
				$('#userpassconf').validationEngine('showPrompt', '<?php echo $this->lang->line('newPassConfNotMatch'); ?>', 'load','bottomRight',1);
				$('#userpassconf').parents('.form-group').eq(0).addClass('has-error');
			}
		}
	});
	
	$('.uploader input[type="file"]').off('change').on('change', function() {
		var $img = $(this).siblings('img').eq(0);
		var input = this;
		
		if (input.files && input.files[0]) {
			$img.attr('src', '');
			var reader = new FileReader();			
			reader.onload = function (e) {
				$img.attr('src', e.target.result);
			}			
			reader.readAsDataURL(input.files[0]);
		}	
		$(this).siblings('input[type="hidden"]').val('0');
	});
	
	$('.datepick').datetimepicker({ format: 'DD-MM-YYYY hh:mm a' });
	
	$("#color").spectrum({ preferredFormat: "hex", color: "#<?php echo ($project && $project['color']) ? str_replace('#','',$project['color']) : 'd4d8dc'; ?>" });
});

function stopProject(me) {	
	var id = Number($('#ID').val());	
	$('#stop_project_id').val(id);
	$('#userpass').val('');
	$('#userpassconf').val('');
	
	closeLoader();
	$('#confirm_stop_modal').modal('show');
}

function clearBannerImage(me) {
	var $u = $(me).parents('.form-group').eq(0).find('.uploader').eq(0);	
	var $i = $u.find('img').eq(0);
	var def = '<?php echo base_url(); ?>dist/img/_sys/banner.png';
	
	if(	$.trim(	$i.attr('src')	) == def ) return;
	
	if(confirm('<?php echo $this->lang->line('confResetBanner'); ?>')) {
		$i.attr('src',def);
		$i.siblings('input[type="hidden"]').val('1');
	}
}

function clearColor() {
	if(confirm('<?php echo $this->lang->line('confResetBg'); ?>')) {
		$("#color").spectrum("set", '#d4d8dc');
	}
}

function deleteProject() { return confirm('<?php echo $this->lang->line('delConfirm'); ?>'); }
</script>




























