Diff for /loncom/interface/loncommon.pm between versions 1.662 and 1.663

version 1.662, 2008/06/24 16:44:22 version 1.663, 2008/06/30 03:56:27
Line 8272  domain - to an array.  Also generates ja Line 8272  domain - to an array.  Also generates ja
 generate Domain Coordinator interface for editing Course Categories.  generate Domain Coordinator interface for editing Course Categories.
   
 Inputs:  Inputs:
   
 categories (reference to hash of category definitions).  categories (reference to hash of category definitions).
   
 cats (reference to array of arrays/hashes which encapsulates hierarchy of  cats (reference to array of arrays/hashes which encapsulates hierarchy of
       categories and subcategories).        categories and subcategories).
   
 idx (reference to hash of counters used in Domain Coordinator interface for   idx (reference to hash of counters used in Domain Coordinator interface for 
       editing Course Categories).        editing Course Categories).
   
 jsarray (reference to array of categories used to create Javascript arrays for  jsarray (reference to array of categories used to create Javascript arrays for
          Domain Coordinator interface for editing Course Categories).           Domain Coordinator interface for editing Course Categories).
   
Line 8319  sub gather_categories { Line 8323  sub gather_categories {
 Used to generate breadcrumb trails for course categories.  Used to generate breadcrumb trails for course categories.
   
 Inputs:  Inputs:
   
 categories (reference to hash of category definitions).  categories (reference to hash of category definitions).
   
 cats (reference to array of arrays/hashes which encapsulates hierarchy of  cats (reference to array of arrays/hashes which encapsulates hierarchy of
       categories and subcategories).        categories and subcategories).
   
 trails (reference to array of breacrumb trails for each category).  trails (reference to array of breacrumb trails for each category).
   
 allitems (reference to hash - key is category key   allitems (reference to hash - key is category key 
          (format: escaped(name):escaped(parent category):depth in hierarchy).           (format: escaped(name):escaped(parent category):depth in hierarchy).
   
 idx (reference to hash of counters used in Domain Coordinator interface for  idx (reference to hash of counters used in Domain Coordinator interface for
       editing Course Categories).        editing Course Categories).
   
 jsarray (reference to array of categories used to create Javascript arrays for  jsarray (reference to array of categories used to create Javascript arrays for
          Domain Coordinator interface for editing Course Categories).           Domain Coordinator interface for editing Course Categories).
   
Line 8374  sub extract_categories { Line 8384  sub extract_categories {
 Recursively used to generate breadcrumb trails for course categories.  Recursively used to generate breadcrumb trails for course categories.
   
 Inputs:  Inputs:
   
 cats (reference to array of arrays/hashes which encapsulates hierarchy of  cats (reference to array of arrays/hashes which encapsulates hierarchy of
       categories and subcategories).        categories and subcategories).
   
 depth (current depth in hierarchy of categories and sub-categories - 0 indexed).  depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
 category (current course category, for which breadcrumb trail is being generated).     
 trails (reference to array of breacrumb trails for each category).  category (current course category, for which breadcrumb trail is being generated).
   
   trails (reference to array of breadcrumb trails for each category).
   
 allitems (reference to hash - key is category key  allitems (reference to hash - key is category key
          (format: escaped(name):escaped(parent category):depth in hierarchy).           (format: escaped(name):escaped(parent category):depth in hierarchy).
   
 parents (array containing containers directories for current category,   parents (array containing containers directories for current category, 
          back to top level).            back to top level). 
   
Line 8388  Returns: nothing Line 8404  Returns: nothing
   
 Side effects: populates trails and allitems hash references  Side effects: populates trails and allitems hash references
   
 =back  
   
 =cut  =cut
   
 sub recurse_categories {  sub recurse_categories {
Line 8420  sub recurse_categories { Line 8434  sub recurse_categories {
     return;      return;
 }  }
   
   =pod
   
   =item *&assign_categories_table()
   
   Create a datatable for display of hierarchical categories in a domain,
   with checkboxes to allow a course to be categorized. 
   
   Inputs:
   
   cathash - reference to hash of categories defined for the domain (from
             configuration.db)
   
   currcat - scalar with an & separated list of categories assigned to a course. 
   
   Returns: $output (markup to be displayed) 
   
   =cut
   
   sub assign_categories_table {
       my ($cathash,$currcat) = @_;
       my $output;
       if (ref($cathash) eq 'HASH') {
           my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
           &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
           $maxdepth = scalar(@cats);
           if (@cats > 0) {
               my $itemcount = 0;
               if (ref($cats[0]) eq 'ARRAY') {
                   $output = &Apache::loncommon::start_data_table();
                   my @currcategories;
                   if ($currcat ne '') {
                       @currcategories = split('&',$currcat);
                   }
                   for (my $i=0; $i<@{$cats[0]}; $i++) {
                       my $parent = $cats[0][$i];
                       my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                       next if ($parent eq 'instcode');
                       my $item = &escape($parent).'::0';
                       my $checked = '';
                       if (@currcategories > 0) {
                           if (grep(/^\Q$item\E$/,@currcategories)) {
                               $checked = ' checked="checked" ';
                           }
                       }
                       $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                                  .'<input type="checkbox" name="usecategory" value="'.
                                  $item.'"'.$checked.' />'.&escape($parent).'</span></td>';
                       my $depth = 1;
                       push(@path,$parent);
                       $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
                       pop(@path);
                       $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                       $itemcount ++;
                   }
                   $output .= &Apache::loncommon::end_data_table();
               }
           }
       }
       return $output;
   }
   
   =pod
   
   =item *&assign_category_rows()
   
   Create a datatable row for display of nested categories in a domain,
   with checkboxes to allow a course to be categorized,called recursively.
   
   Inputs:
   
   itemcount - track row number for alternating colors
   
   cats - reference to array of arrays/hashes which encapsulates hierarchy of
         categories and subcategories.
   
   depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
   
   parent - parent of current category item
   
   path - Array containing all categories back up through the hierarchy from the
          current category to the top level.
   
   currcategories - reference to array of current categories assigned to the course
   
   Returns: $output (markup to be displayed).
   
   =cut
   
   sub assign_category_rows {
       my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
       my ($text,$name,$item,$chgstr);
       if (ref($cats) eq 'ARRAY') {
           my $maxdepth = scalar(@{$cats});
           if (ref($cats->[$depth]) eq 'HASH') {
               if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   my $numchildren = @{$cats->[$depth]{$parent}};
                   my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   $text .= '<td><table class="LC_datatable">';
                   for (my $j=0; $j<$numchildren; $j++) {
                       $name = $cats->[$depth]{$parent}[$j];
                       $item = &escape($name).':'.&escape($parent).':'.$depth;
                       my $deeper = $depth+1;
                       my $checked = '';
                       if (ref($currcategories) eq 'ARRAY') {
                           if (@{$currcategories} > 0) {
                               if (grep(/^\Q$item\E$/,@{$currcategories})) {
                                   $checked = ' checked="checked" ';
                               }
                           }
                       }
                       $text .= '<tr><td><label><input type="checkbox" name="usecategory" value="'
                                .$item.'"'.$checked.' />'.$name.'</label></span></td><td>';
                       if (ref($path) eq 'ARRAY') {
                           push(@{$path},$name);
                           $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
                           pop(@{$path});
                       }
                       $text .= '</td></tr>';
                   }
                   $text .= '</table></td>';
               }
           }
       }
       return $text;
   }
   
 ############################################################  ############################################################
 ############################################################  ############################################################
   

Removed from v.1.662  
changed lines
  Added in v.1.663


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