1 <?php
3 class faiTemplateEdit extends plugin
4 {
5 /* attribute list for save action */
6 var $config = "";
7 var $dn = "";
8 var $value = "";
10 // Encoding identification. Allows to warn the user.
11 var $enc_before_edit = "";
12 var $enc_after_edit = "";
13 var $write_protect = false;
15 function faiTemplateEdit (&$config, $dn, $value)
16 {
17 plugin::plugin ($config, $dn);
18 $this->value = $value;
19 $this->enc_before_edit = mb_detect_encoding($value);
20 if($this->enc_before_edit != "ASCII"){
21 $this->write_protect = TRUE;
22 }
23 }
25 function execute()
26 {
27 /* Call parent execute */
28 plugin::execute();
30 /* We now split cn/FAItemplatePath to make things more clear... */
31 $smarty = get_smarty();
32 $smarty->assign("templateValue",htmlspecialchars(($this->value)));
33 $smarty->assign("write_protect",$this->write_protect);
34 return($smarty->fetch(get_template_path('faiTemplateEdit.tpl', TRUE)));
35 }
37 /* Save data to object */
38 function save_object()
39 {
40 if(isset($_POST['templateValue']) && !$this->write_protect){
41 $this->value = get_post('templateValue');
42 $this->enc_after_edit = mb_detect_encoding($this->value);
43 }
44 if(isset($_POST['editAnyway'])) $this->write_protect = FALSE;
45 }
48 /* Check supplied data */
49 function check()
50 {
51 $message = array();
52 if(!$this->write_protect && $this->enc_after_edit !== $this->enc_before_edit ){
53 $msg = sprintf(_("The file encodig has changed from '%s' to '%s', do you really want to save?"),
54 "<i>".$this->enc_before_edit."</i>","<i>".$this->enc_after_edit."</i>");
55 $message[] = $msg;
56 $this->enc_before_edit = $this->enc_after_edit;
57 }
58 return($message);
59 }
61 function save()
62 {
63 return($this->value);
64 }
65 }
66 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
67 ?>