@@ -1822,16 +2320,93 @@ END
}
}
+sub view_as_js {
+ my ($url,$symb) = @_;
+ my %lt = &Apache::lonlocal::texthash(
+ ente => 'Enter a username or a student/employee ID',
+ info => 'Information you entered does not match a valid course user',
+ );
+ &js_escape(\%lt);
+ return <<"END";
+
+function toggleViewAsUser(change) {
+ var seluserid = document.getElementById('LC_selectuser');
+ var currstyle = seluserid.style.display;
+ if (change == 'off') {
+ document.userview.elements['LC_viewas'].value = '';
+ document.userview.elements['vuname'].value = '';
+ document.userview.elements['vid'].value = '';
+ document.userview.submit();
+ return;
+ }
+ if (currstyle == 'inline') {
+ seluserid.style.display = 'none';
+ document.getElementById('usexpand').innerHTML='► ';
+ document.getElementById('uscollapse').innerHTML='';
+ } else {
+ seluserid.style.display = 'inline';
+ document.getElementById('usexpand').innerHTML='';
+ document.getElementById('uscollapse').innerHTML='◄ ';
+ }
+ return;
+}
+
+function validCourseUser(form,change) {
+ var possuname = form.elements['vuname'].value;
+ var possuid = form.elements['vid'].value;
+ var possudom = form.elements['vudom'].options[form.elements['vudom'].selectedIndex].value;
+ if ((possuname == '') && (possuid == '')) {
+ if (change == 'off') {
+ form.elements['LC_viewas'].value = '';
+ form.submit();
+ } else {
+ alert("$lt{'ente'}");
+ }
+ return;
+ }
+ var http = new XMLHttpRequest();
+ var url = "/adm/courseuser";
+ var params = "uname="+possuname+"&uid="+possuid+"&udom="+possudom;
+ http.open("POST", url, true);
+ http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+ http.onreadystatechange = function() {
+ if (http.readyState == 4 && http.status == 200) {
+ var data = JSON.parse(http.responseText);
+ if (Array.isArray(data.match)) {
+ var len = data.match.length;
+ if (len == 2) {
+ if (data.match[0] != '' && data.match[1] != '') {
+ form.elements['LC_viewas'].value = data.match[0]+':'+data.match[1];
+ form.submit();
+ }
+ } else {
+ alert("$lt{'info'}");
+ }
+ }
+ }
+ return;
+ }
+ http.send(params);
+ return false;
+}
+
+END
+}
+
sub utilityfunctions {
my ($httphost) = @_;
my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
- if ($currenturl =~ m{^/adm/wrapper/ext/}
- && $env{'request.external.querystring'} ) {
+ my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
+ if ($currenturl =~ m{^/adm/wrapper/ext/}) {
+ if ($env{'request.external.querystring'}) {
$currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
+ }
+ my ($anchor) = ($env{'request.symb'} =~ /(\#[^\#]+)$/);
+ if (($anchor) && ($currenturl !~ /\Q$anchor\E$/)) {
+ $currenturl .= $1;
+ }
}
$currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
-
- my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
my $dc_popup_cid;
if ($env{'user.adv'} && exists($env{'user.role.dc./'.
@@ -1855,9 +2430,40 @@ sub utilityfunctions {
my $esc_url=&escape($currenturl);
my $esc_symb=&escape($currentsymb);
+ my $newname = &mt('New Name');
my $countdown = &countdown_toggle_js();
+ my $viewuser;
+ if (($env{'request.course.id'}) &&
+ ($env{'request.symb'} ne '') &&
+ ($env{'request.filename'}=~/$LONCAPA::assess_re/)) {
+ my $canview;
+ foreach my $priv ('msg','vgr') {
+ $canview = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
+ if (!$canview && $env{'request.course.sec'} ne '') {
+ $canview =
+ &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
+ }
+ last if ($canview);
+ }
+ if ($canview) {
+ $viewuser = &view_as_js($esc_url,$esc_symb);
+ }
+ }
+
+ my ($ltitarget,$deeplinktarget);
+ if ($env{'request.lti.login'}) {
+ $ltitarget = $env{'request.lti.target'};
+ }
+ if ($env{'request.deeplink.login'}) {
+ $deeplinktarget = $env{'request.deeplink.target'};
+ }
+
+ my $annotateurl = '/adm/annotation';
+ if ($httphost) {
+ $annotateurl = '/adm/annotations';
+ }
my $hostvar = '
function setLCHost() {
var lcHostname="";
@@ -1916,6 +2522,22 @@ function gocstr(url,filename) {
this.document.cstrdelete.submit();
return;
}
+ if ((url == '/adm/cfile?action=copy') || (url == '/adm/cfile?action=rename')) {
+ this.document.cstrcopy.filename.value = filename;
+ var oldname = filename.substring(filename.lastIndexOf("/") + 1);
+ var newname=prompt('$newname',oldname);
+ if (newname == "" || !newname || newname == oldname) {
+ return;
+ }
+ if (url == '/adm/cfile?action=rename') {
+ this.document.cstrcopy.action.value = 'rename';
+ } else {
+ this.document.cstrcopy.action.value = 'copy';
+ }
+ this.document.cstrcopy.newfilename.value = newname;
+ this.document.cstrcopy.submit();
+ return;
+ }
if (url == '/adm/printout') {
this.document.cstrprint.postdata.value = filename
this.document.cstrprint.curseed.value = 0;
@@ -1954,17 +2576,23 @@ function golist(url) {
currentURL = null;
currentSymb= null;
var lcHostname = setLCHost();
- top.location.href=lcHostname+url;
+ var ltitarget = '$ltitarget';
+ var deeplinktarget = '$deeplinktarget';
+ if ((ltitarget == 'iframe') || (deeplinktarget == '_self')) {
+ document.location.href=lcHostname+url;
+ } else {
+ top.location.href=lcHostname+url;
+ }
}
}
-function catalog_info(isMobile) {
+function catalog_info(url,isMobile) {
if (isMobile == 1) {
- openMyModal(window.location.pathname+'.meta?modal=1',500,400,'yes');
+ openMyModal(url+'.meta?modal=1',500,400,'yes');
} else {
- loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=500,width=400,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
+ loncatinfo=window.open(url+'.meta',"LONcatInfo",'height=500,width=400,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
}
}
@@ -1986,7 +2614,7 @@ function annotate() {
annotator.document.write(
'$start_page_annotate'
+"