Catalog
view release on metacpan or search on metacpan
lib/Catalog.pm view on Meta::CPAN
return $self->ccontrol_panel(Catalog::tools::cgi->new({
'context' => 'ccontrol_panel',
'comment' => 'The catalog has been setup'
}));
}
#
# HTML display control panel
#
sub ccontrol_panel {
my($self, $cgi) = @_;
$self->{'cgi'} = $cgi;
my($ccatalog) = $self->cinfo();
my($url) = $cgi->script_name();
if(!defined($self->{'csetup'})) {
return $self->csetup();
}
my($template) = $self->template("ccontrol_panel");
my($template_catalogs) = $template->{'children'}->{'catalogs'};
$self->cerror("missing catalogs part") if(!defined($template_catalogs));
my($template_theme) = $template_catalogs->{'children'}->{'theme'};
if($ccatalog) {
my($html) = '';
my(%navigation2function) = (
'alpha' => 'calpha_count',
'theme' => 'category_count',
'date' => 'cdate_count',
);
my($assoc) = $template_catalogs->{'assoc'};
my($name, $catalog);
while(($name, $catalog) = each(%$ccatalog)) {
my($root) = $catalog->{'root'};
my($navigation) = $catalog->{'navigation'};
my($count) = $navigation2function{$navigation};
my($id) = '';
if($navigation eq 'theme') {
$id = "&id=$root";
my($assoc) = $template_theme->{'assoc'};
template_set($assoc, '_ID_', $id);
template_set($assoc, '_COUNT_', $count);
template_set($assoc, '_NAME_', $name);
template_set($assoc, '_SCRIPT_', $url);
} else {
$template_theme->{'skip'} = 1;
}
template_set($assoc, '_ID_', $id);
template_set($assoc, '_COUNT_', $count);
template_set($assoc, '_NAME_', $name);
$html .= $self->stemplate_build($template_catalogs);
}
$template_catalogs->{'html'} = $html;
} else {
$template_catalogs->{'skip'} = 'yes';
}
my($navigation) = $cgi->popup_menu(-name => 'navigation',
-values => ['theme', 'alpha', 'date'],
-default => 'theme',
-labels => {
'theme' => 'Thematical',
'alpha' => 'Alphabetical',
'date' => 'Chronological',
});
template_set($template->{'assoc'}, '_NAVIGATION_', $navigation);
my($tables) = $cgi->popup_menu(-name => 'table',
-values => $self->{'ctables'});
template_set($template->{'assoc'}, '_TABLES_', $tables);
template_set($template->{'assoc'}, '_COMMENT_', $cgi->param('comment'));
return $self->stemplate_build($template);
}
#
# HTML import XML representation step 1
#
sub cimport {
my($self, $cgi) = @_;
$self->{'cgi'} = $cgi;
my($template) = $self->template("cimport");
my($assoc) = $template->{'assoc'};
template_set($assoc, '_NAME_', $cgi->param('name'));
template_set($assoc, '_PATH_', $cgi->param('path'));
template_set($assoc, '_COMMENT_', $cgi->param('comment'));
return $self->stemplate_build($template);
}
#
# HTML import XML representation step 2
#
sub cimport_confirm {
my($self, $cgi) = @_;
$self->{'cgi'} = $cgi;
my($name) = $cgi->param('name');
my($file) = $cgi->param('file');
$self->cerror("no file specified") if(!defined($file));
$self->cerror("$file is not a readable file") if(! -r $file);
eval {
$self->cimport_api($name, $file);
};
if($@) {
my($error) = $@;
print STDERR $error;
$self->cerror("load failed, check logs");
}
return $self->ccontrol_panel(Catalog::tools::cgi->new({
'context' => 'ccontrol_panel',
'comment' => "The $name catalog was (re)loaded"
}));
}
#
# HTML export XML representation step 1
#
sub cexport {
my($self, $cgi) = @_;
$self->{'cgi'} = $cgi;
my($template) = $self->template("cexport");
my($assoc) = $template->{'assoc'};
lib/Catalog.pm view on Meta::CPAN
$results_count = $self->searcher(\%context);
};
if($@) {
my($error) = $@;
$self->cerror("The query failed, check the syntax");
}
if($results_count <= 0) {
$template_records->{'skip'} = 1;
} else {
$template_norecords->{'skip'} = 1;
my($assoc) = $template_records->{'assoc'};
template_set($assoc, '_COUNT_', $results_count);
template_set($assoc, '_TEXT_', $cgi->param('text'));
template_set($assoc, '_TEXT-QUOTED_', Catalog::tools::cgi::myescapeHTML($cgi->param('text')));
}
} else {
$template_records->{'skip'} = 1;
$template_norecords->{'skip'} = 1;
}
$self->csearch_fill_form($cgi, $template, $results_count);
my($assoc) = $template->{'assoc'};
template_set($assoc, '_COUNT_', $results_count);
template_set($assoc, '_TEXT_', $cgi->param('text'));
template_set($assoc, '_TEXT-QUOTED_', Catalog::tools::cgi::myescapeHTML($cgi->param('text')));
return $self->stemplate_build($template);
}
sub csearch_form {
my($self, $cgi) = @_;
$self->{'cgi'} = $cgi;
my($ccatalog) = $self->cinfo();
my($name) = $cgi->param('name');
my($catalog) = $ccatalog->{$name};
my($navigation) = $catalog->{'navigation'};
$self->cerror("%s catalog cannot be searched", $navigation) if($navigation ne 'theme');
my($template) = $self->template('csearch');
$template->{'children'}->{'records'}->{'skip'} = 1;
$template->{'children'}->{'norecords'}->{'skip'} = 1;
$template->{'children'}->{'categories'}->{'skip'} = 1;
$template->{'children'}->{'nocategories'}->{'skip'} = 1;
$self->csearch_fill_form($cgi, $template, 0);
return $self->stemplate_build($template);
}
sub csearch_fill_form {
my($self, $cgi, $template, $results_count) = @_;
my($what) = $cgi->param('what');
my($what_menu) = $cgi->popup_menu(-name => 'what',
-values => ['', 'categories', 'records'],
-default => '',
-labels => {
'' => 'Category Names and Records',
'categories' => 'Category Names only',
'records' => 'Records only',
});
my($querymode_menu) = $cgi->popup_menu(-name => 'querymode',
-values => ['simple', 'advanced'],
-default => 'simple',
-labels => {
'simple' => 'Simple Syntax',
'advanced' => 'Advanced Syntax',
});
my($querymode) = $cgi->param('querymode') || 'simple';
my($notquerymode) = $querymode eq 'simple' ? 'advanced' : 'simple';
my(%has_template) = (
'simple' => exists($template->{'children'}->{'simple'}),
'advanced' => exists($template->{'children'}->{'advanced'})
);
my($template_form) = $has_template{$querymode} ? $template->{'children'}->{$querymode} : $template;
$template->{'children'}->{$notquerymode}->{'skip'} = 1 if($has_template{$notquerymode});
my($url) = $cgi->script_name();
my($assoc) = $template_form->{'assoc'};
template_set($assoc, '_HIDDEN_',
$self->hidden('mode' => scalar($cgi->param('mode')),
'context' => 'csearch'));
template_set($assoc, '_PARAMS_',
$self->params('mode' => scalar($cgi->param('mode')),
'context' => undef));
template_set($assoc, '_SCRIPT_', $url);
template_set($assoc, '_WHAT_', $what);
template_set($assoc, '_WHAT-MENU_', $what_menu);
template_set($assoc, '_QUERYMODE_', $querymode);
template_set($assoc, '_QUERYMODE-MENU_', $querymode_menu);
template_set($assoc, '_COUNT_', $results_count);
template_set($assoc, '_TEXT_', $cgi->param('text'));
template_set($assoc, '_TEXT-QUOTED_', Catalog::tools::cgi::myescapeHTML($cgi->param('text')));
}
#
# HTML translate cgi parameters to select order for search
#
sub csearch_param2select {
my($self, $what) = @_;
my($cgi) = $self->{'cgi'};
my($name) = $cgi->param('name');
my($words) = $cgi->param('text');
my($querymode) = $cgi->param('querymode');
#
# No search if nothing specified
#
return undef if(!defined($words) && $words =~ /^\s*$/o);
if($what eq 'categories') {
return $self->csearch_param2select_categories($name, $words, $querymode);
} else {
return $self->csearch_param2select_records($name, $words, $querymode);
}
}
#
# HTML translate cgi parameters to select order for searching records
#
sub csearch_param2select_records {
my($self, $name, $words, $querymode) = @_;
( run in 2.254 seconds using v1.01-cache-2.11-cpan-364913b4093 )