Bug 11876 [Follow-up] Add a diff view to staged MARC Records
[koha.git] / opac / opac-tags.pl
index b5ce340..6c402a5 100755 (executable)
@@ -38,11 +38,12 @@ use CGI::Cookie; # need to check cookies before having CGI parse the POST reques
 use C4::Auth qw(:DEFAULT check_cookie_auth);
 use C4::Context;
 use C4::Debug;
-use C4::Output 3.02 qw(:html :ajax pagination_bar);
-use C4::Dates qw(format_date);
+use C4::Output qw(:html :ajax pagination_bar);
 use C4::Scrubber;
 use C4::Biblio;
-use C4::Tags qw(add_tag get_approval_rows get_tag_rows remove_tag);
+use C4::Tags qw(add_tag get_approval_rows get_tag_rows remove_tag stratify_tags);
+
+use Data::Dumper;
 
 my %newtags = ();
 my @deltags = ();
@@ -53,11 +54,11 @@ my $perBibResults = {};
 # Indexes of @errors that do not apply to a particular biblionumber.
 my @globalErrorIndexes = ();
 
-sub ajax_auth_cgi ($) {     # returns CGI object
+sub ajax_auth_cgi {     # returns CGI object
        my $needed_flags = shift;
        my %cookies = fetch CGI::Cookie;
        my $input = CGI->new;
-       my $sessid = $cookies{'CGISESSID'}->value || $input->param('CGISESSID');
+    my $sessid = $cookies{'CGISESSID'}->value;
        my ($auth_status, $auth_sessid) = check_cookie_auth($sessid, $needed_flags);
        $debug and
        print STDERR "($auth_status, $auth_sessid) = check_cookie_auth($sessid," . Dumper($needed_flags) . ")\n";
@@ -108,11 +109,11 @@ if ($is_ajax) {
        $debug and print STDERR "op: $loggedinuser\n";
 } else {
        ($template, $loggedinuser, $cookie) = get_template_and_user({
-               template_name   => "opac-tags.tmpl",
-               query           => $query,
-               type            => "opac",
-               authnotrequired => ($add_op ? 0 : 1),   # auth required to add tags
-               debug           => 1,
+        template_name   => "opac-tags.tt",
+        query           => $query,
+        type            => "opac",
+        authnotrequired => ($add_op ? 0 : 1), # auth required to add tags
+        debug           => 1,
        });
 }
 
@@ -227,17 +228,17 @@ if ($loggedinuser) {
        $my_tags = get_tag_rows({borrowernumber=>$loggedinuser});
        foreach (@$my_tags) {
                my $biblio = GetBiblioData($_->{biblionumber});
-               $_->{bib_summary} = $biblio->{title}; 
-               ($biblio->{author}) and $_->{bib_summary} .= " by " . $biblio->{author};
+        my $record = &GetMarcBiblio( $_->{biblionumber} );
+        $_->{subtitle} = GetRecordValue( 'subtitle', $record, GetFrameworkCode( $_->{biblionumber} ) );
+        $_->{title} = $biblio->{title};
+        $_->{author} = $biblio->{author};
                my $date = $_->{date_created} || '';
                $date =~ /\s+(\d{2}\:\d{2}\:\d{2})/;
                $_->{time_created_display} = $1;
-               $_->{date_created_display} = format_date($_->{date_created});
        }
 }
 
-$template->param(tagsview => 1,
-dateformat => C4::Context->preference("dateformat"));
+$template->param(tagsview => 1);
 
 if ($add_op) {
        my $adds = 0;
@@ -263,34 +264,9 @@ if ($add_op) {
                $arghash->{biblionumber} = $arg;
        }
        $results = get_approval_rows($arghash);
-
+    stratify_tags(10, $results); # work out the differents sizes for things
        my $count = scalar @$results;
        $template->param(TAGLOOP_COUNT => $count, mine => $mine);
-       # Here we make a halfhearted attempt to separate the tags into "strata" based on weight_total
-       # FIXME: code4lib probably has a better algorithm, iirc
-       # FIXME: when we get a better algorithm, move to C4
-       my $maxstrata = 5;
-       my $strata = 1;
-       my $previous = 0;
-       my $chunk = ($count/$maxstrata)/2;
-       my $total = 0;
-       my %cloud;
-       foreach (reverse @$results) {
-               my $current = $_->{weight_total};
-               $total++;
-               $cloud{$strata}++;
-               if ($current == $previous) {
-                       $_->{cloudweight} = $strata;
-                       next;
-               } 
-               if ($strata < $maxstrata and 
-                       ($cloud{$strata} > $chunk or 
-                       $count-$total <= $maxstrata-$strata)) {
-                       $strata++;
-               }
-               $_->{cloudweight} = $strata;
-               $previous = $current;
-       }
 }
 (scalar @errors  ) and $template->param(ERRORS  => \@errors);
 my @orderedresult = sort { uc($a->{'term'}) cmp uc($b->{'term'}) } @$results;