Code

added alt=\"\" for <img ....
[gosa.git] / 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         /* Set government mode */
59         $smarty= get_smarty();
61         if (isset($_GET['show'])){
62                 $dn= base64_decode($_GET['show']);
63                 if (isset($this->fold["$dn"])){
64                         unset($this->fold["$dn"]);
65                 } else {
66                         $this->fold["$dn"]= "$dn";
67                 }
68         }
70         /* Fill array */
71         $this->reload();
72         $smarty->assign("objectList", $this->objectlist);
74         /* Show main page */
75         return ($smarty->fetch (get_template_path('contents.tpl', TRUE, dirname(__FILE__))));
76   }
78   function reload()
79   {
80         $ldap= $this->config->get_ldap_link();
81         $ldap->cd($this->config->current['BASE']);
82         $ldap->search("(|(member=".$this->dn.")(memberUid=".$this->uid."))");
83         
84         $cycle= array("F5F5F5", "ECECEC");
85         $id= 0;
86         $this->objectlist= "";
87         while ($attrs= $ldap->fetch()){
89                 /* Add more information? */
90                 $addon= "";
91                 if (in_array($attrs['dn'], $this->fold)){
92                         $memberattr= "";
93                         if (isset($attrs['memberUid'])){
94                                 unset($attrs['memberUid']['count']);
95                                 $memberattr= "memberUid";
96                         } 
97                         if (isset($attrs['member'])){
98                                 unset($attrs['member']['count']);
99                                 $memberattr= "member";
100                         } 
101                         if ($memberattr == ""){
102                                 continue;
103                         }
104                         foreach ($attrs[$memberattr] as $uid){
105                                 $content= $this->getCacheObject($uid);
106                                 $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>';
107                         }
108                 }
110                 /* Build final entry */
111                 if (isset($attrs['description'])){
112                         $description= $attrs['description'][0];
113                 } else {
114                         $description= "-";
115                 }
116                 $content= $this->createContentString($attrs['objectClass']);
117                 if ($addon == ""){
118                         $img= "images/expand.png";
119                 } else {
120                         $img= "images/sort_down.png";
121                 }
122                 $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;
124                 $id++;
125         }
126         
127   }
129   function getCacheObject($dn)
130   {
131         if (!isset($this->objectCache[$dn])){
132                 $ldap= $this->config->get_ldap_link();
133                 if (preg_match('/,/', $dn)){
134                         $ldap->cat($dn, array("cn", "objectClass", "description"));
135                 } else {
136                         $ldap->search("(uid=$dn)", array("cn", "objectClass", "description"));
137                 }
138                 $attrs= $ldap->fetch();
139                 if (isset($attrs['description'])){
140                         $description= $attrs['description'][0];
141                 } else {
142                         $description= "-";
143                 }
144                 $this->objectCache[$dn]= array( 'name' => $attrs['cn'][0],
145                                                 'description' => "$description",
146                                                 'type' => $this->createContentString($attrs['objectClass']));
147         }
148         return ($this->objectCache[$dn]);
149   }
151   function createContentString($classes)
152   {
153         $result= "";
154         foreach ($classes as $class){
155                 if (isset($this->obtypes[$class])){
156                         $result.= "<a><img alt=\"\" border=0 src='images/".$this->obtypes[$class]['image']."'>&nbsp;".$this->obtypes[$class]['text']."</a> ";
157                 }
158         }       
159         return (preg_replace('/ $/', '', $result));
160   }
161   
164 ?>