<?php

// -----------------------------------------------------------------------
// This file is part of AROUNDMe
//
// Copyright (C) 2003 - 2007 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.
// -----------------------------------------------------------------------

?>

<style type="text/css">
<!--
@import url(<?php echo $template_path;?>css/aroundme_form.css);
-->
</style>


<form action="index.php?amn=core_maint_permission" method="post" name="frm" id="id_frm">
<input type="hidden" name="role_id" value="<?php echo $role_id;?>" />

<div class="col_main">
	<div class="box">
		<div class="box_top">
			<?php echo $lang['hdr_permissions'];?><br />
		</div>
		
		<div class="box_mid">
			<div class="content">
				<?php
				if (isset($lang['role'][$role_id])) {
				?>
					<b><?php echo $lang['role'][$role_id];?></b><br />
				<?php }?>
				<p>
					<?php echo $lang['txt_permissions_intro'];?><br />
				</p>
				
				<p>
					<?php echo $lang['txt_people_role'];?><br />
				</p>
				<img src="<?php echo $template_path;?>img/pixel.png" width="1" height="9" alt="" /><br />
				
				<?php
				if (isset($user_resources)) {
				?>
				<table border="0" cellspacing="1" cellpadding="2" width="100%">
					<?php
					foreach($user_resources as $rekey => $re):
					if (isset($role_id)) {
					?>
					<tr>
						<?php
						// we obtain the set permission
						$core_perm = 0;
						if (isset($permissions)) {
							foreach($permissions as $perm => $pm):
								if ($role_id == $pm['role_id']) {
									$core_perm = $pm['role_core_permission'];
									break;
								}
							endforeach;
						}	
						?>
						<td class="bg4">
							<?php echo $lang['resource']['user'][$re];?><br />
						</td>
						<td align="right" class="bg2" width="1">
							<?php
							$checked = "";
							if ($core_perm & $user_resources[$rekey]) {
								$checked = "checked=\"checked\"";
							}
							?>
							<input type="checkbox" name="permission[user][<?php echo $re;?>]" value="<?php echo $re;?>" <?php echo $checked;?> /><br />
						</td>
					</tr>
					<?php 
					}
					endforeach;
				?>
				</table>
				<?php }?>
				
				
				<?php
				if (isset($module_resources)) {
				?>
				
				<img src="<?php echo $template_path;?>img/pixel.png" width="1" height="9" alt="" /><br />
				
				<p>
					<?php echo $lang['txt_module_intro'];?><br />
				</p>
				
				<table border="0" cellspacing="1" cellpadding="2" width="100%">
					<?php
					foreach($module_resources as $modrekey => $modre):
					foreach($modre as $mdkey => $re):
					if (isset($lang['role'])) {
					?>
					<tr>
						<?php
						// we obtain the set permission
						$mod_perm = 0;
						if (isset($permissions)) {
							foreach($permissions as $perm => $pm):
								if ($role_id == $pm['role_id']) {
									$mod_perm = $pm['role_mod_permission'];
									break;
								}
							endforeach;
						}
						?>
						<td class="bg4">
							<?php echo $lang['resource']['module'][$re];?><br />
						</td>
						<td align="right" class="bg2" width="1">
							<?php
							$checked = "";
							if ($mod_perm & $module_resources[$modrekey][$mdkey]) {
								$checked = "checked=\"checked\"";
							}
							?>
							<input type="checkbox" name="permission[mod][<?php echo $re;?>]" value="<?php echo $re;?>" <?php echo $checked;?> /><br />
						</td>
					</tr>
					<?php 
					}
					endforeach;
					endforeach;
					?>
					
				</table>
				<?php }?>
				
				<img src="<?php echo $template_path;?>img/pixel.png" width="1" height="12" alt="" /><br />
				
				<table border="0" cellspacing="1" cellpadding="2" width="100%">
					<tr>
						<td valign="top" class="bg4">
							<?php echo $lang['txt_default_only'];?><br />		
						</td>
						<td align="right" valign="bottom" class="bg2">
							<input type="radio" name="update_type" value="0" checked="checked" /><br />
						</td>		
					</tr>
					<tr>
						<td valign="top" class="bg4">
							<?php echo $lang['txt_default_stnd'];?><br />					
						</td>
						<td align="right" valign="bottom" class="bg2">
							<input type="radio" name="update_type" value="permission" /><br />
						</td>		
					</tr>
					<tr>
						<td valign="top" class="bg4">
							<?php echo $lang['txt_default_full'];?><br />					
						</td>
						<td align="right" valign="bottom" class="bg2">
							<input type="radio" name="update_type" value="role" /><br />
						</td>		
					</tr>
				</table>
				
				<hr />
				
				<p align="right">
					<input name="update_permissions" type="submit" class="input_submit" value="<?php echo $lang['sub_update_permissions'];?>" /><br />
				</p>
			</div>
		</div>
	</div>
</div>

<div class="col_side">
	<div class="box">
		<div class="box_top">
			<?php echo $lang['hdr_options'];?><br />
		</div>
		
		<div class="box_mid">
			<div class="content">
				<select name="view_role_id">
					<?php
					foreach($lang['role'] as $key => $i):
					
					$selected = "";
					
					if ($role_id == $key) {
						$selected = "selected=\"selected\"";
					}
					?>
					<option value="<?php echo $key;?>" <?php echo $selected;?>><?php echo $i;?></option>
					<?php
					endforeach;
					?>
				</select>
				
				<p align="right">
					<input name="set_role" type="submit" class="input_submit" value="<?php echo $lang['sub_set_role'];?>" /><br />
				</p>
			</div>
		</div>
	</div>
</div>		
</form>