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

1.1       wenzelju    1: # The LearningOnline Network with CAPA
                      2: # Routines to display the wishlist (handler)
                      3: #
1.6     ! bisitz      4: # $Id: lonwishlistdisplay.pm,v 1.5 2014/02/16 21:50:16 raeburn 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: 
                     67:     if (&Apache::lonwishlist::getWishlist() ne 'error') {
                     68:         # get wishlist entries from user-data db-file and build a tree out of these entries
                     69:         %TreeHash = &Apache::lonwishlist::getWishlist();
                     70: 
                     71:         $root = &Apache::Tree::HashToTree(\%TreeHash);
                     72:         @childrenRt = $root->children();
                     73: 
                     74:         # create a new entry
                     75:         if ($env{'form.title'}) {
                     76:            $root = &Apache::lonwishlist::newEntry($root, $env{'form.title'}, $env{'form.path'}, $env{'form.note'});
                     77:         }
                     78: 
1.5       raeburn    79:         # get unprocessed_cgi (i.e. marked entries, mode ...)
1.2       wenzelju   80:         &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['action','mark','markedToMove','mode','newtitle','note','rat','setTitle','setPath']);
1.1       wenzelju   81: 
                     82:         # change the order of entries within a level, that means sorting the entries
                     83:         my $changeOrder = 0;
1.5       raeburn    84:         if (defined($env{'form.sel'})) {
1.1       wenzelju   85:             my @sel = &Apache::loncommon::get_env_multiple('form.sel');
                     86:             my $indexNode;
                     87:             my $at;
                     88:             for (my $s=0; $s<($#sel+1); $s++) {
                     89:                 if ($sel[$s] ne '') {
                     90:                     $indexNode = $s;
                     91:                     $at = $sel[$s]-1;
                     92:                 }
                     93:             }
                     94:             if ($at ne '') {
                     95:                 $changeOrder = 1;
1.5       raeburn    96:                 $root = &Apache::lonwishlist::sortEntries($root, $indexNode,$at);
1.1       wenzelju   97:             }
                     98:         }
                     99: 
                    100:         # get all marked (checkboxes) entries
                    101:         my @marked = ();
1.5       raeburn   102:         if (defined($env{'form.mark'})) {
1.1       wenzelju  103:             @marked = &Apache::loncommon::get_env_multiple('form.mark');
                    104:         }
                    105: 
                    106:         # move entries from one folder to another
1.5       raeburn   107:         if (defined($env{'form.markedToMove'})) {
1.1       wenzelju  108:            my $markedToMove = $env{'form.markedToMove'};
                    109:            my @ToMove = split(/\,/,$markedToMove);
                    110:            my $moveTo = $env{'form.mark'};
1.5       raeburn   111:            if (defined($moveTo)) { 
                    112:                $root = &Apache::lonwishlist::moveEntries($root, \@ToMove,$moveTo);
1.1       wenzelju  113:            }
                    114:            $changeOrder = 1;
                    115:         }
                    116: 
                    117:         # delete entries
                    118:         if ($env{'form.action'} eq 'delete') {
                    119:             $root = &Apache::lonwishlist::deleteEntries($root, \@marked);
                    120:         }
                    121: 
                    122:         # get all titles and notes and save them
                    123:         # only save, if user wants to save changes
1.5       raeburn   124:         # do not save, when current action is 'delete' or 'sort' or 'move'
1.1       wenzelju  125:         my @newTitles = ();
                    126:         my @newPaths = ();
                    127:         my @newNotes = ();
                    128:         if ((defined $env{'form.newtitle'} || defined $env{'form.newpath'} || defined $env{'form.newnote'})
                    129:             && ($env{'form.action'} ne 'noSave') && ($env{'form.action'} ne 'delete') && !$changeOrder) {
                    130:             @newTitles = &Apache::loncommon::get_env_multiple('form.newtitle');
                    131:             @newPaths = &Apache::loncommon::get_env_multiple('form.newpath');
                    132:             @newNotes = &Apache::loncommon::get_env_multiple('form.newnote');
                    133:             my $node = 0;
                    134:             foreach my $t (@newTitles) {
                    135:                $root = &Apache::lonwishlist::setNewTitle($root, $node, $t);
                    136:                $node++;
                    137:             }
                    138:             $node = 0;
                    139:             my $path = 0;
                    140:             for (my $i = 0; $i < ($#newTitles+1); $i++ ) {
                    141:                if (&Apache::lonwishlist::setNewPath($root, $node, $newPaths[$path])) {
                    142:                      $path++;
                    143:                }
                    144:                $node++;
                    145:             }
                    146:             $node = 0;
                    147:             foreach my $n (@newNotes) {
                    148:                $root =  &Apache::lonwishlist::setNewNote($root, $node, $n);
                    149:                $node++;
                    150:             }
                    151:         }
                    152: 
                    153:         # Create HTML-markup
                    154:         my $page;
                    155:         if ($env{'form.mode'} eq 'edit') {
                    156:             $page = &Apache::lonwishlist::makePage($root, "edit");
1.5       raeburn   157:         } elsif ($env{'form.mode'} eq 'move') {
1.1       wenzelju  158:             $page = &Apache::lonwishlist::makePage($root, "move", \@marked);
1.5       raeburn   159:         } elsif ($env{'form.mode'} eq 'import') {
1.1       wenzelju  160:             $page = &Apache::lonwishlist::makePageImport($root, $env{'form.rat'});
1.5       raeburn   161:         } elsif ($env{'form.mode'} eq 'newLink') {
1.2       wenzelju  162:             $page = &Apache::lonwishlist::makePopUpNewLink($env{'form.setTitle'},$env{'form.setPath'});
1.5       raeburn   163:         } elsif ($env{'form.mode'} eq 'newFolder') {
1.2       wenzelju  164:             $page = &Apache::lonwishlist::makePopUpNewFolder();
1.5       raeburn   165:         } elsif ($env{'form.mode'} eq 'set') {
1.1       wenzelju  166:             $page = &Apache::lonwishlist::makePageSet();
1.5       raeburn   167:         } else {
1.1       wenzelju  168:             $page = &Apache::lonwishlist::makePage($root, "view");
                    169:         }
                    170:         @marked = ();
                    171:         $r->print($page);
1.5       raeburn   172:     } else {
1.6     ! bisitz    173:         # An error occurred, print an error-page
1.1       wenzelju  174:         my $errorPage = &Apache::lonwishlist::makeErrorPage();
                    175:         $r->print($errorPage);
                    176:     }
                    177:     return OK;
                    178: }
                    179: 
                    180: 1;
                    181: __END__

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