Code

Updated reference tab
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 26 Apr 2010 10:23:21 +0000 (10:23 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 26 Apr 2010 10:23:21 +0000 (10:23 +0000)
-Allows to view entry ldifs now.

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@17832 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/ihtml/themes/default/ldifViewer.tpl [new file with mode: 0644]
gosa-core/include/class_ldap.inc
gosa-core/plugins/generic/references/class_ldifViewer.inc [new file with mode: 0644]
gosa-core/plugins/generic/references/class_reference.inc

diff --git a/gosa-core/ihtml/themes/default/ldifViewer.tpl b/gosa-core/ihtml/themes/default/ldifViewer.tpl
new file mode 100644 (file)
index 0000000..dee813f
--- /dev/null
@@ -0,0 +1,8 @@
+
+<pre>
+{$ldif}
+</pre>
+<hr>
+<div class="plugin-actions">
+    <button name='cancelLdifViewer'>{msgPool type='cancelButton'}</button>
+</div>
index 75901c78001dc6228dc35e445ec4c348f4acb683..1a991f1b6e122ba7466593abe2bd1ec1336cda9a 100644 (file)
@@ -857,27 +857,16 @@ class LDAP{
   }
 
 
-  function gen_ldif ($srp, $dn, $filter= "(objectClass=*)", $attributes= array('*'), $recursive= TRUE)
+  function generateLdif ($dn, $filter= "(objectClass=*)", $attributes= array(), $scope = 'sub', $limit=0)
   {
-    $display= "";
-
-    if ($recursive){
-      $this->cd($dn);
-      $this->ls($srp, $filter,$dn, array('dn','objectClass'));
-      $deps = array();
-
-      $display .= $this->gen_one_entry($dn)."\n";
-
-      while ($attrs= $this->fetch($srp)){
-        $deps[] = $attrs['dn'];
-      }
-      foreach($deps as $dn){
-        $display .= $this->gen_ldif($srp, $dn, $filter,$attributes,$recursive);
-      }
-    } else {
-      $display.= $this->gen_one_entry($dn);
-    }
-    return ($display);
+    $host = $this->hostname;
+    $attrs  = (count($attributes))?implode($attributes,' '):'';
+    $scope = (!empty($scope))?' -s '.$scope: '';
+    $limit = (!$limit)?'':' -z '.$limit;
+    $cmd = "ldapsearch -x -LLLL '{$filter}' {$limit} {$scope} -H '{$host}' -b '{$dn}' $attrs";
+    exec($cmd, $ret,$code);
+    $res = implode($ret,"\n");
+    return($res);
   }
 
 
@@ -904,57 +893,6 @@ class LDAP{
   }
 
 
-  function gen_one_entry($dn, $filter= "(objectClass=*)" , $name= array("*"))
-  {
-    $ret = "";
-    $data = "";
-    if($this->reconnect){
-      $this->connect();
-    }
-
-    /* Searching Ldap Tree */
-    $sr= @ldap_read($this->cid, LDAP::fix($dn), $filter, $name);
-
-    /* Get the first entry */   
-    $entry= @ldap_first_entry($this->cid, $sr);
-
-    /* Get all attributes related to that Objekt */
-    $atts = array();
-    
-    /* Assemble dn */
-    $atts[0]['name']  = "dn";
-    $atts[0]['value'] = array('count' => 1, 0 => $dn);
-
-    /* Reset index */
-    $i = 1 ; 
-  $identifier = array();
-    $attribute= @ldap_first_attribute($this->cid,$entry,$identifier);
-    while ($attribute) {
-      $i++;
-      $atts[$i]['name']  = $attribute;
-      $atts[$i]['value'] = @ldap_get_values_len($this->cid, $entry, "$attribute");
-
-      /* Next one */
-      $attribute= @ldap_next_attribute($this->cid,$entry,$identifier);
-    }
-
-    foreach($atts as $at)
-    {
-      for ($i= 0; $i<$at['value']['count']; $i++){
-
-        /* Check if we must encode the data */
-        if(!preg_match('/^[a-z0-9+@#.=, \/ -]+$/i', $at['value'][$i])) {
-          $ret .= $at['name'].":: ".base64_encode($at['value'][$i])."\n";
-        } else {
-          $ret .= $at['name'].": ".$at['value'][$i]."\n";
-        }
-      }
-    }
-
-    return($ret);
-  }
-
-
   function dn_exists($dn)
   {
     return @ldap_list($this->cid, LDAP::fix($dn), "(objectClass=*)", array("objectClass"));
diff --git a/gosa-core/plugins/generic/references/class_ldifViewer.inc b/gosa-core/plugins/generic/references/class_ldifViewer.inc
new file mode 100644 (file)
index 0000000..79d2381
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+
+class ldifViewer extends plugin
+{
+    private $ldif;    
+
+    function __construct($config, $dn)
+    {
+        $this->config = &$config;
+        $this->dn = $dn;
+        $ldap = $this->config->get_ldap_link();
+        $this->ldif=$ldap->generateLdif(LDAP::fix($this->dn),'(objectClass=*)',array(),'base');
+    }
+
+    function execute()
+    {
+        $smarty = get_smarty();
+        $smarty->assign('ldif', $this->ldif);
+        return($smarty->fetch(get_template_path('ldifViewer.tpl')));
+    }
+}
+
+?>
index 3bb9c1ed7b5df57bfd3605cd4c3777e566bef33a..80ed7d304fddc945c79ac2a7c2b75e9efe86553a 100644 (file)
@@ -132,10 +132,14 @@ class reference extends plugin
         // Mark plugin as viewed
         plugin::execute();
 
+        // Show ldif viewer
         if(isset($_POST['viewLdif'])){
-            echo "ding!";
+            $this->dialog = new ldifViewer($this->config, $this->dn);
+        }
+        if(isset($_POST['cancelLdifViewer'])) $this->dialog = NULL;
+        if($this->dialog instanceOf ldifViewer){
+            return($this->dialog->execute());
         }
-
 
         $smarty = get_smarty();