<title>Cumpara Puncte Premium - <?php echo Config::$_SITE_NAME; ?></title>
</div>
	<div class="main-content">
			<div class="breadcrumbs" id="breadcrumbs">
				<script type="text/javascript">
					try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
				</script>

				<ul class="breadcrumb">
					<li>
						<i class="ace-icon fa fa-home home-icon"></i>
						<a href="<?php echo Config::$_PAGE_URL; ?>">Home</a>
					</li>
					<li class="active">Cumpara Puncte Premium</li>
				</ul><!-- /.breadcrumb -->

				<div class="nav-search" id="nav-search">
					<form method="POST" action="search">
						<span class="input-icon">
							<input type="text" placeholder="Search ..." name="sname" id="username" type="submit" class="nav-search-input" autocomplete="on"> 
							<i class="ace-icon fa fa-search nav-search-icon"></i>
						</span>
					</form>
				</div> <!-- /.nav-search -->
			</div>	
<div class="page-content">
	<div class="row-fluid">
		<div class="span12">

<?php
if(!defined('panel'))
	die('Nope.');
if(!isset($_SESSION['user'])) { echo '<meta http-equiv="refresh" content="0;URL=\''.Config::$_PAGE_URL.'login\'/>'; } else {

if(isset($_POST['submit'])) {
	if(!$_POST['PINpsc']) { echo '<div class="alert alert-danger">Introdu un PIN corect!</div>'; }
	else if(!$_POST['PINsum']) echo '<div class="alert alert-danger">Introdu o suma a PIN-ului!</div>';
	else { 
		echo '<div class="alert alert-success">PIN adaugat cu succes. Donatia va fi preluata de un owner in cel mai scurt timp.</div>';
		 echo '<meta http-equiv="refresh" content="5">';
		$q = Config::$g_con->prepare('INSERT INTO `donations` (`donatePIN`, `donateSUM`, `donateName`) VALUES (?, ?, ?)');
		$q->execute(array($_POST['PINpsc'],$_POST['PINsum'],Config::getData('users','name',$_SESSION['user'])));
	}
}
?>

<center>
<?php 
	$q = Config::$g_con->prepare('SELECT * FROM `donations` WHERE `donateName` = ? ORDER BY `donateID` DESC LIMIT 1');
	$q->execute(array(Config::getData('users','name',$_SESSION['user'])));
		$dnn = $q->fetch(PDO::FETCH_OBJ);
if(!$q->rowCount()) { ?>
<div class="col-xs-12 col-sm-4">
	<div class="widget-box">
		<div class="widget-body">
			<div class="widget-main">
			
				<form method="post">
					
					<label for="form-field-1">Introdu PIN-ul PaySafeCard</label><br />
					<input class="form-control input-mask-product"  id="form-field-1" name="PINpsc" type="text"/>
			
					<label for="form-field-select-1">Suma PIN-ului</label><br />
					<select class="form-control" id="form-field-select-1" name="PINsum">
						<option value=""></option>
						<option value="1">25</option>
						<option value="2">50</option>
						<option value="3">100</option>
						<option value="4">300</option>
					</select>
					<br />
					<button type="submit" name="submit" class="btn btn-sm btn-primary">Trimite</button>
				</form>
			</div>
		</div>
	</div>
</div>
<?php } else if($dnn->donateStatus == 0) {
	echo '<div class="alert alert-danger">Trebuie sa astepti sa iti fie confirmata ultima donatie!</div>';
} else { ?>
<div class="col-xs-12 col-sm-4">
	<div class="widget-box">
		<div class="widget-body">
			<div class="widget-main">
			
				<form method="post">
					
					<label for="form-field-1">Introdu PIN-ul PaySafeCard</label><br />
					<input class="form-control input-mask-product"  id="form-field-1" name="PINpsc" type="text"/>
			
					<label for="form-field-select-1">Suma PIN-ului</label><br />
					<select class="form-control" id="form-field-select-1" name="PINsum">
						<option value=""></option>
						<option value="1">25</option>
						<option value="2">50</option>
						<option value="3">100</option>
						<option value="4">300</option>
					</select>
					<br />
					<button type="submit" name="submit" class="btn btn-sm btn-primary">Trimite</button>
				</form>
			</div>
		</div>
	</div>
</div>
<?php } ?>
</div>

<center>
	<h2>Donatiile mele</h2>
</center>

	<div class="table-responsive">
		<table id="login-table" class="table table-striped table-hover table-bordered">
			<thead>
			<tr>
				<td>Name</td>
				<td>PIN</td>
				<td>Sum</td>
				<td><i class="fa fa-clock-o"></i> Date</td>
				<td>Status</td>
			</tr>	
			</thead>
			<tbody>
				<?php
					$q = Config::$g_con->prepare('SELECT * FROM `donations` WHERE `donateName` = ? ORDER BY `donateID` DESC');
					$q->execute(array(Config::getData('users','name',$_SESSION['user'])));
					while($row = $q->fetch(PDO::FETCH_OBJ)) {
						if($row->donateStatus == 0) {
							$status = "<span class='label label-info label-white middle'>In curs de verificare</span>";
						} else if($row->donateStatus == 1) {
							$status = "<span class='label label-success label-white middle'>Acceptata</span>";
						} else if($row->donateStatus == 2) {
							$status = "<span class='label label-danger label-white middle'>Invalid, PIN FOLOSIT</span>";
						} else if($row->donateStatus == 3) {
							$status = "<span class='label label-info label-white middle'>Achitata</span>";
						}
						if($row->donateSUM == 1) {
							$sum = "25";
						} else if($row->donateSUM == 2) {
							$sum = "50";
						} else if($row->donateSUM == 3) {
							$sum = "100";
						} else if($row->donateSUM == 4) {
							$sum = "300";
						}						
						echo 
						"<tr>			
							<td>{$row->donateName}</td>
							<td>{$row->donatePIN}</td>
							<td>" . $sum. " lei</td>
							<td>{$row->donateTime}</td>
							<td>" . $status . "</td>
						</tr>";
					}
				?>
			</tbody>
		</table>
	</div>	


		<!--[if !IE]> -->
		<script src="<?php echo Config::$_PAGE_URL; ?>assets/js/jquery.min.js"></script>

		<!-- <![endif]-->
		<script src="<?php echo Config::$_PAGE_URL; ?>assets/js/chosen.jquery.min.js"></script>
		<script src="<?php echo Config::$_PAGE_URL; ?>assets/js/autosize.min.js"></script>
		<script src="<?php echo Config::$_PAGE_URL; ?>assets/js/jquery.inputlimiter.1.3.1.min.js"></script>
		<script src="<?php echo Config::$_PAGE_URL; ?>assets/js/jquery.maskedinput.min.js"></script>

		<script type="text/javascript">
			jQuery(function($) {							
				$(".input-mask-product").mask("9999-9999-9999-9999",{placeholder:" ",completed:function(){alert("Codul PaySafe introdus este: "+this.val());}});		
			});
		</script>
		
<?php } ?>
