Code

Added acls for printer glpi
[gosa.git] / plugins / admin / systems / class_printGeneric.inc
index ee40925c0800f33cfe8d4e378984cc9ffd2470b4..9ff8c3e3b912fcce9e0a89dce492312c66096619 100644 (file)
@@ -49,11 +49,13 @@ class printgeneric extends plugin
                               "gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter","gotoGroupPrinter");
   var $objectclasses  = array("top", "gotoPrinter");
 
-  function printgeneric ($config, $dn= NULL,$parent = NULL)
+  var $parent;
+
+  function printgeneric ($config, $dn,$parent_init,$parent)
   {
     $this->config = $config;
     $this->dn = $dn; 
-    
     /* If parent was posted(the tabs object) we can detect the printer type. */
     if($parent){
       $this->parent = $parent;
@@ -75,7 +77,7 @@ class printgeneric extends plugin
     $this->orig_dn = $this->dn;
 
     /* Get printer settings, possibly dn has changed */
-    plugin::plugin ($config, $this->dn);
+    plugin::plugin ($config, $this->dn,$parent_init);
 
     /* Get is_account initially_was_account status */
     $this->getTypeOfPrinter(true);
@@ -161,6 +163,8 @@ class printgeneric extends plugin
 
     /* Detect type of printer via parent tabs.
      */
+
+    $class = get_class($this->parent);
     if(isset($this->parent->by_object['workgeneric'])){
 
       /* Exclude templates 
@@ -211,7 +215,6 @@ class printgeneric extends plugin
 
       /* Detect if this is a valid printer account;
        */
-      //FIXME: do we need to do this? we've already everything we need in $this->attrs...
       $ldap = $this->config->get_ldap_link();
       $ldap->cat($this->dn, array('objectClass'));
 
@@ -263,6 +266,21 @@ class printgeneric extends plugin
     }
 
     $smarty= get_smarty();
+
+    /* Assign acls */
+    $tmp = $this->plInfo();
+    foreach($tmp['plProvidedAcls'] as $name => $translation){
+      $smarty->assign($name."ACL", $this->getacl($name));
+    }
+
+    /* Create base acls */
+    $baseACL = $this->getacl("base");
+    if(!$this->acl_is_moveable()) {
+      $baseACL = preg_replace("/w/","",$baseACL);
+    }
+    $smarty->assign("baseACL",          $baseACL);
+
+
     $display="";
 
     /* Tell smarty if this is a standalone object or a terminal / WS depending printer */
@@ -273,9 +291,12 @@ class printgeneric extends plugin
     }
 
     /* Do we need to flip is_account state? */
-    if (isset($_POST['modify_state'])){
-      $this->is_modified = true;
-      $this->is_account= !$this->is_account;
+    if(isset($_POST['modify_state'])){
+      if($this->is_account && $this->acl_is_removeable()){
+        $this->is_account= FALSE;
+      }elseif(!$this->is_account && $this->acl_is_createable()){
+        $this->is_account= TRUE;
+      }
     }
 
     /* Do we represent a valid printer? */
@@ -319,7 +340,7 @@ class printgeneric extends plugin
     foreach($_POST as $name => $value){
       if(preg_match("/^chooseBase/",$name) && $once){
         $once = false;
-        $this->dialog = new baseSelectDialog($this->config,$this);
+        $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
         $this->dialog->setCurrentBase($this->base);
         $this->baseSelection = true;
       }
@@ -345,17 +366,14 @@ class printgeneric extends plugin
     }
 
     /* Fill templating stuff */
-    $smarty->assign("bases", $this->config->idepartments);
+    $smarty->assign("bases", $this->get_allowed_bases());
     $smarty->assign("base_select", $this->base);
 
     /* Assign attributes */
     foreach ($this->attributes as $attr){
-      $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
       $smarty->assign("$attr", $this->$attr);
     }
 
-    $smarty->assign("baseACL", chkacl($this->acl,"base"));
-
     if(isset($_POST['AddUser'])){
       $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddUser");
     }
@@ -499,7 +517,7 @@ class printgeneric extends plugin
       }else{
         $smarty->assign("desc"    ,sprintf(_("This printer belongs to workstation %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
       }
-      $smarty->assign("cnACL"    ," disabled ");
+      $smarty->assign("cnACL"    , $this->getacl("cn",true));
     }else{
       $smarty->assign("desc"    ,"");
     }
@@ -571,10 +589,27 @@ class printgeneric extends plugin
   function save_object()
   {
     plugin::save_object();
-    $this->netConfigDNS->save_object();
+    
+    if(is_object($this->netConfigDNS)){
+      $this->netConfigDNS->save_object();
+    }
+
     /* Save base, since this is no LDAP attribute */
-    if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
-      $this->base= $_POST['base'];
+    if((isset($_POST['base'])) && ($this->acl_is_moveable()) ) {
+      $this->set_acl_base('dummy,'.$_POST['base']);
+      if($this->acl_is_moveable()){
+
+        if(isset($this->config->idepartments[$_POST['base']])){
+          $this->base = $_POST['base'];
+          if ($_POST['base'] != $this->base){
+            $this->is_modified= TRUE;
+          }
+        }
+      }else{
+
+        print_red(sprintf(_("You are not allowed to move this object to '%s'."),LDAP::fix($_POST['base'])));
+        $this->set_acl_base('dummy,'.$this->base);
+      }
     }
   }
 
@@ -604,6 +639,12 @@ class printgeneric extends plugin
     if(($this->BelongsTo == "Printer") && (empty($this->cn))){
       $message[]= "The required field 'Printer name' is not set.";
     }
+
+    if($this->BelongsTo == "Printer"){
+      if ($this->orig_dn == "new" && !$this->acl_is_createable()){
+        $message[]= _("You have no permissions to create a group on this 'Base'.");
+      }
+    }
     
     /* must: labeledURI */
     if(empty($this->labeledURI)){
@@ -687,8 +728,13 @@ class printgeneric extends plugin
     }else{
       $method="http://";
     }
-    $this->attrs['gotoPrinterPPD'] = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD);
+
+    /* If no ppd is selected, remove this attribute */
+    if(!empty($this->gotoPrinterPPD)) {
+      $this->attrs['gotoPrinterPPD'] = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD);
+    }else{
+      $this->attrs['gotoPrinterPPD'] = array();
+    }
 
     /* Append printer user 
      */
@@ -796,9 +842,10 @@ class printgeneric extends plugin
           "plPriority"    => 0,
           "plSection"     => array("administration"),
           "plCategory"    => array("printer" => array("description"  => _("Printer"),
-                                                    "objectClass"  => "gotoPrinter")),
+                                                    "objectClass"  => "gotoPrinter"),"workstation"),
           "plProvidedAcls"=> array(
-            "cn"                => _("Name"), 
+            "cn"                => _("Name"),
+            "base"                => _("Base") ,         
             "description"       => _("Description"), 
             "l"                 => _("Location"), 
             "labeledURI"        => _("LabeledURL"), 
@@ -817,12 +864,12 @@ class printgeneric extends plugin
         $id = $key;
       }
     }
-    
-    if(!$this->acl_is_writeable($type)){
+  
+    if(!$this->acl_is_writeable("gotoUserPrinter")){
       print_red(sprintf(_("You are not allowed to remove the given object '%s' from the list of members of printer '%s'."),$id,$this->dn));
       return(FALSE);
     }
-  
     if(isset($this->member[$type][$id])){
       unset($this->member[$type][$id]);
       return(TRUE);