Code

Updated gosaDaemon class.
[gosa.git] / gosa-core / include / functions.inc
index 3ab7a405346f19d3c70c4ecef361737817333310..e0561c2bbfc0056c56635bd57d1a249c78b25750 100644 (file)
@@ -93,14 +93,46 @@ $REWRITE= array( "รค" => "ae",
 /* Class autoloader */
 function __autoload($class_name) {
     global $class_mapping, $BASE_DIR;
+
+    if ($class_mapping === NULL){
+           echo sprintf(_("Fatal error: no class locations defined - please run '%s' to fix this"), "<b>update-gosa</b>");
+           exit;
+    }
+
     if (isset($class_mapping[$class_name])){
       require_once($BASE_DIR."/".$class_mapping[$class_name]);
     } else {
-      echo _("Fatal: cannot load class \"$class_name\" - execution aborted");
+      echo sprintf(_("Fatal error: cannot instantiate class '%s' - try running '%s' to fix this"), $class_name, "<b>update-gosa</b>");
+      print_a(debug_backtrace());
+      exit;
     }
 }
 
 
+/*! \brief Checks if a class is available. 
+ *  @param  name String  The class name.
+ *  @return boolean      True if class is available, else false.
+ */
+function class_available($name)
+{
+  global $class_mapping;
+  return(isset($class_mapping[$name]));
+}
+
+
+/* Check if plugin is avaliable */
+function plugin_available($plugin)
+{
+       global $class_mapping, $BASE_DIR;
+
+       if (!isset($class_mapping[$plugin])){
+               return false;
+       } else {
+               return is_readable($BASE_DIR."/".$class_mapping[$plugin]);
+       }
+}
+
+
 /* Create seed with microseconds */
 function make_seed() {
   list($usec, $sec) = explode(' ', microtime());
@@ -725,7 +757,6 @@ function get_multiple_locks($objects)
  */
 function get_sub_list($filter, $category,$sub_base, $base= "", $attributes= array(), $flags= GL_SUBSEARCH)
 {
-
   global $config, $ui;
 
   /* Get LDAP link */
@@ -741,8 +772,12 @@ function get_sub_list($filter, $category,$sub_base, $base= "", $attributes= arra
   /* Remove , ("ou=1,ou=2.." => "ou=1") */
   $sub_base = preg_replace("/,.*$/","",$sub_base);
 
-  /* Check if there is a sub department specified */
-  if($sub_base == ""){
+  /* Check if we have enabled the sub_dir search support AND 
+   *  if there is a sub department specified.
+   * If not, fall back to old method, get_list().
+   */
+  $sub_enabled = isset($config->current['SUB_LIST_SUPPORT']) && preg_match("/true/i",$config->current['SUB_LIST_SUPPORT']);
+  if($sub_base == "" || !$sub_enabled){
     return(get_list($filter, $category,$base,$attributes,$flags));
   }
 
@@ -2593,12 +2628,28 @@ function remove_objectClass($classes, &$attrs)
   }
 }
 
+/*! \brief  Initialize a file download with given content, name and data type. 
+ *  @param  data  String The content to send.
+ *  @param  name  String The name of the file.
+ *  @param  type  String The content identifier, default value is "application/octet-stream";
+ */
+function send_binary_content($data,$name,$type = "application/octet-stream")
+{
+  header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
+  header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
+  header("Cache-Control: no-cache");
+  header("Pragma: no-cache");
+  header("Cache-Control: post-check=0, pre-check=0");
+  header("Content-type: ".$type."");
+
+  /* force download dialog */
+  if (preg_match('/MSIE 5.5/', $HTTP_USER_AGENT) || preg_match('/MSIE 6.0/', $HTTP_USER_AGENT)) {
+    header('Content-Disposition: filename="'.$name.'"');
+  } else {
+    header('Content-Disposition: attachment; filename="'.$name.'"');
+  }
 
-function display_error_page()
-{
-  $smarty= get_smarty();
-  $smarty->display(get_template_path('headers.tpl'));
-  echo "<body>".msg_dialog::get_dialogs()."</body></html>";
+  echo $data;
   exit();
 }