]> git.imager.perl.org - bse.git/blob - site/cgi-bin/modules/BSE/Edit/Catalog.pm
304c944c2e0b5b41ca78cb3c2bae4a709364a775
[bse.git] / site / cgi-bin / modules / BSE / Edit / Catalog.pm
1 package BSE::Edit::Catalog;
2 use strict;
3 use base 'BSE::Edit::Article';
4 use BSE::Util::HTML;
5 use BSE::Util::Tags qw(tag_article);
6 use constant CATALOG_CUSTOM_FIELDS_CFG => "catalog custom fields";
7
8 our $VERSION = "1.003";
9
10 sub base_template_dirs {
11   return ( "catalog" );
12 }
13
14 sub extra_templates {
15   my ($self, $article) = @_;
16
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";
20
21   return @extras;
22 }
23
24 #  sub low_edit_tags {
25 #    my ($self, $acts, $req, $article, $articles, $msg) = @_;
26
27 #    return 
28 #      (
29 #       $self->SUPER::low_edit_tags($acts, $req, $article, $articles, $msg),
30 #      );
31 #  }
32
33 sub edit_template { 
34   my ($self, $article, $cgi) = @_;
35
36   my $base = 'catalog';
37   my $t = $cgi->param('_t');
38   if ($t && $t =~ /^\w+$/) {
39     $base = $t;
40   }
41   return $self->{cfg}->entry('admin templates', $base, 
42                              "admin/edit_$base");
43 }
44
45 sub generator { "BSE::Generate::Catalog" }
46
47 sub validate_parent {
48   my ($self, $data, $articles, $parent, $rmsg) = @_;
49
50   my $shopid = $self->{cfg}->entryErr('articles', 'shop');
51   unless ($parent && 
52           ($parent->{id} == $shopid 
53            || $parent->{generator} eq 'BSE::Generate::Catalog')) {
54     $$rmsg = "Catalogs must be in the shop";
55     return;
56   }
57
58   return $self->SUPER::validate_parent($data, $articles, $parent, $rmsg);
59 }
60
61 sub possible_parents {
62   my ($self, $article, $articles) = @_;
63
64   my %labels;
65   my @values;
66
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} ];
71   while (@work) {
72     my ($id, $title) = @{pop @work};
73     if (!$article->{id} || $article->{id} != $id) {
74       push(@values, $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);
80     }
81   }
82
83   return (\@values, \%labels);
84 }
85
86 sub default_link_path {
87   my ($self, $article) = @_;
88
89   $self->{cfg}->entry('uri', 'shop', '/shop');
90 }
91
92 sub make_link {
93   my ($self, $article) = @_;
94
95   $article->is_linked
96     or return "";
97
98 # Modified by adrian
99   my $urlbase = '';
100   if ($self->{cfg}->entry('shop', 'secureurl_articles', 1)) {
101     $urlbase = $self->{cfg}->entryVar('site', 'secureurl');
102   }
103 # end adrian
104
105   if ($article->is_dynamic) {
106     return "$urlbase/cgi-bin/page.pl?page=$article->{id}&title=".escape_uri($article->{title});
107   }
108
109   my $shop_uri = $self->link_path($article);
110   return $urlbase.$shop_uri."/shop$article->{id}.html";
111 }
112
113 sub child_types {
114   return qw(BSE::Edit::Product BSE::Edit::Seminar BSE::Edit::Catalog);
115 }
116
117 sub shop_article { 1 }
118
119 sub default_template {
120   my ($self, $article, $cfg, $templates) = @_;
121
122   my $template = $cfg->entry('catalogs', 'template');
123   return $template
124     if $template && grep $_ eq $template, @$templates;
125
126   return $self->SUPER::default_template($article, $cfg, $templates);
127 }
128
129 sub flag_sections {
130   my ($self) = @_;
131
132   return ( 'catalog flags', $self->SUPER::flag_sections );
133 }
134
135 sub type_default_value {
136   my ($self, $req, $col) = @_;
137
138   my $value = $req->cfg->entry('catalog defaults', $col);
139   defined $value and return $value;
140
141   return $self->SUPER::type_default_value($req, $col);
142 }
143
144 sub custom_fields {
145   my ($self) = @_;
146
147   my $custom = $self->SUPER::custom_fields();
148
149   require DevHelp::Validate;
150   DevHelp::Validate->import;
151   return DevHelp::Validate::dh_configure_fields
152     (
153      $custom,
154      $self->cfg,
155      CATALOG_CUSTOM_FIELDS_CFG,
156      BSE::DB->single->dbh,
157     );
158 }
159
160 1;
161