Code

Fixed acls & picture settings
[gosa.git] / include / class_acl.inc
index 637d0ca845565e65041801a856f09fe69013e66d..a25ea05a90b85fcc1ac1a50a758580e32b78f42f 100644 (file)
@@ -87,7 +87,7 @@ class acl extends plugin
     /* Objects */
     $tmp= get_global('plist');
     $plist= $tmp->info;
-    if (isset($this->parent)){
+    if (isset($this->parent) && $this->parent != NULL){
       $oc= array();
       foreach ($this->parent->by_object as $key => $obj){
         $oc= array_merge($oc, $obj->objectclasses);
@@ -125,19 +125,29 @@ class acl extends plugin
             $this->aclObjects[$idx]= $data['description'];
 
             /* Additionally filter the classes we're interested in in "self edit" mode */
-            if (in_array_ics($data['objectClass'], $oc)){
-              $this->myAclObjects[$class]= $acls['plDescription'];
+            if (is_array($data['objectClass'])){
+              foreach($data['objectClass'] as $objectClass){
+                if (in_array_ics($objectClass, $oc)){
+                  $this->myAclObjects[$idx.'/'.$class]= $acls['plDescription'];
+                  break;
+                }
+              }
+            } else {
+              if (in_array_ics($data['objectClass'], $oc)){
+                $this->myAclObjects[$idx.'/'.$class]= $acls['plDescription'];
+              }
             }
           }
 
         }
       }
     }
+    $this->aclObjects['all']= '* '._("All categories");
+    $this->ocMapping['all']= array('0' => 'all');
 
     /* Sort categories */
     asort($this->aclObjects);
 
-
     /* Fill acl types */
     if ($this->isContainer){
       $this->aclTypes= array("reset" => _("Reset ACLs"),
@@ -251,9 +261,13 @@ class acl extends plugin
     if ($aclDialog && isset($this->ocMapping[$this->aclObject])){
       foreach ($this->ocMapping[$this->aclObject] as $oc){
         unset($this->aclContents[$oc]);
+        unset($this->aclContents[$this->aclObject.'/'.$oc]);
         if (isset($new_acl[$oc])){
           $this->aclContents[$oc]= $new_acl[$oc];
         }
+        if (isset($new_acl[$this->aclObject.'/'.$oc])){
+          $this->aclContents[$this->aclObject.'/'.$oc]= $new_acl[$this->aclObject.'/'.$oc];
+        }
       }
     }
 
@@ -350,7 +364,7 @@ class acl extends plugin
         $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='acl_edit_$key' title='"._("Edit ACL")."'>";
         $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='acl_del_$key' title='"._("Delete ACL")."'>";
 
-        $field3= array("string" => $action, "attach" => "style='border-right:0px;width:50px';text-align:right");
+        $field3= array("string" => $action, "attach" => "style='border-right:0px;width:50px;text-align:right;'");
         $aclList->AddEntry(array($field1, $field2, $field3));
       }
 
@@ -368,6 +382,13 @@ class acl extends plugin
         foreach($this->ocMapping[$section] as $oc){
           if (isset($this->aclContents[$oc]) && count($this->aclContents[$oc]) && isset($this->aclContents[$oc][0]) &&
               $this->aclContents[$oc][0] != ""){
+
+            $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] != ""){
+
             $summary.= "$oc, ";
             continue;
           }
@@ -428,12 +449,14 @@ class acl extends plugin
       $smarty->assign('headline', sprintf(_("Edit ACL for '%s', scope is '%s'"), $this->aclObjects[$this->aclObject], $this->aclTypes[$this->aclType]));
 
       /* Collect objects for selected category */
-      $aclObjects= array();
       foreach ($this->ocMapping[$this->aclObject] as $idx => $class){
         if ($idx == 0){
           continue;
         }
-        $aclObjects[$class]= $plist[$class]['plDescription'];
+        $aclObjects[$this->aclObject.'/'.$class]= $plist[$class]['plDescription'];
+      }
+      if ($this->aclObject == 'all'){
+        $aclObjects['all']= _("All objects in current subtree");
       }
       $smarty->assign('aclSelector', $this->buildAclSelector($aclObjects));
     }
@@ -464,7 +487,33 @@ class acl extends plugin
       $currentAcl= $this->aclContents[$key];
 
       /* Object header */
-      $display.= "<table style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2><tr><td style='background-color:#C8C8C8;height:1.8em' colspan=$cols><b>"._("Object").": $name</b></td></tr>";
+      if($_SESSION['js']) {
+        if(isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) {
+          $display.= "\n<table style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
+                     "\n  <tr>".
+                     "\n    <td style='background-color:#C8C8C8;height:1.8em;' colspan=".($cols-1)."><b>"._("Object").": $name</b></td>".
+                     "\n    <td align='right' style='background-color:#C8C8C8;height:1.8em;'>".
+                     "\n    <input type='button' onclick='divtoggle(\"".preg_replace("/[^a-z0-9]/i","_",$name)."\");' value='"._("Show/Hide Advanced Settings")."' /></td>".
+                     "\n  </tr>";
+        } else if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT'])) {
+          $display.= "\n<table style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
+                     "\n  <tr>".
+                     "\n    <td style='background-color:#C8C8C8;height:1.8em;' colspan=".($cols-1)."><b>"._("Object").": $name</b></td>".
+                     "\n    <td align='right' style='background-color:#C8C8C8;height:1.8em;'>".
+                     "\n    <input type='button' onclick='divtoggle(\"".preg_replace("/[^a-z0-9]/i","_",$name)."\");' value='"._("Show/Hide Advanced Settings")."' /></td>".
+                     "\n  </tr>";
+        } else {
+          $display.= "\n<table style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
+                     "\n  <tr>".
+                     "\n    <td style='background-color:#C8C8C8;height:1.8em;' colspan=$cols><b>"._("Object").": $name</b></td>".
+                     "\n  </tr>";
+        }
+      } else {
+          $display.= "\n<table style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
+                     "\n  <tr>".
+                     "\n    <td style='background-color:#C8C8C8;height:1.8em;' colspan=$cols><b>"._("Object").": $name</b></td>".
+                     "\n  </tr>";
+      }
 
       /* Generate options */
       $spc= "&nbsp;&nbsp;";
@@ -472,13 +521,13 @@ class acl extends plugin
         $options= $this->mkchkbx($key."_0_c",  _("Create objects"), preg_match('/c/', $currentAcl[0])).$spc;
         $options.= $this->mkchkbx($key."_0_m", _("Move objects"), preg_match('/m/', $currentAcl[0])).$spc;
         $options.= $this->mkchkbx($key."_0_d", _("Remove objects"), preg_match('/d/', $currentAcl[0])).$spc;
-        if ($plist[$key]['plSelfModify']){
+        if ($plist[preg_replace('%^.*/%', '', $key)]['plSelfModify']){
           $options.= $this->mkchkbx($key."_0_s", _("Modifyable by owner"), preg_match('/s/', $currentAcl[0])).$spc;
         }
       } else {
         $options= $this->mkchkbx($key."_0_m", _("Move object"), preg_match('/m/', $currentAcl[0])).$spc;
         $options.= $this->mkchkbx($key."_0_d", _("Remove object"), preg_match('/d/', $currentAcl[0])).$spc;
-        if ($plist[$key]['plSelfModify']){
+        if ($plist[preg_replace('%^.*/%', '', $key)]['plSelfModify']){
           $options.= $this->mkchkbx($key."_0_s", _("Modifyable by owner"), preg_match('/s/', $currentAcl[0])).$spc;
         }
       }
@@ -487,12 +536,28 @@ class acl extends plugin
       $more_options= $this->mkchkbx($key."_0_r",  _("read"), preg_match('/r/', $currentAcl[0])).$spc;
       $more_options.= $this->mkchkbx($key."_0_w", _("write"), preg_match('/w/', $currentAcl[0]));
 
-      $display.= "<tr><td style='background-color:#E0E0E0' colspan=".($cols-1).">$options</td><td style='background-color:#D4D4D4'>&nbsp;".("Complete object:")." $more_options</td></tr>";
+      $display.= "\n  <tr>".
+                 "\n    <td style='background-color:#E0E0E0' colspan=".($cols-1).">$options</td>".
+                 "\n    <td style='background-color:#D4D4D4'>&nbsp;".("Complete object:")." $more_options</td>".
+                 "\n  </tr>";
 
       /* Walk through the list of attributes */
       $cnt= 1;
-      $splist= $plist[$key]['plProvidedAcls'];
+      $splist= $plist[preg_replace('%^.*/%', '', $key)]['plProvidedAcls'];
       asort($splist);
+      if($_SESSION['js']) {
+        if(isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) {
+          $display.= "\n  <tr id='tr_".preg_replace("/[^a-z0-9]/i","_",$name)."' style='vertical-align:top;height:0px;'>".
+                     "\n    <td colspan=".$cols.">".
+                     "\n      <div id='".preg_replace("/[^a-z0-9]/i","_",$name)."' style='overflow:hidden;visibility:hidden;height:0px;vertical-align:top;width:100%;'>".
+                     "\n        <table style='width:100%;'>";
+        } else if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT'])) {
+          $display.= "\n  <tr id='tr_".preg_replace("/[^a-z0-9]/i","_",$name)."' style='vertical-align:top;height:0px;'>".
+                     "\n    <td colspan=".$cols.">".
+                     "\n      <div id='".preg_replace("/[^a-z0-9]/i","_",$name)."' style='position:absolute;overflow:hidden;visibility:hidden;height:0px;vertical-align:top;width:100%;'>".
+                     "\n        <table style='width:100%;'>";
+        }
+      }
       foreach($splist as $attr => $dsc){
 
         /* Skip pl* attributes, they are internal... */
@@ -502,14 +567,14 @@ class acl extends plugin
 
         /* Open table row */
         if ($cnt == 1){
-          $display.= "<tr>";
+          $display.= "\n  <tr>";
         }
 
         /* Close table row */
         if ($cnt == $cols){
           $cnt= 1;
           $rb= "";
-          $end= "</tr>";
+          $end= "\n  </tr>";
         } else {
           $cnt++;
           $rb= "border-right:1px solid #A0A0A0;";
@@ -521,15 +586,25 @@ class acl extends plugin
         if (isset($currentAcl[$attr])){
           $state= $currentAcl[$attr];
         }
-        $display.= "<td style='border-top:1px solid #A0A0A0;${rb}width:".(int)(100/$cols)."%'><b>$dsc</b> ($attr)<br>".$this->mkrwbx($key."_".$attr, $state)."</td>$end";
+        $display.= "\n    <td style='border-top:1px solid #A0A0A0;${rb}width:".(int)(100/$cols)."%'>".
+                   "\n      <b>$dsc</b> ($attr)<br>".$this->mkrwbx($key."_".$attr, $state)."</td>$end";
       }
       
       /* Fill missing td's if needed */
       if (--$cnt != $cols && $cnt != 0){
-       $display.= str_repeat("<td style='border-top:1px solid #A0A0A0; width:".(int)(100/$cols)."%'>&nbsp;</td>", $cols-$cnt); 
+       $display.= str_repeat("\n    <td style='border-top:1px solid #A0A0A0; width:".(int)(100/$cols)."%'>&nbsp;</td>", $cols-$cnt); 
       }
 
-      $display.= "</table><br>";
+      if($_SESSION['js']) {
+        if(isset($_SERVER['HTTP_USER_AGENT']) && (preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) || (preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT']))) {
+          $display.= "\n        </table>".
+                     "\n      </div>".
+                     "\n    </td>".
+                     "\n  </tr>";
+        }
+      }
+
+      $display.= "\n</table><br />\n";
     }
 
     return ($display);
@@ -539,7 +614,8 @@ class acl extends plugin
   function mkchkbx($name, $text, $state= FALSE)
   {
     $state= $state?"checked":"";
-    return "<input id='acl_$name' type=checkbox name='acl_$name' $state><label for='acl_$name'>$text</label>";
+    return "\n      <input id='acl_".preg_replace("/[^a-z0-9]/i","_",$name)."' type=checkbox name='acl_$name' $state>".
+           "\n      <label for='acl_$name'>$text</label>";
   }
 
 
@@ -547,8 +623,10 @@ class acl extends plugin
   {
     $rstate= preg_match('/r/', $state)?'checked':'';
     $wstate= preg_match('/w/', $state)?'checked':'';
-    return ("<input id='acl_${name}_r' type=checkbox name='acl_${name}_r' $rstate><label for='acl_${name}_r'>"._("read")."</label>".
-            "<input id='acl_${name}_w' type=checkbox name='acl_${name}_w' $wstate><label for='acl_${name}_w'>"._("write")."</label>");
+    return ("\n      <input id='acl_".preg_replace("/[^a-z0-9]/i","_",$name)."_r' type=checkbox name='acl_${name}_r' $rstate>".
+            "\n      <label for='acl_${name}_r'>"._("read")."</label>".
+            "\n      <input id='acl_".preg_replace("/[^a-z0-9]/i","_",$name)."_w' type=checkbox name='acl_${name}_w' $wstate>".
+            "\n      <label for='acl_${name}_w'>"._("write")."</label>");
   }
 
 
@@ -800,6 +878,11 @@ class acl extends plugin
     $ldap->modify ($this->attrs);
 
     show_ldap_error($ldap->get_error(), sprintf(_("Saving ACLs with dn '%s' failed."),$this->dn));
+
+    /* Refresh users ACLs */
+    $ui= get_userinfo();
+    $ui->loadACL();
+    $_SESSION['ui']= $ui;
   }