]> git.sur5r.net Git - openldap/blob - contrib/php3-tool/include/ldap_manager.inc
fixed test on "" (empty) parent dn
[openldap] / contrib / php3-tool / include / ldap_manager.inc
1 <?
2 include 'include/ldap_entry.inc';
3 class ldap_manager {
4         var $entries;
5         var $result_identifier, $search_filter, $base_dn;
6         var $ldap_action, $host;
7         var $link_identifier;
8         var $entriesCount;
9
10         function connect($host) {
11                 $this->link_identifier = ldap_connect($host);
12                 if ($this->link_identifier) return 1;
13                 return 0;
14         }
15
16         function disconnect() {
17                 ldap_close($this->link_identifier);
18         }
19
20         function ldapTakeAction($a = "search") {
21                 $func_ptr = "ldap_".$a;
22                 if ($this->result_identifier = $func_ptr($this->link_identifier, $this->base_dn, $this->search_filter)) {
23                         $this->entriesCount = ldap_count_entries($this->link_identifier, $this->result_identifier);
24                         return 1;
25                 }
26                 return 0;
27         }
28         
29         cfunction getEntries() {
30                 $i=0;
31                 $entry = new ldap_entry($this->link_identifier);
32                 $entry->r_e_i = ldap_first_entry($this->link_identifier, $this->result_identifier);
33                 while($entry->r_e_i) {
34                         $entry->dn = ldap_get_dn($this->link_identifier, $entry->r_e_i);
35                         $entry->getAttributes();
36                         $this->entries[$i] = $entry;
37                         $i++;
38                         $r = $entry->r_e_i;
39                         $entry = new ldap_entry($this->link_identifier);
40                         $entry->r_e_i = ldap_next_entry($this->link_identifier, $r);
41                 }
42 //              ldap_free_result($this->result_identifier);
43         }
44
45         cfunction displayEntries() {
46                 echo $this->formatHTMLEntries();
47         }
48
49         cfunction formatHTMLBaseDN($dn) {
50                 global $FILE, $host;
51                 $string = "";
52                 $attribs = ldap_explode_dn($dn, 0);
53                 $names = ldap_explode_dn($dn, 1);
54                 for ($i=0; $i<$attribs["count"]; $i++) {
55                         $s = $attribs[$i];
56                         for ($j=$i+1; $j<$attribs["count"]; $j++) {
57                                 $s .= ",".$attribs[$j];
58                         }
59                         if (($s[0] == "c") && ($s[1] == "n")) {
60                                 $string .= "<a href=".$FILE."?ldap_action=read&base_dn=".urlencode($s).">".$names[$i]."</a>, ";
61                         }
62                         else {
63                                 $string .= "<a href=".$FILE."?ldap_action=list&base_dn=".urlencode($s).">".$names[$i]."</a>, ";
64                         }
65                 }
66                 return $string;
67         }
68
69         cfunction formatHTMLEntries() {
70                 $string = "";
71                 $string .= '<table width="100%" border=1 cellpadding=0 cellspacing=0>';
72                 $string .= "\n";
73                 for ($i=0; $i<count($this->entries); $i++) {
74                         $e = $this->entries[$i];
75                         $string .= $e->formatHTMLAttributes();
76                 }       
77                 $string .= "</table>\n";
78                 return $string;
79         }
80
81         cfunction calculateTime($string, $s_t, $e_t) {
82                 $tok1 = strtok($s_t, " ");
83                 $msecs1 = $tok1;
84                 $tok1 = strtok(" ");
85                 $secs1 = $tok1;
86          
87                 $tok2 = strtok($e_t, " ");
88                 $msecs2 = $tok2;
89                 $tok2 = strtok(" ");
90                 $secs2 = $tok2;
91                 $t_t = (float) ($secs2 + $msecs2) - (float) ($secs1 + $msecs1);
92                 echo "execution time for <b>".$string."</b> : <b>".$t_t."</b> seconds<br>\n";
93         //      echo "start: ".$secs1."<br>\n";
94         //      echo "end: ".$secs2."<br>\n";
95                 return (float) $t_t;
96         }
97         
98         cfunction stripString($string, $tokens) {
99                 $s = $string;
100                 for ($i=0; $i<count($tokens); $i++) {
101                         $result = "";
102                         $tok = strtok($s, $tokens[$i]);
103                         while($tok) {
104                                 $result .= $tok;
105                         //      echo "result = ".$result."\n";
106                                 $tok = strtok($tokens[$i]);
107                         }
108                         $s = $result;
109                 //      echo "s = ".$s."\n";
110                 }
111         //      echo "result = ".$result."\n";
112                 return $result;
113         }
114 }
115 ?>