Code

get rid of the div stuff
[gosa.git] / gosa-plugins / fai / admin / fai / class_faiTemplateEdit.inc
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;
14   var $mb_extension = TRUE;
16   function faiTemplateEdit (&$config, $dn, $value)
17   {
18     plugin::plugin ($config, $dn);
19     if(!function_exists("mb_detect_encoding")){
20       $this->mb_extension = FALSE;
21     }else{
22       $this->value = $value;
23       $this->enc_before_edit = mb_detect_encoding($value);
24       if($this->enc_before_edit != "ASCII"){
25         $this->write_protect = TRUE;
26       }
27     }
28   }
30   function execute()
31   {
32     /* Call parent execute */
33     plugin::execute();
35     /* We now split cn/FAItemplatePath to make things more clear... */
36     $smarty     = get_smarty();
37     $smarty->assign("templateValue",htmlspecialchars(($this->value)));
38     $smarty->assign("write_protect",$this->write_protect);
39     $smarty->assign("mb_extension",$this->mb_extension);
40     return($smarty->fetch(get_template_path('faiTemplateEdit.tpl', TRUE)));
41   }
43   /* Save data to object */
44   function save_object()
45   { 
46     if(!$this->mb_extension) return;
47     if(isset($_POST['templateValue']) && !$this->write_protect){
48       $this->value = get_post('templateValue');
49       $this->enc_after_edit = mb_detect_encoding($this->value);
50     }
51     if(isset($_POST['editAnyway'])) $this->write_protect = FALSE;
52   }
55   /* Check supplied data */
56   function check()
57   {
58     $message = array();
59     if($this->mb_extension && !$this->write_protect && $this->enc_after_edit !== $this->enc_before_edit ){
60       $msg = sprintf(_("The file encodig has changed from '%s' to '%s'. Do you really want to save?"),
61         "<i>".$this->enc_before_edit."</i>","<i>".$this->enc_after_edit."</i>");
62       $message[] = $msg;
63       $this->enc_before_edit = $this->enc_after_edit;
64     }
65     return($message);
66   }
68   function save()
69   {
70     return($this->value);
71   }
72 }
73 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
74 ?>