1 package BSE::Edit::Catalog;
3 use base 'BSE::Edit::Article';
5 use BSE::Util::Tags qw(tag_article);
6 use constant CATALOG_CUSTOM_FIELDS_CFG => "catalog custom fields";
8 our $VERSION = "1.003";
10 sub base_template_dirs {
15 my ($self, $article) = @_;
17 my @extras = $self->SUPER::extra_templates($article);
18 my $basedir = $self->{cfg}->entryVar('paths', 'templates');
19 push @extras, 'catalog.tmpl' if -f "$basedir/catalog.tmpl";
25 # my ($self, $acts, $req, $article, $articles, $msg) = @_;
29 # $self->SUPER::low_edit_tags($acts, $req, $article, $articles, $msg),
34 my ($self, $article, $cgi) = @_;
37 my $t = $cgi->param('_t');
38 if ($t && $t =~ /^\w+$/) {
41 return $self->{cfg}->entry('admin templates', $base,
45 sub generator { "BSE::Generate::Catalog" }
48 my ($self, $data, $articles, $parent, $rmsg) = @_;
50 my $shopid = $self->{cfg}->entryErr('articles', 'shop');
52 ($parent->{id} == $shopid
53 || $parent->{generator} eq 'BSE::Generate::Catalog')) {
54 $$rmsg = "Catalogs must be in the shop";
58 return $self->SUPER::validate_parent($data, $articles, $parent, $rmsg);
61 sub possible_parents {
62 my ($self, $article, $articles) = @_;
67 my $shopid = $self->{cfg}->entryErr('articles', 'shop');
68 # the parents of a catalog can be other catalogs or the shop
69 my $shop = $articles->getByPkey($shopid);
70 my @work = [ $shopid, $shop->{title} ];
72 my ($id, $title) = @{pop @work};
73 if (!$article->{id} || $article->{id} != $id) {
75 $labels{$id} = $title;
76 push @work, map [ $_->{id}, $title.' / '.$_->{title} ],
77 sort { $b->{displayOrder} <=> $a->{displayOrder} }
78 grep $_->{generator} eq 'BSE::Generate::Catalog',
79 $articles->getBy(parentid=>$id);
83 return (\@values, \%labels);
86 sub default_link_path {
87 my ($self, $article) = @_;
89 $self->{cfg}->entry('uri', 'shop', '/shop');
93 my ($self, $article) = @_;
100 if ($self->{cfg}->entry('shop', 'secureurl_articles', 1)) {
101 $urlbase = $self->{cfg}->entryVar('site', 'secureurl');
105 if ($article->is_dynamic) {
106 return "$urlbase/cgi-bin/page.pl?page=$article->{id}&title=".escape_uri($article->{title});
109 my $shop_uri = $self->link_path($article);
110 return $urlbase.$shop_uri."/shop$article->{id}.html";
114 return qw(BSE::Edit::Product BSE::Edit::Seminar BSE::Edit::Catalog);
117 sub shop_article { 1 }
119 sub default_template {
120 my ($self, $article, $cfg, $templates) = @_;
122 my $template = $cfg->entry('catalogs', 'template');
124 if $template && grep $_ eq $template, @$templates;
126 return $self->SUPER::default_template($article, $cfg, $templates);
132 return ( 'catalog flags', $self->SUPER::flag_sections );
135 sub type_default_value {
136 my ($self, $req, $col) = @_;
138 my $value = $req->cfg->entry('catalog defaults', $col);
139 defined $value and return $value;
141 return $self->SUPER::type_default_value($req, $col);
147 my $custom = $self->SUPER::custom_fields();
149 require DevHelp::Validate;
150 DevHelp::Validate->import;
151 return DevHelp::Validate::dh_configure_fields
155 CATALOG_CUSTOM_FIELDS_CFG,
156 BSE::DB->single->dbh,