<?php

// -----------------------------------------------------------------------
// This file is part of AROUNDMe
// 
// Copyright (C) 2003 - 2006 Barnraiser
// http://www.barnraiser.org/
// info@barnraiser.org
// 
// 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; either version 2, or (at your option) any
// later version.
// 
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with program; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
// 02110-1301, USA.
// -----------------------------------------------------------------------

?>

<form action="grp_acs.php" method="post" name="frm" id="id_frm">
<input type="hidden" name="role_id" value="<?php if (isset($role['role_id'])) {echo $role['role_id'];}?>" />
<input type="hidden" name="group_id" value="<?php echo $group['group_id'];?>" />

<div class="col_left1">
	<div class="box">
		<div class="box_top">
			<?php echo $lang['hdr_acs_permissions'];?><br />
		</div>
		
		<div class="box_mid">
			<div class="content">
				<table cellpadding="4" cellspacing="0" border="0" width="100%">
					<?php
					if (isset($resources[0])) {
					foreach($resources as $key1 => $res):
					?>
					<tr>
						<td colspan="2" valign="top">
							<b><?php echo $res['resource_name'];?></b><br />
						</td>
					</tr>
					<?php
					//get the privileges for each resource
					if (isset($res['privileges'])) {
					foreach($res['privileges'] as $key2 => $priv):
					?>
					<tr>
						<td valign="top" width="50%">
							<?php echo $priv['privilege_name'];?><br />
						</td>
						<td valign="top">
							<?php
							//create a table for each permission (one per role)
							if (isset($priv['permissions'])) {
							foreach($priv['permissions'] as $key3 => $perm):
							$checked = "";
							if ($perm == 1) {
								$checked = "checked";
							}
							?>
							<input type="checkbox" name="ids[<?php echo $res["resource_id"]."-".$priv["privilege_id"]."-".$key3;?>]" value="1" <?php echo $checked;?> /> <?php echo $roles[$key3]['role_name'];?><br />
							<?php
							endforeach;
							}
							?>
						</td>
					</tr>
					<?php
					endforeach;
					}
					?>
					
					
					<?php
					endforeach;
					}
					?>
					<tr>
						<td colspan="2" align="right">
							<input type="submit" name="update_permissions" value="<?php echo $lang['sub_update_permissions'];?>" class="button_urgent" / ><br />
						</td>
					</tr>
				</table>
			</div>
		</div>
	</div>
	
	<div class="box_bottom">
		<span class="box_bottom_right"></span>
		<span class="box_bottom_left"></span>
	</div>
</div>

<div class="col_right1">
	<div class="box">
		<div class="box_top">
			<?php echo $group['group_title'];?><br />
		</div>
		
		<div class="box_mid">
			<div class="content">
				<?php
				if (isset($group['image']['file_id'])) {
				?>
				<img src="get_file.php?file=<?php echo $group['image']['file'];?>" border="0" alt="<?php echo $group['image']['file_title'];?>" /><br />
				<?php }?>
				
				<p>
					<select name="options" class="options_select">
					<option value="0" selected="selected"></option>
					<option value="grp_view"><?php echo $lang['txt_option_group'];?></option>
					<option value="grp_structure"><?php echo $lang['txt_option_structure'];?></option>
					<option value="grp_membership"><?php echo $lang['txt_option_membership'];?></option>
				</select>
					<input type="image" src="<?php echo $templatePath;?>img/go.png" value="option_action" class="go" /><br />
				</p>
			</div>
		</div>
	</div>
	
	<div class="box_bottom">
		<span class="box_bottom_right"></span>
		<span class="box_bottom_left"></span>
	</div>
	
	<div class="box">
		<div class="box_top">
			<?php echo $lang['hdr_acs_roles'];?><br />
		</div>
		
		<div class="box_mid">
			<div class="content">
				
				<table cellpadding="4" cellspacing="0" border="0" width="100%" class="table_nested">
					<tr>
						<td valign="top" colspan="2">
							<?php echo $lang['txt_acs_roles_help'];?><br />
						</td>
					</tr>
					<tr>
						<td valign="top">
							<b><?php echo $lang['txt_role_name'];?></b><br />
						</td>
						<td valign = "top" align="right">
							<b><?php echo $lang['txt_default_role'];?></b><br />
						</td>
					</tr>
					<?php
					if (isset($roles)) {
					foreach($roles as $key => $i):
					?>
					<tr>
						<td valign="top">
							<?php echo ($key+1);?>:&nbsp;<a href="grp_acs.php?group_id=<?php echo $group['group_id'];?>&amp;role_id=<?php echo $i['role_id'];?>"><?php echo $i['role_name'];?></a><br />
						</td>
						<td valign = "top" align="right">
							<?php
							$selected = "";
							if ($i['role_default'] == 1) {
								$selected = "checked=\nchecked\n";
							}
							?>
							
							<?php
							if ($i['role_visitor'] == null) {
							?>
							<input type="radio" name="default_role_id" value="<?php echo $i['role_id'];?>" <?php echo $selected;?> /><br />
							<?php }?>
						</td>
					</tr>
					<?php
					endforeach;
					}
					?>
					<tr>
						<td align="right" colspan="2">
							<input type="submit" name="set_default" value="<?php echo $lang['sub_update_default_role'];?>" class="button_urgent" /><br />
						</td>
					</tr>
				</table>
				
				<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="10" alt="" /><br />
				
				<table cellpadding="4" cellspacing="0" border="0" width="100%">
					<tr>
						<td class="txt_title" align="right" colspan="2">
							<?php echo $lang['hdr_acs_role'];?><br />
							<hr />
						</td>
					</tr>
					<tr>
						<td valign="top" class="txt_footer" colspan="2">
							<?php echo $lang['txt_acs_role_help'];?><br />
						</td>
					</tr>
					<tr>
						<td valign="top" colspan="2">
							<?php echo $lang['txt_name'];?><br />
						</td>
					</tr>
					<tr>
						<td valign="top" colspan="2">
							<input type="text" size="35" name="role_name" value="<?php if (isset($role['role_name'])) {echo $role['role_name'];}?>" /><br />
						</td>
					</tr>
					<tr>
						<td colspan="2">
							<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="4" alt="" /><br />
						</td>
					</tr>
					<?php
					if (isset($role)) {
					?>
					<tr>
						<td>
							<input type="hidden" name="role_default" value="<?php if (!empty($role['role_default'])) {echo 1;}?>" />
							<input type="submit" name="delete_role" value="<?php echo $lang['sub_delete_role'];?>" class="button_urgent" /><br />
						</td>
						<td align="right">
							<input type="submit" name="update_role" value="<?php echo $lang['sub_update_role'];?>" class="button_urgent" /><br />
						</td>
					</tr>
					<?php
					}
					else {
					?>
					<tr>
						<td align="right" colspan="2">
							<input type="submit" name="insert_role" value="<?php echo $lang['sub_insert_role'];?>" class="button_urgent" /><br />
						</td>
					</tr>
					<?php
					}
					?>
				</table>
			</div>
		</div>
	</div>
	
	<div class="box_bottom">
		<span class="box_bottom_right"></span>
		<span class="box_bottom_left"></span>
	</div>
</div>
</form>
