Code

Updated acl resolver and the reference tab
[gosa.git] / 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();
32     var $aclResolver = NULL;
34     function reference (&$config, $dn= NULL)
35     {
36         /* Include config object */
37         $this->config= &$config;
38         $this->dn= $dn;
39         $this->aclResolver = new aclResolver($this->config, $this->dn, $this);
41         /* Fill translation array */
42         $this->obtypes= array(  
43                 "gosaAccount" => array(    "text" => _("Generic"),
44                     "image" => "images/penguin.png"),
45                 "posixAccount" => array(   "text" =>_("UNIX"),
46                     "image" => "plugins/users/images/select_user.png"),
47                 "gosaMailAccount" => array("text" => _("Mail"),
48                     "image" => "images/mailto.png"),
49                 "sambaSamAccount" => array("text" => _("Samba"),
50                     "image" => "plugins/systems/images/select_winstation.png"),
51                 "sambaAccount" => array(   "text" => _("Samba"),
52                     "image" => "plugins/sysmtes/images/select_winstation.png"),
53                 "goFaxAccount" => array(   "text" => _("FAX"),
54                     "image" => "plugins/gofax/images/fax_small.png"),
55                 "gosaProxyAccount" => array("text" => _("Proxy"),
56                     "image" => "images/select_proxy.png"),
57                 "PureFTPdUser" => array(   "text" => _("FTP"),
58                     "image" => "images/select_proxy.png"),
59                 "posixGroup" => array(     "text" => _("Group"),
60                     "image" => "plugins/groups/images/select_group.png"),
61                 "gosaDepartment" => array( "text" => _("Department"),
62                     "image" => "images/select_department.png"),
63                 "goFonHardware" => array(   "text" => _("Phone"),
64                         "image" => "plugins/systems/images/select_phone.png"),
65                 "gosaApplication" => array("text" => _("Application"),
66                         "image" => "plugins/goto/images/select_application.png"),
67                 "goServer" => array(       "text" => _("Server"),
68                         "image" => "plugins/systems/images/select_server.png"),
69                 "gotoTerminal" => array(   "text" => _("Thin Client"),
70                         "image" => "images/select_terminal.png"),
71                 "gotoWorkstation" => array("text" => _("Workstation"),
72                         "image" => "plugins/systems/images/select_workstation.png"),
73                 "gosaGroupOfNames" => array("text" => _("Object group"),
74                         "image" => "plugins/ogroups/images/select_ogroup.png"),
75                 "gotoPrinter" => array(    "text" => _("Printer"),
76                         "image" => "plugins/systems/images/select_printer.png"));
78     }
80     function execute()
81     {
82         /* Call parent execute */
83         plugin::execute();
85         // ACL's we have
86         $ui = get_userinfo();
88         /* Set government mode */
89         $smarty= get_smarty();
91         if (isset($_GET['show'])){
92             $dn= base64_decode($_GET['show']);
93             if (isset($this->fold["$dn"])){
94                 unset($this->fold["$dn"]);
95             } else {
96                 $this->fold["$dn"]= "$dn";
97             }
98         }
100         /* Fill array */
101         $this->reload();
102         $smarty->assign("objectList", $this->objectlist);
103         $smarty->assign("acls",$this->aclResolver->getReadableACL());
105         /* Show main page */
106         return ($smarty->fetch (get_template_path('contents.tpl', TRUE, dirname(__FILE__))));
107     }
110     function reload()
111     {
112         $ldap= $this->config->get_ldap_link();
113         $ldap->cd($this->config->current['BASE']);
115         $ldap->search(
116                 "(|(gotoHotplugDeviceDN=".LDAP::prepare4filter($this->dn).")".
117                 "(member=".LDAP::prepare4filter($this->dn).")(memberUid=".$this->uid."))",
118                 array("memberUid","member","cn","description","objectClass"));
120         $cycle= array("F5F5F5", "ECECEC");
121         $id= 0;
122         $this->objectlist= "";
123         while ($attrs= $ldap->fetch()){
125             /* Add more information? */
126             $addon= "";
127             if (in_array($attrs['dn'], $this->fold)){
128                 $memberattr= "";
129                 if (isset($attrs['memberUid'])){
130                     unset($attrs['memberUid']['count']);
131                     $memberattr= "memberUid";
132                 } 
133                 if (isset($attrs['member'])){
134                     unset($attrs['member']['count']);
135                     $memberattr= "member";
136                 } 
137                 if ($memberattr == ""){
138                     continue;
139                 }
140                 foreach ($attrs[$memberattr] as $uid){
141                     $content= $this->getCacheObject($uid);
142                     if ($content === NULL) {
143                         continue;
144                     }
145                     $addon.= 
146                         ' <tr style="background-color:'.$cycle[$id&1].';"> '.
147                         '   <td title="'.$attrs['cn'][0].'">&nbsp;&nbsp;&nbsp;'.$content['name'].'</td>'.
148                         '   <td>'.$content['description'].'</td>'.
149                         '   <td>'.$content['type'].'</td> '.
150                         ' </tr>';
151                 }
152             }
154             /* Build final entry */
155             if (isset($attrs['description'])){
156                 $description= $attrs['description'][0];
157             } else {
158                 $description= "-";
159             }
160             $content= $this->createContentString($attrs['objectClass']);
161             if ($addon == ""){
162                 $img= "images/lists/expand.png";
163             } else {
164                 $img= "images/lists/sort-down.png";
165             }
167             $this->objectlist.= 
168                 ' <tr style="background-color:'.$cycle[$id&1].';">  '.
169                 '   <td class="phonelist" title="'.$attrs['cn'][0].'">  '.
170                 '     '.image($img).
171                 '     <a href="main.php?plug='.$_GET['plug'].'&amp;start=&amp;show='.base64_encode($attrs['dn']).'"> '.
172                 '     &nbsp;'.$attrs['cn'][0].
173                 '     </a> '.
174                 '   </td> '.
175                 '   <td>'.
176                 '     <a href="main.php?plug='.$_GET['plug'].'&amp;start=&amp;show='.base64_encode($attrs['dn']).'"> '.
177                 $description.
178                 '     </a> '.
179                 '   </td> '.
180                 '   <td>'.$content.'</td> '.
181                 ' </tr>'.$addon;
182             $id++;
183         }
185     }
187     function getCacheObject($dn)
188     {
189         if (!isset($this->objectCache[$dn])){
190             $ldap= $this->config->get_ldap_link();
191             if (preg_match('/,/', $dn)){
192                 $ldap->cat($dn, array("cn", "objectClass", "description","ou"));
193             } else {
194                 $ldap->search("(uid=$dn)", array("cn", "objectClass", "description","ou"));
195             }
196             if ($ldap->count()){
197                 $attrs= $ldap->fetch();
199                 if(isset($attrs['ou']) && !isset($attrs['cn'])){
200                     $attrs['cn'] = $attrs['ou'];
201                 }
203                 if (isset($attrs['description'])){
204                     $description= $attrs['description'][0];
205                 } else {
206                     $description= "-";
207                 }
208                 $this->objectCache[$dn]= array( 'name' => $attrs['cn'][0],
209                         'description' => "$description",
210                         'type' => $this->createContentString($attrs['objectClass']));
211             } else {
212                 return NULL;
213             }
214         }
215         return ($this->objectCache[$dn]);
216     }
218     function createContentString($classes)
219     {
220         $result= "";
221         if(!is_null($classes)) {
222             foreach ($classes as $class){
223                 if (isset($this->obtypes[$class])){
224                     $result.= 
225                         " ".image($this->obtypes[$class]['image']).
226                         " <a>".
227                         "   ".$this->obtypes[$class]['text'].
228                         " </a> ";
229                 }
230             }
231         }
232         return (preg_replace('/ $/', '', $result));
233     }
237 ?>