lilalo

changeset 89:62001c1e3295

Доделан вызов окна редактирования журнала.

+ исправлен баг с unicode
author devi
date Thu Mar 02 20:13:31 2006 +0200 (2006-03-02)
parents 385499ec544a
children 1d97bb13da20
files l3-cgi l3-frontend l3config.pm
line diff
     1.1 --- a/l3-cgi	Thu Mar 02 00:06:54 2006 +0200
     1.2 +++ b/l3-cgi	Thu Mar 02 20:13:31 2006 +0200
     1.3 @@ -13,7 +13,7 @@
     1.4  
     1.5  my %filter;
     1.6  
     1.7 -for my $key (qw(login_from local_session_id)) {
     1.8 +for my $key (qw(login_from local_session_id action)) {
     1.9      $filter{$key} =     param($key) if param($key);
    1.10      $filter{$key} =     $ENV{$key} if defined $ENV{$key};
    1.11  }
     2.1 --- a/l3-frontend	Thu Mar 02 00:06:54 2006 +0200
     2.2 +++ b/l3-frontend	Thu Mar 02 20:13:31 2006 +0200
     2.3 @@ -11,7 +11,10 @@
     2.4  our %Args_Description;
     2.5  our $Mywi_Socket;
     2.6  our %Sessions;
     2.7 +
     2.8  our %filter;
     2.9 +our $filter_url;
    2.10 +sub init_filter;
    2.11  
    2.12  our %Files;
    2.13  
    2.14 @@ -43,7 +46,9 @@
    2.15  
    2.16  sub print_all_txt;
    2.17  sub print_all_html;
    2.18 +sub print_edit_all_html;
    2.19  sub print_command_lines_html;
    2.20 +sub print_command_lines_txt;
    2.21  sub print_files_html;
    2.22  sub print_stat_html;
    2.23  sub print_header_html;
    2.24 @@ -59,16 +64,34 @@
    2.25      init_config();
    2.26      $Config{frontend_ico_path}=$Config{frontend_css};
    2.27      $Config{frontend_ico_path}=~s@/[^/]*$@@;
    2.28 +    init_filter();
    2.29  
    2.30      open_mywi_socket();
    2.31      load_command_lines_from_xml($Config{"backend_datafile"});
    2.32      load_sessions_from_xml($Config{"backend_datafile"});
    2.33      sort_command_lines;
    2.34      process_command_lines;
    2.35 -    print_all_txt($Config{"output"});
    2.36 +    if (defined($filter{action}) && $filter{action} eq "edit") {
    2.37 +        print_edit_all_html($Config{"output"});
    2.38 +    }
    2.39 +    else {
    2.40 +        print_all_html($Config{"output"});
    2.41 +    }
    2.42      close_mywi_socket;
    2.43  }
    2.44  
    2.45 +sub init_filter
    2.46 +{
    2.47 +    if ($Config{filter}) {
    2.48 +        # Инициализация фильтра
    2.49 +        for (split /&/,$Config{filter}) {
    2.50 +            my ($var, $val) = split /=/;
    2.51 +            $filter{$var} = $val || "";
    2.52 +        }
    2.53 +    }
    2.54 +    $filter_url = join ("&", map("$_=$filter{$_}", keys %filter));
    2.55 +}
    2.56 +
    2.57  # extract_from_cline
    2.58  
    2.59  # In:   $what       = commands | args
    2.60 @@ -237,6 +260,7 @@
    2.61      open (CLASS, $datafile)
    2.62          or die "Can't open file with xml lablog ",$datafile,"\n";
    2.63      local $/;
    2.64 +    binmode CLASS, ":utf8";
    2.65      $data = <CLASS>;
    2.66      close(CLASS);
    2.67  
    2.68 @@ -253,9 +277,10 @@
    2.69  {
    2.70      my $datafile = $_[0];
    2.71  
    2.72 -    open (CLASS, $datafile)
    2.73 +    open (CLASS,  $datafile)
    2.74          or die "Can't open file with xml lablog ",$datafile,"\n";
    2.75      local $/;
    2.76 +    binmode CLASS, ":utf8";
    2.77      my $data = <CLASS>;
    2.78      close(CLASS);
    2.79  
    2.80 @@ -301,11 +326,20 @@
    2.81  
    2.82  sub process_command_lines
    2.83  {
    2.84 +
    2.85 +COMMAND_LINE_PROCESSING:
    2.86      for my $i (@Command_Lines_Index) {
    2.87          my $cl = \$Command_Lines[$i];
    2.88  
    2.89          next if !$cl;
    2.90  
    2.91 +        for my $filter_key (keys %filter) {
    2.92 +            next COMMAND_LINE_PROCESSING
    2.93 +                if defined($$cl->{local_session_id})
    2.94 +                && defined($Sessions{$$cl->{local_session_id}}->{$filter_key})
    2.95 +                && $Sessions{$$cl->{local_session_id}}->{$filter_key} ne $filter{$filter_key};
    2.96 +        }
    2.97 +
    2.98          $$cl->{id} = $$cl->{"time"};
    2.99  
   2.100          $$cl->{err} ||=0;
   2.101 @@ -461,13 +495,6 @@
   2.102      my @known_commands;
   2.103  
   2.104  
   2.105 -    if ($Config{filter}) {
   2.106 -        # Инициализация фильтра
   2.107 -        for (split /&/,$Config{filter}) {
   2.108 -            my ($var, $val) = split /=/;
   2.109 -            $filter{$var} = $val || "";
   2.110 -        }
   2.111 -    }
   2.112  
   2.113      $Stat{LastCommand}   ||= 0;
   2.114      $Stat{TotalCommands} ||= 0;
   2.115 @@ -615,10 +642,12 @@
   2.116  
   2.117  # Session change
   2.118          if ( $last_session ne $cl->{"local_session_id"}) {
   2.119 -            my $tty = $cl->{"tty"};
   2.120 -            $this_day_result .= "<div class='ttychange'><a href='?local_session_id=".$cl->{"local_session_id"}."'>"
   2.121 +            my $tty;
   2.122 +            if (defined $Sessions{$cl->{"local_session_id"}}->{"tty"}) {
   2.123 +                $this_day_result .= "<div class='ttychange'><a href='?local_session_id=".$cl->{"local_session_id"}."'>"
   2.124                                  . $Sessions{$cl->{"local_session_id"}}->{"tty"}
   2.125                                  ."</a></div>";
   2.126 +            }
   2.127              $last_session=$cl->{"local_session_id"};
   2.128          }
   2.129  
   2.130 @@ -817,7 +846,7 @@
   2.131  # In:       $_[0]       output_filename
   2.132  # Out:
   2.133  
   2.134 -sub print_all_txt
   2.135 +sub print_command_lines_txt
   2.136  {
   2.137  
   2.138      my $output_filename=$_[0];
   2.139 @@ -985,40 +1014,86 @@
   2.140          $result .= $this_day_result;
   2.141     }
   2.142  
   2.143 +   return $result;
   2.144  
   2.145  
   2.146  
   2.147 -  my $SetCursorPosition_JS = <<JS;
   2.148 -function setCursorPosition(oInput,oStart,oEnd) {
   2.149 -    oInput.focus();
   2.150 -    if( oInput.setSelectionRange ) {
   2.151 -        oInput.setSelectionRange(oStart,oEnd);
   2.152 -    } else if( oInput.createTextRange ) {
   2.153 -        var range = oInput.createTextRange();
   2.154 -        range.collapse(true);
   2.155 -        range.moveEnd('character',oEnd);
   2.156 -        range.moveStart('character',oStart);
   2.157 -        range.select();
   2.158 -    }
   2.159  }
   2.160 -JS
   2.161  
   2.162 -    if ($output_filename eq "-") {
   2.163 -        print 
   2.164 +#############
   2.165 +# print_edit_all_html
   2.166 +#
   2.167 +# Вывести страницу с текстовым представлением журнала для редактирования
   2.168 +#
   2.169 +# In:       $_[0]       output_filename
   2.170 +# Out:
   2.171 +
   2.172 +sub print_edit_all_html
   2.173 +{
   2.174 +    my $output_filename= shift;
   2.175 +    my $result;
   2.176 +    my $cursor_position = 0;
   2.177 +
   2.178 +    $result = print_command_lines_txt;
   2.179 +
   2.180 +    $result = 
   2.181                 "<html>"
   2.182 +                ."<head>"
   2.183 +                ."<meta content='text/html; charset=utf-8' http-equiv='Content-Type' />"
   2.184 +                ."<link rel='stylesheet' href='$Config{frontend_css}' type='text/css'/>"
   2.185 +                ."<title>$title</title>"
   2.186 +                ."</head>"
   2.187                ."<script>"
   2.188                .$SetCursorPosition_JS
   2.189                ."</script>"
   2.190                ."<body onLoad='setCursorPosition(document.all.mytextarea, $cursor_position, $cursor_position+10)'>"
   2.191 +              ."<h1>Журнал лабораторных работ. Правка</h1>"
   2.192 +              ."<form>"
   2.193                ."<textarea rows='30' cols='100' wrap='off' id='mytextarea'>$result</textarea>"
   2.194 +              ."<br/><input type='submit' value='Сохранить' label='label'/>"
   2.195 +              ."</form>"
   2.196 +              ."<p>Внимательно правим, потом сохраняем</p>"
   2.197 +              ."<p>Строки, начинающиеся символами #l3: можно трогать, только если точно знаешь, что делаешь</p>"
   2.198                ."</body>"
   2.199 -              ."</html>"
   2.200 -              ;
   2.201 +              ."</html>";
   2.202 +
   2.203 +    if ($output_filename eq "-") {
   2.204 +        print $result;
   2.205      }
   2.206      else {
   2.207          open(OUT, ">", $output_filename)
   2.208              or die "Can't open $output_filename for writing\n";
   2.209 -        print OUT "<pre>$result</pre>";
   2.210 +        binmode ":utf8";
   2.211 +        print OUT "$result";
   2.212 +        close(OUT);
   2.213 +    }
   2.214 +}
   2.215 +
   2.216 +#############
   2.217 +# print_all_txt
   2.218 +#
   2.219 +# Вывести страницу с текстовым представлением журнала для редактирования
   2.220 +#
   2.221 +# In:       $_[0]       output_filename
   2.222 +# Out:
   2.223 +
   2.224 +sub print_all_txt
   2.225 +{
   2.226 +    my $result;
   2.227 +    
   2.228 +    $result = print_command_lines_txt;
   2.229 +
   2.230 +    $result =~ s/&gt;/>/g;
   2.231 +    $result =~ s/&lt;/</g;
   2.232 +    $result =~ s/&amp;/&/g;
   2.233 +
   2.234 +    if ($output_filename eq "-") {
   2.235 +        print $result;
   2.236 +    }
   2.237 +    else {
   2.238 +        open(OUT, ">:utf8", $output_filename)
   2.239 +            or die "Can't open $output_filename for writing\n";
   2.240 +        print OUT "$result";
   2.241          close(OUT);
   2.242      }
   2.243  }
   2.244 @@ -1052,16 +1127,17 @@
   2.245  
   2.246      $result.= "<h2 id='log'>Журнал</h2>"       . $command_lines;
   2.247      $result.= "<h2 id='files'>Файлы</h2>"      . $files_section if $files_section;
   2.248 -    $result.= "<h2 id='stat'>Статистика</h2>"  . print_stat;
   2.249 +    $result.= "<h2 id='stat'>Статистика</h2>"  . print_stat_html;
   2.250      $result.= "<h2 id='help'>Справка</h2>"     . $Html_Help . "<br/>"; 
   2.251      $result.= "<h2 id='about'>О программе</h2>". $Html_About. "<br/>"; 
   2.252      $result.= print_footer_html;
   2.253  
   2.254      if ($output_filename eq "-") {
   2.255 +        binmode STDOUT, ":utf8";
   2.256          print $result;
   2.257      }
   2.258      else {
   2.259 -        open(OUT, ">", $output_filename)
   2.260 +        open(OUT, ">:utf8", $output_filename)
   2.261              or die "Can't open $output_filename for writing\n";
   2.262          print OUT $result;
   2.263          close(OUT);
   2.264 @@ -1140,7 +1216,10 @@
   2.265  <!-- ^^^ Tigra Hints ^^^ -->
   2.266  
   2.267  
   2.268 -    <h1 onmouseover="myHint.show('1')" onmouseout="myHint.hide()">Журнал лабораторных работ</h1>
   2.269 +    <div class='edit_link'>
   2.270 +    [ <a href='?action=edit&$filter_url'>править</a> ]
   2.271 +    </div>
   2.272 +    <h1 onmouseover="myHint.show('1')" onmouseout="myHint.hide()" class='lined_header'>Журнал лабораторных работ</h1>
   2.273  HEADER
   2.274      if (    $course_student 
   2.275              || $course_trainer 
   2.276 @@ -1334,7 +1413,12 @@
   2.277                    .  "<div class='file_navigation'><a href='#command:".$Files{$file}->{source_command_id}."'>"."&gt;"."</a></div>"
   2.278                    .  "<div class='filedata'><pre>".$Files{$file}->{content}."</pre></div>";
   2.279      }
   2.280 -    return "<div class='files_toc'>".collapse_list(\@toc)."</div>".$result;
   2.281 +    if ($result) {
   2.282 +        return "<div class='files_toc'>".collapse_list(\@toc)."</div>".$result;
   2.283 +    } 
   2.284 +    else {
   2.285 +        return "";
   2.286 +    }
   2.287  }
   2.288  
   2.289  
   2.290 @@ -1665,6 +1749,21 @@
   2.291      }
   2.292  JS
   2.293  
   2.294 +$SetCursorPosition_JS = <<JS;
   2.295 +function setCursorPosition(oInput,oStart,oEnd) {
   2.296 +    oInput.focus();
   2.297 +    if( oInput.setSelectionRange ) {
   2.298 +        oInput.setSelectionRange(oStart,oEnd);
   2.299 +    } else if( oInput.createTextRange ) {
   2.300 +        var range = oInput.createTextRange();
   2.301 +        range.collapse(true);
   2.302 +        range.moveEnd('character',oEnd);
   2.303 +        range.moveStart('character',oStart);
   2.304 +        range.select();
   2.305 +    }
   2.306 +}
   2.307 +JS
   2.308 +
   2.309  %Search_Machines = (
   2.310          "google" =>     {   "query" =>  "http://www.google.com/search?q=" ,
   2.311                      "icon"  =>  "$Config{frontend_google_ico}" },
     3.1 --- a/l3config.pm	Thu Mar 02 00:06:54 2006 +0200
     3.2 +++ b/l3config.pm	Thu Mar 02 20:13:31 2006 +0200
     3.3 @@ -1,6 +1,6 @@
     3.4 -
     3.5  package l3config;
     3.6  
     3.7 +use utf8;
     3.8  use Exporter;
     3.9  use vars qw(@ISA @EXPORT $VERSION);
    3.10  use Getopt::Long;
    3.11 @@ -163,5 +163,8 @@
    3.12  	read_config_file(\%file_config, $User_Config_File);
    3.13  	GetOptions(\%argv_config, map "$_=s", keys %Config);
    3.14  	%Config = (%Config, %file_config, %argv_config);
    3.15 +    for my $key (keys %Config) {
    3.16 +        utf8::decode($Config{$key});
    3.17 +    }
    3.18  }
    3.19