View | Details | Raw Unified | Return to bug 9032
Collapse All | Expand All

(-)a/C4/VirtualShelves.pm (-1 / +97 lines)
Lines 44-50 BEGIN { Link Here
44
            &ModShelf
44
            &ModShelf
45
            &ShelfPossibleAction
45
            &ShelfPossibleAction
46
            &DelFromShelf &DelShelf
46
            &DelFromShelf &DelShelf
47
            &GetBibliosShelves &AddShare
47
            &GetBibliosShelves
48
            &AddShare &AcceptShare &RemoveShare &IsSharedList
48
    );
49
    );
49
        @EXPORT_OK = qw(
50
        @EXPORT_OK = qw(
50
            &GetAllShelves &ShelvesMax
51
            &GetAllShelves &ShelvesMax
Lines 434-439 ShelfPossibleAction($loggedinuser, $shelfnumber, $action); Link Here
434
C<$loggedinuser,$shelfnumber,$action>
435
C<$loggedinuser,$shelfnumber,$action>
435
436
436
$action can be "view", "add", "delete", "manage", "new_public", "new_private".
437
$action can be "view", "add", "delete", "manage", "new_public", "new_private".
438
New additional actions are: invite, acceptshare.
437
Note that add/delete here refers to adding/deleting entries from the list. Deleting the list itself falls under manage.
439
Note that add/delete here refers to adding/deleting entries from the list. Deleting the list itself falls under manage.
438
new_public and new_private refers to creating a new public or private list.
440
new_public and new_private refers to creating a new public or private list.
439
The distinction between deleting your own entries from the list or entries from
441
The distinction between deleting your own entries from the list or entries from
Lines 441-446 others is made in DelFromShelf. Link Here
441
443
442
Returns 1 if the user can do the $action in the $shelfnumber shelf.
444
Returns 1 if the user can do the $action in the $shelfnumber shelf.
443
Returns 0 otherwise.
445
Returns 0 otherwise.
446
For the actions invite and acceptshare a second errorcode is returned if the
447
result is false. See opac-shareshelf.pl
444
448
445
=cut
449
=cut
446
450
Lines 490-495 sub ShelfPossibleAction { Link Here
490
        #DelFromShelf checks the situation per biblio
494
        #DelFromShelf checks the situation per biblio
491
        return 1 if $user>0 && ($shelf->{allow_delete_own}==1 || $shelf->{allow_delete_other}==1);
495
        return 1 if $user>0 && ($shelf->{allow_delete_own}==1 || $shelf->{allow_delete_other}==1);
492
    }
496
    }
497
    elsif($action eq 'invite') {
498
        #for sharing you must be the owner and the list must be private
499
        if( $shelf->{category}==1 ) {
500
            return 1 if $shelf->{owner}==$user;
501
            return (0, 4); # code 4: should be owner
502
        }
503
        else {
504
            return (0, 5); # code 5: should be private list
505
        }
506
    }
507
    elsif($action eq 'acceptshare') {
508
        #the key for accepting is checked later in AcceptShare
509
        #you must not be the owner, list must be private
510
        if( $shelf->{category}==1 ) {
511
            return (0, 8) if $shelf->{owner}==$user;
512
                #code 8: should not be owner
513
            return 1;
514
        }
515
        else {
516
            return (0, 5); # code 5: should be private list
517
        }
518
    }
493
    elsif($action eq 'manage') {
519
    elsif($action eq 'manage') {
494
        return 1 if $user && $shelf->{owner}==$user;
520
        return 1 if $user && $shelf->{owner}==$user;
495
    }
521
    }
Lines 665-670 sub AddShare { Link Here
665
    $dbh->do($sql);
691
    $dbh->do($sql);
666
    $sql="INSERT INTO virtualshelfshares (shelfnumber, invitekey, sharedate) VALUES (?, ?, ADDDATE(NOW(),?))";
692
    $sql="INSERT INTO virtualshelfshares (shelfnumber, invitekey, sharedate) VALUES (?, ?, ADDDATE(NOW(),?))";
667
    $dbh->do($sql, undef, ($shelfnumber, $key, SHARE_INVITATION_EXPIRY_DAYS));
693
    $dbh->do($sql, undef, ($shelfnumber, $key, SHARE_INVITATION_EXPIRY_DAYS));
694
    return !$dbh->err;
695
}
696
697
=head2 AcceptShare
698
699
     my $result= AcceptShare($shelfnumber, $key, $borrowernumber);
700
701
Checks acceptation of a share request.
702
Key must be found for this shelf. Invitation must not have expired.
703
Returns true when accepted, false otherwise.
704
705
=cut
706
707
sub AcceptShare {
708
    my ($shelfnumber, $key, $borrowernumber)= @_;
709
    return if !$shelfnumber || !$key || !$borrowernumber;
710
711
    my $sql;
712
    my $dbh = C4::Context->dbh;
713
    $sql="
714
UPDATE virtualshelfshares
715
SET invitekey=NULL, sharedate=NULL, borrowernumber=?
716
WHERE shelfnumber=? AND invitekey=? AND sharedate>NOW()
717
    ";
718
    my $i= $dbh->do($sql, undef, ($borrowernumber, $shelfnumber, $key));
719
    return if !defined($i) || !$i || $i eq '0E0'; #not found
720
    return 1;
721
}
722
723
=head2 IsSharedList
724
725
     my $bool= IsSharedList( $shelfnumber );
726
727
IsSharedList checks if a (private) list has shares.
728
Note that such a check would not be useful for public lists. A public list has
729
no shares, but is visible for anyone by nature..
730
Used to determine the list type in the display of Your lists (all private).
731
Returns boolean value.
732
733
=cut
734
735
sub IsSharedList {
736
    my ($shelfnumber) = @_;
737
    my $dbh = C4::Context->dbh;
738
    my $sql="SELECT id FROM virtualshelfshares WHERE shelfnumber=? AND borrowernumber IS NOT NULL";
739
    my $sth = $dbh->prepare($sql);
740
    $sth->execute($shelfnumber);
741
    my ($rv)= $sth->fetchrow_array;
742
    return defined($rv);
743
}
744
745
=head2 RemoveShare
746
747
     RemoveShare( $user, $shelfnumber );
748
749
RemoveShare removes a share for specific shelf and borrower.
750
Returns true if a record could be deleted.
751
752
=cut
753
754
sub RemoveShare {
755
    my ($user, $shelfnumber)= @_;
756
    my $dbh = C4::Context->dbh;
757
    my $sql="
758
DELETE FROM virtualshelfshares
759
WHERE borrowernumber=? AND shelfnumber=?
760
    ";
761
    my $n= $dbh->do($sql,undef,($user, $shelfnumber));
762
    return if !defined($n) || !$n || $n eq '0E0'; #nothing removed
763
    return 1;
668
}
764
}
669
765
670
# internal subs
766
# internal subs
(-)a/C4/VirtualShelves/Page.pm (-2 / +12 lines)
Lines 360-372 sub shelfpage { Link Here
360
360
361
        #Deleting a shelf (asking for confirmation if it has entries)
361
        #Deleting a shelf (asking for confirmation if it has entries)
362
            foreach ( $query->param() ) {
362
            foreach ( $query->param() ) {
363
                /DEL-(\d+)/ or next;
363
                /(DEL|REMSHR)-(\d+)/ or next;
364
                $delflag = 1;
364
                $delflag = 1;
365
                my $number = $1;
365
                my $number = $2;
366
                unless ( defined $shelflist->{$number} || defined $privshelflist->{$number} ) {
366
                unless ( defined $shelflist->{$number} || defined $privshelflist->{$number} ) {
367
                    push( @paramsloop, { unrecognized => $number } );
367
                    push( @paramsloop, { unrecognized => $number } );
368
                    last;
368
                    last;
369
                }
369
                }
370
                #remove a share
371
                if(/REMSHR/) {
372
                    RemoveShare($loggedinuser, $number);
373
                    delete $shelflist->{$number} if exists $shelflist->{$number};
374
                    delete $privshelflist->{$number} if exists $privshelflist->{$number};
375
                    $stay=0;
376
                    next;
377
                }
378
                #
370
                unless ( ShelfPossibleAction( $loggedinuser, $number, 'manage' ) ) {
379
                unless ( ShelfPossibleAction( $loggedinuser, $number, 'manage' ) ) {
371
                    push( @paramsloop, { nopermission => $shelfnumber } );
380
                    push( @paramsloop, { nopermission => $shelfnumber } );
372
                    last;
381
                    last;
Lines 434-439 sub shelfpage { Link Here
434
        $shelflist->{$element}->{ownername} = defined($member) ? $member->{firstname} . " " . $member->{surname} : '';
443
        $shelflist->{$element}->{ownername} = defined($member) ? $member->{firstname} . " " . $member->{surname} : '';
435
        $numberCanManage++ if $canmanage;    # possibly outmoded
444
        $numberCanManage++ if $canmanage;    # possibly outmoded
436
        if ( $shelflist->{$element}->{'category'} eq '1' ) {
445
        if ( $shelflist->{$element}->{'category'} eq '1' ) {
446
            $shelflist->{$element}->{shares} = IsSharedList($element);
437
            push( @shelveslooppriv, $shelflist->{$element} );
447
            push( @shelveslooppriv, $shelflist->{$element} );
438
        } else {
448
        } else {
439
            push( @shelvesloop, $shelflist->{$element} );
449
            push( @shelvesloop, $shelflist->{$element} );
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref (-1 / +1 lines)
Lines 521-527 OPAC: Link Here
521
              choices:
521
              choices:
522
                  no: "Don't allow"
522
                  no: "Don't allow"
523
                  yes: Allow
523
                  yes: Allow
524
            - opac users to share private lists with other patrons. This feature is not active yet but will be released soon
524
            - opac users to share private lists with other patrons.
525
525
526
    Privacy:
526
    Privacy:
527
        -
527
        -
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt (-1 / +1 lines)
Lines 538-544 function placeHold () { Link Here
538
        <td><a href="shelves.pl?[% IF ( shelveslooppri.showprivateshelves ) %]display=privateshelves&amp;[% END %]viewshelf=[% shelveslooppri.shelf %]&amp;shelfoff=[% shelfoff %]">[% shelveslooppri.shelfname |html %]</a></td>
538
        <td><a href="shelves.pl?[% IF ( shelveslooppri.showprivateshelves ) %]display=privateshelves&amp;[% END %]viewshelf=[% shelveslooppri.shelf %]&amp;shelfoff=[% shelfoff %]">[% shelveslooppri.shelfname |html %]</a></td>
539
        <td>[% shelveslooppri.count %] item(s)</td>
539
        <td>[% shelveslooppri.count %] item(s)</td>
540
        <td>[% IF ( shelveslooppri.sortfield == "author" ) %]Author[% ELSIF ( shelveslooppri.sortfield == "copyrightdate" ) %]Year[% ELSIF (shelveslooppri.sortfield == "itemcallnumber") %]Call number[% ELSE %]Title[% END %]</td>
540
        <td>[% IF ( shelveslooppri.sortfield == "author" ) %]Author[% ELSIF ( shelveslooppri.sortfield == "copyrightdate" ) %]Year[% ELSIF (shelveslooppri.sortfield == "itemcallnumber") %]Call number[% ELSE %]Title[% END %]</td>
541
        <td>[% IF ( shelveslooppri.viewcategory1 ) %]Private[% END %]
541
        <td>[% IF ( shelveslooppri.viewcategory1 ) %][% IF !shelveslooppri.shares %]Private[% ELSE %]Shared[% END %][% END %]
542
			[% IF ( shelveslooppri.viewcategory2 ) %]Public[% END %]
542
			[% IF ( shelveslooppri.viewcategory2 ) %]Public[% END %]
543
		</td>
543
		</td>
544
        <td>
544
        <td>
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/opac-shareshelf.tt (-5 / +8 lines)
Lines 19-24 Link Here
19
        [% IF errcode==4 %]<div class="dialog alert">You can only share a list if you are the owner.</div>[% END %]
19
        [% IF errcode==4 %]<div class="dialog alert">You can only share a list if you are the owner.</div>[% END %]
20
        [% IF errcode==5 %]<div class="dialog alert">You cannot share a public list.</div>[% END %]
20
        [% IF errcode==5 %]<div class="dialog alert">You cannot share a public list.</div>[% END %]
21
        [% IF errcode==6 %]<div class="dialog alert">Sorry, but you did not enter any valid email address.</div>[% END %]
21
        [% IF errcode==6 %]<div class="dialog alert">Sorry, but you did not enter any valid email address.</div>[% END %]
22
        [% IF errcode==7 %]<div class="dialog alert">Sorry, but we could not accept this key. The invitation may have expired. Contact the patron who sent you the invitation.</div>[% END %]
23
        [% IF errcode==8 %]<div class="dialog alert">As owner of a list you cannot accept an invitation for sharing it.</div>[% END %]
22
24
23
    [% ELSIF op=='invite' %]
25
    [% ELSIF op=='invite' %]
24
        <form method="post" onsubmit="return $('#invite_address').val().trim()!='';">
26
        <form method="post" onsubmit="return $('#invite_address').val().trim()!='';">
Lines 37-54 Link Here
37
        </form>
39
        </form>
38
40
39
    [% ELSIF op=='conf_invite' %]
41
    [% ELSIF op=='conf_invite' %]
42
        [% IF approvedaddress %]
40
        <p>An invitation to share list <i>[% shelfname %]</i> has been sent to [% approvedaddress %].</p>
43
        <p>An invitation to share list <i>[% shelfname %]</i> has been sent to [% approvedaddress %].</p>
44
        [% END %]
41
        [% IF failaddress %]
45
        [% IF failaddress %]
42
            <p>The following addresses appear to be invalid. Please correct them and try again. These are: [% failaddress %]</p>
46
            <p>Something went wrong while processing the following addresses. Please check them. These are: [% failaddress %]</p>
43
        [% END %]
47
        [% END %]
48
        [% IF approvedaddress %]
44
        <p>You will receive an email notification if someone accepts your share within two weeks.</p>
49
        <p>You will receive an email notification if someone accepts your share within two weeks.</p>
50
        [% END %]
45
        <p><a href="/cgi-bin/koha/opac-shelves.pl?display=privateshelves">Return to your lists</a></p>
51
        <p><a href="/cgi-bin/koha/opac-shelves.pl?display=privateshelves">Return to your lists</a></p>
46
52
47
    [% ELSIF op=='accept' %]
53
    [% ELSIF op=='accept' %]
48
        [%# TODO: Replace the following two lines %]
54
        [%# Nothing to do: we already display an error or we redirect. %]
49
        <p>Thank you for testing this feature.</p>
50
        <p>Your signoff will certainly help in finishing the remaining part!</p>
51
52
    [% END %]
55
    [% END %]
53
[%# End of essential part %]
56
[%# End of essential part %]
54
57
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tt (-5 / +24 lines)
Lines 8-13 Link Here
8
var MSG_REMOVE_FROM_LIST = _("Are you sure you want to remove these items from the list?");
8
var MSG_REMOVE_FROM_LIST = _("Are you sure you want to remove these items from the list?");
9
var MSG_REMOVE_ONE_FROM_LIST = _("Are you sure you want to remove this item from the list?");
9
var MSG_REMOVE_ONE_FROM_LIST = _("Are you sure you want to remove this item from the list?");
10
var MSG_CONFIRM_DELETE_LIST = _("Are you sure you want to delete this list?");
10
var MSG_CONFIRM_DELETE_LIST = _("Are you sure you want to delete this list?");
11
var MSG_CONFIRM_REMOVE_SHARE = _("Are you sure you want to remove this share?");
11
12
12
[% IF ( opacuserlogin ) %][% IF ( RequestOnOpac ) %]
13
[% IF ( opacuserlogin ) %][% IF ( RequestOnOpac ) %]
13
function holdSelections() {
14
function holdSelections() {
Lines 239-244 $(document).ready(function() { Link Here
239
    </li>
240
    </li>
240
[% END %]
241
[% END %]
241
242
243
[%# When using the next block, add the parameter for shelfnumber and add a tag to end the form %]
244
[% BLOCK remove_share %]
245
    <form action="opac-shelves.pl" method="post">
246
        <input type="hidden" name="shelves" value="1" />
247
        <input type="hidden" name="display" value="privateshelves" />
248
        <input type="hidden" name="shelfoff" value="[% shelfoff %]" />
249
        <input type="submit" class="removeshare" onclick="return confirmDelete(MSG_CONFIRM_REMOVE_SHARE);" value="Remove share" />
250
[% END %]
251
242
[% IF ( OpacNav ) %]<div id="doc3" class="yui-t1">[% ELSIF ( loggedinusername ) %]<div id="doc3" class="yui-t1">[% ELSE %]<div id="doc3" class="yui-t7">[% END %]
252
[% IF ( OpacNav ) %]<div id="doc3" class="yui-t1">[% ELSIF ( loggedinusername ) %]<div id="doc3" class="yui-t1">[% ELSE %]<div id="doc3" class="yui-t7">[% END %]
243
    <div id="bd">
253
    <div id="bd">
244
      [% INCLUDE 'masthead.inc' %]
254
      [% INCLUDE 'masthead.inc' %]
Lines 371-376 $(document).ready(function() { Link Here
371
                            <input type="submit" class="Share" value="Share" />
381
                            <input type="submit" class="Share" value="Share" />
372
                        </form>
382
                        </form>
373
                    [% END %]
383
                    [% END %]
384
                [% ELSIF showprivateshelves %]
385
                    [% INCLUDE remove_share %]
386
                    <input type="hidden" name="REMSHR-[% shelfnumber %]" value="1" />
387
                    </form>
374
                [% END %]
388
                [% END %]
375
389
376
390
Lines 596-604 $(document).ready(function() { Link Here
596
                  <ul class="link-tabs">
610
                  <ul class="link-tabs">
597
                  [% IF ( opacuserlogin ) %]
611
                  [% IF ( opacuserlogin ) %]
598
                  [% IF ( showprivateshelves ) %]
612
                  [% IF ( showprivateshelves ) %]
599
                    <li id="privateshelves_tab" class="on"><a href="/cgi-bin/koha/opac-shelves.pl?display=privateshelves">Your private lists</a></li>
613
                    <li id="privateshelves_tab" class="on"><a href="/cgi-bin/koha/opac-shelves.pl?display=privateshelves">Your lists</a></li>
600
                  [% ELSE %]
614
                  [% ELSE %]
601
                    <li id="privateshelves_tab" class="off"><a href="/cgi-bin/koha/opac-shelves.pl?display=privateshelves">Your private lists</a></li>
615
                    <li id="privateshelves_tab" class="off"><a href="/cgi-bin/koha/opac-shelves.pl?display=privateshelves">Your lists</a></li>
602
                  [% END %]
616
                  [% END %]
603
                  [% END %]
617
                  [% END %]
604
                  [% IF ( showpublicshelves ) %]
618
                  [% IF ( showpublicshelves ) %]
Lines 623-629 $(document).ready(function() { Link Here
623
                          <th>List name</th>
637
                          <th>List name</th>
624
                          <th>Contents</th>
638
                          <th>Contents</th>
625
                          <th>Type</th>
639
                          <th>Type</th>
626
                          <th>&nbsp;</th>
640
                          <th>Options</th>
627
                        </tr>
641
                        </tr>
628
                        [% FOREACH shelveslooppri IN shelveslooppriv %]
642
                        [% FOREACH shelveslooppri IN shelveslooppriv %]
629
                          [% UNLESS ( loop.odd ) %]
643
                          [% UNLESS ( loop.odd ) %]
Lines 634-640 $(document).ready(function() { Link Here
634
                              <td><a href="/cgi-bin/koha/opac-shelves.pl?display=privateshelves&amp;viewshelf=[% shelveslooppri.shelf %]&amp;sortfield=[% shelveslooppri.sortfield %]">[% shelveslooppri.shelfname |html %]</a></td>
648
                              <td><a href="/cgi-bin/koha/opac-shelves.pl?display=privateshelves&amp;viewshelf=[% shelveslooppri.shelf %]&amp;sortfield=[% shelveslooppri.sortfield %]">[% shelveslooppri.shelfname |html %]</a></td>
635
                              <td>[% IF ( shelveslooppri.count ) %][% shelveslooppri.count %] [% IF ( shelveslooppri.single ) %]item[% ELSE %]items[% END %][% ELSE %]Empty[% END %]</td>
649
                              <td>[% IF ( shelveslooppri.count ) %][% shelveslooppri.count %] [% IF ( shelveslooppri.single ) %]item[% ELSE %]items[% END %][% ELSE %]Empty[% END %]</td>
636
                              <td>
650
                              <td>
637
                                [% IF ( shelveslooppri.viewcategory1 ) %]Private[% END %]
651
                                [% IF ( shelveslooppri.viewcategory1 ) %][% IF !shelveslooppri.shares %]Private[% ELSE %]Shared[% END %][% END %]
638
                                [% IF ( shelveslooppri.viewcategory2 ) %]Public[% END %]
652
                                [% IF ( shelveslooppri.viewcategory2 ) %]Public[% END %]
639
                              </td>
653
                              </td>
640
                              <td>
654
                              <td>
Lines 664-669 $(document).ready(function() { Link Here
664
                                  <input type="submit" class="Share" value="Share" />
678
                                  <input type="submit" class="Share" value="Share" />
665
                                </form>
679
                                </form>
666
                              [% END %]
680
                              [% END %]
681
                            [% ELSIF shelveslooppri.shares %]
682
                                [% INCLUDE remove_share %]
683
                                <input type="hidden" name="REMSHR-[% shelveslooppri.shelf %]" value="1" />
684
                                </form>
667
                            [% END %]&nbsp;
685
                            [% END %]&nbsp;
668
                            </td>
686
                            </td>
669
                          </tr>
687
                          </tr>
Lines 696-702 $(document).ready(function() { Link Here
696
                        <tr>
714
                        <tr>
697
                          <th>List name</th>
715
                          <th>List name</th>
698
                          <th>Contents</th>
716
                          <th>Contents</th>
699
                          <th>Type</th><th>&nbsp;</th>
717
                          <th>Type</th>
718
                          <th>Options</th>
700
                        </tr>
719
                        </tr>
701
                    [% FOREACH shelvesloo IN shelvesloop %]
720
                    [% FOREACH shelvesloo IN shelvesloop %]
702
                      [% UNLESS ( loop.odd ) %]
721
                      [% UNLESS ( loop.odd ) %]
(-)a/opac/opac-shareshelf.pl (-21 / +77 lines)
Lines 22-27 use warnings; Link Here
22
22
23
use constant KEYLENGTH => 10;
23
use constant KEYLENGTH => 10;
24
use constant TEMPLATE_NAME => 'opac-shareshelf.tmpl';
24
use constant TEMPLATE_NAME => 'opac-shareshelf.tmpl';
25
use constant SHELVES_URL => '/cgi-bin/koha/opac-shelves.pl?display=privateshelves&viewshelf=';
25
26
26
use CGI;
27
use CGI;
27
use Email::Valid;
28
use Email::Valid;
Lines 29-34 use Email::Valid; Link Here
29
use C4::Auth;
30
use C4::Auth;
30
use C4::Context;
31
use C4::Context;
31
use C4::Letters;
32
use C4::Letters;
33
use C4::Members ();
32
use C4::Output;
34
use C4::Output;
33
use C4::VirtualShelves;
35
use C4::VirtualShelves;
34
36
Lines 55-62 sub _init { Link Here
55
    $param->{addrlist} = $query->param('invite_address')||'';
57
    $param->{addrlist} = $query->param('invite_address')||'';
56
    $param->{key} = $query->param('key')||'';
58
    $param->{key} = $query->param('key')||'';
57
    $param->{appr_addr} = [];
59
    $param->{appr_addr} = [];
58
60
    $param->{fail_addr} = [];
59
    $param->{errcode} = check_common_errors($param);
61
    $param->{errcode} = check_common_errors($param);
62
63
    #get some list details
64
    my @temp;
65
    @temp= GetShelf( $param->{shelfnumber} ) if !$param->{errcode};
66
    $param->{shelfname} = @temp? $temp[1]: '';
67
    $param->{owner} = @temp? $temp[2]: -1;
68
    $param->{category} = @temp? $temp[3]: -1;
69
60
    load_template($param);
70
    load_template($param);
61
    return $param;
71
    return $param;
62
}
72
}
Lines 94-107 sub confirm_invite { Link Here
94
104
95
sub show_accept {
105
sub show_accept {
96
    my ($param) = @_;
106
    my ($param) = @_;
97
    #TODO Add some code here to accept an invitation (followup report)
107
108
    my @rv= ShelfPossibleAction($param->{loggedinuser},
109
        $param->{shelfnumber}, 'acceptshare');
110
    $param->{errcode} = $rv[1] if !$rv[0];
111
    return if $param->{errcode};
112
        #errorcode 5: should be private list
113
        #errorcode 8: should not be owner
114
115
    my $dbkey= keytostring( stringtokey($param->{key}, 0), 1);
116
    if( AcceptShare($param->{shelfnumber}, $dbkey, $param->{loggedinuser} ) ) {
117
        notify_owner($param);
118
        #redirect to view of this shared list
119
        print $param->{query}->redirect(SHELVES_URL.$param->{shelfnumber});
120
        exit;
121
    }
122
    else {
123
        $param->{errcode} = 7; #not accepted (key not found or expired)
124
    }
125
}
126
127
sub notify_owner {
128
    my ($param) = @_;
129
130
    my $toaddr=  C4::Members::GetNoticeEmailAddress( $param->{owner} );
131
    return if !$toaddr;
132
133
    #prepare letter
134
    my $letter= C4::Letters::GetPreparedLetter(
135
        module => 'members',
136
        letter_code => 'SHARE_ACCEPT',
137
        branchcode => C4::Context->userenv->{"branch"},
138
        tables => { borrowers => $param->{loggedinuser}, },
139
        substitute => {
140
            listname => $param->{shelfname},
141
        },
142
    );
143
144
    #send letter to queue
145
    C4::Letters::EnqueueLetter( {
146
        letter                 => $letter,
147
        message_transport_type => 'email',
148
        from_address => C4::Context->preference('KohaAdminEmailAddress'),
149
        to_address             => $toaddr,
150
    });
98
}
151
}
99
152
100
sub process_addrlist {
153
sub process_addrlist {
101
    my ($param) = @_;
154
    my ($param) = @_;
102
    my @temp= split /[,:;]/, $param->{addrlist};
155
    my @temp= split /[,:;]/, $param->{addrlist};
103
    my @appr_addr;
156
    my @appr_addr;
104
    my $fail_addr='';
157
    my @fail_addr;
105
    foreach my $a (@temp) {
158
    foreach my $a (@temp) {
106
        $a=~s/^\s+//;
159
        $a=~s/^\s+//;
107
        $a=~s/\s+$//;
160
        $a=~s/\s+$//;
Lines 109-119 sub process_addrlist { Link Here
109
            push @appr_addr, $a;
162
            push @appr_addr, $a;
110
        }
163
        }
111
        else {
164
        else {
112
            $fail_addr.= ($fail_addr? '; ': '').$a;
165
            push @fail_addr, $a;
113
        }
166
        }
114
    }
167
    }
115
    $param->{appr_addr}= \@appr_addr;
168
    $param->{appr_addr}= \@appr_addr;
116
    $param->{fail_addr}= $fail_addr;
169
    $param->{fail_addr}= \@fail_addr;
117
}
170
}
118
171
119
sub send_invitekey {
172
sub send_invitekey {
Lines 124-132 sub send_invitekey { Link Here
124
        $param->{shelfnumber}."&op=accept&key=";
177
        $param->{shelfnumber}."&op=accept&key=";
125
        #TODO Waiting for the right http or https solution (BZ 8952 a.o.)
178
        #TODO Waiting for the right http or https solution (BZ 8952 a.o.)
126
179
180
    my @ok; #the addresses that were processed well
127
    foreach my $a ( @{$param->{appr_addr}} ) {
181
    foreach my $a ( @{$param->{appr_addr}} ) {
128
        my @newkey= randomlist(KEYLENGTH, 64); #generate a new key
182
        my @newkey= randomlist(KEYLENGTH, 64); #generate a new key
129
183
184
        #add a preliminary share record
185
        if( ! AddShare( $param->{shelfnumber}, keytostring(\@newkey,1) ) ) {
186
            push @{$param->{fail_addr}}, $a;
187
            next;
188
        }
189
        push @ok, $a;
190
130
        #prepare letter
191
        #prepare letter
131
        my $letter= C4::Letters::GetPreparedLetter(
192
        my $letter= C4::Letters::GetPreparedLetter(
132
            module => 'members',
193
            module => 'members',
Lines 146-166 sub send_invitekey { Link Here
146
            from_address           => $fromaddr,
207
            from_address           => $fromaddr,
147
            to_address             => $a,
208
            to_address             => $a,
148
        });
209
        });
149
        #add a preliminary share record
150
        AddShare( $param->{shelfnumber}, keytostring(\@newkey,1));
151
    }
210
    }
211
    $param->{appr_addr}= \@ok;
152
}
212
}
153
213
154
sub check_owner_category {
214
sub check_owner_category {
155
    my ($param)= @_;
215
    my ($param)= @_;
156
    #TODO candidate for a module?
216
    #sharing user should be the owner
157
    #need to get back the two different error codes and the shelfname
217
    #list should be private
158
159
    ( undef, $param->{shelfname}, $param->{owner}, my $category ) =
160
    GetShelf( $param->{shelfnumber} );
161
    $param->{errcode}=4 if $param->{owner}!= $param->{loggedinuser};
218
    $param->{errcode}=4 if $param->{owner}!= $param->{loggedinuser};
162
    $param->{errcode}=5 if !$param->{errcode} && $category!=1;
219
    $param->{errcode}=5 if !$param->{errcode} && $param->{category}!=1;
163
        #should be private
164
    return !defined $param->{errcode};
220
    return !defined $param->{errcode};
165
}
221
}
166
222
Lines 178-191 sub load_template { Link Here
178
sub load_template_vars {
234
sub load_template_vars {
179
    my ($param) = @_;
235
    my ($param) = @_;
180
    my $template = $param->{template};
236
    my $template = $param->{template};
181
    my $str= join '; ', @{$param->{appr_addr}};
237
    my $appr= join '; ', @{$param->{appr_addr}};
238
    my $fail= join '; ', @{$param->{fail_addr}};
182
    $template->param(
239
    $template->param(
183
        errcode         => $param->{errcode},
240
        errcode         => $param->{errcode},
184
        op              => $param->{op},
241
        op              => $param->{op},
185
        shelfnumber     => $param->{shelfnumber},
242
        shelfnumber     => $param->{shelfnumber},
186
        shelfname       => $param->{shelfname},
243
        shelfname       => $param->{shelfname},
187
        approvedaddress => $str,
244
        approvedaddress => $appr,
188
        failaddress     => $param->{fail_addr},
245
        failaddress     => $fail,
189
    );
246
    );
190
}
247
}
191
248
Lines 214-227 sub stringtokey { Link Here
214
    my @temp=split '', $str||'';
271
    my @temp=split '', $str||'';
215
    if($flgBase64) {
272
    if($flgBase64) {
216
        my $alphabet= [ 'A'..'Z', 'a'..'z', 0..9, '+', '/' ];
273
        my $alphabet= [ 'A'..'Z', 'a'..'z', 0..9, '+', '/' ];
217
        return map { alphabet_ordinal($_, $alphabet); } @temp;
274
        return [ map { alphabet_ordinal($_, $alphabet); } @temp ];
218
    }
275
    }
219
    return () if $str!~/^\d+$/;
276
    return [] if $str!~/^\d+$/;
220
    my @retval;
277
    my @retval;
221
    for(my $i=0; $i<@temp-1; $i+=2) {
278
    for(my $i=0; $i<@temp-1; $i+=2) {
222
        push @retval, $temp[$i]*10+$temp[$i+1];
279
        push @retval, $temp[$i]*10+$temp[$i+1];
223
    }
280
    }
224
    return @retval;
281
    return \@retval;
225
}
282
}
226
283
227
sub alphabet_ordinal {
284
sub alphabet_ordinal {
228
- 

Return to bug 9032