From bea18a6ee5962797ff0cf1bcbd4594857e827ea4 Mon Sep 17 00:00:00 2001 From: hickert Date: Tue, 23 Jun 2009 08:09:38 +0000 Subject: [PATCH] Added FAI template editor. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13765 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../fai/admin/fai/class_faiTemplateEdit.inc | 67 ++++++++++++++++++ .../fai/admin/fai/class_faiTemplateEntry.inc | 34 ++++++++-- .../fai/admin/fai/faiTemplateEdit.tpl | 19 ++++++ .../fai/admin/fai/faiTemplateEntry.tpl | 68 ++++++++++--------- 4 files changed, 152 insertions(+), 36 deletions(-) create mode 100644 gosa-plugins/fai/admin/fai/class_faiTemplateEdit.inc create mode 100644 gosa-plugins/fai/admin/fai/faiTemplateEdit.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 index 000000000..7534e6c0d --- /dev/null +++ b/gosa-plugins/fai/admin/fai/class_faiTemplateEdit.inc @@ -0,0 +1,67 @@ +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?"), + "".$this->enc_before_edit."","".$this->enc_after_edit.""); + $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: +?> diff --git a/gosa-plugins/fai/admin/fai/class_faiTemplateEntry.inc b/gosa-plugins/fai/admin/fai/class_faiTemplateEntry.inc index ad1451a36..2902562ee 100644 --- a/gosa-plugins/fai/admin/fai/class_faiTemplateEntry.inc +++ b/gosa-plugins/fai/admin/fai/class_faiTemplateEntry.inc @@ -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 index 000000000..a8b2526c8 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/faiTemplateEdit.tpl @@ -0,0 +1,19 @@ +

Template entry

+ +{if $write_protect} +{t}This FAI template is write protected due to its character encoding, editing may brake this file!{/t} +
+{/if} + + + +

+

+ +   + +
+

diff --git a/gosa-plugins/fai/admin/fai/faiTemplateEntry.tpl b/gosa-plugins/fai/admin/fai/faiTemplateEntry.tpl index 789dac439..f2a7cbf66 100644 --- a/gosa-plugins/fai/admin/fai/faiTemplateEntry.tpl +++ b/gosa-plugins/fai/admin/fai/faiTemplateEntry.tpl @@ -53,46 +53,50 @@ - + + +

 {t}Template attributes{/t}

+

+  {t}Template attributes{/t} +

+
- +
- - + + {if $bStatus} + + + + {/if} + + - - - - -
- - - {$status} - {if $bStatus} - - {t}Save template{/t}... - - {/if} -
-
+
+ {t}File{/t}{$must}:  {$status} + {if $bStatus} + + {t}Save template{/t}... + + + {t}Edit template{/t}... + + {/if} +
+ {t}Full path{/t}:  {$FAItemplatePath} +
{render acl=$FAItemplateFileACL} - + {/render} {render acl=$FAItemplateFileACL} -   -{/render} -
-
-
- {t}Full path{/t}  - -{render acl=$FAItemplatePathACL} - {$FAItemplatePath} + {/render} -
+
-- 2.30.2