Now the application reads the yaml file. The TEST_DB environmental variable should...
[breadcrumbs.git] / web-site / breadcrumbs / lib / breadcrumbs / Controller / Help.pm
blobbce94ba7a9a4725c42facfc74898e5deebe621e1
1 package breadcrumbs::Controller::Help;
3 use strict;
4 use warnings;
5 use breadcrumbs::Controller::BcController;
6 use base 'breadcrumbs::Controller::BcController';
8 use Data::Dumper;
10 =head1 NAME
12 breadcrumbs::Controller::Help - Catalyst Controller
14 =head1 DESCRIPTION
16 Catalyst Controller.
18 =head1 METHODS
20 =cut
23 =head2 index
25 =cut
27 sub index : Private {
28 my ( $self, $c ) = @_;
30 $c->stash->{template} = "map_of_documentation.tt";
33 sub who_we_are : Local{
34 my ( $self, $c ) = @_;
35 $c->stash->{template} = "who_we_are.tt";
38 sub record_this_answer{
39 my ($current_question, $current_answer, $list_of_faqs) = @_;
40 my $quest = $$current_question;
41 my $answ = $$current_answer;
42 my @faq = ($quest, $answ);
43 push(@{$list_of_faqs}, \@faq);
45 $$current_question = "";
46 $$current_answer = "";
48 # print "<!-- REGISTRO LA DOMANDA \n";
49 # print Dumper($list_of_faqs);
50 # print "\n-->";
54 sub faq : Local{
55 my ( $self, $c ) = @_;
57 my $config = $c->config();
58 $c->stash->{config} = $config;
59 my $faq_file = $config->{home} . "/root/src/breadcrumbs-faq";
61 open (INFILE, "<$faq_file") or die "Non trovo il file delle domande $faq_file!\n";
63 # if ($ENV{"TEST_DB"}){
65 # #open (INFILE, "<root/src/breadcrumbs-faq") or die "Non trovo il file delle domande in debug!\n";
66 # open (INFILE, "<$faq_file") or die "Non trovo il file delle domande in debug!\n";
67 # } else {
68 # open (INFILE, "</var/www/bc/web-site/breadcrumbs/root/src/breadcrumbs-faq") or die "Non trovo il file delle domande!\n";
69 # }
71 my @faqs = ();
72 #ok, now I read this file
73 my $READING_SECTION = 0;
74 my $READING_QUESTION = 1;
75 my $READING_ANSWER = 2;
76 my $INITIAL_STATE = 3;
78 my $state = $INITIAL_STATE;
80 my $current_question;
81 my $current_answer;
82 my $current_section;
84 my @current_faqs;
86 while(<INFILE>){
87 #chomp;
89 # print "<!-- NUOVA RIGA $_ -->\n";
90 # print "<!-- per ora la mia hash vale \n";
91 # print Dumper(\%faqs);
92 # print "\n ed il vettore vale : \n";
93 # print Dumper(\@current_faqs);
94 # print "\n-->";
97 if (/--S--/){
98 if ($state == $READING_ANSWER){
99 #Ok, I was reading an answer, I should push it
100 record_this_answer(\$current_question, \$current_answer, \@current_faqs);
102 #I should finish the section...
103 my @temp = @current_faqs;
104 #$faqs{$current_section} = \@temp;
105 my @temp_vec = ($current_section, \@temp);
106 push (@faqs, \@temp_vec);
108 #print "<!-- registro la sezione $current_section \n";
111 @current_faqs = ();
114 $state = $READING_SECTION;
115 next;
116 } elsif (/--Q--/){
117 if ($state == $READING_ANSWER){
118 #Ok, I was reading an answer, I should push it
119 record_this_answer(\$current_question, \$current_answer, \@current_faqs);
121 $state = $READING_QUESTION;
122 next;
123 } elsif (/--A--/){
124 $state = $READING_ANSWER;
125 next;
128 #ok, I don't have a control section
129 if ($state == $READING_SECTION){
130 chomp;
131 $current_section = $_;
132 } elsif ($state == $READING_QUESTION){
133 if (/^$/){
134 $current_question .= "<p>";
135 next;
137 $current_question .= $_;
138 } elsif ($state == $READING_ANSWER){
139 $current_answer .= $_;
140 if (/^$/){
141 $current_answer .= "<p>";
142 next;
148 if ($state == $READING_ANSWER){
149 #OK, I should register the answer and the section
150 record_this_answer(\$current_question, \$current_answer, \@current_faqs);
152 my @temp = @current_faqs;
153 my @temp_vec = ($current_section, \@temp);
154 push (@faqs, \@temp_vec);
157 close (INFILE);
159 $c->stash->{faqs} = \@faqs;
160 $c->stash->{template} = "faq.tt";
163 sub release : Local{
164 my ( $self, $c ) = @_;
165 $c->stash->{template} = "release.tt";
168 sub licence : Local{
169 my ( $self, $c ) = @_;
170 $c->stash->{template} = "licence_and_conditions.tt";
173 sub fake_users : Local{
174 my ( $self, $c ) = @_;
175 $c->stash->{template} = "fake_users.tt";
178 sub breadcrumb_and_gpg : Local {
179 my ( $self, $c ) = @_;
180 $c->stash->{template} = "breadcrumb_and_gpg.tt";
184 sub _make_menu{
185 my ( $self, $c) = @_;
187 my @menu = ();
189 breadcrumbs::util::MenuUtils->add_menu_entry('licence', 'Licenza', \@menu, $c);
190 breadcrumbs::util::MenuUtils->add_menu_entry('breadcrumb_and_gpg', 'Sicurezza', \@menu, $c);
191 breadcrumbs::util::MenuUtils->add_menu_entry('faq', 'FAQ', \@menu, $c);
192 breadcrumbs::util::MenuUtils->add_menu_entry('/bcd-doc', 'Manuale', \@menu, $c);
193 breadcrumbs::util::MenuUtils->add_menu_entry('/simplehelp', 'Schede', \@menu, $c);
194 breadcrumbs::util::MenuUtils->add_menu_entry('/help/who_we_are', 'Chi siamo', \@menu, $c);
195 breadcrumbs::util::MenuUtils->add_menu_entry('/starthere', 'Inizia da qui', \@menu, $c);
197 $c->stash->{"menu_items"} = \@menu;
203 sub auto : Private {
204 my ( $self, $c) = @_;
206 my $trails = $c->stash->{"trails"};
207 my $url = $c->uri_for('/help');
208 my @item = ('Aiuto', "$url");
209 push(@{$trails}, \@item);
211 return 1; #You can continue
215 =head1 AUTHOR
217 Pasqualino Ferrentino,,,
219 =head1 LICENSE
221 This library is free software, you can redistribute it and/or modify
222 it under the same terms as Perl itself.
224 =cut