Code

Updated filter, added i18n to xml and added list
authorcajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 11 Aug 2009 16:17:20 +0000 (16:17 +0000)
committercajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 11 Aug 2009 16:17:20 +0000 (16:17 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14033 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/include/class_filter.inc
gosa-core/include/class_listing.inc [new file with mode: 0644]
gosa-core/include/utils/class_xml.inc

index dd3c9b335a14e40e00d74a8779dedfddcdabaf5f..9d4d9384e81ada3a402ad0fa91573df6a4e5cfa4 100644 (file)
@@ -59,6 +59,11 @@ class filter {
       $this->initial= true;
     }
 
+    // Transfer category
+    if (isset($this->xmlData['definition']['category'])){
+      $this->category= $this->xmlData['definition']['category'];
+    }
+
     // Generate formular data
     if (isset($this->xmlData['element'])) {
       if (!isset($this->xmlData['element'][0])){
@@ -149,28 +154,7 @@ class filter {
 
       // Handle translations
       if (is_array($value['set'])) {
-        $li= null;
-
-        // Get language index if available
-        $lang= preg_replace('/_.*$/', '', $GLOBALS['t_language']);
-        $mapper= array();
-        foreach($value['set'] as $index => $lv){
-          if (preg_match('/_attr$/', $index) && isset($lv['xml:lang']) && $lv['xml:lang'] == $lang) {
-            $li= preg_replace('/_attr$/', '', $index);
-            if (isset($mapper[$li])) {
-              unset($mapper[$li]);
-            }
-          } else {
-            $mapper[$index]= $index;
-          }
-        }
-
-        // Use some default if no index is available
-        if (!$li) {
-          $li= array_shift($mapper);
-        }
-
-        $result.= "<option value='".$value['key']."'$selected>".$value['set'][$li]."</option>";
+        $result.= "<option value='".$value['key']."'$selected>".xml::getLocalizedAttribute($value['set'], $GLOBALS['t_language'])."</option>";
       } else {
         $result.= "<option value='".$value['key']."'$selected>".$value['set']."</option>";
       }
@@ -229,11 +213,6 @@ class filter {
   }
 
 
-  function setCategory($category) {
-    $this->category= $category;    
-  }
-
-
   function setCurrentBase($base) {
     $this->base= $base;
   }
@@ -313,7 +292,7 @@ class filter {
   }
 
 
-  function renderFilter()
+  function render()
   {
     $smarty= get_smarty();
     $smarty->assign("ALPHABET", $this->renderAlphabet());
diff --git a/gosa-core/include/class_listing.inc b/gosa-core/include/class_listing.inc
new file mode 100644 (file)
index 0000000..aab36da
--- /dev/null
@@ -0,0 +1,179 @@
+<?php
+
+class listing {
+
+  var $xmlData;
+  var $entries;
+  var $departmentBrowser= false;
+  var $departmentRootVisible= false;
+  var $multiSelect= false;
+  var $template;
+  var $summary;
+  var $header= array();
+  var $colprops= array();
+
+  function listing($filename)
+  {
+    if (!$this->load($filename)) {
+      die("Cannot parse $filename!");
+    }
+  }
+
+
+  function load($filename)
+  {
+    $contents = file_get_contents($filename);
+    $this->xmlData= xml::xml2array($contents, 1);
+
+    if (!isset($this->xmlData['list'])) {
+      return false;
+    }
+
+    $this->xmlData= $this->xmlData["list"];
+
+    // Load some definition values
+    foreach (array("departmentBrowser", "departmentRootVisible", "multiSelect") as $token) {
+      if (isset($this->xmlData['definition'][$token]) &&
+          $this->xmlData['definition'][$token] == "true"){
+        $this->$token= true;
+      }
+    }
+
+    // Parse layout per column
+    $this->colprops= $this->parseLayout($this->xmlData['table']['layout']);
+
+    // Prepare table headers
+    $this->header= array();
+    if (isset($this->xmlData['table']['column'])){
+      foreach ($this->xmlData['table']['column'] as $index => $config) {
+        if (isset($config['header'])) {
+          $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">".xml::getLocalizedAttribute($config['header'], $GLOBALS['t_language'])."</td>";
+        } else {
+          $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">&nbsp;</td>";
+        }
+      }
+    }
+
+    return true;  
+  }
+
+
+  function render()
+  {
+    #print_a($this->xmlData);
+    #print_a($this->entries);
+echo "Fill summary, handle empty lists differently, alternating<br>";
+    $summary= "empty";
+
+    // Initialize list
+    $result= "<table summary='$summary' style='width:600px;height:450px;' cellspacing='0' id='t_scrolltable'>
+<tr><td class='scrollhead'><table summary='' style='width:100%;' cellspacing='0' id='t_scrollhead'>";
+    $num_cols= count($this->colprops) + ($this->multiSelect?1:0);
+
+    // Build list header
+    $result.= "<tr>";
+    if ($this->multiSelect) {
+      $result.= "<td class='listheader' style='width:20px;'><input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."' onClick='toggle_all_(\"item_selected_[0-9]*$\",\"select_all\");' ></td>";
+    }
+    foreach ($this->header as $header) {
+      $result.= $header;
+    }
+
+    // Add 13px for scroller
+    $result.= "<td class='listheader' style='width:13px;border-right:0px;'>&nbsp;</td></table></td></tr>";
+
+    // New table for the real list contents
+    $result.= "<tr><td colspan='$num_cols' class='scrollbody'><div style='width:100%;height:430px;' id='d_scrollbody' class='scrollbody'><table summary='' style='height:100%;width:581px;' cellspacing='0' id='t_scrollbody'>";
+
+    // Fill with contents
+    $first= true;
+    foreach ($this->entries as $entry){
+      $result.="<tr class='rowxp1'>";
+      foreach ($this->xmlData['table']['column'] as $config) {
+        if ($first) {
+          
+        } else {
+        }
+      }
+      $first= false;
+    }
+#    for ($i= 0; $i<10; $i++) {
+#      $result.="<tr class='rowxp1'>";
+#      $result.="<td  style='text-align:center;width:20px;'  class='list1'>&nbsp;</td>";
+#      $result.="<td  style='text-align:center;width:20px;'  class='list1'><image src='images/lists/folder.png' class='center'></td>";
+#      $result.="<td  style=''  class='list1'><a href='?plug=19&amp;post_id=12499984306&amp;act=dep_open&amp;dep_id=1'>Administrativa - [Funktionelle Daten]</a></td>";
+#      $result.="<td  style='width:100px;'  class='list1'>&nbsp;</td>";
+#      $result.="<td  style='width:158px;border-right:0px;'  class='list1'>&nbsp;</td>";
+#      $result.="</tr>";
+#    }
+
+    // Need to fill the list if it's not full (nobody knows why this is 22 ;-))
+    if (count($this->entries) < 22) {
+      $result.= "<tr>";
+      for ($i= 0; $i<=$num_cols; $i++) {
+        if ($i == 0) {
+          $result.= "<td class='list1nohighlight' style='height:100%;'>&nbsp;</td>";
+          continue;
+        }
+        if ($i != $num_cols-1) {
+          $result.= "<td class='list1nohighlight''>&nbsp;</td>";
+        } else {
+          $result.= "<td class='list1nohighlight' style='border-right:0px'>&nbsp;</td>";
+        }
+      }
+      $result.= "</tr>";
+    }
+
+    $result.= "</table></div></td></tr></table>";
+
+    return $result;
+  }
+
+
+  function setEntries($entries)
+  {
+    $this->entries= &$entries;
+  }
+
+
+  function parseLayout($layout)
+  {
+    $result= array();
+    $layout= preg_replace("/^\|/", "", $layout);
+    $layout= preg_replace("/\|$/", "", $layout);
+    $cols= split("\|", $layout);
+    foreach ($cols as $index => $config) {
+      if ($config != "") {
+        $components= split(';', $config);
+        $config= "";
+        foreach ($components as $part) {
+          if (preg_match("/^r$/", $part)) {
+            $config.= "text-align:right;";
+            continue;
+          }
+          if (preg_match("/^l$/", $part)) {
+            $config.= "text-align:left;";
+            continue;
+          }
+          if (preg_match("/^c$/", $part)) {
+            $config.= "text-align:center;";
+            continue;
+          }
+          if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
+            $config.= "width:$part;";
+            continue;
+          }
+        }
+
+        $result[$index]= " style='$config' ";
+      } else {
+        $result[$index]= null;
+      }
+    }
+
+    return $result;
+  }
+
+}
+
+?>
index 690ee7f2c0dedec7cc9a6e25798d9ffdaee3849b..096bb0973a0435376108bebf3c580c00ba614638 100644 (file)
@@ -143,4 +143,35 @@ class xml {
     
     return($xml_array);
   }
+
+
+  static function getLocalizedAttribute($attribute, $lang)
+  {
+    // Return directly if there's no lang code
+    if (!is_array($attribute)) {
+      return($attribute);
+    }
+
+    // Get language index if available
+    $lang= preg_replace('/_.*$/', '', $lang);
+    $mapper= array();
+    foreach($attribute as $index => $lv){
+      if (preg_match('/_attr$/', $index) && isset($lv['xml:lang']) && $lv['xml:lang'] == $lang) {
+        $li= preg_replace('/_attr$/', '', $index);
+        if (isset($mapper[$li])) {
+          unset($mapper[$li]);
+        }
+      } else {
+        $mapper[$index]= $index;
+      }
+    }
+
+    // Use some default if no index is available
+    if (!$li) {
+      $li= array_shift($mapper);
+    }
+
+    return $attribute[$li];
+  }
+
 }