Code

Updated 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();
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/select_group.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(
108         "(|(gotoHotplugDeviceDN=".LDAP::prepare4filter($this->dn).")".
109         "(member=".LDAP::prepare4filter($this->dn).")(memberUid=".$this->uid."))",
110         array("memberUid","member","cn","description","objectClass"));
112     $cycle= array("F5F5F5", "ECECEC");
113     $id= 0;
114     $this->objectlist= "";
115     while ($attrs= $ldap->fetch()){
117       /* Add more information? */
118       $addon= "";
119       if (in_array($attrs['dn'], $this->fold)){
120         $memberattr= "";
121         if (isset($attrs['memberUid'])){
122           unset($attrs['memberUid']['count']);
123           $memberattr= "memberUid";
124         } 
125         if (isset($attrs['member'])){
126           unset($attrs['member']['count']);
127           $memberattr= "member";
128         } 
129         if ($memberattr == ""){
130           continue;
131         }
132         foreach ($attrs[$memberattr] as $uid){
133           $content= $this->getCacheObject($uid);
134           if ($content === NULL) {
135             continue;
136           }
137           $addon.= 
138             ' <tr style="background-color:'.$cycle[$id&1].';"> '.
139             '   <td title="'.$attrs['cn'][0].'">&nbsp;&nbsp;&nbsp;'.$content['name'].'</td>'.
140             '   <td>'.$content['description'].'</td>'.
141             '   <td>'.$content['type'].'</td> '.
142             ' </tr>';
143         }
144       }
146       /* Build final entry */
147       if (isset($attrs['description'])){
148         $description= $attrs['description'][0];
149       } else {
150         $description= "-";
151       }
152       $content= $this->createContentString($attrs['objectClass']);
153       if ($addon == ""){
154         $img= "images/lists/expand.png";
155       } else {
156         $img= "images/lists/sort-down.png";
157       }
158       $this->objectlist.= 
159         ' <tr style="background-color:'.$cycle[$id&1].';">  '.
160         '   <td class="phonelist" title="'.$attrs['cn'][0].'">  '.
161         '     '.image($img).'&nbsp;'.$attrs['cn'][0].
162         '     <a href="main.php?plug='.$_GET['plug'].'&amp;start=&amp;show='.base64_encode($attrs['dn']).'"> '.
163         '     </a> '.
164         '   </td> '.
165         '   <td>'.$description.'</td> '.
166         '   <td>'.$content.'</td> '.
167         ' </tr>'.$addon;
168       $id++;
169     }
171   }
173   function getCacheObject($dn)
174   {
175     if (!isset($this->objectCache[$dn])){
176       $ldap= $this->config->get_ldap_link();
177       if (preg_match('/,/', $dn)){
178         $ldap->cat($dn, array("cn", "objectClass", "description","ou"));
179       } else {
180         $ldap->search("(uid=$dn)", array("cn", "objectClass", "description","ou"));
181       }
182       if ($ldap->count()){
183         $attrs= $ldap->fetch();
185         if(isset($attrs['ou']) && !isset($attrs['cn'])){
186           $attrs['cn'] = $attrs['ou'];
187         }
189         if (isset($attrs['description'])){
190           $description= $attrs['description'][0];
191         } else {
192           $description= "-";
193         }
194         $this->objectCache[$dn]= array( 'name' => $attrs['cn'][0],
195             'description' => "$description",
196             'type' => $this->createContentString($attrs['objectClass']));
197       } else {
198         return NULL;
199       }
200     }
201     return ($this->objectCache[$dn]);
202   }
204   function createContentString($classes)
205   {
206     $result= "";
207     if(!is_null($classes)) {
208       foreach ($classes as $class){
209         if (isset($this->obtypes[$class])){
210           $result.= 
211             " ".image($this->obtypes[$class]['image']).
212             " <a>".
213             "   ".$this->obtypes[$class]['text'].
214             " </a> ";
215         }
216       }
217     }
218     return (preg_replace('/ $/', '', $result));
219   }
223 ?>