Diff for /loncom/interface/lonwishlist.pm between versions 1.8 and 1.11

version 1.8, 2010/08/25 12:38:45 version 1.11, 2012/05/14 16:39:41
Line 1 Line 1
 # The LearningOnline Network with CAPA  # The LearningOnline Network with CAPA
 # Routines to control the wishlist  # Utility-routines for wishlist
 #  #
 # $Id$  # $Id$
 #  #
Line 39  It is only available for user with acces Line 39  It is only available for user with acces
   
 The wishlist-module uses the CPAN-module "Tree" for easily handling the directory-structure of the wishlist. Each node in the tree has an index to be referenced by.  The wishlist-module uses the CPAN-module "Tree" for easily handling the directory-structure of the wishlist. Each node in the tree has an index to be referenced by.
   
   =back
   
 =cut  =cut
   
 package Apache::lonwishlist;  package Apache::lonwishlist;
   
 use strict;  use strict;
 use Apache::Constants qw(:common);  
 use Apache::lonnet;  use Apache::lonnet;
 use Apache::loncommon();  use Apache::loncommon();
 use Apache::lonhtmlcommon;  use Apache::lonhtmlcommon;
Line 124  sub getWishlist { Line 125  sub getWishlist {
 # Write wishlist to user-data  # Write wishlist to user-data
 sub putWishlist {  sub putWishlist {
     my $wishlist = shift;      my $wishlist = shift;
     $foldersOption = '';  
     &getFoldersForOption(\@childrenRt);  
     my $options = '<option value="" selected="selected">('.&mt('Top level').')</option>'.$foldersOption;  
     $foldersOption = '';  
     $$wishlist{'folders'} = $options;  
     &Apache::lonnet::put('wishlist',$wishlist);      &Apache::lonnet::put('wishlist',$wishlist);
 }  }
   
Line 193  sub deleteWishlist { Line 189  sub deleteWishlist {
   
 # Create a new entry  # Create a new entry
 sub newEntry() {  sub newEntry() {
     my ($title, $path, $note) = @_;      my ($rootgiven, $title, $path, $note) = @_;
   
       $root = $rootgiven;
       @childrenRt = $root->children();
   
     my $date = gmtime();      my $date = gmtime();
     # Create Entry-Object      # Create Entry-Object
     my $entry = Entry->new(title => $title, path => $path, note => $note, date => $date);      my $entry = Entry->new(title => $title, path => $path, note => $note, date => $date);
Line 204  sub newEntry() { Line 204  sub newEntry() {
     if ($folderIndex ne '') {      if ($folderIndex ne '') {
         @allFolders = ();          @allFolders = ();
         &getFoldersToArray(\@childrenRt);          &getFoldersToArray(\@childrenRt);
         my $folderToInsertOn = &Tree::getNodeByIndex($folderIndex,\@allFolders);          my $folderToInsertOn = &Apache::Tree::getNodeByIndex($folderIndex,\@allFolders);
         $folderToInsertOn->add_child($tree);          $folderToInsertOn->add_child($tree);
     }      }
     else {      else {
         $root->add_child($tree);          $root->add_child($tree);
     }      }
     &saveChanges();      return &saveChanges();
 }  }
   
   
 # Delete entries  # Delete entries
 sub deleteEntries {  sub deleteEntries {
       my $rootgiven = shift;
     my $marked = shift;      my $marked = shift;
     &getNodesToArray(\@childrenRt);  
   
       $root = $rootgiven;
       @childrenRt = $root->children();
   
       &getNodesToArray(\@childrenRt);
     foreach my $m (@$marked) {      foreach my $m (@$marked) {
         my $found = &Tree::getNodeByIndex($m, \@allNodes);          my $found = &Apache::Tree::getNodeByIndex($m, \@allNodes);
         &Tree::removeNode($found);          # be sure, that entry exists (may have been deleted before, e.g. in an other browsertab)
           if (defined $found) {
               &Apache::Tree::removeNode($found);
           }
     }      }
     @allNodes = ();      @allNodes = ();
     &saveChanges();      return &saveChanges();
 }  }
   
   
 # Sort entries  # Sort entries
 sub sortEntries {  sub sortEntries {
       my $rootgiven = shift;
     my $indexNode = shift;      my $indexNode = shift;
     my $at = shift;      my $at = shift;
   
       $root = $rootgiven;
       @childrenRt = $root->children();
           
     &getNodesToArray(\@childrenRt);      &getNodesToArray(\@childrenRt);
     my $foundNode = &Tree::getNodeByIndex($indexNode, \@allNodes);      my $foundNode = &Apache::Tree::getNodeByIndex($indexNode, \@allNodes);
   
     &Tree::moveNode($foundNode,$at,undef);      &Apache::Tree::moveNode($foundNode,$at,undef);
     @allNodes = ();      @allNodes = ();
       return &saveChanges();
 }  }
   
   
 # Move entries  # Move entries
 sub moveEntries {  sub moveEntries {
       my $rootgiven = shift;
     my $indexNodesToMove = shift;      my $indexNodesToMove = shift;
     my $indexParent = shift;      my $indexParent = shift;
     my @nodesToMove = ();      my @nodesToMove = ();
   
       $root = $rootgiven;
       @childrenRt = $root->children();
   
     # get all nodes that should be moved      # get all nodes that should be moved
     &getNodesToArray(\@childrenRt);      &getNodesToArray(\@childrenRt);
     foreach my $index (@$indexNodesToMove) {      foreach my $index (@$indexNodesToMove) {
         my $foundNode = &Tree::getNodeByIndex($index, \@allNodes);          my $foundNode = &Apache::Tree::getNodeByIndex($index, \@allNodes);
         push(@nodesToMove, $foundNode);          push(@nodesToMove, $foundNode);
     }      }
   
Line 266  sub moveEntries { Line 282  sub moveEntries {
         }          }
         if (!$parentIsIn) {          if (!$parentIsIn) {
             if ($indexParent ne "root") {              if ($indexParent ne "root") {
                 $foundParent = &Tree::getNodeByIndex($indexParent, \@allNodes);                  $foundParent = &Apache::Tree::getNodeByIndex($indexParent, \@allNodes);
                 &Tree::moveNode($node,undef,$foundParent);                  &Apache::Tree::moveNode($node,undef,$foundParent);
             }              }
             else {              else {
                 &Tree::moveNode($node,undef,$root);                  &Apache::Tree::moveNode($node,undef,$root);
             }              }
         }          }
     }      }
     @allNodes = ();      @allNodes = ();
       return &saveChanges();
 }  }
   
   
 # Set a new title for an entry  # Set a new title for an entry
 sub setNewTitle {  sub setNewTitle {
     my ($nodeindex, $newTitle) = @_;      my ($rootgiven, $nodeindex, $newTitle) = @_;
   
       $root = $rootgiven;
       @childrenRt = $root->children();
   
     &getNodesToArray(\@childrenRt);      &getNodesToArray(\@childrenRt);
     my $found = &Tree::getNodeByIndex($nodeindex, \@allNodes);      my $found = &Apache::Tree::getNodeByIndex($nodeindex, \@allNodes);
     $found->value()->title($newTitle);       $found->value()->title($newTitle); 
     @allNodes = ();      @allNodes = ();
       return &saveChanges();
 }  }
   
   
 # Set a new path for an entry  # Set a new path for an entry
 sub setNewPath {  sub setNewPath {
     my ($nodeindex, $newPath) = @_;      my ($rootgiven, $nodeindex, $newPath) = @_;
   
       $root = $rootgiven;
       @childrenRt = $root->children();
   
     &getNodesToArray(\@childrenRt);      &getNodesToArray(\@childrenRt);
     my $found = &Tree::getNodeByIndex($nodeindex, \@allNodes);      my $found = &Apache::Tree::getNodeByIndex($nodeindex, \@allNodes);
     if ($found->value()->path()) {      if ($found->value()->path()) {
         $found->value()->path($newPath);           $found->value()->path($newPath); 
         return 1;          return &saveChanges();
     }      }
     @allNodes = ();      @allNodes = ();
     return 0;      return 0;
Line 304  sub setNewPath { Line 330  sub setNewPath {
   
 # Set a new note for an entry  # Set a new note for an entry
 sub setNewNote {  sub setNewNote {
     my ($nodeindex, $newNote) = @_;      my ($rootgiven, $nodeindex, $newNote) = @_;
   
       $root = $rootgiven;
       @childrenRt = $root->children();
   
     &getNodesToArray(\@childrenRt);      &getNodesToArray(\@childrenRt);
     my $found = &Tree::getNodeByIndex($nodeindex, \@allNodes);      my $found = &Apache::Tree::getNodeByIndex($nodeindex, \@allNodes);
     $found->value()->note($newNote);       $found->value()->note($newNote); 
     @allNodes = ();      @allNodes = ();
       return &saveChanges();
 }  }
   
   
 # Save all changes  # Save all changes
 sub saveChanges {  sub saveChanges {
     @childrenRt = $root->children();      @childrenRt = $root->children();
     &Tree::TreeIndex(\@childrenRt);      &Apache::Tree::TreeIndex(\@childrenRt);
     &Tree::setCountZero();      &Apache::Tree::setCountZero();
     &Tree::RootToHash(\@childrenRt);      &Apache::Tree::RootToHash(\@childrenRt);
     &Tree::TreeToHash(\@childrenRt);      &Apache::Tree::TreeToHash(\@childrenRt);
     &deleteWishlist();      &deleteWishlist();
     &putWishlist(\%TreeToHash);      &putWishlist(\%TreeToHash);
       return $root;
   
 }  }
   
Line 349  sub saveChanges { Line 381  sub saveChanges {
      Recursive call starting with all children of the root of the tree (parameter nodes is reference to an array containing the nodes of the current level).            Recursive call starting with all children of the root of the tree (parameter nodes is reference to an array containing the nodes of the current level).     
     
   
  =back  =back
   
 =cut  =cut
   
Line 446  sub getNodesToArray { Line 478  sub getNodesToArray {
      Calls &wishlistView(nodes), &wishlistEdit(nodes) or &wishlistMove(nodes, marked).       Calls &wishlistView(nodes), &wishlistEdit(nodes) or &wishlistMove(nodes, marked).
     
   
   =item * &makePopUpNewLink(title, path)
   
        Returns the HTML-markup for the pop-up-window 'Add Link'. If this is called up from a browsed resource, the input-fields titel and path are pre-filled with the resources' meta-data-title and it's path. 
   
   
   =item * &makePopUpNewFolder()
   
        Returns the HTML-markup for the pop-up-window 'Add Folder'.
   
   
 =item * &makePageSet()  =item * &makePageSet()
   
      Returns the HTML-Markup for the page shown when a link was set by using the icon when viewing a resource.       Returns the HTML-Markup for the page shown when a link was set by using the icon when viewing a resource.
Line 479  sub JSforWishlist { Line 521  sub JSforWishlist {
     &getFoldersToArray(\@childrenRt);      &getFoldersToArray(\@childrenRt);
     &getFoldersForOption(\@childrenRt);      &getFoldersForOption(\@childrenRt);
   
     # texthash  
     my %lt = &Apache::lonlocal::texthash(  
                  'nl' => 'New Link',  
                  'nf' => 'New Folder',  
                  'lt' => 'Link Title',  
                  'ft' => 'Folder Title',  
                  'pa' => 'Path',  
                  'nt' => 'Note',  
                  'si' => 'Save in',  
                  'cl' => 'Cancel');  
   
   
     my $inPageNewLink = '<h1>'.$lt{'nl'}.'</h1>'.  
                         '<form method="post" name="newlink" action="/adm/wishlist" target="wishlist" '.  
                         'onsubmit="return newlinksubmit();" >'.  
                         &Apache::lonhtmlcommon::start_pick_box().  
                         &Apache::lonhtmlcommon::row_title($lt{'lt'}).  
                         '<input type="text" name="title" size="45" value="" />'.  
                         &Apache::lonhtmlcommon::row_closure().  
                         &Apache::lonhtmlcommon::row_title($lt{'pa'}).  
                         '<input type="text" name="path" size="45" value="" />'.  
                         &Apache::lonhtmlcommon::row_closure().  
                         &Apache::lonhtmlcommon::row_title($lt{'nt'}).  
                         '<textarea name="note" rows="3" cols="35" style="width:100%"></textarea>'.  
                         &Apache::lonhtmlcommon::row_closure(1).  
                         &Apache::lonhtmlcommon::end_pick_box().  
                         '<br/><br/>'.  
                         '<input type="submit" value="'.$lt{'si'}.'" />'.  
                         '<select name="folders">'.  
                         '<option value="" selected="selected">('.&mt('Top level').')</option>'.  
                         $foldersOption.  
                         '</select>'.  
                         '<input type="button" value="'.$lt{'cl'}.'" onclick="javascript:window.close();" />'.  
                         '</form>';  
       
     my $inPageNewFolder = '<h1>'.$lt{'nf'}.'</h1>'.  
                           '<form method="post" name="newfolder" action="/adm/wishlist" target="wishlist" '.  
                           'onsubmit="return newfoldersubmit();" >'.  
                           &Apache::lonhtmlcommon::start_pick_box().  
                           &Apache::lonhtmlcommon::row_title($lt{'ft'}).  
                           '<input type="text" name="title" size="45" value="" /><br />'.  
                           &Apache::lonhtmlcommon::row_closure().  
                           &Apache::lonhtmlcommon::row_title($lt{'nt'}).  
                           '<textarea name="note" rows="3" cols="35" style="width:100%"></textarea><br />'.  
                           &Apache::lonhtmlcommon::row_closure(1).  
                           &Apache::lonhtmlcommon::end_pick_box().  
                           '<br/><br/>'.  
                           '<input type="submit" value="'.$lt{'si'}.'" />'.  
                           '<select name="folders">'.  
                           '<option value="" selected="selected">('.&mt('Top level').')</option>'.  
                           $foldersOption.  
                           '</select>'.  
                           '<input type="button" value="'.$lt{'cl'}.'" onclick="javascript:window.close();" />'.  
                           '</form>';  
   
     # Remove all \n for inserting on javascript document.write  
     $inPageNewLink =~ s/\n//g;  
     $inPageNewFolder =~ s/\n//g;  
   
     # it is checked, wether a path links to a LON-CAPA-resource or an external website. links to course-contents are not allowed      # it is checked, wether a path links to a LON-CAPA-resource or an external website. links to course-contents are not allowed
     # because they probably will return a kind of 'no access' (unless the user is already in the course, the path links to).      # because they probably will return a kind of 'no access' (unless the user is already in the course, the path links to).
     # also importing these kind of links into a course does not make much sense.      # also importing these kind of links into a course does not make much sense.
Line 553  sub JSforWishlist { Line 536  sub JSforWishlist {
     my $warningFolder = &mt('You must insert a title!');      my $warningFolder = &mt('You must insert a title!');
     my $warningDelete = &mt('Are you sure you want to delete the selected entries? Deleting a folder also deletes all entries within this folder!');      my $warningDelete = &mt('Are you sure you want to delete the selected entries? Deleting a folder also deletes all entries within this folder!');
     my $warningSave = &mt('You have unsaved changes. You can either save these changes now by clicking "ok" or click "cancel" if you do not want to save your changes.');      my $warningSave = &mt('You have unsaved changes. You can either save these changes now by clicking "ok" or click "cancel" if you do not want to save your changes.');
     my $warningMove = &mt('You must select a destination folder!');      my $warningMoveS = &mt('You must select at minimum one entry to move!');
       my $warningMoveD = &mt('You must select a destination folder!');
     $foldersOption = '';      $foldersOption = '';
   
     my $js = &Apache::lonhtmlcommon::scripttag(<<JAVASCRIPT);      my $js = &Apache::lonhtmlcommon::scripttag(<<JAVASCRIPT);
     function newLink() {      function newLink() {
         newlinkWin=window.open('','newlinkWin','width=580,height=320,scrollbars=yes');          newlinkWin=window.open('/adm/wishlist?mode=newLink','newlinkWin','width=580,height=350, scrollbars=yes');
         newlinkWin.document.write('$startPagePopup'   
                               +'<script type="text\/javascript">'  
                               +'function newlinksubmit(){'  
                               +'var path = document.getElementsByName("path")[0].value;'  
                               +'var title = document.getElementsByName("title")[0].value;'  
                               +'if (!path || !title) {'  
                               +'alert("$warningLink");'  
                               +'return false;}'  
                               +'var linkOK = (path.match(/^http:(\\\\/\\\\/)/) || path.match(/^https:(\\\\/\\\\/)/))'  
                               +'&& !(path.match(/\\.problem/) || path.match(/\\.exam/)'  
                               +'|| path.match(/\\.quiz/) || path.match(/\\.assess/)'  
                               +'|| path.match(/\\.survey/) || path.match(/\\.form/)'  
                               +'|| path.match(/\\.library/) || path.match(/\\.page/)'  
                               +'|| path.match(/\\.sequence/));'  
                               +'if (!path.match(/^(\\\\/res\\\\/)/) && !linkOK) {'  
                               +'alert("$warningLinkNotAllowed1");'  
                               +'return false;}'  
                               +'else {'  
                               +'window.close();'  
                               +'return true;}}'  
                               +'<\/scr'+'ipt>'  
                               +'$inPageNewLink'  
                               +'$endPagePopup');  
         newlinkWin.document.close();  
     }      }
   
     function newFolder() {      function newFolder() {
         newfolderWin=window.open('','newfolderWin','width=580,height=270, scrollbars=yes');          newfolderWin=window.open('/adm/wishlist?mode=newFolder','newfolderWin','width=580,height=270, scrollbars=yes');
         newfolderWin.document.write('$startPagePopup'   
                               +'<script type="text\/javascript">'  
                               +'function newfoldersubmit(){'  
                               +'var title = document.getElementsByName("title")[0].value;'  
                               +'if (!title) {'  
                               +'alert("$warningFolder");'  
                               +'return false;}'  
                               +'else {'  
                               +'window.close();'  
                               +'return true;}}'  
                               +'<\/scr'+'ipt>'  
                               +'$inPageNewFolder'  
                               +'$endPagePopup');  
         newfolderWin.document.close();  
     }      }
   
     function setFormAction(action,mode) {      function setFormAction(action,mode) {
Line 626  sub JSforWishlist { Line 572  sub JSforWishlist {
             r = linksOK();              r = linksOK();
         }          }
         else if (action == 'move') {          else if (action == 'move') {
             r = selectDestinationFolder();              r = selectDestinationFolder(mode);
         }          }
         document.getElementsByName('list')[0].setAttribute("action", "/adm/wishlist?mode="+mode);           document.getElementsByName('list')[0].setAttribute("action", "/adm/wishlist?mode="+mode); 
         if (r) {          if (r) {
Line 1030  sub JSforWishlist { Line 976  sub JSforWishlist {
         }          }
     }      }
   
     function selectDestinationFolder() {      function selectDestinationFolder(mode) {
         var mark = document.getElementsByName('mark');          var mark = document.getElementsByName('mark');
         var i = 0;          var i = 0;
         for (i = 0; i < mark.length; i++) {          for (i = 0; i < mark.length; i++) {
Line 1039  sub JSforWishlist { Line 985  sub JSforWishlist {
                 return true;                  return true;
             }              }
         }          }
         alert('$warningMove');          if (mode == 'move') {
               alert('$warningMoveS');
           }
           else {
               alert('$warningMoveD');
           }
         return false;          return false;
     }      }
   
Line 1152  sub wishlistView { Line 1103  sub wishlistView {
     
         # checkboxes          # checkboxes
         $wishlistHTMLview .= '<td><input type="checkbox" name="mark" id="check'.$index.'" value="'.$index.'" '.          $wishlistHTMLview .= '<td><input type="checkbox" name="mark" id="check'.$index.'" value="'.$index.'" '.
                              'onclick="selectAction('."'row".$index."'".')"/></td>';                               'onclick="selectAction('."'row".$index."'".')" /></td>';
   
         # entry is a folder          # entry is a folder
         if ($n->value()->path() eq '') {          if ($n->value()->path() eq '') {
Line 1220  sub wishlistEdit { Line 1171  sub wishlistEdit {
   
         # checkboxes          # checkboxes
         $wishlistHTMLedit .= '<td><input type="checkbox" name="mark" id="check'.$index.'" value="'.$index.'" '.          $wishlistHTMLedit .= '<td><input type="checkbox" name="mark" id="check'.$index.'" value="'.$index.'" '.
                              'onclick="selectAction('."'row".$index."'".')"/></td>';                               'onclick="selectAction('."'row".$index."'".')" /></td>';
   
         # option-tags for sorting entries. we need the numbers from 1 to n with n being the number of entries on the same level as the current entry.          # option-tags for sorting entries. we need the numbers from 1 to n with n being the number of entries on the same level as the current entry.
         # set the number for the current entry into brackets           # set the number for the current entry into brackets 
Line 1243  sub wishlistEdit { Line 1194  sub wishlistEdit {
                                  '<a href="javascript:;" onclick="folderAction('."'row".$index."'".')" style="vertical-align:top" >'.                                   '<a href="javascript:;" onclick="folderAction('."'row".$index."'".')" style="vertical-align:top" >'.
                                  '<img src="/adm/lonIcons/arrow.closed.gif" id="img'.$index.'" alt = ""  class="LC_icon"/>'.                                   '<img src="/adm/lonIcons/arrow.closed.gif" id="img'.$index.'" alt = ""  class="LC_icon"/>'.
                                  '<img src="/adm/lonIcons/navmap.folder.closed.gif" id="imgFolder'.$index.'" alt="folder"/></a>'.                                   '<img src="/adm/lonIcons/navmap.folder.closed.gif" id="imgFolder'.$index.'" alt="folder"/></a>'.
                                  '<input type="text" name="newtitle" value="'.$n->value()->title().'" alt = "'.$n->value()->title().'"/>'.                                   '<input type="text" name="newtitle" value="'.$n->value()->title().'" alt = "'.$n->value()->title().'" />'.
                                  '</td><td></td>';                                   '</td><td></td>';
   
         }          }
Line 1253  sub wishlistEdit { Line 1204  sub wishlistEdit {
                                  $options.'</select></td>'.                                   $options.'</select></td>'.
                                  '<td id="padd'.$index.'" style="padding-left:'.(($indent-$indentConst)<=0?$indentConst:$indent).'px;">'.                                   '<td id="padd'.$index.'" style="padding-left:'.(($indent-$indentConst)<=0?$indentConst:$indent).'px;">'.
                                  '<img src="/res/adm/pages/wishlist-link.png" id="img'.$index.'" alt="link"/>'.                                   '<img src="/res/adm/pages/wishlist-link.png" id="img'.$index.'" alt="link"/>'.
                                  '<input type="text" name="newtitle" value="'.$n->value()->title().'" alt = "'.$n->value()->title().'"/></td>'.                                   '<input type="text" name="newtitle" value="'.$n->value()->title().'" alt = "'.$n->value()->title().'" /></td>'.
                                  '<td><input type="text" name="newpath" value="'.$n->value()->path().'" alt = "'.$n->value()->path().'"/></td>';                                   '<td><input type="text" name="newpath" value="'.$n->value()->path().'" alt = "'.$n->value()->path().'" /></td>';
         }          }
                   
         # note-icon, different icons for an entries with note and those without          # note-icon, different icons for an entries with note and those without
Line 1397  sub wishlistImport { Line 1348  sub wishlistImport {
         # checkboxes          # checkboxes
         $wishlistHTMLimport .= '<td>'.          $wishlistHTMLimport .= '<td>'.
                                '<input type="checkbox" name="check" id="check'.$index.'" value="'.$index.'" '.                                 '<input type="checkbox" name="check" id="check'.$index.'" value="'.$index.'" '.
                                'onclick="selectAction('."'row".$index."'".')"/>'.                                 'onclick="selectAction('."'row".$index."'".')" />'.
                                '<input type="hidden" name="title'.$index.'" value="'.&escape($n->value()->title()).'">'.                                 '<input type="hidden" name="title'.$index.'" value="'.&escape($n->value()->title()).'" />'.
                                '<input type="hidden" name="filelink'.$index.'" value="'.&escape($n->value()->path()).'">'.                                 '<input type="hidden" name="filelink'.$index.'" value="'.&escape($n->value()->path()).'" />'.
                                '<input type="hidden" name="id'.$index.'">'.                                 '<input type="hidden" name="id'.$index.'" />'.
                                '</td>';                                 '</td>';
   
         # entry is a folder          # entry is a folder
Line 1453  sub wishlistImport { Line 1404  sub wishlistImport {
   
 # Returns the HTML-Markup for wishlist  # Returns the HTML-Markup for wishlist
 sub makePage {  sub makePage {
       my $rootgiven = shift;
     my $mode = shift;      my $mode = shift;
     my $marked = shift;      my $marked = shift;
   
       $root = $rootgiven;
       @childrenRt = $root->children();
   
     # breadcrumbs and start_page      # breadcrumbs and start_page
     &Apache::lonhtmlcommon::clear_breadcrumbs();      &Apache::lonhtmlcommon::clear_breadcrumbs();
     &Apache::lonhtmlcommon::add_breadcrumb(      &Apache::lonhtmlcommon::add_breadcrumb(
Line 1542  sub makePage { Line 1497  sub makePage {
   
     # start form       # start form 
     my $inner .= '<form name="list" action ="/adm/wishlist" method="post">'.      my $inner .= '<form name="list" action ="/adm/wishlist" method="post">'.
                  '<input type="hidden" id="action" name="action" value=""/>';                   '<input type="hidden" id="action" name="action" value="" />';
     
     # only display subbox in view- or edit-mode      # only display subbox in view- or edit-mode
     if ($mode eq 'view' || $mode eq 'edit') {      if ($mode eq 'view' || $mode eq 'edit') {
Line 1579  sub makePage { Line 1534  sub makePage {
         }          }
         if ($markStr) {          if ($markStr) {
             $markStr = substr($markStr, 0, length($markStr)-1);              $markStr = substr($markStr, 0, length($markStr)-1);
             $inner .= '<input type="hidden" value="'.$markStr.'" name="markedToMove"/>';              $inner .= '<input type="hidden" value="'.$markStr.'" name="markedToMove" />';
             $inner .= '<p><span class="LC_info">'.&mt('You have selected the red marked entries to be moved to another folder. '.              $inner .= '<p><span class="LC_info">'.&mt('You have selected the red marked entries to be moved to another folder. '.
                                                    'Now choose the new destination folder.').'</span></p>';                                                     'Now choose the new destination folder.').'</span></p>';
             &wishlistMove(\@childrenRt, $marked);              &wishlistMove(\@childrenRt, $marked);
             $inner .= '<table class="LC_data_table LC_tableOfContent">'.$wishlistHTMLmove.'</table><br/><br/>';              $inner .= '<table class="LC_data_table LC_tableOfContent">'.$wishlistHTMLmove.'</table><br/><br/>';
             $inner .= '<input type="button" value="'.&mt('Move').'" onclick="setFormAction('."'move','view'".');"/>'.              $inner .= '<input type="button" value="'.&mt('Move').'" onclick="setFormAction('."'move','view'".');" />'.
                       '<input type="button" value="'.&mt('Cancel').'" onclick="go('."'/adm/wishlist'".')"/>';                        '<input type="button" value="'.&mt('Cancel').'" onclick="go('."'/adm/wishlist'".')" />';
   
             $wishlistHTMLmove ='<tr id="root" class="LC_odd_row"><td><input type="radio" name="mark" id="radioRoot" value="root" /></td>'.              $wishlistHTMLmove ='<tr id="root" class="LC_odd_row"><td><input type="radio" name="mark" id="radioRoot" value="root" /></td>'.
                                '<td>'.&mt('Top level').'</td><td></td></tr>';                                 '<td>'.&mt('Top level').'</td><td></td></tr>';
         }          }
         else {          else {
             $inner .= '<p><span class="LC_info">'.&mt("You haven't marked any entry to move.").'</span></p>'.              $inner .= '<p><span class="LC_info">'.&mt("You haven't marked any entry to move.").'</span></p>'.
                       '<input type="button" value="'.&mt('Back').'" onclick="go('."'/adm/wishlist'".')"/>';                        '<input type="button" value="'.&mt('Back').'" onclick="go('."'/adm/wishlist'".')" />';
         }          }
     }      }
           
Line 1609  sub makePage { Line 1564  sub makePage {
 }  }
   
   
   # Returns the HTML-Markup for the PopUp, shown when a new link should set, when NOT
   # beeing in the wishlist-interface (method is called in lonmenu and lonsearchcat)
   sub makePopUpNewLink {
       my ($title, $path) = @_;
   
       # Get all existing folders to offer posibility to set a new link
       # into a folder
       my %TreeHashLink = &Apache::lonwishlist::getWishlist();
       my $rootLink = &Apache::Tree::HashToTree(\%TreeHashLink);
       my @childrenRtLink = $rootLink->children();
   
       $foldersOption = '';
       @allFolders = ();
       &getFoldersToArray(\@childrenRtLink);
       &getFoldersForOption(\@childrenRtLink);
   
       my $options = '<option value="" selected="selected">('.&mt('Top level').')</option>'.$foldersOption;
       $foldersOption = '';
       @allFolders = ();
   
       # HTML-Markup for the Pop-Up-window 'Set a link for this resource to wishlist'
       my $startPageWishlistlink = 
           &Apache::loncommon::start_page('Set link to wishlist',undef,
                                         {'only_body' => 1,
                                          'bgcolor'   => '#FFFFFF',});
   
       my $warningLink = &mt('You must insert a title!');
       my $warningLinkNotAllowed1 = &mt('You can only insert links to LON-CAPA resources from the resource-pool '.
                                       'or to external websites. Paths to LON-CAPA resources must be of the form /res/dom/usr... . '.
                                       'Paths to external websites must contain the network protocol (e.g. http://...).');
   
       my $inPageWishlistlink1 = '<h1>'.&mt('Set a link to wishlist').'</h1>';
       # If no title is delivered, 'New Link' is called up from the wishlist-interface, so after
       # submitting the window should close instead of offering a link to wishlist (like it should do
       # if we call 'Set New Link' from within a browsed ressource)
       if (!$title) {
           $inPageWishlistlink1 .= '<form method="post" name="newlink" action="/adm/wishlist" target="wishlist"'.
                                   'onsubmit="return newlinksubmit();" >';
       }
       else {
           $inPageWishlistlink1 .= '<form method="post" name="newlink" action="/adm/wishlist?mode=set" '.
                                   'onsubmit="return newlinksubmit();" >';
       }
       $inPageWishlistlink1 .= &Apache::lonhtmlcommon::start_pick_box().
                               &Apache::lonhtmlcommon::row_title(&mt('Link Title'));
   
       my $inPageWishlistlink2 = &Apache::lonhtmlcommon::row_closure().
                                 &Apache::lonhtmlcommon::row_title(&mt('Path'));
   
       my $inPageWishlistlink3 = &Apache::lonhtmlcommon::row_closure().
                                 &Apache::lonhtmlcommon::row_title(&mt('Note')).
                                 '<textarea name="note" rows="3" cols="35" style="width:100%"></textarea>'.
                                 &Apache::lonhtmlcommon::row_closure(1).
                                 &Apache::lonhtmlcommon::end_pick_box().
                                 '<br/><br/>'.
                                 '<input type="submit" value="'.&mt('Save in').'" />'.
                                 '<select name="folders">'.
                                 $options.
                                 '</select>'.
                                 '<input type="button" value="'.&mt('cancel').'" onclick="javascript:window.close();" />'.
                                 '</form>';
       $options = '';
   
       my $endPageWishlistlink = &Apache::loncommon::end_page();
   
       my $popUp = $startPageWishlistlink.
       $inPageWishlistlink1.
       '<input type="text" name="title" size="45" value="" />'.
       $inPageWishlistlink2.
       '<input type="text" name="path" size="45" value="" />'.
       $inPageWishlistlink3;
   
       # JavaScript-function to set title and path of ressource automatically
       # and show warning, if no title was set or path is invalid
       $popUp .= <<SCRIPT;
       <script type="text\/javascript">
       document.getElementsByName("title")[0].value = '$title';
       document.getElementsByName("path")[0].value = '$path';
       var fromwishlist = false;
       var titleget = '$title';
       if (!titleget) {
           fromwishlist = true;
       } 
       function newlinksubmit(){
       var title = document.getElementsByName("title")[0].value;
       var path = document.getElementsByName("path")[0].value;
       if (!title) {
           alert("$warningLink");
           return false;}
       var linkOK = (path.match(/\^http:(\\\/\\\/)/) || path.match(/\^https:(\\\/\\\/)/))
       && !(path.match(/\\.problem/) || path.match(/\\.exam/)
       || path.match(/\\.quiz/) || path.match(/\\.assess/)
       || path.match(/\\.survey/) || path.match(/\\.form/)
       || path.match(/\\.library/) || path.match(/\\.page/)
       || path.match(/\\.sequence/));
       if (!path.match(/\^(\\\/res\\\/)/) && !linkOK) {
           alert("$warningLinkNotAllowed1");
           return false;}
       if (fromwishlist) {
           window.close();
       }
       return true;}
       <\/script>
   SCRIPT
   
       $popUp .= $endPageWishlistlink;
   
       return $popUp;
   }
   
   sub makePopUpNewFolder {
       # Get all existing folders to offer posibility to create a new folder
       # into an existing folder
       my %TreeHashLink = &Apache::lonwishlist::getWishlist();
       my $rootLink = &Apache::Tree::HashToTree(\%TreeHashLink);
       my @childrenRtLink = $rootLink->children();
   
       $foldersOption = '';
       @allFolders = ();
       &getFoldersToArray(\@childrenRtLink);
       &getFoldersForOption(\@childrenRtLink);
   
       my $options = '<option value="" selected="selected">('.&mt('Top level').')</option>'.$foldersOption;
       $foldersOption = '';
       @allFolders = ();
   
       # HTML-Markup for the Pop-Up-window 'New Folder'
       my $startPageWishlistfolder = 
           &Apache::loncommon::start_page('New Folder',undef,
                                         {'only_body' => 1,
                                          'bgcolor'   => '#FFFFFF',});
   
       my $warningFolder = &mt('You must insert a title!');
   
   
       my $inPageNewFolder = '<h1>'.&mt('New Folder').'</h1>'.
                             '<form method="post" name="newfolder" action="/adm/wishlist" target="wishlist" '.
                             'onsubmit="return newfoldersubmit();" >'.
                             &Apache::lonhtmlcommon::start_pick_box().
                             &Apache::lonhtmlcommon::row_title(&mt('Folder title')).
                             '<input type="text" name="title" size="45" value="" /><br />'.
                             &Apache::lonhtmlcommon::row_closure().
                             &Apache::lonhtmlcommon::row_title(&mt('Note')).
                             '<textarea name="note" rows="3" cols="35" style="width:100%"></textarea><br />'.
                             &Apache::lonhtmlcommon::row_closure(1).
                             &Apache::lonhtmlcommon::end_pick_box().
                             '<br/><br/>'.
                             '<input type="submit" value="'.&mt('Save in').'" />'.
                             '<select name="folders">'.
                             $options.
                             '</select>'.
                             '<input type="button" value="'.&mt('Cancel').'" onclick="javascript:window.close();" />'.
                             '</form>';
       my $endPageWishlistfolder = &Apache::loncommon::end_page();
   
       my $popUp = $startPageWishlistfolder.
       $inPageNewFolder;
   
       $popUp .= <<SCRIPT;
       <script type="text\/javascript">
           function newfoldersubmit(){
               var title = document.getElementsByName("title")[0].value;
               if (!title) {
               alert("$warningFolder");
               return false;}
               else {
               window.close();
               return true;}}
       <\/script>
   SCRIPT
   
       $popUp .= $endPageWishlistfolder;
   
       return $popUp;
   }
   
 # Returns the HTML-Markup for the page, shown when a link was set  # Returns the HTML-Markup for the page, shown when a link was set
 sub makePageSet {  sub makePageSet {
     # start_page       # start_page 
Line 1635  sub makePageSet { Line 1766  sub makePageSet {
   
 # Returns the HTML-Markup for the page, shown when links should be imported into a course  # Returns the HTML-Markup for the page, shown when links should be imported into a course
 sub makePageImport {  sub makePageImport {
       my $rootgiven = shift;
     my $rat = shift;      my $rat = shift;
   
       $root = $rootgiven;
       @childrenRt = $root->children();
     # start_page       # start_page 
     my $startPage = &Apache::loncommon::start_page('Wishlist',undef,      my $startPage = &Apache::loncommon::start_page('Wishlist',undef,
                                                    {'only_body' => 1});                                                     {'only_body' => 1});
Line 1656  sub makePageImport { Line 1791  sub makePageImport {
                                                   .'</span></p>';                                                    .'</span></p>';
     }      }
     my %wishlist = &getWishlist();      my %wishlist = &getWishlist();
     my $fnum = (keys %wishlist)-1;  
   
     $inner .= '<form method="post" name="groupsort">'.      #FIXME Saved string containing all folders in wishlist.db-file (key 'folders') in first version of lonwishlist
               '<input type="hidden" value="'.$fnum.'" name="fnum">'.      #After splitting lonwishlist into two modules, this is not necessary anymore. So, dependent from when the wishlist
               '<input type="button" onclick="javascript:checkAll()" id="checkallbutton" value="'.&mt('Check All').'">'.      #was first called (i.e. when wishlist.db was created), there might be an entry 'folders' or not. Number of links in
               '<input type="button" onclick="javascript:uncheckAll()" id="uncheckallbutton" value="'.&mt('Uncheck All').'">'.      #wishlist.db depends on wether this entry exists or not...JW  
               '<input type="button" value="'.&mt('Import Checked').'" onclick="finish_import();">'.          my $fnum;
               '<input type="button" value="'.&mt('Cancel').'" onclick="window.close();"><br/><br/>';       if (defined $wishlist{'folders'}) {
           $fnum = (keys %wishlist)-2;
       }
       else {
           $fnum = (keys %wishlist)-1;
       }
   
       $inner .= '<form method="post" name="groupsort" action="">'.
                 '<input type="hidden" value="'.$fnum.'" name="fnum" />'.
                 '<input type="button" onclick="javascript:checkAll()" id="checkallbutton" value="'.&mt('Check All').'" />'.
                 '<input type="button" onclick="javascript:uncheckAll()" id="uncheckallbutton" value="'.&mt('Uncheck All').'" />'.
                 '<input type="button" value="'.&mt('Import Checked').'" onclick="finish_import();" />'.    
                 '<input type="button" value="'.&mt('Cancel').'" onclick="window.close();" /><br/><br/>'; 
   
           
     # wishlist-table      # wishlist-table
Line 1711  sub makeErrorPage { Line 1857  sub makeErrorPage {
     return $page;      return $page;
 }  }
   
 # ----------------------------------------------------- Main Handler, package lonwishlist  
 sub handler {  
     my ($r) = @_;  
     &Apache::loncommon::content_type($r,'text/html');  
     $r->send_http_header;  
   
     if (&getWishlist() ne 'error') {  
         # get wishlist entries from user-data db-file and build a tree out of these entries  
         %TreeHash = &getWishlist();  
         $root = &Tree::HashToTree();  
         @childrenRt = $root->children();  
   
         # greate a new entry  
         if ($env{'form.title'}) {  
            &newEntry($env{'form.title'}, $env{'form.path'}, $env{'form.note'});  
         }  
   
         # get unprocessed_cgi (i.e. marked entries, mode ...)   
         &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['action','mark','markedToMove','mode','newtitle','note','rat']);  
   
         # change the order of entries within a level, that means sorting the entries  
         my $changeOrder = 0;  
         if (defined $env{'form.sel'}) {  
             my @sel = &Apache::loncommon::get_env_multiple('form.sel');  
             my $indexNode;  
             my $at;  
             for (my $s=0; $s<($#sel+1); $s++) {  
                 if ($sel[$s] ne '') {  
                     $indexNode = $s;  
                     $at = $sel[$s]-1;  
                 }  
             }  
             if ($at ne '') {  
                 $changeOrder = 1;  
                 &sortEntries($indexNode,$at);  
                 &saveChanges();  
             }  
         }  
   
         # get all marked (checkboxes) entries  
         my @marked = ();  
         if (defined $env{'form.mark'}) {  
             @marked = &Apache::loncommon::get_env_multiple('form.mark');  
         }  
   
         # move entries from one folder to another  
         if (defined $env{'form.markedToMove'}) {  
            my $markedToMove = $env{'form.markedToMove'};  
            my @ToMove = split(/\,/,$markedToMove);  
            my $moveTo = $env{'form.mark'};  
            if (defined $moveTo){   
                &moveEntries(\@ToMove,$moveTo);  
                &saveChanges();  
            }  
            $changeOrder = 1;  
       
         }  
   
         # delete entries  
         if ($env{'form.action'} eq 'delete') {  
             &deleteEntries(\@marked);  
         }  
      
   
         # get all titles and notes and save them  
         # only save, if user wants to save changes  
         # do not save, when current action is 'delete' or 'sort' or 'move'   
         my @newTitles = ();  
         my @newPaths = ();  
         my @newNotes = ();  
         if ((defined $env{'form.newtitle'} || defined $env{'form.newpath'} || defined $env{'form.newnote'})  
             && ($env{'form.action'} ne 'noSave') && ($env{'form.action'} ne 'delete') && !$changeOrder) {  
             @newTitles = &Apache::loncommon::get_env_multiple('form.newtitle');  
             @newPaths = &Apache::loncommon::get_env_multiple('form.newpath');  
             @newNotes = &Apache::loncommon::get_env_multiple('form.newnote');  
             my $node = 0;  
             foreach my $t (@newTitles) {  
                &setNewTitle($node, $t);  
                $node++;  
             }  
             $node = 0;  
             my $path = 0;  
             for (my $i = 0; $i < ($#newTitles+1); $i++ ) {  
                if (&setNewPath($node, $newPaths[$path])) {  
                      $path++;  
                }  
                $node++;  
             }  
             $node = 0;  
             foreach my $n (@newNotes) {  
                &setNewNote($node, $n);  
                $node++;  
             }  
             &saveChanges();  
         }  
   
         # Create HTML-markup  
         my $page;  
         if ($env{'form.mode'} eq 'edit') {  
             $page = &makePage("edit");  
         }  
         elsif ($env{'form.mode'} eq 'move') {  
             $page = &makePage("move", \@marked);  
         }  
         elsif ($env{'form.mode'} eq 'import') {  
             $page = &makePageImport($env{'form.rat'});  
         }  
         elsif ($env{'form.mode'} eq 'set') {  
             $page = &makePageSet();  
         }  
         else {  
             $page = &makePage("view");  
         }  
         @marked = ();  
         $r->print($page);  
     }  
     # An error occured, print an error-page  
     else {  
         my $errorPage = &makeErrorPage();  
         $r->print($errorPage);  
     }  
     return OK;  
 }  
   
 # ----------------------------------------------------- package Tree  # ----------------------------------------------------- package Tree
 # Extend CPAN-Module Tree by function like 'moveNode' or 'deleteNode'  # Extend CPAN-Module Tree by function like 'moveNode' or 'deleteNode'
 package Tree;  package Apache::Tree;
   
 =pod  =pod
   
Line 1904  sub getNodeByIndex { Line 1927  sub getNodeByIndex {
     my $nodes = shift;      my $nodes = shift;
     my $found;      my $found;
           
     for my $n (@$nodes) {      foreach my $n (@$nodes) {
         my $curIndex = $n->value()->nindex();          my $curIndex = $n->value()->nindex();
         if ($n->value()->nindex() == $index) {          if ($curIndex == $index) {
             $found = $n;              $found = $n;
         }          }
     }      }
Line 2020  sub TreeToHash { Line 2043  sub TreeToHash {
 # build a tree-object for each entry in the hash  # build a tree-object for each entry in the hash
 # afterwards call &buildTree to connect the tree-objects  # afterwards call &buildTree to connect the tree-objects
 sub HashToTree {  sub HashToTree {
       my $TreeHash = shift;
     my @TreeNodes = ();      my @TreeNodes = ();
     my $root;      my $root;
   
     foreach my $key (keys %TreeHash) {      foreach my $key (keys %$TreeHash) {
         if ($key eq 'root') {          if ($key eq 'root') {
             $root = Tree->new("root");              $root = Tree->new("root");
         }          }
         elsif ($key ne 'folders') {          elsif ($key ne 'folders') {
         my @attributes = @{ $TreeHash{$key} };          my @attributes = @{ $$TreeHash{$key} };
         my $tmpNode;          my $tmpNode;
             $tmpNode = Tree->new(Entry->new(title=>$attributes[0],              $tmpNode = Tree->new(Entry->new(title=>$attributes[0],
                                             path=>$attributes[1],                                              path=>$attributes[1],
Line 2042  sub HashToTree { Line 2066  sub HashToTree {
         shift(@attributes);          shift(@attributes);
         shift(@attributes);          shift(@attributes);
         shift(@attributes);          shift(@attributes);
         $TreeHash{$key} = [ @attributes ];          $$TreeHash{$key} = [ @attributes ];
         }          }
     }      }
     # if there are nodes, build up the tree-structure      # if there are nodes, build up the tree-structure
     if (defined $TreeHash{'root'} && $TreeHash{'root'} ne '') {      if (defined $$TreeHash{'root'} && $$TreeHash{'root'} ne '') {
         my @childrenRtIn = @{ $TreeHash{'root'} };          my @childrenRtIn = @{ $$TreeHash{'root'} };
         &buildTree(\$root, \@childrenRtIn,\@TreeNodes,\%TreeHash);          &buildTree(\$root, \@childrenRtIn,\@TreeNodes,$TreeHash);
     }      }
     return $root;       return $root; 
 }  }

Removed from v.1.8  
changed lines
  Added in v.1.11


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