Code

Added printer patch
[gosa.git] / plugins / admin / fai / class_faiProfile.inc
index bf80503dfc9ae8f8de48a02dc6863a9d51484ad9..65871611b31db6f43195d4ea74c3c9d924ceaa8b 100644 (file)
@@ -30,12 +30,25 @@ 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();
@@ -44,7 +57,11 @@ 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){
@@ -52,7 +69,7 @@ class faiProfile extends plugin
       }
     }
 
-    $categories = array("FAIscript","FAItemplate","FAIhook","FAIvariable","FAIpartitionTable","FAIpackage");
+    $categories = array("FAIscript","FAItemplate","FAIhook","FAIvariable","FAIpartitionTable","FAIpackageList");
 
     /* Build filter */
     $filter= "";
@@ -61,7 +78,7 @@ class faiProfile extends plugin
     }
     
     /* Get ldap connection */ 
-    $base = $_SESSION['faifilter']['base'];
+    $base = $_SESSION['CurrentMainBase'];
     $ldap->cd($base);
     $sort = array();
 
@@ -83,7 +100,7 @@ class faiProfile extends plugin
     } 
 
     /* Sort the sort array */
-    ksort($sort);
+    //ksort($sort);
 
     /* Reorder the FAIclasses array */
     foreach($sort as $name){
@@ -252,7 +269,7 @@ class faiProfile extends plugin
         $this->is_dialog=false;
         unset($this->dialog);
         $this->dialog=NULL;
-        ksort($this->FAIclasses);
+        //ksort($this->FAIclasses);
       }
     }
 
@@ -276,7 +293,7 @@ class faiProfile extends plugin
     $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 */
@@ -298,7 +315,13 @@ class faiProfile extends plugin
   
       $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));
     }
 
@@ -316,6 +339,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);
@@ -326,6 +356,7 @@ class faiProfile extends plugin
     $ldap = $this->config->get_ldap_link();
     $ldap->cd ($this->dn);
     $ldap->rmdir_recursive($this->dn);
+    show_ldap_error($ldap->get_error(), _("Removing FAI profile failed"));
     $this->handle_post_events("remove");    
   }
 
@@ -345,7 +376,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.");
@@ -356,8 +388,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.");
@@ -381,11 +417,12 @@ class faiProfile extends plugin
 
     $this->attrs['FAIclass']=trim($this->FAIclass);
 
-    $ldap->cat($this->dn);
+    $ldap->cat($this->dn,array("objectClass"));
     if($ldap->count()!=0){
       /* Write FAIscript to ldap*/
       $ldap->cd($this->dn);
-      $ldap->modify($this->attrs);
+      $this->cleanup();
+      $ldap->modify ($this->attrs); 
     }else{
       /* Write FAIscript to ldap*/
       $ldap->cd($this->config->current['BASE']);
@@ -393,6 +430,10 @@ class faiProfile extends plugin
       $ldap->cd($this->dn);
       $ldap->add($this->attrs);
     }
+    show_ldap_error($ldap->get_error(), _("Saving FAI profile failed"));
+
+    /* Do object tagging */
+    $this->handle_object_tagging();
     show_ldap_error($ldap->get_error());
   }
 }