# HG changeset patch
# User devi
# Date 1141323211 -7200
# Node ID 62001c1e3295c5ebfa098efe21a7421362dd4162
# Parent  385499ec544aee4ce33c8bf29d45c1bfd4a3d03a
Доделан вызов окна редактирования журнала.

+ исправлен баг с unicode

diff -r 385499ec544a -r 62001c1e3295 l3-cgi
--- a/l3-cgi	Thu Mar 02 00:06:54 2006 +0200
+++ b/l3-cgi	Thu Mar 02 20:13:31 2006 +0200
@@ -13,7 +13,7 @@
 
 my %filter;
 
-for my $key (qw(login_from local_session_id)) {
+for my $key (qw(login_from local_session_id action)) {
     $filter{$key} =     param($key) if param($key);
     $filter{$key} =     $ENV{$key} if defined $ENV{$key};
 }
diff -r 385499ec544a -r 62001c1e3295 l3-frontend
--- a/l3-frontend	Thu Mar 02 00:06:54 2006 +0200
+++ b/l3-frontend	Thu Mar 02 20:13:31 2006 +0200
@@ -11,7 +11,10 @@
 our %Args_Description;
 our $Mywi_Socket;
 our %Sessions;
+
 our %filter;
+our $filter_url;
+sub init_filter;
 
 our %Files;
 
@@ -43,7 +46,9 @@
 
 sub print_all_txt;
 sub print_all_html;
+sub print_edit_all_html;
 sub print_command_lines_html;
+sub print_command_lines_txt;
 sub print_files_html;
 sub print_stat_html;
 sub print_header_html;
@@ -59,16 +64,34 @@
     init_config();
     $Config{frontend_ico_path}=$Config{frontend_css};
     $Config{frontend_ico_path}=~s@/[^/]*$@@;
+    init_filter();
 
     open_mywi_socket();
     load_command_lines_from_xml($Config{"backend_datafile"});
     load_sessions_from_xml($Config{"backend_datafile"});
     sort_command_lines;
     process_command_lines;
-    print_all_txt($Config{"output"});
+    if (defined($filter{action}) && $filter{action} eq "edit") {
+        print_edit_all_html($Config{"output"});
+    }
+    else {
+        print_all_html($Config{"output"});
+    }
     close_mywi_socket;
 }
 
+sub init_filter
+{
+    if ($Config{filter}) {
+        # Инициализация фильтра
+        for (split /&/,$Config{filter}) {
+            my ($var, $val) = split /=/;
+            $filter{$var} = $val || "";
+        }
+    }
+    $filter_url = join ("&", map("$_=$filter{$_}", keys %filter));
+}
+
 # extract_from_cline
 
 # In:   $what       = commands | args
@@ -237,6 +260,7 @@
     open (CLASS, $datafile)
         or die "Can't open file with xml lablog ",$datafile,"\n";
     local $/;
+    binmode CLASS, ":utf8";
     $data = <CLASS>;
     close(CLASS);
 
@@ -253,9 +277,10 @@
 {
     my $datafile = $_[0];
 
-    open (CLASS, $datafile)
+    open (CLASS,  $datafile)
         or die "Can't open file with xml lablog ",$datafile,"\n";
     local $/;
+    binmode CLASS, ":utf8";
     my $data = <CLASS>;
     close(CLASS);
 
@@ -301,11 +326,20 @@
 
 sub process_command_lines
 {
+
+COMMAND_LINE_PROCESSING:
     for my $i (@Command_Lines_Index) {
         my $cl = \$Command_Lines[$i];
 
         next if !$cl;
 
+        for my $filter_key (keys %filter) {
+            next COMMAND_LINE_PROCESSING
+                if defined($$cl->{local_session_id})
+                && defined($Sessions{$$cl->{local_session_id}}->{$filter_key})
+                && $Sessions{$$cl->{local_session_id}}->{$filter_key} ne $filter{$filter_key};
+        }
+
         $$cl->{id} = $$cl->{"time"};
 
         $$cl->{err} ||=0;
@@ -461,13 +495,6 @@
     my @known_commands;
 
 
-    if ($Config{filter}) {
-        # Инициализация фильтра
-        for (split /&/,$Config{filter}) {
-            my ($var, $val) = split /=/;
-            $filter{$var} = $val || "";
-        }
-    }
 
     $Stat{LastCommand}   ||= 0;
     $Stat{TotalCommands} ||= 0;
@@ -615,10 +642,12 @@
 
 # Session change
         if ( $last_session ne $cl->{"local_session_id"}) {
-            my $tty = $cl->{"tty"};
-            $this_day_result .= "<div class='ttychange'><a href='?local_session_id=".$cl->{"local_session_id"}."'>"
+            my $tty;
+            if (defined $Sessions{$cl->{"local_session_id"}}->{"tty"}) {
+                $this_day_result .= "<div class='ttychange'><a href='?local_session_id=".$cl->{"local_session_id"}."'>"
                                 . $Sessions{$cl->{"local_session_id"}}->{"tty"}
                                 ."</a></div>";
+            }
             $last_session=$cl->{"local_session_id"};
         }
 
@@ -817,7 +846,7 @@
 # In:       $_[0]       output_filename
 # Out:
 
-sub print_all_txt
+sub print_command_lines_txt
 {
 
     my $output_filename=$_[0];
@@ -985,40 +1014,86 @@
         $result .= $this_day_result;
    }
 
+   return $result;
 
 
 
-  my $SetCursorPosition_JS = <<JS;
-function setCursorPosition(oInput,oStart,oEnd) {
-    oInput.focus();
-    if( oInput.setSelectionRange ) {
-        oInput.setSelectionRange(oStart,oEnd);
-    } else if( oInput.createTextRange ) {
-        var range = oInput.createTextRange();
-        range.collapse(true);
-        range.moveEnd('character',oEnd);
-        range.moveStart('character',oStart);
-        range.select();
-    }
 }
-JS
 
-    if ($output_filename eq "-") {
-        print 
+#############
+# print_edit_all_html
+#
+# Вывести страницу с текстовым представлением журнала для редактирования
+#
+# In:       $_[0]       output_filename
+# Out:
+
+sub print_edit_all_html
+{
+    my $output_filename= shift;
+    my $result;
+    my $cursor_position = 0;
+
+    $result = print_command_lines_txt;
+
+    $result = 
                "<html>"
+                ."<head>"
+                ."<meta content='text/html; charset=utf-8' http-equiv='Content-Type' />"
+                ."<link rel='stylesheet' href='$Config{frontend_css}' type='text/css'/>"
+                ."<title>$title</title>"
+                ."</head>"
               ."<script>"
               .$SetCursorPosition_JS
               ."</script>"
               ."<body onLoad='setCursorPosition(document.all.mytextarea, $cursor_position, $cursor_position+10)'>"
+              ."<h1>Журнал лабораторных работ. Правка</h1>"
+              ."<form>"
               ."<textarea rows='30' cols='100' wrap='off' id='mytextarea'>$result</textarea>"
+              ."<br/><input type='submit' value='Сохранить' label='label'/>"
+              ."</form>"
+              ."<p>Внимательно правим, потом сохраняем</p>"
+              ."<p>Строки, начинающиеся символами #l3: можно трогать, только если точно знаешь, что делаешь</p>"
               ."</body>"
-              ."</html>"
-              ;
+              ."</html>";
+
+    if ($output_filename eq "-") {
+        print $result;
     }
     else {
         open(OUT, ">", $output_filename)
             or die "Can't open $output_filename for writing\n";
-        print OUT "<pre>$result</pre>";
+        binmode ":utf8";
+        print OUT "$result";
+        close(OUT);
+    }
+}
+
+#############
+# print_all_txt
+#
+# Вывести страницу с текстовым представлением журнала для редактирования
+#
+# In:       $_[0]       output_filename
+# Out:
+
+sub print_all_txt
+{
+    my $result;
+    
+    $result = print_command_lines_txt;
+
+    $result =~ s/&gt;/>/g;
+    $result =~ s/&lt;/</g;
+    $result =~ s/&amp;/&/g;
+
+    if ($output_filename eq "-") {
+        print $result;
+    }
+    else {
+        open(OUT, ">:utf8", $output_filename)
+            or die "Can't open $output_filename for writing\n";
+        print OUT "$result";
         close(OUT);
     }
 }
@@ -1052,16 +1127,17 @@
 
     $result.= "<h2 id='log'>Журнал</h2>"       . $command_lines;
     $result.= "<h2 id='files'>Файлы</h2>"      . $files_section if $files_section;
-    $result.= "<h2 id='stat'>Статистика</h2>"  . print_stat;
+    $result.= "<h2 id='stat'>Статистика</h2>"  . print_stat_html;
     $result.= "<h2 id='help'>Справка</h2>"     . $Html_Help . "<br/>"; 
     $result.= "<h2 id='about'>О программе</h2>". $Html_About. "<br/>"; 
     $result.= print_footer_html;
 
     if ($output_filename eq "-") {
+        binmode STDOUT, ":utf8";
         print $result;
     }
     else {
-        open(OUT, ">", $output_filename)
+        open(OUT, ">:utf8", $output_filename)
             or die "Can't open $output_filename for writing\n";
         print OUT $result;
         close(OUT);
@@ -1140,7 +1216,10 @@
 <!-- ^^^ Tigra Hints ^^^ -->
 
 
-    <h1 onmouseover="myHint.show('1')" onmouseout="myHint.hide()">Журнал лабораторных работ</h1>
+    <div class='edit_link'>
+    [ <a href='?action=edit&$filter_url'>править</a> ]
+    </div>
+    <h1 onmouseover="myHint.show('1')" onmouseout="myHint.hide()" class='lined_header'>Журнал лабораторных работ</h1>
 HEADER
     if (    $course_student 
             || $course_trainer 
@@ -1334,7 +1413,12 @@
                   .  "<div class='file_navigation'><a href='#command:".$Files{$file}->{source_command_id}."'>"."&gt;"."</a></div>"
                   .  "<div class='filedata'><pre>".$Files{$file}->{content}."</pre></div>";
     }
-    return "<div class='files_toc'>".collapse_list(\@toc)."</div>".$result;
+    if ($result) {
+        return "<div class='files_toc'>".collapse_list(\@toc)."</div>".$result;
+    } 
+    else {
+        return "";
+    }
 }
 
 
@@ -1665,6 +1749,21 @@
     }
 JS
 
+$SetCursorPosition_JS = <<JS;
+function setCursorPosition(oInput,oStart,oEnd) {
+    oInput.focus();
+    if( oInput.setSelectionRange ) {
+        oInput.setSelectionRange(oStart,oEnd);
+    } else if( oInput.createTextRange ) {
+        var range = oInput.createTextRange();
+        range.collapse(true);
+        range.moveEnd('character',oEnd);
+        range.moveStart('character',oStart);
+        range.select();
+    }
+}
+JS
+
 %Search_Machines = (
         "google" =>     {   "query" =>  "http://www.google.com/search?q=" ,
                     "icon"  =>  "$Config{frontend_google_ico}" },
diff -r 385499ec544a -r 62001c1e3295 l3config.pm
--- a/l3config.pm	Thu Mar 02 00:06:54 2006 +0200
+++ b/l3config.pm	Thu Mar 02 20:13:31 2006 +0200
@@ -1,6 +1,6 @@
-
 package l3config;
 
+use utf8;
 use Exporter;
 use vars qw(@ISA @EXPORT $VERSION);
 use Getopt::Long;
@@ -163,5 +163,8 @@
 	read_config_file(\%file_config, $User_Config_File);
 	GetOptions(\%argv_config, map "$_=s", keys %Config);
 	%Config = (%Config, %file_config, %argv_config);
+    for my $key (keys %Config) {
+        utf8::decode($Config{$key});
+    }
 }