]> git.sur5r.net Git - openldap/blob - contrib/php3-tool/include/ldap_entry_attribute.inc
Update contrib software.
[openldap] / contrib / php3-tool / include / ldap_entry_attribute.inc
1 <?
2 class ldap_entry_attribute {
3         var $name, $values, $parent;
4         cfunction ldap_entry_attribute($d) {
5         //      echo "creating new ldap_entry_attribtute<br>\n";
6                 $this->dn = $d;
7                 $a = ldap_explode_dn($this->dn, 1);
8                 $this->cn = $a[0];
9         }
10
11         cfunction getAttributeName($string) {
12                 global $prefs;
13                 for ($i=0; $i<count($prefs->attribute_names); $i++) {
14                         if ($prefs->attribute_names[$i][0] == $string) {
15                                 return $prefs->attribute_names[$i][1];
16                         }       
17                 }
18                 return $string;
19         }
20         cfunction isVisible($string) {
21                 global $prefs;
22                 for ($i=0; $i<count($prefs->attribute_names); $i++) {
23                         if ($prefs->attribute_names[$i][0] == $string) {
24                                 return $prefs->attribute_names[$i][2];
25                         }
26                 }
27                 return "FALSE";
28         }
29         
30         cfunction getValues($l_i, $r_e_i) {
31                 //echo "My name is ".$this->name."<br>\n";
32                 $this->values = ldap_get_values($l_i, $r_e_i, $this->name);
33         }
34
35         cfunction display() {
36                 echo "<tr>\n\t<td valign=top bgcolor=white>\n";
37                 echo "\t\t".$this->name."\n\t\t</td>\n\t<td valign=top bgcolor=lightyellow>\n";
38                 echo "<ul type=square>\n";
39                 for($i=0; $i<$this->values["count"]; $i++) {
40                         //echo "Displaying value ".$i."<br>\n";
41                         echo "<li>";
42                         $this->displayValue($i);
43                         echo "<br>\n";
44                 }
45                 echo "</ul>\n";
46                 echo "</td>\n</tr>\n";
47         }
48
49         cfunction formatHTMLValues() {
50                 $ct = $this->values["count"];
51                 $str = "";
52                 $str .= "<tr>\n\t<td valign=top bgcolor=white>\n";
53                 $n = $this->getAttributeName($this->name);
54                 $str .= "\t\t".$n."\n\t\t</td>\n\t<td valign=top bgcolor=lightyellow>\n\t\t<ul type=square>\n";
55         //      if ($ct > 1) {
56         //              $str .= "\t\t<ul type=square>\n";
57         //      }
58                 for ($i=0; $i<$this->values["count"]; $i++) {
59                         $str .= "\t\t\t<li>";
60                         $str .= $this->formatHTMLValue($i);
61                         $str .= "<br>\n";
62                 }
63                 //if ($ct > 1) { $str .= "\t\t\t</ul>\n"; }
64                 $str .= "\t\t\t</ul>\n\t\t</td>\n\t</tr>\n";
65                 return $str;
66         }
67         
68         cfunction formatHTMLValue($index) {
69                 global $prefs, $FILE, $host;
70                 $p = "";
71                 switch ($this->name) {
72                         case "cn":
73                                 $p .= "<a href=".$FILE."?host=".urlencode($host)."&ldap_action=read&base_dn=".urlencode($this->dn).">".$this->values[$index]."</a>";
74                                 break;
75                         case "ou":
76                                 $p .= "<a href=".$FILE."?ldap_action=list&host=".urlencode($host)."&base_dn=".urlencode($this->dn).">".$this->values[$index]."</a>";
77                                 break;
78                         case "seealso":
79                         case "member":
80                         case "requeststo":
81                         case "errorsto":
82                         case "owner":
83                         case "lastmodifiedby":
84                         case "modifiersname":
85                                 $p .= "<a href=".$FILE."?host=".urlencode($host)."&ldap_action=read&base_dn=".urlencode($this->values[$index]).">".ldap_dn2ufn($this->values[$index])."</a>";
86                                 break;
87                         case "mail":
88                                 $p .= "<a href=mailto:".$this->values[$index].">".$this->values[$index]."</a>";
89                                 break;
90                         case "postaladdress":
91                         case "homepostaladdress":
92                                 $i=0;
93                                 $tok = strtok($this->values[$index], "$");
94                                 while ($tok) {
95                                         $p .= $i." ".$tok."<br>\n";
96                                         $tok = strtok("$");
97                                         $i++;
98                                 }
99                                 break;
100                         case "labeledurl":
101                                 $tok = strtok($this->values[$index], " ");
102                                 $tok2 = strtok("\0");
103                                 $p .=  '<a href='.$tok.'>'.$tok2.'</a>';
104                                 break;
105                         case "lastmodifiedtime":
106                         case "modifytimestamp":
107                                 $t = $this->values[$index];
108                                 $hour = (int) $t[6].$t[7];
109                                 $minute = (int) $t[8].$t[9];
110                                 $second = (int) $t[10].$t[11];
111                                 $month = (int) $t[2].$t[3];
112                                 $day = (int) $t[4].$t[5];
113                                 $year = (int) $t[0].$t[1];
114                                 $timestamp = mktime($hour, $minute, $second, $month, $day, $year);
115                                 $date = date("h:i:sa, on l, dS of F Y", $timestamp);
116                                 $p .= $date;
117                                 break;
118                         case "jpegphoto":
119                                 $p .= '<a href="'.$prefs->get("PATH.photo").'?base_dn='.urlencode($this->dn).'"><img src="'.$prefs->get("PATH.photo").'?base_dn='.urlencode($this->dn).'" alt="Image of '.$this->cn.'" border=0></a>';
120                                 break;
121                         default:
122                                 $p .= $this->values[$index];
123                                 break;
124                 }
125                 return $p;
126         }
127
128         cfunction displayValue($index) {
129                 //echo "ldap_entry_attribute.displayValue(".$index.")<br>\n";
130                 global $FILE, $host;
131                 if ($this->name == "cn") {
132                         print "<a href=".$FILE."?host=".urlencode($host)."&ldap_action=read&base_dn=".urlencode($this->dn).">".$this->values[$index]."</a>";
133                 }
134                 else if ($this->name == "ou") {
135                         print "<a href=".$FILE."?ldap_action=list&host=".urlencode($host)."&base_dn=".urlencode($this->dn).">".$this->values[$index]."</a>";
136                 }
137                 else if ($this->name == "seealso" || $this->name == "member" || $this->name == "requeststo" || $this->name == "errorsto" || $this->name == "owner" || $this->name == "lastmodifiedby" || $this->name == "modifiersname") {
138                         print "<a href=".$FILE."?host=".urlencode($host)."&ldap_action=read&base_dn=".urlencode($this->values[$index]).">".ldap_dn2ufn($this->values[$index])."</a>";
139                 }
140                 else if ($this->name == "mail") {
141                         print "<a href=mailto:".$this->values[$index].">".$this->values[$index]."</a>";
142                 }
143                 else if ($this->name == "labeledurl") {
144                         $tok = strtok($this->values[$index], " ");
145                         $tok2 = strtok("\0");
146                         print '<a href='.$tok.'>'.$tok2.'</a>';
147                 }
148                 else if ($this->name == "lastmodifiedtime" || $this->name == "modifytimestamp") {
149                         $t = $this->values[$index];
150                         $hour = (int) $t[6].$t[7];
151                         $minute = (int) $t[8].$t[9];
152                         $second = (int) $t[10].$t[11];
153                         $month = (int) $t[2].$t[3];
154                         $day = (int) $t[4].$t[5];
155                         $year = (int) $t[0].$t[1];
156                         $timestamp = mktime($hour, $minute, $second, $month, $day, $year);
157                         $date = date("h:i:sa, on l, dS of F Y", $timestamp);
158                 //      $date = getdate($timestamp);
159                 //      $date = getdate($this->values[$index]);
160                 //      echo "".$date["hours"].":".$date["minutes"].",
161                 //      ".$date["weekday"].",".$date["month"]." ".$date["mday"].", ".$date["year"]."<br>\n";
162                         print $date;
163                 }
164                 else {
165                         print $this->values[$index];
166                 }
167         }
168 }
169 ?>