steffen: server/kolab/kolab/admin/administrator create_administrator.php, 1.8, 1.9 index.php, 1.9, 1.10

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/administrator
In directory doto:/tmp/cvs-serv22487/admin/administrator

Modified Files:
	create_administrator.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_administrator.php
===================================================================
RCS file: /kolabrepository/server/kolab/kolab/admin/administrator/create_administrator.php,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- create_administrator.php	28 Nov 2003 02:01:04 -0000	1.8
+++ create_administrator.php	16 Apr 2004 10:17:28 -0000	1.9
@@ -5,19 +5,17 @@
  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");
-
-    This("administrator/create_administrator.php?action=create");
-    Head();
+require_once('../include/authenticate.php');
+include("head.php");
 
-    include("../include/checks.php");
-?>
+This("administrator/create_administrator.php?action=create");
+Head();
 
+include("../include/checks.php");
 
-<?
 function debug ($a) 
 {
-//   print "debug: $a<br>\n";
+   print "debug: $a<br>\n";
 }
 
 
@@ -26,12 +24,12 @@
 $errors = array();
 $valid_actions = array('save','firstsave','modify','create','delete','kill');
 
-if (!empty($HTTP_GET_VARS['action']) && 
-    in_array($HTTP_GET_VARS['action'],$valid_actions)) $action = trim(urldecode($HTTP_GET_VARS['action']));
+if (!empty($_REQUEST['action']) && 
+    in_array($_REQUEST['action'],$valid_actions)) $action = trim(urldecode($_REQUEST['action']));
    else array_push($errors, "Error: need valid action to proceed");
 
 $dn="";
-if (!empty($HTTP_GET_VARS['dn'])) $dn = trim(urldecode($HTTP_GET_VARS['dn']));
+if (!empty($_REQUEST['dn'])) $dn = trim(urldecode($_REQUEST['dn']));
 
 if (strcmp($dn,"cn=manager,".$_SESSION['base_dn']) == 0) {
    print("<span class=\"warning\">"); 
@@ -41,10 +39,10 @@
    exit;
 }
 
-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 != "admin")  
    array_push($errors, "Error: You don't have the required Permissions"); 
@@ -53,49 +51,8 @@
 
 $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 ( 'cn', 'sn', 'uid', 'userPassword');
 
-$utf8 = array ( 'sn', 'cn' );
-
-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;
-}
 
 $beautify = array (
       'sn' => 'Surname', 'uid' => 'Unique UserID', 'userPassword' => 'Password', 
@@ -158,9 +115,6 @@
 $password_0 = "";
 $password_1 = "";
 
-if (!$errors && (!($link = ldap_connect($ldap_server,$ldap_port)) || 
-    !ldap_bind($link, $bind_dn, $_SERVER["PHP_AUTH_PW"])))
-   array_push($errors, "Communication Error: could not query ldap://$ldap_server:$ldap_port ".ldap_error($link));
 if (!$errors) {
 
    $oldmemberline = array();
@@ -183,9 +137,9 @@
       if (!$errors) {    
          print("<div class=\"maintitle\"> Delete Administrator </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)." is deleted </div>\n");
+           print("<div class=\"message\"> The object ".$dn." is deleted </div>\n");
            if (!ldap_mod_del($link, "cn=admin,".$_SESSION['base_dn'], $oldmemberline))
               array_push($errors, "LDAP Error: could not update admin group ".ldap_error($link));
          }
@@ -196,8 +150,8 @@
 
          case "firstsave":
 
-            if (!empty($HTTP_GET_VARS['uid'])) {
-               $ldap_object['uid'] = trim(urldecode($HTTP_GET_VARS['uid']));
+            if (!empty($_REQUEST['uid'])) {
+               $ldap_object['uid'] = trim(urldecode($_REQUEST['uid']));
             } else {
                $comment['uid'] = "<span class=\"warning\"> Fill in uid </span>";
                missing_input();
@@ -206,12 +160,12 @@
          case "save":
 
             if ($action == "save" && !$dn) array_push($errors, "Internal Error: need dn to save");
-            if (!empty($HTTP_GET_VARS['password_0'])) $password_0 = urldecode($HTTP_GET_VARS['password_0']);
+            if (!empty($_REQUEST['password_0'])) $password_0 = urldecode($_REQUEST['password_0']);
             else {
                $comment['password_0'] = "<span class=\"warning\"> Fill in password </span>";
                missing_input();
             }
-            if (!empty($HTTP_GET_VARS['password_1'])) $password_1 = urldecode($HTTP_GET_VARS['password_1']);
+            if (!empty($_REQUEST['password_1'])) $password_1 = urldecode($_REQUEST['password_1']);
             else {
                $comment['password_1'] = "<span class=\"warning\"> Fill in password </span>";
                missing_input();
@@ -224,21 +178,20 @@
                   missing_input();
                }
             }
-            if (!empty($HTTP_GET_VARS['firstname']))
-               $firstname = trim(urldecode($HTTP_GET_VARS['firstname']));
+            if (!empty($_REQUEST['firstname']))
+               $firstname = trim(urldecode($_REQUEST['firstname']));
             else {
                $comment['firstname'] = "<span class=\"warning\"> Fill in firstname </span>";
                missing_input();
             }
-            if (!empty($HTTP_GET_VARS['sn'])) {
-               $ldap_object['sn'] = trim(urldecode($HTTP_GET_VARS['sn']));
+            if (!empty($_REQUEST['sn'])) {
+               $ldap_object['sn'] = trim(urldecode($_REQUEST['sn']));
                if (isset($firstname)) $ldap_object['cn'] = $firstname." ".$ldap_object['sn'];
             } else {
                $comment['sn'] = "<span class=\"warning\"> Fill in lastname </span>";
                missing_input();
             }
 
-            $ldap_object = to_utf8($ldap_object);
             if (!empty($ldap_object['uid']) && !is_unique('uid', $ldap_object['uid'])) {
                $comment['uid'] = "<span class=\"warning\"> Error: This uid is already taken by another user </span>";
                missing_input();
@@ -274,7 +227,6 @@
                if ($errors) {
                   $action = "create";
                   print("<div class=\"maintitle\"> Create New Administrator </div>\n");
-		  $ldap_object = from_utf8($ldap_object);
                   break;
                }
             }
@@ -304,7 +256,6 @@
              ($entry = ldap_first_entry($link,$result)) &&
              ($ldap_object = ldap_get_attributes($link,$entry))) {
             //$myentry = array_merge_recursive($myentry, $attrs);
-            $ldap_object = from_utf8($ldap_object);
             $ldap_object = fill_up($ldap_object);
             ldap_free_result($result);
          }

Index: index.php
===================================================================
RCS file: /kolabrepository/server/kolab/kolab/admin/administrator/index.php,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- index.php	30 Jun 2003 15:08:48 -0000	1.9
+++ index.php	16 Apr 2004 10:17:28 -0000	1.10
@@ -6,27 +6,26 @@
  Read the file COPYING that comes with this packages for details.
 
 */
-    include("head.php");
-    This("administrator/");
-    Head();
-
-$utf8 = array ( 'cn', 'sn' );
+require_once('../include/authenticate.php');
+include("head.php");
+This("administrator/");
+Head();
 
 $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") 
    array_push($errors, "Error: You don't have Permissions to access this Menue");
 
 // read selector for register display
-if (isset($HTTP_GET_VARS['alphaselect'])) $alphaselect = $HTTP_GET_VARS['alphaselect'];
+if (isset($_GET['alphaselect'])) $alphaselect = $_GET['alphaselect'];
    else $alphaselect = "[all]";
-if (isset($HTTP_GET_VARS['page'])) $page = $HTTP_GET_VARS['page'];
+if (isset($_GET['page'])) $page = $_GET['page'];
    else $page = "1";
    
 
@@ -35,225 +34,215 @@
 
 $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);
-	
-	// counting all entries
-	if ($result) {
-	ldap_sort($link,$result,'sn');
-	$entry = ldap_first_entry($link, $result);
-	$entries = 0;
-		while ($entry) {   
-			$dn = ldap_get_dn($link,$entry);
-			$attrs = ldap_get_attributes($link, $entry);
-			$userid = $attrs['uid'][0];
-         	$gid = uid2group($userid);
-			if ($gid == "admin") {
-				$entries++;
-			}
-			$entry = ldap_next_entry($link, $entry);
-		} 
-		ldap_free_result($result);
-	} else array_push($errors, "Communication Error: ldap server did not answer query for user information");
-
-if (!$errors) {
-	printf("<div class=\"maintitle\">Manage Administrators (%s Administrators)</div>", $entries);
-	// 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");
+$filter = "(&(cn=*)(objectclass=inetOrgPerson)(uid=*)(sn=*))";
+$result = $ldap->search($base_dn, $filter);
 
-		for ($i = 65; $i < 91; $i++) {
-			switch ($alphaselect) {
-				case "[".chr($i)."]":
-					$filter = "(&(cn=*)(objectclass=inetOrgPerson)(uid=*)(|(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;
-			}
-		}
-	}
-	// 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;
-			}
-		
-	}
-	// 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=*))"; }
+// counting all entries
+if ($result) {
+  ldap_sort($link,$result,'sn');
+  $entry = ldap_first_entry($link, $result);
+  $entries = 0;
+  while ($entry) {   
+    $dn = ldap_get_dn($link,$entry);
+    $attrs = ldap_get_attributes($link, $entry);
+    $userid = $attrs['uid'][0];
+    $gid = $ldap->groupForUid($userid);
+    if ($gid == "admin") {
+      $entries++;
+    }
+    $entry = ldap_next_entry($link, $entry);
+  } 
+  //ldap_free_result($result);
+} else array_push($errors, "Communication Error: ldap server did not answer query for user information");
 
+if (!$errors) {
+  printf("<div class=\"maintitle\">Manage Administrators (%s Administrators)</div>", $entries);
+  // 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=*)(|(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;
+      }
+    }
+  }
+  // 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;
+    }
+    
+  }
+  // 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=*))"; }
+  
 }
 
 
 if (!$errors) {
-	$result = ldap_search($link, $base_dn, $filter);
-	$entries = 0;
-	ldap_sort($link,$result,'sn');
-	$entry = ldap_first_entry($link, $result);
-	while ($entry) {   
-		$dn = ldap_get_dn($link,$entry);
-		$attrs = ldap_get_attributes($link, $entry);
-		$userid = $attrs['uid'][0];
-		$gid = uid2group($userid);
-        if ($gid == "admin")
-			$entries = $entries+1;
-       	$entry = ldap_next_entry($link, $entry);
+  $result = ldap_search($link, $base_dn, $filter);
+  $entries = 0;
+  ldap_sort($link,$result,'sn');
+  $entry = ldap_first_entry($link, $result);
+  while ($entry) {   
+    $dn = ldap_get_dn($link,$entry);
+    $attrs = ldap_get_attributes($link, $entry);
+    $userid = $attrs['uid'][0];
+    $gid = $ldap->groupForUid($userid);
+    if ($gid == "admin")
+      $entries = $entries+1;
+    $entry = ldap_next_entry($link, $entry);
+  }
+  ldap_free_result($result);
+  $result = ldap_search($link, $base_dn, $filter);
+  // splitting into more than one page?
+  print("<div class=\"pagelisting\">");
+  $pages = ceil($entries / $views);
+  if ($pages > 1) {
+    for ($i = 1; $i < $pages; $i++) {
+      // the actual page won't be clickable
+      if ($page != $i)
+	printf(" <a href=\"index.php?alphaselect=%s&page=%s\">%s</a> |\n", $alphaselect, $i, $i);
+      else 
+	printf(" %s |\n", $i);
     }
-	ldap_free_result($result);
-	$result = ldap_search($link, $base_dn, $filter);
-// splitting into more than one page?
-print("<div class=\"pagelisting\">");
-$pages = ceil($entries / $views);
-if ($pages > 1) {
-	for ($i = 1; $i < $pages; $i++) {
-		// the actual page won't be clickable
-		if ($page != $i)
-			printf(" <a href=\"index.php?alphaselect=%s&page=%s\">%s</a> |\n", $alphaselect, $i, $i);
-		else 
-			printf(" %s |\n", $i);
+    // last item w/o vertical dash
+    if ($page != $i)
+      printf(" <a href=\"index.php?alphaselect=%s&page=%s\">%s</a> \n", $alphaselect, $i, $i);
+    else 
+      printf(" %s ", $i);
+  }
+  print("</div>");
+  if ($result) {
+    print("<div class=\"contenttable\">");
+    print("<TABLE class=\"content\" nosave>\n");
+    ldap_sort($link,$result,'sn');
+    $entry = ldap_first_entry($link, $result);
+    $first=0;
+    $skip = 0;
+    while ($entry) {   
+      $dn = ldap_get_dn($link,$entry);
+      $attrs = ldap_get_attributes($link, $entry);
+      $userid = $attrs['uid'][0];
+      $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);
+      $gid = $ldap->groupForUid($userid);
+      if ($gid == "admin") {
+	// skipping to correct page and start with first entry
+	if ($page != '1') {
+	  for ($i = 1; $i <= ($page-1)*$views; $i++)
+	    $entry = ldap_next_entry($link, $entry);
 	}
-	// last item w/o vertical dash
-	if ($page != $i)
-		printf(" <a href=\"index.php?alphaselect=%s&page=%s\">%s</a> \n", $alphaselect, $i, $i);
-	else 
-		printf(" %s ", $i);
-}
-print("</div>");
-if ($result) {
-   print("<div class=\"contenttable\">");
-   print("<TABLE class=\"content\" nosave>\n");
-   ldap_sort($link,$result,'sn');
-	$entry = ldap_first_entry($link, $result);
-      $first=0;
-	  $skip = 0;
-      while ($entry) {   
-         $dn = ldap_get_dn($link,$entry);
-         $attrs = ldap_get_attributes($link, $entry);
-         $userid = $attrs['uid'][0];
-         $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);
-         $gid = uid2group($userid);
-         if ($gid == "admin") {
-		// skipping to correct page and start with first entry
-		if ($page != '1') {
-			for ($i = 1; $i <= ($page-1)*$views; $i++)
-				$entry = ldap_next_entry($link, $entry);
-		}
-		// counts the entries, which are already listed on this page and breaks on overflow
-		if ($countentries < $views) {
-			if ($dn != "cn=manager,".$_SESSION['base_dn']) {
-				$userid = urlencode($userid);
-				$dn = urlencode($dn);
-				if ($first == 0) printf("<thead><td class=\"content\"> Name </td><td class=\"content\"> UID </td><td class=\"content\"> Action </td></thead>\n");
-				$first++;
-				printf("<tr><td class=\"content\"> %s, %s </td><td class=\"content\"> %s </td><td class=\"contentaction\">
+	// counts the entries, which are already listed on this page and breaks on overflow
+	if ($countentries < $views) {
+	  if ($dn != "cn=manager,".$_SESSION['base_dn']) {
+	    $userid = urlencode($userid);
+	    $dn = urlencode($dn);
+	    if ($first == 0) printf("<thead><td class=\"content\"> Name </td><td class=\"content\"> UID </td><td class=\"content\"> Action </td></thead>\n");
+	    $first++;
+	    printf("<tr><td class=\"content\"> %s, %s </td><td class=\"content\"> %s </td><td class=\"contentaction\">
 	            	        <a href=\"create_administrator.php?action=modify&dn=%s\"> [Modify]</a>
     	    	            <a href=\"create_administrator.php?action=delete&dn=%s\"> [Delete]</a>
 							</td></tr>\n", $sn, $fn, $userid, $dn,$dn);
-					} else printf("<tr><td class=\"content\"> %s </td><td class=\"content\"> %s </td><td class=\"content\">   </td></tr>\n", $sn, $userid);
-				}
-				$countentries++;
-			}
-        	$skip++;
-		$entry = ldap_next_entry($link, $entry);
-      } 
-      ldap_free_result($result);
-  if ($first == 0) print("<tr><td class=\"nocontent\"> (No administrators in the category $alphaselect) </td></tr>\n"); 
-  ldap_close($link);
-} else array_push($errors, "Communication Error: ldap server did not answer query for user information");
-
+	  } else printf("<tr><td class=\"content\"> %s </td><td class=\"content\"> %s </td><td class=\"content\">   </td></tr>\n", $sn, $userid);
+	}
+	$countentries++;
+      }
+      $skip++;
+      $entry = ldap_next_entry($link, $entry);
+    } 
+    ldap_free_result($result);
+    if ($first == 0) print("<tr><td class=\"nocontent\"> (No administrators in the category $alphaselect) </td></tr>\n"); 
+    ldap_close($link);
+  } else array_push($errors, "Communication Error: ldap server did not answer query for user information");
+  
 } // if !$errors
 
 print("</table>\n<div class=\"pagelisting\">");
 // splitting into more than one page?
 $pages = ceil($entries / $views);
 if ($pages > 1) {
-	for ($i = 1; $i < $pages; $i++) {
-		// the actual page won't be clickable
-		if ($page != $i)
-			printf(" <a href=\"index.php?alphaselect=%s&page=%s\">%s</a> |\n", $alphaselect, $i, $i);
-		else 
-			printf(" %s |\n", $i);
-	}
-	// last item w/o vertical dash
-	if ($page != $i)
-		printf(" <a href=\"index.php?alphaselect=%s&page=%s\">%s</a> \n", $alphaselect, $i, $i);
-	else 
-		printf(" %s ", $i);
+  for ($i = 1; $i < $pages; $i++) {
+    // the actual page won't be clickable
+    if ($page != $i)
+      printf(" <a href=\"index.php?alphaselect=%s&page=%s\">%s</a> |\n", $alphaselect, $i, $i);
+    else 
+      printf(" %s |\n", $i);
+  }
+  // last item w/o vertical dash
+  if ($page != $i)
+    printf(" <a href=\"index.php?alphaselect=%s&page=%s\">%s</a> \n", $alphaselect, $i, $i);
+  else 
+    printf(" %s ", $i);
 }
 print("</div></div>\n");
 
 if ($errors) {
-   print("<TABLE style=\"errors\">\n");
-   print("<TR><TD class=\"head\"> There were Errors : </TD></TR>\n");
-   print("<TR><TD class=\"body\">\n");
-   foreach ($errors as $message) print($message); 
-   print("</TD></TR>\n");
-   print("</TABLE>\n");
+  print("<TABLE style=\"errors\">\n");
+  print("<TR><TD class=\"head\"> There were Errors : </TD></TR>\n");
+  print("<TR><TD class=\"body\">\n");
+  foreach ($errors as $message) print($message); 
+  print("</TD></TR>\n");
+  print("</TABLE>\n");
 }
-
 
 Foot(); 
 ?>





More information about the commits mailing list