Line # Revision Author
1 198 ahitrov %# vim:syn=mason
2 <& "/contenido/components/header.msn" &>
3 <& "/contenido/components/naviline.msn", sect_id => $owner->id &>
4
5 % if ($error) {
6 <div align="center" style="font-size:110%; color:red;">
7 <% $error %>
8 </div>
9 <br><br>
10 % }
11
12 % if (!ref($document)) {
13 % if ($id) {
14 <div align="center" style="font-size:110%; color:red;">
15 Документ с идентификатором <% $id %> не найден
16 </div>
17 <br><br>
18 % } elsif ($class) {
19 <!-- Блок с выбором нового документа для создания -->
20 <table width="50%" border="0"><tr><td>
21 <fieldset>
22 <legend>Выберите тип документа для создания</legend>
23 <& "/contenido/components/new_objects_form.msn", proto => 'documents', sect_id => $owner->id &>
24 </fieldset>
25 </td></tr></table>
26 % } else {
27 <div align="center" style="font-size:110%; color:red;">
28 Неверный вызов документа!!! (отсутствуют id и class одновременно)
29 </div>
30 <br><br>
31 % }
32
33 % } else {
34 % if ( $document->postman_id == $user->id ) {
35 <& "/contenido/components/obj_list_js.msn", object => $document &>
36 <& "/contenido/webshop/components/order_form.msn",
37 context => 'post',
38 object => $document,
39 proto => 'documents',
40 sect_id => $owner->id,
41 clone => $clone,
42 filter_params => \%filter_params,
43 &>
44 % } else {
45 % my $profile = $keeper->get_user_by_id( $document->postman_id );
46 <div style="padding:10px;">
47 <b style="font-size:110%">Доставка ЗАКАЗА</b>
48 <p style="color:red"><b>Внимание!</b> Доставку заказа осуществляет <% $profile->name %></p>
49 <p><a href="./?ost=3">&lt;&lt; Вернуться в список доставки</a></p>
50 </div>
51 % }
52 % }
53
54 </body>
55 </html>
56 <%ARGS>
57 $p => 1
58 $class => 'webshop::Order'
59 $sect_id => undef
60 $s_alias => undef
61 $id => undef
62 $delete => undef
63 $save => undef
64 $clone => undef
65 $activate => undef
66 $deactivate => undef
67 </%ARGS>
68 <%INIT>
69
70 &abort404 unless $class;
71 my $error='';
72 ### !!! При добавлении переменных в ARGS их надо внести в список исключений в структуре ниже
73
74 my $filter = $m->comp('/contenido/components/context.msn', name => 'filter');
75
76 my $document;
77 my $new;
78 my $now = Contenido::DateTime->new;
79
80 if ($id && ($id !~ /\D/) && ($id > 0)) {
81 $document = $keeper->get_document_by_id($id, class=>$class);
82 if ( $clone && exists $document->{'attributes'}->{'dtime'} ) {
83 $document->dtime(undef);
84 }
85 } elsif ( ($class) && (length($class)>0) && (! ref($document)) ) {
86 $document = new $class ($keeper);
87 $new = 1;
88 my @properties = $document->structure();
89 foreach my $prop ( @properties ) {
90 my $attr = $prop->{attr};
91 ### !!! Если не стандартная переменная, то можем инициализировать
92 if ( exists $ARGS{$attr} && ! grep { $prop->{attr} eq $_ } qw( class sect_id id delete save clone s_alias activate deactivate p s use_section alpha alpha_search search_by search ) ) {
93 $document->$attr($ARGS{$attr});
94 }
95 }
96 }
97 &abort404 unless ref $document;
98
99 my @props = $document->structure();
100 my %filter_params;
101 if ($ARGS{use_section} && !grep { $_->{attr} eq 'use_section' } @props ) {
102 $filter_params{use_section} = $ARGS{use_section};
103 $filter_params{class} = $document->class;
104 }
105 $filter_params{alpha} = $ARGS{alpha} if $ARGS{alpha} && !grep { $_->{attr} eq 'alpha' } @props;
106 $filter_params{alpha_search} = $ARGS{alpha_search} if $ARGS{alpha_search} && !grep { $_->{attr} eq 'alpha_search' } @props;
107 $filter_params{search_by} = $ARGS{search_by} if $ARGS{search_by} && !grep { $_->{attr} eq 'search_by' } @props;
108 $filter_params{search} = $ARGS{search} if $ARGS{search} && !grep { $_->{attr} eq 'search' } @props;
109 $filter_params{s} = $ARGS{s} if $ARGS{s} && !grep { $_->{attr} eq 's' } @props;
110 $filter_params{p} = $p if $p > 1;
111 my $return_params = join ('&', map { $_.'='.$filter_params{$_} } grep { $_ ne 's' } keys %filter_params );
112
113
114 if ($s_alias) {
115 $sect_id = $project->s_alias->{$s_alias};
116 }
117
118 if ( (! $sect_id) && (ref($document)) && ($document->id) ) {
119 $sect_id = $document->section();
120 }
121 my $owner = $keeper->get_section_by_id ($sect_id || $Contenido::Section::ROOT || 1);
122
123 if (! ref($owner)) {
124 $owner = $keeper->get_section_by_id ($Contenido::Section::ROOT || 1);
125 }
126 if (! ref($owner)) {
127 warn "Contenido Die: Не могу найти корневую секцию\n";
128 return undef;
129 }
130
131 if ( ref $document && !$document->postman_id ) {
132 $document->postman_id( $user->id );
133 $document->store;
134 }
135 if (ref($document) && $document->id() && $document->section()) {
136 my $document_access = $user->section_accesses($user, $owner);
137 if ($document_access != 2) {
138 $m->clear_buffer;
139 $m->abort(403);
140 }
141 }
142
143 # Удаление...
144 if (defined($id) && ($id > 0) && $delete) {
145 $document->status( 5 );
146 $document->store;
147
148 $m->redirect("./?ost=3".($return_params ? '&'.$return_params : ''));
149 }
150
151 # Сохранение существующего документа или создание нового...
152 # Кстати, пока никак не обрабатываются связи...
153 elsif ( $save == 1 )
154 {
155 my $clonesource;
156 if ( $clone ) {
157 $clonesource = $keeper->get_document_by_id ($clone,
158 class => $document->class,
159 );
160 }
161 if ($m->comp('/contenido/webshop/components/set_properties.msn', object => $document, SETS => \%ARGS, context => 'post') != 1)
162 {
163 # Ошибка, надо бы обработать...
164 warn "Contenido Warning: Не могу установить значения полей!\n";
165 }
166 if ( $clone ) {
167 $m->comp('/contenido/components/clone_attachments.msn', object => $document, source => $clonesource );
168 $document->sections( $clonesource->sections );
169 } elsif ( $new ) {
170 $document->sections( $owner->id, $filter > 0 ? ($filter) : ());
171 }
172
173 if ( $ARGS{_save_and_deliver} ) {
174 $document->status(4);
175 $document->postman_id( $user->id );
176 $document->etime( $now->ymd('-').' '.$now->hms );
177 } elsif ( $ARGS{_ret_manager} ) {
178 $document->status(1);
179 } elsif ( $ARGS{_ret_facility} ) {
180 $document->status(2);
181 } elsif ( $ARGS{_save_and_leave} ) {
182 }
183
184 unless ($document->store()) {
185 # Ошибка, надо бы обработать...
186 $error="Ошибка сохранения ($keeper->{last_error})";
187 } else {
188
189 if ($ARGS{_save_and_deliver}) {
190 $m->redirect("./?ost=3");
191 } elsif ($ARGS{_ret_manager}) {
192 $m->redirect("./?ost=3");
193 } elsif ($ARGS{_ret_facility}) {
194 $m->redirect("./?ost=3");
195 } elsif ($ARGS{_save_and_leave}) {
196 $m->redirect("./?ost=1".($return_params ? '&'.$return_params : ''));
197 }
198
199 $m->redirect("delivery.html?id=".$document->id.($return_params ? '&'.$return_params : ''));
200 }
201 }
202
203 </%INIT>