Code

Updated divlists.
[gosa.git] / plugins / admin / fai / class_faiScript.inc
index 5516f19d5fe653dc8079e5e3d87516adab183272..c130a568d6cba899f26716d82ed72edf824ce727 100644 (file)
@@ -69,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";
@@ -111,11 +119,13 @@ 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= $_SESSION['CurrentMainBase'];
+        $dn= "cn=dummy,".$_SESSION['CurrentMainBase'];
       }else{
         $dn = $this->dn;
       }
@@ -145,37 +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->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));
 
+        /* 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]);
@@ -183,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($this->acl_base_for_current_object($this->SubObjects[$script]['dn']));
-      $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){
@@ -206,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 */
@@ -218,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";
           }
@@ -270,6 +289,7 @@ class faiScript extends plugin
       $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{
@@ -279,6 +299,7 @@ class faiScript extends plugin
         }
       }
 
+      /* 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 = "";
@@ -288,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,7 +333,10 @@ class faiScript extends plugin
     }
 
     $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")) && $this->FAIstate!="freeze");
+    $smarty->assign("sub_object_is_addable",  
+        preg_match("/c/",$this->ui->get_permissions($dn,"fai/faiScriptEntry")) && 
+        !preg_match("/freeze/",$this->FAIstate));
+
     $tmp = $this->plInfo();
     foreach($tmp['plProvidedAcls'] as $name => $translated){
       $smarty->assign($name."ACL",$this->getacl($name));