<?php
/****************************************************************************/
/* ATutor																	*/
/****************************************************************************/
/* Copyright (c) 2002-2010                                                  */
/* Inclusive Design Institute                                               */
/* http://atutor.ca															*/
/*																			*/
/* This program is free software. You can redistribute it and/or			*/
/* modify it under the terms of the GNU General Public License				*/
/* as published by the Free Software Foundation.							*/
/****************************************************************************/
// $Id$

define('AT_INCLUDE_PATH', '../../../../include/');
require(AT_INCLUDE_PATH.'vitals.inc.php');
require(AT_INCLUDE_PATH.'../mods/_core/themes/lib/themes.inc.php');
admin_authenticate(AT_ADMIN_PRIV_ADMIN);

if (isset($_POST['delete'], $_POST['auto_enroll_id'])) {
	header('Location: auto_enroll_delete.php?auto_enroll_id='.$_POST['auto_enroll_id']);
	exit;
} else if (isset($_POST['edit'], $_POST['auto_enroll_id'])) {
	header('Location: auto_enroll_edit.php?auto_enroll_id='.$_POST['auto_enroll_id']);
	exit;
} else if (!empty($_POST)) {
	$msg->addError('NO_ITEM_SELECTED');
}

require(AT_INCLUDE_PATH.'header.inc.php'); 

?>
<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table summary="" class="data" align="center" style="width: 95%;">

<thead>
<tr>
	<th scope="col">&nbsp;</th>
	<th scope="col"><?php echo _AT('name'); ?></th>
	<th scope="col"><?php echo _AT('courses'); ?></th>
	<th scope="col"><?php echo _AT('url'); ?></th>
</tr>
</thead>
<tfoot>
<tr>
	<td colspan="4">
		<div class="row buttons">
		<input type="submit" name="edit" value="<?php echo _AT('edit'); ?>" /> <input type="submit" name="delete" value="<?php echo _AT('delete'); ?>" /> 
		</div>
	</td>
</tr>
</tfoot>
<tbody>
<?php

$sql	= "SELECT * FROM ".TABLE_PREFIX."auto_enroll ae ORDER BY name";
$rows_ae = queryDB($sql, array(TABLE_PREFIX));

if(count($rows_ae) > 0){
    foreach($rows_ae as $row){
		$courses = "";
		$sql_courses = "SELECT c.title FROM %sauto_enroll_courses aec, %scourses c 
		          WHERE aec.auto_enroll_id = %d
		            AND aec.course_id = c.course_id
		          ORDER BY c.title";
		$rows_courses = queryDB($sql_courses, array(TABLE_PREFIX, TABLE_PREFIX, $row['auto_enroll_id']));
		
        foreach($rows_courses as $row_courses){
			$courses .= $row_courses["title"] . "<br>";
			}
	?>
		<tr onmousedown="document.form['m<?php echo $row['auto_enroll_id']; ?>'].checked = true; rowselect(this);" id="r_<?php echo $row['auto_enroll_id']; ?>">
			<td width="10"><input type="radio" name="auto_enroll_id" value="<?php echo $row['auto_enroll_id']; ?>" id="m<?php echo $row['auto_enroll_id']; ?>" /></td>
			<td><label for="m<?php echo $row['auto_enroll_id']; ?>"><?php if ($row['name']=="") echo _AT('na'); else echo $row['name']; ?></label></td>
			<td><?php echo $courses; ?></td>
			<td nowrap><?php echo $_base_href. "registration.php?en_id=". $row['associate_string']; ?></td>
		</tr>
	<?php } ?>

<?php }else{ ?>
	<tr>
		<td colspan="4"><?php echo _AT('none_found'); ?></td>
	</tr>
<?php } ?>
</tbody>
</table>

</form>


<?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>