File: Cats.pm

package info (click to toggle)
sporum 1.8b1-3.1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,108 kB
  • ctags: 676
  • sloc: perl: 14,300; makefile: 52
file content (99 lines) | stat: -rw-r--r-- 2,888 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package Templates::Admin::Cats;

use SmallPigVars qw($config);
use Templates::Admin::SmallPig;
use SPDB;
use CGI qw(:standard :cgi-lib);
use CGI::Cookie ();

use Templates::Admin::Block;
use Templates::Admin::OptBlock;

use strict;

my @ISA = qw(Templates::Admin::Block);

my %CACHE;

my $lang;

sub new{
  my ($class) = @_;
  my $self = Templates::Admin::Block->new("catsblock");
  $self->{'spdb'} = SPDB->new();
  
  my $id = join '', sort values %$self, "catsblock";
  return $CACHE{$id} if $CACHE{$id};
  return $CACHE{$id} = bless $self, $class;
}

sub DESTROY{
    my $self = shift;
    my $spdb = $self->{'spdb'};
    $spdb->db_disconnect($spdb->{'dbh'});
}

sub display{
  my ($self, $STATE) = @_;
  my $op = $STATE->{'op'};
  my $prev_op = $STATE->{'prev_op'};
  my $theme = $STATE->{'theme'};
 
  $lang = $STATE->{'langptr'};

  my $standardindex = Templates::Admin::StandardIndex->new($STATE);

  my $content = $self->_get_createcategory($STATE);
  my $classvars = {('title' => (($prev_op ne "modifycategory")?
				$lang->{'create_cat1'}:
				$lang->{'modify_cat3'}),
		    'content' => $content)};
  my $createcategory = Templates::Admin::OptBlock->new($classvars, $theme);

  my $ret;
  $ret = start_form(-method=>"post", -action=>"$config->{'cgidir'}/admin.cgi");
  $ret .= $standardindex->get();
  $ret .= $createcategory->get();
  $ret .= "<INPUT TYPE=hidden NAME=prev_op VALUE=$prev_op><font size=1>";
  $ret .= submit(-name=>"op", -value=>$lang->{'SaveCategory'});
  $ret .= "</font>".end_form()."</TD>";
  return $ret;
}

sub _get_createcategory{
  my ($self, $STATE) = @_;
  my $spdb = $self->{'spdb'};
  my $DBH = $spdb->{'dbh'};
  
  my $op = $STATE->{'prev_op'};
  my $ret = "";
  my $selectedcategory = $STATE->{selectedcategory};

  my $catidq = $DBH->quote($selectedcategory);
  my ($catidv, $titlev, $catorderv); 
  ($catidv, $titlev, $catorderv) = 
    $spdb->db_select_cols("catid, cattitle, catorder", 
			 "Cats", "catid=$catidq") if $catidq;

  my $catid = textfield(-name=>'categoryid', -size=>30, -value=>$catidv);
  my $title = textfield(-name=>'categorytitle', -size=>30, -value=>$titlev);

  # --- find the number of categories
  my $cnt = $spdb->db_count("Cats");
  my $tmp = {}; $cnt++ if $op ne "modifycategory";
  for(my $i=1; $i<=$cnt; $i++){ $tmp->{$i} = $i; }
  my $order = Templates::Admin::SmallPig::select_option($tmp, "categoryorder", $catorderv);
  
  $ret .= qq!
      <TR><TD><TABLE BORDER=0 CELLPADDING=10><TR><TD>
	<B>$lang->{'cat_title'}:</B><BR><font size=1>$title</font><BR><BR>
	<B>$lang->{'keyword'}:</B> ($lang->{'must_be_20c'})<BR><font size=1>$catid</font><BR><BR>
	<B>$lang->{'cat_order'}</B><BR><font size=1>$order</font><BR>
      </TD></TR></TABLE></TD><TR>
      <INPUT TYPE=hidden NAME=prev_catid VALUE="$selectedcategory">
      <INPUT TYPE=hidden NAME=prev_catorder VALUE=$catorderv>
    !;
  return $ret;
}

return 1;