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

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

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