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

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

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