{include file="$admingentemplates/admin_top.tpl"}
<div class="back">
    <a href="{$form.back}">{$lang.button.back}</a>
</div>
<div class="cr"></div>
<div class="show_help" style="display: none;">&nbsp;</div>
<div class="red_header">{$lang.groups.editform_perm}{$data.groupname}</div>
<div class="cr">&nbsp;</div>
<div class="cr">&nbsp;</div>
<div class="help_text" style="display:block;">
    <div class="close_help">
        <img src="{$site_root}{$template_root}/images/close_help.png" alt="">
    </div>
    <div class="help_body">
        <span class="help_title">{$lang.help}:</span>{$lang.admin_help.groups_perm}
    </div>
</div>

<ul class="tabs">
    <li>
        <a href="admin_users.php">{$lang.users.razdel_name}</a>
    </li>
    <li>
        <a class="current" >{$lang.groups.razdel_name}</a>
    </li>
    <li>
        <a href="admin_users.php?sel=import">{$lang.admin_user.import.sub_header}</a>
    </li>
</ul>
    <div class="user_operation_line" style="height:4px;font-size:0px;">
          
    </div>
<div class="cr">&nbsp;</div>    
<div id="tab_all_users" class="user_status_elem" width="80px">
    <a href="{$data.permlink}" >{$lang.pays.option_general} </a>
</div>
<div id="tab_inactive_users" class="user_status_elem_active" width="80px">
    {$lang.groups.access_permissions}
</div>
{if $data.is_gender!=1}
<div id="tab_pricing" class="user_status_elem" width="80px">
    <a href="{$data.permlink}&price=1" >{$lang.users.pricing}</a>
</div>
{/if}
<table border=0 cellspacing=0 cellpadding=5 width="100%">
	<tr class="table_header">
		<td width="30%" >
			<input type="checkbox" id="select_all" name="select_all" onclick="PutAll()" />
			<b>{$lang.groups.module}</b>
		</td>
		<td width="55%" ><b>{$lang.groups.module_comment}</b></td>
		<td width="10%" ></td>
	</tr>
</table>			
<form action="{$form.action}" method="post" name="permissions" enctype="multipart/form-data">
<input type="hidden" name=sel value="permchange">
{$form.hiddens}

<table border=0  cellspacing=0 cellpadding=0 width="100%">
	{section name=f loop=$perm}
	{if $perm[f].name ne 'Invite Friends'}
	<tr {if $smarty.section.f.index mod 2 eq 1}class="user even"{else}class="user odd"{/if}>
		<td width="30%" align="left" style="padding-left:10px;" valign="top">
			<div style="float: left; margin: 2px 10px 2px 0px;"><input {if $perm[f].id eq 27}onclick="check_send_mess({$smarty.section.f.index});"{/if} {if $perm[f].id eq 17}onclick="check_email({$smarty.section.f.index});"{/if}type=checkbox name="perm{$smarty.section.f.index}" id="perm{$smarty.section.f.index}" value='{$perm[f].id}' {if $perm[f].checked eq 1 && !($perm[f].id eq 17 && $use_mailbox eq 0)}checked{/if} {if $perm[f].id eq 17 && $use_mailbox eq 0}disabled{/if}></div>
			<b><div id="module{$perm[f].id}" style="float: left;margin: 2px 10px 2px 0px;">{$perm[f].name}</div></b>
		</td>
		<td width="55%" align="left" class="main_content_text" style="padding:3;" valign="top">{$perm[f].comment}</td>
		<td width="10%" align="center" class="main_header_text" valign="top">
		</td>
	</tr>
	{elseif $settings.use_invite_friends eq 1}
		<tr {if $smarty.section.f.index mod 2 eq 1}class="user even"{else}class="user odd"{/if}>
		<td width="30%" align="left" style="padding-left:10px;" valign="top">
			<div style="float: left; margin: 2px 10px 2px 0px;"><input {if $perm[f].id eq 27}onclick="check_send_mess({$smarty.section.f.index});"{/if} {if $perm[f].id eq 17}onclick="check_email({$smarty.section.f.index});"{/if}type=checkbox name="perm{$smarty.section.f.index}" id="perm{$smarty.section.f.index}" value='{$perm[f].id}' {if $perm[f].checked eq 1 && !($perm[f].id eq 17 && $use_mailbox eq 0)}checked{/if} {if $perm[f].id eq 17 && $use_mailbox eq 0}disabled{/if}></div>
			<b><div id="module{$perm[f].id}" style="float: left;margin: 2px 10px 2px 0px;">{$perm[f].name}</div></b>
		</td>
		<td width="55%" align="left" class="main_content_text" style="padding:3;" valign="top">{$perm[f].comment}</td>
		<td width="10%" align="center" class="main_header_text" valign="top">
		</td>
		</tr>
	{elseif $settings.use_invite_friends eq 0}
		<input type="hidden" id="perm25" value="73">
	{/if}
        {*if $perm[f].id eq 27}
        <tr {if $smarty.section.f.index mod 2 eq 1}class="user even"{else}class="user odd"{/if}>
		<td width="30%" align="left" style="padding-left:10px;" class="main_header_text" valign="top">
			<div style="float: left; margin: 2px 10px 2px 0px;" id="add_perm"><input type="checkbox" name="add_perm[7]" id="add_perm[7]" value='{$add_perm_8.id}' {if $add_perm_8.active eq 1}checked{/if} onclick="javascript: changeAddPerm(7);"></div>
			<b><div style="margin: 2px 10px 2px 0px;">{$add_perm_8.name}</div></b>
		</td>
		<td width="55%" align="left" class="main_content_text" style="padding:3;" valign="top">{$add_perm_8.comment}</td>
		<td width="10%" align="center" class="main_header_text" valign="top">
			<input type="hidden" id="first_text_add_perm7" name="first_text_add_perm7" value="{$add_perm_8.name}:&nbsp;">
			<input type="hidden" id="second_text_add_perm7" name="second_text_add_perm7" value="&nbsp;{$add_perm_8.value_name}">
			{if $add_perm_8.id ne 8}
			<input type="text" name="count_add_perm[7]" id="count_add_perm[7]" value='{$add_perm_8.value}' {if $add_perm_8.active eq 0}disabled{/if} style="width: 35px;">
			{else}
			<input type="hidden" name="count_add_perm[7]" id="count_add_perm[7]" value='1'>
			{/if}
		</td>
	</tr>
        {/if*}
	{/section}
	{section name=a loop=$add_perm}
	<tr {if $smarty.section.a.index mod 2 eq 1}class="user even"{else}class="user odd"{/if} {if $add_perm[a].id eq 8 && !$use_im_default}style="display:none;"{/if}>
		<td width="30%" align="left" style="padding-left:10px;" class="main_header_text" valign="top">
			<div style="float: left; margin: 2px 10px 2px 0px;" id="add_perm_{$smarty.section.a.index}">
			<input type=checkbox name="add_perm[{$smarty.section.a.index}]" id="add_perm[{$smarty.section.a.index}]" value='{$add_perm[a].id}'  {if $add_perm[a].active eq 1}checked{/if} onclick="javascript: changeAddPerm({$smarty.section.a.index});" {if $add_perm[a].id eq 8 && $use_im eq 0}disabled{/if}></div>
			<b><div style="margin: 2px 10px 2px 0px;">{$add_perm[a].name}</div></b>
		</td>
		<td width="55%" align="left" class="main_content_text" style="padding:3;" valign="top">{$add_perm[a].comment}</td>
		<td width="10%" align="center" class="main_header_text" valign="top">
			<input type="hidden" id="first_text_add_perm{$smarty.section.a.index}" name="first_text_add_perm{$smarty.section.a.index}" value="{$add_perm[a].name}:&nbsp;">
			<input type="hidden" id="second_text_add_perm{$smarty.section.a.index}" name="second_text_add_perm{$smarty.section.a.index}" value="&nbsp;{$add_perm[a].value_name}">
			{if $add_perm[a].id ne 8}
				<input type="text" name="count_add_perm[{$smarty.section.a.index}]" id="count_add_perm[{$smarty.section.a.index}]" value='{$add_perm[a].value}' {if $add_perm[a].active eq 0}disabled{/if} style="width: 35px;">
			{else}
				<input type="hidden" name="count_add_perm[{$smarty.section.a.index}]" id="count_add_perm[{$smarty.section.a.index}]" value='1'>
			{/if}
		</td>
	</tr>
	{/section}
	{if $smarty.get.id ne 2}
	<tr {if $smarty.section.a.loop mod 2 eq 1}class="user even"{else}class="user odd"{/if}>
		<td width="30%" align="left" style="padding-left:10px;" class="main_header_text" valign="top">
			<div style="float: left; margin: 2px 10px 2px 0px;" id="add_perm"><input type="checkbox" name="add_perm[7]" id="add_perm[7]" value='{$add_perm_8.id}' {if $add_perm_8.active eq 1}checked{/if} onclick="javascript: changeAddPerm(7);"></div>
			<b><div style="margin: 2px 10px 2px 0px;">{$add_perm_8.name}</div></b>
		</td>
		<td width="55%" align="left" class="main_content_text" style="padding:3;" valign="top">{$add_perm_8.comment}</td>
		<td width="10%" align="center" class="main_header_text" valign="top">
			<input type="hidden" id="first_text_add_perm7" name="first_text_add_perm7" value="{$add_perm_8.name}:&nbsp;">
			<input type="hidden" id="second_text_add_perm7" name="second_text_add_perm7" value="&nbsp;{$add_perm_8.value_name}">
			{if $add_perm_8.id ne 8}
				<input type="text" name="count_add_perm[7]" id="count_add_perm[7]" value='{$add_perm_8.value}' {if $add_perm_8.active eq 0}disabled{/if} style="width: 35px;">
			{else}
				<input type="hidden" name="count_add_perm[7]" id="count_add_perm[7]" value='1'>
			{/if}
		</td>
	</tr>
	{/if}
</table>
</form>
<table width="100%" style="margin-top:15px;">
<tr height="40">
	<td align="left">
		<a class="admin_button_major" onclick="javascript: update_permissions();" >{$lang.button.save}<span>&nbsp;</span></a>
	</td>
</tr>
</table>
  {literal}
  <script>
check_email({/literal}{$index}{literal});

$(window).load(function () {
	$("#user_link").css("font-weight","bold");
});

function check_send_mess(num){
    var isChecked = $("#perm"+num).attr("checked");
    if (isChecked)
        $("#add_perm input").attr('checked', 'checked');
    else
        $("#add_perm input").attr('checked', '');
}
function check_email(num){
    var isChecked = $("#perm"+num).attr("checked");
    if (isChecked){
        $("#add_perm_0 input").removeAttr('disabled');
    }else{
        $("#add_perm_0 input").removeAttr('checked');
        $('#count_add_perm[0]').attr('disabled', 'true');
        $("#add_perm_0 input").attr('disabled', 'true');
    }
}
    
$("#admin_link").click(function(){
	$("#user_link").css("font-weight","normal");
	$("#admin_link").css("font-weight","bold");
	$(".user").hide();
	return false;
});

$("#user_link").click(function(){
	$("#admin_link").css("font-weight","normal");
	$("#user_link").css("font-weight","bold");
	$(".user").show();
	return false;
});
  
  //// if disable permiss_checkbox => disable demo_checkbox
  var permiss = document.permissions;
  for(i=0;i<permiss.length;i++){
	if(permiss[i].name.substr(0,4)== 'perm'){
		id = permiss[i].name.substr(4);
	}
  }

  function changeAddPerm(id) {
	if (document.getElementById('add_perm['+id+']').checked == false) {
		document.getElementById('count_add_perm['+id+']').disabled = true;
	} else {
		document.getElementById('count_add_perm['+id+']').disabled = false;
	}
  }

  function update_permissions(){
	var permiss = document.permissions;
	var perm_str = '';
	var module_str = '';
	var j = 0;
	var k = 0;
	var l = 0;

	var add_perm_str = '';

	for(i=0;i<permiss.length;i++){
		if(permiss[i].name.substr(0,4)== 'perm'){
			perm_id = permiss[i].value;
			id = permiss[i].name.substr(4);
			if(permiss[i].checked == true){
				perm_str = perm_str + '<input type=hidden name="perm['+j+']" value="'+perm_id+'">';
				permiss[i].name = 'perm['+j+']';			  					
				var module_element = document.getElementById('module'+perm_id);
				module_str = module_str + module_element.innerHTML+'<br>';
				j++;
			}
		}

		if (permiss[i].name.substr(0,8)== 'add_perm'){
			perm_id = permiss[i].value;
                            //alert(permiss[i].checked);
			if (permiss[i].checked == true && permiss[i].disabled == false) {
				add_perm_str = add_perm_str + '<input type=hidden name="add_perm['+l+']" value='+document.getElementById('add_perm['+l+']').value+'>';
				add_perm_str = add_perm_str + '<input type=hidden name="add_perm_count['+l+']" value='+document.getElementById('count_add_perm['+l+']').value+'>';
				add_perm_str = add_perm_str + document.getElementById('first_text_add_perm'+l).value + document.getElementById('count_add_perm['+l+']').value + document.getElementById('second_text_add_perm'+l).value+'<br>';
			}
			l++;
		}
	}
	/*module_str = module_str.substr(0, module_str.length-4);
	var opener_modules_element = window.document.getElementById('modules');
	opener_modules_element.innerHTML = module_str + perm_str;
	window.document.getElementById('add_modules').innerHTML = add_perm_str;*/
	permiss.submit();
  }
                  
function PutAll() {
	var permiss = document.permissions;
	var i
    var o=document.getElementsByName('select_all')	
	if (o[0].checked){                    
		for (i=0; i<permiss.length; i++){                
			permiss[i].checked = true
		}            
	}
	else{
		for (i=0; i<permiss.length; i++){                
			permiss[i].checked = false
		}            
	}             
}
</script>
{/literal}
{include file="$admingentemplates/admin_bottom.tpl"}