Revision 3 (by ahitrov@rambler.ru, 2010/03/24 15:19:32) The CORE
<script language="JavaScript">
<!--
	var dom = (document.getElementById) ? true : false;
	var nn4 = (document.layers) ? true : false;
	var ie4 = (!dom && document.all) ? true : false;
	var layerOk;

	if (dom || ie4 || nn4) { layerOk = 1; } 
	else { layerOk = 0; }

	var layerRef, styleRef, showVar, hideVar, showDVar, hideDVar;
	var srcOpen  = '/contenido/i/open11x11.gif';
	var srcClose = '/contenido/i/close11x11.gif';

	var imageRef;

	if (nn4) {
		layerRef = "document.layers.";
		styleRef = "";
		imageRef = "";
		showDVar = "'block'";
		hideDVar = "'none'";
		showVar  = "'show'";
		hideVar  = "'hide'";
	} else {
		layerRef = "document.all.";
		imageRef = "";
		styleRef = ".style";
		showDVar = "'block'";
		hideDVar = "'none'";
		showVar  = "'visible'";
		hideVar  = "'hidden'";
	}

	if (dom) {
		layerRef = "document.getElementById('";
		styleRef = "').style";
		imageRef = "')";
	}

function changeDiv( divID ) {
	if (eval(layerRef + 'slinks' + divID + styleRef + '.visibility') == 'hidden') {
		showDiv(divID);
	} else {
		hideDiv(divID);
	}
}

function showDiv( divID ) {
	if (layerOk) {
		eval(layerRef + 'slinks' + divID + styleRef + '.visibility=' + showVar);
		eval(layerRef + 'slinks' + divID + styleRef + '.display='    + showDVar);
		eval(layerRef + 'simg'   + divID + imageRef + '.src = "'     + srcClose + '"');
	}
}

function hideDiv( divID ) {
	if (layerOk) {
		eval(layerRef + 'slinks' + divID + styleRef + '.visibility=' + hideVar);
		eval(layerRef + 'slinks' + divID + styleRef + '.display='    + hideDVar);
		eval(layerRef + 'simg'   + divID + imageRef + '.src = "'     + srcOpen + '"');
	}
}

//-->
</script>
<fieldset>
	<legend>������ � �������� (��������) �����<sup>1</sup></legend>
	<table height="400" border=0>
		<tr valign="top">
			<td>
				<form action="store_user_sections.html" method="POST">
					<input type="submit" value="��������� ������" class="input_btn">

%	my @sections = $luser->groups();
%	my $sections_ = {};
%	for my $secti (@sections) {
%		$sections_->{$secti} = 1;
%		my @trace = $keeper->get_section_by_id($secti)->trace();
%		for my $traci (@trace) {
%			next	if (exists $sections_->{$traci});
%			$sections_->{$traci} = 1;
%		}
%	}
%	my @fullsections = keys(%{ $sections_ });
%	my $root = $keeper->get_section_by_id(1);
					<ul style="font-size:13px;font-family:Tahoma;">
%	user_sections_tree($root, \@fullsections, \@sections, 0);
					</ul>

					<input type="hidden" name="login" value="<% $luser->login %>">
					<input type="submit" value="��������� ������" class="input_btn">
				</form>
			</td>
		</tr>
	</table>
</fieldset>

<!-- ���������� -->
<fieldset>
	<legend>����������</legend>
	<table width="100%" cellspacing="5" cellpadding="0" class="tform" height="50">
		<tr>
			<th valign=top>1)</th>
			<td width="100%">������ � ������ ������������� ���� ������ �� ���� �������� �������� ���� ������;<br></td>
		</tr>
	</table>
</fieldset>

<%args>

	$luser => undef

</%args>

<%init>
	return	undef	if !ref($luser);
	return  undef   unless ($luser->{attributes}->{groups});

	my $root_section = $keeper->get_section_by_id($Contenido::Section::ROOT || 1);
	
	sub user_sections_tree
	{
		my ($sect, $fullsections, $sections, $depth) = @_;
		my $count_checked = 0;

		my @childs = $sect->childs(1);

		if ($sect->id)
		{
			my $checked = (grep {$_ == $sect->{id} } @{ $sections }) ? ' checked' : '';
			$count_checked++ if( grep {$_ == $sect->{id} } @{ $fullsections } );

			if (@childs && $sect->id != 1) { $m->out("<a title=\"��������/�������\" style=\"width:22px;text-decoration:none;\" href=\"javascript:changeDiv('$sect->{id}');\"><img id=\"simg$sect->{id}\" src=\"/contenido/i/open11x11.gif\" width=\"11\" height=\"11\" border=\"0\"></a>"); } 
			else { $m->out( '<span style="width:22px;"></span>' ); }
			$m->out("<input type=\"checkbox\" name=\"section_$sect->{id}\" value=\"1\" $checked>");
			$m->out("$sect->{name}<br>\n");
		}

		if (@childs)
		{
			my $check_childs = undef;
			if ($depth > 0) { $m->out( '<div style="visibility:hidden;display:none;" id="slinks'.$sect->id.'">'."\n" ); }
			$m->out( '<ul>'."\n" );
			foreach my $child_id (@childs)
			{
				my $child = $keeper->get_section_by_id($child_id);
				$check_childs += user_sections_tree($child, $fullsections, $sections, $depth + 1);
			}
			$m->out("</ul>\n");
			if ($depth > 0) { $m->out( '</div>'."\n" ); }
			if ($check_childs > 0 && $sect->id != 1) { $m->out( "<script language=\"JavaScript\"><!--\nshowDiv('$sect->{id}');\n//-->\n</script>\n" ); }
		}
		return $count_checked;
	}

</%init>