Revision 195 (by ahitrov, 2012/03/15 18:26:13) Users plugin
%# vim:syn=mason
<& "/contenido/components/header.msn" &>

<& "/contenido/components/naviline.msn", sect_id => $owner->id &>

% if ($error) {
<div align="center" style="font-size:110%; color:red;">
<% $error %>
</div>
<br><br>
% }

% if (!ref($document)) {
%	if ($id) {
<div align="center" style="font-size:110%; color:red;">
�������� � ��������������� <% $id %> �� ������
</div>
<br><br>
%	} elsif ($class) {
<!-- ���� � ������� ������ ��������� ��� �������� -->
<table width="50%" border="0"><tr><td>
<fieldset>
<legend>�������� ��� ��������� ��� ��������</legend>
<& "/contenido/components/new_objects_form.msn", proto => 'documents', sect_id => $owner->id &>
</fieldset>
</td></tr></table>
%	} else {
<div align="center" style="font-size:110%; color:red;">
�� ������ ����� ���������!!! (����������� id � class ������������)
</div>
<br><br>
%	}

% } else {

<& "/contenido/components/obj_list_js.msn", object => $document &>
<& "/contenido/components/object_form.msn", 
		object	=> $document, 
		proto	=> 'documents', 
		sect_id	=> $owner->id,
		clone	=> $clone &>
%	if (ref($document) && ($document->id))
%	{

<!-- ����� � �������� � �������� -->

<br>

<table width="100%" cellspacing="5" cellpadding="0" border="0">
<tr>
<td width=50% valign=top>\
<& "/contenido/components/document_sections.msn", document => $document &>\
<& "/contenido/components/user_sections.msn", luser => $document &>\
%		if ( $m->comp_exists ("/contenido/components/pbase_rubrics.msn") ) {
<& "/contenido/components/pbase_rubrics.msn", document => $document &>\
%		}
</td>
<td width=50% valign=top>
%		if ( $m->comp_exists ("/contenido/components/pbase_links.msn") ) {
<& "/contenido/components/pbase_links.msn", document => $document &>\
%		}
<iframe id="links" src="document_links.html?id=<% $document->id() %>&class=<% $document->class() %>" width="100%" height="700" frameborder="0"></iframe>

</td>
</tr>
</table>

<!-- / ����� � �������� � �������� -->

%	}
% }

</body>
</html>
<%ARGS>
	$class => undef
	$sect_id => undef
	$s_alias => undef
	$id => undef
	$delete => undef
	$save => undef
	$clone  => undef
	$activate => undef
	$deactivate => undef
</%ARGS>
<%INIT>
	my $error='';

	my $filter = $m->comp('/contenido/components/context.msn', name => 'filter');

	my $document;
	my $new;

	if ($id && ($id !~ /\D/) && ($id > 0)) {
		$document = $keeper->get_document_by_id($id, class=>$class);
		if ( $clone && exists $document->{'attributes'}->{'dtime'} ) {
			$document->dtime(undef);
		}
	} elsif ( ($class) && (length($class)>0) && (! ref($document)) ) {
		$document = new $class ($keeper);
		$new = 1;
		my @properties = $document->structure();
		foreach my $prop ( @properties ) {
			my $attr = $prop->{attr};
			### !!! ���� �� ����������� ����������, �� ����� ����������������
			if ( exists $ARGS{$attr} && ! grep { $prop->{attr} eq $_ } qw( class sect_id id delete save clone s_alias activate deactivate ) ) {
				$document->$attr($ARGS{$attr});
			}
		}
	}

	if (ref($document) && $document->id() && $document->section()) {
		my $document_access = $user->section_accesses($user, $document->section);
		if ($document_access != 2) {
			$m->clear_buffer;
			$m->abort(403);
		}
	}

	if ($s_alias) {
		$sect_id = $project->s_alias->{$s_alias};	
	}

	if ( (! $sect_id) && (ref($document)) && ($document->id) ) {
		$sect_id = $document->section();
	}
	my $owner = $keeper->get_section_by_id ($sect_id || $Contenido::Section::ROOT || 1);

	if (! ref($owner)) {
		$owner = $keeper->get_section_by_id ($Contenido::Section::ROOT || 1);
	}
	if (! ref($owner)) {
		warn "Contenido Die: �� ���� ����� �������� ������\n";
		return undef;
	}


	# ��������...
	if (defined($id) && ($id > 0) && ($delete == 1)) {
		$document->delete();

		$r->header_out("Location", "sections.html?id=".$owner->id);
		$r->status(302);
		$r->send_http_header();
		$m->abort();
	}

        # ���������...
	if (defined($id) && ($id > 0) && ($activate == 1)) {
		$document->status(1);
		$document->store;

		$r->header_out("Location", "sections.html?id=".$owner->id);
		$r->status(302);
		$r->send_http_header();
		$m->abort();
        }

	# ����������...
	if (defined($id) && ($id > 0) && ($deactivate == 1)) {
		$document->status(0);
		$document->store;

		$r->header_out("Location", "sections.html?id=".$owner->id);
		$r->status(302);
		$r->send_http_header();
		$m->abort();
        }

	# ���������� ������������� ��������� ��� �������� ������...
	# ������, ���� ����� �� �������������� �����...
	elsif ( $save == 1 )
	{
		my $clonesource;
		if ( $clone ) {
			$clonesource = $keeper->get_document_by_id ($clone,
				class   => $document->class,
			);
		}
		if ($m->comp('/contenido/components/set_properties.msn', object => $document, SETS => \%ARGS) != 1)
		{
			# ������, ���� �� ����������...
			warn "Contenido Warning: �� ���� ���������� �������� �����!\n";
		}
		if ( $clone ) {
			$m->comp('/contenido/components/clone_attachments.msn', object => $document, source => $clonesource );
		}

		$document->sections( $owner->id, $filter > 0 ? ($filter) : ()) if $new;

		unless ($document->store()) {
			# ������, ���� �� ����������...
			$error="������ ���������� ($keeper->{last_error})";
		} else {

		if ($ARGS{_save_and_leave})
		{
			$r->header_out("Location", "sections.html?id=".$owner->id);
			$r->status(302);
			$r->send_http_header();
			$m->abort();
		}
		elsif ($ARGS{_save_and_again})
		{
			$r->header_out("Location", "document.html?class=".$document->class()."&sect_id=".$owner->id);
			$r->status(302);
			$r->send_http_header();
			$m->abort();
		}


		$r->header_out("Location", "document.html?id=".$document->id()."&class=".$document->class());
		$r->status(302);
		$r->send_http_header();
		$m->abort();
		}
	}

</%INIT>