Code

Made filter rely on it's own input
[gosa.git] / gosa-core / include / functions.inc
index 8129514a28ce17ba7b53b0f150fb9caeb552bc82..f6626a8ac9aa9497cb633eb53c83c6d05ac71a6f 100644 (file)
@@ -88,6 +88,7 @@ define ("DEBUG_CONFIG", 64);
 define ("DEBUG_ACL",    128);
 define ("DEBUG_SI",     256);
 define ("DEBUG_MAIL",   512); // mailAccounts, imap, sieve etc.
+define ("DEBUG_FAI",   1024); // FAI (incomplete)
 
 /* Rewrite german 'umlauts' and spanish 'accents'
    to get better results */
@@ -606,6 +607,13 @@ function add_lock($object, $user)
   if(!session::global_is_set("LOCK_CACHE")){
     session::global_set("LOCK_CACHE",array(""));
   }
+  if(is_array($object)){
+    foreach($object as $obj){
+      add_lock($obj,$user);
+    }
+    return;
+  }
+
   $cache = &session::global_get("LOCK_CACHE");
   if(isset($_POST['open_readonly'])){
     $cache['READ_ONLY'][$object] = TRUE;
@@ -615,12 +623,6 @@ function add_lock($object, $user)
     unset($cache['READ_ONLY'][$object]);
   }
 
-  if(is_array($object)){
-    foreach($object as $obj){
-      add_lock($obj,$user);
-    }
-    return;
-  }
 
   /* Just a sanity check... */
   if ($object == "" || $user == ""){
@@ -1066,7 +1068,7 @@ function eval_sizelimit()
         isset($_POST['action']) && $_POST['action']=="newlimit"){
 
       session::global_set('size_limit', validate($_POST['new_limit']));
-      session::global_set('size_ignore', FALSE);
+      session::set('size_ignore', FALSE);
     }
 
     /* User wants no limits? */
@@ -1098,8 +1100,8 @@ function getMenuCache()
     $str.= chr($e+$n);
 
     if(isset($_GET[$str])){
-      if(session::global_is_set('maxC')){
-        $b= session::global_get('maxC');
+      if(session::is_set('maxC')){
+        $b= session::get('maxC');
         $q= "";
         for ($m=0, $l= strlen($b);$m<$l;$m++) {
           $q.= $b[$m++];
@@ -1164,6 +1166,7 @@ function get_ou($name)
   global $config;
 
   $map = array( 
+                "roleRDN"      => "ou=roles,",
                 "ogroupRDN"      => "ou=groups,",
                 "applicationRDN" => "ou=apps,",
                 "systemRDN"     => "ou=systems,",
@@ -1287,13 +1290,16 @@ function gen_locked_message($user, $dn, $allow_readonly = FALSE)
 {
   global $plug, $config;
 
+  session::set('dn', $dn);
   $remove= false;
 
   /* Save variables from LOCK_VARS_TO_USE in session - for further editing */
-  if( session::global_is_set('LOCK_VARS_TO_USE') && count(session::global_get('LOCK_VARS_TO_USE'))){
+  if( session::is_set('LOCK_VARS_TO_USE') && count(session::get('LOCK_VARS_TO_USE'))){
 
-    $LOCK_VARS_USED   = array();
-    $LOCK_VARS_TO_USE = session::global_get('LOCK_VARS_TO_USE');
+    $LOCK_VARS_USED_GET   = array();
+    $LOCK_VARS_USED_POST   = array();
+    $LOCK_VARS_USED_REQUEST   = array();
+    $LOCK_VARS_TO_USE = session::get('LOCK_VARS_TO_USE');
 
     foreach($LOCK_VARS_TO_USE as $name){
 
@@ -1303,18 +1309,26 @@ function gen_locked_message($user, $dn, $allow_readonly = FALSE)
 
       foreach($_POST as $Pname => $Pvalue){
         if(preg_match($name,$Pname)){
-          $LOCK_VARS_USED[$Pname] = $_POST[$Pname];
+          $LOCK_VARS_USED_POST[$Pname] = $_POST[$Pname];
         }
       }
 
       foreach($_GET as $Pname => $Pvalue){
         if(preg_match($name,$Pname)){
-          $LOCK_VARS_USED[$Pname] = $_GET[$Pname];
+          $LOCK_VARS_USED_GET[$Pname] = $_GET[$Pname];
+        }
+      }
+
+      foreach($_REQUEST as $Pname => $Pvalue){
+        if(preg_match($name,$Pname)){
+          $LOCK_VARS_USED_REQUEST[$Pname] = $_REQUEST[$Pname];
         }
       }
     }
-    session::global_set('LOCK_VARS_TO_USE',array());
-    session::global_set('LOCK_VARS_USED'  , $LOCK_VARS_USED);
+    session::set('LOCK_VARS_TO_USE',array());
+    session::set('LOCK_VARS_USED_GET'  , $LOCK_VARS_USED_GET);
+    session::set('LOCK_VARS_USED_POST'  , $LOCK_VARS_USED_POST);
+    session::set('LOCK_VARS_USED_REQUEST'  , $LOCK_VARS_USED_REQUEST);
   }
 
   /* Prepare and show template */
@@ -1748,7 +1762,8 @@ function gen_uids($rule, $attributes)
 
     /* Don't assign used ones */
     if (!in_array($uid, $used)){
-      $ret[]= $uid;
+      /* Add uid, but remove {} first. These are invalid anyway. */
+      $ret[]= preg_replace('/[{}]/', '', $uid);
     }
   }
 
@@ -1979,40 +1994,7 @@ function compare_revision($revision_file, $revision)
 
 function progressbar($percentage,$width=100,$height=15,$showvalue=false)
 {
-  $str = ""; // Our return value will be saved in this var
-
-  $color  = dechex($percentage+150);
-  $color2 = dechex(150 - $percentage);
-  $bgcolor= $showvalue?"FFFFFF":"DDDDDD";
-
-  $progress = (int)(($percentage /100)*$width);
-
-  /* If theres a better solution for this, use it... */
-  $str = "\n   <div style=\" width:".($width)."px; ";
-  $str.= "\n       height:".($height)."px; ";
-  $str.= "\n       background-color:#000000; ";
-  $str.= "\n       padding:1px;\" > ";
-
-  $str.= "\n     <div style=\" width:".($width)."px; ";
-  $str.= "\n         background-color:#$bgcolor; ";
-  $str.= "\n         height:".($height)."px;\" > ";
-
-  if(($height >10)&&($showvalue)){
-    $str.= "\n   <font style=\"font-size:".($height-2)."px; ";
-    $str.= "\n     color:#FF0000; align:middle; ";
-    $str.= "\n     padding-left:".((int)(($width*0.4)))."px; \"> ";
-    $str.= "\n     <b>".$percentage."%</b> ";
-    $str.= "\n   </font> ";
-  }
-
-  $str.= "\n       <div style=\" width:".$progress."px; ";
-  $str.= "\n         height:".$height."px; ";
-  $str.= "\n         background-color:#".$color2.$color2.$color."; \" >";
-  $str.= "\n       </div>";
-  $str.= "\n     </div>";
-  $str.= "\n   </div>";
-
-  return($str);
+  return("<img src='progress.php?x=$width&amp;y=$height&amp;p=$percentage'>");
 }
 
 
@@ -2453,7 +2435,7 @@ function change_password ($dn, $password, $mode=0, $hash= "")
   // Get all available encryption Methods
 
   // NON STATIC CALL :)
-  $methods = new passwordMethod(session::global_get('config'));
+  $methods = new passwordMethod(session::get('config'));
   $available = $methods->get_available_methods();
 
   // read current password entry for $dn, to detect the encryption Method
@@ -2573,6 +2555,11 @@ function generate_smb_nt_hash($password)
     } else {
       $hash= "";
     }
+
+    if ($hash == "") {
+      msg_dialog::display(_("Configuration error"), _("Cannot generate samba hash!"), ERROR_DIALOG);
+      return ("");
+    }
   } else {
          $tmp= $config->get_cfg_value('sambaHashHook')." ".escapeshellarg($password);
          @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, $tmp, "Execute");
@@ -2581,11 +2568,11 @@ function generate_smb_nt_hash($password)
          flush();
          reset($ar);
          $hash= current($ar);
-  }
 
-  if ($hash == "") {
-         msg_dialog::display(_("Configuration error"), _("Cannot generate samba hash!"), ERROR_DIALOG);
-         return ("");
+    if ($hash == "") {
+      msg_dialog::display(_("Configuration error"), sprintf(_("Cannot generate samba hash: running '%s' failed, check the 'sambaHashHook'!"),$config->get_cfg_value('sambaHashHook')), ERROR_DIALOG);
+      return ("");
+    }
   }
 
   list($lm,$nt)= split (":", trim($hash));
@@ -2814,7 +2801,6 @@ function get_object_info()
 
 function set_object_info($str = "")
 {
-  echo "-->> $str <br>";
   session::set('objectinfo',$str);
 }