Code

Fix path for groups in references tab (#6185)
[gosa.git] / trunk / gosa-core / plugins / generic / references / class_reference.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class reference extends plugin
24 {
25   /* attribute list for save action */
26   var $attributes= array();
27   var $objectclasses= array();
28   var $objectlist= "";
29   var $obtypes= array();
30   var $fold= array();
31   var $objectCache= array();
33   function reference (&$config, $dn= NULL)
34   {
35         /* Include config object */
36         $this->config= &$config;
37         $this->dn= $dn;
39         /* Fill translation array */
40         $this->obtypes= array(  
41                                 "gosaAccount" => array(    "text" => _("Generic"),
42                                         "image" => "images/penguin.png"),
43                                 "posixAccount" => array(   "text" =>_("UNIX"),
44                                         "image" => "plugins/users/images/select_user.png"),
45                                 "gosaMailAccount" => array("text" => _("Mail"),
46                                         "image" => "images/mailto.png"),
47                                 "sambaSamAccount" => array("text" => _("Samba"),
48                                         "image" => "plugins/systems/images/select_winstation.png"),
49                                 "sambaAccount" => array(   "text" => _("Samba"),
50                                         "image" => "plugins/sysmtes/images/select_winstation.png"),
51                                 "goFaxAccount" => array(   "text" => _("FAX"),
52                                         "image" => "plugins/gofax/images/fax_small.png"),
53                                 "gosaProxyAccount" => array("text" => _("Proxy"),
54                                         "image" => "images/select_proxy.png"),
55                                 "PureFTPdUser" => array(   "text" => _("FTP"),
56                                         "image" => "images/select_proxy.png"),
57                                 "posixGroup" => array(     "text" => _("Group"),
58                                         "image" => "plugins/groups/images/groups.png"),
59                                 "gosaDepartment" => array( "text" => _("Department"),
60                                         "image" => "images/select_department.png"),
61                                 "goFonHardware" => array(   "text" => _("Phone"),
62                                         "image" => "plugins/systems/images/select_phone.png"),
63                                 "gosaApplication" => array("text" => _("Application"),
64                                                 "image" => "plugins/goto/images/select_application.png"),
65                                 "goServer" => array(       "text" => _("Server"),
66                                                 "image" => "plugins/systems/images/select_server.png"),
67                                 "gotoTerminal" => array(   "text" => _("Thin Client"),
68                                                 "image" => "images/select_terminal.png"),
69                                 "gotoWorkstation" => array("text" => _("Workstation"),
70                                                 "image" => "plugins/systems/images/select_workstation.png"),
71                                 "gosaGroupOfNames" => array("text" => _("Object group"),
72                                                 "image" => "plugins/ogroups/images/select_ogroup.png"),
73                                 "gotoPrinter" => array(    "text" => _("Printer"),
74                                                 "image" => "plugins/systems/images/select_printer.png"));
75   }
77   function execute()
78   {
79         /* Call parent execute */
80         plugin::execute();
82         /* Set government mode */
83         $smarty= get_smarty();
85         if (isset($_GET['show'])){
86                 $dn= base64_decode($_GET['show']);
87                 if (isset($this->fold["$dn"])){
88                         unset($this->fold["$dn"]);
89                 } else {
90                         $this->fold["$dn"]= "$dn";
91                 }
92         }
94         /* Fill array */
95         $this->reload();
96         $smarty->assign("objectList", $this->objectlist);
98         /* Show main page */
99         return ($smarty->fetch (get_template_path('contents.tpl', TRUE, dirname(__FILE__))));
100   }
102   function reload()
103   {
104         $ldap= $this->config->get_ldap_link();
105         $ldap->cd($this->config->current['BASE']);
107         $ldap->search("(|(gotoHotplugDeviceDN=".LDAP::prepare4filter($this->dn).")(member=".LDAP::prepare4filter($this->dn).")(memberUid=".$this->uid."))",array("memberUid","member","cn","description","objectClass"));
108         
109         $cycle= array("F5F5F5", "ECECEC");
110         $id= 0;
111         $this->objectlist= "";
112         while ($attrs= $ldap->fetch()){
114                 /* Add more information? */
115                 $addon= "";
116                 if (in_array($attrs['dn'], $this->fold)){
117                         $memberattr= "";
118                         if (isset($attrs['memberUid'])){
119                                 unset($attrs['memberUid']['count']);
120                                 $memberattr= "memberUid";
121                         } 
122                         if (isset($attrs['member'])){
123                                 unset($attrs['member']['count']);
124                                 $memberattr= "member";
125                         } 
126                         if ($memberattr == ""){
127                                 continue;
128                         }
129                         foreach ($attrs[$memberattr] as $uid){
130                                 $content= $this->getCacheObject($uid);
131                                 if ($content === NULL) {
132                                         continue;
133                                 }
134                                 $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>';
135                         }
136                 }
138                 /* Build final entry */
139                 if (isset($attrs['description'])){
140                         $description= $attrs['description'][0];
141                 } else {
142                         $description= "-";
143                 }
144                 $content= $this->createContentString($attrs['objectClass']);
145                 if ($addon == ""){
146                         $img= "images/lists/expand.png";
147                 } else {
148                         $img= "images/lists/sort-down.png";
149                 }
150                 $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;
152                 $id++;
153         }
154         
155   }
157   function getCacheObject($dn)
158   {
159         if (!isset($this->objectCache[$dn])){
160                 $ldap= $this->config->get_ldap_link();
161                 if (preg_match('/,/', $dn)){
162                         $ldap->cat($dn, array("cn", "objectClass", "description","ou"));
163                 } else {
164                         $ldap->search("(uid=$dn)", array("cn", "objectClass", "description","ou"));
165                 }
166                 if ($ldap->count()){
167                         $attrs= $ldap->fetch();
169                         if(isset($attrs['ou']) && !isset($attrs['cn'])){
170                                 $attrs['cn'] = $attrs['ou'];
171                         }
172                                 
173                         if (isset($attrs['description'])){
174                                 $description= $attrs['description'][0];
175                         } else {
176                                 $description= "-";
177                         }
178                         $this->objectCache[$dn]= array( 'name' => $attrs['cn'][0],
179                                         'description' => "$description",
180                                         'type' => $this->createContentString($attrs['objectClass']));
181                 } else {
182                         return NULL;
183                 }
184         }
185         return ($this->objectCache[$dn]);
186   }
188   function createContentString($classes)
189   {
190         $result= "";
191         if(!is_null($classes)) {
192                 foreach ($classes as $class){
193                         if (isset($this->obtypes[$class])){
194                                 $result.= "<a><img alt=\"\" border=0 src='".$this->obtypes[$class]['image']."'>&nbsp;".$this->obtypes[$class]['text']."</a> ";
195                         }
196                 }
197         }
198         return (preg_replace('/ $/', '', $result));
199   }
200   
203 ?>