+} elsif ($q->path_info =~ m#template#) {
+
+ my @actions;
+
+ if ($q->param('save_template')) {
+
+ my $tmpl = $iconv_loc->convert( $q->param('tt_template') ) || die "no template?";
+ sub _conv_js {
+ my $t = shift || return;
+ return $iconv_loc->convert(chr(hex($t)));
+ }
+ $tmpl =~ s/%u([a-fA-F0-9]{4})/_conv_js($1)/gex;
+
+ my $tmpl_file = $out->{'include_path'} . '/' . $template;
+ write_file($tmpl_file . '.new', $tmpl) || die "can't save $tmpl_file: $!";
+ rename $tmpl_file . '.new', $tmpl_file || die "can't rename to $tmpl_file: $!";
+
+ print qq{<response>
+<action type='html' target='div_status' errorCode='' errorMessage='' >
+<tt>$template</tt> saved
+</action>
+<action type='js'>
+<!--
+iwfShow('div_status', 1);
+reload_rec();
+iwfHideGentlyDelay('div_status', 2, 2000, 1);
+-->
+</action>
+</response>
+ };
+ exit;
+
+ }
+
+ my $tmpl = read_file($out->{'include_path'} . '/' . $template) || die "can't read template $template: $!";
+ $tmpl = $q->escapeHTML($iconv_utf8->convert($tmpl));
+
+ print qq{<response>
+<action type='html' target='div_template' errorCode='' errorMessage='' >
+<pre>}, Dumper($q->Vars), qq{</pre>
+
+<form name="frmEditor" action="$self" method="post" iwfTarget="div_status" >
+
+<textarea name="tt_template" cols="80" rows="10" style="display: block;">
+$tmpl
+</textarea>
+
+<br/>
+<input type="button" name="save_template" value="Save" onclick="javascript:iwfRequest(this);" />
+<!--
+<input type="checkbox" name="checkin_template" id="checkin_checkbox" label="checkin" /> checkin
+-->
+ <span id="div_status" style="color: #808080;">idle</span>
+
+<input type='hidden' value='hidden post value' name='hidValue' />
+
+</form>
+</action>
+<action type='js'>
+<!--
+iwfHideGentlyDelay('div_status', 2, 2000, 1);
+-->
+</action>
+</response>
+ };
+
+ exit;
+