Code

* Introduced FAIstate in workstationGeneric
[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                                 $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>';
110                         }
111                 }
113                 /* Build final entry */
114                 if (isset($attrs['description'])){
115                         $description= $attrs['description'][0];
116                 } else {
117                         $description= "-";
118                 }
119                 $content= $this->createContentString($attrs['objectClass']);
120                 if ($addon == ""){
121                         $img= "images/expand.png";
122                 } else {
123                         $img= "images/sort_down.png";
124                 }
125                 $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;
127                 $id++;
128         }
129         
130   }
132   function getCacheObject($dn)
133   {
134         if (!isset($this->objectCache[$dn])){
135                 $ldap= $this->config->get_ldap_link();
136                 if (preg_match('/,/', $dn)){
137                         $ldap->cat($dn, array("cn", "objectClass", "description"));
138                 } else {
139                         $ldap->search("(uid=$dn)", array("cn", "objectClass", "description"));
140                 }
141                 $attrs= $ldap->fetch();
142                 if (isset($attrs['description'])){
143                         $description= $attrs['description'][0];
144                 } else {
145                         $description= "-";
146                 }
147                 $this->objectCache[$dn]= array( 'name' => $attrs['cn'][0],
148                                                 'description' => "$description",
149                                                 'type' => $this->createContentString($attrs['objectClass']));
150         }
151         return ($this->objectCache[$dn]);
152   }
154   function createContentString($classes)
155   {
156         $result= "";
157         if(!is_null($classes)) {
158                 foreach ($classes as $class){
159                         if (isset($this->obtypes[$class])){
160                                 $result.= "<a><img alt=\"\" border=0 src='images/".$this->obtypes[$class]['image']."'>&nbsp;".$this->obtypes[$class]['text']."</a> ";
161                         }
162                 }
163         }
164         return (preg_replace('/ $/', '', $result));
165   }
166   
169 ?>