# Selima Website Content Management System # LinkCat.pm: The related-link category form. # Copyright (c) 2004-2018 imacat. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Author: imacat # First written: 2004-10-24 package Selima::Form::LinkCat; use 5.008; use strict; use warnings; use base qw(Selima::Form); use Selima::CommText; use Selima::FormFunc; use Selima::HTTP; use Selima::MarkAbbr; use Selima::ShortCut; # new: Initialize the HTML form table displayer sub new : method { local ($_, %_); my ($class, $status, $args, $self); ($class, $status, $args) = @_; $args = {} if !defined $args; # $args must be a hash reference http_500 "type of argument 2 must be a hash reference" if ref($args) ne "HASH"; $$args{"type"} = form_type if !exists $$args{"type"}; $$args{"table"} = "linkcat" if !exists $$args{"table"}; $$args{"deltext"} = C_("Delete this category") if !exists $$args{"deltext"}; if (!exists $$args{"summary"}) { # A form to create a new item if ($$args{"type"} eq "new") { $$args{"summary"} = C_("This table provides you a form to add a new category."); # A form to edit a current item } elsif ($$args{"type"} eq "cur") { $$args{"summary"} = C_("This table provides you a form to edit a current category."); # A form to delete a current item } elsif ($$args{"type"} eq "del") { $$args{"summary"} = C_("This table provides you a form to delete a category."); } } if (!exists $$args{"cols"}) { # A form to create a new item if ($$args{"type"} eq "new") { $$args{"cols"} = [qw(parent id ord title kw hid)]; # A form to edit a current item # A form to delete a current item } elsif ($$args{"type"} eq "cur" || $$args{"type"} eq "del") { $$args{"cols"} = [qw(sn parent id ord title kw hid scats links created createdby updated updatedby)]; } } if (!exists $$args{"title"}) { # A form to create a new item if ($$args{"type"} eq "new") { $$args{"title"} = C_("Add a New Link Category"); # A form to edit a current item } elsif ($$args{"type"} eq "cur") { $$args{"title"} = C_("Edit a Current Link Category"); # A form to delete a current item } elsif ($$args{"type"} eq "del") { $$args{"title"} = C_("Delete a Link Category"); } } $self = $class->SUPER::new($status, $args); ${$self->{"maxlens"}}{"ord"} = 2; if ($self->{"type"} eq "cur") { if (defined $self->{"cur"}->param("scatcount") && $self->{"cur"}->param("scatcount") > 0) { $self->{"nodelete"} = 1; push @{$self->{"prefmsg"}}, C_("This category has [numerate,_1,a subcategory,subcategories]. It cannot be deleted. To delete the category, [numerate,_1,its subcategory,all of its subcategories] must first be deleted.", $self->{"cur"}->param("scatcount")); } if (defined $self->{"cur"}->param("linkcount") && $self->{"cur"}->param("linkcount") > 0) { $self->{"nodelete"} = 1; push @{$self->{"prefmsg"}}, C_("This category has [numerate,_1,a link,links]. It cannot be deleted. To delete the category, [numerate,_1,its link,all of its links] must first be deleted.", $self->{"cur"}->param("linkcount")); } } return $self; } # _html_col_hid: Hide? sub _html_col_hid : method { $_[0]->_html_coltmpl_bool("hid", h_abbr(C_("Hide?")), h_abbr(C_("Hide this category")), h_abbr(C_("Show this category")), h_abbr(C_("Hide this category currently."))); } # _html_col_id: The ID. sub _html_col_id : method { $_[0]->_html_coltmpl_text("id", h_abbr(C_("ID.:")), undef, 8); } # _html_col_links: The links sub _html_col_links : method { my ($self, $form, $current, $label, $mark, $colspan, $thclass, $thcolspan); $self = $_[0]; $form = $self->{"form"}; $current = $self->{"cur"}; $mark = $self->_mark("links"); $colspan = $self->_colspan; $label = h_abbr(C_("[numerate,_1,Link,Links]:", $current->param("linkcount"))); # A current form span for 2 columns $thclass = $self->{"type"} ne "cur"? " class=\"th\"": ""; $thcolspan = $self->{"type"} eq "cur"? " colspan=\"2\"": ""; print << "EOT"; $mark$label EOT print " "; for ($_ = 0, @_ = qw(); $_ < $current->param("linkcount"); $_++) { push @_, sprintf("
  • %2\$s\n" . " (%3\$s)\n" . "
  • \n", h("links.cgi?form=cur&sn=" . $current->param("link$_" . "sn")), h_abbr($current->param("link$_" . "title")), h($current->param("link$_" . "url"))); } print @_ > 0? "
      \n" . join("", @_) ."
    \n ": h_abbr(t_none); print << "EOT"; EOT } return 1;