<?php
include('../config/config.php');
include(ADMIN_HTML.'html.inc.php');
include(ADMIN_INCLUDES.'functions.php');
checkLoginAdmin();

// Delete News
if ( isset($_GET['event']) && !empty($_GET['event']) ){
	
	$eventFile = clean(base64_decode($_GET['img']));
	mysql_query("DELETE FROM tbl_candidate WHERE Id = '".clean(base64_decode($_GET['event']))."'");
	
	deleteFile(UPLOADS_PATH.'partylogo/', $eventFile); // Delete the file
	deleteFile(UPLOADS_PATH.'partylogo/thumbs/', 'thumb_'.$eventFile); // Delete the thumbnail of the file
	
	$redirectUrl = 'view-candidates.php';
	$_SESSION['succesMessage'] = 6;
	
	header("Location: $redirectUrl");
	exit;
}

startHtml($title = "View Events");
tophead($title);
leftNav();
?>

<?php
	if ( isset($_SESSION['succesMessage']) ){
		successMsg($_SESSION['succesMessage']);
		unset($_SESSION['succesMessage']);
	}
?>

<section id="main" class="column">
    <article class="module width_full">
        <header>
            <h3 class="tabs_involved">Candidates Management</h3>
            <ul class="tabs">
                <li class="active"><a href="<?php echo ADMIN_URL;?>add-candidate.php">Add Record</a></li>
            </ul>
        </header>
        <table class="display data-table" id="myTable">
            <thead>
                <tr>
                    <th width="50">Rec.#</th>
                    <th width="250">Name</th>
                    <th width="250">Description</th>
                    <th width="90">Party</th>
                    <th width="90">Action</th>
                </tr>
            </thead>
            <tbody>
             <?php
			$getRes = mysql_query("SELECT Id, Logo, Name, Description, Logo FROM tbl_candidate ORDER BY Id DESC");
            $count = 1;
            while( $row = mysql_fetch_array($getRes) )
			{
        	?>
                <tr>
                    <td align="right"><?php echo $count;?></td>
                    <td><?php echo $row['Name'];?></td>
                    <td><?php echo nl2br($row['Description']);?></td>
                    <td align="center">
                    	<a href="<?php echo UPLOADS_URL.'partylogo/'.$row['Logo'];?>" class="lightbox">
                        	<img src="<?php echo UPLOADS_URL.'partylogo/thumbs/thumb_'.$row['Logo'];?>" />
                        </a>
                    </td>
                    <td align="center">
                    	<a href="<?php ADMIN_URL;?>edit-candidate.php?event=<?php echo base64_encode($row['Id']);?>"><img src="images/icn_edit.png" /></a>
                        |
                        <a href="<?php ADMIN_URL;?>view-candidates.php?event=<?php echo base64_encode($row['Id']);?>&img=<?php echo base64_encode($row['Logo'])?>"><img src="images/icn_trash.png" onclick="return confirm('Are you sure you want to delete the selected record?')" /></a>
                    </td>
                </tr>
                <?php 
            $count++;
            }
        	?>
            </tbody>
        </table>
    </article>
    <div class="spacer"></div>
</section>

<script type="text/javascript" src="<?php echo LIGHTBOX;?>js/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo LIGHTBOX;?>themes/default/jquery.lightbox.css" />
<!--[if IE 6]><link rel="stylesheet" type="text/css" href="<?php echo LIGHTBOX;?>themes/default/jquery.lightbox.ie6.css" /><![endif]-->
<script type="text/javascript" src="<?php echo LIGHTBOX;?>js/jquery.lightbox.js"></script>
<script type="text/javascript">
	jQuery.noConflict();
	jQuery(document).ready(function(){
		jQuery('.lightbox').lightbox();
	});
</script>

<?php
endHtml();
?>