</div><div class="main-content">
<?php
if(!defined('panel'))
	die('Nope.');
if(!isset($_SESSION['user']) && !isset(Config::$_url[1])) echo '<meta http-equiv="refresh" content="0;URL=\''.Config::$_PAGE_URL.'login\'/>';
if(isset(Config::$_url[1])) $user = (int)Config::$_url[1];
else $user = $_SESSION['user'];
$q = Config::$g_con->prepare('SELECT * FROM `factions` WHERE `ID` = ?');
$q->execute(array($user));
if(!$q->rowCount()) {
	echo '
<title>Error! Invalid ID</title>
	<div class="breadcrumbs" id="breadcrumbs">
		<ul class="breadcrumb">
			<li>
				<i class="icon-home home-icon"></i>
				<a href="../">Home</a>
			</li>
			<li>
				<a href="../factionslist">Factions</a>
			</li>
			<li class="active">Invalid ID.</li>
		</ul>

		<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="alert alert-danger">Error! Invalid ID.</div>';
	echo '<meta http-equiv="refresh" content="0;URL=\''.Config::$_PAGE_URL.'factionslist\'/>';
	return;
}

if(isset($_POST['submit']))
{

	$q = Config::$g_con->prepare('SELECT * FROM `factions` WHERE `ID` = ?');
	$q->execute(array(Config::$_url[1]));
	while($dnn = $q->fetch(PDO::FETCH_OBJ)) {
	
	if($_POST['q_1'] == "") { $r1 = ""; $q1 = ""; } else $r1 = htmlspecialchars($_POST['q_1']); $q1 = Config::getData('factions','q1',$dnn->ID);
	if($_POST['q_2'] == "") { $r2 = ""; $q2 = ""; } else $r2 = htmlspecialchars($_POST['q_2']); $q2 = Config::getData('factions','q2',$dnn->ID);
	if($_POST['q_3'] == "") { $r3 = ""; $q3 = ""; } else $r3 = htmlspecialchars($_POST['q_3']); $q3 = Config::getData('factions','q3',$dnn->ID);
	if($_POST['q_4'] == "") { $r4 = ""; $q4 = ""; } else $r4 = htmlspecialchars($_POST['q_4']); $q4 = Config::getData('factions','q4',$dnn->ID);
	if($_POST['q_5'] == "") { $r5 = ""; $q5 = ""; } else $r5 = htmlspecialchars($_POST['q_5']); $q5 = Config::getData('factions','q5',$dnn->ID);
	if($_POST['q_6'] == "") { $r6 = ""; $q6 = ""; } else $r6 = htmlspecialchars($_POST['q_6']); $q6 = Config::getData('factions','q6',$dnn->ID);
	if($_POST['q_7'] == "") { $r7 = ""; $q7 = ""; } else $r7 = htmlspecialchars($_POST['q_7']); $q7 = Config::getData('factions','q7',$dnn->ID);
	if($_POST['q_8'] == "") { $r8 = ""; $q8 = ""; } else $r8 = htmlspecialchars($_POST['q_8']); $q8 = Config::getData('factions','q8',$dnn->ID);
	if($_POST['q_9'] == "") { $r9 = ""; $q9 = ""; } else $r9 = htmlspecialchars($_POST['q_9']); $q9 = Config::getData('factions','q9',$dnn->ID);
	if($_POST['q_10'] == "") { $r10 = ""; $q10 = ""; } else $r10 = htmlspecialchars($_POST['q_10']); $q10 = Config::getData('factions','q10',$dnn->ID);
	if($_POST['q_11'] == "") { $r11 = ""; $q11 = ""; } else $r11 = htmlspecialchars($_POST['q_11']); $q11 = Config::getData('factions','q11',$dnn->ID);
	if($_POST['q_12'] == "") { $r12 = ""; $q12 = ""; } else $r12 = htmlspecialchars($_POST['q_12']); $q12 = Config::getData('factions','q12',$dnn->ID);
	if($_POST['q_13'] == "") { $r13 = ""; $q13 = ""; } else $r13 = htmlspecialchars($_POST['q_13']); $q13 = Config::getData('factions','q13',$dnn->ID);
	if($_POST['q_14'] == "") { $r14 = ""; $q14 = ""; } else $r14 = htmlspecialchars($_POST['q_14']); $q14 = Config::getData('factions','q14',$dnn->ID);
	if($_POST['q_15'] == "") { $r15 = ""; $q15 = ""; } else $r15 = $_POST['q_15']; $q15 = Config::getData('factions','q15',$dnn->ID);	
	
	$q = Config::$g_con->prepare('INSERT INTO `aplications` SET `name` = ?, 
		`r1` = ?, `r2` = ?, `r3` = ?, `r4` = ?, `r5` = ?, `r6` = ?, `r7` = ?, `r8` = ?, `r9` = ?, `r10` = ?, `r11` = ?, `r12` = ?, `r13` = ?, `r14` = ?, `r15` = ?, 
		`q1` = ?, `q2` = ?, `q3` = ?, `q4` = ?, `q5` = ?, `q6` = ?, `q7` = ?, `q8` = ?, `q9` = ?, `q10` = ?, `q11` = ?, `q12` = ?, `q13` = ?, `q14` = ?, `q15` = ?, 
		`factionid` = ?, `playerid` = ?');
	$q->execute(array(Config::getData('users','name',$_SESSION['user']),
	$r1,$r2,$r3,$r4,$r5,$r6,$r7,$r8,$r9,$r10,$r11,$r12,$r13,$r14,$r15,
	Config::getData('factions','q1',$dnn->ID),Config::getData('factions','q2',$dnn->ID),Config::getData('factions','q3',$dnn->ID),Config::getData('factions','q4',$dnn->ID),Config::getData('factions','q5',$dnn->ID),Config::getData('factions','q6',$dnn->ID),Config::getData('factions','q7',$dnn->ID),Config::getData('factions','q8',$dnn->ID),Config::getData('factions','q9',$dnn->ID),Config::getData('factions','q10',$dnn->ID),Config::getData('factions','q11',$dnn->ID),Config::getData('factions','q12',$dnn->ID),Config::getData('factions','q13',$dnn->ID),Config::getData('factions','q14',$dnn->ID),Config::getData('factions','q15',$dnn->ID),
	$dnn->ID,Config::getData('users','id',$_SESSION['user'])));
	echo '<meta http-equiv="refresh" content="0;URL=\''.Config::$_PAGE_URL.'applications/'.Config::$_url[1].'/>';
	}	
}	
if(isset($_SESSION['user'])) {

?>

<?php
	$q = Config::$g_con->prepare('SELECT * FROM `factions` WHERE `ID` = ?');
	$q->execute(array(Config::$_url[1]));
	while($dnn = $q->fetch(PDO::FETCH_OBJ)) { ?>
<title>Apply to <?php echo Config::$factions[$dnn->ID]; ?><?php } ?> - <?php echo Config::$_SITE_NAME; ?></title>

			<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>
						<a href="<?php echo Config::$_PAGE_URL; ?>factionlist">Factions</a>
					</li>
					<?php
						$q = Config::$g_con->prepare('SELECT * FROM `factions` WHERE `ID` = ?');
						$q->execute(array(Config::$_url[1]));
							while($dnn = $q->fetch(PDO::FETCH_OBJ)) { ?>	
					<li>
						<a href="<?php echo Config::$_PAGE_URL; ?>applications/<?php echo $dnn->ID; ?>">Faction Applications</a>
					</li>
					<li class="active">
						Apply to <?php echo Config::$factions[$dnn->ID]; ?>	
					</li>
					<?php } ?>
				</ul>

				<div class="nav-search" id="nav-search">
					<form method="POST" action="<?php echo Config::$_PAGE_URL; ?>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">

<?php	
	$q = Config::$g_con->prepare('SELECT * FROM `factions` WHERE `ID` = ?');
	$q->execute(array(Config::$_url[1]));
	while($dnn = $q->fetch(PDO::FETCH_OBJ))
	if($dnn->Application == 0) { echo '<meta http-equiv="refresh" content="5;URL=\''.Config::$_PAGE_URL.'factionslist\'/>';
		die ('<div class="alert alert-danger">Aplica&#355;iile pentru fac&#355;iunea <b>'.Config::$factions[$dnn->ID].'</b> sunt momentan &#238;nchise.</div>');
	} 

	$q = Config::$g_con->prepare("SELECT * FROM `aplications` WHERE `name` = ?");
	$q->execute(array(Config::getData("users", "name", $_SESSION['user'])));
	while($dnn = $q->fetch(PDO::FETCH_OBJ))
	if($dnn->status == 0 or $dnn->status == 1) { 
		die ('<div class="alert alert-danger">Ai depus deja o aplica&#355;ie pentru <b>'.Config::$factions[$dnn->factionid].'</b>, nu mai po&#355;i depune &#238;nc&#259; una.</div>');
	}
?>


<?php if(Config::getData('users','Member',$_SESSION['user']) or Config::getData('users','Leader',$_SESSION['user']) != 0 || Config::getData('users','Level',$_SESSION['user']) < 3 || Config::getData('users','Fpunish',$_SESSION['user']) >= 1)  {  ?>
<div class="alert alert-block alert-danger">
Pentru a aplica, trebuie s&#259; fii Civil, s&#259; ai 0 Faction Punish-uri &#351;i level 3+.
</div>

 <?php } else {
 
	$q = Config::$g_con->prepare('SELECT * FROM `factions` WHERE `ID` = ?');
	$q->execute(array(Config::$_url[1]));
	while($dnn = $q->fetch(PDO::FETCH_OBJ)) { ?>

<h3>Aplic&#259; pentru <?php echo Config::$factions[$dnn->ID]; ?></h3>
			
<hr>


<div class="alert alert-info">
Poti avea o singura aplicatie deschisa. Daca aplici la aceasta factiune, nu vei putea aplica la o alta factiune pana aplicatia nu este respinsa sau iti stergi aplicatia.
</div>

<form name="login_form"  id="login_form" action="" method="post">
		<?php if(Config::getData('factions','q1',$dnn->ID) != "") { ?>
		<?php echo Config::getData('factions','q1',$dnn->ID); ?>:<br>
		<textarea name='q_1' class="span6" rows="2" required></textarea>
		<br><br><br>
		<?php } else echo '<input name="q_1" type="hidden" value="">'; ?>

		<?php if(Config::getData('factions','q2',$dnn->ID) != "") { ?>
		<?php echo Config::getData('factions','q2',$dnn->ID); ?>:<br>
		<textarea name='q_2' class="span6" rows="2" required></textarea>
		<br><br><br>
		<?php } else echo '<input name="q_2" type="hidden" value="">'; ?>

		<?php if(Config::getData('factions','q3',$dnn->ID) != "") { ?>
		<?php echo Config::getData('factions','q3',$dnn->ID); ?>:<br>
		<textarea name='q_3' class="span6" rows="2" required></textarea>
		<br><br><br>
		<?php } else echo '<input name="q_3" type="hidden" value="">'; ?>

		<?php if(Config::getData('factions','q4',$dnn->ID) != "") { ?>
		<?php echo Config::getData('factions','q4',$dnn->ID); ?>:<br>
		<textarea name='q_4' class="span6" rows="2" required></textarea>
		<br><br><br>
		<?php } else echo '<input name="q_4" type="hidden" value="">'; ?>

		<?php if(Config::getData('factions','q5',$dnn->ID) != "") { ?>
		<?php echo Config::getData('factions','q5',$dnn->ID); ?>:<br>
		<textarea name='q_5' class="span6" rows="2" required></textarea>
		<br><br><br>
		<?php } else echo '<input name="q_5" type="hidden" value="">'; ?>

		<?php if(Config::getData('factions','q6',$dnn->ID) != "") { ?>
		<?php echo Config::getData('factions','q6',$dnn->ID); ?>:<br>
		<textarea name='q_6' class="span6" rows="2" required></textarea>
		<br><br><br>
		<?php } else echo '<input name="q_6" type="hidden" value="">'; ?>

		<?php if(Config::getData('factions','q7',$dnn->ID) != "") { ?>
		<?php echo Config::getData('factions','q7',$dnn->ID); ?>:<br>
		<textarea name='q_7' class="span6" rows="2" required></textarea>
		<br><br><br>
		<?php } else echo '<input name="q_7" type="hidden" value="">'; ?>

		<?php if(Config::getData('factions','q8',$dnn->ID) != "") { ?>
		<?php echo Config::getData('factions','q8',$dnn->ID); ?>:<br>
		<textarea name='q_8' class="span6" rows="2" required></textarea>
		<br><br><br>
		<?php } else echo '<input name="q_8" type="hidden" value="">'; ?>

		<?php if(Config::getData('factions','q9',$dnn->ID) != "") { ?>
		<?php echo Config::getData('factions','q9',$dnn->ID); ?>:<br>
		<textarea name='q_9' class="span6" rows="2" required></textarea>
		<br><br><br>
		<?php } else echo '<input name="q_9" type="hidden" value="">'; ?>

		<?php if(Config::getData('factions','q10',$dnn->ID) != "") { ?>
		<?php echo Config::getData('factions','q10',$dnn->ID); ?>:<br>
		<textarea name='q_10' class="span6" rows="2" required></textarea>
		<br><br><br>
		<?php } else echo '<input name="q_10" type="hidden" value="">'; ?>

		<?php if(Config::getData('factions','q11',$dnn->ID) != "") { ?>
		<?php echo Config::getData('factions','q11',$dnn->ID); ?>:<br>
		<textarea name='q_11' class="span6" rows="2" required></textarea>
		<br><br><br>
		<?php } else echo '<input name="q_11" type="hidden" value="">'; ?>

		<?php if(Config::getData('factions','q12',$dnn->ID) != "") { ?>
		<?php echo Config::getData('factions','q12',$dnn->ID); ?>:<br>
		<textarea name='q_12' class="span6" rows="2" required></textarea>
		<br><br><br>
		<?php } else echo '<input name="q_12" type="hidden" value="">'; ?>

		<?php if(Config::getData('factions','q13',$dnn->ID) != "") { ?>
		<?php echo Config::getData('factions','q13',$dnn->ID); ?>:<br>
		<textarea name='q_13' class="span6" rows="2" required></textarea>
		<br><br><br>
		<?php } else echo '<input name="q_13" type="hidden" value="">'; ?>

		<?php if(Config::getData('factions','q14',$dnn->ID) != "") { ?>
		<?php echo Config::getData('factions','q14',$dnn->ID); ?>:<br>
		<textarea name='q_14' class="span6" rows="2" required></textarea>
		<br><br><br>
		<?php } else echo '<input name="q_14" type="hidden" value="">'; ?>

		<?php if(Config::getData('factions','q15',$dnn->ID) != "") { ?>
		<?php echo Config::getData('factions','q15',$dnn->ID); ?>:<br>
		<textarea name='q_15' class="span6" rows="2" required></textarea>
		<br><br><br>
		<?php } else echo '<input name="q_15" type="hidden" value="">'; ?>
<br />
<input type="submit" name="submit" value="Aplica!" class="btn btn-info btn-small"/>
</form>
 
 <?php } } ?>
</div>
</div>
</div>
</div>
</div>
<?php } else echo '<meta http-equiv="refresh" content="0;URL=\''.Config::$_PAGE_URL.'login\'/>';	 ?>
