summaryrefslogtreecommitdiffstats
path: root/Bachelor/Systemprogrammierung in Perl/zettel.zip_FILES/kasten/zettel.pm
blob: 60dc876866725564ba8ee9c8dcb8224b8d6690c0 (plain)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package Zettel;
use base CGI::Application;
use CGI::Application::Plugin::AutoRunmode;
use CGI qw(:standard *table );
use CGI::Pretty;
use strict;
#use Data::Dumper;
use Storable;
#use CGI::Application::Plugin::Session;

  
my $kasten =[];
$kasten = retrieve("d:/xampp/cgi-bin/kasten/kasten.txt") if -e "d:/xampp/cgi-bin/kasten/kasten.txt";
my %start_labels = (
	delete_func => "delete",
	edit_func => "edit", 
	new_func => "new",
	list_func => "list"
	);



sub cgiapp_init {
        my $self = shift;
}

   sub teardown {
        my $self = shift;
	store $kasten, 'd:/xampp/cgi-bin/kasten/kasten.txt';
   }

sub start_func : StartRunmode
{
	my $self = shift;
	my $output = "";

	$output .= start_form();
	$output .= radio_group(-name=>'rm',
			     -values=>[keys %start_labels],
			     -labels => \%start_labels,
			     -rows => 5);
	$output .= br;
	$output .= submit();

	$output .= end_form;
}

sub delete_func : Runmode
{
	my $self = shift;
	$self->select_func("delete1_func");
}

sub delete1_func : Runmode
{
	my $output = "";
	my $self = shift;
	my $q = $self->query();
	my $index = $q->param('liste');
	splice @$kasten, $index, 1;
	$self->start_func();
}

sub edit_func : Runmode
{
	my $self = shift;
	$self->select_func("edit1_func");
}

sub edit1_func : Runmode
{
	my $output = "";
	my $self = shift;
	my $q = $self->query();
	my $index = $q->param('liste');
	$output .= start_form();
	$output .= textarea(-name=>'zettel',
			  -default=>$kasten->[$index],
			  -rows=>10,
			  -columns=>50);
	$output .= input({ -type=>'hidden', -name=> 'rm', -value => 'edit2_func'});
	$output .= br;
	$output .= submit();
	$output .= end_form();
}

sub edit2_func : Runmode
{
	my $self = shift;
	$self->start_func();
}

sub new_func  : Runmode
{
	my $output = "";
	$output .= start_form();
	$output .= textarea(-name=>'zettel',
			  -default=>'',
			  -rows=>10,
			  -columns=>50);
	$output .= input({ -type=>'hidden', -name=> 'rm', -value => 'new1_func'});
	$output .= br;
	$output .= submit();
	$output .= end_form();
}

sub new1_func  : Runmode
{
	my $output = "";
	my $self = shift;
	my $q = $self->query();
	push @$kasten, $q->param("zettel");
	$self->start_func();
}

sub list_func() : Runmode
{
	my $output = "";
	my $self = shift;
	$self->start_func();
}

sub select_func
{
	my $self = shift;
	my $next_rm = shift;
	my $output = "";
	#~ my $i = 0;
	#~ my %labels = map {$i++ => substr($_, 0, 20) } @$kasten;
	my %labels ;
	@labels{0 .. scalar @$kasten -1} = map {substr($_, 0, 20) } @$kasten;
	my $size = @$kasten > 12 ? 12 : @$kasten;
	$output .= start_form();
	$output .= scrolling_list(-name=>'liste',
				-values=>[keys %labels],
				-default=>[0],
				-size => $size,
				-multiple=>'false',
				-labels=> \%labels);
	$output .= input({ -type=>'hidden', -name=> 'rm', -value => $next_rm});
	$output .= submit();
	$output .= end_form;
}

sub cgiapp_postrun
{
	my $self = shift;
	my $output_ref = shift;
	my $output = start_html('Zettelkasten') . h1('Zettelkasten');
	$$output_ref = $output . $$output_ref . end_html();
}

1;