Code

Fixed references with strange dn's
[gosa.git] / gosa-core / plugins / generic / references / class_reference.inc
1 <?php
3 class reference extends plugin
4 {
5   /* attribute list for save action */
6   var $attributes= array();
7   var $objectclasses= array();
8   var $objectlist= "";
9   var $obtypes= array();
10   var $fold= array();
11   var $objectCache= array();
13   function reference (&$config, $dn= NULL)
14   {
15         /* Include config object */
16         $this->config= &$config;
17         $this->dn= $dn;
19         /* Fill translation array */
20         $this->obtypes= array(  "gosaAccount" => array(    "text" => _("Generic"),
21                                                            "image" => "penguin.png"),
22                                 "posixAccount" => array(   "text" =>_("UNIX"),
23                                                            "image" => "select_user.png"),
24                                 "gosaMailAccount" => array("text" => _("Mail"),
25                                                            "image" => "mailto.png"),
26                                 "sambaSamAccount" => array("text" => _("Samba"),
27                                                            "image" => "select_winstation.png"),
28                                 "sambaAccount" => array(   "text" => _("Samba"),
29                                                            "image" => "select_winstation.png"),
30                                 "goFaxAccount" => array(   "text" => _("FAX"),
31                                                            "image" => "fax_small.png"),
32                                 "gosaProxyAccount" => array("text" => _("Proxy"),
33                                                            "image" => "select_proxy.png"),
34                                 "PureFTPdUser" => array(   "text" => _("FTP"),
35                                                            "image" => "select_proxy.png"),
36                                 "posixGroup" => array(     "text" => _("Group"),
37                                                            "image" => "select_groups.png"),
38                                 "gosaDepartment" => array( "text" => _("Department"),
39                                                            "image" => "select_department.png"),
40                                 "goFonHardware" => array(   "text" => _("Phone"),
41                                                            "image" => "select_phone.png"),
42                                 "gosaApplication" => array("text" => _("Application"),
43                                                            "image" => "select_application.png"),
44                                 "goServer" => array(       "text" => _("Server"),
45                                                            "image" => "select_server.png"),
46                                 "gotoTerminal" => array(   "text" => _("Thin Client"),
47                                                            "image" => "select_terminal.png"),
48                                 "gotoWorkstation" => array("text" => _("Workstation"),
49                                                            "image" => "select_workstation.png"),
50                                 "gosaGroupOfNames" => array("text" => _("Object group"),
51                                                            "image" => "select_ogroup.png"),
52                                 "gotoPrinter" => array(    "text" => _("Printer"),
53                                                            "image" => "select_printer.png"));
54   }
56   function execute()
57   {
58         /* Call parent execute */
59         plugin::execute();
61         /* Set government mode */
62         $smarty= get_smarty();
64         if (isset($_GET['show'])){
65                 $dn= base64_decode($_GET['show']);
66                 if (isset($this->fold["$dn"])){
67                         unset($this->fold["$dn"]);
68                 } else {
69                         $this->fold["$dn"]= "$dn";
70                 }
71         }
73         /* Fill array */
74         $this->reload();
75         $smarty->assign("objectList", $this->objectlist);
77         /* Show main page */
78         return ($smarty->fetch (get_template_path('contents.tpl', TRUE, dirname(__FILE__))));
79   }
81   function reload()
82   {
83         $ldap= $this->config->get_ldap_link();
84         $ldap->cd($this->config->current['BASE']);
86         $ldap->search("(|(member=".normalizeLdap(preg_replace('/\\\\/', '\\\\\\', LDAP::fix($this->dn))).")(memberUid=".$this->uid."))",array("memberUid","member","cn","description","objectClass"));
87         
88         $cycle= array("F5F5F5", "ECECEC");
89         $id= 0;
90         $this->objectlist= "";
91         while ($attrs= $ldap->fetch()){
93                 /* Add more information? */
94                 $addon= "";
95                 if (in_array($attrs['dn'], $this->fold)){
96                         $memberattr= "";
97                         if (isset($attrs['memberUid'])){
98                                 unset($attrs['memberUid']['count']);
99                                 $memberattr= "memberUid";
100                         } 
101                         if (isset($attrs['member'])){
102                                 unset($attrs['member']['count']);
103                                 $memberattr= "member";
104                         } 
105                         if ($memberattr == ""){
106                                 continue;
107                         }
108                         foreach ($attrs[$memberattr] as $uid){
109                                 $content= $this->getCacheObject($uid);
110                                 if ($content === NULL) {
111                                         continue;
112                                 }
113                                 $addon.= '<tr style="background-color:'.$cycle[$id&1].';"><td title="'.$attrs['cn'][0].'">&nbsp;&nbsp;&nbsp;'.$content['name'].'</td><td>'.$content['description'].'</td><td>'.$content['type'].'</td> </tr>';
114                         }
115                 }
117                 /* Build final entry */
118                 if (isset($attrs['description'])){
119                         $description= $attrs['description'][0];
120                 } else {
121                         $description= "-";
122                 }
123                 $content= $this->createContentString($attrs['objectClass']);
124                 if ($addon == ""){
125                         $img= "images/expand.png";
126                 } else {
127                         $img= "images/sort_down.png";
128                 }
129                 $this->objectlist.= '<tr style="background-color:'.$cycle[$id&1].';"><td class="phonelist" title="'.$attrs['cn'][0].'"><a href="main.php?plug='.$_GET['plug'].'&amp;start=&amp;show='.base64_encode($attrs['dn']).'"><img alt="" src="'.$img.'" border=0>&nbsp;'.$attrs['cn'][0].'</a></td><td>'.$description.'</td><td>'.$content.'</td> </tr>'.$addon;
131                 $id++;
132         }
133         
134   }
136   function getCacheObject($dn)
137   {
138         if (!isset($this->objectCache[$dn])){
139                 $ldap= $this->config->get_ldap_link();
140                 if (preg_match('/,/', $dn)){
141                         $ldap->cat($dn, array("cn", "objectClass", "description","ou"));
142                 } else {
143                         $ldap->search("(uid=$dn)", array("cn", "objectClass", "description","ou"));
144                 }
145                 if ($ldap->count()){
146                         $attrs= $ldap->fetch();
148                         if(isset($attrs['ou']) && !isset($attrs['cn'])){
149                                 $attrs['cn'] = $attrs['ou'];
150                         }
151                                 
152                         if (isset($attrs['description'])){
153                                 $description= $attrs['description'][0];
154                         } else {
155                                 $description= "-";
156                         }
157                         $this->objectCache[$dn]= array( 'name' => $attrs['cn'][0],
158                                         'description' => "$description",
159                                         'type' => $this->createContentString($attrs['objectClass']));
160                 } else {
161                         return NULL;
162                 }
163         }
164         return ($this->objectCache[$dn]);
165   }
167   function createContentString($classes)
168   {
169         $result= "";
170         if(!is_null($classes)) {
171                 foreach ($classes as $class){
172                         if (isset($this->obtypes[$class])){
173                                 $result.= "<a><img alt=\"\" border=0 src='images/".$this->obtypes[$class]['image']."'>&nbsp;".$this->obtypes[$class]['text']."</a> ";
174                         }
175                 }
176         }
177         return (preg_replace('/ $/', '', $result));
178   }
179   
182 ?>