File:  [LON-CAPA] / loncom / interface / lonpickauthor.pm
Revision 1.7: download - view: text, annotated - select for diffs
Wed Mar 15 20:18:06 2017 UTC (7 years, 9 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_12_X, version_2_11_X, version_2_11_5_msu, version_2_11_5, version_2_11_4_uiuc, version_2_11_4_msu, version_2_11_4, 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, HEAD
- lonroles::check_for_adhoc() expects four args.

# The LearningOnline Network with CAPA
# Display authors in domain for selection of ad loc co-author role by Domain Coordinator. 
#
# $Id: lonpickauthor.pm,v 1.7 2017/03/15 20:18:06 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::lonpickauthor;

use strict;
use Apache::Constants qw(:common);
use Apache::loncommon;
use Apache::lonnet;
use Apache::lonlocal;
use Apache::lonroles;
use Apache::lonuserutils;
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
    $r->print(&Apache::loncommon::start_page("Selecting an Author",undef,
                                             {'no_nav_bar' => 1}));


    &Apache::loncommon::get_unprocessed_cgi
        ($ENV{'QUERY_STRING'},['form','roledom','sortby']);
    my $then=$env{'user.login.time'};
    my $update=$env{'user.update.time'};
    if (!$update) {
        $update = $then;
    }
    my (%dcroles,%helpdeskroles,%dom_roles,$earlyout,$domdesc);
    my ($numdc) = &Apache::lonroles::check_for_adhoc(\%dcroles,\%helpdeskroles,$update,$then);
    if ($env{'form.roledom'} ne '') {
        $domdesc = &Apache::lonnet::domain($env{'form.roledom'});
        if ($domdesc eq '') {
            $earlyout = $earlyout = &mt('Invalid domain'); 
        } elsif ($numdc) {
            if ($dcroles{$env{'form.roledom'}}) {
                %dom_roles = &Apache::lonnet::get_domain_roles($env{'form.roledom'},['au']);
                if (keys(%dom_roles) == 0) {
                    $earlyout = &mt('There are no library servers containing Authoring Spaces currently in domain: [_1], so you can not assume a co-author role.',$domdesc); 
                }
            } else {
                $earlyout = &mt('You do not have a domain coordinator role in domain: [_1], so you cannot choose an Authoring Space for which you can assume a co-author role.',$domdesc);
            }
        } else {
            $earlyout = &mt('You do not have a domain coordinator role, so you cannot choose an Authoring Space for which you can assume a co-author role.');
        }
    } else {
        $earlyout = &mt('Invalid domain'); 
    }
    if ($earlyout) {
        $r->print('<span class="LC_error">'.$earlyout.'</span>');
        $r->print(&Apache::loncommon::end_page());
        return OK;
    }
    $r->print(<<ENDSCRIPT);
<script type="text/javascript">
function username_display_launch(username,domain) {
    document.location.href = '/adm/'+domain+'/'+username+'/aboutme';
    return;
}

function gochoose(uname) {
    var coauthorTarget = "ca./$env{'form.roledom'}/"+uname;
    opener.document.title='Role selected. Please stand by.';
    opener.status='Role selected. Please stand by.';
    opener.document.$env{'form.form'}.newrole.value=coauthorTarget
    opener.document.$env{'form.form'}.submit();
    self.close();
}
</script>
ENDSCRIPT
    my $formname = 'pickauthor';
    my $caller = 'pickauthor';
    my $context = 'domain';
    my $format = 'html';
    my (%userlist,%userinfo);
    my ($indexhash,$keylist) = &Apache::lonuserutils::make_keylist_array();
    my ($permission,$allowed) = &Apache::lonuserutils::get_permission($context);
    $env{'form.roletype'} = 'domain';
    $env{'form.showrole'} = 'au';
    foreach my $key (keys(%dom_roles)) {
        if (ref($dom_roles{$key}) eq 'HASH') {
            &Apache::lonuserutils::gather_userinfo($context,$format,\%userlist,$indexhash,
                                                  \%userinfo,$dom_roles{$key},$permission);
        }
    }
    if (keys(%userlist) > 0) {
        $r->print('<form name="'.$formname.'" action="/adm/pickauthor">');
        &Apache::lonuserutils::show_users_list($r,$context,$caller,$permission,
                                               'Any',\%userlist,$keylist,$formname);
        $r->print('<input type="hidden" name="roledom" value="'.$env{'form.roledom'}.'" />'."\n".
                  '<input type="hidden" name="form" value="'.$env{'form.form'}.'" /></form>');
    } else {
       $r->print(&mt('There are no author roles currently in domain: [_1], so there are no Authoring Spaces for which you can assume a co-author role.',$domdesc));
    }
    $r->print(&Apache::loncommon::end_page());
    return OK;
}

1;

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