d3bc4fb432caab066a387a21aeb8c6372a1bbb02
1 <?php
3 class TemplateWidget_textEditor extends TemplateWidget
4 {
5 protected $value = array();
6 protected $write_protect = FALSE;
8 function __construct(&$config, $name, $value, $description,$syntax,$required,$type,$display,$values)
9 {
10 parent:: __construct($config, $name, $value, $description,$syntax,$required,$type,$display,$values);
12 // Keep an eye on dangerous encodings, we may break scripts while editing.
13 $this->mb_extension = function_exists("mb_detect_encoding");
14 if($this->mb_extension){
15 $this->enc_before_edit = mb_detect_encoding($this->value);
16 if($this->enc_before_edit != "ASCII"){
17 $this->write_protect = TRUE;
18 }
19 }
20 }
23 function render()
24 {
25 $smarty = get_smarty();
26 $smarty->assign("postName", set_post($this->postName));
27 $smarty->assign("write_protect", set_post($this->write_protect));
28 $smarty->assign("value", set_post($this->value));
29 return($smarty->fetch(get_template_path("TemplateWidget_textEditor.tpl", TRUE, dirname(__FILE__))));
30 }
33 function save_object()
34 {
35 TemplateWidget::save_object();
36 if(isset($_POST['editAnyway'])) $this->write_protect = FALSE;
38 if(isset($_POST['ImportUpload'])){
39 if(($_FILES['ImportFile']['error']!=0)){
40 msg_dialog::display(_("Error"), msgPool::incorrectUpload(), ERROR_DIALOG);
41 }elseif(($_FILES['ImportFile']['size']==0)){
42 msg_dialog::display(_("Error"), msgPool::incorrectUpload(_("file is empty")), ERROR_DIALOG);
43 }else{
44 $str = file_get_contents(gosa_file_name($_FILES['ImportFile']['tmp_name']));
45 $this->value = $str;
47 // Check encoding again
48 if($this->mb_extension){
49 $this->enc_before_edit = mb_detect_encoding($this->value);
50 if($this->enc_before_edit != "ASCII"){
51 $this->write_protect = TRUE;
52 }
53 }
54 }
55 }
56 $this->enc_after_edit = mb_detect_encoding($this->value);
57 }
60 /*! \brief Check the value entry using the provieded syntax.
61 * @return Array Returns a list of errors
62 */
63 function check()
64 {
65 $msgs = TemplateWidget::check();
66 if($this->mb_extension && !$this->write_protect && $this->enc_after_edit !== $this->enc_before_edit ){
67 $msg = sprintf(_("The text encodig has changed from %s to %s. Do you really want to save?"),
68 bold($this->enc_before_edit),bold($this->enc_after_edit));
69 $msgs[] = $msg;
70 $this->enc_before_edit = $this->enc_after_edit;
71 }
72 return($msgs);
73 }
74 }
75 ?>