Annotation of loncom/interface/lonwishlistdisplay.pm, revision 1.7

1.1       wenzelju    1: # The LearningOnline Network with CAPA
                      2: # Routines to display the wishlist (handler)
                      3: #
1.7     ! raeburn     4: # $Id: lonwishlistdisplay.pm,v 1.6 2014/02/28 19:24:03 bisitz Exp $
1.1       wenzelju    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: 
                     29: package Apache::lonwishlistdisplay;
                     30: 
                     31: use strict;
1.3       raeburn    32: use Apache::Constants qw(:common :http);
1.1       wenzelju   33: use Apache::lonnet;
                     34: use Apache::loncommon();
                     35: use Apache::lonhtmlcommon;
                     36: use Apache::lonlocal;
                     37: use Apache::lonwishlist;
                     38: use LONCAPA;
                     39: use Tree;
                     40: 
                     41: 
                     42: # Global variables
                     43: my $root;
                     44: my @childrenRt;
                     45: my %TreeHash;
                     46: 
                     47:  
                     48: # ----------------------------------------------------- Main Handler, package lonwishlistdisplay
                     49: sub handler {
                     50:     my ($r) = @_;
1.3       raeburn    51: 
                     52:     if ($r->header_only) {
                     53:         &Apache::loncommon::content_type($r,'text/html');
                     54:         $r->send_http_header;
                     55:         return OK;
                     56:     }
                     57: 
1.4       raeburn    58:     if ($env{'user.adv'}) {
1.3       raeburn    59:         &Apache::loncommon::content_type($r,'text/html');
                     60:         $r->send_http_header;
                     61:     } else {
                     62:         $env{'user.error.msg'}=
                     63:             "/adm/wishlist:bre:0:0:No rights to access Stored Links";
                     64:         return HTTP_NOT_ACCEPTABLE;
                     65:     }
1.1       wenzelju   66: 
1.7     ! raeburn    67:     my $clientip = &Apache::lonnet::get_requestor_ip($r);
        !            68:     my ($blocked,$blocktext) =
        !            69:         &Apache::loncommon::blocking_status('wishlist',$clientip);
        !            70:     if ($blocked) {
        !            71:         &Apache::lonhtmlcommon::clear_breadcrumbs();
        !            72:         &Apache::lonhtmlcommon::add_breadcrumb(
        !            73:                { href => '/adm/wishlist',
        !            74:                  text => 'Stored Links'});
        !            75:         my $startPage = &Apache::loncommon::start_page('Stored Links');
        !            76:         my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Stored Links','Wishlist');
        !            77:         my $endpage = &Apache::loncommon::end_page();
        !            78:         $r->print($startPage.$breadcrumbs.$blocktext);
        !            79:         return OK;
        !            80:     }
        !            81: 
1.1       wenzelju   82:     if (&Apache::lonwishlist::getWishlist() ne 'error') {
                     83:         # get wishlist entries from user-data db-file and build a tree out of these entries
                     84:         %TreeHash = &Apache::lonwishlist::getWishlist();
                     85: 
                     86:         $root = &Apache::Tree::HashToTree(\%TreeHash);
                     87:         @childrenRt = $root->children();
                     88: 
                     89:         # create a new entry
                     90:         if ($env{'form.title'}) {
                     91:            $root = &Apache::lonwishlist::newEntry($root, $env{'form.title'}, $env{'form.path'}, $env{'form.note'});
                     92:         }
                     93: 
1.5       raeburn    94:         # get unprocessed_cgi (i.e. marked entries, mode ...)
1.2       wenzelju   95:         &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['action','mark','markedToMove','mode','newtitle','note','rat','setTitle','setPath']);
1.1       wenzelju   96: 
                     97:         # change the order of entries within a level, that means sorting the entries
                     98:         my $changeOrder = 0;
1.5       raeburn    99:         if (defined($env{'form.sel'})) {
1.1       wenzelju  100:             my @sel = &Apache::loncommon::get_env_multiple('form.sel');
                    101:             my $indexNode;
                    102:             my $at;
                    103:             for (my $s=0; $s<($#sel+1); $s++) {
                    104:                 if ($sel[$s] ne '') {
                    105:                     $indexNode = $s;
                    106:                     $at = $sel[$s]-1;
                    107:                 }
                    108:             }
                    109:             if ($at ne '') {
                    110:                 $changeOrder = 1;
1.5       raeburn   111:                 $root = &Apache::lonwishlist::sortEntries($root, $indexNode,$at);
1.1       wenzelju  112:             }
                    113:         }
                    114: 
                    115:         # get all marked (checkboxes) entries
                    116:         my @marked = ();
1.5       raeburn   117:         if (defined($env{'form.mark'})) {
1.1       wenzelju  118:             @marked = &Apache::loncommon::get_env_multiple('form.mark');
                    119:         }
                    120: 
                    121:         # move entries from one folder to another
1.5       raeburn   122:         if (defined($env{'form.markedToMove'})) {
1.1       wenzelju  123:            my $markedToMove = $env{'form.markedToMove'};
                    124:            my @ToMove = split(/\,/,$markedToMove);
                    125:            my $moveTo = $env{'form.mark'};
1.5       raeburn   126:            if (defined($moveTo)) { 
                    127:                $root = &Apache::lonwishlist::moveEntries($root, \@ToMove,$moveTo);
1.1       wenzelju  128:            }
                    129:            $changeOrder = 1;
                    130:         }
                    131: 
                    132:         # delete entries
                    133:         if ($env{'form.action'} eq 'delete') {
                    134:             $root = &Apache::lonwishlist::deleteEntries($root, \@marked);
                    135:         }
                    136: 
                    137:         # get all titles and notes and save them
                    138:         # only save, if user wants to save changes
1.5       raeburn   139:         # do not save, when current action is 'delete' or 'sort' or 'move'
1.1       wenzelju  140:         my @newTitles = ();
                    141:         my @newPaths = ();
                    142:         my @newNotes = ();
                    143:         if ((defined $env{'form.newtitle'} || defined $env{'form.newpath'} || defined $env{'form.newnote'})
                    144:             && ($env{'form.action'} ne 'noSave') && ($env{'form.action'} ne 'delete') && !$changeOrder) {
                    145:             @newTitles = &Apache::loncommon::get_env_multiple('form.newtitle');
                    146:             @newPaths = &Apache::loncommon::get_env_multiple('form.newpath');
                    147:             @newNotes = &Apache::loncommon::get_env_multiple('form.newnote');
                    148:             my $node = 0;
                    149:             foreach my $t (@newTitles) {
                    150:                $root = &Apache::lonwishlist::setNewTitle($root, $node, $t);
                    151:                $node++;
                    152:             }
                    153:             $node = 0;
                    154:             my $path = 0;
                    155:             for (my $i = 0; $i < ($#newTitles+1); $i++ ) {
                    156:                if (&Apache::lonwishlist::setNewPath($root, $node, $newPaths[$path])) {
                    157:                      $path++;
                    158:                }
                    159:                $node++;
                    160:             }
                    161:             $node = 0;
                    162:             foreach my $n (@newNotes) {
                    163:                $root =  &Apache::lonwishlist::setNewNote($root, $node, $n);
                    164:                $node++;
                    165:             }
                    166:         }
                    167: 
                    168:         # Create HTML-markup
                    169:         my $page;
                    170:         if ($env{'form.mode'} eq 'edit') {
                    171:             $page = &Apache::lonwishlist::makePage($root, "edit");
1.5       raeburn   172:         } elsif ($env{'form.mode'} eq 'move') {
1.1       wenzelju  173:             $page = &Apache::lonwishlist::makePage($root, "move", \@marked);
1.5       raeburn   174:         } elsif ($env{'form.mode'} eq 'import') {
1.1       wenzelju  175:             $page = &Apache::lonwishlist::makePageImport($root, $env{'form.rat'});
1.5       raeburn   176:         } elsif ($env{'form.mode'} eq 'newLink') {
1.2       wenzelju  177:             $page = &Apache::lonwishlist::makePopUpNewLink($env{'form.setTitle'},$env{'form.setPath'});
1.5       raeburn   178:         } elsif ($env{'form.mode'} eq 'newFolder') {
1.2       wenzelju  179:             $page = &Apache::lonwishlist::makePopUpNewFolder();
1.5       raeburn   180:         } elsif ($env{'form.mode'} eq 'set') {
1.1       wenzelju  181:             $page = &Apache::lonwishlist::makePageSet();
1.5       raeburn   182:         } else {
1.1       wenzelju  183:             $page = &Apache::lonwishlist::makePage($root, "view");
                    184:         }
                    185:         @marked = ();
                    186:         $r->print($page);
1.5       raeburn   187:     } else {
1.6       bisitz    188:         # An error occurred, print an error-page
1.1       wenzelju  189:         my $errorPage = &Apache::lonwishlist::makeErrorPage();
                    190:         $r->print($errorPage);
                    191:     }
                    192:     return OK;
                    193: }
                    194: 
                    195: 1;
                    196: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>