Code

Added textEditor widget
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 4 Oct 2010 06:45:30 +0000 (06:45 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 4 Oct 2010 06:45:30 +0000 (06:45 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19893 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/goto/admin/systems/goto/Config/TemplateWidget_textEditor.tpl [new file with mode: 0644]
gosa-plugins/goto/admin/systems/goto/Config/class_TemplateWidget_textEditor.inc [new file with mode: 0644]
gosa-plugins/goto/admin/systems/goto/Config/puppet.tpl

diff --git a/gosa-plugins/goto/admin/systems/goto/Config/TemplateWidget_textEditor.tpl b/gosa-plugins/goto/admin/systems/goto/Config/TemplateWidget_textEditor.tpl
new file mode 100644 (file)
index 0000000..4f2ae45
--- /dev/null
@@ -0,0 +1,12 @@
+{if $write_protect}
+  {t}The text is write protected, due to its encoding. Editing may break it!{/t}
+  <br>
+  <button type='submit' name='editAnyway'>{t}Edit anyway{/t}</button>
+{/if}
+<textarea {if $write_protect} disabled {/if} {if !$write_protect} name="{$postName}" {/if}
+    style="width:100%;height:300px;" id="{$postName}"
+    rows="20" cols="120">{$value}</textarea>
+<div>
+  <input type="file" name="ImportFile">&nbsp;
+  <button type='submit' name='ImportUpload'>{t}Import text{/t}</button>
+</div>
diff --git a/gosa-plugins/goto/admin/systems/goto/Config/class_TemplateWidget_textEditor.inc b/gosa-plugins/goto/admin/systems/goto/Config/class_TemplateWidget_textEditor.inc
new file mode 100644 (file)
index 0000000..93b7951
--- /dev/null
@@ -0,0 +1,75 @@
+<?php
+
+class TemplateWidget_textEditor extends TemplateWidget
+{
+    protected $value = array();
+    protected $write_protect = FALSE;
+    
+    function __construct(&$config, $name, $value, $description,$syntax,$required,$type,$display,$values)
+    {
+        parent:: __construct($config, $name, $value, $description,$syntax,$required,$type,$display,$values);
+
+        // Keep an eye on dangerous encodings, we may break scripts while editing.
+        $this->mb_extension = function_exists("mb_detect_encoding");
+        if($this->mb_extension){
+            $this->enc_before_edit = mb_detect_encoding($this->value);
+            if($this->enc_before_edit != "ASCII"){
+                $this->write_protect = TRUE;
+            }
+        }
+    }
+
+
+    function render()
+    {
+        $smarty = get_smarty();
+        $smarty->assign("postName", set_post($this->postName));
+        $smarty->assign("write_protect", set_post($this->write_protect));
+        $smarty->assign("value", set_post($this->value));
+        return($smarty->fetch(get_template_path("TemplateWidget_textEditor.tpl", TRUE, dirname(__FILE__))));
+    }
+
+
+    function save_object()
+    {
+        TemplateWidget::save_object();
+        if(isset($_POST['editAnyway'])) $this->write_protect = FALSE;
+
+        if(isset($_POST['ImportUpload'])){
+            if(($_FILES['ImportFile']['error']!=0)){
+                msg_dialog::display(_("Error"), msgPool::incorrectUpload(), ERROR_DIALOG);
+            }elseif(($_FILES['ImportFile']['size']==0)){
+                msg_dialog::display(_("Error"), msgPool::incorrectUpload(_("file is empty")), ERROR_DIALOG);
+            }else{
+                $str = file_get_contents($_FILES['ImportFile']['tmp_name']);
+                $this->value = $str;
+
+                // Check encoding again
+                if($this->mb_extension){
+                    $this->enc_before_edit = mb_detect_encoding($this->value);
+                    if($this->enc_before_edit != "ASCII"){
+                        $this->write_protect = TRUE;
+                    }
+                }
+            }
+        }
+        $this->enc_after_edit = mb_detect_encoding($this->value);
+    }
+
+
+    /*! \brief  Check the value entry using the provieded syntax.
+     * @return  Array   Returns a list of errors
+     */
+    function check()
+    {
+        $msgs = TemplateWidget::check();
+        if($this->mb_extension && !$this->write_protect && $this->enc_after_edit !== $this->enc_before_edit ){
+            $msg = sprintf(_("The text encodig has changed from '%s' to '%s'. Do you really want to save?"),
+                    "<i>".$this->enc_before_edit."</i>","<i>".$this->enc_after_edit."</i>");
+            $msgs[] = $msg;
+            $this->enc_before_edit = $this->enc_after_edit;
+        }
+        return($msgs);
+    }
+}
+?>
index 799343e28046454267ad7600316810138da4c1f6..aceefdb0cf818d9380bd42262248b46cfba55a01 100644 (file)
             </td>
         </tr>
     </table>
+    {$textEditorName}
+    {$textEditor}
 
-    {$fixedList}
     {$fixedListName}
+    {$fixedList}
 {/if}
 {if $type == 'PuppetTemplate'}
     <table>