Code

Updated divlists.
[gosa.git] / plugins / admin / fai / class_faiTemplateEntry.inc
index 9fec3e07b879fcd8ca7109f37a681acba53b1daa..7a3c48ddf370042b058dca626bc8da9956fded21 100644 (file)
@@ -32,7 +32,7 @@ class faiTemplateEntry extends plugin
   {
     plugin::plugin ($config, $dn);
 
-    if($dn != "new"){
+    if((isset($object['cn'])) && (!empty($object['cn']))){
       $this->orig_cn= $object['cn'];
       $this->dn=$object['dn'];
       foreach($object as $name=>$value){
@@ -46,15 +46,22 @@ class faiTemplateEntry extends plugin
 
     }else{
       $this->status = "new";
-      $this->orig_cn       = false;
+      $this->orig_cn= false;
     }
 
     $this->user = explode( '.', $this->FAIowner );
     $this->group = $this->user[1];
     $this->user = $this->user[0];
+
     $_SESSION['binary'] = $this->FAItemplateFile;
     $_SESSION['binarytype'] = 'octet-stream';
     $_SESSION['binaryfile'] = basename( $this->FAItemplatePath );
+
+    if(!empty($this->dn) && $this->dn != "new"){
+      $ldap = $this->config->get_ldap_link();
+      $_SESSION['binary'] =$ldap->get_attribute($this->dn,"FAItemplateFile");
+      $this->FAItemplateFile = $_SESSION['binary'];
+    }
     
     $this->FAImode= sprintf("%0.4s", $this->FAImode)." ";
   }
@@ -62,15 +69,15 @@ class faiTemplateEntry extends plugin
 
   function execute()
   {
-       /* Call parent execute */
-       plugin::execute();
+    /* Call parent execute */
+    plugin::execute();
 
     /* Fill templating stuff */
     $smarty     = get_smarty();
     $smarty->assign("rand", rand(0, 10000));
     $display = "";
 
-    if(isset($_POST['TmpFileUpload'])){
+    if(isset($_POST['TmpFileUpload']) && $this->acl_is_writeable("FAItemplateFile")){
       if($str=file_get_contents($_FILES['FAItemplateFile']['tmp_name'])){
         $this->FAItemplateFile = $str;
 
@@ -90,6 +97,7 @@ class faiTemplateEntry extends plugin
     $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 
     }
@@ -126,54 +134,50 @@ class faiTemplateEntry extends plugin
     $smarty->assign("FAItemplateFile","");
 
     foreach($this->attributes as $attr){
-      if(($this->FAIstate == "freeze") || (chkacl($this->acl,$attr)!= "")){
-        $smarty->assign($attr."ACL"," disabled ");
-      }else{
-        $smarty->assign($attr."ACL","  ");
-      }
+      $smarty->assign($attr."ACL",$this->getacl($attr,preg_match("/freeze/",$this->FAIstate)));
     }
 
-    $display.= $smarty->fetch(get_template_path('faiTemplateEntry.tpl', TRUE));
+    $display.=  $smarty->fetch(get_template_path('faiTemplateEntry.tpl', TRUE));
     return($display);
   }
 
   /* Save data to object */
   function save_object()
   {
-    if (!isset($_POST['FAItemplatePath'])){
-      return;
-    }
+    /* Check if form is posted and we are not freezed */
     if((isset($_POST['SubObjectFormSubmitted'])) && ($this->FAIstate != "freeze")){
-      foreach($this->attributes as $attrs){
-        if($attrs == "FAItemplateFile") 
-          continue;
-        if($attrs == "FAIowner") {
-          $this->$attrs = $_POST["user"] . '.' . $_POST["group"];
-          continue;
-        }
-        if(isset($_POST[$attrs])){
-          $this->$attrs = $_POST[$attrs];
-        }else{
-          $this->$attrs = "";
-        }
+
+      plugin::save_object();
+
+      /* Set user.group (FAIowner) attribute */  
+      if(isset($_POST['group']) && isset($_POST["user"]) && $this->acl_is_writeable("FAIowner")){
+        $this->FAIowner = $_POST["user"].'.'.$_POST["group"];
+        $this->user = $_POST['user'];
+        $this->group= $_POST['group'];
       }
-      /* Save mode */
-      $tmode= "";
-      foreach (array("s", "u", "g", "o") as $type){
-        $nr= 1;
-        $dest= 0;
-        while ($nr < 5){
-          if (isset($_POST["$type$nr"])){
-            $dest+= $nr;
+
+      /* Check if permissions have changed */
+      if($this->acl_is_writeable("FAImode")){
+
+        /* Save mode */
+        $tmode= "";
+        foreach (array("s", "u", "g", "o") as $type){
+          $nr= 1;
+          $dest= 0;
+          while ($nr < 5){
+            if (isset($_POST["$type$nr"])){
+              $dest+= $nr;
+            }
+            $nr+= $nr;
           }
-          $nr+= $nr;
+          $tmode= $tmode.$dest;
         }
-        $tmode= $tmode.$dest;
+        $this->FAImode= $tmode;
       }
-      $this->FAImode= $tmode;
     }
   }
 
+
   /* Check supplied data */
   function check()
   {
@@ -226,6 +230,29 @@ class faiTemplateEntry extends plugin
 
     return($tmp);
   }
+
+  
+  /* Return plugin informations for acl handling */
+  function plInfo()
+  {
+    return (array(
+          "plShortName" => _("Template entry"),
+          "plDescription" => _("FAI template entry"),
+          "plSelfModify"  => FALSE,
+          "plDepends"     => array(),
+          "plPriority"    => 25,
+          "plSection"     => array("administration"),
+          "plCategory"    => array("fai"),
+          "plProvidedAcls" => array(
+            "cn"                => _("Name"),
+            "description"       => _("Description"),
+            "FAItemplateFile"   => _("Template file"),
+            "FAItemplatePath"   => _("Template path"),
+            "FAIowner"          => _("File owner"),
+            "FAImode"           => _("File permissions"))
+          ));
+  }
+
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>