steffen: server/kolab/kolab/admin/addressbook create_vcard.php, 1.6, 1.7 head.php, 1.6, 1.7 index.php, 1.7, 1.8

cvs at intevation.de cvs at intevation.de
Fri Apr 16 12:17:30 CEST 2004


Author: steffen

Update of /kolabrepository/server/kolab/kolab/admin/addressbook
In directory doto:/tmp/cvs-serv22487/admin/addressbook

Modified Files:
	create_vcard.php head.php index.php 
Log Message:
Started restructuring the webinterface. New classes:

KolabLdap: Class for accessing the ldap server, API not fully evolved yet
KolabAuth: Class for authenticating a user using the LDAP class
KolabForm: HTML form handling class. This is supposed to replace the many 
	long input forms in the webinterface. Currently it is only used in
	user/ and some error-handling is missing



Index: create_vcard.php
===================================================================
RCS file: /kolabrepository/server/kolab/kolab/admin/addressbook/create_vcard.php,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- create_vcard.php	14 Jun 2003 17:06:31 -0000	1.6
+++ create_vcard.php	16 Apr 2004 10:17:28 -0000	1.7
@@ -5,7 +5,8 @@
  This program is Free Software under the GNU General Public License (>=v2). 
  Read the file COPYING that comes with this packages for details.
 */
-    include("head.php");
+require_once('../include/authenticate.php');
+include("head.php");
 
     This("addressbook/create_vcard.php?action=create");
 
@@ -13,13 +14,11 @@
 
     include("../include/checks.php");
 ?>
-
 <TABLE WIDTH="100%" CELLSPACING=0 CELLPADDING=0 BORDER=0>
-
 <?
 function debug ($a) 
 {
-//   print "debug: $a<br>\n";
+  //print "debug: $a<br>\n";
 }
 
 debug("debug is on");
@@ -34,10 +33,10 @@
 $dn="";
 if (!empty($HTTP_GET_VARS['dn'])) $dn = trim(urldecode($HTTP_GET_VARS['dn']));
 
-if (!($uid = $_SERVER['PHP_AUTH_USER']) ||
-    !($bind_dn = uid2dn($uid)) ||
-    !($group = uid2group($uid)))
-   array_push($errors, "Internal Error: could not get Authentication Information");
+$uid = $auth->uid();
+$bind_dn = $auth->dn();
+$group = $auth->group();
+$link = $ldap->connection;
 
 if (!$errors && $group != "maintainer" && $group != "admin") 
    array_push($errors, "Error: You don't have the required Permissions"); 
@@ -46,54 +45,11 @@
 
 $myself = $_SERVER['PHP_SELF'];
 
-if (!empty($_SESSION['ldap_server'])) $ldap_server = $_SESSION['ldap_server'];
-   else $ldap_server = '127.0.0.1';
-
-if (!empty($_SESSION['ldap_port'])) $ldap_port = $_SESSION['ldap_port'];
-   else $ldap_port = 389;
-
 $attributes = array( 'title', 'cn', 'sn', 'mail', 'alias', 'o',
                      'ou', 'roomNumber', 'street', 'postOfficeBox',
                      'postalCode', 'l', 'c', 'telephoneNumber',
                      'facsimileTelephoneNumber' );
 
-$utf8 = array ( 'cn', 'title', 'o', 'ou', 'roomNumber', 'street', 'sn',
-                'postOfficeBox', 'postalCode', 'l', 'c', 'telephoneNumber',
-                'facsimileTelephoneNumber' );
-
-function to_utf8 ($a)
-{
-   global $utf8;
-   global $attributes;
-   foreach ($attributes as $attr) {
-      if (!in_array($attr,$utf8) || empty($a[$attr])) continue;
-      if (is_array($a[$attr])) {
-         $index = 0;
-         while (!empty($a[$attr][$index])) {
-            $a[$attr][$index] = utf8_encode($a[$attr][$index]);
-            $index++;
-         }
-      } elseif (!empty($a[$attr])) $a[$attr] = utf8_encode($a[$attr]);
-   }
-   return $a;
-}
-
-function from_utf8 ($a)
-{
-   global $utf8;
-   global $attributes;
-   foreach ($attributes as $attr) {
-      if (!in_array($attr,$utf8) || empty($a[$attr])) continue;
-      if (is_array($a[$attr])) {
-         $index = 0;
-         while (!empty($a[$attr][$index])) {
-            $a[$attr][$index] = utf8_decode($a[$attr][$index]);
-            $index++;
-         }
-      } elseif (!empty($a[$attr])) $a[$attr] = utf8_decode($a[$attr]);
-   }
-   return $a;
-}
 
 function fill_up($a)
 {
@@ -166,9 +122,8 @@
 
 $ldap_object = array('objectClass' => "inetOrgPerson");
 
-if (!$errors && (!($link = ldap_connect($ldap_server,$ldap_port)) || 
-    !ldap_bind($link, $bind_dn, $_SERVER["PHP_AUTH_PW"])))
-   array_push($errors, "Communication Error: could bind to ldap://$ldap_server:$ldap_port ".ldap_error($link));
+print "Bound with dn ".$ldap->bind_dn;
+
 if (!$errors) {
    // ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, 3);
    /*if (($result = ldap_read($link, "k=kolab,".$_SESSION['base_dn'], "(objectclass=*)")) &&
@@ -193,9 +148,9 @@
       if (!$errors) {    
          print("<div class=\"maintitle\"> Delete Address Book Entry </div>\n");
          if (!(ldap_delete($link,$dn))) {
-            array_push($errors, "LDAP Error: could not delete ".utf8_decode($dn)." ".ldap_error($link));
+            array_push($errors, "LDAP Error: could not delete ".$dn." ".ldap_error($link));
          } else {
-            print("<div class=\"message\"> The object ".utf8_decode($dn)." has been deleted </div>\n");
+            print("<div class=\"message\"> The object ".$dn." has been deleted </div>\n");
          }
       } 
 
@@ -235,8 +190,6 @@
 
 //print("ldap_object: "); print_r($ldap_object); print("<br>");
 
-            $ldap_object = to_utf8($ldap_object);
-
             if ($action == "save") {
                if (!$errors) {
                   if (!empty($ldap_object['cn'])) $newdn = "cn=".$ldap_object['cn'].",".$addressbook_root;
@@ -246,26 +199,25 @@
                          ($entry=ldap_first_entry($link,$result)) &&
                          ($oldattrs=ldap_get_attributes($link,$entry))) {
                         if (!ldap_add($link,$newdn, $ldap_object) || !ldap_delete($link,$dn))
-                           array_push($errors, "LDAP Error: could not rename ".utf8_decode($dn).
-			               " to ".utf8_decode($newdn)." ".ldap_error($link));
+                           array_push($errors, "LDAP Error: could not rename ".$dn.
+			               " to ".$newdn." ".ldap_error($link));
                         $dn = $newdn;
-                     } else array_push($errors,"LDAP Error: could not read ".utf8_decode($dn)." ".ldap_error($link));
+                     } else array_push($errors,"LDAP Error: could not read ".$dn." ".ldap_error($link));
                   } else {
                      $ldap_object = fill_up($ldap_object);
                      if (!ldap_modify($link, $dn, $ldap_object))
-                     array_push($errors, "LDAP Error: could not modify object ".utf8_decode($dn)." ".ldap_error($link)); 
+                     array_push($errors, "LDAP Error: could not modify object ".$dn." ".ldap_error($link)); 
                   }
                } 
             } else {
                if (!$errors) {
                   $dn = "cn=".$ldap_object['cn'].",".$addressbook_root;
                   if ($dn && !ldap_add($link, $dn, $ldap_object)) 
-                     array_push($errors, "LDAP Error: could not add object ".utf8_decode($dn)." ".ldap_error($link));
+                     array_push($errors, "LDAP Error: could not add object ".$dn." ".ldap_error($link));
                }
                if ($errors) {
                   print("<div class=\"maintitle\"> Create New Address Book Entry </div>\n");
 		  $action = "create";
-		  $ldap_object = from_utf8($ldap_object);
                   break;
                }
             }
@@ -290,10 +242,9 @@
          if (($result = ldap_read($link, $dn, "(objectclass=*)")) &&
              ($entry = ldap_first_entry($link,$result)) &&
              ($ldap_object = ldap_get_attributes($link,$entry))) {
-            $ldap_object = from_utf8($ldap_object);
             $ldap_object = fill_up2($ldap_object);
             ldap_free_result($result);
-         } else array_push($errors, "LDAP Error: could not read ".utf8_decode($dn)." ".ldap_error($link));
+         } else array_push($errors, "LDAP Error: could not read ".$dn." ".ldap_error($link));
       }
    }
    ldap_close($link);

Index: head.php
===================================================================
RCS file: /kolabrepository/server/kolab/kolab/admin/addressbook/head.php,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- head.php	14 Jun 2003 17:06:31 -0000	1.6
+++ head.php	16 Apr 2004 10:17:28 -0000	1.7
@@ -5,11 +5,11 @@
  This program is Free Software under the GNU General Public License (>=v2).
  Read the file COPYING that comes with this packages for details.
 */
-    include("../include/myfunctions.php");
-    include("../include/headfoot.php");
+include('../include/myfunctions.php');
+include('../include/headfoot.php');
    
-    $uid=$_SERVER['PHP_AUTH_USER'];
-    $group_id = uid2group($uid);
+$uid=$auth->uid();
+$group_id = $auth->group();
 /*  echo "uid=$uid<br>";
     echo "head: group_id=$group_id<hr>";
 */    

Index: index.php
===================================================================
RCS file: /kolabrepository/server/kolab/kolab/admin/addressbook/index.php,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- index.php	14 Jun 2003 17:06:31 -0000	1.7
+++ index.php	16 Apr 2004 10:17:28 -0000	1.8
@@ -5,21 +5,19 @@
  This program is Free Software under the GNU General Public License (>=v2).
  Read the file COPYING that comes with this packages for details.
 */
-    include("head.php");
+require_once('../include/authenticate.php');
+include("head.php");
 
     This("addressbook/");
     Head();
 
-
-$utf8 = array ( 'cn', 'sn' );
-
 $errors = array();
 
-// check user authentication 
-if (!($uid = $_SERVER["PHP_AUTH_USER"]) ||
-    !($bind_dn = uid2dn($uid)) ||
-    !($group = uid2group($uid))) 
-   array_push($errors, "Internal Error: could not get Authentication Information");
+// user authentication 
+$uid = $auth->uid();
+$bind_dn = $auth->dn();
+$group = $auth->group();
+$link = $ldap->connection;
 
 if (!$errors && $group != "admin" && $group != "maintainer") 
    array_push($errors, "Error: You don't have Permissions to access this Menue");
@@ -36,99 +34,90 @@
    
 $myself = $_SERVER['PHP_SELF'];
 
-if (isset($_SESSION['ldap_server'])) $ldap_server = $_SESSION['ldap_server'];
-   else $ldap_server = '127.0.0.1';
-
-if (isset($_SESSION['ldap_port'])) $ldap_port = $_SESSION['ldap_port'];
-   else $ldap_port = 389;
-
-if (!$errors && !($link = ldap_connect($ldap_server,$ldap_port)) || !ldap_bind($link)) 
-   array_push($errors, "Communication Error: could not query ldap://$ldap_server:$ldap_port ".ldap_error($link));   
-
 
 // get all entries & dynamically split the letters with growing entries
-	$filter = "(&(cn=*)(objectclass=inetOrgPerson)(!(uid=*))(sn=*))";
-	$result = ldap_search($link, $base_dn, $filter);
-	if (!$errors) {
-		$entries = ldap_count_entries($link, $result);
-		printf("<div class=\"maintitle\">Manage Address Book (%s Addresses)</div>", $entries);
-		printf("<div class=\"mainsubtitle\">(only external addresses without a kolab user account)</div>");
-		// if there are more than 2000 entries, split in 26 categories for every letter
-		if ($entries > 2000) { 
-		    print("<div class=\"alphabetlisting\"><form method=\"POST\" action=\"$myself\">\n\n");
-			for ($i = 65; $i < 91; $i++) {
-			    printf("<a href=\"$myself?alphaselect=[%s]\"> [%s] </a>", chr($i), chr($i));
-			}
-		    $text="[all]";
-		    print("<a href=\"$myself?alphaselect=$text\">  $text  </a>\n");
-			print("</form></div>\n");
-
-			for ($i = 65; $i < 91; $i++) {
-				switch ($alphaselect) {
-					case "[".chr($i)."]":
-						$filter = "(&(cn=*)(objectclass=inetOrgPerson)(uid=*)(mail=*)(|(sn=".chr($i)."*)(sn=".chr($i+32)."*)";
-						if ($i == 65) {
-							if (in_array('sn', $utf8)) $filter = $filter."(sn=".utf8_encode("Ä")."*)(sn=".utf8_encode("ä")."*)"; }
-						if ($i == 79) {
-							if (in_array('sn', $utf8)) $filter = $filter."(sn=".utf8_encode("Ö")."*)(sn=".utf8_encode("ö")."*)"; }
-						if ($i == 85) {
-							if (in_array('sn', $utf8)) $filter = $filter."(sn=".utf8_encode("Ü")."*)(sn=".utf8_encode("ü")."*)"; }
-						$filter = $filter."))";
-					break;
-				}
-			}
-	        ldap_free_result($result);
-			$result = ldap_search($link, $base_dn, $filter);
-			$entries = ldap_count_entries($link, $result);
-		}
-		// if there are more than 50 entries, split in four categories
-		elseif ($entries >50) { 
-		    print("<div class=\"alphabetlisting\"><form method=\"POST\" action=\"$myself\">\n\n");
-		    $text = "[A-F]";
-		    print("<a href=\"$myself?alphaselect=$text\"> $text </a>");
-		    $text = "[G-L]";
-		    print("<a href=\"$myself?alphaselect=$text\"> $text </a>");
-		    $text="[M-S]";
-		    print("<a href=\"$myself?alphaselect=$text\"> $text </a>");
-		    $text="[T-Z]";
-		    print("<a href=\"$myself?alphaselect=$text\"> $text </a>");
-		    $text="[all]";
-		    print("<a href=\"$myself?alphaselect=$text\">  $text  </a>\n");
-			print("</form></div>\n");
-			switch ($alphaselect) {
-				case "[A-F]":
-					$filter = "(&(cn=*)(objectclass=inetOrgPerson)(!(uid=*))(|(sn=F*)(sn=E*)(sn=D*)(sn=C*)(sn=B*)(sn=A*)"; 
-					$filter = $filter."(sn=f*)(sn=e*)(sn=d*)(sn=c*)(sn=b*)(sn=a*)";
-					if (in_array('sn', $utf8)) $filter = $filter."(sn=".utf8_encode("Ä")."*)(sn=".utf8_encode("ä")."*)";
-					$filter = $filter."))";
-				break;
-				case "[G-L]":
-					$filter = "(&(cn=*)(objectclass=inetOrgPerson)(!(uid=*))(|(sn=G*)(sn=H*)(sn=I*)(sn=J*)(sn=K*)(sn=L*)";
-					$filter = $filter."(sn=g*)(sn=h*)(sn=i*)(sn=j*)(sn=k*)(sn=l*)))";
-				break;
-				case "[M-S]":
-					$filter = "(&(cn=*)(objectclass=inetOrgPerson)(!(uid=*))(|(sn=M*)(sn=N*)(sn=O*)(sn=P*)(sn=Q*)(sn=R*)(sn=S*)";
-					$filter = $filter."(sn=m*)(sn=n*)(sn=o*)(sn=p*)(sn=q*)(sn=r*)(sn=s*)";
-					if (in_array('sn', $utf8)) $filter = $filter."(sn=".utf8_encode("Ö")."*)(sn=".utf8_encode("ö")."*)".
-																 "(sn=".utf8_encode("Ü")."*)(sn=".utf8_encode("ü")."*)";
-					$filter = $filter."))";
-				break;
-				case "[T-Z]":
-					$filter = "(&(cn=*)(objectclass=inetOrgPerson)(!(uid=*))(|(sn=T*)(sn=U*)(sn=V*)(sn=W*)(sn=X*)(sn=Y*)(sn=Z*)";
-					$filter = $filter."(sn=t*)(sn=u*)(sn=v*)(sn=w*)(sn=x*)(sn=y*)(sn=z*)))";
-				break;
-				default: 
-					$filter = "(&(cn=*)(objectclass=inetOrgPerson)(!(uid=*))(sn=*))";
-				break;
-			}
-	        ldap_free_result($result);	
-			$result = ldap_search($link, $base_dn, $filter);
-			$entries = ldap_count_entries($link, $result);
-
-		}
-		// if there are less than 50 entries, all entries are shown - w/o options
-		else { echo "<div class=\"alphabetlisting\"></div>\n"; $alphaselect = "[all]"; }
-	}
+$filter = "(&(cn=*)(objectclass=inetOrgPerson)(!(uid=*))(sn=*))";
+$result = ldap_search($link, $base_dn, $filter);
+if (!$errors) {
+  $entries = ldap_count_entries($link, $result);
+  printf("<div class=\"maintitle\">Manage Address Book (%s Addresses)</div>", $entries);
+  printf("<div class=\"mainsubtitle\">(only external addresses without a kolab user account)</div>");
+  // if there are more than 2000 entries, split in 26 categories for every letter
+  if ($entries > 2000) { 
+    print("<div class=\"alphabetlisting\"><form method=\"POST\" action=\"$myself\">\n\n");
+    for ($i = 65; $i < 91; $i++) {
+      printf("<a href=\"$myself?alphaselect=[%s]\"> [%s] </a>", chr($i), chr($i));
+    }
+    $text="[all]";
+    print("<a href=\"$myself?alphaselect=$text\">  $text  </a>\n");
+    print("</form></div>\n");
+    
+    for ($i = 65; $i < 91; $i++) {
+      switch ($alphaselect) {
+      case "[".chr($i)."]":
+	$filter = "(&(cn=*)(objectclass=inetOrgPerson)(uid=*)(mail=*)(|(sn=".chr($i)."*)(sn=".chr($i+32)."*)";
+	if ($i == 65) {
+	  $filter = $filter."(sn=".utf8_encode("Ä")."*)(sn=".utf8_encode("ä")."*)"; }
+	if ($i == 79) {
+	  $filter = $filter."(sn=".utf8_encode("Ö")."*)(sn=".utf8_encode("ö")."*)"; }
+	if ($i == 85) {
+	  $filter = $filter."(sn=".utf8_encode("Ü")."*)(sn=".utf8_encode("ü")."*)"; }
+	$filter = $filter."))";
+	break;
+      }
+    }
+    ldap_free_result($result);
+    $result = ldap_search($link, $base_dn, $filter);
+    $entries = ldap_count_entries($link, $result);
+  }
+  // if there are more than 50 entries, split in four categories
+  elseif ($entries >50) { 
+    print("<div class=\"alphabetlisting\"><form method=\"POST\" action=\"$myself\">\n\n");
+    $text = "[A-F]";
+    print("<a href=\"$myself?alphaselect=$text\"> $text </a>");
+    $text = "[G-L]";
+    print("<a href=\"$myself?alphaselect=$text\"> $text </a>");
+    $text="[M-S]";
+    print("<a href=\"$myself?alphaselect=$text\"> $text </a>");
+    $text="[T-Z]";
+    print("<a href=\"$myself?alphaselect=$text\"> $text </a>");
+    $text="[all]";
+    print("<a href=\"$myself?alphaselect=$text\">  $text  </a>\n");
+    print("</form></div>\n");
+    switch ($alphaselect) {
+    case "[A-F]":
+      $filter = "(&(cn=*)(objectclass=inetOrgPerson)(!(uid=*))(|(sn=F*)(sn=E*)(sn=D*)(sn=C*)(sn=B*)(sn=A*)"; 
+      $filter = $filter."(sn=f*)(sn=e*)(sn=d*)(sn=c*)(sn=b*)(sn=a*)";
+      $filter = $filter."(sn=".utf8_encode("Ä")."*)(sn=".utf8_encode("ä")."*)";
+      $filter = $filter."))";
+      break;
+    case "[G-L]":
+      $filter = "(&(cn=*)(objectclass=inetOrgPerson)(!(uid=*))(|(sn=G*)(sn=H*)(sn=I*)(sn=J*)(sn=K*)(sn=L*)";
+      $filter = $filter."(sn=g*)(sn=h*)(sn=i*)(sn=j*)(sn=k*)(sn=l*)))";
+      break;
+    case "[M-S]":
+      $filter = "(&(cn=*)(objectclass=inetOrgPerson)(!(uid=*))(|(sn=M*)(sn=N*)(sn=O*)(sn=P*)(sn=Q*)(sn=R*)(sn=S*)";
+      $filter = $filter."(sn=m*)(sn=n*)(sn=o*)(sn=p*)(sn=q*)(sn=r*)(sn=s*)";
+      $filter = $filter."(sn=".utf8_encode("Ö")."*)(sn=".utf8_encode("ö")."*)".
+	"(sn=".utf8_encode("Ü")."*)(sn=".utf8_encode("ü")."*)";
+      $filter = $filter."))";
+      break;
+    case "[T-Z]":
+      $filter = "(&(cn=*)(objectclass=inetOrgPerson)(!(uid=*))(|(sn=T*)(sn=U*)(sn=V*)(sn=W*)(sn=X*)(sn=Y*)(sn=Z*)";
+      $filter = $filter."(sn=t*)(sn=u*)(sn=v*)(sn=w*)(sn=x*)(sn=y*)(sn=z*)))";
+      break;
+    default: 
+      $filter = "(&(cn=*)(objectclass=inetOrgPerson)(!(uid=*))(sn=*))";
+      break;
+    }
+    ldap_free_result($result);	
+    $result = ldap_search($link, $base_dn, $filter);
+    $entries = ldap_count_entries($link, $result);
+    
+  }
+  // if there are less than 50 entries, all entries are shown - w/o options
+  else { echo "<div class=\"alphabetlisting\"></div>\n"; $alphaselect = "[all]"; }
+}
 
 if (!$errors) {
 
@@ -170,9 +159,7 @@
          $dn = ldap_get_dn($link,$entry);
          $attrs = ldap_get_attributes($link, $entry);
          $sn = $attrs['sn'][0];
-         if (in_array('sn', $utf8)) $sn = utf8_decode($sn);
          $cn = $attrs['cn'][0];
-         if (in_array('cn', $utf8)) $cn = utf8_decode($cn);
          $a = strlen($sn);
          $b = strlen($cn); 
          $fn = substr($cn, 0, $b - $a);





More information about the commits mailing list