Code

4b17529dbbbf318a30ffc91b5e3ebb99f40418d4
[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         /* 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']);
85         $ldap->search("(|(member=".$this->dn.")(memberUid=".$this->uid."))",array("memberUid","member","cn","description","objectClass"));
86         
87         $cycle= array("F5F5F5", "ECECEC");
88         $id= 0;
89         $this->objectlist= "";
90         while ($attrs= $ldap->fetch()){
92                 /* Add more information? */
93                 $addon= "";
94                 if (in_array($attrs['dn'], $this->fold)){
95                         $memberattr= "";
96                         if (isset($attrs['memberUid'])){
97                                 unset($attrs['memberUid']['count']);
98                                 $memberattr= "memberUid";
99                         } 
100                         if (isset($attrs['member'])){
101                                 unset($attrs['member']['count']);
102                                 $memberattr= "member";
103                         } 
104                         if ($memberattr == ""){
105                                 continue;
106                         }
107                         foreach ($attrs[$memberattr] as $uid){
108                                 $content= $this->getCacheObject($uid);
109                                 if ($content == NULL){
110                                         continue;
111                                 }
112                                 $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>';
113                         }
114                 }
116                 /* Build final entry */
117                 if (isset($attrs['description'])){
118                         $description= $attrs['description'][0];
119                 } else {
120                         $description= "-";
121                 }
122                 $content= $this->createContentString($attrs['objectClass']);
123                 if ($addon == ""){
124                         $img= "images/expand.png";
125                 } else {
126                         $img= "images/sort_down.png";
127                 }
128                 $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;
130                 $id++;
131         }
132         
133   }
135   function getCacheObject($dn)
136   {
137         if (!isset($this->objectCache[$dn])){
138                 $ldap= $this->config->get_ldap_link();
139                 if (preg_match('/,/', $dn)){
140                         $ldap->cat($dn, array("cn", "objectClass", "description"));
141                 } else {
142                         $ldap->search("(uid=$dn)", array("cn", "objectClass", "description"));
143                 }
144                 if ($ldap->count()){
145                         $attrs= $ldap->fetch();
146                         if (isset($attrs['description'])){
147                                 $description= $attrs['description'][0];
148                         } else {
149                                 $description= "-";
150                         }
151                         $this->objectCache[$dn]= array( 'name' => $attrs['cn'][0],
152                                         'description' => "$description",
153                                         'type' => $this->createContentString($attrs['objectClass']));
154                 } else {
155                         return NULL;
156                 }
157         }
158         return ($this->objectCache[$dn]);
159   }
161   function createContentString($classes)
162   {
163         $result= "";
164         if(!is_null($classes)) {
165                 foreach ($classes as $class){
166                         if (isset($this->obtypes[$class])){
167                                 $result.= "<a><img alt=\"\" border=0 src='images/".$this->obtypes[$class]['image']."'>&nbsp;".$this->obtypes[$class]['text']."</a> ";
168                         }
169                 }
170         }
171         return (preg_replace('/ $/', '', $result));
172   }
173   
176 ?>