File:  [LON-CAPA] / loncom / interface / lonpickcourse.pm
Revision 1.54: download - view: text, annotated - select for diffs
Sun Nov 5 20:59:17 2006 UTC (17 years, 6 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Start on subdividing monolithic handler() into subroutines.  When pickcourse is called from portfolio form (to choose a course to set conditional course-based access controls) now only courses in which user has an active role are offered as choices, if user does not have $env{'user.adv'} = 1.

# The LearningOnline Network
# Pick a course
#
# $Id: lonpickcourse.pm,v 1.54 2006/11/05 20:59:17 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#

package Apache::lonpickcourse;

use strict;
use Apache::Constants qw(:common);
use Apache::loncommon;
use Apache::loncoursedata;
use Apache::lonnet;
use Apache::lonlocal;
use Apache::longroup;
use lib '/home/httpd/lib/perl/';
use LONCAPA;

sub handler {
    my $r = shift;
    &Apache::loncommon::content_type($r,'text/html');
    $r->send_http_header;
    return OK if $r->header_only;

# ------------------------------------------------------------ Print the screen

# Get parameters from query string
    &Apache::loncommon::get_unprocessed_cgi
        ($ENV{'QUERY_STRING'},['domainfilter','descriptfilter',
			       'sincefilter','form','cnumelement',
			       'cdomelement','cnameelement','roleelement',
                               'pickedcourse','instcodefilter',
                               'ownerfilter','coursefilter','multiple',
                               'type','ownerdomfilter']);

    my ($type,$title,$jscript,$multelement,$multiple,$name_code,$name_input,
        $roleelement);
    $type = $env{'form.type'};
    if (!defined($env{'form.type'})) {
        $type = 'Course';
    }
    $title = &mt('Selecting a [_1]',$type);

    # Setup for multiple course selections, if flag for multiples set.
    ($title,$jscript,$multelement,$multiple) = &multiples_tag($type,$title);

    if (defined($env{'form.cnameelement'}) && $env{'form.cnameelement'} ne '') {
        $name_code = "opener.document.$env{'form.form'}.$env{'form.cnameelement'}.".
                     "value=cdesc;";
        $name_input ='<input type="hidden" name="cnameelement" value="'.
                     $env{'form.cnameelement'}.'" />';
    }

    my $submitopener = '';
    my $autosubmit = '';
    my $lastaction = 'self.close()';
    if ($env{'form.form'} eq 'cu') {
        $lastaction = 'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n".
                      'document.courselist.submit();';
    }
    if ($env{'form.form'} eq 'portform') {
        $lastaction = 'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n".
                      'document.courselist.submit();';
    }
    my $roledom = $env{'form.roleelement'};
    if ($roledom) {
        $roleelement = '<input type="hidden" name="roleelement" value="'.$roledom.'" />';
        $submitopener = &Apache::lonroles::processpick();
        $autosubmit = 'process_pick("'.$roledom.'")';
    }

    my (%filter,%list);
    my $filterdisplay;
    my $onlyown = 0;
    if ((($env{'form.form'} eq 'portform') && ($env{'user.adv'}))) {
        $onlyown = 1;
    } else {   
        $filterdisplay = &build_filters($type,$name_input,$roleelement,
                                        $multelement, \%filter,\%list);
    }
# if called from loncreateuser, report sections, then close
    my (%loaditem,$seclist,$groupslist,$roleslist,$rolesnameslist,
	$accesslist,$accessnameslist);
    my $sec_element = 'currsec';
    my $grplist_element = 'groups';
    my $num_sections = 0;
    my $num_groups = 0;
    my $num_roles = 0;
    my $num_access = 0;
    my ($cdom,$cnum);
    if ($env{'form.pickedcourse'}) {
        ($cdom,$cnum) = split/_/,$env{'form.pickedcourse'};
    }
    if ($env{'form.form'} eq 'cu' && $env{'form.pickedcourse'}) {
        $loaditem{'onload'} ="setSections()";
        ($seclist,$num_sections,$groupslist,$num_groups) = 
             &build_selection_lists($cdom,$cnum,$type,undef,undef,
                                    $env{'form.form'});
    }
# if called from portfolio, report roles, sections, groups and close
    my ($roles_element,$groups_element,$status_element,$setitems_function);
    if ($env{'form.form'} eq 'portform' && $env{'form.pickedcourse'}) {
        $loaditem{'onload'} ="setItems()";
        ($seclist,$num_sections,$groupslist,$num_groups,$roleslist,$num_roles,
         $rolesnameslist,$accesslist,$num_access,$accessnameslist) =
            &build_selection_lists($cdom,$cnum,$type,1,1,$env{'form.form'});
        ($sec_element,$grplist_element,$setitems_function) = 
            &setitems_javascript($seclist,$num_sections,$groupslist,$num_groups,
                                 $roleslist,$num_roles,$rolesnameslist,
                                 $accesslist,$num_access,$accessnameslist);
    }
    $r->print(&Apache::loncommon::start_page($title,undef,
					     {'add_entries' => \%loaditem,
					      'no_nav_bar'  => 1, }));
    my %elements = (
                     'Course' => {
                                 name  => 'coursepick',
                                 total => 'coursetotal',
                                 list  => 'courselist',
                               },
                     'Non-standard course' => {
                                 name  => 'grouppick',
                                 total => 'grouptotal',
                                 list  => 'grouplist',
                             },
                    );
    my $setsec_func = &setsec_javascript($seclist,$sec_element,$grplist_element,
                                         $groupslist,$num_sections);
    $r->print(<<ENDSCRIPT);
<script>
function gochoose(cname,cdom,cdesc,multiple,caller) {
    var openerForm = "$env{'form.form'}";
    courseCount = 0;
    var courses = '';
    if (multiple) {
	if (typeof(document.courselist.course_id.length) == 'undefined') {
	    // only 1 course checkbox was created
	    if (document.courselist.course_id.checked) {
		courses = courses + document.courselist.course_id.value + "&&";
		courseCount ++;
	    }
	} else {
	    for (var j=0; j<document.courselist.course_id.length; j++) {
		if (document.courselist.course_id[j].checked) {
		    courses = courses + document.courselist.course_id[j].value + "&&";
		    courseCount ++;
		}
	    }
	} 
        opener.document.$env{'form.form'}.$elements{$type}{'total'}.value = courseCount;
	if (typeof(opener.document.$env{'form.form'}.$elements{$type}{'name'}.length) ==
	    'undefined') {
	    if (opener.document.$env{'form.form'}.$elements{$type}{'name'}.value == 'specific') {  
		opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = true;
	    } else {
		opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = false;
	    }
	} else {
	    for (var j=0; j<opener.document.$env{'form.form'}.$elements{$type}{'name'}.length; j++) { 
		if (opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].value == 'specific') {  
		    opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = true;
		} else {
		    opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = false;
		}
	    }
	}
	if (courseCount > 0) {
	    courses = courses.substr(0,courses.length-2);
	    opener.document.$env{'form.form'}.$elements{$type}{'list'}.value = courses;
	}
    } else {
        $name_code
        opener.document.$env{'form.form'}.$env{'form.cnumelement'}.value=cname;
        var slct=opener.document.$env{'form.form'}.$env{'form.cdomelement'};
        if (slct.options == undefined) {
            opener.document.$env{'form.form'}.$env{'form.cdomelement'}.value=cdom;
        }
        else {
            var i;
            for (i=0;i<slct.length;i++) {
                if (slct.options[i].value==cdom) { slct.selectedIndex=i; }
            }
        }
    }
    $autosubmit
    $lastaction
}

$setsec_func

$setitems_function

$jscript
</script>
$submitopener
ENDSCRIPT
    $r->print($filterdisplay);

# ---------------------------------------------------------------- Get the data
    if ($env{'form.gosearch'} || $onlyown) {
        my %courses = &search_courses($r,$type,$onlyown,\%filter);
        &display_matched_courses($r,$type,$multiple,%courses);
    }
    $r->print(&Apache::loncommon::end_page());
    return OK;
}

sub display_matched_courses {
    my ($r,$type,$multiple,%courses) = @_;
    $r->print('<form name="courselist" method="post" action="/adm/pickcourse">');
    my %by_descrip;
    my $numcourses = keys(%courses);
    foreach my $course (keys(%courses)) {
        my $descr;
        if ($courses{$course} =~ m/^([^:]*):/i) {
            $descr = &unescape($1);
        } else {
            $descr = &unescape($courses{$course});
        }
        my $description = $descr;
        push (@{$by_descrip{$description}}, $course);
    }
    if ($numcourses > 1 && $multiple) {
        $r->print('<input type="button" value="check all"
                  onclick="javascript:checkAll(document.courselist.course_id)" />
                  &nbsp;&nbsp;<input type="button" value="uncheck all"
                  onclick="javascript:uncheckAll(document.courselist.course_id)" />
                  <br /><br />');
    }
    foreach my $description (sort { lc($a) cmp lc($b) } (keys(%by_descrip))) {
        foreach my $course (@{$by_descrip{$description}}) {
            my $cleandesc=&HTML::Entities::encode($description,'<>&"');
            $cleandesc=~s/'/\\'/g;
            my ($cdom,$cnum)=split(/\_/,$course);
            my ($descr,$instcode,$owner,$ttype) = split/:/,$courses{$course};
            $r->print(&course_chooser($multiple,$cdom,$cnum,$cleandesc));
            $r->print($description.'('.
                      ($Apache::lonnet::domaindescription{$cdom}?
                       $Apache::lonnet::domaindescription{$cdom}:$cdom).")");
            unless ($instcode eq '') {
                $r->print(" - ".&unescape($instcode));
            }
            unless ($owner eq '') {
                $r->print(", owner - ".&unescape($owner));
            }
            unless ($ttype eq '') {
                $r->print('('.&Apache::lonnet::unescape($ttype).')');
            }
            if ($multiple) { $r->print("</label>\n"); }
            $r->print("<br />\n");
        }
    }
    if (!%courses) {
        $r->print(&mt('None found'));
    } elsif ($multiple) {
        $r->print('<input type="button" value="Submit" onClick="gochoose('."'','','',1)".'" />');
    }
    $r->print('<input type="hidden" name="form" value="'.$env{'form.form'}.'" />'.
              "\n".'<input type="hidden" name="pickedcourse" value="" />'."\n".
              '<input type="hidden" name="cnumelement" value="'.$env{'form.cnumelement'}.'" />'."\n".
              '<input type="hidden" name="cdomelement" value="'.$env{'form.cdomelement'}.'" />'."\n".
              '<input type="hidden" name="type" value="'.$type.'" />'."\n");
    if ((exists($env{'form.roleelement'})) && ($env{'form.form'} eq 'rolechoice')) {
        $r->print('<input type="hidden" name="roleelement" value="'.
                  $env{'form.roleelement'}.'" />'."\n");
    }
    $r->print("</form>\n");
    return;
}


sub multiples_tag {
    my ($type,$title) = @_;
    my ($jscript,$multelement,$multiple);
    $multiple = $env{'form.multiple'};
    if ($multiple) {
        $title = &mt('Selecting [_1](s)',lc($type));
        $jscript = &Apache::loncommon::check_uncheck_jscript();
        $multelement = '<input type="hidden" name="multiple" value="'.$multiple.'" />';
    }
    return ($title,$jscript,$multelement,$multiple);
}

sub build_filters {
    my ($type,$name_input,$roleelement,$multelement,$filter,$list) = @_;
    my @filters = ('domainfilter','descriptfilter','instcodefilter','ownerfilter','ownerdomfilter');
    # course ID filter for DCs only
    my ($courseidtag,$domainselectform,$sincefilterform,$ownerdomselectform,
        $instcodeform,$typeselectform);
    if ($env{'user.adv'} && $env{'form.domainfilter'} &&
        exists($env{'user.role.dc./'.$env{'form.domainfilter'}})) {
        push(@filters,'coursefilter');
        $courseidtag=&mt('LON-CAPA course ID').
                     '<input type="text" name="coursefilter" size="25" value="'.                     $list->{'coursefilter'}.'" /><br />';
    }
    foreach my $item (@filters) {
        $filter->{$item} = $env{'form.'.$item};
        if ($item ne 'descriptfilter' && $item ne 'instcodefilter') {
            $filter->{$item} =~ s/\W//g;
            if (!$filter->{$item}) {
                $filter->{$item} = '';
            }
        }
        if ($item eq 'domainfilter') {
            $domainselectform =
     &Apache::loncommon::select_dom_form($filter->{$item},'domainfilter',1);
        } elsif ($item eq 'ownerdomfilter') {
            $ownerdomselectform =
     &Apache::loncommon::select_dom_form($filter->{$item},'ownerdomfilter',1);
        } else {
            $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
        }
    }

    # last course activity filter and selection
    $filter->{'sincefilter'} = $env{'form.sincefilter'};
    $filter->{'sincefilter'} =~ s/[^\d-]//g;
    if (!$filter->{'sincefilter'}) { $filter->{'sincefilter'}=-1; }
    $sincefilterform=&Apache::loncommon::select_form($filter->{'sincefilter'},
       'sincefilter',('-1'=>'',
                      '86400' => 'today',
                      '604800' => 'last week',
                      '2592000' => 'last month',
                      '7776000' => 'last three months',
                      '15552000' => 'last six months',
                      '31104000' => 'last year',
                      'select_form_order' =>
                      ['-1','86400','604800','2592000','7776000',
                      '15552000','31104000']));

    my %lt = (
              'cac' => &mt('[_1] Activity',$type),
              'cde' => &mt('[_1] Description',$type),
              'cdo' => &mt('[_1] Domain',$type),
              'cin' => &mt('Course Institutional Code'),
              'cow' => &mt("[_1] Owner's Username",$type),
              'cod' => &mt("[_1] Owner's Domain", $type),
              'cog' => &mt('Course Type')
             );

    $typeselectform =  '<select name="type" size="1"';
    $typeselectform .= ">\n";
    if ($type eq 'Course') {
        $instcodeform = $lt{'cin'}.': <input type="text" name="instcodefilter"
 size="10" value="'.$list->{'instcodefilter'}.'" /><br />';
    }
    foreach my $posstype ('Course','Non-standard course') {
        $typeselectform.='<option value="'.$posstype.'" "'.
            ($posstype eq $type ? 'selected="selected" ' : ''). ">$posstype</option>\n";
    }
    $typeselectform.="</select>";
    my $output = <<"END";
<form method="post" name="filterpicker" action="/adm/pickcourse">
<input type="hidden" name="cnumelement" value="$env{'form.cnumelement'}" />
<input type="hidden" name="cdomelement" value="$env{'form.cdomelement'}" />
$name_input
<input type="hidden" name="form" value="$env{'form.form'}" />
$roleelement
$multelement
$lt{'cac'}: $sincefilterform
<br />
$lt{'cdo'}: $domainselectform
<br />
$lt{'cog'}: $typeselectform
<br />
$instcodeform
$lt{'cow'}:
<input type="text" name="ownerfilter" size="10" value="$list->{'ownerfilter'}" />
<br />
$lt{'cod'}: $ownerdomselectform
<br />
$courseidtag
$lt{'cde'}:
<input type="text" name="descriptfilter" size="40" value="$list->{'descriptfilter'}" />
<p><input type="submit" name="gosearch" value="Search" /></p>
</form>
<hr />
END
    return $output; 
}

sub search_courses {
    my ($r,$type,$onlyown,$filter) = @_;
    my %courses;
    if (!$onlyown) {
        $r->print(&mt('Searching').' ...<br />&nbsp;<br />');
        $r->rflush();
        if (($filter->{'ownerfilter'} ne '') ||
            ($filter->{'ownerdomfilter'} ne '')) {
            $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
                                           $filter->{'ownerdomfilter'};
        }
        foreach my $item ('descriptfilter','instcodefilter','coursefilter',
                          'combownerfilter') {
            if (!$filter->{$item}) {
                $filter->{$item}='.';
            }
        }
        if ($type eq '') { $type = '.'; }
        my $timefilter = 
           ($filter->{'sincefilter'}==-1?1:time-$filter->{'sincefilter'});
        %courses = 
            &Apache::lonnet::courseiddump($filter->{'domainfilter'},
                                          $filter->{'descriptfilter'},
                                          $timefilter,
                                          $filter->{'instcodefilter'},
                                          $filter->{'combownerfilter'},
                                          $filter->{'coursefilter'},
                                          undef,undef,$type);
    } else {
        $r->print('<br />');
        foreach my $cid (sort(&Apache::loncommon::findallcourses())) {
            $courses{$cid} = $env{'course.'.$cid.'.description'};
        }
    }
    return %courses;
}

sub course_chooser {
    my ($multiple,$cdom,$cnum,$cleandesc) = @_;
    my $output; 
    if ($multiple) {
        $output = '<label><input type="checkbox" name="course_id" value="'.$cdom.'_'.$cnum.'" />'."\n";
    } else {
        $output = '<input type="button" value="Select" onClick="gochoose('.
                  "'".$cnum."','".$cdom."','".$cleandesc."')".'" />'."\n";
    }
    return $output;
}

sub setsec_javascript {
    my ($seclist,$sec_element,$grplist_element,$groupslist,$num_sections) = @_;
    my $sectsections = qq|
function setSections() {
    var numSections = $num_sections
    var sectionsArray = new Array("$seclist")
    opener.document.$env{"form.form"}.$sec_element.length = 0
    if (numSections == 0) {
        opener.document.$env{"form.form"}.$sec_element.multiple=false
        opener.document.$env{"form.form"}.$sec_element.size=1;
        opener.document.$env{"form.form"}.$sec_element.options[0] = new Option('No existing sections','',false,false)
    } else {
        if (numSections == 1) {
            opener.document.$env{"form.form"}.$sec_element.multiple=false;
            opener.document.$env{"form.form"}.$sec_element.size=1;
            opener.document.$env{"form.form"}.$sec_element.options[0] = new Option('Select','',true,true);
            opener.document.$env{"form.form"}.$sec_element.options[1] = new Option('No section','',false,false)
            opener.document.$env{"form.form"}.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
        } else {
            for (var i=0; i<numSections; i++) {
                opener.document.$env{"form.form"}.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
            }
            opener.document.$env{"form.form"}.$sec_element.multiple=true
            if (numSections < 3) {
                opener.document.$env{"form.form"}.$sec_element.size=numSections;            } else {
                opener.document.$env{"form.form"}.$sec_element.size=3;
            }
            opener.document.$env{"form.form"}.$sec_element.options[0].selected = false
        }
    }
    opener.document.$env{"form.form"}.$grplist_element.value='$groupslist';
    self.close()
}
|;
}

sub setitems_javascript {
    my ($seclist,$num_sections,$groupslist,$num_groups,$roleslist,$num_roles,
        $rolesnameslist,$accesslist,$num_access,$accessnameslist) = @_;
    my ($row_id) = ($env{'form.cnumelement'} =~ /^crsnum_(\d+)$/);
    my $roles_element = 'role_'.$row_id.'_1';
    my $groups_element = 'group_'.$row_id.'_1';
    my $sec_element = 'section_'.$row_id.'_1';
    my $status_element = 'access_'.$row_id.'_1';
    my $grplist_element = 'grplist_'.$row_id.'_1';
    my $setitems_function = qq|
function setItems() {
    opener.document.$env{"form.form"}.activate.checked = true;
    setRoles();
    setGroups();
    setStatus();
    setSections();
}

function setRoles() {
    var numRoles = $num_roles
    var rolesArray = new Array("$roleslist");
    var roleNamesArray = new Array("$rolesnameslist");
    opener.document.$env{"form.form"}.$roles_element.length = 0;
    if (numRoles == 0) {
        opener.document.$env{"form.form"}.$roles_element.multiple=false;
        opener.document.$env{"form.form"}.$roles_element.size=1;
        opener.document.$env{"form.form"}.$roles_element.options[0] = new Option('No existing roles','',false,false);
    } else {
        if (numRoles == 1) {
            opener.document.$env{"form.form"}.$roles_element.multiple=false;
            opener.document.$env{"form.form"}.$roles_element.size=1;
            opener.document.$env{"form.form"}.$roles_element.options[0] = new Option('Select','',true,true);
            opener.document.$env{"form.form"}.$roles_element.options[1] = new Option(roleNamesArray[0],rolesArray[0],false,false);
        } else {
            for (var i=0; i<numRoles; i++) {
                opener.document.$env{"form.form"}.$roles_element.options[i] = new Option(roleNamesArray[i],rolesArray[i],false,false);
            }
            opener.document.$env{"form.form"}.$roles_element.multiple=true;
            if (numRoles < 3) {
                opener.document.$env{"form.form"}.$roles_element.size=numRoles;
            } else {
                opener.document.$env{"form.form"}.$roles_element.size=3;
            }
            opener.document.$env{"form.form"}.$roles_element.options[0].selected = false;
        }
    }
}

function setStatus() {
    var numStatus = $num_access;
    var statusArray = new Array("$accesslist");
    var statusNamesArray = new Array("$accessnameslist");
    opener.document.$env{"form.form"}.$status_element.multiple=true;
    opener.document.$env{"form.form"}.$status_element.size=3;
    for (var i=0; i<numStatus; i++) {
        opener.document.$env{"form.form"}.$status_element.options[i] = new Option(statusNamesArray[i],statusArray[i],false,false);
    }
}

function setGroups() {
    var numGroups = $num_groups;
    var groupsArray = new Array("$groupslist");
    opener.document.$env{"form.form"}.$groups_element.length = 0;
    if (numGroups == 0) {
        opener.document.$env{"form.form"}.$groups_element.multiple=false;
        opener.document.$env{"form.form"}.$groups_element.size=1;
        opener.document.$env{"form.form"}.$groups_element.options[0] = new Option('No existing groups','',false,false);
    } else {
        if (numGroups == 1) {
            opener.document.$env{"form.form"}.$groups_element.multiple=false;
            opener.document.$env{"form.form"}.$groups_element.size=1;
            opener.document.$env{"form.form"}.$groups_element.options[0] = new Option('Select','',true,true);
            opener.document.$env{"form.form"}.$groups_element.options[1] = new Option('No group','',false,false);
            opener.document.$env{"form.form"}.$groups_element.options[2] = new Option(groupsArray[0],groupsArray[0],false,false);
        } else {
            for (var i=0; i<numGroups; i++) {
                opener.document.$env{"form.form"}.$groups_element.options[i] = new Option(groupsArray[i],groupsArray[i],false,false);
            }
            opener.document.$env{"form.form"}.$groups_element.multiple=true;
            if (numGroups < 3) {
                opener.document.$env{"form.form"}.$groups_element.size=numGroups;
            } else {
                opener.document.$env{"form.form"}.$groups_element.size=3;
            }
            opener.document.$env{"form.form"}.$groups_element.options[0].selected = false;
        }
    }
}

|;
    return ($sec_element,$grplist_element,$setitems_function);

}

sub build_selection_lists {
    my ($cdom,$cnum,$type,$needroles,$needaccess,$caller) = @_;
    my ($sections,$groups,$allroles,$roleshash,$accesshash) = 
          &Apache::loncommon::get_secgrprole_info($cdom,$cnum,$needroles,$type);
    if ($caller eq 'portform') {
        if (@{$sections} == 0) {
            @{$sections} = ('none');
        } else {
            unshift(@{$sections},('all','none'));
        }
        if (@{$groups} == 0) {
            @{$groups} = ('none');
        } else {
            unshift(@{$groups},('all','none'));
        }

    } 
    my $num_sections = scalar(@{$sections});
    my $seclist = join('","',@{$sections});
    my $num_groups = scalar(@{$groups});
    my $groupslist = join('","',@{$groups});
    my ($roleslist,$num_roles,$rolesnameslist,$num_access,$accesslist,
        $accessnameslist);
    if ($needroles) {
        $num_roles = @{$allroles};
        $roleslist = join('","',@{$allroles});
        my @allrolesnames; 
        foreach my $role (@{$allroles}) {
            push(@allrolesnames,$$roleshash{$role});
        }  
        $rolesnameslist = join('","',@allrolesnames);
    }
    if ($needaccess) {
        $num_access = keys(%{$accesshash});
        my (@allaccess,@allaccessnames);
        foreach my $key (sort(keys(%{$accesshash}))) {
            push(@allaccess,$key);
            push(@allaccessnames,$$accesshash{$key}); 
        }
        $accesslist = join('","',@allaccess);
        $accessnameslist = join('","',@allaccessnames);
    }
    return ($seclist,$num_sections,$groupslist,$num_groups,$roleslist,
            $num_roles,$rolesnameslist,$accesslist,$num_access,$accessnameslist);
}

1;
__END__

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