Code

Updated viewport
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 6 Nov 2007 07:32:44 +0000 (07:32 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 6 Nov 2007 07:32:44 +0000 (07:32 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6-playground@7737 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa.conf
include/class_ObjectList.inc
include/class_ObjectListViewport.inc
test

index 02f25da4cd6ffab6cb8f993132fd36cac131b4c6..36b145b2e852be4e24fbda165d6bce46c82e1137 100644 (file)
--- a/gosa.conf
+++ b/gosa.conf
@@ -119,6 +119,6 @@ kiosk-path = "/var/spool/kiosk"
 ppd-path = "/var/spool/ppds"
 
 [plugin/sample]
-headline= "|{16px}|{90%}Name|{64px:R}Actions|"
+headline= "|{196px}|{:CB}Name|{64px:R}Actions|"
 footer= "Statistics with no information currently"
 entryFormat= "|{_icon}|{cn} ({_filter(uppercase,{cn})})|{_actions}|"
index 9185c7b42713f98af0b0c5ce2456180c3318fdc3..9958f2fc890a999fd3f2fcd17d1b7d334b84fddd 100644 (file)
@@ -68,14 +68,286 @@ class ObjectList implements IteratorAggregate {
          defined filter modules. Handles sorting, too.
         */
        private function load(){
-    # Crap filling
+# Crap filling
     $this->objects= array(
-                            array("dn" => "cn=Demo client,ou=systems,dc=gonicus,dc=de", "cn" => "Demo client", "_icon" => "s_terminal.png", "_actions" => "ED", "objectClass" => array('gotoWorkstation')),
-                            array("dn" => "cn=Demo client2,ou=systems,dc=gonicus,dc=de", "cn" => "Demo client2", "_icon" => "s_terminal.png", "_actions" => "ED", "objectClass" => array('gotoWorkstation')),
-                            array("dn" => "cn=Printer,ou=systems,dc=gonicus,dc=de", "cn" => "Printer", "_icon" => "s_printer.png", "_actions" => "ED", "objectClass" => array('gotoPrinter')),
-                            array("dn" => "cn=Server,ou=systems,dc=gonicus,dc=de", "cn" => "Server", "_icon" => "s_server.png", "_actions" => "ED", "objectClass" => array("goServer")),
-                           );
-       }
+
+ array("dn" => "cn=1aherbertskiste,ou=workstations,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "1aherbertskiste",
+              "_icon" => "select_workstation.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=72:9c:13:e9:72:2b,ou=incoming,o=Landeshauptstadt München,c=de",
+              "cn" => "72:9c:13:e9:72:2b",
+              "_icon" => "select_newsystem.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=8f:9c:d0:d5:42:c0,ou=incoming,o=Landeshauptstadt München,c=de",
+              "cn" => "8f:9c:d0:d5:42:c0",
+              "_icon" => "select_newsystem.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=a.b_c,ou=printers,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "a.b_c",
+              "_icon" => "select_printer.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=a5:35:77:86:ff:ca,ou=workstations,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "a5:35:77:86:ff:ca",
+              "_icon" => "select_workstation.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=cl1--141,ou=workstations,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "cl1--141",
+              "_icon" => "select_workstation.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=d9:57:9d:08:2c:65,ou=incoming,o=Landeshauptstadt München,c=de",
+              "cn" => "d9:57:9d:08:2c:65",
+              "_icon" => "select_newsystem.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=dyn-111,ou=servers,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "dyn-111",
+              "_icon" => "select_server.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=e3:b4:43:51:f6:13,ou=incoming,o=Landeshauptstadt München,c=de",
+              "cn" => "e3:b4:43:51:f6:13",
+              "_icon" => "select_newsystem.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=f2:d7:ef:92:e6:43,ou=incoming,o=Landeshauptstadt München,c=de",
+              "cn" => "f2:d7:ef:92:e6:43",
+              "_icon" => "select_newsystem.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=f9:fa:4e:f8:1a:40,ou=incoming,o=Landeshauptstadt München,c=de",
+              "cn" => "f9:fa:4e:f8:1a:40",
+              "_icon" => "select_newsystem.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=hu_ber-test.gonicus.de,ou=printers,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "hu_ber-test.gonicus.de",
+              "_icon" => "select_printer.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=loghost-01,ou=servers,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "loghost-01",
+              "_icon" => "select_server.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=ntp.jp.,ou=servers,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "ntp.jp.",
+              "_icon" => "select_server.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=phone-1.gonicus.de.,ou=phones,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "phone-1.gonicus.de.",
+              "_icon" => "select_phone.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=printer.222,ou=printers,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "printer.222",
+              "_icon" => "select_printer.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=printer,ou=printers,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "printer",
+              "_icon" => "select_printer.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=shares.jp.,ou=servers,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "shares.jp. [Share server]",
+              "_icon" => "select_server.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=terminal.jp.,ou=servers,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "terminal.jp.",
+              "_icon" => "select_server.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=test.test.etst,ou=printers,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "test.test.etst",
+              "_icon" => "select_printer.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=tester,ou=printers,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "tester",
+              "_icon" => "select_printer.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=vserver-04.intranet.gonicus.de,ou=servers,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "vserver-04.intranet.gonicus.de [Mail Server]",
+              "_icon" => "select_server.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=workstation,ou=workstations,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "workstation",
+              "_icon" => "select_workstation.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+ array("dn" => "cn=1aherbertskiste,ou=workstations,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "1aherbertskiste",
+              "_icon" => "select_workstation.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=72:9c:13:e9:72:2b,ou=incoming,o=Landeshauptstadt München,c=de",
+              "cn" => "72:9c:13:e9:72:2b",
+              "_icon" => "select_newsystem.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=8f:9c:d0:d5:42:c0,ou=incoming,o=Landeshauptstadt München,c=de",
+              "cn" => "8f:9c:d0:d5:42:c0",
+              "_icon" => "select_newsystem.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=a.b_c,ou=printers,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "a.b_c",
+              "_icon" => "select_printer.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=a5:35:77:86:ff:ca,ou=workstations,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "a5:35:77:86:ff:ca",
+              "_icon" => "select_workstation.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=cl1--141,ou=workstations,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "cl1--141",
+              "_icon" => "select_workstation.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=d9:57:9d:08:2c:65,ou=incoming,o=Landeshauptstadt München,c=de",
+              "cn" => "d9:57:9d:08:2c:65",
+              "_icon" => "select_newsystem.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=dyn-111,ou=servers,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "dyn-111",
+              "_icon" => "select_server.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=e3:b4:43:51:f6:13,ou=incoming,o=Landeshauptstadt München,c=de",
+              "cn" => "e3:b4:43:51:f6:13",
+              "_icon" => "select_newsystem.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=f2:d7:ef:92:e6:43,ou=incoming,o=Landeshauptstadt München,c=de",
+              "cn" => "f2:d7:ef:92:e6:43",
+              "_icon" => "select_newsystem.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=f9:fa:4e:f8:1a:40,ou=incoming,o=Landeshauptstadt München,c=de",
+              "cn" => "f9:fa:4e:f8:1a:40",
+              "_icon" => "select_newsystem.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=hu_ber-test.gonicus.de,ou=printers,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "hu_ber-test.gonicus.de",
+              "_icon" => "select_printer.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=loghost-01,ou=servers,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "loghost-01",
+              "_icon" => "select_server.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=ntp.jp.,ou=servers,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "ntp.jp.",
+              "_icon" => "select_server.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=phone-1.gonicus.de.,ou=phones,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "phone-1.gonicus.de.",
+              "_icon" => "select_phone.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=printer.222,ou=printers,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "printer.222",
+              "_icon" => "select_printer.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=printer,ou=printers,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "printer",
+              "_icon" => "select_printer.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=shares.jp.,ou=servers,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "shares.jp. [Share server]",
+              "_icon" => "select_server.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=terminal.jp.,ou=servers,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "terminal.jp.",
+              "_icon" => "select_server.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=test.test.etst,ou=printers,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "test.test.etst",
+              "_icon" => "select_printer.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=tester,ou=printers,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "tester",
+              "_icon" => "select_printer.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=vserver-04.intranet.gonicus.de,ou=servers,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "vserver-04.intranet.gonicus.de [Mail Server]",
+              "_icon" => "select_server.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation')),
+
+ array("dn" => "cn=workstation,ou=workstations,ou=systems,o=Landeshauptstadt München,c=de",
+              "cn" => "workstation",
+              "_icon" => "select_workstation.png",
+              "_actions" => "CPSRED",
+              "objectClass" => array('gotoWorkstation'))
+
+        );
+  }
 
 
        /*! \brief Function to reload object list in case of external changes
index da9b985084f882b25c048ac7fdce62874a24887e..84cf37c648691f8fb3530196d27cecfd218ea7f9 100644 (file)
@@ -57,7 +57,7 @@ class ObjectListViewport {
     /* Dummy here */
     $cr= Registry::getInstance("ConfigManager");
     $cr->setSection($config);
-    $this->headline= $cr->getValue("headline");
+    $this->headline= $this->parseHeadline($cr->getValue("headline"));
     $this->footer= $cr->getValue("footer");
     $this->entryFormat= $cr->getValue("entryFormat");
 
@@ -117,6 +117,14 @@ class ObjectListViewport {
     /* Copy template */
     $buffer= $this->entryFormat;
 
+    $tmp = split("\|",trim($this->entryFormat,"|"));  
+
+    $buffer ="<tr>\n";
+    foreach($tmp as $key => $value){
+      $buffer .= "<td style='".$this->headline[$key]['style']."'>".$value."</td>\n";
+    }
+    $buffer.="</tr>\n";
+
     /* Replace set of attributes */
     foreach ($this->attributes as $attribute){
       if (!isset($entry[$attribute])){
@@ -131,7 +139,7 @@ class ObjectListViewport {
     foreach ($matches as $match){
       $filterName= preg_replace('/,.+$/', '', $match[1]);
       $filterParameter= preg_replace('/^[^,]+,/', '', $match[1]);
-      $buffer= preg_replace('/\{_filter\('.$match[1].'\)\}/', $this->applyEntryFilter($filterName, $filterParameter), $buffer);
+      $buffer= preg_replace('/\{_filter\('.normalizePreg($match[1]).'\)\}/', $this->applyEntryFilter($filterName, $filterParameter), $buffer);
     }
 
     #TODO: Make $buffer a proper HTML table output
@@ -159,6 +167,7 @@ class ObjectListViewport {
       \return HTML rendered list
         */
   public function render() {
+
     /* Generate fixed headline */
     $buffer= $this->renderHeadline();
 
@@ -171,9 +180,67 @@ class ObjectListViewport {
     /* Generate footer */
     $buffer.= $this->renderFooter();
 
-    return ($buffer);
+    return ("<table border=1 style='width:100%'>".$buffer."</table>");
   }
 
+
+       /*! \brief Parses the given headline format string 
+
+      \return Array with cell properties (width, alignment,name)
+        */
+  private function parseHeadline($data)
+  {
+    /* Each cell definition is seperated by | 
+     *  split by and go through each definition
+     */
+    $tmp = split("\|",trim($data,"|"));  
+    $cell_formats = array();
+    foreach($tmp as $key => $data){
+
+      $s_width    = "";
+      $s_alignment= "";
+      $s_name     = preg_replace("/\{[^\}]*+\}/","",$data);
+      $s_style    = "height:40px;";
+    
+      /* Parse format string and detect width & alignment */
+      if(preg_match("/\{.*\}/",$data)){
+        $s_format=  preg_replace("/^[^\{]*+\{([^\}]*).*$/","\\1",$data);
+    
+        /* Get aligment */
+        if(preg_match("/:/",$s_format)){
+          $s_al = preg_replace("/^[^:]*+:([a-z]*).*$/i","\\1",$s_format);
+
+          if(preg_match("/T/i",$s_al)){
+            $s_alignment.= "top-"  ;
+            $s_style.= "vertical-align: top;";
+          }
+          if(preg_match("/B/i",$s_al)){
+            $s_alignment.= "bottom-"  ;
+            $s_style.= "vertical-align: bottom;";
+          }
+          if(preg_match("/R/i",$s_al)){
+            $s_alignment.= "right"  ;
+            $s_style.= "text-align: right;";
+          }elseif(preg_match("/L/i",$s_al)){
+            $s_alignment.= "left"  ;
+            $s_style.= "text-align: left;";
+          }elseif(preg_match("/C/i",$s_al) || preg_match("/M/i",$s_al) ){
+            $s_alignment.= "center"  ;
+            $s_style.= "text-align: center;";
+          }
+        }
+
+        /* Get width */
+        $s_width = preg_replace("/^([^:]*).*$/","\\1",$s_format);
+        if(!empty($s_width)){
+          $s_style = "width: ".$s_width.";";
+        }
+        
+        $cell_formats[$key] = array("name" => $s_name, "width" => $s_width, "alignment" => $s_alignment,"style" => $s_style);
+      }
+    }
+    return($cell_formats);
+  }
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
diff --git a/test b/test
index ff8262398ce563211f22cb1ca5bcc0af7b54c145..3c8f54fe20355daecd2efab71df836af6c8edcfa 100755 (executable)
--- a/test
+++ b/test
@@ -4,9 +4,17 @@
 /* This is good for testing... */
 error_reporting (E_ALL | E_STRICT);
 
+/* Escape all preg_* relevant characters */
+function normalizePreg($input)
+{
+  return (addcslashes($input, '[]()|/.*+-'));
+}
+
+
+
 /* Initiate autoloader... */
 require_once("include/autoload.inc");
-
+restore_error_handler();
 try {
 
        /* Get new test instance of the Configuration */