Code

Updated divlists.
[gosa.git] / plugins / admin / fai / class_faiScript.inc
index 1fbd6d64c7b8e75f7c616dfbd05d83404956055c..c130a568d6cba899f26716d82ed72edf824ce727 100644 (file)
@@ -38,6 +38,8 @@ class faiScript extends plugin
 
   var $FAIstate         ="";
 
+  var $ui;
+
   function faiScript ($config, $dn= NULL)
   {
     /* Load Attributes */
@@ -67,6 +69,14 @@ class faiScript extends plugin
       $ldap->search("(&(objectClass=FAIclass)(objectClass=".$this->subClass."))",$attrs_to_search);
 
       while($object = $ldap->fetch()){
+
+        /* Skip objects, that are tagged as removed */
+        if(isset($object['FAIstate'][0])){
+          if(preg_match("/removed$/",$object['FAIstate'][0])){
+            continue;
+          }
+        }
+
         /* Set status for save management */
         $objects = array();
         $objects['status']      = "FreshLoaded";
@@ -75,6 +85,7 @@ class faiScript extends plugin
         $this->SubObjects[$objects['cn']] = $objects;
       }
     }
+    $this->ui = get_userinfo();
   }
 
 
@@ -108,6 +119,20 @@ class faiScript extends plugin
     return($object);
   }
 
+  
+  /* Return a valid dn to fetch acls. Because 'new' will not work. */
+  function acl_base_for_current_object($dn)
+  {
+    if($dn == "new"){
+      if($this->dn == "new"){
+        $dn= "cn=dummy,".$_SESSION['CurrentMainBase'];
+      }else{
+        $dn = $this->dn;
+      }
+    }
+    return($dn);
+  }
+
 
   function execute()
   {
@@ -120,14 +145,8 @@ class faiScript extends plugin
 
     /* Add new sub object */
     if(isset($_POST['AddSubObject'])){
-
-      $c_dn = $this->dn;
-      if($c_dn == "new"){
-        $c_dn = $_SESSION['CurrentMainBase'];
-      }
-
       $this->dialog= new $this->subClassName($this->config,"new");
-      $this->dialog->set_acl_base($c_dn);
+      $this->dialog->set_acl_base($this->acl_base);
       $this->dialog->set_acl_category("fai");
       $this->is_dialog=true;
     }
@@ -136,45 +155,48 @@ class faiScript extends plugin
       $_SESSION['objectinfo']= $this->dn;
     }
 
-
-    /* New Listhandling 
-     */
+    /* Handle posts */
     $once = true;
     foreach($_POST as $name => $value){
+
+      /* Edit script posted */
       if(preg_match("/^editscript_/",$name)&&($once)){
 
+        /* Get posted entry id */
         $once = false;
         $entry = preg_replace("/^editscript_/","",$name);
         $entry = base64_decode(preg_replace("/_.*/","",$entry));
 
+        /* Get object, and load missing entry values */
         $obj  = $this->SubObjects[$entry];
         if($obj['status'] == "FreshLoaded"){
           $obj  = $this->get_object_attributes($obj,$this->sub_Load_Later);
         }
+
+        /* Create new dialog and set acl attributes  */
         $this->dialog= new $this->subClassName($this->config,$this->dn,$obj);
-        $this->dialog->set_acl_base($this->dn);
+        $this->dialog->set_acl_base($this->acl_base_for_current_object($obj['dn']));
         $this->dialog->set_acl_category("fai");
 
-
+        /* Assign some additional dialog informations like headline and parent  */
         $_SESSION['objectinfo'] = $obj['dn'];
         $this->dialog->parent = &$this;
         $this->is_dialog=true;
       }
+
+      /* Delete script requested */
       if(preg_match("/^deletescript_/",$name)&&($once)){
+
+        /* Parse out posted entry id */
         $once = false;
         $entry = preg_replace("/^deletescript_/","",$name);
         $entry = base64_decode(preg_replace("/_.*/","",$entry));
 
-    
-        $dn = $this->SubObjects[$entry]['dn'];
-
-        if($dn == "new"){
-          $dn = $_SESSION['CurrentMainBase'];
-        }
-        $acl = $this->ui -> get_permissions($dn,"fai/faiScriptEntry")  ;
-
+        /* Check acls, are we allowed to delete an entry */
+        $acl = $this->ui->get_permissions($this->acl_base_for_current_object($this->SubObjects[$entry]['dn']),"fai/faiScriptEntry")  ;
         if(preg_match("/d/",$acl)){
-          if(($this->SubObjects[$entry]['status'] == "edited")||($this->SubObjects[$entry]['status'] == "FreshLoaded")){
+          $status = $this->SubObjects[$entry]['status'];
+          if($status == "edited" || $status == "FreshLoaded"){
             $this->SubObjects[$entry]['status']= "delete";
           }else{
              unset($this->SubObjects[$entry]);
@@ -182,22 +204,12 @@ class faiScript extends plugin
         }
       }
     }
-    ///// Ende new list handling
 
 
-    /* Edit selected Sub Object */
-    if((isset($_POST['EditSubObject']))&&(isset($_POST['SubObject']))){
-      $script = $_POST['SubObject'][0];
-      $this->dialog= new $this->subClassName($this->config,$this->dn,$this->SubObjects[$script]);
-      $this->dialog->set_acl_base($_SESSION['CurrentMainBase']);
-      $this->dialog->set_acl_category("fai");
-      $_SESSION['objectinfo'] = $this->SubObjects[$script]['dn'];
-      $this->is_dialog=true;
-    }
-
-
-    /* Save Dialog */
+    /* Save the edited entry */
     if(isset($_POST['SaveSubObject'])){
+
+      /* Check if there are still errors remaining that must be fixed before saving */
       $this->dialog->save_object();
       $msgs = $this->dialog->check();
       if(count($msgs)>0){
@@ -205,10 +217,14 @@ class faiScript extends plugin
           print_red($msg);
         }
       }else{
-           /* Get return object */
+
+        /* Get return object */
         $obj = $this->dialog->save();
+
+        /* If we have renamed the script entry, we must remove the old entry */
         if(isset($obj['remove'])){
 
+          /* Get old entry values */
           $old_stat = $this->SubObjects[$obj['remove']['from']]['status'];
 
           /* Depending on status, set new status */
@@ -217,10 +233,14 @@ class faiScript extends plugin
           }elseif($this->SubObjects[$obj['remove']['from']]['status']=="new"){
             unset($this->SubObjects[$obj['remove']['from']]);
           }
+
+          /* Append the new entry */
           $obj['status'] = "new";
           $this->SubObjects[$obj['remove']['to']] = $obj;
           unset($this->SubObjects[$obj['remove']['to']]['remove']);
         }else{
+  
+          /* Set new status and append the entry */
           if($obj['status'] == "FreshLoaded"){
             $obj['status'] = "edited";
           }
@@ -265,13 +285,11 @@ class faiScript extends plugin
     $divlist->setHeight(400);
     foreach($this->getList(true) as $key => $name){
 
-      $dn= $name['dn'];
-      if($dn == "new"){
-        $dn = $_SESSION['CurrentMainBase'];
-      }
-      $acl = $this->ui -> get_permissions($dn,"fai/faiScriptEntry")  ;
+      $dn= $this->acl_base_for_current_object($name['dn']);
+      $acl = $this->ui->get_permissions($dn,"fai/faiScriptEntry")  ;
       $act = "";
       
+      /* Hide delete icon if this object is freezed */
       if($this->FAIstate == "freeze"){
         $act .= "<input type='image' src='images/edit.png'      name='editscript_%s'    title='"._("edit")."' alt='"._("edit")."'>";
       }else{
@@ -281,7 +299,9 @@ class faiScript extends plugin
         }
       }
 
-      if(($this->SubObjects[$key]['status'] == "new") || ($this->SubObjects[$key]['dn'] == "new")){
+      /* Check acls for download icon */
+      $s_acl = $this->ui->get_permissions($dn,"fai/faiScriptEntry","FAIscript")  ;
+      if(($this->SubObjects[$key]['status'] == "new") || ($this->SubObjects[$key]['dn'] == "new") || !preg_match("/r/",$s_acl)){
         $down = "";
       }else{
         $down = "<a href='getFAIscript.php?id=".base64_encode($name['dn'])."' >
@@ -289,13 +309,18 @@ class faiScript extends plugin
           </a>"; 
       } 
 
-      $divlist->AddEntry(array( array("string"=>$name['name']),
-            array("string"=>$down , "attach" => "style='width:20px;'"),
-            array("string"=>str_replace("%s",base64_encode($key),$act),
-              "attach"=>"style='border-right: 0px;width:50px;text-align:right;'")));
+      /* Check if we are allowed to view this object */
+      $s_acl = $this->ui->get_permissions($dn,"fai/faiScriptEntry","cn")  ;
+      if(preg_match("/r/",$s_acl)){
+        $divlist->AddEntry(array( array("string"=>$name['name']),
+              array("string"=>$down , "attach" => "style='width:20px;'"),
+              array("string"=>str_replace("%s",base64_encode($key),$act),
+                "attach"=>"style='border-right: 0px;width:50px;text-align:right;'")));
+      }
     }
     $smarty->assign("Entry_divlist",$divlist->DrawList());
 
+
     /* Magic quotes GPC, escapes every ' " \, to solve some security risks
      * If we post the escaped strings they will be escaped again
      */
@@ -307,14 +332,12 @@ class faiScript extends plugin
       }
     }
 
-    $tmp = $this->plInfo();
-    $this->ui = get_userinfo();
+    $dn = $this->acl_base_for_current_object($this->dn);
+    $smarty->assign("sub_object_is_addable",  
+        preg_match("/c/",$this->ui->get_permissions($dn,"fai/faiScriptEntry")) && 
+        !preg_match("/freeze/",$this->FAIstate));
 
-    $c_dn = $this->dn;  
-    if($c_dn == "new"){
-      $c_dn = $_SESSION['CurrentMainBase'];
-    }
-    $smarty->assign("sub_object_is_addable", preg_match("/c/",$this->ui->get_permissions($c_dn,"fai/faiScriptEntry")) && $this->FAIstate!="freeze");
+    $tmp = $this->plInfo();
     foreach($tmp['plProvidedAcls'] as $name => $translated){
       $smarty->assign($name."ACL",$this->getacl($name));
     }
@@ -352,26 +375,26 @@ class faiScript extends plugin
    */
   function remove_from_parent()
   {
-    $ldap = $this->config->get_ldap_link();
-    $ldap->cd ($this->dn);
+    if($this->acl_is_removeable()){
+      $ldap = $this->config->get_ldap_link();
+      $ldap->cd ($this->dn);
 
-#    $use_dn = str_ireplace( get_release_dn($this->dn), $_SESSION['faifilter']['branch'], $this->dn);
-    $use_dn = preg_replace("/".normalizePreg(get_release_dn($this->dn))."/i", $_SESSION['faifilter']['branch'], $this->dn);
-    if($_SESSION['faifilter']['branch'] == "main"){
-      $use_dn = $this->dn;
-    }
-  
-    prepare_to_save_FAI_object($use_dn,array(),true);
-    
-    foreach($this->SubObjects as $name => $obj){
-#      $use_dn = str_ireplace( get_release_dn($this->dn), $_SESSION['faifilter']['branch'], $obj['dn']);
-      $use_dn = preg_replace("/".normalizePreg(get_release_dn($this->dn))."/i", $_SESSION['faifilter']['branch'], $obj['dn']);
+      $use_dn = preg_replace("/".normalizePreg(get_release_dn($this->dn))."/i", $_SESSION['faifilter']['branch'], $this->dn);
       if($_SESSION['faifilter']['branch'] == "main"){
-        $use_dn = $obj['dn'];
+        $use_dn = $this->dn;
       }
+    
       prepare_to_save_FAI_object($use_dn,array(),true);
+      
+      foreach($this->SubObjects as $name => $obj){
+        $use_dn = preg_replace("/".normalizePreg(get_release_dn($this->dn))."/i", $_SESSION['faifilter']['branch'], $obj['dn']);
+        if($_SESSION['faifilter']['branch'] == "main"){
+          $use_dn = $obj['dn'];
+        }
+        prepare_to_save_FAI_object($use_dn,array(),true);
+      }
+      $this->handle_post_events("remove");
     }
-    $this->handle_post_events("remove");
   }