Code

Fixed alphabet match
[gosa.git] / gosa-core / include / class_listing.inc
index 96e63ac83521f68ce404f41256e207d447c0d81e..095bbfbd720b63935f8841f693f0c6026403df47 100644 (file)
@@ -49,6 +49,8 @@ class listing {
   var $snapshotHandler= null;
   var $exporter= array();
   var $exportColumns= array();
+  var $useSpan= false;
+  var $height= 0;
 
 
   function listing($filename)
@@ -101,6 +103,12 @@ class listing {
   }
 
 
+  function setHeight($height)
+  {
+    $this->height= $height;
+  }
+
+
   function setSnapshotHandler($handler)
   {
     $this->snapshotHandler= &$handler;
@@ -256,8 +264,14 @@ class listing {
 
     // Initialize list
     $result= "<input type='hidden' value='$this->pid' name='PID'>\n";
+    $height= 450;
+    if ($this->height != 0) {
+      $result.= "<input type='hidden' value='$this->height' id='d_height'>\n";
+      $height= $this->height;
+    }
+    
     $result.= "<div class='contentboxb' id='listing_container' style='border-top:1px solid #B0B0B0;'>\n";
-    $result.= "<table summary='$this->headline' style='width:600px;height:450px;' cellspacing='0' id='t_scrolltable'>
+    $result.= "<table summary='$this->headline' style='width:600px;height:".$height."px;' cellspacing='0' id='t_scrolltable'>
 <tr><td class='scrollhead'><table summary='' style='width:100%;' cellspacing='0' id='t_scrollhead'>\n";
     $this->numColumns= count($this->colprops) + ($this->multiSelect?1:0);
 
@@ -274,7 +288,7 @@ class listing {
     $result.= "<td class='listheader' style='width:13px;border-right:0px;'>&nbsp;</td></table></td></tr>\n";
 
     // New table for the real list contents
-    $result.= "<tr><td colspan='$this->numColumns' class='scrollbody'><div style='width:600px;height:430px;' id='d_scrollbody' class='scrollbody'><table summary='' style='height:100%;width:581px;' cellspacing='0' id='t_scrollbody'>\n";
+    $result.= "<tr><td colspan='$this->numColumns' class='scrollbody'><div style='width:600px;height:".($height-20)."px;' id='d_scrollbody' class='scrollbody'><table summary='' style='height:100%;width:581px;' cellspacing='0' id='t_scrollbody'>\n";
 
     // No results? Just take an empty colspanned row
     if (count($this->entries) + count($this->departments) == 0) {
@@ -286,6 +300,7 @@ class listing {
     $deps= 0;
 
     // Draw department browser if configured and we're not in sub mode
+    $this->useSpan= false;
     if ($this->departmentBrowser && $this->filter->scope != "sub") {
       // Fill with department browser if configured this way
       $departmentIterator= new departmentSortIterator($this->departments, $this->sortDirection[$this->sortColumn]);
@@ -303,6 +318,7 @@ class listing {
           $colspan= 1;
           if (isset($config['span'])){
             $colspan= $config['span'];
+            $this->useSpan= true;
           }
           $result.="<td colspan='$colspan' ".$this->colprops[$index]." class='list1'>".$this->renderCell($config['value'], $entry, $row)."</td>";
           $rest-= $colspan;
@@ -356,7 +372,7 @@ class listing {
     }
 
     // Need to fill the list if it's not full (nobody knows why this is 22 ;-))
-    $emptyListStyle= (count($this->entries) + $deps == 0)?"border:0;":"";
+    $emptyListStyle= (count($this->entries) + (($this->useSpan && count($this->entries))?$deps:0) == 0)?"border:0;":"";
     if ((count($this->entries) + $deps) < 22) {
       $result.= "<tr>";
       for ($i= 0; $i<$this->numColumns; $i++) {
@@ -392,6 +408,7 @@ class listing {
     $result.= "</table></div>";
 
     $smarty= get_smarty();
+    $smarty->assign("usePrototype", "true");
     $smarty->assign("FILTER", $this->filter->render());
     $smarty->assign("SIZELIMIT", print_sizelimit_warning());
     $smarty->assign("LIST", $result);
@@ -424,9 +441,8 @@ class listing {
     // Reset object counter
     $this->objectTypeCount= array();
 
-    // Do not do anything if this is not our PID or there's even
-    // no PID available
-    if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
+    // Do not do anything if this is not our PID
+    if(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid) {
       return;
     }
 
@@ -452,7 +468,12 @@ class listing {
       if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
         $exporter= $this->exporter[$_POST['act']];
         $userinfo= ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
-        $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $this->entries, $this->exportColumns);
+        $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
+        $sortedEntries= array();
+        foreach ($entryIterator as $entry){
+          $sortedEntries[]= $entry;
+        }
+        $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
         $type= call_user_func(array($exporter['class'], "getInfo"));
         $type= $type[$_POST['act']];
         send_binary_content($instance->query(), $type['filename'], $type= $type['mime']);
@@ -499,7 +520,7 @@ class listing {
     }
     if ($action == 'HOME') {
       $ui= get_userinfo();
-      $this->base= get_base_from_people($ui->dn);
+      $this->base= $this->filter->getObjectBase($ui->dn);
     }
 
     // Reload departments
@@ -752,9 +773,28 @@ class listing {
     foreach($actions as $action) {
       // Skip the entry completely if there's no permission to execute it
       if (!$this->hasActionPermission($action, $dn)) {
+        $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
         continue;
       }
 
+      // Skip entry if the pseudo filter does not fit
+      if (isset($action['filter']) && preg_match('/^[a-z0-9_]+!?=[a-z0-9_]+$/i', $action['filter'])) {
+        list($fa, $fv)= split('=', $action['filter']);
+        if (preg_match('/^(.*)!$/', $fa, $m)){
+          $fa= $m[1];
+          if (isset($this->entries[$row][$fa]) && $this->entries[$row][$fa][0] == $fv) {
+            $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
+            continue;
+          }
+        } else {
+          if (!isset($this->entries[$row][$fa]) && !$this->entries[$row][$fa][0] == $fv) {
+            $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
+            continue;
+          }
+        }
+      }
+
+
       // If there's an objectclass definition and we don't have it
       // add an empty picture here.
       if (isset($action['objectclass'])){
@@ -864,7 +904,7 @@ class listing {
     $listhead ="";
 
     /* Check if we are in users home  department */
-    if(!count($deps) ||$this->filter->base == get_base_from_people($ui->dn)){
+    if(!count($deps) || $this->filter->base == $this->filter->getObjectBase($ui->dn)){
       $enableHome = false;
     }
 
@@ -976,10 +1016,15 @@ class listing {
       return "";
     }
 
+    // Array?
+    if (isset($this->xmlData['actionmenu']['action']['type'])){
+      $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
+    }
+
     // Load shortcut
     $actions= &$this->xmlData['actionmenu']['action'];
     $result= "<input type='hidden' name='act' id='actionmenu' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>".
-             "<ul class='level1' id='root'><li><a href='#'>Aktionen&nbsp;<img ".
+             "<ul class='level1' id='root'><li><a href='#'>"._("Actions")."&nbsp;<img ".
              "border=0 class='center' src='images/lists/sort-down.png'></a>";
 
     // Build ul/li list
@@ -991,6 +1036,7 @@ class listing {
 
   function recurseActions($actions)
   {
+    global $class_mapping;
     static $level= 2;
     $result= "<ul class='level$level'>";
     $separator= "";
@@ -1002,6 +1048,16 @@ class listing {
         continue;
       }
 
+      // Skip entry if there're missing dependencies
+      if (isset($action['depends'])) {
+        $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
+        foreach($deps as $clazz) {
+          if (!isset($class_mapping[$clazz])){
+            continue 2;
+          }
+        }
+      }
+
       // Fill image if set
       $img= "";
       if (isset($action['image'])){
@@ -1168,7 +1224,7 @@ class listing {
       $attrs[]= $data['ATTR'];
     }
     $filter.= "))";
-    $res= get_list($filter, $this->module, $this->base, $attrs, GL_NONE | GL_SIZELIMIT);
+    $res= get_list($filter, $this->module, $this->base, $attrs, GL_NONE);
 
     // Analyze list of departments
     foreach ($res as $department) {