<?
    $GLOBALS
['highlight'] = 'forum';

    require_once(
'include/functions/community_permissions.php');

    
$_id = isset($_GET['i']) ? intval($_GET['i']) : 0;
    
$_admin_name = isset($_GET['admin_name']) ? trim(strval($_GET['admin_name'])) : '';

    if (
language() == 'french')
    {
        
define('ACTION_COMMUNITY_ADMIN_NOT_FOUND_COMMUNITY''Sorry, but this community does not exist.');
        
define('ACTION_COMMUNITY_ADMIN_NOT_FOUND_PERMISSION''Sorry, you don\'t have permission to modify this community.');
        
define('ACTION_COMMUNITY_ADMIN_NOT_FOUND_USER''Sorry, that user does not exist.');
        
define('ACTION_COMMUNITY_ADMIN_NOT_FOUND_MODERATOR''Sorry, that user is not a moderator of your community.');
        
define('ACTION_COMMUNITY_ADMIN_NOT_FOUND_YOURSELF''Sorry, but you can not edit your own permissions.');
    }
    else
    {
        
define('ACTION_COMMUNITY_ADMIN_NOT_FOUND_COMMUNITY''Sorry, but this community does not exist.');
        
define('ACTION_COMMUNITY_ADMIN_NOT_FOUND_PERMISSION''Sorry, you don\'t have permission to modify this community.');
        
define('ACTION_COMMUNITY_ADMIN_NOT_FOUND_USER''Sorry, that user does not exist.');
        
define('ACTION_COMMUNITY_ADMIN_NOT_FOUND_MODERATOR''Sorry, that user is not a moderator of your community.');
        
define('ACTION_COMMUNITY_ADMIN_NOT_FOUND_YOURSELF''Sorry, but you can not edit your own permissions.');
    }

    
$community mysql_query("SELECT * FROM community WHERE community_id = " sq($_id));
    if (!
$community_row mysql_fetch_assoc($community))
    {
        
make_cookie('notice'ACTION_COMMUNITY_ADMIN_NOT_FOUND_COMMUNITY);
        
header('Location: ./?s=community_create');
        die;
    }

    
community_permissions($community_row['community_id']);
    
    if (!
$GLOBALS['auth']['community']['administration'])
    {
        
make_cookie('notice'ACTION_COMMUNITY_ADMIN_NOT_FOUND_PERMISSION);
        
header('Location: ./?s=community_create');
        die;
    }

    if (!
$user_id get_user_id($_admin_name))    
    {
        
make_cookie('notice'ACTION_COMMUNITY_ADMIN_NOT_FOUND_USER);
        
header('Location: ./?s=community_modify&i=' $community_row['community_id']);
        die;
    }
    
    if (
$user_id == $GLOBALS['auth']['id'])
    {
        
make_cookie('notice'ACTION_COMMUNITY_ADMIN_NOT_FOUND_YOURSELF);
        
header('Location: ./?s=community_modify&i=' $community_row['community_id']);
        die;
    }

    
$community_permissions mysql_query("SELECT * FROM community_permissions WHERE community_id = '" $community_row['community_id'] . "' AND user_id = '" $user_id "' LIMIT 1");
    if (!
$community_permissions_row mysql_fetch_assoc($community_permissions))
    {
        
make_cookie('notice'ACTION_COMMUNITY_ADMIN_NOT_FOUND_MODERATOR);
        
header('Location: ./?s=community_modify&i=' $community_row['community_id']);
        die;                
    }

    include(
'include/parts/header.php');

    echo 
box_outside_top('<a href="?s=community_modify&i=' $community_row['community_id'] . '">Modify Your Community</a> - ' $_admin_name ' Moderator Info');
    echo 
box_inside_top();
?>

<form action="?a=community_admin_modify&i=<?= $community_row['community_id'?>&admin_name=<? echo $_admin_name ?>" method="post" class="form">
Granted Permissions
<div style="padding: 5px 0px 0px 0px;"></div>
<?    
    $community_permissions 
mysql_query("SELECT DISTINCT(permission) FROM community_permissions WHERE permission != 'admin' AND permission != 'administrator' ORDER BY permission");
    while (
$community_permissions_row mysql_fetch_array($community_permissions))
    {
        
$has_perm mysql_num_rows(mysql_query("SELECT user_id FROM community_permissions WHERE community_id = '" $community_row['community_id'] . "' AND permission = '" $community_permissions_row['permission'] . "' AND user_id = '" $user_id "'"));
        echo 
'<input type="checkbox" name="' $community_permissions_row['permission'] . '"' . ($has_perm 'CHECKED' '') . '> ' $community_permissions_row['permission'] . '<br />';
    }
?>
<div style="padding: 5px 0px 0px 0px;"></div>
<input type="submit" value="Modify Moderator Permissions" class="input_submit">
</form>

<?
    
echo box_inside_bottom();
    echo 
box_outside_bottom();

    include(
'include/parts/footer.php');
?>