Code

<h2> => </h3>
[gosa.git] / gosa-core / plugins / admin / acl / class_aclRole.inc
index b78c955e156c7b00831412de4567e57e50a0cf51..51f19e973dd30bf1252848789c3c7bfa098d4ac6 100644 (file)
@@ -49,10 +49,12 @@ class aclrole extends acl
   /* Role attributes */
   var $gosaAclTemplate= "";
   var $cn = "";
+  var $orig_cn = "";
   var $description = "";
   var $orig_dn;
   var $orig_base;
   var $base ="";
+  var $baseSelector;
 
   function aclrole (&$config,  $dn= NULL)
   {
@@ -60,7 +62,8 @@ class aclrole extends acl
     plugin::plugin($config, $dn);
 
     if($this->dn == "new"){
-      $this->base  = session::get('CurrentMainBase');
+      $ui = get_userinfo();
+      $this->base= dn2base(session::global_is_set("CurrentMainBase")?"cn=test,".session::global_get("CurrentMainBase"):$ui->dn);
     }else{
       $this->base = preg_replace("/^[^,]+,[^,]+,/","",$this->dn);
       new log("view","acl/".get_class($this),$this->dn);
@@ -139,6 +142,13 @@ class aclrole extends acl
     $this->is_account= TRUE;
     $this->orig_base = $this->base;
     $this->orig_dn = $this->dn;
+    $this->orig_cn = $this->cn;
+
+    /* Instanciate base selector */
+    $this->baseSelector= new baseSelector($this->get_allowed_bases(), $this->base);
+    $this->baseSelector->setSubmitButton(false);
+    $this->baseSelector->setHeight(300);
+    $this->baseSelector->update(true);
   }
 
 
@@ -147,36 +157,6 @@ class aclrole extends acl
     /* Call parent execute */
     plugin::execute();
 
-    /* Base select dialog */
-    $once = true;
-    foreach($_POST as $name => $value){
-      if((preg_match("/^chooseBase/",$name) && $once) && ($this->acl_is_moveable())){
-        $once = false;
-        $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
-        $this->dialog->setCurrentBase($this->base);
-      }
-    }
-
-    /* Dialog handling */
-    if(is_object($this->dialog)){
-      /* Must be called before save_object */
-      $this->dialog->save_object();
-
-      if($this->dialog->isClosed()){
-        $this->dialog = false;
-      }elseif($this->dialog->isSelected()){
-
-        /* Check if selected base is valid */
-        $tmp = $this->get_allowed_bases();
-        if(isset($tmp[$this->dialog->isSelected()])){
-          $this->base = $this->dialog->isSelected();
-        }
-        $this->dialog= false;
-      }else{
-        return($this->dialog->execute());
-      }
-    }
-
     $tmp= session::get('plist');
     $plist= $tmp->info;
 
@@ -264,7 +244,7 @@ class aclrole extends acl
 
       /* ACL saving... */
       if (preg_match('/^acl_.*_[^xy]$/', $name) && $this->acl_is_writeable("gosaAclEntry")){
-        list($dummy, $object, $attribute, $value)= split('_', $name);
+        list($dummy, $object, $attribute, $value)= explode('_', $name);
 
         /* Skip for detection entry */
         if ($object == 'dummy') {
@@ -360,9 +340,9 @@ class aclrole extends acl
 
     /* Create templating instance */
     $smarty= get_smarty();
+    $smarty->assign("usePrototype", "true");
 
-    $smarty->assign("bases", $this->get_allowed_bases());
-    $smarty->assign("base_select", $this->base);
+    $smarty->assign("base", $this->baseSelector->render());
 
     $tmp = $this->plInfo();
     foreach($tmp['plProvidedAcls'] as $name => $translation){
@@ -424,9 +404,7 @@ class aclrole extends acl
             $summary.= "$oc, ";
             continue;
           }
-          if (isset($this->aclContents["$section/$oc"]) && count($this->aclContents["$section/$oc"]) && isset($this->aclContents["$section/$oc"][0]) &&
-              $this->aclContents["$section/$oc"][0] != ""){
-
+          if (isset($this->aclContents["$section/$oc"]) && count($this->aclContents["$section/$oc"])){
             $summary.= "$oc, ";
             continue;
           }
@@ -697,11 +675,14 @@ class aclrole extends acl
     plugin::save_object();
     if(isset($_POST['acl_role_posted'])){
      
-      /* Get base selection */
-      if(isset($_POST['base'])){
-        $tmp = $this->get_allowed_bases();
-        if(isset($tmp[$_POST['base']])){
-          $this->base = $_POST['base'];
+      /* Refresh base */
+      if ($this->acl_is_moveable($this->base)){
+        if (!$this->baseSelector->update()) {
+          msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
+        }
+        if ($this->base != $this->baseSelector->getBase()) {
+          $this->base= $this->baseSelector->getBase();
+          $this->is_modified= TRUE;
         }
       }
     }
@@ -763,10 +744,28 @@ class aclrole extends acl
     if(empty($this->cn)){
       $message[] = msgPool::required(_("Name"));
     }
-   
+  
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cd($this->config->current['BASE']);
+    if($this->cn != $this->orig_cn){
+      $ldap->search("(&(objectClass=gosaRole)(cn=".$this->cn."))");
+      if($ldap->count()) {
+        while($attrs = $ldap->fetch()){
+          if($attrs['dn'] != $this->orig_dn){
+            $message[] = msgPool::duplicated(_("Name"));
+          }
+        }
+      }
+    } 
     if(!count($this->gosaAclTemplate)){
       $message[] = msgPool::required(_("ACL"));
     }
+
+    // Check if a wrong base was supplied
+    if(!$this->baseSelector->checkLastBaseUpdate()){
+      $message[]= msgPool::check_base();;
+    }
  
     /* Check if we are allowed to create or move this object
      */