index 3a0263a41f811bfff321c57a77b853671fddecdf..ba46e840db640eba6469a22e0dd6418e9ac46c74 100644 (file)
function array_remove_entries($needles, $haystack)
{
- $tmp= array();
-
- /* Loop through entries to be removed */
- foreach ($haystack as $entry){
- if (!in_array($entry, $needles)){
- $tmp[]= $entry;
- }
- }
-
- return ($tmp);
+ return (array_merge(array_diff($haystack, $needles)));
}
function array_remove_entries_ics($needles, $haystack)
{
- $tmp= array();
-
- /* Loop through entries to be removed */
- foreach ($haystack as $entry){
- if (!in_array_ics($entry, $needles)){
- $tmp[]= $entry;
- }
- }
-
- return ($tmp);
+ // strcasecmp will work, because we only compare ASCII values here
+ return (array_merge(array_udiff($haystack, $needles, 'strcasecmp')));
}
}
-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);
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"));
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();
global $REWRITE;
foreach ($REWRITE as $key => $val){
- $s= preg_replace("/$key/", "$val", $s);
+ $s= str_replace("$key", "$val", $s);
}
return ($s);
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));
}
/* 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));
}
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);
}
}
- if(preg_match('/\{id#\d+}/',$uid)){
- $size= preg_replace('/^.*{id#(\d+)}.*$/', '\\1', $uid);
+ if(preg_match('/\{id#\d+}/',$uid)){
+ $size= preg_replace('/^.*{id#(\d+)}.*$/', '\\1', $uid);
- while (true){
- mt_srand((double) microtime()*1000000);
- $number= sprintf("%0".$size."d", mt_rand(0, pow(10, $size)-1));
- $res= preg_replace('/{id#(\d+)}/', $number, $uid);
- if (!in_array($res, $used)){
- $uid= $res;
- break;
+ while (true){
+ mt_srand((double) microtime()*1000000);
+ $number= sprintf("%0".$size."d", mt_rand(0, pow(10, $size)-1));
+ $res= preg_replace('/{id#(\d+)}/', $number, $uid);
+ if (!in_array($res, $used)){
+ $uid= $res;
+ break;
+ }
}
}
- }
-/* Don't assign used ones */
-if (!in_array($uid, $used)){
- $ret[]= $uid;
-}
-}
+ /* Don't assign used ones */
+ if (!in_array($uid, $used)){
+ $ret[]= $uid;
+ }
+ }
-return(array_unique($ret));
+ return(array_unique($ret));
}
function validate($string)
{
- return (strip_tags(preg_replace('/\0/', '', $string)));
+ return (strip_tags(str_replace('\0', '', $string)));
}
function array_key_ics($ikey, $items)
{
- /* Gather keys, make them lowercase */
- $tmp= array();
- foreach ($items as $key => $value){
- $tmp[strtolower($key)]= $key;
- }
-
- if (isset($tmp[strtolower($ikey)])){
- return($tmp[strtolower($ikey)]);
+ $tmp= array_change_key_case($items, CASE_LOWER);
+ $ikey= strtolower($ikey);
+ if (isset($tmp[$ikey])){
+ return($tmp[$ikey]);
}
- return ("");
+ return ('');
}
return (TRUE);
}
- /* So the count is the same - lets check the contents */
- $differs= FALSE;
- foreach($src as $value){
- if (!in_array($value, $dst)){
- $differs= TRUE;
- }
- }
-
- return ($differs);
+ return (count(array_diff($src, $dst)) != 0);
}