--- loncom/interface/lonhtmlcommon.pm 2016/08/10 03:17:15 1.358.2.6 +++ loncom/interface/lonhtmlcommon.pm 2015/04/24 21:31:56 1.361 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common html routines # -# $Id: lonhtmlcommon.pm,v 1.358.2.6 2016/08/10 03:17:15 raeburn Exp $ +# $Id: lonhtmlcommon.pm,v 1.361 2015/04/24 21:31:56 musolffc Exp $ # # Copyright Michigan State University Board of Trustees # @@ -451,10 +451,12 @@ sub radio { &date_setter returns html and javascript for a compact date-setting form. To retrieve values from it, use &get_date_from_form. -Inputs - =over 4 +=item Inputs + +=over + =item $dname The name to prepend to the form elements. @@ -482,50 +484,23 @@ the date/time fields are left empty. =item $state Specifies the initial state of the form elements. Either 'disabled' or empty. -Defaults to empty, which indicates the form elements are not disabled. - -=item $no_hh_mm_ss - -If true, text boxes for hours, minutes and seconds are omitted. - -=item $defhour - -Default value for hours (a default of 0 is used otherwise). - -=item $defmin - -Default value for minutes (a default of 0 is used otherwise). - -=item defsec - -Default value for seconds (a default of 0 is used otherwise). - -=item $nolink - -If true, a "Select calendar" link (to pop-up a calendar) is not displayed -to the right of the items. - -=item $no_mm_ss - -If true, text boxes for minutes and seconds are omitted. - -=item $no_ss - -If true, text boxes for seconds are omitted. +Defaults to empty, which indiciates the form elements are not disabled. =back -Bugs +=item Bugs The method used to restrict user input will fail in the year 2400. +=back + =cut ############################################## ############################################## sub date_setter { my ($formname,$dname,$currentvalue,$special,$includeempty,$state, - $no_hh_mm_ss,$defhour,$defmin,$defsec,$nolink,$no_mm_ss,$no_ss) = @_; + $no_hh_mm_ss,$defhour,$defmin,$defsec,$nolink) = @_; my $now = time; my $tzname; @@ -678,24 +653,17 @@ ENDJS $result .= &mt('[_1] [_2] [_3] ', $monthselector,$dayselector,$yearselector). $tzone; - } elsif ($no_mm_ss) { - $result .= &mt('[_1] [_2] [_3] [_4]', - $monthselector,$dayselector,$yearselector, - $hourselector). - $tzone; - } elsif ($no_ss) { - $result .= &mt('[_1] [_2] [_3] [_4] [_5]m', - $monthselector,$dayselector,$yearselector, - $hourselector,$minuteselector). - $tzone; + if (!$nolink) { + $result .= &mt('[_1]Select Date[_2]',$cal_link,''); + } } else { $result .= &mt('[_1] [_2] [_3] [_4] [_5]m [_6]s ', $monthselector,$dayselector,$yearselector, $hourselector,$minuteselector,$secondselector). $tzone; - } - if (!$nolink) { - $result .= &mt('[_1]Select Date[_2]',$cal_link,''); + if (!$nolink) { + $result .= &mt('[_1]Select Date[_2]',$cal_link,''); + } } $result .= "\n\n"; return $result; @@ -739,7 +707,9 @@ sub build_url { get_date_from_form retrieves the date specified in an &date_setter form. -Inputs: +=over + +=item Inputs: =over 4 @@ -753,6 +723,8 @@ The unix time to use as the default in c =back +=back + Returns: Unix time represented in the form. =cut @@ -924,7 +896,9 @@ sub javascript_docopen { Returns html for a selection box which allows the user to choose the enrollment status of students. The selection box name is 'Status'. -Inputs: +=over + +=item Inputs: $status: the currently selected status. If undefined the value of $env{'form.Status'} is taken. If that is undefined, a value of 'Active' @@ -938,6 +912,8 @@ $size: the size (number of lines) of the $onchange: javascript to use when the value is changed. Enclosed in double quotes, ""s, not single quotes. +=back + Returns: a perl string as described. =cut @@ -985,7 +961,7 @@ sub StatusOptions { =pod -=item Progess Window Handling Routines +=item Progress Window Handling Routines These routines handle the creation, update, increment, and closure of progress windows. The progress window reports to the user the number @@ -999,9 +975,11 @@ of items completed and an estimate of th Writes javascript to the client to open a progress window and returns a data structure used for bookkeeping. -Inputs +=over + +=item Inputs -=over 4 +=over =item $r Apache request @@ -1009,15 +987,18 @@ Inputs =back -Returns a hash containing the progress state data structure. +=back +Returns a hash containing the progress state data structure. =item &Update_PrgWin() Updates the text in the progress indicator. Does not increment the count. See &Increment_PrgWin. -Inputs: +=over + +=item Inputs: =over 4 @@ -1029,25 +1010,38 @@ Inputs: =back +=back + Returns: none -=item Increment_PrgWin() +=item &Increment_PrgWin() Increment the count of items completed for the progress window by $step or 1 if no step is provided. -Inputs: +=over + +=item Inputs: =over 4 -=item $r Apache request +=item $r -=item $prog_state Pointer to the data structure returned by Create_PrgWin +Apache request + +=item $prog_state -=item $extraInfo A description of the items being iterated over. Typically -'student'. +Pointer to the data structure returned by Create_PrgWin -=item $step (optional) counter step. Will be set to default 1 if ommited. step must be greater than 0 or empty. +=item $extraInfo + +A description of the items being iterated over. Typically 'student'. + +=item $step + +(optional) counter step. Will be set to default 1 if ommited. step must be greater than 0 or empty. + +=back =back @@ -1058,7 +1052,9 @@ Returns: none Closes the progress window. -Inputs: +=over + +=item Inputs: =over 4 @@ -1068,6 +1064,8 @@ Inputs: =back +=back + Returns: none =back @@ -1158,7 +1156,7 @@ sub Close_PrgWin { # ------------------------------------------------------- Puts directory header sub crumbs { - my ($uri,$target,$prefix,$form,$skiplast,$onclick)=@_; + my ($uri,$target,$prefix,$form,$skiplast)=@_; # You cannot crumbnify uploaded or adm resources if ($uri=~/^\/*(uploaded|adm)\//) { return &mt('(Internal Course/Group Content)'); } if ($target) { @@ -1184,9 +1182,9 @@ sub crumbs { &Apache::loncommon::inhibit_menu_check(\$href_path); if ($form) { my $href = 'javascript:'.$form.".action='".$href_path."';".$form.'.submit();'; - $output.=qq{$dir/}; + $output.=qq{$dir/}; } else { - $output.=qq{$dir/}; + $output.=qq{$dir/}; } } } else { @@ -1257,9 +1255,9 @@ sub htmlareaheaders { ENDEDITOR } $s.=(< - - + + + @@ -1342,6 +1340,41 @@ sub htmlareaselectactive { } function startRichEditor(id) { + // fix character entities inside + // NOTE: this is not fixing characters inside + // NOTE: < and > inside should fix automatically because there should not be a letter after <. + var ta = document.getElementById(id); + var value = ta.value; + var in_m = false; // in the m element + var in_text = false; // in the text inside the m element + var im = -1; // position of + var it = -1; // position of the text inside + for (var i=0; i if found twice + in_m = true; + in_text = false; + im = i; + it = -1; + } else if (in_m) { + if (!in_text) { + if (value.charAt(i) == ">") { + in_text = true; + it = i+1; + } + } else if (value.substr(i, 4) == "") { + in_m = false; + var text = value.substr(it, i-it); + var l1 = text.length; + text = text.replace(//g, ">"); + var l2 = text.length; + value = value.substr(0, it) + text + "" + value.substr(i+4); + i = i + (l2-l1); + } + } + } + ta.value = value; CKEDITOR.replace(id, { customConfig: "/ckeditor/loncapaconfig.js", @@ -1353,6 +1386,68 @@ sub htmlareaselectactive { function destroyRichEditor(id) { CKEDITOR.instances[id].destroy(); + // replace character entities < and > in and + // and "&fctname(" by "&fctname(" + // and the quotes inside functions: "&fct(1, "a")" -> "&fct(1, "a")" + var ta = document.getElementById(id); + var value = ta.value; + var in_element = false; // in the m or chem element + var tagname = ""; // m or chem + var in_text = false; // in the text inside the element + var im = -1; // position of start tag + var it = -1; // position of the text inside + for (var i=0; i") { + in_text = true; + it = i+1; + } + } else if (value.substr(i, 3+tagname.length) == "") { + in_element = false; + var text = value.substr(it, i-it); + var l1 = text.length; + text = text.replace(/</g, "<"); + text = text.replace(/>/g, ">"); + var l2 = text.length; + value = value.substr(0, it) + text + value.substr(i); + i = i + (l2-l1); + } + } + } + // fix function names + value = value.replace(/&([a-zA-Z_]+)\(/g, "&$1("); + // fix quotes in functions + var pos_next_fct = value.search(/&[a-zA-Z_]+\(/); + var depth = 0; + for (var i=0; i 0) { + if (value.charAt(i) == ")") + depth--; + else if (value.substr(i, 6) == """) + value = value.substr(0, i) + "\"" + value.substr(i+6); + } + } + // replace the text value + ta.value = value; } function editorHandler(event) { @@ -1659,19 +1754,37 @@ A link to help for the component will be All inputs can be undef without problems. -Inputs: $component (the text on the right side of the breadcrumbs trail), - $component_help (the help item filename (without .tex extension). - $menulink (boolean, controls whether to include a link to /adm/menu) - $helplink (if 'nohelp' don't include the orange help link) - $css_class (optional name for the class to apply to the table for CSS) - $no_mt (optional flag, 1 if &mt() is _not_ to be applied to $component - when including the text on the right. - $CourseBreadcrumbs (optional flag, 1 if &breadcrumbs called from &docs_breadcrumbs, - because breadcrumbs are being) - $topic_help (optional help item to be displayed on right side of the breadcrumbs - row, using loncommon::help_open_topic() to generate the link. - $topic_help_text (text to include in the link in the optional help item - on the right side of the breadcrumbs row. +=over + +=item Inputs: + +=over + +=item $component + +the text on the right side of the breadcrumbs trail + +=item $component_help + +=item $menulink + +boolean, controls whether to include a link to /adm/menu + +=item $helplink + +if 'nohelp' don't include the orange help link + +=item $css_class + +optional name for the class to apply to the table for CSS + +=item $no_mt + +optional flag, 1 if &mt() is _not_ to be applied to $component when including the text on the right + +=back + +=back Returns a string containing breadcrumbs for the current page. @@ -1700,7 +1813,7 @@ returns: nothing sub breadcrumbs { my ($component,$component_help,$menulink,$helplink,$css_class,$no_mt, - $CourseBreadcrumbs,$topic_help,$topic_help_text) = @_; + $CourseBreadcrumbs) = @_; # $css_class ||= 'LC_breadcrumbs'; @@ -1807,10 +1920,6 @@ returns: nothing $component_help, $faq,$bug); } - if ($topic_help && $topic_help_text) { - $icons .= ' '.&Apache::loncommon::help_open_topic($topic_help,&mt($topic_help_text),'', - undef,600); - } # @@ -1823,7 +1932,7 @@ returns: nothing } - if (($component) || ($topic_help && $topic_help_text)) { + if ($component) { $links = &htmltag('span', ( $no_mt ? $component : mt($component) ). ( $icons ? $icons : '' ), @@ -1878,7 +1987,9 @@ Adds $html to $category of the breadcrum $html is usually a link to a page that invokes a function on the currently displayed data (e.g. print when viewing a problem) -Currently there are 3 possible values for $category: +=over + +=item Currently there are 3 possible values for $category: =over @@ -1892,7 +2003,9 @@ remaining items in right of breadcrumbs advanced tools shown in a separate box below breadcrumbs line =back - + +=back + returns: nothing =cut @@ -1926,23 +2039,22 @@ returns: nothing undef(%tools); } -=item ¤t_breadcrumb_tools() +=item &render_tools(\$breadcrumbs) -returns: a hash containing the current breadcrumb tools. +Creates html for breadcrumb tools (categories navigation and tools) and inserts +\$breadcrumbs at the correct position. -=cut +=over - sub current_breadcrumb_tools { - return %tools; - } +=item input: -=item &render_tools(\$breadcrumbs) +=over -Creates html for breadcrumb tools (categories navigation and tools) and inserts -\$breadcrumbs at the correct position. +=item \$breadcrumbs - a reference to the string containing prepared breadcrumbs. -input: \$breadcrumbs - a reference to the string containing prepared -breadcrumbs. +=back + +=back returns: nothing @@ -1968,8 +2080,17 @@ returns: nothing Creates html for advanced tools (category advtools) and inserts \$breadcrumbs at the correct position. -input: \$breadcrumbs - a reference to the string containing prepared -breadcrumbs (after render_tools call). +=over + +=item input: + +=over + +=item \$breadcrumbs - a reference to the string containing prepared breadcrumbs (after render_tools call). + +=back + +=back returns: nothing @@ -2298,7 +2419,7 @@ sub course_selection { if ($totcodes > 0) { my $numtitles = @$codetitles; if ($numtitles > 0) { - $output .= '
'; + $output .= '
'; $output .= '
'.$$codetitles[0].'
'."\n". '