Code

Same here
[gosa.git] / plugins / admin / fai / class_faiProfile.inc
index 5cb6600f99930499eb6e251d02bd4d4b5133b79e..53a511ad704386148e49ad0023971b19d2487f6b 100644 (file)
@@ -16,10 +16,6 @@ class faiProfile extends plugin
   /* ObjectClasses for this Object*/
   var $objectclasses    = array("top","FAIclass","FAIprofile");
 
-  /* Class name of the Ldap ObjectClass for the Sub Object */
-  var $subClass         = "FAIscriptEntry";
-  var $subClasses       = array("top","FAIclass","FAIscriptEntry");
-
   /* Specific attributes */
   var $old_cn           = "";
   var $cn               = "";       // The class name for this object
@@ -30,12 +26,26 @@ class faiProfile extends plugin
   var $FAIclasses       = array();  // Contains classname seperated in an array
   var $FAIAllclasses    = array();  // Contains all possible Classnames
 
+  var $FAIstate      = "";
+
   function faiProfile($config, $dn= NULL)
   {
     /* Load Attributes */
     plugin::plugin ($config, $dn);
     $ldap=$this->config->get_ldap_link();
 
+    $this->acl = "#all#";
+
+    if($this->dn != "new"){
+      /* Set acls
+       */
+      $ui   = get_userinfo();
+      $acl  = get_permissions ($this->dn, $ui->subtreeACL);
+      $acli = get_module_permission($acl, "FAIclass", $this->dn);
+      $this->acl=$acli;
+    }
+
+    /* Parse ldap attribute to get all assigned classes */
     $tmp = split(" ",$this->FAIclass);
     $tmp2 = array();
     foreach($tmp as $class){
@@ -43,14 +53,19 @@ class faiProfile extends plugin
         $tmp2[trim($class)] = trim($class);
       }
     }
-    
+
+    if(isset($this->attrs['FAIstate'][0])){
+      $this->FAIstate = $this->attrs['FAIstate'][0];
+    }
+
+    /* Sort assigned classes */ 
     if(is_array($tmp2)){
       foreach($tmp2 as $class){
         $this->FAIclasses[$class]=$class;
       }
     }
 
-    $categories = array("FAIscript","FAItemplate","FAIhook","FAIvariable","FAIpartitionTAble","FAIpackage");
+    $categories = array("FAIscript","FAItemplate","FAIhook","FAIvariable","FAIpartitionTable","FAIpackageList");
 
     /* Build filter */
     $filter= "";
@@ -58,22 +73,37 @@ class faiProfile extends plugin
       $filter.= "(objectClass=$cat)";
     }
     
-    $sort = array();
-    $base = $_SESSION['faifilter']['base'];
+    /* Get ldap connection */ 
+    $base = $_SESSION['CurrentMainBase'];
     $ldap->cd($base);
+    $sort = array();
+
+    /* search all FAI classes */
     $ldap->search("(|$filter)",array("*"));
     while($attrs = $ldap->fetch()){
+
+      /* Sort by categorie */
       foreach($categories as $cat){
         if(in_array($cat,$attrs['objectClass'])){
+
+          /* Append entry */
           $this->FAIAllclasses[$attrs['cn'][0]][$cat]=$attrs;
+  
+          /* Create sort array, because the array above is a multidimensional array, and can't be sorted by php sorting functions*/
           $sort[strtolower($attrs['cn'][0])] = $attrs['cn'][0];
         }
       }
     } 
-    ksort($sort);
+
+    /* Sort the sort array */
+    //ksort($sort);
+
+    /* Reorder the FAIclasses array */
     foreach($sort as $name){
       $tmp[$name] =$this->FAIAllclasses[$name];
     }
+
+    /* Assign sorted classes */
     $this->FAIAllclasses = array();
     $this->FAIAllclasses = $tmp;
 
@@ -84,7 +114,7 @@ class faiProfile extends plugin
   }
 
 
-  /* Combine new array */
+  /* Combine new array, used for up down buttons */
   function combineArrays($ar0,$ar1,$ar2)
   {
     $ret = array();
@@ -103,6 +133,7 @@ class faiProfile extends plugin
     return($ret);
   }
 
+  /* returns position in array */
   function getpos($atr,$attrs)
   {
     $i = 0;
@@ -115,7 +146,7 @@ class faiProfile extends plugin
     return(-1);
   }
 
-  /* TRansports the geiven Arraykey one position up*/
+  /* Transports the given Arraykey one position up*/
   function ArrayUp($atr,$attrs)
   {
     $ret = $attrs;
@@ -132,7 +163,7 @@ class faiProfile extends plugin
   }
 
 
-  /* TRansports the geiven Arraykey one position up*/
+  /* Transports the given Arraykey one position down*/
   function ArrayDown($atr,$attrs)
   {
     $ret = $attrs;
@@ -148,6 +179,7 @@ class faiProfile extends plugin
     return($ret);
   }
 
+  /* class one position up */
   function catUp($id)
   {
     /* Get all cats depinding on current dir */
@@ -155,6 +187,7 @@ class faiProfile extends plugin
     $this->FAIclasses =$this->ArrayUp($id,$cats);
   }
 
+  /* Class one position down */
   function catDown($id)
   {
     /* Get all cats depinding on current dir */
@@ -189,6 +222,7 @@ class faiProfile extends plugin
         $s_action  = "add";
       }
 
+      /* Check if a list element should be pushed one position up */
       if((preg_match("/sortup_/",$name))&&(!$sort_once)){
         $sort_once = true;
         $val = preg_replace("/sortup_/","",$name);
@@ -197,6 +231,7 @@ class faiProfile extends plugin
         $this->catUp($val);
       }
       
+      /* Check if a list element should be pushed one position down */
       if((preg_match("/sortdown_/",$name))&&(!$sort_once)){
         $sort_once = true;
         $val = preg_replace("/sortdown_/","",$name);
@@ -230,7 +265,7 @@ class faiProfile extends plugin
         $this->is_dialog=false;
         unset($this->dialog);
         $this->dialog=NULL;
-        ksort($this->FAIclasses);
+        //ksort($this->FAIclasses);
       }
     }
 
@@ -249,33 +284,40 @@ class faiProfile extends plugin
     $divlist  =new divSelectBox("Profile");
     $divlist->SetSummary(_("This list displays all assigned class names for this profile."));
 
+    /* item images */
     $objTypes['FAIhook']            = "<img src='images/fai_hook.png' title='"._("Hook bundle")."' alt=''>";
     $objTypes['FAItemplate']        = "<img src='images/fai_template.png' title='"._("Template bundle")."' alt=''>";
     $objTypes['FAIscript']          = "<img src='images/fai_script.png' title='"._("Script bundle")."' alt=''>";
     $objTypes['FAIvariable']        = "<img src='images/fai_variable.png' title='"._("Variable bundle")."' alt=''>";
-    $objTypes['FAIpackages']        = "<img src='images/fai_packages.png' title='"._("Packages bundle")."' alt=''>";
+    $objTypes['FAIpackageList']        = "<img src='images/fai_packages.png' title='"._("Packages bundle")."' alt=''>";
     $objTypes['FAIpartitionTable']  = "<img src='images/fai_partitionTable.png' title='"._("Partition table")."' alt=''>";
 
+    /* Delete button */
     $actions = "<input type='image' src='images/edittrash.png' title='"._("Remove class from profile")."' name='DEL_%KEY%'>"; 
-
+    
+    /* Up down buttons */
     $linkupdown = "&nbsp;<input type='image' name='sortup_%s'   alt='up'    title='"._("Up")."'   src='images/sort_up.png' align='top' >";
     $linkupdown.= "<input type='image' name='sortdown_%s' alt='down'  title='"._("Down")."' src='images/sort_down.png' >";
 
+    /* Append fai classes to divlist */
     foreach($this->FAIclasses as $usedClass){
       $str = "&nbsp;";
 
-
       if(isset($this->FAIAllclasses[$usedClass])){
         foreach($this->FAIAllclasses[$usedClass] as $class => $obj){
           $str.= $objTypes[$class]; 
         }
       }
-
-          
   
       $field1 = array("string"=> $usedClass,"attach"=>"");
       $field2 = array("string"=> $str,"attach"=>"");
-      $field3 = array("string"=> preg_replace("/%KEY%/",base64_encode($usedClass),$actions).preg_replace("/%s/",base64_encode($usedClass),$linkupdown),"attach"=>"style='border-right:none;'");
+      if($this->FAIstate != "freeze"){
+        $field3 = array("string"=> preg_replace("/%KEY%/",base64_encode($usedClass),$actions).
+            preg_replace("/%s/",base64_encode($usedClass),$linkupdown),
+            "attach"=>"style='border-right:none;'");
+      }else{
+        $field3 = array("string"=>"&nbsp;", "attach"=>"style='border-right:none;'");
+      }
       $divlist->AddEntry(array($field1,$field2,$field3));
     }
 
@@ -293,6 +335,13 @@ class faiProfile extends plugin
       }
     }
 
+    foreach($this->attributes as $attr){
+      if(($this->FAIstate == "freeze") || (chkacl($this->acl,$attr)!= "")){
+        $smarty->assign($attr."ACL"," disabled ");
+      }else{
+        $smarty->assign($attr."ACL","  ");
+      }
+    }
 
     $display.= $smarty->fetch(get_template_path('faiProfile.tpl', TRUE));
     return($display);
@@ -302,10 +351,17 @@ class faiProfile extends plugin
   {
     $ldap = $this->config->get_ldap_link();
     $ldap->cd ($this->dn);
-    $ldap->rmdir_recursive($this->dn);
+
+    $use_dn = str_ireplace( get_release_dn($this->dn), $_SESSION['faifilter']['branch'], $this->dn);
+    if($_SESSION['faifilter']['branch'] == "main"){
+      $use_dn = $this->dn;
+    }
+
+    prepare_to_save_FAI_object($use_dn,array(),true);
     $this->handle_post_events("remove");    
   }
 
+
   /* Save data to object 
    */
   function save_object()
@@ -322,7 +378,8 @@ class faiProfile extends plugin
   /* Check supplied data */
   function check()
   {
-    $message= array();
+    /* Call common method to give check the hook */
+    $message= plugin::check();
 
     if(count($this->FAIclasses) == 0){
       $message[]=_("Please assign at least one class to this  profile.");
@@ -333,8 +390,12 @@ class faiProfile extends plugin
     }
 
     $ldap = $this->config->get_ldap_link();
-    $ldap->cd($_SESSION['faifilter']['base']);
-    $ldap->search("(&(objectClass=FAIprofile)(cn=".$this->cn.")(!cn=".$this->old_cn."))",array("*"));
+    $ldap->cd($_SESSION['CurrentMainBase']);
+    if ($this->old_cn == ""){
+      $ldap->search("(&(objectClass=FAIprofile)(cn=".$this->cn."))",array("*"));
+    } else {
+      $ldap->search("(&(objectClass=FAIprofile)(cn=".$this->cn.")(!cn=".$this->old_cn."))",array("*"));
+    }
 
     if($ldap->count()){
       $message[]=_("There is already a profile with this class name defined.");
@@ -358,19 +419,32 @@ class faiProfile extends plugin
 
     $this->attrs['FAIclass']=trim($this->FAIclass);
 
-    $ldap->cat($this->dn);
-    if($ldap->count()!=0){
-      /* Write FAIscript to ldap*/
-      $ldap->cd($this->dn);
-      $ldap->modify($this->attrs);
-    }else{
-      /* Write FAIscript to ldap*/
-      $ldap->cd($this->config->current['BASE']);
-      $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
-      $ldap->cd($this->dn);
-      $ldap->add($this->attrs);
-    }
-    show_ldap_error($ldap->get_error());
+    prepare_to_save_FAI_object($this->dn,$this->attrs);
+    
+    show_ldap_error($ldap->get_error(), sprintf(_("Saving of FAI/profile with dn '%s' failed."),$this->dn));
+
+    /* Do object tagging */
+    $this->handle_object_tagging();
+    show_ldap_error($ldap->get_error(), sprintf(_("Saving of FAI/profile with dn '%s' failed."),$this->dn));
+  }
+
+
+  /* Return plugin informations for acl handling */ 
+  function plInfo()
+  {
+    return (array( 
+          "plShortName" => _("Profile"),
+          "plDescription" => _("FAI profile"),
+          "plSelfModify"  => FALSE,
+          "plDepends"     => array(),
+          "plPriority"    => 0,
+          "plSection"     => array("administration"),
+          "plCategory"    => array("fai"),
+          "plProvidedAcls" => array(
+            "cn"                => _("Name"),
+            "description"       => _("Description"),
+            "FAIclass"          => _("FAI classes"))
+          ));
   }
 }