<title>Donatii - <?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">Donatii</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\'/>';
if(Config::getData('users','Admin',$_SESSION['user']) >= 6) {
	
if(isset($_POST['submit'])) {
	if($_POST['donatesum'] == 1) {
		$sum = "25";
	} else if($_POST['donatesum'] == 2) {
		$status = "50";
	} else if($_POST['donatesum'] == 3) {
		$sum = "100";
	} else if($_POST['donatesum'] == 4) {
		$sum = "300";
	}
		echo '<div class="alert alert-success">Actiune salvata cu succes.</div>';
		if($_POST['submit'] == 1) {
			$status1 = "Donatia ta in valoare de ". $sum ." lei a fost acceptata.";
		} if($_POST['submit'] == 2) {
			$status1 = "Donatia ta in valoare de ". $sum ." nu a fost finalizata cu succes. Motiv: PIN incorect/folosit deja.";
		} if($_POST['submit'] == 3) {
			$status1 = "Donatia ta in valoare de ". $sum ." a fost achitata cu succes.";
		}
		$em = Config::$g_con->prepare("INSERT INTO emails (Message, playerid,giverid) VALUES 
			('".$status1."', 
			'".Config::getID('users', 'id', $_POST['donatename'])."', 
			'".Config::getID('users', 'id', $_SESSION['user'])."')");
			$em->execute();
		$q = Config::$g_con->prepare('UPDATE `donations` SET `donateStatus` = ?, `donateAdminAction` = ? WHERE `donateID` = ?');
		$q->execute(array($_POST['submit'],date('Y-m-d H:i:s'),$_POST['donateid']));	
		
		//$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>
	<h2>Donatii</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>Suma</td>
				<td><i class="fa fa-clock-o"></i> Date</td>
				<td>Status</td>
				<td>Action</td>
			</tr>	
			</thead>
			<tbody>
				<?php
					$q = Config::$g_con->prepare('SELECT * FROM `donations` ORDER BY `donateID` DESC');
					$q->execute();
					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><b>{$row->donatePIN}</b></td>
							<td>" . $sum. " lei</td>
							<td>{$row->donateTime}</td>
							<td>" . $status . "</td>"; { ?>
							<td><form method="post">
								<div class="btn-group">
								<button class="btn btn-sm btn-yellow">Alege actiune</button>

								<button data-toggle="dropdown" class="btn btn-sm btn-yellow dropdown-toggle">
									<i class="ace-icon fa fa-angle-down icon-only"></i>
								</button>
							
								<ul class="dropdown-menu dropdown-yellow">
									<li>
										<button class="btn btn-link" type="submit" name="submit" value="1">Donatie acceptata</a>
										<input name="donateid" type="hidden" value="<?php echo $row->donateID ?>">
										<input name="donatename" type="hidden" value="<?php echo $row->donateName ?>">
										<input name="donatesum" type="hidden" value="<?php echo $row->donateSUM ?>">
									</li>
									<li>
										<button class="btn btn-link" type="submit" name="submit" Value="2">PIN incorect</a>
										<input name="donateid" type="hidden" value="<?php echo $row->donateID ?>">
										<input name="donatename" type="hidden" value="<?php echo $row->donateName ?>">
										<input name="donatesum" type="hidden" value="<?php echo $row->donateSUM ?>">										
									</li>
									<li>
										<button class="btn btn-link" type="submit" name="submit" Value="3">Donatie achitata</a>
										<input name="donateid" type="hidden" value="<?php echo $row->donateID ?>">
										<input name="donatename" type="hidden" value="<?php echo $row->donateName ?>">
										<input name="donatesum" type="hidden" value="<?php echo $row->donateSUM ?>">
									</li>
								</ul>
							</form>	
													
							</td></div>
						<?php } echo"</tr>";
					}
				?>
			</tbody>
		</table>
	</div>
<?php } else  echo '<meta http-equiv="refresh" content="0;URL=\''.Config::$_PAGE_URL.'\'/>';
