Code

Added FAI template editor.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 23 Jun 2009 08:09:38 +0000 (08:09 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 23 Jun 2009 08:09:38 +0000 (08:09 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13765 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/fai/admin/fai/class_faiTemplateEdit.inc [new file with mode: 0644]
gosa-plugins/fai/admin/fai/class_faiTemplateEntry.inc
gosa-plugins/fai/admin/fai/faiTemplateEdit.tpl [new file with mode: 0644]
gosa-plugins/fai/admin/fai/faiTemplateEntry.tpl

diff --git a/gosa-plugins/fai/admin/fai/class_faiTemplateEdit.inc b/gosa-plugins/fai/admin/fai/class_faiTemplateEdit.inc
new file mode 100644 (file)
index 0000000..7534e6c
--- /dev/null
@@ -0,0 +1,67 @@
+<?php
+
+class faiTemplateEdit extends plugin
+{
+  /* attribute list for save action */
+  var $config = "";
+  var $dn     = "";
+  var $value  = "";
+
+  // Encoding identification. Allows to warn the user.
+  var $enc_before_edit = "";
+  var $enc_after_edit = "";
+  var $write_protect = false;
+
+  function faiTemplateEdit (&$config, $dn, $value)
+  {
+    plugin::plugin ($config, $dn);
+    $this->value = $value;
+    $this->enc_before_edit = mb_detect_encoding($value);
+    if($this->enc_before_edit != "ASCII"){
+      $this->write_protect = TRUE;
+    }
+  }
+
+  function execute()
+  {
+    /* Call parent execute */
+    plugin::execute();
+
+    /* We now split cn/FAItemplatePath to make things more clear... */
+    $smarty     = get_smarty();
+    $smarty->assign("templateValue",htmlspecialchars(($this->value)));
+    $smarty->assign("write_protect",$this->write_protect);
+    return($smarty->fetch(get_template_path('faiTemplateEdit.tpl', TRUE)));
+  }
+
+  /* Save data to object */
+  function save_object()
+  {
+    if(isset($_POST['templateValue']) && !$this->write_protect){
+      $this->value = get_post('templateValue');
+      $this->enc_after_edit = mb_detect_encoding($this->value);
+    }
+    if(isset($_POST['editAnyway'])) $this->write_protect = FALSE;
+  }
+
+
+  /* Check supplied data */
+  function check()
+  {
+    $message = array();
+    if(!$this->write_protect && $this->enc_after_edit !== $this->enc_before_edit ){
+      $msg = sprintf(_("The file 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>");
+      $message[] = $msg;
+      $this->enc_before_edit = $this->enc_after_edit;
+    }
+    return($message);
+  }
+
+  function save()
+  {
+    return($this->value);
+  }
+}
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
index ad1451a3695dcd6e7f34e4008cefe5d4e7a8ac91..2902562ee9d7d4ebf4bb35ba39d0c5c1b0657efe 100644 (file)
@@ -86,16 +86,42 @@ class faiTemplateEntry extends plugin
     if(isset($_GET['getFAItemplate'])){
       send_binary_content($this->FAItemplateFile,$this->cn.".FAItemplate");
     }
-    $status= _("no file uploaded yet");
 
+    /* File edit requested */
+    if(isset($_GET['editFAItemplate'])){
+      $this->dialog = new faiTemplateEdit($this->config,$this->dn,$this->FAItemplateFile);
+    }
+
+    /* File edit requested, was canceled  */
+    if(isset($_POST['templateEditCancel'])){
+      $this->dialog = null;
+    }
+
+    /* File edit requested, was canceled  */
+    if($this->dialog instanceOf faiTemplateEdit && isset($_POST['templateEditSave'])){
+      $this->dialog->save_object();
+      $msgs = $this->dialog->check();
+      if(count($msgs)){
+        msg_dialog::displayChecks($msgs);
+      }else{
+        $this->FAItemplateFile = $this->dialog->save();
+        $this->dialog = null;
+      }
+    }
+
+    /* Display opened dialog */
+    if($this->dialog){
+      $this->dialog->save_object();
+      return($this->dialog->execute());
+    }
+
+    $status= _("no file uploaded yet");
     $bStatus = false; // Hide download icon on default 
-    
     if(strlen($this->FAItemplateFile)){
-
       $status= sprintf(_("exists in database (size: %s bytes)"),strlen($this->FAItemplateFile));
       $bStatus = true;  // Display download icon 
     }
+
     $smarty->assign("status",$status);
     $smarty->assign("bStatus",$bStatus);
 
diff --git a/gosa-plugins/fai/admin/fai/faiTemplateEdit.tpl b/gosa-plugins/fai/admin/fai/faiTemplateEdit.tpl
new file mode 100644 (file)
index 0000000..a8b2526
--- /dev/null
@@ -0,0 +1,19 @@
+<h2>Template entry</h2>
+
+{if $write_protect}
+{t}This FAI template is write protected due to its character encoding, editing may brake this file!{/t}
+<br><input type='submit' value='{t}Edit anyway{/t}' name='editAnyway'>
+{/if}
+
+<textarea {if $write_protect} disabled {/if}
+  style='width:100%; height: 350px;'
+  {if !$write_protect}name="templateValue"{/if}
+>{$templateValue}</textarea>
+
+<p class='seperator'>
+  <div style='text-align:right;'>
+    <input type='submit' name='templateEditSave' value='{msgPool type=okButton}'>
+    &nbsp;
+    <input type='submit' name='templateEditCancel' value='{msgPool type=cancelButton'}'>
+  </div>
+</p>
index 789dac439c54939cdc64178f6630d9c684d496fe..f2a7cbf6631b544120103c0bf1764e4644ab87e3 100644 (file)
 
 <table width="100%" summary="">
 <tr>
-  <td colspan=2><h2><img class="middle" alt="" src="plugins/fai/images/fai_template.png" title="{t}Template attributes{/t}">&nbsp;{t}Template attributes{/t}</h2></td>
+  <td colspan=2>
+    <h2>
+      <img class="center" alt="" 
+        src="plugins/fai/images/fai_template.png" 
+        title="{t}Template attributes{/t}">&nbsp;{t}Template attributes{/t}
+    </h2>
+  </td>
 </tr>
 <tr>
   <td style="vertical-align:top;width:50%;border-right:1px solid #B0B0B0">
-   <table summary="">
+  <table summary="">
     <tr>
-               <td style="vertical-align:top">
-                       <LABEL for="FAItemplateFile">
-                               {t}File{/t}{$must}&nbsp;
-                       </LABEL>
-                       </td>
-               <td style="vertical-align:top" class="center">
-                       {$status}
-                       {if $bStatus}
-                         <a href="{$plug}&amp;getFAItemplate">
-                               <img class="center" alt="{t}Save template{/t}..." title="{t}Save template{/t}..." src="images/save.png" border="0" />
-                         </a>
-                       {/if}
-                       <br>
-                       <br>
+      <td>
+        {t}File{/t}{$must}:&nbsp; {$status}
+        {if $bStatus}
+          <a href="{$plug}&amp;getFAItemplate">
+          <img class="center" alt="{t}Save template{/t}..." 
+            title="{t}Save template{/t}..." src="images/save.png" border="0" />
+          </a>
+          <a href="{$plug}&amp;editFAItemplate">
+          <img class="center" alt="{t}Edit template{/t}..." 
+            title="{t}Edit template{/t}..." src="images/lists/edit.png" border="0" />
+          </a>
+        {/if}
+      </td>
+    </tr>
+    {if $bStatus}
+    <tr>
+      <td>
+                   {t}Full path{/t}:&nbsp; <i>{$FAItemplatePath}</i>
+      </td>
+    </tr>
+    {/if}
+    <tr>
+                 <td style="vertical-align:top" class="center">
 {render acl=$FAItemplateFileACL}
-                       <input type="file" name="FAItemplateFile" value="" id="FAItemplateFile">
+                         <input type="file" name="FAItemplateFile" value="" id="FAItemplateFile">
 {/render}
 {render acl=$FAItemplateFileACL}
-                       &nbsp;<input type="submit" value="{t}Upload{/t}" name="TmpFileUpload">
-{/render}
-                       <br>
-                       <br>
-                       </td>
-       </tr><tr>
-                       <td>
-                               {t}Full path{/t}&nbsp;
-                               </td>
-                       <td>
-{render acl=$FAItemplatePathACL}
-                               <i>{$FAItemplatePath}</i>
+                         <input type="submit" value="{t}Upload{/t}" name="TmpFileUpload">
 {/render}
-                               </td>
-               </tr>
-               </table>
+                 </td>
+    </tr>
+       </table>
        </td>
        <td>
          <table summary="">