<?php TPL::output('admin/global/header.tpl.htm'); ?>

<!--left-->
<?php TPL::output('admin/global/left.tpl.htm'); ?>
<!--left-->

<!-- main -->
<div id="main-content">
	<div class="clear"></div>
	<div class="content-box">
		<div class="content-box-header">
			<h3>User group management</h3>
			<ul class="content-box-tabs">
				<li><a href="#tab1" class="default-tab current">Usergroup list</a></li>
				<li><a href="#tab2" class="">Create usergroup</a></li>
			</ul>
			<div class="clear"></div>
		</div>
		<div class="content-box-content">
			<div class="tab-content default-tab" id="tab1">				
				<?php if ($this->groups_list) { ?>
				<table class="list">
					<thead>
						<tr>
							<th width="60%">Usergroup name</th>
							<th>Number of users</th>
							<th>Created time</th>
							<th>Operation</th>
						</tr>
					</thead>
					<tbody style="border-bottom: 1px solid #ddd;">
						<?php foreach ($this->groups_list AS $key => $val) { ?>
						<tr>
							<td><?php echo $val['title']; ?></td>
							<td><?php echo $val['users']; ?></td>
							<td><?php echo date_friendly($val['time']); ?></a>
							<td><a href="admin/edm/remove_group/<?php echo $val['id']; ?>" onclick="if (confirm('Confirm to delete the usergroup?')) { window.location = this.href; } return false;">Delete</a></td>
						</tr>
						<?php } ?>
					</tbody>
					<tfoot>
						<tr>
							<td colspan="4">
								<div class="pagination"><?php echo $this->pagination; ?></div>
								<div class="clear"></div>
							</td>
						</tr>
					</tfoot>
				</table>
				<?php } ?>
			</div>
			
			<div class="tab-content" id="tab2" style="display:none;">
				<form action="admin/edm/add_group/" method="post">
				
				<fieldset> <!-- Set class to "column-left" or "column-right" on fieldsets to divide the form into columns -->	
					<p>
						<label>Usergroup name</label>
							<input class="text-input small-input" type="text" name="title" />
					</p>
					
					<p>
						<label>Import method</label>              
						<select name="import_type" id="import_type" class="small-input" onchange="set_import_type(this.value)">
							<option value="text">Text</option>
							<option value="system_group">System usergroup</option>
							<option value="reputation_group">Credited usergroup</option>
							<option value="last_active">Latest active time</option>
						</select> 
					</p>
					
					<div id="option_text" class="hidden_option" style="display:none">
						<p>
							<label>Email list</label>
							<small>One Email address per row</small><br />
							<textarea class="text-input textarea" name="email" cols="79" rows="15"></textarea>
						</p>
					</div>
					
					<div id="option_system_group" class="hidden_option" style="display:none">
						<p>
							<label>System usergroup</label><br />
							
							<?php foreach ($this->system_user_group AS $key => $val) { ?>
							<input type="checkbox" name="user_groups[]" value="<?php echo $val['group_id']; ?>" /> <?php echo $val['group_name']; ?> &nbsp; 
							<?php } ?>
						</p>
					</div>
					
					<div id="option_reputation_group" class="hidden_option" style="display:none">
						<p>
							<label>Credited usergroup</label><br />
							
							<?php foreach ($this->reputation_user_group AS $key => $val) { ?>
							<input type="checkbox" name="user_groups[]" value="<?php echo $val['group_id']; ?>" /> <?php echo $val['group_name']; ?> &nbsp; 
							<?php } ?>
						</p>
					</div>
					
					
					
					<div id="option_last_active" class="hidden_option" style="display:none">
						<p>
							<label>Latest active time</label><br />

							<input type="radio" name="last_active" value="7776000" checked="checked" /> Recent 3 month &nbsp; 
							<input type="radio" name="last_active" value="15552000" /> Recent half a year &nbsp; 
							<input type="radio" name="last_active" value="31104000" /> Recent one year &nbsp; 
						</p>
					</div>
					
					<p>
						<input class="button" type="submit" value="Create" />
					</p>
					
				</fieldset>
				
				<div class="clear"></div><!-- End .clear -->
				
			</form>
				
			</div>
			
		</div>
		<div class="clear"></div>
	</div>

<!-- footer -->
<?php TPL::output('admin/global/footer.tpl.htm'); ?>
<!-- footer -->

</div>
<!-- main -->

</div>

<script type="text/javascript">
	function set_import_type(item_name)
	{
		$('.hidden_option').css('display', 'none');
		
		$('#option_' + item_name).css('display', '');
	}
	
	$(document).ready(function () {
		set_import_type($('#import_type').val());
	});
</script>

</body>
</html>