Code

Macro setting will be saved in Extension_table for asterisk
[gosa.git] / include / functions.inc
index 2810e186e9f5cd0b579979cd5263816260432671..27f188dcb96f64629b80b85fc83000a51326f10f 100644 (file)
@@ -178,7 +178,7 @@ function get_template_path($filename= '', $plugin= FALSE, $path= "")
 {
   global $config, $BASE_DIR;
 
-  if (!isset($config->data['MAIN']['THEME'])){
+  if (!@isset($config->data['MAIN']['THEME'])){
     $theme= 'default';
   } else {
     $theme= $config->data['MAIN']['THEME'];
@@ -302,7 +302,6 @@ function ldap_login_user ($username, $password)
 
     /* user not found */
     case 0:    return (NULL);
-            break;
 
             /* valid uniq user */
     case 1: 
@@ -465,6 +464,48 @@ function get_lock ($object)
 }
 
 
+function get_list2($subtreeACL, $filter, $subsearch= TRUE, $base="", $attrs= array(), $flag= FALSE)
+{
+ global $config;
+
+  /* Base the search on default base if not set */
+  $ldap= $config->get_ldap_link($flag);
+  if ($base == ""){
+    $ldap->cd ($config->current['BASE']);
+  } else {
+    $ldap->cd ($base);
+  }
+
+  /* Perform ONE or SUB scope searches? */
+  $ldap->ls ($filter);
+
+  /* Check for size limit exceeded messages for GUI feedback */
+  if (preg_match("/size limit/i", $ldap->error)){
+    $_SESSION['limit_exceeded']= TRUE;
+  } else {
+    $_SESSION['limit_exceeded']= FALSE;
+  }
+  $result= array();
+
+
+  /* Crawl through reslut entries and perform the migration to the
+     result array */
+  while($attrs = $ldap->fetch()) {
+    $dn= preg_replace("/[ ]*,[ ]*/", ",", $ldap->getDN());
+    foreach ($subtreeACL as $key => $value){
+      if (preg_match("/$key/", $dn)){
+        $attrs["dn"]= convert_department_dn($dn);
+        $result[]= $attrs;
+        break;
+      }
+    }
+  }
+
+
+  return ($result);
+
+}
+
 function get_list($subtreeACL, $filter, $subsearch= TRUE, $base="", $attrs= array(), $flag= FALSE)
 {
   global $config;
@@ -701,6 +742,22 @@ function convert_department_dn($dn)
   return rtrim($dep, "/");
 }
 
+function convert_department_dn2($dn)
+{
+  $dep= "";
+
+  /* Build a sub-directory style list of the tree level
+     specified in $dn */
+  $tmp = split (",", $dn);
+
+  $dep= preg_replace("%^.*/([^/]+)$%", "\\1", $tmp[0]);
+  
+  
+  /* Return and remove accidently trailing slashes */
+  $tmp = rtrim($dep, "/");
+  return $tmp;
+}
+
 
 function get_ou($name)
 {
@@ -896,7 +953,7 @@ function print_red()
   if (isset($_SESSION['DEBUGLEVEL'])){
     $_SESSION['errors'].= "<div align=\"left\" style=\"border-width:5px;".
       "border-style:solid;border-color:red; background-color:black;".
-      "margin-bottom:10px; padding:8px;\"><table summary=\"\" ><tr><td><img alt=\"\" src=\"".
+      "margin-bottom:10px; padding:8px;\"><table summary=''><tr><td><img alt=\"\" src=\"".
       get_template_path('images/warning.png')."\"></td>".
       "<td width=\"100%\" align=\"center\"><font color=\"#FFFFFF\">".
       "<b style='font-size:16px;'>$string</b></font></td><td>".
@@ -966,7 +1023,7 @@ function get_printer_list($cups_server)
 
     /* CUPS is not available, try lpstat as a replacement */
   } else {
-    unset ($ar);
+    $ar = false;
     exec("lpstat -p", $ar);
     foreach($ar as $val){
       list($dummy, $printer, $rest)= split(' ', $val, 3);
@@ -1134,8 +1191,12 @@ function range_selector($dcnt,$start,$range=25)
   }
 
   $numpages= (($dcnt / $range));
-  if(((int)($numpages))!=($numpages))
+  if(((int)($numpages))!=($numpages)){
     $numpages = (int)$numpages + 1;
+  }
+  if (((int)$numpages) <= 1 ){
+    return ("");
+  }
   $ppage= (int)(($start / $range) + 0.5);
 
 
@@ -1156,6 +1217,8 @@ function range_selector($dcnt,$start,$range=25)
     $begin= $end - $max_entries;
   }
 
+  $output.= "<div style='border:1px solid #E0E0E0; background-color:#FFFFFF;'>";
+
   /* Draw decrement */
   if ($start > 0 ) {
     $output.="  <a href= \"main.php?plug=".validate($_GET['plug'])."&amp;start=".
@@ -1182,6 +1245,8 @@ function range_selector($dcnt,$start,$range=25)
       "<img alt=\"\" src=\"images/forward.png\" border=0 align=\"middle\"></a>";
   }
 
+  $output.= "</div>";
+
   return($output);
 }
 
@@ -1191,7 +1256,7 @@ function apply_filter()
   $apply= "";
 
   $apply= ''.
-    '<table summary=\"\"  width="100%"  style="background:#EEEEEE;border-top:1px solid #B0B0B0;"><tr><td width="100%" align="right">'.
+    '<table summary=""  width="100%"  style="background:#EEEEEE;border-top:1px solid #B0B0B0;"><tr><td width="100%" align="right">'.
     '<input type="submit" name="apply" value="'._("Apply").'"></td></tr></table>';
 
   return ($apply);
@@ -1581,6 +1646,7 @@ function clean_smarty_compile_dir($directory)
       if(!compare_revision($revision_file, $svn_revision)){
         // If revision differs, clean compile directory
         foreach(scan_directory($directory) as $file) {
+          if(($file==".")||($file=="..")) continue;
           if( is_file($directory."/".$file) &&
               is_writable($directory."/".$file)) {
               // delete file