item_edit


NAME

item_edit - universal web-interface for editing Communiware item.


DESCRIPTION

item_edit is universal interface for creating/editing ANY communiware item.

Following restrictions are placed for item edit:

  1. Type of item can be changed only to item with same list of extended attributes

  2. Only types which have default template on this site appears as possible choices. If current item doesn't have default template, its type would be added.

  3. Only SUPERUSER can change site this item belongs to.

  4. Only texts with less than 64K size can be edited directly in form, Use Download link and upload field for editing large texts.

All updatable attributes appear in the form, as well as all link types in which this item may act as passive. They are presented as input fields where item_id (or multiple comma-separated item_ids for M:N relation type) can be typed. Each such field is accompanied with ``Choose'' button and inputline where substring of item_id or title can be typed.

When this button is pressed, page where all matching items from current site appear accompanied with checkbox or radiobutton to select it.

Upon submitting this page all values except file name in upload field are presented. (this is HTML security restriction)

Links where current item is active are listed below with link to the script orderlink which allows to specify default sort order of children manually.

                my (@types, $deftype);
                @types = keys %types;
                $deftype = $types{'ARTICLE'} ? 'ARTICLE' : $types[0];
                print " ", gettext("Type: "),
                  $cgi->popup_menu(
                        -name    => 'TYPE_ID',
                        -Values  => \@types,
                        -labels  => \%types,
                        -default => $deftype
                  ),
                  "\n";
                print "\n";
                $typesmenu = 1;
                delete $attrlist{TYPE_ID};
        }
        print "\n\ \ \  \ \ \ \n" if $typesmenu;
        if ($item_id && $type_id eq 'TEMPLATE') {
                print '<p>', gettext("This item is a TEMPLATE. It is better to "),
                  $cgi->a(
                        { -href => $Communiware::Prefix{'URL'} . "/$item_id" },
                        gettext("see it here")
                  ),
                  , gettext(" and to "),
                  $cgi->a({ -href => $Communiware::Prefix{'URL'} . "/$item_id/edit_template" },
                        gettext("edit it here")),
                  ".</p>\n";
        }
        if (exists $attrlist{TYPE_ID}) {
                print $cgi->hidden('TYPE_ID');
                delete $attrlist{TYPE_ID};
        }
        print gettext("Title: "), $cgi->textfield(-name => 'TITLE', -size => 66, -maxwidth => 250),
          "<br>";
        delete $attrlist{TITLE};
        print gettext("Abstract: "), "<BR>\n",
          $cgi->textarea(-name => "ABSTRACT", -rows => 5, -cols => 80, -wrap => "soft"), "<BR>";
        delete $attrlist{ABSTRACT};
=cut
        if ($tp_id && !exists $template{$tp_id}) {
                $template{$tp_id} = $tp_id;
                Apache->warn(gettext("Template $tp_id is not in this server list"));
        }
        my @templ = ("NULL", sort keys(%template));
        $template{'NULL'} = gettext("Type default");
        print $cgi->table(
                { -border => 1, -width => '100%' },
                $cgi->Tr(
                        $cgi->td(
                                gettext("Template: "),
                                $cgi->popup_menu(
                                        -name    => 'TEMPLATE_ID',
                                        -Values  => \@templ,
                                        -labels  => \%template,
                                        -default => 'NULL'
                                ),
                                $cgi->small(
                                        gettext(
                                                    "If you don't see necessary template here, "
                                                  . "enable template for thi item type through editing template properties"
                                        )
                                )
                        )
                ),
                $cgi->Tr(
                        $cgi->td(
                                $tp_id
                                ? $cgi->a({ -href => $ctx{site}->make_item_url($tp_id), -target => '_blank' },
                                        gettext("View"))
                                  . $cgi->a(
                                        { -href => $ctx{site}->make_item_url($tp_id) . "/edit_template", -target => '_blank' },
                                        gettext("Edit")
                                  )
                                : '&nbsp;'
                        )
                )
        );
        # Если айтем был показан по другому шаблону...
        my ($ref_server, $ref_item, $ref_template);
        ($ref_server, $ref_item, $ref_template) =
          (split(/\/\/?/, $cgi->param('REFERER')))[2, 3, 4];
        if ($ref_server eq 'scripts') {$ref_item = $ref_template = '';}
        $ref_template =~ s/^(.*?)\?.*/$1/;
        if ($ref_template && $ref_template ne $tp_id && $ref_item eq $item_id) {
                my $tplurl = $ctx{site}->make_item_url($ref_template);
                print "<tr><td>",
                  gettext(
"<b>$item_id</b> was shown through <b>$ref_template</b> template which is not default for this item.</td>\n<td>["
                  ), $cgi->a({ -href => $tplurl, -target => '_blank' }, gettext("View")),
                  "\&nbsp;$ref_template\&nbsp;]\&nbsp;</td><td>\&nbsp;[",
                  $cgi->a({ -href => $tplurl . "/edit_template", -target => '_blank' },
                        gettext("Edit")),
                  "\&nbsp;$ref_template\&nbsp;]\n</td></tr>\n";
        }
        print "</table>\n";
        delete $attrlist{TEMPLATE_ID};
=cut
        unless ($fctx->is_create) {
                # Кнопка редактирования текста айтема прямо в странице интерфейса модератора
                text_in_form_button($cgi);
                # Пока публикатора и последнего редактировавшего
                publisher_and_last_editor();
        }
        # Show/edit item attributes.
        print $cgi->h2(gettext('Attributes of item'));
    print $cgi->table(
        { -cellpadding => 0, -cellspacing => 5, -border => 0, },
        (
            $fctx->is_create ? create_attrs(
                {
                    ITEM_ID =>
                        { type => 'STRING', name => gettext('Identifier'), table => 'ITEM' }
                },
                'ITEM'
                ) : ''
            )
            . (
            $fctx->get('TYPE_ID') eq 'AUTHOR' ? create_attrs(
                {
                    PASSWD =>
                        { type => 'STRING', name => gettext('New password'), table => 'AUTHOR' }
                },
                'AUTHOR'
                ) : ''
            )
            . create_attrs(\%attrlist, 'ITEM')
            . (
            defined $ext_attr_table
            ? create_attrs(\%attrlist, $ext_attr_table)
            : ''
            )
        ),
        $cgi->hr;
        # Show/edit information on links to other items.
    print $cgi->h2(
        gettext('Links to other items') . '&nbsp('
            . $cgi->small(
            gettext('Enter ITEM_IDs of items related to current into following fields')
            )
            . ')'
    );
        print '<table cellpadding=0 cellspacing=5 border=0 width="100%">';
        create_link_fields($ext_attr_table);
        print '</table>';
        print $cgi->hr;
        # Links which could be ordered
        list_links_to_order(0);
        print $cgi->h4(gettext("Body text"));
        print create_text();
        print $cgi->hr;
        print $cgi->table(
                { -cellpadding => 0, -cellspacing => 5, -border => 0, -width => "100%" },
                $cgi->Tr(
                        $cgi->td(
                                gettext("Upon save:"), "\&nbsp;\n"
                                  .
                                  # Вывести меню возможных действий по сохранении айтема
                                  $cgi->popup_menu(
                                        -name   => 'RETURN',
                                        -Values => ['back', 'item', 'stay'],
                                        -labels => {
                                                back => gettext("Return where we came from"),
                                                item => gettext("Go to new/updated item"),
                                                stay => gettext("Don't leave web-mastering page")
                                        },
                                        -default => $cgi->param('RETURN') || "item"
                                  )
                                  . $cgi->submit(-name => 'SAVE', -value => gettext('Save'))
                        ),
                        (
                                $fctx->is_create ? '' : $cgi->td(
                                        { -align => "right" },
                                        $cgi->submit(-name => 'GO_DELETE', -value => gettext('Delete'))
                                )
                          )
                )
        );
        print $cgi->end_form;
}

# # sub get_attr_list ($attrlist) # # Возвращает список updatable атрибутов в виде хэша имя(в формате # параметра для update_item => таблица # sub get_attr_list { my $attrlist = shift; my $sth = $dbh->prepare(<<'EOS'); select NAME, ATTR_TYPE, TABLE_NAME, get_msg(MSG_ID) from ATTRIBUTE where ATTR_STATE = 'UPDATABLE' EOS $sth->execute; my ($name, $type, $table, $descr); while (($name, $type, $table, $descr) = $sth->fetchrow_array) { $attrlist->{$name} = { 'type' => $type, 'table' => $table, 'name' => $descr }; } }

# # sub get_link_list ($linklist) # sub get_link_list { my $linklist = shift; my $sth = $dbh->prepare( 'select linktype_id,get_msg(msg_id),rel_type from linktype where editable=1'); $sth->execute; my ($type, $name, $rel); while (($type, $name, $rel) = $sth->fetchrow_array) { $linklist->{$type} = { 'name' => $name, 'multi' => $rel !~ /^1/ }; } }

# # sub get_type_list ($class) # # Возвращает список типов iteм в виде хэша название->комментарий # sub get_type_list { my $class = shift; my $sth; if ($class) { $sth = $dbh->prepare( 'select item_type.type_id, nvl(get_msg(msg_id),item_type.type_id) from item_type,default_template where extended_attr_table=? and item_type.type_id = default_template.type_id and default_template.keyitem=?', {} ); $sth->execute($class, $Communiware::server); } else { $sth = $dbh->prepare( 'select item_type.type_id, nvl(get_msg(msg_id),item_type.type_id) from item_type,default_template where extended_attr_table is null and item_type.type_id=default_template.type_id and default_template.keyitem=? ' ); $sth->execute($Communiware::server); } my (@list, $t, $d); while (($t, $d) = $sth->fetchrow_array) {push @list, $t, $d} return @list; }

# # sub get_template_list () # # Возвращает список шаблонов в виде хэша item_id=>nvl(title,item_id); # sub get_template_list { my $sth = $dbh->prepare( ``select item.item_id,title from item, template where template.item_id=item.item_id and template_type='PAGE' and (server=? or server='default') order by item.item_id'' ); $sth->execute($Communiware::server); my (@list, $t, $d); while (($t, $d) = $sth->fetchrow_array) { push @list, $t, ``$d ($t)''; } return @list; }

# # sub get_template_list_typed () # # Возвращает список шаблонов в виде хэша item_id=>nvl(title,item_id); # sub get_template_list_typed { my $type = shift;

        #new variant using subs_item_type
        my $sth_allowed = $dbh->prepare(<<EOS);
select item.item_id, title 
  from item, subs_item_type, template
 where item.item_id = SUBSCRIPTION_TYPE
   and template.item_id = item.item_id
   and template.template_type = 'PAGE'
   and subs_item_type.type_id = ?
   and (restrict_templates = 0 or server = ?)
EOS
        $sth_allowed->execute($type, $Communiware::server);
        my (@list, $t, $d);
        while (($t, $d) = $sth_allowed->fetchrow_array) {
                push @list, $t, "$d ($t)";
        }
        return @list;
}

# # sub download_link ($id) # # This item appears just becouse MSIE refuses to download file if told # that it have application/octet-stream and tries to determine file type # from context # sub download_link { my $id = shift; my $href = ``<A HREF=\''/scripts/getitem/item_$id.html?ITEM_ID=$id\&TYPE=``; return $href . (($ENV{'HTTP_USER_AGENT'} =~ /MSIE/) ? ''text%2Fhtml\`` target=\''_blank\``>'' : ``application%2Fx-communiware-item\''>``); }

sub create_attrs { my ($attrlist, $table) = @_; my $out = ''; while (my ($name, $val) = each(%$attrlist)) { next unless $val->{'table'} eq $table; my $control = Communiware::DE::EditField::exec($ctx{form}, $name); $out .= $cgi->Tr( $cgi->td( { -valign => 'top', -width => ``30%'' }, $cgi->span({ -title => $name }, $val->{'name'}) ), $cgi->td($control) ) if $control; } return $out; }

sub create_text { my $fc = $ctx{form};

    # we have to first analyze text for representation
    my $control = Communiware::DE::EditField::exec(
        $fc, 'TEXT', undef,
        wysiwyg => 'no',
        style => 'width: 100%; height: 100%'
    );
    my $repr = $fc->get('TEXT.REPR');
    my $out = $cgi->table(
        { -border => 0, -cellpadding => 0, -cellspacing => 5, -width => "100%" },
        $cgi->Tr(
            { -valign => 'top' },
            $cgi->td($control),
            $cgi->td('&nbsp;'),
            $cgi->td(
                { -width => '10%' },
                gettext('Content-type') . ': ' . $fc->CONTENT_TYPE() . $cgi->br,
                (
                    $repr ? gettext('Representation') . ': ' . $repr . $cgi->br
                    : ''
                ),
                gettext('Upload:'),
                $cgi->br,
                $cgi->filefield(-name => posting_param_name('UPLOAD')),
                $cgi->br,
                (
                    !$fc->is_create ? $cgi->a(
                        {
                            -href => $fc->PREFIX('SCRIPT')
                                . '/pictures?ITEM_ID='
                                . $fc->id
                                . '&SERVER='
                                . $sc->id,
                            -target => '_blank'
                        },
                        gettext('Graphic design elements')
                        )
                    : ''
                ),
            )
        )
    );
    return $out;
}

# # sub ask_delete_confirmation () # sub ask_delete_confirmation {

    start_interface(gettext('Confirm item deleting, please.'));
    my $item = $ctx{item};
    print $cgi->h2(gettext('You are going to delete an item') . " '"
            . $item->id . "' ('"
            . $item->get('TITLE') . "')")
        . $cgi->h3(gettext("This item has type of '")
            . $item->get('TYPE_ID') . "' (\""
            . $item->TXT('TYPE_ID')
            . "\")");
    my $links = list_links_to_order(1);
    print $cgi->p(
        gettext(
            "WARNING: children will NOT be deleted with this item. You have to delete'em explicitly if you want so."
        )
    ) if $links;
    print $cgi->start_form(-method => 'GET', -action => $ENV{'SCRIPT_NAME'}),
        hiddens('REFERER', 'SERVER', 'RETURN', posting_param_name('ITEM_ID'), 'Posting');
    print $cgi->h3(gettext("Do you really want to delete it?")), "\n",
        $cgi->submit(-name => 'DELETE', -value => gettext("Delete")),
        $cgi->submit(-name => 'none', -value => gettext("Do not delete")), $cgi->end_form,
        $cgi->end_html;
    return "EXIT NOW";
}

# # sub create_link_fields ($restrict) # sub create_link_fields { my $ext_attr_table = shift; warn ``EAT=$ext_attr_table\n''; my $fctx = $ctx{form}; my $sth;

        # get links for current TYPE_ID
        $sth = $dbh->prepare(<<'EOS');
select LINKTYPE.LINKTYPE_ID, LINKTYPE.REL_TYPE, get_msg(LINKTYPE.MSG_ID)
  from LINKTYPE, ALLOWED_LINKTYPE 
 where LINKTYPE.LINKTYPE_ID = ALLOWED_LINKTYPE.LINKTYPE_ID
   and LINKSIDE = 'PASSIVE'
   and TYPE_ID = ?
   and LINKTYPE.EDITABLE = 1
EOS
        $sth->execute($fctx->get('TYPE_ID'));
    my ($ltype, $rel_type, $descr, $count);
    while (($ltype, $rel_type, $descr) = $sth->fetchrow_array) {
        if ($rel_type =~ /M:N/) {
            $cgi->param($ltype, join(",", grep(!/^NULL$/, $cgi->param($ltype))));
        }
        else {
            $cgi->delete($ltype) if ($cgi->param($ltype) eq 'NULL');
        }
        $count = $dbh->selectrow_array(<<'EOS', {}, $ltype, $Communiware::server);
select count(ITEM_ID)
  from item
 where type_id in (select type_id from allowed_linktype where linktype_id=? and linkside='ACTIVE')
   and (server=? or restrict_templates=0)
EOS
        print $cgi->Tr(
            $cgi->td({ -width => "30%" }, $cgi->span({-title => $ltype}, "$descr ($rel_type)"))
                . $cgi->td({ -width => "40%" },
                                Communiware::DE::EditField::exec($fctx, $ltype, undef, 'style', 'width: 100%')
                                
                                )
                . $cgi->td(
                      $cgi->textfield(-name => "${ltype}_PATTERN", -style => "width: 100%")
                    . $cgi->hidden("${ltype}_DESCR", $descr)
                )
                . $cgi->td(
                $cgi->submit(-name => "${ltype}_CHOOSE", -value => gettext("Choose"))
                    . "&nbsp;($count)"
                )
        );
    }
}

# # sub choose_linked ($linktype) # sub choose_linked { my $linktype = shift; my $descr = shift;

    my $linktype_param = posting_param_name($linktype);
    my $item           = $sc->special_context('document_item');
    print $cgi->header(text_html()),
        $cgi->start_html(-title => $sc->id . ': '
            . gettext('selection of linked items for link type ')
            . $linktype),
        $cgi->h1(gettext('Choose items linked with ') . '\''
            . $item->id . '\''
            . gettext(' by link ')
            . "'$descr'");
    my $pattern = $cgi->param("${linktype}_PATTERN");
    print $cgi->h3(gettext("Search pattern") . ' &quot;' . $cgi->escapeHTML($pattern) . "&quot")
        if length($pattern);
    $pattern = '%' . $pattern . '%';
    print $cgi->startform(-method => 'POST', -action => $cgi->url(-relative => 1, -query => 0));
    # pass form parameters
    for my $param ($cgi->param) {
        print $cgi->hidden($param) unless $param eq $linktype_param || $param eq "${linktype}_CHOOSE";
    }
    # Link parameters
    my ($hierarchy, $reltype) =
        $dbh->selectrow_array('select hierarchy,rel_type from linktype where linktype_id = ?',
        {}, $linktype);
    my $multiple = $reltype =~ /M:N/;
    print gettext("Link type: "), ($multiple ? gettext("multiple") : gettext("single")), " ",
        ($hierarchy ? gettext("hierarchic") : gettext("one-level")), $cgi->br;
    $cgi->param($linktype_param, split(/\s*,\s*/, $cgi->param($linktype_param)))
        if $multiple;
    my %missing;
    if ($cgi->param($linktype_param)) {
        map {$missing{$_} = 1} $cgi->param($linktype_param);
    }
    my $sth;
    if ($hierarchy) {
        $sth = $dbh->prepare(<<'EOS');
select ITEM_ID, ACTIVE as PARENT_ID, TITLE, ORDNUM
  from ITEM left join (select ACTIVE, PASSIVE, ORDNUM from ITEM_LINK where LINKTYPE_ID = ?) a
    on (ITEM_ID = PASSIVE)
 where (SERVER = ? or RESTRICT_TEMPLATES = 0)
   and TYPE_ID in (select TYPE_ID from ALLOWED_LINKTYPE where LINKTYPE_ID = ? and LINKSIDE = 'ACTIVE')
   and (ITEM_ID like ? or TITLE like ?)
 order by item_id
EOS
        $sth->execute($linktype, $sc->id, $linktype, $pattern, $pattern);
    }
    else {
        $sth = $dbh->prepare(<<'EOS');
select ITEM_ID, TITLE from ITEM
 where TYPE_ID in (select TYPE_ID from ALLOWED_LINKTYPE where LINKTYPE_ID = ?  and linkside = 'ACTIVE') 
   and (SERVER = ? or RESTRICT_TEMPLATES = 0)
   and (ITEM_ID like ? or TITLE like ?)
  order by item_id
EOS
        $sth->execute($linktype, $sc->id, $pattern, $pattern);
    }
    my $result = $sth->fetchall_arrayref({});
    $sth->finish;
    $result = treesort($result, sub {Communiware::Ontology::attr_type(undef, $_[0])},
        'ITEM_ID', 'PARENT_ID', 'ORDNUM')
        if $hierarchy;
    my $record;
    my $level = 0;
    print "<DL>\n";
    for $record (@$result) {
        print "<DT>";
        delete $missing{ $record->{'ITEM_ID'} };
        if (exists $record->{'LEVEL'}) {
            my $newlevel = $record->{'LEVEL'};
            while ($level < $newlevel) {
                print "<DL><DT>";
                $level++;
            }
            while ($level > $newlevel) {
                print "</DL>";
                $level--;
            }
        }
        if ($multiple) {
            print $cgi->checkbox(
                -name  => $linktype_param,
                -value => $record->{'ITEM_ID'},
                -label => ""
            );
        }
        else {
            print '<input type="radio" name="'
                . $linktype_param
                . '" value="'
                . $record->{'ITEM_ID'} . '"'
                . ($record->{'ITEM_ID'} eq $cgi->param($linktype_param) ? ' CHECKED' : '')
                . '>';
        }
        print $cgi->a(
            {
                -href   => $sc->make_item_url($record->{'ITEM_ID'}),
                -target => '_blank'
            },
            $record->{'ITEM_ID'}
            ),
            " ", &Communiware::Format::untag_html($record->{'TITLE'}, 'p');
    }
    while ($level > 0) {print "</DL>"; $level--;}
    print $cgi->hr;
    unless ($multiple) {
        if (exists $missing{ $cgi->param($linktype_param) }) {
            print "<DT><input type=\"radio\" name=$linktype value=\""
                . $cgi->param($linktype)
                . "\" CHECKED>"
                . gettext("Current value")
                . "(", $cgi->param($linktype), ")\n";
        }
        print "<DT><input type=\"radio\" name=$linktype_param value=\"NULL\"",
            ($cgi->param($linktype_param) ? "" : " CHECKED"), ">",
            gettext("No links of type ") . $linktype;
    }
    else {
        map {
            print "<DT>",
                $cgi->checkbox(-name => $linktype_param, -value => $_, -label => " $_");
            }
            keys %missing;
    }
    print "</DL>";
    print $cgi->submit(-name => "MAKE_CHOICE", -value => gettext("Choose")), $cgi->end_form,
        $cgi->end_html;
}

# # sub list_links_to_order ($dont_allow_sort) # sub list_links_to_order { my $dont_allow_sort = shift; my $item = $cgi->param('ITEM_ID') or return; my $header_out = 0; my $linktypes_count = 0;

        my $sth = $dbh->prepare("
select
  lt.linktype_id,
  count(il.passive) as cnt,
  nvl(get_msg(msg_id), lt.linktype_id)
from
  linktype lt, item_link il
where
  lt.linktype_id = il.linktype_id and
  il.active = ?
group by
  lt.linktype_id, msg_id
");
        $sth->execute($item);
        my ($type, $count, $name);
        while (($type, $count, $name) = $sth->fetchrow_array) {
                next if $count <= 1;
                $linktypes_count++;
                unless ($header_out) {
                        print $cgi->h3(gettext("This item have childrens by following link types")),
                          "\n<table border=0>\n";
                        $header_out++;
                }
                print "<TR><TD>", $cgi->escapeHTML($name), ":</TD><TD>$count</TD>\n";
                print "<TD>",
                  $cgi->a(
                        {
                                    -href => $Communiware::config{SCRIPTURL}
                                  . "/orderlink?SERVER="
                                  . $cgi->param('SERVER')
                                  . "\&ITEM_ID=$item\&LINKTYPE=$type\&RETURN="
                                  . $cgi->param('RETURN')
                                  . "\&REFERER="
                                  . $cgi->escape($cgi->param('REFERER'))
                        },
                        gettext("[Reorder]")
                  ),
                  "</TD></TR>\n"
                  unless $dont_allow_sort;
        }
        print "</table>\n". $cgi->hr if ($header_out);
        return $linktypes_count;
}

# # sub show_html_field () # sub show_html_field { my $cgi = shift; print gettext( ``Text in HTML format - complete from &lt;HTML&gt; to &lt;/HTML&gt; tag, or plain text with highlighting as in replic pos'' ), ``<BR>\n'', $cgi->textarea( -name => ``TEXT_HTML'', -wrap => ``soft'', -rows => 25, -cols => ``80'' ), $cgi->hidden('SHOW_HTML'), ``<BR>''; }

# # sub setheader (,$string) # sub setheader { my $cgi = shift; $cgi->param(``__header__'', shift); }

# # sub putheader ($cgi, $string) # sub putheader { my $cgi = shift; my $string = $cgi->param(``__header__''); if ($string) { print $string; $cgi->delete(``__header__''); } $cgi->param(``__header__'', $string) if ($string = shift); }

# # sub perform_ucheck () # # an internal subroutine for sub user_check # sub perform_ucheck { }

# # sub hiddens (@) # sub hiddens { my $out; foreach my $param (@_) { $cgi->param($param, $cgi->referer) if $param eq 'REFERER' && !defined $cgi->param($param); $out .= $cgi->hidden($param), @_; } return $out; }

# # sub get_act_linked($passive, $linktype) # # Select all items who are active for given item by given linktype. # Returns a refference to this list; # sub get_act_linked ($$) { my $passive = shift; my $sth = $dbh->prepare( 'select active from item_link where linktype_id=? and passive=?'); $sth->execute(shift, $passive); my (@links, $link); while (($link) = $sth->fetchrow_array) {push @links, $link} return \@links; }

sub set_document_item { return Communiware::Context::Item->make_special_context('document_item', $cgi->param('S.ITEM_ID') || $cgi->param('ITEM_ID')); }

sub start_interface {
my $title = shift;
        my $user_id = $ctx{user}->get('ITEM_ID');
        my $login   = $ctx{user}->get('LOGIN');
        my $item = Communiware::Context->special_context('document_item');
        if($item) {
                $cgi->param('ITEM_ID', $item->id);
                $ctx{item} = Communiware::Context->set_special_context('document_item', $item);
                $item->formname('item_edit');
        }
        my $sth = $dbh->prepare(<<'TYPES');
select ITEM_TYPE.TYPE_ID, nvl(get_msg(MSG_ID), initcap(ITEM_TYPE.TYPE_ID)) 
  from ITEM_TYPE, DEFAULT_TEMPLATE 
 where ITEM_TYPE.TYPE_ID = DEFAULT_TEMPLATE.TYPE_ID 
   and DEFAULT_TEMPLATE.KEYITEM = ?
union
select ITEM_TYPE.TYPE_ID, nvl(get_msg(MSG_ID), initcap(ITEM_TYPE.TYPE_ID))
  from ITEM_TYPE
 where TYPE_ID in ('SERVER','TEMPLATE')
TYPES
        $sth->execute($sc->id);
        my %type_name;
        while (my ($type, $name) = $sth->fetchrow_array) {
                $type_name{$type} = $name;
        }
        print $cgi->start_html(-title => "$Communiware::server: $title");
        print $cgi->table(
                { -border => 0, -cellpadding => 0, -cellspacing => 5, -width => "100%" },
                $cgi->Tr(
                        $cgi->td(
                                $cgi->small(
                                        $cgi->a(
                                                { -href => $cgi->param('REFERER') },
                                                '[&lt;&lt;&nbsp;' . gettext('Return') . ']'
                                        ),
                                        "&nbsp;|&nbsp;",
                                        (
                                                gettext('User') . ': '
                                                  . $cgi->a(
                                                        { -href => $sc->make_item_url($user_id) },
                                                        ($user_id . ($user_id ne $login ? "/$login" : ''))
                                                  )
                                        ),
                                        "&nbsp;|&nbsp;",
                                        (
                                                gettext('Site') . ': '
                                                  . $cgi->a({ -href => $sc->make_item_url($sc->id) }, $sc->id)
                                        ),
                                )
                        ),
                        $cgi->td(
                                $cgi->start_form(
                                        -method => 'GET',
                                        -action => $ENV{'SCRIPT_NAME'},
                                        -style  => 'margin:0'
                                  )
                                  . hiddens('REFERER', 'SERVER', 'RETURN')
                                  . gettext('Item') . ': '
                                  . $cgi->textfield(-name => 'ITEM_ID', -maxsize => $Communiware::MaxItemIdLen)
                                  . $cgi->submit(-name => 'FIND', -value => gettext('Go'))
                                  . $cgi->end_form
                        ),
                        $cgi->td(
                                $cgi->start_form(
                                        -method => 'GET',
                                        -action => $ENV{'SCRIPT_NAME'},
                                        -style  => 'margin:0'
                                  )
                                  . hiddens('REFERER', 'SERVER', 'RETURN')
                                  . gettext('New') . ': '
                                  . $cgi->popup_menu(
                                        -name     => 'TYPE_ID',
                                        -Values   => [keys %type_name],
                                        -labels   => \%type_name,
                                        -onChange => 'this.form.submit()'
                                  )
                                  . $cgi->submit(-name => "NEW_ITEM", -value => gettext("Create"))
                                  . $cgi->end_form
                        ),
                )
          ),
          $cgi->hr;
}

# # sub text_in_form_button # # Кнопка редактирования текста прямо в форме # (или ссылка на этот текст, если он уже в форме) #

sub text_in_form_button {
my $cgi = shift;
        #FIXME тут надо обращаться в модуль, работающий с этим типом.
        return if (non_text_type($cgi->param('TYPE_ID')));
        if ($cgi->param('SHOW_HTML')) {
                print $cgi->a({ -href => "#main_text" }, gettext("Go to main text"));
        }
        else {
                if ($cgi->param('DATASIZE') < 65536) {
                        print $cgi->submit(-name => 'SHOW_HTML', value => gettext("Edit in browser"));
                }
                else {
                        print gettext(
                                "Text is too large. Use Download button.\n");
                }
        }
        my $chkbox = {
                -name  => 'ALWAYS_TEXT',
                -value => '1',             #-on=>undef, #$cgi->param('ALWAYS_TEXT'),
                #                     -override=>0,
                -label => gettext(" Always edit in browser ")
        };
        $$chkbox{-on} = 1
          if (
                $cgi->param('ALWAYS_TEXT')
                || (                       #!$cgi->param('HIDD_ALWAYS_TEXT') &&
                        $cgi->param('SAVE_ALWAYS_TEXT')
                )
          );
        print "\n", $cgi->checkbox(%$chkbox), "<BR>\n";  #,$cgi->hidden('HIDD_ALWAYS_TEXT',1),"\n";
        $cgi->delete('ALWAYS_TEXT');
}

sub publisher_and_last_editor {
my $flag;
my $fctx = $ctx{form};
print '<p>';
if (my $publisher_id = $fctx->get('PUBLISHER')) {
my $publisher = Communiware::Context::Item->new($publisher_id);
print gettext(``Published by ''),
$cgi->a(
{ -href => $fctx->make_item_url($publisher_id) },
Communiware::Format::untag_html($publisher->get('TITLE'), ``a'')
) . ', '. $fctx->get('PUBLISHED') . '&nbsp;|&nbsp;';
$flag = 1;
}
print gettext('Last edited');
if (my $lasteditor_id = $fctx->get('LASTEDITED')) {
my $lasteditor = Communiware::Context::Item->new($lasteditor_id);
print gettext(' by '),
$cgi->a(
{ -href => $fctx->make_item_url($lasteditor_id) },
Communiware::Format::untag_html($lasteditor->get('TITLE'), ``a'')
);
$flag = 2;
}
        print scalar(($flag == 2) ? ', ' : ': '), $fctx->get('LASTCHANGE');
        print '&nbsp;|&nbsp;' .gettext("The last status update was at "), $fctx->get('STATUS_UPDATE')
          if $fctx->get('STATUS_UPDATE');
        print '</p>';
}

sub get_type_msg ($) { my ($m) = $dbh->selectrow_array( 'select get_msg(MSG_ID) from ITEM_TYPE where TYPE_ID = ?', {}, shift); return $m; }

# # sub print_header ($cookies_array_ref) # sub print_header ($) { my $cookies = shift;

        if (defined $cookies && scalar @$cookies) {
                print $cgi->header(
                        -type   => text_html(),
                        -cookie => $cookies
                  );
        }
        else {
                print $cgi->header(
                        text_html()
                  );
        }
}

# # sub get_content_type ($type_id) # sub get_content_type ($) { my $t = shift; return $dbh->selectrow_array( ``select CONTENT_TYPE from item_type where type_id=?'', {}, $t || return ''); }

# # Checks whether given type have no editable text #FIXME Should call some method of Communiware::Datatype::* sub non_text_type { my $type = shift; my $ct = get_content_type($type); return 1 unless $ct; return 1 if $ct eq 'Binary'; return 1 if $ct eq 'None'; return 1 if $ct eq 'Table';

}

sub posting_param_name { return POSTING_PREFIX . '.' . shift; }

16 октябрь 2007 13:45