Code

Removed debug output
[gosa.git] / gosa-core / include / functions.inc
index 34ab7348282a21299de084f5255dab123b874207..df32e69ea857864c9cb278cefa02afef3b14d365 100644 (file)
@@ -528,6 +528,7 @@ function ldap_login_user_htaccess ($username)
   /* Bail out if we have login restrictions set, for security reasons
      the message is the same than failed user/pw */
   if (!$ui->loginAllowed()){
+    new log("security","login","",array(),"Login restriction for user \"$username\", login not permitted");
     return (NULL);
   }
 
@@ -624,6 +625,7 @@ function ldap_login_user ($username, $password)
   /* Bail out if we have login restrictions set, for security reasons
      the message is the same than failed user/pw */
   if (!$ui->loginAllowed()){
+    new log("security","login","",array(),"Login restriction for user \"$username\", login not permitted");
     return (NULL);
   }
 
@@ -3504,5 +3506,82 @@ function get_next_id_traditional($attrib, $dn)
 }
 
 
+/* Mark the occurance of a string with a span */
+function mark($needle, $haystack, $ignorecase= true)
+{
+  $result= "";
+
+  while (preg_match('/^(.*)('.preg_quote($needle).')(.*)$/i', $haystack, $matches)) {
+    $result.= $matches[1]."<span class='mark'>".$matches[2]."</span>";
+    $haystack= $matches[3];
+  }
+
+  return $result.$haystack;
+}
+
+
+/* Return an image description using the path */
+function image($path, $action= "", $title= "", $align= "middle")
+{
+  global $config;
+  global $BASE_DIR;
+  $label= null;
+
+  // Bail out, if there's no style file
+  if(!session::global_is_set("img-styles")){
+
+    // Get theme
+    if (isset ($config)){
+      $theme= $config->get_cfg_value("theme", "default");
+    } else {
+      # For debuging - avoid that there's no theme set
+      die("config not set!");
+      $theme= "default";
+    }
+
+    if (!file_exists("$BASE_DIR/ihtml/themes/$theme/img.styles")){
+      die ("No img.style for this theme found!");
+    }
+
+    session::global_set('img-styles', unserialize(file_get_contents("$BASE_DIR/ihtml/themes/$theme/img.styles")));
+  }
+  $styles= session::global_get('img-styles');
+
+  /* Extract labels from path */
+  if (preg_match("/\.png\[(.*)\]$/", $path, $matches)) {
+    $label= $matches[1];
+  }
+
+  $lbl= "";
+  if ($label) {
+    if (isset($styles["images/label-".$label.".png"])) {
+      $lbl= "<div style='".$styles["images/label-".$label.".png"]."'></div>";
+    } else {
+      die("Invalid label specified: $label\n");
+    }
+
+    $path= preg_replace("/\[.*\]$/", "", $path);
+  }
+
+  // Non middle layout?
+  if ($align == "middle") {
+    $align= "";
+  } else {
+    $align= ";vertical-align:$align";
+  }
+
+  // Clickable image or not?
+  if ($title != "") {
+    $title= "title='$title'";
+  }
+  if ($action == "") {
+    return "<div class='img' $title style='".$styles[$path]."$align'>$lbl</div>";
+  } else {
+    return "<input type='submit' class='img' id='$action' value='' name='$action' $title style='".$styles[$path]."$align'>";
+  }
+}
+
+
+
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>