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

1.1       wenzelju    1: # The LearningOnline Network with CAPA
                      2: # Routines to display the wishlist (handler)
                      3: #
1.4     ! raeburn     4: # $Id: lonwishlistdisplay.pm,v 1.3 2012/05/15 14:13:14 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: 
                     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;
                     84:         if (defined $env{'form.sel'}) {
                     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;
                     96:                 $root =  &Apache::lonwishlist::sortEntries($root, $indexNode,$at);
                     97:             }
                     98:         }
                     99: 
                    100:         # get all marked (checkboxes) entries
                    101:         my @marked = ();
                    102:         if (defined $env{'form.mark'}) {
                    103:             @marked = &Apache::loncommon::get_env_multiple('form.mark');
                    104:         }
                    105: 
                    106:         # move entries from one folder to another
                    107:         if (defined $env{'form.markedToMove'}) {
                    108:            my $markedToMove = $env{'form.markedToMove'};
                    109:            my @ToMove = split(/\,/,$markedToMove);
                    110:            my $moveTo = $env{'form.mark'};
                    111:            if (defined $moveTo){ 
                    112:                $root =  &Apache::lonwishlist::moveEntries($root, \@ToMove,$moveTo);
                    113:            }
                    114:            $changeOrder = 1;
                    115:     
                    116:         }
                    117: 
                    118:         # delete entries
                    119:         if ($env{'form.action'} eq 'delete') {
                    120:             $root = &Apache::lonwishlist::deleteEntries($root, \@marked);
                    121:         }
                    122:    
                    123: 
                    124:         # get all titles and notes and save them
                    125:         # only save, if user wants to save changes
                    126:         # do not save, when current action is 'delete' or 'sort' or 'move' 
                    127:         my @newTitles = ();
                    128:         my @newPaths = ();
                    129:         my @newNotes = ();
                    130:         if ((defined $env{'form.newtitle'} || defined $env{'form.newpath'} || defined $env{'form.newnote'})
                    131:             && ($env{'form.action'} ne 'noSave') && ($env{'form.action'} ne 'delete') && !$changeOrder) {
                    132:             @newTitles = &Apache::loncommon::get_env_multiple('form.newtitle');
                    133:             @newPaths = &Apache::loncommon::get_env_multiple('form.newpath');
                    134:             @newNotes = &Apache::loncommon::get_env_multiple('form.newnote');
                    135:             my $node = 0;
                    136:             foreach my $t (@newTitles) {
                    137:                $root = &Apache::lonwishlist::setNewTitle($root, $node, $t);
                    138:                $node++;
                    139:             }
                    140:             $node = 0;
                    141:             my $path = 0;
                    142:             for (my $i = 0; $i < ($#newTitles+1); $i++ ) {
                    143:                if (&Apache::lonwishlist::setNewPath($root, $node, $newPaths[$path])) {
                    144:                      $path++;
                    145:                }
                    146:                $node++;
                    147:             }
                    148:             $node = 0;
                    149:             foreach my $n (@newNotes) {
                    150:                $root =  &Apache::lonwishlist::setNewNote($root, $node, $n);
                    151:                $node++;
                    152:             }
                    153:         }
                    154: 
                    155:         # Create HTML-markup
                    156:         my $page;
                    157:         if ($env{'form.mode'} eq 'edit') {
                    158:             $page = &Apache::lonwishlist::makePage($root, "edit");
                    159:         }
                    160:         elsif ($env{'form.mode'} eq 'move') {
                    161:             $page = &Apache::lonwishlist::makePage($root, "move", \@marked);
                    162:         }
                    163:         elsif ($env{'form.mode'} eq 'import') {
                    164:             $page = &Apache::lonwishlist::makePageImport($root, $env{'form.rat'});
                    165:         }
1.2       wenzelju  166:         elsif ($env{'form.mode'} eq 'newLink') {
                    167:             $page = &Apache::lonwishlist::makePopUpNewLink($env{'form.setTitle'},$env{'form.setPath'});
                    168:         }
                    169:         elsif ($env{'form.mode'} eq 'newFolder') {
                    170:             $page = &Apache::lonwishlist::makePopUpNewFolder();
                    171:         }
1.1       wenzelju  172:         elsif ($env{'form.mode'} eq 'set') {
                    173:             $page = &Apache::lonwishlist::makePageSet();
                    174:         }
                    175:         else {
                    176:             $page = &Apache::lonwishlist::makePage($root, "view");
                    177:         }
                    178:         @marked = ();
                    179:         $r->print($page);
                    180:     }
                    181:     # An error occured, print an error-page
                    182:     else {
                    183:         my $errorPage = &Apache::lonwishlist::makeErrorPage();
                    184:         $r->print($errorPage);
                    185:     }
                    186:     return OK;
                    187: }
                    188: 
                    189: 1;
                    190: __END__

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