Apache::loncommon - pile of common routines
Common routines for manipulating connections, student answers, domains, common Javascript fragments, etc.
A collection of commonly used subroutines that don't have a natural home anywhere else. This collection helps remove redundancy from other modules and increase efficiency of memory usage.
openbrowser
and
opensearcher
. Returned string does not contain <script>
tags.
openbrowser(formname,elementname,only,omit)
[javascript]formname and elementname indicate the name of the html form and name of the element that the results of the browsing selection are to be placed in.
Specifying 'only' will restrict the browser to displaying only files with the given extension. Can be a comma separated list.
Specifying 'omit' will restrict the browser to NOT displaying files with the given extension. Can be a comma separated list.
formname and elementname specify the name of the html form and the name of the element the selection from the search results will be placed in.
linked_select_forms(...)
linked_select_forms takes the following ordered inputs:
Below is an example of such a hash. Only the 'text', 'default', and
'select2' keys must appear as stated. keys(%menu)
are the possible
values for the first select menu. The text that coincides with the
first menu value is given in $menu{$choice1}->{'text'}. The values
and text for the second menu are given in the hash pointed to by
$menu{$choice1}->{'select2'}.
my %menu = ( A1 => { text =>"Choice A1" , default => "B3", select2 => { B1 => "Choice B1", B2 => "Choice B2", B3 => "Choice B3", B4 => "Choice B4" } }, A2 => { text =>"Choice A2" , default => "C2", select2 => { C1 => "Choice C1", C2 => "Choice C2", C3 => "Choice C3" } }, A3 => { text =>"Choice A3" , default => "D6", select2 => { D1 => "Choice D1", D2 => "Choice D2", D3 => "Choice D3", D4 => "Choice D4", D5 => "Choice D5", D6 => "Choice D6", D7 => "Choice D7" } } );
$text will optionally be linked to the same topic, allowing you to link text in addition to the graphic. If you do not want to link text, but wish to specify one of the later parameters, pass an empty string.
$stayOnPage is a value that will be interpreted as a boolean. If true, the link will not open a new window. If false, the link will open a new window using Javascript. (Default is false.)
$width and $height are optional numerical parameters that will override the width and height of the popped up window, which may be useful for certain help topics with big pictures included.
The Javascript fragment returned by this function (no <script> tag)
must be written to the HTML page once. It will prove the Javascript
function ``change(name, content)''. Calling the change function with the
name of the section
you want to update, matching the name passed to changable_area
, and
the new content you want to put in there, will put the content into
that area.
Note: Netscape 4 only reserves enough space for the changable area to contain room for the original contents. You need to ``make space'' for whatever changes you wish to make, and be sure to check your code in Netscape 4. This feature in Netscape 4 is not powerful; it's adequate for updating a one-line status display, but little more. This script will set the space to 100% width, so you only need to worry about height in Netscape 4.
Modern browsers are much less limiting, and if you can commit to the user not using Netscape 4, this feature may be used freely with pretty much any HTML.
change_content_javascript
. $name is
the name you will use to reference the area later; do not repeat the
same name on a given HTML page more then once. $origContent is what
the area will originally contain, which can be left blank.
csv_translate($text)
Currently supported formats:
Inputs: $workbook
Returns: $format, a hash reference.
Inputs: Apache request object
Returns (undef) on failure, Excel worksheet object, scalar with filename, and formats from &Apache::loncommon::define_excel_formats on success
Inputs: Apache request object, and file suffix
Returns (undef) on failure, Filehandle and filename on success.
get_domains()
multiple_select_form($name,$value,$size,$hash,$order)
Args: $name - name of the <select> element $value - sclara or array ref of values that should already be selected $size - number of rows long the select element is $hash - the elements should be 'option' => 'shown text' (shown text should already have been &mt()) $order - (optional) array ref of the order to show the elments in
select_form($defdom,$name,%hash)
select_dom_form($defdom,$name,$includeempty)
If the $includeempty flag is set, it also includes an empty choice (``no domain selected'');
get_library_servers($domain)
home_server_option_list($domain)
Outputs:
See loncreateuser.pm for invocation and use examples.
Returns default authentication type and an associated argument as listed in file 'domain.tab'.
get_auth_defaults($target_domain)
returns the default authentication
type and an associated argument (initial password or a kerberos domain).
These values are stored in lonTabs/domain.tab
($def_auth, $def_arg) = &get_auth_defaults($target_domain);
If target_domain is not found in domain.tab, returns nothing ('').
get_kerberos_defaults($target_domain)
returns the default kerberos
version and domain. If not found in domain.tabs, it defaults to
version 4 and the domain of the server.
($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
keyword($word)
Uses global $thesaurus_db_file.
plainname($uname,$udom,$first)
nickname($uname,$udom)
``"nickname"''
if the user has a nickname or
``first middle last generation''
if the user does not
screenname($uname,$udom)
languageids()
languagedescription()
copyrightids()
copyrightdescription()
source_copyrightids()
source_copyrightdescription()
filecategories()
filecategorytypes()
fileembstyle()
filedescription()
filedescriptionex()
The output string is a table containing all desired attempts, if any.
get_student_answers()
Returns: A link to grades.pm such as to see the SUBM view of a student
Returns: A link to grades.pm such as to see the PGRD view of a student
Returns: A link to parmset.pm such as to see the PPRM view of a student and a specific resource
Returns: Determines which domain should be used for designs
Returns: A link to a domain logo, if the domain logo exists. If the domain logo does not exist, a description of the domain.
Returns: value of designparamter $which
Inputs:
Returns: A uniform header for LON-CAPA web pages. If $bodyonly is nonzero, a string containing a <body> tag will be returned. If $bodyonly is undef or zero, an html string containing a <body> tag and other decorations will be returned.
Inputs: none
Inputs: (all optional) domain -> force to color decorate a page for a specific domain function -> force usage of a specific rolish color scheme bgcolor -> override the default page bgcolor
Inputs: $title - optional title for the head $head_extra - optional extra HTML to put inside the <head> $args - optional arguments force_register - if is true call registerurl so the remote is informed redirect -> array ref of 1- seconds before redirect occurs 2- url to redirect to 3- whether the side effect should occur (side effect of setting $env{'internal.head.redirect'} to the url redirected too) domain -> force to color decorate a page for a specific domain function -> force usage of a specific rolish color scheme bgcolor -> override the default page bgcolor no_auto_mt_title -> prevent &mt()ing the title arg
Inputs: none
Inputs: none
Inputs: none
Inputs: $title - optional title for the page $head_extra - optional extra HTML to put inside the <head>
Inputs: $title - optional title for the page $head_extra - optional extra HTML to incude inside the <head> $args - additional optional args supported are: only_body -> is true will set &bodytag() onlybodytag arg on no_nav_bar -> is true will set &bodytag() notopbar arg on add_entries -> additional attributes to add to the <body> domain -> force to color decorate a page for a specific domain function -> force usage of a specific rolish color scheme redirect -> see &headtag() bgcolor -> override the default page bg color js_ready -> return a string ready for being used in a javascript writeln html_encode -> return a string ready for being used in a html attribute force_register -> if is true will turn on the &bodytag() $forcereg arg body_title -> alternate text to use instead of $title in the title box that appears, this text is not auto translated like the $title is frameset -> if true will start with a <frameset> rather than <body> no_title -> if true the title bar won't be shown skip_phases -> hash ref of head -> skip the <html><head> generation body -> skip all <body> generation
no_inline_link -> if true and in remote mode, don't show the 'Switch To Inline Menu' link
no_auto_mt_title -> prevent &mt()ing the title arg
Inputs: $args - additional optional args supported are: js_ready -> return a string ready for being used in a javascript writeln html_encode -> return a string ready for being used in a html attribute frameset -> if true will start with a <frameset> rather than <body> dicsussion -> if true will get discussion from lonxml::xmlend (you can pass the target and parser arguments through optional 'target' and 'parser' args to this routine)
Inputs: user's domain, user's username, course's domain, course's number, optional section ID.
Outputs: role status: active, previous or future.
1. domain 2. course number 3. reference to array containing roles for which sections should be gathered (optional). 4. reference to array containing status types for which sections should be gathered (optional).
If the third argument is undefined, sections are gathered for any role. If the fourth argument is undefined, sections are gathered for any status. Permissible values are 'active' or 'future' or 'previous'.
Returns section hash (keys are section IDs, values are number of users in each section), subject to the optional roles filter, optional status filter
Incoming parameters: 1. course domain 2. course number 3. access status: users must have - either active, previous, future, or all. 4. reference to array of permissible roles 5. reference to array of section restrictions (optional) 6. reference to results object (hash of hashes). 7. reference to optional userdata hash Keys of top level hash are roles. Keys of inner hashes are username:domain, with values set to access type. Optional userdata hash returns an array with arguments in the same order as loncoursedata::get_classlist() for student data.
Entries for end, start, section and status are blank because of the possibility of multiple values for non-student roles.
Incoming parameters: 1. user's username 2. user's domain
Returns: 1. Disk quota (in Mb) assigned to student.
If a value has been stored in the user's environment, it will return that, otherwise it returns the default for users in the domain.
Incoming parameters: 1. domain
Returns: 1. Default disk quota (in Mb) for user portfolios in the domain.
If a value has been stored in the domain's configuration db, it will return that, otherwise it returns 20 (for backwards compatibility with domains which have not set up a configuration db file; the original statically defined portfolio quota was 20 Mb).
get_unprocessed_cgi($query,$possible_names)
Typically called with $ENV{'QUERY_STRING'} as the first parameter. $possible_names is an ref to an array of form element names. As an example: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']); will result in $env{'form.uname'} and $env{'form.udom'} being set.
cacheheader()
no_cache($r)
add_to_env($name,$value)
get_env_multiple($name)
returns an array of values
upfile_store($r)
load_tmp_file($r)
upfile_record_sep()
record_sep($record)
upfile_select_html()
csv_print_samples($r,$records)
csv_print_select_table($r,$records,$d)
$r is an Apache Request ref, $records is an arrayref from &Apache::loncommon::upfile_record_sep, $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
csv_samples_select_table($r,$records,$d)
$r is an Apache Request ref, $records is an arrayref from &Apache::loncommon::upfile_record_sep, $d is an array of 2 element arrays (internal name, displayed name)
clean_excel_name($name)
check_if_partid_hidden($id,$symb,$udom,$uname)
1 if the part is to be hidden, undef if it is to be shown
Arguments are:
$id the id of the part to be checked $symb, optional the symb of the resource to check $udom, optional the domain of the user to check for $uname, optional the username of the user to check for
Returns an id which can be used to pass environment variables to various cgi-bin scripts. These environment variables will be removed from the users environment after a given time by the routine &Apache::lonnet::transfer_profile_to_env.
Inputs:
Returns:
An <img> tag which references graph.png and the appropriate identifying information for the plot.
Inputs:
Returns:
An <img> tag which references graph.png and the appropriate identifying information for the plot.
Inputs:
Returns:
An <img> tag which references graph.png and the appropriate identifying information for the plot.
Bad place for them but what the hell.
Inputs:
Inputs: a scalar describing the data (e.g. 'chart', 'problem_analysis')
a hash ref describing the data to be stored. For example:
%Save_Parameters = ('Status' => 'scalar', 'chartoutputmode' => 'scalar', 'chartoutputdata' => 'scalar', 'Section' => 'array', 'Group' => 'array', 'StudentData' => 'array', 'Maps' => 'array');
Returns: both routines return nothing