Code

Updated read only handling for locks.
[gosa.git] / gosa-core / include / functions.inc
index df091fca67fe5fd92252ededf500461974d146e8..ba46e840db640eba6469a22e0dd6418e9ac46c74 100644 (file)
@@ -595,10 +595,28 @@ function ldap_expired_account($config, $userdn, $username)
 }
 
 
-function add_lock ($object, $user)
+function add_lock($object, $user)
 {
   global $config;
 
+  /* Remember which entries were opened as read only, because we 
+      don't need to remove any locks for them later.
+   */
+  if(!session::is_set("LOCK_CACHE")){
+    session::set("LOCK_CACHE",array(""));
+  }
+  $cache = &session::get("LOCK_CACHE");
+  if(isset($_POST['open_readonly'])){
+    $cache['READ_ONLY'][$object] = TRUE;
+    echo "ADDED : {$user}:{$object}<br>";
+    return;
+  }
+  if(isset($cache['READ_ONLY'][$object])){
+    echo "Removed lock entry $object <br>";
+    unset($cache['READ_ONLY'][$object]);
+  }
+
+
   if(is_array($object)){
     foreach($object as $obj){
       add_lock($obj,$user);
@@ -656,6 +674,21 @@ function del_lock ($object)
     return;
   }
 
+  /* If this object was opened in read only mode then 
+      skip removing the lock entry, there wasn't any lock created.
+    */
+  if(session::is_set("LOCK_CACHE")){
+    $cache = &session::get("LOCK_CACHE");
+    if(isset($cache['READ_ONLY'][$object])){
+      if(isset($_POST['delete_lock'])){
+        unset($cache['READ_ONLY'][$object]);
+      }else{
+        echo "Skipped: $object <br>";
+        return;
+      }
+    }
+  }
+
   /* Check for existance and remove the entry */
   $ldap= $config->get_ldap_link();
   $ldap->cd ($config->get_cfg_value("config"));
@@ -698,6 +731,9 @@ function get_lock ($object)
     return("");
   }
 
+  /* Allow readonly access, the plugin::plugin will restrict the acls */
+  if(isset($_POST['open_readonly'])) return("");
+
   /* Get LDAP link, check for presence of the lock entry */
   $user= "";
   $ldap= $config->get_ldap_link();
@@ -1345,7 +1381,7 @@ function rewrite($s)
   global $REWRITE;
 
   foreach ($REWRITE as $key => $val){
-    $s= preg_replace("/$key/", "$val", $s);
+    $s= str_replace("$key", "$val", $s);
   }
 
   return ($s);
@@ -1596,7 +1632,7 @@ function recurse($rule, $variables)
   unset ($variables[$key]);
 
   foreach($val as $possibility){
-    $nrule= preg_replace("/\{$key\}/", $possibility, $rule);
+    $nrule= str_replace("{$key}", $possibility, $rule);
     $result= array_merge($result, recurse($nrule, $variables));
   }
 
@@ -1614,7 +1650,7 @@ function expand_id($rule, $attributes)
   /* Check for clean attribute */
   if (preg_match('/^%[a-zA-Z0-9]+$/', $rule)){
     $rule= preg_replace('/^%/', '', $rule);
-    $val= rewrite(preg_replace('/ /', '', strtolower($attributes[$rule])));
+    $val= rewrite(str_replace(' ', '', strtolower($attributes[$rule])));
     return (array($val));
   }
 
@@ -1622,7 +1658,7 @@ function expand_id($rule, $attributes)
   if (preg_match('/^%[a-zA-Z0-9]+\[[0-9-]+\]$/', $rule)){
     $param= preg_replace('/^[^[]+\[([^]]+)]$/', '\\1', $rule);
     $part= preg_replace('/^%/', '', preg_replace('/\[.*$/', '', $rule));
-    $val= rewrite(preg_replace('/ /', '', strtolower($attributes[$part])));
+    $val= rewrite(str_replace(' ', '', strtolower($attributes[$part])));
     $start= preg_replace ('/-.*$/', '', $param);
     $stop = preg_replace ('/^[^-]+-/', '', $param);
 
@@ -1792,7 +1828,7 @@ function generate_alphabet($count= 10)
 
 function validate($string)
 {
-  return (strip_tags(preg_replace('/\0/', '', $string)));
+  return (strip_tags(str_replace('\0', '', $string)));
 }
 
 
@@ -1989,7 +2025,7 @@ function progressbar($percentage,$width=100,$height=15,$showvalue=false)
 
 function array_key_ics($ikey, $items)
 {
-  $tmp= array_change_key_case($itmes, CASE_LOWER);
+  $tmp= array_change_key_case($items, CASE_LOWER);
   $ikey= strtolower($ikey);
   if (isset($tmp[$ikey])){
     return($tmp[$ikey]);
@@ -2006,7 +2042,7 @@ function array_differs($src, $dst)
     return (TRUE);
   }
 
-  return (count(array_diff($src, $dst)) == 0);
+  return (count(array_diff($src, $dst)) != 0);
 }