Code

Updated mimetype copy & paste
[gosa.git] / plugins / admin / fai / class_faiScript.inc
index 4e913cb5335807d326717c89487fdf27c6b8dc31..9c01f5489e6881b34ab391bb936b8bf2cd7c40de 100644 (file)
@@ -38,6 +38,7 @@ class faiScript extends plugin
 
   var $FAIstate         ="";
 
+  var $view_logged = FALSE;
   var $ui;
 
   function faiScript ($config, $dn= NULL)
@@ -84,6 +85,7 @@ class faiScript extends plugin
         $objects                = $this->get_object_attributes($objects,$this->subAttributes);
         $this->SubObjects[$objects['cn']] = $objects;
       }
+    
     }
     $this->ui = get_userinfo();
   }
@@ -119,11 +121,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;
       }
@@ -137,6 +141,11 @@ class faiScript extends plugin
     /* Call parent execute */
     plugin::execute();
 
+    if($this->is_account && !$this->view_logged){
+      $this->view_logged = TRUE;
+      new log("view","fai/".get_class($this),$this->dn);
+    }
+
     /* Fill templating stuff */
     $smarty= get_smarty();
     $display= "";
@@ -153,37 +162,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]);
@@ -191,22 +211,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){
@@ -214,10 +224,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 */
@@ -226,10 +240,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";
           }
@@ -309,6 +327,7 @@ class faiScript extends plugin
     }
     $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
      */
@@ -371,7 +390,9 @@ class faiScript extends plugin
       if($_SESSION['faifilter']['branch'] == "main"){
         $use_dn = $this->dn;
       }
-    
+   
+      new log("remove","fai/".get_class($this),$use_dn,$this->attributes);
       prepare_to_save_FAI_object($use_dn,array(),true);
       
       foreach($this->SubObjects as $name => $obj){
@@ -421,6 +442,12 @@ class faiScript extends plugin
     prepare_to_save_FAI_object($this->dn,$this->attrs);
     show_ldap_error($ldap->get_error(), sprintf(_("Creating of FAI/script with dn '%s' failed."),$this->dn));
 
+    if($this->initially_was_account){
+      new log("modify","fai/".get_class($this),$this->dn,$this->attributes);
+    }else{
+      new log("create","fai/".get_class($this),$this->dn,$this->attributes);
+    }
+
     /* Do object tagging */
     $this->handle_object_tagging();