NAME

Apache::loncommon - pile of common routines


SYNOPSIS

Referenced by other mod_perl Apache modules.

Invocation: &Apache::loncommon::SUBROUTINENAME(ARGUMENTS);


INTRODUCTION

Common collection of used subroutines. This collection helps remove redundancy from other modules and increase efficiency of memory usage.

Current things done:

 Makes a table out of the previous homework attempts
 Inputs result_from_symbread, user, domain, course_id
 Reads in non-network-related .tab files

This is part of the LearningOnline Network with CAPA project described at http://www.lon-capa.org.

General Subroutines

BEGIN()
Initialize values from language.tab, copyright.tab, filetypes.tab, and filecategories.tab.

browser_and_searcher_javascript
Returns scalar containing javascript to open a browser window or a searcher window. Also creates
openbrowser(formname,elementname,only,omit) [javascript]
inputs: formname, elementname, only, omit

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 seperated list.

Specifying 'omit' will restrict the browser to NOT displaying files with the given extension. Can be a comma seperated list.

opensearcher(formname, elementname) [javascript]
Inputs: formname, elementname

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 returns a string containing a <script></script> block and html for two <select> menus. The select menus will be linked in that changing the value of the first menu will result in new values being placed in the second menu. The values in the select menu will appear in alphabetical order.

linked_select_forms takes the following ordered inputs:

$formname, the name of the <form> tag
$middletext, the text which appears between the <select> tags
$firstdefault, the default value for the first menu
$firstselectname, the name of the first <select> tag
$secondselectname, the name of the second <select> tag
$hashref, a reference to a hash containing the data for the menus.

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'' } } );

csv_translate($text)
Translate $text to allow it to be output as a 'comma seperated values' format.

get_domains()
Returns an array containing each of the domains listed in the hosts.tab file.

select_dom_form($defdom,$name)
Returns a string containing a <select name='$name' size='1'> form to allow a user to select the domain to preform an operation in. See loncreateuser.pm for an example invocation and use.

get_home_servers($domain)
Returns a hash which contains keys like '103l3' and values like 'kirk.lite.msu.edu'. All of the keys will be for machines in the given $domain.

home_server_option_list($domain)
returns a string which contains an <option> list to be used in a <select> form input. See loncreateuser.pm for an example.

authform_xxxxxx
The authform_xxxxxx subroutines provide javascript and html forms which handle some of the conveniences required for authentication forms. This is not an optimal method, but it works.

See loncreateuser.pm for invocation and use examples.

authform_header
authform_authorwarning
authform_nochange
authform_kerberos
authform_internal
authform_filesystem

CSV Upload/Handling functions

upfile_store($r)
Store uploaded file, $r should be the HTTP Request object, needs $ENV{'form.upfile'} returns $datatoken to be put into hidden field

load_tmp_file($r)
Load uploaded file from tmp, $r should be the HTTP Request object, needs $ENV{'form.datatoken'}, sets $ENV{'form.upfile'} to the contents of the file

upfile_record_sep()
Separate uploaded file into records returns array of records, needs $ENV{'form.upfile'} and $ENV{'form.upfiletype'}

record_sep($record)
Separate a record into fields $record should be an item from the upfile_record_sep(), needs $ENV{'form.upfiletype'}

upfile_select_html()
return HTML code to select file and specify its type

csv_print_samples($r,$records)
Prints a table of sample values from each column uploaded $r is an Apache Request ref, $records is an arrayref from &Apache::loncommon::upfile_record_sep

csv_print_select_table($r,$records,$d)
Prints a table to create associations between values and table columns. $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)

csv_samples_select_table($r,$records,$d)
Prints a table of sample values from the upload and can make associate samples to internal names.

$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)

Access .tab File Data

languageids()
returns list of all language ids

languagedescription()
returns description of a specified language id

copyrightids()
returns list of all copyrights

copyrightdescription()
returns description of a specified copyright id

filecategories()
returns list of all file categories

filecategorytypes()
returns list of file types belonging to a given file category

fileembstyle()
returns embedding style for a specified file type

filedescription()
returns description for a specified file type

filedescriptionex()
returns description for a specified file type with extra formatting

Alternate Problem Views

get_previous_attempt()
return string with previous attempt on problem

get_student_view()
show a snapshot of what student was looking at

get_student_answers()
show a snapshot of how student was answering problem

HTTP Helper

get_unprocessed_cgi($query,$possible_names)
Modify the %ENV hash to contain unprocessed CGI form parameters held in $query. The parameters listed in $possible_names (an array reference), will be set in $ENV{'form.name'} if they do not already exist.

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()
returns cache-controlling header code

nocache()
specifies header code to not have cache

add_to_env($name,$value)
adds $name to the %ENV hash with value $value, if $name already exists, the entry is converted to an array reference and $value is added to the array.