Code

Test
[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();
90         $smarty->assign("usePrototype", "true");
91         session::set('autocomplete', $this->aclResolver);
93         if (isset($_GET['show'])){
94             $dn= base64_decode($_GET['show']);
95             if (isset($this->fold["$dn"])){
96                 unset($this->fold["$dn"]);
97             } else {
98                 $this->fold["$dn"]= "$dn";
99             }
100         }
102         /* Fill array */
103         $this->reload();
104         $smarty->assign("objectList", $this->objectlist);
105         $smarty->assign("acls",$this->aclResolver->getReadableACL());
107         /* Show main page */
108         return ($smarty->fetch (get_template_path('contents.tpl', TRUE, dirname(__FILE__))));
109     }
112     function reload()
113     {
114         $ldap= $this->config->get_ldap_link();
115         $ldap->cd($this->config->current['BASE']);
117         $ldap->search(
118                 "(|(gotoHotplugDeviceDN=".LDAP::prepare4filter($this->dn).")".
119                 "(member=".LDAP::prepare4filter($this->dn).")(memberUid=".$this->uid."))",
120                 array("memberUid","member","cn","description","objectClass"));
122         $cycle= array("F5F5F5", "ECECEC");
123         $id= 0;
124         $this->objectlist= "";
125         while ($attrs= $ldap->fetch()){
127             /* Add more information? */
128             $addon= "";
129             if (in_array($attrs['dn'], $this->fold)){
130                 $memberattr= "";
131                 if (isset($attrs['memberUid'])){
132                     unset($attrs['memberUid']['count']);
133                     $memberattr= "memberUid";
134                 } 
135                 if (isset($attrs['member'])){
136                     unset($attrs['member']['count']);
137                     $memberattr= "member";
138                 } 
139                 if ($memberattr == ""){
140                     continue;
141                 }
142                 foreach ($attrs[$memberattr] as $uid){
143                     $content= $this->getCacheObject($uid);
144                     if ($content === NULL) {
145                         continue;
146                     }
147                     $addon.= 
148                         ' <tr style="background-color:'.$cycle[$id&1].';"> '.
149                         '   <td title="'.$attrs['cn'][0].'">&nbsp;&nbsp;&nbsp;'.$content['name'].'</td>'.
150                         '   <td>'.$content['description'].'</td>'.
151                         '   <td>'.$content['type'].'</td> '.
152                         ' </tr>';
153                 }
154             }
156             /* Build final entry */
157             if (isset($attrs['description'])){
158                 $description= $attrs['description'][0];
159             } else {
160                 $description= "-";
161             }
162             $content= $this->createContentString($attrs['objectClass']);
163             if ($addon == ""){
164                 $img= "images/lists/expand.png";
165             } else {
166                 $img= "images/lists/sort-down.png";
167             }
169             $this->objectlist.= 
170                 ' <tr style="background-color:'.$cycle[$id&1].';">  '.
171                 '   <td class="phonelist" title="'.$attrs['cn'][0].'">  '.
172                 '     '.image($img).
173                 '     <a href="main.php?plug='.$_GET['plug'].'&amp;start=&amp;show='.base64_encode($attrs['dn']).'"> '.
174                 '     &nbsp;'.$attrs['cn'][0].
175                 '     </a> '.
176                 '   </td> '.
177                 '   <td>'.
178                 '     <a href="main.php?plug='.$_GET['plug'].'&amp;start=&amp;show='.base64_encode($attrs['dn']).'"> '.
179                 $description.
180                 '     </a> '.
181                 '   </td> '.
182                 '   <td>'.$content.'</td> '.
183                 ' </tr>'.$addon;
184             $id++;
185         }
187     }
189     function getCacheObject($dn)
190     {
191         if (!isset($this->objectCache[$dn])){
192             $ldap= $this->config->get_ldap_link();
193             if (preg_match('/,/', $dn)){
194                 $ldap->cat($dn, array("cn", "objectClass", "description","ou"));
195             } else {
196                 $ldap->search("(uid=$dn)", array("cn", "objectClass", "description","ou"));
197             }
198             if ($ldap->count()){
199                 $attrs= $ldap->fetch();
201                 if(isset($attrs['ou']) && !isset($attrs['cn'])){
202                     $attrs['cn'] = $attrs['ou'];
203                 }
205                 if (isset($attrs['description'])){
206                     $description= $attrs['description'][0];
207                 } else {
208                     $description= "-";
209                 }
210                 $this->objectCache[$dn]= array( 'name' => $attrs['cn'][0],
211                         'description' => "$description",
212                         'type' => $this->createContentString($attrs['objectClass']));
213             } else {
214                 return NULL;
215             }
216         }
217         return ($this->objectCache[$dn]);
218     }
220     function createContentString($classes)
221     {
222         $result= "";
223         if(!is_null($classes)) {
224             foreach ($classes as $class){
225                 if (isset($this->obtypes[$class])){
226                     $result.= 
227                         " ".image($this->obtypes[$class]['image']).
228                         " <a>".
229                         "   ".$this->obtypes[$class]['text'].
230                         " </a> ";
231                 }
232             }
233         }
234         return (preg_replace('/ $/', '', $result));
235     }
239 ?>