File:  [LON-CAPA] / loncom / interface / lonwishlistdisplay.pm
Revision 1.6: download - view: text, annotated - select for diffs
Fri Feb 28 19:24:03 2014 UTC (10 years, 2 months ago) by bisitz
Branches: MAIN
CVS tags: version_2_11_3_uiuc, version_2_11_3_msu, version_2_11_3, version_2_11_2_uiuc, version_2_11_2_msu, version_2_11_2_educog, version_2_11_2, version_2_11_1, version_2_11_0_RC3, version_2_11_0, HEAD
Fix typos in comments

    1: # The LearningOnline Network with CAPA
    2: # Routines to display the wishlist (handler)
    3: #
    4: # $Id: lonwishlistdisplay.pm,v 1.6 2014/02/28 19:24:03 bisitz Exp $
    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 :http);
   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: 
   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 ($env{'user.adv'}) {
   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:     }
   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 ...)
   80:         &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['action','mark','markedToMove','mode','newtitle','note','rat','setTitle','setPath']);
   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:         # 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
  124:         # do not save, when current action is 'delete' or 'sort' or 'move'
  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");
  157:         } elsif ($env{'form.mode'} eq 'move') {
  158:             $page = &Apache::lonwishlist::makePage($root, "move", \@marked);
  159:         } elsif ($env{'form.mode'} eq 'import') {
  160:             $page = &Apache::lonwishlist::makePageImport($root, $env{'form.rat'});
  161:         } elsif ($env{'form.mode'} eq 'newLink') {
  162:             $page = &Apache::lonwishlist::makePopUpNewLink($env{'form.setTitle'},$env{'form.setPath'});
  163:         } elsif ($env{'form.mode'} eq 'newFolder') {
  164:             $page = &Apache::lonwishlist::makePopUpNewFolder();
  165:         } elsif ($env{'form.mode'} eq 'set') {
  166:             $page = &Apache::lonwishlist::makePageSet();
  167:         } else {
  168:             $page = &Apache::lonwishlist::makePage($root, "view");
  169:         }
  170:         @marked = ();
  171:         $r->print($page);
  172:     } else {
  173:         # An error occurred, print an error-page
  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>